Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: a Reverb slider joins speed and pitch in the player's ⋯ menu
My-Name-Is-Jeff5816a9323acb
diff --git a/harness/audio-effects-page/README.md b/harness/audio-effects-page/README.mdindex 0489ddb6..1bdb1b21 100644--- a/harness/audio-effects-page/README.md+++ b/harness/audio-effects-page/README.md@@ -11,8 +11,8 @@ directory, and an error for any chosen file with "broken" in its name).xcrun simctl launch <udid> com.vojta.audioeffectspageharness master allon section=4 drag=9:7.5xcrun simctl io <udid> screenshot shot.png-Other agents use the simulator too: make a device of your own on the iOS 26.5 runtime (`xcrun simctl create`;-the iOS 27 simulator crashes this harness) and address it by UDID. Every launch clears the `spotifyglass.dsp` keys first unless `keep` is on the line; `main.m` lists the+Other agents use the simulator too: make a device of your own (`xcrun simctl create`) and address it by UDID.+It has a scene delegate (`../scene.m`), so it runs on the iOS 27 simulator as well as 26.5. Every launch clears the `spotifyglass.dsp` keys first unless `keep` is on the line; `main.m` lists thesetup words (`master`, `allon`, `broken`, `slow`) and the actions, played one every 0.7 s from 1 s in:scrolling to a card, flipping a card's switch, a band mid-drag and let go, a preset, a tap on a row, thefile and GraphicEQ pages, an import through the document picker's delegate, Paste, a slider moved, VoiceOver'sdiff --git a/harness/audio-effects-page/build.sh b/harness/audio-effects-page/build.shindex a2791332..040f0a14 100755--- a/harness/audio-effects-page/build.sh+++ b/harness/audio-effects-page/build.sh@@ -11,7 +11,7 @@ rm -rf "$OUT"; mkdir -p "$OUT/AudioEffectsPageHarness.app"SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \-I"$SRC" -I"$FX" -isysroot "$SDK" -Wall -Wno-deprecated-declarations \- "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" \+ "$(dirname "$0")/main.m" "$(dirname "$0")/../scene.m" "$(dirname "$0")/stubs.m" \"$FX"/AudioEffectsSettings.m "$FX"/AudioEffectsPage.m "$FX"/SGDSPCurveView.m "$FX"/AudioEffectsLibraryPage.m "$FX"/SGDSPFilters.m \"$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m "$SRC"/Settings/SGModPage.m "$SRC"/Settings/SGGlowSwitch.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \@@ -31,6 +31,12 @@ cat > "$OUT/AudioEffectsPageHarness.app/Info.plist" <<'PLIST'<key>UILaunchScreen</key><dict/><key>UIApplicationSceneManifest</key><dict><key>UIApplicationSupportsMultipleScenes</key><false/>+ <key>UISceneConfigurations</key><dict>+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>+ <key>UISceneConfigurationName</key><string>Default</string>+ <key>UISceneDelegateClassName</key><string>SGRHarnessScene</string>+ </dict></array>+ </dict></dict></dict></plist>PLISTdiff --git a/harness/audio-effects/main.m b/harness/audio-effects/main.mindex 01b5f894..0146e14e 100644--- a/harness/audio-effects/main.m+++ b/harness/audio-effects/main.m@@ -231,7 +231,7 @@ static void allOff(SGDSPEngine *engine) {SGDSPEngineSetConvolver(engine, false, NULL, 0, error, sizeof error);SGDSPEngineSetDDC(engine, false, NULL, error, sizeof error);SGDSPEngineSetLiveprog(engine, false, NULL, error, sizeof error);- SGDSPEngineSetReverb(engine, false, 5);+ SGDSPEngineSetReverb(engine, false, 5, 50);SGDSPEngineSetStereoWide(engine, false, 60);SGDSPEngineSetCrossfeed(engine, false, 2);SGDSPEngineSetTube(engine, false, 2);@@ -772,7 +772,7 @@ static void checkReverb(void) {for (int p = 0; p < SGDSPReverbPresetCount; p++) {SGDSPEngine *engine = SGDSPEngineCreate(kRate);allOff(engine);- SGDSPEngineSetReverb(engine, true, p);+ SGDSPEngineSetReverb(engine, true, p, 50);Audio impulse = makeAudio((size_t)kRate * 12);impulse.left[kSGDSPEngineBlock * 2] = impulse.right[kSGDSPEngineBlock * 2] = 0.5f;run(engine, impulse, kPattern1024);@@ -933,7 +933,7 @@ static bool setEffect(SGDSPEngine *engine, Effect effect, bool on) {ok = SGDSPEngineSetLiveprog(engine, on, "desc: width\n@init\nw = 0.3;\n@sample\nm = (spl0 + spl1) / 2;\ns = (spl0 - spl1) / 2 * (1 + w);\nspl0 = m + s;\nspl1 = m - s;\n",error, sizeof error);break;- case kReverb: SGDSPEngineSetReverb(engine, on, 5); break;+ case kReverb: SGDSPEngineSetReverb(engine, on, 5, 50); break;case kWide: SGDSPEngineSetStereoWide(engine, on, 60); break;case kCrossfeed: SGDSPEngineSetCrossfeed(engine, on, 2); break;case kTube: SGDSPEngineSetTube(engine, on, 2); break;@@ -1109,7 +1109,7 @@ static void *hammer(void *context) {// Setters that leave the sound as it is, so every block, processed or passed dry, must be exact.switch (i % 6) {case 0: SGDSPEngineSetOutput(h->engine, 0, -0.1, 60); break;- case 1: SGDSPEngineSetReverb(h->engine, false, 5); break;+ case 1: SGDSPEngineSetReverb(h->engine, false, 5, 50); break;case 2: SGDSPEngineSetEqualizer(h->engine, false, kEqFrequencies, zeros); break;case 3: SGDSPEngineSetCrossfeed(h->engine, false, 2); break;case 4: SGDSPEngineSetLiveprog(h->engine, false, NULL, error, sizeof error); break;diff --git a/harness/menu/README.md b/harness/menu/README.mdindex c2d53cff..db85742a 100644--- a/harness/menu/README.md+++ b/harness/menu/README.md@@ -11,9 +11,13 @@ pitch the way it would on the phone. Speed and pitch themselves are stubs that lIt has a scene delegate, so it runs on the iOS 27 simulator as well as 26. The mod's own lines(`SGLog`) go to the unified log: `xcrun simctl spawn <udid> log stream --predicate 'eventMessage CONTAINS "[spotifyglass]"'`.-The plain run opens the menu at 1 s, the block at 3 s, moves both sliders at 5 s and closes the block-at 7 s. `footer` gives the mock table a header of Spotify's, so the block goes to the footer;-`nospeed` has the player refuse speed.+The plain run opens the menu at 1 s, the block at 3 s, moves the three sliders at 5 s, and at 6 s logs+`PASS` or `FAIL` for what the block then says: the Reverb thumb where it was let go, the Pitch reading+"Follows speed" (its reset off) while Pitch follows speed is on at 1.25x, and the switch enabled. It+closes the block at 7 s and at 8 s checks the closed row reads "1.25× Reverb", no semitones claimed.+`footer` gives the mock table a header of Spotify's, so the block goes to the footer;+`nospeed` has the player refuse speed: the speed slider is left alone, the switch must be disabled, and+the Pitch and the row read "−3 st".- `loading` builds the sheet the way Spotify's is laid out (a header, a content container holding atable sized to its content by KVO on `contentSize`, a spinner) and gives it its rows 4 s after it isdiff --git a/harness/menu/main.m b/harness/menu/main.mindex 5048ad99..47001370 100644--- a/harness/menu/main.m+++ b/harness/menu/main.m@@ -4,8 +4,8 @@// THEOS=$HOME/theos ./build.sh && xcrun simctl install <udid> build/MenuHarness.app// xcrun simctl launch --console-pty <udid> com.vojta.menuharness [footer] [nospeed] [loading] [stuck] [open]//-// The plain run opens the menu at 1 s, opens the block at 3 s, moves both sliders at 5 s and closes the-// block at 7 s. `loading` builds the sheet the way Spotify's is (the ivars of ContextMenuViewController in+// The plain run opens the menu at 1 s, opens the block at 3 s, moves the sliders at 5 s, checks what the+// block says at 6 s (PASS or FAIL lines), closes the block at 7 s and checks its row at 8 s. `loading` builds the sheet the way Spotify's is (the ivars of ContextMenuViewController in// 9.1.78: a header, a content container holding a ContextMenuTableView whose height follows its// contentSize by KVO, a loading spinner) and hands it its rows only 4 s after it is up, as Spotify does// once its item factories have answered; `stuck` never hands them over. `open` opens the block on a first@@ -26,11 +26,24 @@ void SGSetPlayerSpeed(double speed) { sg_speed = speed; NSLog(@"[harness] speedfloat SGPlayerPitch(void) { return sg_pitch; }void SGSetPlayerPitch(float semitones) { sg_pitch = semitones; NSLog(@"[harness] pitch %.0f", semitones); }BOOL SGPlayerPitchAvailable(void) { return YES; }+static BOOL sg_follows = YES;+BOOL SGPlayerPitchFollowsSpeed(void) { return sg_follows; }+void SGSetPlayerPitchFollowsSpeed(BOOL follows) { sg_follows = follows; NSLog(@"[harness] pitch follows speed %d", follows); }+// The audio effects' settings, kept in a dictionary: the reverb slider reads and writes them.+static NSMutableDictionary *sg_dsp;+BOOL SGDSPSwitch(NSString *key) { return [sg_dsp[key] boolValue]; }+void SGDSPSetSwitch(NSString *key, BOOL on) { if (!sg_dsp) sg_dsp = [NSMutableDictionary dictionary]; sg_dsp[key] = @(on); NSLog(@"[harness] %@ %d", key, on); }+double SGDSPNumber(NSString *key) { return [sg_dsp[key] doubleValue]; }+void SGDSPSetNumber(NSString *key, double value) { if (!sg_dsp) sg_dsp = [NSMutableDictionary dictionary]; sg_dsp[key] = @(value); NSLog(@"[harness] %@ %.0f", key, value); }static BOOL argument(NSString *name) {return [NSProcessInfo.processInfo.arguments containsObject:name];}+static void check(BOOL ok, NSString *what) {+ NSLog(@"[harness] %@ %@", ok ? @"PASS" : @"FAIL", what);+}+static NSArray<NSArray<NSString *> *> *spotifyRows(void) {return @[@[@"plus.circle", @"Add to playlist"], @[@"music.note.list", @"Add to queue"], @[@"person", @"Go to artist"],@[@"square.stack", @"Go to album"], @[@"square.and.arrow.up", @"Share"], @[@"moon", @"Sleep timer"],@@ -336,14 +349,40 @@ static void tapRow(UIViewController *menu) {});after(5, ^{NSArray<UISlider *> *found = sliders(findBlock(menu.view));- found[0].value = 1.27;- [found[0] sendActionsForControlEvents:UIControlEventValueChanged];- [found[0] sendActionsForControlEvents:UIControlEventTouchUpInside];+ // A disabled slider takes no finger, so `nospeed` leaves speed alone.+ if (sg_speedAllowed) {+ found[0].value = 1.27;+ [found[0] sendActionsForControlEvents:UIControlEventValueChanged];+ [found[0] sendActionsForControlEvents:UIControlEventTouchUpInside];+ }found[1].value = -3.2;[found[1] sendActionsForControlEvents:UIControlEventValueChanged];[found[1] sendActionsForControlEvents:UIControlEventTouchUpInside];+ found[2].value = 41;+ [found[2] sendActionsForControlEvents:UIControlEventValueChanged];+ [found[2] sendActionsForControlEvents:UIControlEventTouchUpInside];+ });+ // What the block says once the fingers are off: the reverb's thumb where it was let go, and while pitch+ // follows a speed that is not normal, no semitones claimed. Without speed (`nospeed`) the switch is off+ // limits and the pitch is the slider's.+ BOOL speed = !argument(@"nospeed");+ after(6, ^{+ UIView *block = findBlock(menu.view);+ NSArray<UISlider *> *found = sliders(block);+ UIButton *pitch = [block valueForKey:@"_pitchValue"];+ UISwitch *follows = [block valueForKey:@"_follows"];+ check(found[2].value == 40, [NSString stringWithFormat:@"the reverb's thumb stays at 40 once let go (%.0f)", found[2].value]);+ NSString *want = speed ? @"Follows speed" : @"−3 st";+ check([[pitch titleForState:UIControlStateNormal] isEqualToString:want] && pitch.enabled == !speed,+ [NSString stringWithFormat:@"the pitch reads %@ (%@, reset %@)", want, [pitch titleForState:UIControlStateNormal], pitch.enabled ? @"on" : @"off"]);+ check(follows.enabled == speed, [NSString stringWithFormat:@"Pitch follows speed %@", speed ? @"enabled" : @"disabled without speed"]);});after(7, ^{ tapRow(menu); });+ after(8, ^{+ UILabel *summary = [findBlock(menu.view) valueForKey:@"_summary"];+ NSString *want = speed ? @"1.25× Reverb" : @"−3 st Reverb";+ check([summary.text isEqualToString:want], [NSString stringWithFormat:@"the closed row reads \"%@\" (\"%@\")", want, summary.text]);+ });}@enddiff --git a/tweak/Sources/Shared/AudioEffects/AudioEffects.h b/tweak/Sources/Shared/AudioEffects/AudioEffects.hindex 09b934d6..6cd9273e 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffects.h+++ b/tweak/Sources/Shared/AudioEffects/AudioEffects.h@@ -55,6 +55,7 @@#define SGKeyDSPReverb @"spotifyglass.dsp.reverb"#define SGKeyDSPReverbPreset @"spotifyglass.dsp.reverb.preset" // SGDSPReverbPresetNames index+#define SGKeyDSPReverbAmount @"spotifyglass.dsp.reverb.amount" // %, 50 is the room's own mix#define SGKeyDSPStereoWide @"spotifyglass.dsp.wide"#define SGKeyDSPStereoWideLevel @"spotifyglass.dsp.wide.level" // percent, 50 leaving the width as it isdiff --git a/tweak/Sources/Shared/AudioEffects/AudioEffects.x b/tweak/Sources/Shared/AudioEffects/AudioEffects.xindex 6695865f..c762a393 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffects.x+++ b/tweak/Sources/Shared/AudioEffects/AudioEffects.x@@ -394,7 +394,7 @@ static void applyEffect(SGDSPEngine *engine, NSString *effect) {what = [NSString stringWithFormat:@"Liveprog %@%@%@", onOff(on), on ? @", " : @"", on ? [NSString stringWithFormat:@"%@ compiled in %.0f ms",path.lastPathComponent, (CFAbsoluteTimeGetCurrent() - start) * 1000] : @""];} else if ([effect isEqualToString:SGKeyDSPReverb]) {- SGDSPEngineSetReverb(engine, on, (int)SGDSPNumber(SGKeyDSPReverbPreset));+ SGDSPEngineSetReverb(engine, on, (int)SGDSPNumber(SGKeyDSPReverbPreset), (float)SGDSPNumber(SGKeyDSPReverbAmount));what = [NSString stringWithFormat:@"reverb %@, %@", onOff(on), choice(SGDSPReverbPresetNames(), SGKeyDSPReverbPreset)];} else if ([effect isEqualToString:SGKeyDSPStereoWide]) {double level = SGDSPNumber(SGKeyDSPStereoWideLevel);diff --git a/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m b/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.mindex 77333685..0ed17175 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m+++ b/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m@@ -140,6 +140,7 @@ static NSArray<SGDSPEffect *> *effects(void) {]),effect(SGKeyDSPReverb, @"Reverb", @"A room around the music", @"building.columns", @[choice(@"Room", SGKeyDSPReverbPreset, SGDSPReverbPresetNames()),+ slider(@"Amount", SGKeyDSPReverbAmount, @"%"),]),effect(SGKeyDSPStereoWide, @"Stereo widening", @"A wider or narrower stereo image", @"arrow.left.and.right", @[width,diff --git a/tweak/Sources/Shared/AudioEffects/AudioEffectsSettings.m b/tweak/Sources/Shared/AudioEffects/AudioEffectsSettings.mindex 1aa24331..ab3000ba 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffectsSettings.m+++ b/tweak/Sources/Shared/AudioEffects/AudioEffectsSettings.m@@ -24,6 +24,7 @@ static const SGDSPNumberKey kNumbers[] = {{SGKeyDSPBassGain, {1, 15, 6, 0.5}},{SGKeyDSPConvolverMode, {0, 2, 0, 1}},{SGKeyDSPReverbPreset, {0, 8, 5, 1}}, // Plate+ {SGKeyDSPReverbAmount, {0, 100, 50, 1}}, // the room's own mix{SGKeyDSPStereoWideLevel, {0, 100, 60, 1}},{SGKeyDSPCrossfeedMode, {0, 2, 2, 1}}, // libbs2b's own default{SGKeyDSPTubeDrive, {0, 18, 4, 0.5}},diff --git a/tweak/Sources/Shared/AudioEffects/SGDSPEffects.h b/tweak/Sources/Shared/AudioEffects/SGDSPEffects.hindex 489ae604..1e7e346e 100644--- a/tweak/Sources/Shared/AudioEffects/SGDSPEffects.h+++ b/tweak/Sources/Shared/AudioEffects/SGDSPEffects.h@@ -61,8 +61,9 @@ void SGDSPCrossfeedRun(void *crossfeed, float *left, float *right, uint32_t fram// preset: an index of SGDSPReverbPresetCount. NULL when the unit could not be made.enum { SGDSPReverbPresetCount = 9 };typedef struct SGDSPReverb SGDSPReverb;-SGDSPReverb *SGDSPReverbCreate(double rate, int preset);-void SGDSPReverbSet(SGDSPReverb *reverb, int preset);+// `amount` scales the room's wet mix: 50 is the room's own, 100 twice it.+SGDSPReverb *SGDSPReverbCreate(double rate, int preset, float amount);+void SGDSPReverbSet(SGDSPReverb *reverb, int preset, float amount);void SGDSPReverbRun(void *reverb, float *left, float *right, uint32_t frames);void SGDSPReverbFree(void *reverb);diff --git a/tweak/Sources/Shared/AudioEffects/SGDSPEngine.h b/tweak/Sources/Shared/AudioEffects/SGDSPEngine.hindex 62c5b8dd..690c9cb9 100644--- a/tweak/Sources/Shared/AudioEffects/SGDSPEngine.h+++ b/tweak/Sources/Shared/AudioEffects/SGDSPEngine.h@@ -35,7 +35,7 @@ void SGDSPEngineSetCompander(SGDSPEngine *engine, bool on, double timeConstant,void SGDSPEngineSetBassBoost(SGDSPEngine *engine, bool on, double maxGainDB);void SGDSPEngineSetEqualizer(SGDSPEngine *engine, bool on, const double frequencies[15], const double gains[15]);// preset: an index of SGDSPReverbPresetCount.-void SGDSPEngineSetReverb(SGDSPEngine *engine, bool on, int preset);+void SGDSPEngineSetReverb(SGDSPEngine *engine, bool on, int preset, float amount);void SGDSPEngineSetStereoWide(SGDSPEngine *engine, bool on, double levelPercent);// preset: an index of SGDSPCrossfeedPresetCount, lightest first.void SGDSPEngineSetCrossfeed(SGDSPEngine *engine, bool on, int preset);diff --git a/tweak/Sources/Shared/AudioEffects/SGDSPEngine.m b/tweak/Sources/Shared/AudioEffects/SGDSPEngine.mindex dba8a7a9..b8b86e09 100644--- a/tweak/Sources/Shared/AudioEffects/SGDSPEngine.m+++ b/tweak/Sources/Shared/AudioEffects/SGDSPEngine.m@@ -411,18 +411,18 @@ void SGDSPEngineSetEqualizer(SGDSPEngine *engine, bool on, const double frequencinstall(engine, SlotEqualizer, SGDSPEqualizerCreate(bands));}-void SGDSPEngineSetReverb(SGDSPEngine *engine, bool on, int preset) {+void SGDSPEngineSetReverb(SGDSPEngine *engine, bool on, int preset, float amount) {if (!on) {install(engine, SlotReverb, NULL);return;}SGDSPReverb *reverb = running(engine, SlotReverb);if (reverb) {- SGDSPReverbSet(reverb, preset);+ SGDSPReverbSet(reverb, preset, amount);done(engine);return;}- install(engine, SlotReverb, SGDSPReverbCreate(engine->rate, preset));+ install(engine, SlotReverb, SGDSPReverbCreate(engine->rate, preset, amount));}void SGDSPEngineSetStereoWide(SGDSPEngine *engine, bool on, double levelPercent) {diff --git a/tweak/Sources/Shared/AudioEffects/SGDSPReverb.m b/tweak/Sources/Shared/AudioEffects/SGDSPReverb.mindex f862809b..a43483ff 100644--- a/tweak/Sources/Shared/AudioEffects/SGDSPReverb.m+++ b/tweak/Sources/Shared/AudioEffects/SGDSPReverb.m@@ -1,5 +1,6 @@#import "SGDSPEffects.h"#import <AudioToolbox/AudioToolbox.h>+#import <math.h>#import <stdlib.h>#import <string.h>@@ -41,7 +42,7 @@ static OSStatus pull(void *refCon, AudioUnitRenderActionFlags *flags, const Audireturn noErr;}-SGDSPReverb *SGDSPReverbCreate(double rate, int preset) {+SGDSPReverb *SGDSPReverbCreate(double rate, int preset, float amount) {AudioComponentDescription description = {kAudioUnitType_Effect, kAudioUnitSubType_Reverb2, kAudioUnitManufacturer_Apple, 0, 0};AudioComponent component = AudioComponentFindNext(NULL, &description);SGDSPReverb *reverb = component ? calloc(1, sizeof *reverb) : NULL;@@ -67,17 +68,18 @@ SGDSPReverb *SGDSPReverbCreate(double rate, int preset) {return NULL;}reverb->output.list.mNumberBuffers = 2;- SGDSPReverbSet(reverb, preset);+ SGDSPReverbSet(reverb, preset, amount);// The unit sets itself up on its first render, allocating: that render is a block of silence, here.float silence[2][kSGDSPEffectMaxFrames] = {{0}};SGDSPReverbRun(reverb, silence[0], silence[1], kSGDSPEffectMaxFrames);return reverb;}-void SGDSPReverbSet(SGDSPReverb *reverb, int preset) {+void SGDSPReverbSet(SGDSPReverb *reverb, int preset, float amount) {const Preset *p = &kPresets[preset < 0 ? 0 : preset >= SGDSPReverbPresetCount ? SGDSPReverbPresetCount - 1 : preset];+ float mix = fminf(100, p->mix * fmaxf(0, amount) / 50);const struct { AudioUnitParameterID id; float value; } values[] = {- {kReverb2Param_DryWetMix, p->mix}, {kReverb2Param_Gain, 0}, {kReverb2Param_MinDelayTime, p->minDelay},+ {kReverb2Param_DryWetMix, mix}, {kReverb2Param_Gain, 0}, {kReverb2Param_MinDelayTime, p->minDelay},{kReverb2Param_MaxDelayTime, p->maxDelay}, {kReverb2Param_DecayTimeAt0Hz, p->decay},{kReverb2Param_DecayTimeAtNyquist, p->decayHigh}, {kReverb2Param_RandomizeReflections, p->density},};diff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.xindex 3c8a4534..ff83e601 100644--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x@@ -24,6 +24,7 @@#import <CoreText/SFNTLayoutTypes.h>#import <objc/runtime.h>#import "Core/SGCore.h"+#import "Shared/AudioEffects/AudioEffects.h"#import "Shared/Haptics/Haptics.h"#import "SpeedPitch.h"@@ -93,12 +94,12 @@ static char kBlockKey, kDecidedKey, kWatchedKey, kShownAtKey, kRowsInKey;UIImageView *_icon, *_chevron;UILabel *_title, *_summary;UIView *_panel;- UILabel *_speedName, *_pitchName;- UIButton *_speedValue, *_pitchValue;- UISlider *_speed, *_pitch;+ UILabel *_speedName, *_pitchName, *_reverbName;+ UIButton *_speedValue, *_pitchValue, *_reverbValue;+ UISlider *_speed, *_pitch, *_reverb;UILabel *_followsName;UISwitch *_follows;- float _shownSpeed, _shownPitch;+ float _shownSpeed, _shownPitch, _shownReverb;NSTimeInterval _speedSentAt;BOOL _speedPending;}@@ -219,19 +220,25 @@ static void placeTick(UISlider *slider) {_speed.accessibilityLabel = @"Speed";_pitch = [self slider:-kMaxPitch max:kMaxPitch normal:0 minImage:@"arrow.down" maxImage:@"arrow.up"];_pitch.accessibilityLabel = @"Pitch";+ _reverbName = makeLabel(nameFont, secondary());+ _reverbName.text = @"Reverb";+ _reverbValue = [self valueButton:@selector(resetReverb)];+ _reverb = [self slider:0 max:100 normal:0 minImage:@"speaker" maxImage:@"building.columns"];+ _reverb.accessibilityLabel = @"Reverb";_followsName = makeLabel(nameFont, primary());_followsName.text = @"Pitch follows speed";_follows = [UISwitch new];_follows.accessibilityLabel = @"Pitch follows speed";[_follows addTarget:self action:@selector(followsChanged) forControlEvents:UIControlEventValueChanged];- for (UIView *view in @[_speedName, _speedValue, _speed, _pitchName, _pitchValue, _pitch, _followsName, _follows]) [_panel addSubview:view];+ for (UIView *view in @[_speedName, _speedValue, _speed, _pitchName, _pitchValue, _pitch, _reverbName, _reverbValue, _reverb,+ _followsName, _follows]) [_panel addSubview:view];[self refresh];return self;}+ (CGFloat)heightOpen:(BOOL)open {- return kRowHeight + (open ? 2 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom : 0);+ return kRowHeight + (open ? 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom : 0);}- (void)layoutSubviews {@@ -246,9 +253,10 @@ static void placeTick(UISlider *slider) {CGFloat summaryX = CGRectGetMaxX(_title.frame) + kGrid;_summary.frame = CGRectMake(summaryX, 0, MAX(0, CGRectGetMinX(_chevron.frame) - kGrid - summaryX), kRowHeight);- _panel.frame = CGRectMake(0, kRowHeight, width, 2 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);+ _panel.frame = CGRectMake(0, kRowHeight, width, 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);CGFloat y = 0;- for (NSArray<UIView *> *line in @[@[_speedName, _speedValue, _speed], @[_pitchName, _pitchValue, _pitch]]) {+ for (NSArray<UIView *> *line in @[@[_speedName, _speedValue, _speed], @[_pitchName, _pitchValue, _pitch],+ @[_reverbName, _reverbValue, _reverb]]) {line[0].frame = CGRectMake(side, y + 4, width / 2 - side, 24);line[1].frame = CGRectMake(width / 2, y + 4, width / 2 - side, 24);line[2].frame = CGRectMake(side, y + 30, width - 2 * side, 36);@@ -263,6 +271,18 @@ static void placeTick(UISlider *slider) {#pragma mark state+// The audio effects' reverb, from the menu: any amount turns the effects and the reverb on, none turns the+// reverb off and leaves the rest of the effects as they were.+static void setReverb(float amount) {+ if (amount > 0) {+ SGDSPSetNumber(SGKeyDSPReverbAmount, amount);+ if (!SGDSPSwitch(SGKeyDSPReverb)) SGDSPSetSwitch(SGKeyDSPReverb, YES);+ if (!SGDSPSwitch(SGKeyDSP)) SGDSPSetSwitch(SGKeyDSP, YES);+ } else if (SGDSPSwitch(SGKeyDSPReverb)) {+ SGDSPSetSwitch(SGKeyDSPReverb, NO);+ }+}+static float snappedSpeed(float value) {float speed = roundf(value / kSpeedStep) * kSpeedStep;return fabsf(speed - 1) < kSpeedStep * 0.6f ? 1 : speed;@@ -282,35 +302,52 @@ static NSString *pitchText(float pitch) {BOOL speedAllowed = SGPlayerSpeedAllowed(), pitchAvailable = SGPlayerPitchAvailable();if (!_speed.tracking) _shownSpeed = snappedSpeed(SGPlayerSpeed());if (!_pitch.tracking) _shownPitch = SGPlayerPitch();+ if (!_reverb.tracking) _shownReverb = SGDSPSwitch(SGKeyDSP) && SGDSPSwitch(SGKeyDSPReverb) ? roundf(SGDSPNumber(SGKeyDSPReverbAmount)) : 0;+ _reverb.value = _shownReverb;_speed.value = _shownSpeed;_pitch.value = _shownPitch;_speed.enabled = speedAllowed;_pitch.enabled = pitchAvailable;_speed.alpha = speedAllowed ? 1 : 0.4;+ // Following needs the speed's unit, which the in place fallback does not have._follows.on = SGPlayerPitchFollowsSpeed();+ _follows.enabled = speedAllowed;+ _follows.alpha = _followsName.alpha = speedAllowed ? 1 : 0.4;[self showValues];}- (void)showValues {BOOL speedAllowed = SGPlayerSpeedAllowed(), pitchAvailable = SGPlayerPitchAvailable();+ // While pitch follows a speed that is not normal, the speed sets the pitch and the semitones are not+ // played (SGTimePitch.h), so the slider stands aside and nothing claims them.+ BOOL following = speedAllowed && _follows.on && _shownSpeed != 1;+ float pitch = following ? 0 : _shownPitch;[UIView performWithoutAnimation:^{[_speedValue setTitle:speedAllowed ? speedText(_shownSpeed) : @"Unavailable here" forState:UIControlStateNormal];- [_pitchValue setTitle:pitchAvailable ? [pitchText(_shownPitch) stringByAppendingString:_shownPitch ? @" st" : @""] : @"Unavailable" forState:UIControlStateNormal];+ [_pitchValue setTitle:!pitchAvailable ? @"Unavailable" : following ? @"Follows speed" : [pitchText(pitch) stringByAppendingString:pitch ? @" st" : @""]+ forState:UIControlStateNormal];[_speedValue layoutIfNeeded];[_pitchValue layoutIfNeeded];}];- // While pitch follows a speed that is not normal, the speed sets the pitch, so the slider stands aside.- BOOL pitchFree = pitchAvailable && !(_follows.on && _shownSpeed != 1);+ BOOL pitchFree = pitchAvailable && !following;_pitch.enabled = pitchFree;_pitch.alpha = pitchFree ? 1 : 0.4;_speedValue.enabled = speedAllowed && _shownSpeed != 1;- _pitchValue.enabled = pitchAvailable && _shownPitch != 0;+ _pitchValue.enabled = pitchFree && pitch != 0;+ [UIView performWithoutAnimation:^{+ [_reverbValue setTitle:_shownReverb > 0 ? [NSString stringWithFormat:@"%.0f%%", _shownReverb] : @"Off" forState:UIControlStateNormal];+ [_reverbValue layoutIfNeeded];+ }];+ _reverbValue.enabled = _shownReverb > 0;+ _reverb.accessibilityValue = _shownReverb > 0 ? [NSString stringWithFormat:@"%.0f percent", _shownReverb] : @"Off";_speed.accessibilityValue = speedAllowed ? speedText(_shownSpeed) : @"Unavailable";- _pitch.accessibilityValue = _shownPitch == 0 ? @"Original pitch" : [NSString stringWithFormat:@"%.0f semitones %@", fabsf(_shownPitch), _shownPitch > 0 ? @"up" : @"down"];+ _pitch.accessibilityValue = following ? @"Follows speed" : pitch == 0 ? @"Original pitch"+ : [NSString stringWithFormat:@"%.0f semitones %@", fabsf(pitch), pitch > 0 ? @"up" : @"down"];NSMutableArray<NSString *> *changed = [NSMutableArray array];if (_shownSpeed != 1) [changed addObject:speedText(_shownSpeed)];- if (_shownPitch != 0) [changed addObject:[pitchText(_shownPitch) stringByAppendingString:@" st"]];+ if (pitch != 0) [changed addObject:[pitchText(pitch) stringByAppendingString:@" st"]];+ if (_shownReverb > 0) [changed addObject:@"Reverb"];_summary.text = sg_open ? nil : [changed componentsJoinedByString:@" "];_row.accessibilityLabel = changed.count ? [@"Speed and pitch, " stringByAppendingString:[changed componentsJoinedByString:@", "]] : @"Speed and pitch";_row.accessibilityValue = sg_open ? @"Expanded" : @"Collapsed";@@ -375,6 +412,12 @@ static NSString *pitchText(float pitch) {if (view && view->_speedPending) [view sendSpeed];});}+ } else if (slider == _reverb) {+ float amount = roundf(slider.value / 5) * 5;+ if (amount == _shownReverb) return;+ if (amount == 0 || _shownReverb == 0) SGPlayFeedback(SGFeedbackDetent);+ _shownReverb = amount;+ setReverb(amount);} else {float pitch = roundf(slider.value);if (pitch == _shownPitch) return;@@ -389,11 +432,20 @@ static NSString *pitchText(float pitch) {if (slider == _speed) {slider.value = _shownSpeed;if (_speedPending || snappedSpeed(SGPlayerSpeed()) != _shownSpeed) [self sendSpeed];+ } else if (slider == _reverb) {+ slider.value = _shownReverb;} else {slider.value = _shownPitch;}}+- (void)resetReverb {+ _shownReverb = 0;+ setReverb(0);+ [_reverb setValue:0 animated:YES];+ [self showValues];+}+- (void)followsChanged {SGSetPlayerPitchFollowsSpeed(_follows.on);SGPlayFeedback(SGFeedbackDetent);