From 7ac57ea618cbeda8b1296bec52a7ff997c48ca7d Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:19:57 +0700 Subject: [PATCH] feat(automix): choose how often songs are mixed on their beats AutoMix mixes two songs on their beats only when it is sure of both beat grids, and otherwise crossfades. Measured offline over 64 songs of a mixed library in every order, that was 0.8% of the pairs: 96% failed because one of the two grids was not certain enough, 3% because the tempos were too far apart, and none because of a late first beat. Lowering the confidence a single analysis window needs was not the way: of the songs whose first window scored 0.25 to 0.35, fewer than half kept the same tempo six seconds later. Agreement between two windows is the better evidence, and the analyzer already asked for it, but only from a second window that was itself certain. A grid recovered that way is now marked confirmed, and the new Beat matching setting chooses how certain the confirming window must be and how far the incoming tempo may move: Standard 0.55, 8% 0.8% of pairs (unchanged behaviour, the default) More often 0.40, 10% 3.7% Most often 0.30, 12% 6.2% The tempo and phase agreement the analyzer requires is unchanged, and so are the first beat limit and the alignment check when the mix starts. The setting rests while the transition effect is Crossfade, travels with Link sound sync (a peer without it ignores the key), and falls back to Standard for a value it does not know. --- lib/l10n/arb/app_en.arb | 10 ++++ lib/l10n/arb/app_id.arb | 7 +++ lib/models/automix_options.dart | 38 +++++++++++- lib/models/settings.dart | 8 +++ lib/models/settings.g.dart | 14 +++++ lib/providers/settings_provider.dart | 3 + lib/services/automix_analysis.dart | 23 ++++++- lib/services/automix_analyzer.dart | 6 +- .../link/sync/link_sound_sync_protocol.dart | 5 ++ .../link/sync/link_sound_sync_store.dart | 5 ++ lib/services/music_player_automix.dart | 6 +- lib/widgets/automix_settings.dart | 49 +++++++++++++++ test/automix_analysis_test.dart | 60 +++++++++++++++++++ test/automix_analyzer_test.dart | 23 +++++++ test/automix_options_test.dart | 4 ++ test/automix_settings_test.dart | 45 ++++++++++++++ test/link_sound_sync_test.dart | 6 +- .../support/music_player_automix_harness.dart | 1 + 18 files changed, 305 insertions(+), 8 deletions(-) diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index d925deacf..7c8c3a35c 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -10113,6 +10113,16 @@ "autoMixPitch": "Pitch (semitones)", "autoMixEcho": "Echo", "autoMixLowPass": "Muffled filter", + "autoMixMatching": "Beat matching", + "@autoMixMatching": { + "description": "AutoMix setting: how readily two songs are mixed on their beats instead of crossfaded" + }, + "autoMixMatchingStandard": "Standard", + "autoMixMatchingStandardHint": "Only songs with a clear beat", + "autoMixMatchingMore": "More often", + "autoMixMatchingMoreHint": "Also songs with a less clear beat", + "autoMixMatchingMost": "Most often", + "autoMixMatchingMostHint": "As many songs as possible. A mix can sometimes sound off.", "autoMixMixing": "Mixing", "autoMixCrossfading": "Crossfade", "playbackAutomation": "Automatic playback", diff --git a/lib/l10n/arb/app_id.arb b/lib/l10n/arb/app_id.arb index cdec02dca..cc65d9054 100644 --- a/lib/l10n/arb/app_id.arb +++ b/lib/l10n/arb/app_id.arb @@ -8641,6 +8641,13 @@ "autoMixPitch": "Nada (semitone)", "autoMixEcho": "Gema", "autoMixLowPass": "Filter redam", + "autoMixMatching": "Pencocokan ketukan", + "autoMixMatchingStandard": "Standar", + "autoMixMatchingStandardHint": "Hanya lagu dengan ketukan yang jelas", + "autoMixMatchingMore": "Lebih sering", + "autoMixMatchingMoreHint": "Juga lagu dengan ketukan yang kurang jelas", + "autoMixMatchingMost": "Paling sering", + "autoMixMatchingMostHint": "Sebanyak mungkin lagu. Mix kadang bisa terdengar meleset.", "autoMixMixing": "Mixing", "autoMixCrossfading": "Crossfade", "playbackAutomation": "Pemutaran otomatis", diff --git a/lib/models/automix_options.dart b/lib/models/automix_options.dart index d101262fe..56247f6cc 100644 --- a/lib/models/automix_options.dart +++ b/lib/models/automix_options.dart @@ -1,5 +1,29 @@ enum AutoMixEffect { auto, crossfade, muffled, echo, pitch, custom } +/// How readily two songs are mixed on their beats instead of crossfaded. +/// +/// One analysis window is trusted from a confidence of 0.55. Below that a +/// second window of the song must repeat its tempo and beats; the levels +/// differ in how uncertain that second window may be and in how far the +/// incoming song's tempo may move. Measured over 64 songs in every order, +/// [standard] mixed 0.8% of the pairs, [more] 3.7% and [most] 6.2%. +enum AutoMixMatching { + standard(confirmedConfidence: 0.55, maxTempoChange: 0.08), + more(confirmedConfidence: 0.4, maxTempoChange: 0.1), + most(confirmedConfidence: 0.3, maxTempoChange: 0.12); + + const AutoMixMatching({ + required this.confirmedConfidence, + required this.maxTempoChange, + }); + + /// The least confidence, 0 to 1, of the window that repeats the beats. + final double confirmedConfidence; + + /// The most the incoming song's tempo may change, as a share of it. + final double maxTempoChange; +} + int autoMixDurationFromJson(Object? value) => value is num && value.isFinite && value > 0 ? value.round().clamp(3, 60) @@ -19,11 +43,13 @@ class AutoMixOptions { this.pitchSemitones = 0, this.echo = false, this.lowPass = false, + this.matching = AutoMixMatching.standard, }); /// Zero chooses a short musical overlap automatically. final int durationSeconds; final AutoMixEffect effect; + final AutoMixMatching matching; final double speed; final double pitchSemitones; final bool echo; @@ -32,7 +58,15 @@ class AutoMixOptions { @override bool operator ==(Object other) => other is AutoMixOptions && - (durationSeconds, effect, speed, pitchSemitones, echo, lowPass) == + ( + durationSeconds, + effect, + speed, + pitchSemitones, + echo, + lowPass, + matching, + ) == ( other.durationSeconds, other.effect, @@ -40,6 +74,7 @@ class AutoMixOptions { other.pitchSemitones, other.echo, other.lowPass, + other.matching, ); @override @@ -50,6 +85,7 @@ class AutoMixOptions { pitchSemitones, echo, lowPass, + matching, ); int get safeDurationSeconds => autoMixDurationFromJson(durationSeconds); diff --git a/lib/models/settings.dart b/lib/models/settings.dart index 5ecb16e07..b0c8bd6cb 100644 --- a/lib/models/settings.dart +++ b/lib/models/settings.dart @@ -209,6 +209,10 @@ class AppSettings { final bool autoMixEcho; final bool autoMixLowPass; + /// How readily AutoMix mixes two songs on their beats. + @JsonKey(unknownEnumValue: AutoMixMatching.standard) + final AutoMixMatching autoMixMatching; + /// Playback speed for every song, from [minPlaybackSpeed] to /// [maxPlaybackSpeed]; 1 is normal. @JsonKey(fromJson: playbackSpeedFromJson) @@ -229,6 +233,7 @@ class AppSettings { pitchSemitones: autoMixPitch, echo: autoMixEcho, lowPass: autoMixLowPass, + matching: autoMixMatching, ); final bool discordRichPresenceEnabled; final bool usbBitPerfect; @@ -574,6 +579,7 @@ class AppSettings { this.autoMixPitch = 0, this.autoMixEcho = false, this.autoMixLowPass = false, + this.autoMixMatching = AutoMixMatching.standard, this.playbackSpeed = 1, this.playbackKeepPitch = true, this.playbackPitch = 0, @@ -777,6 +783,7 @@ class AppSettings { double? autoMixPitch, bool? autoMixEcho, bool? autoMixLowPass, + AutoMixMatching? autoMixMatching, double? playbackSpeed, bool? playbackKeepPitch, double? playbackPitch, @@ -954,6 +961,7 @@ class AppSettings { autoMixPitch: autoMixPitch ?? this.autoMixPitch, autoMixEcho: autoMixEcho ?? this.autoMixEcho, autoMixLowPass: autoMixLowPass ?? this.autoMixLowPass, + autoMixMatching: autoMixMatching ?? this.autoMixMatching, playbackSpeed: playbackSpeed ?? this.playbackSpeed, playbackKeepPitch: playbackKeepPitch ?? this.playbackKeepPitch, playbackPitch: playbackPitch ?? this.playbackPitch, diff --git a/lib/models/settings.g.dart b/lib/models/settings.g.dart index 14458ece4..9fe9a1c88 100644 --- a/lib/models/settings.g.dart +++ b/lib/models/settings.g.dart @@ -65,6 +65,13 @@ AppSettings _$AppSettingsFromJson(Map json) => AppSettings( : autoMixPitchFromJson(json['autoMixPitch']), autoMixEcho: json['autoMixEcho'] as bool? ?? false, autoMixLowPass: json['autoMixLowPass'] as bool? ?? false, + autoMixMatching: + $enumDecodeNullable( + _$AutoMixMatchingEnumMap, + json['autoMixMatching'], + unknownValue: AutoMixMatching.standard, + ) ?? + AutoMixMatching.standard, playbackSpeed: json['playbackSpeed'] == null ? 1 : playbackSpeedFromJson(json['playbackSpeed']), @@ -296,6 +303,7 @@ Map _$AppSettingsToJson( 'autoMixPitch': instance.autoMixPitch, 'autoMixEcho': instance.autoMixEcho, 'autoMixLowPass': instance.autoMixLowPass, + 'autoMixMatching': _$AutoMixMatchingEnumMap[instance.autoMixMatching]!, 'playbackSpeed': instance.playbackSpeed, 'playbackKeepPitch': instance.playbackKeepPitch, 'playbackPitch': instance.playbackPitch, @@ -443,3 +451,9 @@ const _$AutoMixEffectEnumMap = { AutoMixEffect.pitch: 'pitch', AutoMixEffect.custom: 'custom', }; + +const _$AutoMixMatchingEnumMap = { + AutoMixMatching.standard: 'standard', + AutoMixMatching.more: 'more', + AutoMixMatching.most: 'most', +}; diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 28eda2b8a..8fa3ae9df 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -691,6 +691,9 @@ class SettingsNotifier extends Notifier { void setAutoMixLowPass(bool enabled) => _commit(state.copyWith(autoMixLowPass: enabled)); + void setAutoMixMatching(AutoMixMatching matching) => + _commit(state.copyWith(autoMixMatching: matching)); + void setPlaybackSpeed(double speed) => _commit(state.copyWith(playbackSpeed: playbackSpeedFromJson(speed))); diff --git a/lib/services/automix_analysis.dart b/lib/services/automix_analysis.dart index 527b18ed3..17905b365 100644 --- a/lib/services/automix_analysis.dart +++ b/lib/services/automix_analysis.dart @@ -9,6 +9,7 @@ class AutoMixBeatGrid { required this.phase, required this.confidence, required this.firstSound, + this.confirmed = false, }); final double bpm; @@ -16,7 +17,22 @@ class AutoMixBeatGrid { final double confidence; final double firstSound; - bool get reliable => confidence >= 0.55 && bpm >= 60 && bpm <= 180; + /// A second window of the song repeated this tempo and these beats. + final bool confirmed; + + bool get _inRange => bpm >= 60 && bpm <= 180; + + /// Certain enough on its own to mix on its beats. + bool get reliable => confidence >= 0.55 && _inRange; + + /// Certain enough at [matching] to back up another window of the song. + bool confirms(AutoMixMatching matching) => + confidence >= matching.confirmedConfidence && _inRange; + + /// Certain enough at [matching], which also takes a less certain grid + /// that is [confirmed]. + bool reliableFor(AutoMixMatching matching) => + reliable || confirmed && confirms(matching); double get period => 60 / bpm; double beatAtOrAfter(double seconds) => phase + ((seconds - phase) / period).ceil() * period; @@ -265,7 +281,8 @@ class AutoMixPlan { fallbackReason = AutoMixFallbackReason.effectTempo; } else if (outro == null || intro == null) { fallbackReason = AutoMixFallbackReason.analysisUnavailable; - } else if (!outro.reliable || !intro.reliable) { + } else if (!outro.reliableFor(options.matching) || + !intro.reliableFor(options.matching)) { fallbackReason = AutoMixFallbackReason.unreliableBeats; } else { final outgoing = outro; @@ -282,7 +299,7 @@ class AutoMixPlan { // The detector measures leading silence, not the length of a musical // intro. A quiet lead-in should not disable an otherwise reliable mix. // Bound the trim so an uncertain/very late onset still uses crossfade. - if ((candidate - 1).abs() > 0.08) { + if ((candidate - 1).abs() > options.matching.maxTempoChange) { fallbackReason = AutoMixFallbackReason.incompatibleTempo; } else if (firstBeat > math.min(12, nextLength * 0.1)) { fallbackReason = AutoMixFallbackReason.longIntro; diff --git a/lib/services/automix_analyzer.dart b/lib/services/automix_analyzer.dart index a23ad411a..b895c32af 100644 --- a/lib/services/automix_analyzer.dart +++ b/lib/services/automix_analyzer.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:mornye/models/automix_options.dart'; import 'package:mornye/services/audio_analysis_jobs.dart'; import 'package:mornye/services/automix_analysis.dart'; import 'package:mornye/services/ffmpeg_support.dart'; @@ -65,9 +66,11 @@ class AutoMixAnalyzer { /// Retry nearby windows only when the first grid is uncertain. Agreement /// with its tempo and phase is required before extrapolating back into the /// actual transition window, so a later tempo change cannot move its cue. + /// [matching] sets how uncertain the nearby window itself may be. Future analyzeTransition( String path, { double offset = 0, + AutoMixMatching matching = AutoMixMatching.standard, }) async { final generation = _generation; final first = await analyze(path, offset: offset); @@ -84,7 +87,7 @@ class AutoMixAnalyzer { if (!attempted.add(nearby)) continue; final candidate = await analyze(path, offset: nearby); if (generation != _generation) return null; - if (candidate == null || !candidate.reliable) continue; + if (candidate == null || !candidate.confirms(matching)) continue; if ((candidate.bpm / first.bpm - 1).abs() > 0.02) continue; final phase = candidate.phase + nearby - offset; // Check both edges. A coincident first beat with a drifting tempo must @@ -111,6 +114,7 @@ class AutoMixAnalyzer { phase: phase, confidence: candidate.confidence, firstSound: first.firstSound, + confirmed: true, ); } return first; diff --git a/lib/services/link/sync/link_sound_sync_protocol.dart b/lib/services/link/sync/link_sound_sync_protocol.dart index 55529cd4b..3d1aba50d 100644 --- a/lib/services/link/sync/link_sound_sync_protocol.dart +++ b/lib/services/link/sync/link_sound_sync_protocol.dart @@ -75,6 +75,7 @@ abstract final class LinkSoundSettingKeys { static const autoMixPitch = 'autoMixPitch'; static const autoMixEcho = 'autoMixEcho'; static const autoMixLowPass = 'autoMixLowPass'; + static const autoMixMatching = 'autoMixMatching'; static const all = { normalizationPreamp, @@ -85,6 +86,7 @@ abstract final class LinkSoundSettingKeys { autoMixPitch, autoMixEcho, autoMixLowPass, + autoMixMatching, }; } @@ -109,6 +111,7 @@ Map linkSoundSettingValues(AppSettings settings) => { LinkSoundSettingKeys.autoMixPitch: settings.autoMixPitch, LinkSoundSettingKeys.autoMixEcho: settings.autoMixEcho, LinkSoundSettingKeys.autoMixLowPass: settings.autoMixLowPass, + LinkSoundSettingKeys.autoMixMatching: settings.autoMixMatching.name, }; /// [value] for setting [key] as this app stores it, or null when it is not @@ -130,6 +133,8 @@ Object? linkSoundSettingValue(String key, Object? value) => switch (key) { ), LinkSoundSettingKeys.autoMixEcho || LinkSoundSettingKeys.autoMixLowPass when value is bool => value, + LinkSoundSettingKeys.autoMixMatching when value is String => + AutoMixMatching.values.any((level) => level.name == value) ? value : null, _ => null, }; diff --git a/lib/services/link/sync/link_sound_sync_store.dart b/lib/services/link/sync/link_sound_sync_store.dart index a6ed4c861..35bb351ce 100644 --- a/lib/services/link/sync/link_sound_sync_store.dart +++ b/lib/services/link/sync/link_sound_sync_store.dart @@ -456,6 +456,11 @@ class LinkSoundProviderAccess implements LinkSoundSettingsAccess { if (value(LinkSoundSettingKeys.autoMixLowPass) case final low?) { notifier.setAutoMixLowPass(low); } + if (value(LinkSoundSettingKeys.autoMixMatching) case final name?) { + for (final level in AutoMixMatching.values) { + if (level.name == name) notifier.setAutoMixMatching(level); + } + } } } diff --git a/lib/services/music_player_automix.dart b/lib/services/music_player_automix.dart index ca82295aa..b7fa72e9a 100644 --- a/lib/services/music_player_automix.dart +++ b/lib/services/music_player_automix.dart @@ -242,9 +242,13 @@ class _MusicAutoMix { final outro = await analyzer.analyzeTransition( currentPath, offset: offset, + matching: options.matching, ); if (!_current(generation)) return; - final intro = await analyzer.analyzeTransition(nextPath); + final intro = await analyzer.analyzeTransition( + nextPath, + matching: options.matching, + ); if (!_current(generation)) return; final plan = AutoMixPlan.create( outgoingDuration: duration, diff --git a/lib/widgets/automix_settings.dart b/lib/widgets/automix_settings.dart index 386f1a59f..d8852c1c8 100644 --- a/lib/widgets/automix_settings.dart +++ b/lib/widgets/automix_settings.dart @@ -69,6 +69,37 @@ class _AutoMixSettingsState extends ConsumerState { ); } + void _showMatchingPicker( + BuildContext context, + AutoMixMatching current, + Map names, + ) { + final l10n = context.l10n; + showAppChoiceSheet( + context: context, + title: l10n.autoMixMatching, + selected: current, + choices: [ + for (final matching in AutoMixMatching.values) + AppChoice( + matching, + switch (matching) { + AutoMixMatching.standard => Icons.looks_one_outlined, + AutoMixMatching.more => Icons.looks_two_outlined, + AutoMixMatching.most => Icons.looks_3_outlined, + }, + names[matching]!, + subtitle: switch (matching) { + AutoMixMatching.standard => l10n.autoMixMatchingStandardHint, + AutoMixMatching.more => l10n.autoMixMatchingMoreHint, + AutoMixMatching.most => l10n.autoMixMatchingMostHint, + }, + ), + ], + onSelected: ref.read(settingsProvider.notifier).setAutoMixMatching, + ); + } + @override Widget build(BuildContext context) { final settings = ref.watch(settingsProvider); @@ -83,6 +114,11 @@ class _AutoMixSettingsState extends ConsumerState { AutoMixEffect.pitch: l10n.autoMixEffectPitch, AutoMixEffect.custom: l10n.autoMixEffectCustom, }; + final matchingNames = { + AutoMixMatching.standard: l10n.autoMixMatchingStandard, + AutoMixMatching.more: l10n.autoMixMatchingMore, + AutoMixMatching.most: l10n.autoMixMatchingMost, + }; Widget slider( String label, String valueLabel, @@ -146,6 +182,19 @@ class _AutoMixSettingsState extends ConsumerState { setState(() => _duration = null); }, ), + // A Crossfade transition never mixes on the beat. + SettingsItem( + icon: Icons.join_inner, + title: l10n.autoMixMatching, + subtitle: matchingNames[settings.autoMixMatching], + onTap: enabled && settings.autoMixEffect != AutoMixEffect.crossfade + ? () => _showMatchingPicker( + context, + settings.autoMixMatching, + matchingNames, + ) + : null, + ), SettingsItem( icon: Icons.tune, title: l10n.autoMixEffect, diff --git a/test/automix_analysis_test.dart b/test/automix_analysis_test.dart index b91e1b75c..6352b7723 100644 --- a/test/automix_analysis_test.dart +++ b/test/automix_analysis_test.dart @@ -125,6 +125,66 @@ void main() { expect(late.incomingStart, Duration.zero); }); + test('a looser matching level takes confirmed beats and a wider tempo', () { + AutoMixPlan at( + AutoMixMatching matching, { + double confidence = 0.9, + bool confirmed = false, + double to = 124, + }) => AutoMixPlan.create( + outgoingDuration: const Duration(seconds: 180), + incomingDuration: const Duration(seconds: 200), + outro: grid(120), + intro: AutoMixBeatGrid( + bpm: to, + phase: 0.17, + confidence: confidence, + firstSound: 0.1, + confirmed: confirmed, + ), + outroOffset: 156, + options: AutoMixOptions(matching: matching), + )!; + // A beat one window is sure of mixes at every level. + for (final matching in AutoMixMatching.values) { + expect(at(matching).beatMatched, isTrue); + } + // A less certain one needs a second window, and a level that takes it. + for (final (confidence, levels) in [ + (0.45, [AutoMixMatching.more, AutoMixMatching.most]), + (0.32, [AutoMixMatching.most]), + (0.28, []), + ]) { + for (final matching in AutoMixMatching.values) { + expect( + at(matching, confidence: confidence, confirmed: true).beatMatched, + levels.contains(matching), + reason: '$confidence at ${matching.name}', + ); + expect( + at(matching, confidence: confidence).fallbackReason, + AutoMixFallbackReason.unreliableBeats, + ); + } + } + // Slowing 131, 135 and 138 BPM to 120 changes them 8.4%, 11.1% and 13%. + for (final (to, levels) in [ + (131.0, [AutoMixMatching.more, AutoMixMatching.most]), + (135.0, [AutoMixMatching.most]), + (138.0, []), + ]) { + for (final matching in AutoMixMatching.values) { + expect( + at(matching, to: to).fallbackReason, + levels.contains(matching) + ? isNull + : AutoMixFallbackReason.incompatibleTempo, + reason: '$to at ${matching.name}', + ); + } + } + }); + test('incompatible or uncertain beats use unstretched crossfade', () { for (final transition in [ plan(120, 160), diff --git a/test/automix_analyzer_test.dart b/test/automix_analyzer_test.dart index 81d576792..76a2b916f 100644 --- a/test/automix_analyzer_test.dart +++ b/test/automix_analyzer_test.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mornye/models/automix_options.dart'; import 'package:mornye/services/automix_analysis.dart'; import 'package:mornye/services/automix_analyzer.dart'; @@ -57,6 +58,28 @@ void main() { }, ); + test('the matching level sets how sure the nearby window must be', () async { + for (final (matching, recovers) in [ + (AutoMixMatching.standard, false), + (AutoMixMatching.more, true), + (AutoMixMatching.most, true), + ]) { + final original = grid(0.35); + final analyzer = WindowAnalyzer() + ..windows.addAll({0: original, 6: grid(0.45), 12: grid(0.45)}); + final result = await analyzer.analyzeTransition( + 'track', + matching: matching, + ); + expect(result!.reliableFor(matching), recovers, reason: matching.name); + expect(result.confirmed, recovers); + // Alone, neither window is sure enough. + expect(result.reliable, isFalse); + if (!recovers) expect(result, same(original)); + analyzer.dispose(); + } + }); + test( 'different tempo or phase cannot lend confidence to the transition', () async { diff --git a/test/automix_options_test.dart b/test/automix_options_test.dart index 88fb330f2..cf75a6e5f 100644 --- a/test/automix_options_test.dart +++ b/test/automix_options_test.dart @@ -13,7 +13,9 @@ void main() { 'autoMixEffect': 'unknown', 'autoMixSpeed': -9, 'autoMixPitch': 88, + 'autoMixMatching': 'unknown', }); + expect(restored.autoMixMatching, AutoMixMatching.standard); expect(restored.autoMixDuration, 60); expect(restored.autoMixEffect, AutoMixEffect.auto); expect(restored.autoMixSpeed, 0.8); @@ -27,7 +29,9 @@ void main() { autoMixPitch: 2, autoMixEcho: true, autoMixLowPass: true, + autoMixMatching: AutoMixMatching.most, ); + expect(selected.autoMixOptions.matching, AutoMixMatching.most); expect( AppSettings.fromJson(selected.toJson()).autoMixOptions, selected.autoMixOptions, diff --git a/test/automix_settings_test.dart b/test/automix_settings_test.dart index 1675e010d..0d593126e 100644 --- a/test/automix_settings_test.dart +++ b/test/automix_settings_test.dart @@ -64,6 +64,51 @@ void main() { }, ); + testWidgets('beat matching saves the level and rests under Crossfade', ( + tester, + ) async { + SharedPreferences.setMockInitialValues({}); + final container = ProviderContainer( + overrides: [ + initialSettingsProvider.overrideWithValue( + const AppSettings(autoMix: true), + ), + ], + ); + addTearDown(container.dispose); + await tester.pumpWidget( + UncontrolledProviderScope( + container: container, + child: const MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: Scaffold(body: SingleChildScrollView(child: AutoMixSettings())), + ), + ), + ); + expect(find.text('Standard'), findsOneWidget); + await tester.tap(find.text('Beat matching')); + await tester.pumpAndSettle(); + expect(find.byType(AppSheetOption), findsNWidgets(3)); + await tester.tap(find.text('Most often')); + await tester.pumpAndSettle(); + expect( + container.read(settingsProvider).autoMixMatching, + AutoMixMatching.most, + ); + expect(find.byType(AppBottomSheet), findsNothing); + expect(find.text('Most often'), findsOneWidget); + // A Crossfade transition never mixes on the beat. + container + .read(settingsProvider.notifier) + .setAutoMixEffect(AutoMixEffect.crossfade); + await tester.pump(); + await tester.tap(find.text('Beat matching')); + await tester.pumpAndSettle(); + expect(find.byType(AppBottomSheet), findsNothing); + expect(tester.takeException(), isNull); + }); + for (final mornye in [false, true]) { testWidgets( 'effect picker follows app theme and saves selection ($mornye)', diff --git a/test/link_sound_sync_test.dart b/test/link_sound_sync_test.dart index 52293352f..0b169ec7f 100644 --- a/test/link_sound_sync_test.dart +++ b/test/link_sound_sync_test.dart @@ -637,8 +637,8 @@ void main() { .setEnabled(true); await _eventually(() => phone.access.presets.containsKey('Desk')); expect(desk.access.presets.keys, unorderedEquals(['Phone', 'Desk'])); - // One preset and the eight settings. - expect(client.posts.single['items'], hasLength(9)); + // One preset and the nine settings. + expect(client.posts.single['items'], hasLength(10)); expect(desk.container.read(_notified), greaterThan(0)); // A desktop edit arrives after its notice. @@ -779,6 +779,7 @@ void main() { setting(LinkSoundSettingKeys.autoMixPitch, -1.0), setting(LinkSoundSettingKeys.autoMixDuration, 12), setting(LinkSoundSettingKeys.autoMixLowPass, true), + setting(LinkSoundSettingKeys.autoMixMatching, 'more'), ]); final presets = container.read(equalizerProvider).presets; expect(presets.map((preset) => preset.name), ['Second', 'Third']); @@ -791,6 +792,7 @@ void main() { expect(settings.autoMixPitch, -1); expect(settings.autoMixDuration, 12); expect(settings.autoMixLowPass, isTrue); + expect(settings.autoMixMatching, AutoMixMatching.more); // The curve playing now is not touched. expect(container.read(equalizerProvider).settings.gains, everyElement(0)); diff --git a/test/support/music_player_automix_harness.dart b/test/support/music_player_automix_harness.dart index e5f4702e4..e5479b695 100644 --- a/test/support/music_player_automix_harness.dart +++ b/test/support/music_player_automix_harness.dart @@ -320,6 +320,7 @@ void setAutoMixOptions(AutoMixOptions options) => musicPlayerRuntime.configure( autoMixPitch: options.pitchSemitones, autoMixEcho: options.echo, autoMixLowPass: options.lowPass, + autoMixMatching: options.matching, ), );