Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: Speed, Pitch & Reverb opens sliders from the player's ⋯ again

My-Name-Is-Jeff9ca0541e7252
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 32f97664..579db076 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -474,8 +474,9 @@ Redesigned:
and a close with no pick dismisses the hidden sheet. Checked in the simulator against
harness/system-menu/
Player/ the redesigned full screen player (Player.h lists its files); its more button opens the system
- menu (ContextMenu/), Spotify's rows and then Playback Speed, Pitch (with Pitch follows speed),
- Reverb and the backgrounds it can switch to (PlayerMenu.m), and a hold on either side of the
+ menu (ContextMenu/), Spotify's rows and then Speed, Pitch & Reverb, which opens the sliders and
+ Pitch follows speed in a popover from the ⋯ (SpeedPitchMenu.x), and the backgrounds it can switch
+ to (PlayerMenu.m), and a hold on either side of the
cover plays at 2x until the finger lifts (PlayerArtwork.x), an octave higher while Pitch follows
speed is on. A Free account gets it too: Spotify's Reinvented Free player mode, whose units none of
the hooks reach, declines while the redesign runs, so the track falls to Spotify's other Free mode,
diff --git a/tweak/Sources/Redesigned/Player/PlayerMenu.m b/tweak/Sources/Redesigned/Player/PlayerMenu.m
index 22680c04..da07b76c 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMenu.m
+++ b/tweak/Sources/Redesigned/Player/PlayerMenu.m
@@ -2,25 +2,20 @@
// queue in a row at its top, then the player's own items here, then More with the rest of Spotify's rows. The
// player's items take over what Speed and pitch's block is on Spotify's sheet:
//
-// Speed, Pitch & Reverb a submenu of three:
-// Playback Speed 0.5× to 2× in the steps Podcasts offers, the current one checked
-// Pitch Pitch Follows Speed, then three semitones down to three up, Original between them
-// Reverb Off and a quarter at a time up to 100%, the audio effects' reverb
+// Speed, Pitch & Reverb opens the sliders in a popover from the ⋯ (SGPlayerShowSpeedPitchPanel): speed,
+// pitch, reverb and Pitch follows speed, as on Spotify's sheet (issue #14)
// Show Fluid Artwork, Show Animated Artwork, Show Visualizer
// a button for each of the two the background is not, while it is one of the
// three, named for what it switches to
//
-// Each submenu says what it is set to under its name, so the menu reads as a settings summary without opening
-// anything. A public menu has no sliders, so the steps stand in for them: the sheet's block, with its finer
-// steps, is still what shows when the menu cannot open (ContextMenu.h). What the speed or the pitch is set to
-// outside the steps (from that block) is kept, said under the name, and checked nowhere.
+// The item says under its name what is not as Spotify plays it, so the menu reads as a settings summary.
#import "Core/SGCore.h"
#import "Redesigned/ContextMenu/ContextMenu.h"
#import "Shared/Player/PlayerState.h"
#import "Shared/Player/SpeedPitch.h"
#import "Player.h"
-static const float kSemitonesShown = 3;
+static __weak UIView *sg_moreButton; // the ⋯ the sliders' panel comes from
static UIImage *symbol(NSString *name) {
return [UIImage systemImageNamed:name];
@@ -44,77 +39,16 @@ static BOOL pitchFollowing(void) {
return SGPlayerSpeedAllowed() && SGPlayerPitchFollowsSpeed() && SGPlayerSpeed() != 1;
}
-static UIMenu *speedMenu(void) {
- BOOL allowed = SGPlayerSpeedAllowed();
- double current = SGPlayerSpeed();
- NSMutableArray<UIMenuElement *> *choices = [NSMutableArray array];
- for (NSNumber *step in @[@0.5, @0.75, @1, @1.25, @1.5, @1.75, @2]) {
- UIAction *choice = [UIAction actionWithTitle:speedText(step.doubleValue) image:nil identifier:nil handler:^(UIAction *action) {
- SGSetPlayerSpeed(step.doubleValue);
- }];
- choice.state = fabs(current - step.doubleValue) < 0.01 ? UIMenuElementStateOn : UIMenuElementStateOff;
- if (!allowed) choice.attributes = UIMenuElementAttributesDisabled;
- [choices addObject:choice];
- }
- UIMenu *menu = [UIMenu menuWithTitle:@"Playback Speed" image:symbol(@"gauge.with.dots.needle.67percent") identifier:nil options:0 children:choices];
- menu.subtitle = allowed ? speedText(current) : @"Unavailable";
- return menu;
-}
-
-static UIMenu *pitchMenu(void) {
- BOOL available = SGPlayerPitchAvailable(), speedAllowed = SGPlayerSpeedAllowed(), follows = SGPlayerPitchFollowsSpeed();
- BOOL following = pitchFollowing();
- float current = SGPlayerPitch();
-
- UIAction *follow = [UIAction actionWithTitle:@"Pitch Follows Speed" image:nil identifier:nil handler:^(UIAction *action) {
- SGSetPlayerPitchFollowsSpeed(!follows);
- }];
- follow.state = follows ? UIMenuElementStateOn : UIMenuElementStateOff;
- // Following needs the speed's unit, which the in place fallback does not have.
- if (!speedAllowed) follow.attributes = UIMenuElementAttributesDisabled;
-
- NSMutableArray<UIMenuElement *> *steps = [NSMutableArray array];
- for (float semitones = kSemitonesShown; semitones >= -kSemitonesShown; semitones--) {
- float chosen = semitones;
- UIAction *step = [UIAction actionWithTitle:semitonesText(chosen) image:nil identifier:nil handler:^(UIAction *action) {
- SGSetPlayerPitch(chosen);
- }];
- step.state = !following && current == chosen ? UIMenuElementStateOn : UIMenuElementStateOff;
- if (!available || following) step.attributes = UIMenuElementAttributesDisabled;
- [steps addObject:step];
- }
- UIMenu *menu = [UIMenu menuWithTitle:@"Pitch" image:symbol(@"tuningfork") identifier:nil options:0 children:@[
- [UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:@[follow]],
- [UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:steps],
- ]];
- menu.subtitle = !available ? @"Unavailable" : following ? @"Follows Speed" : semitonesText(current);
- return menu;
-}
-
-static UIMenu *reverbMenu(void) {
- float current = SGPlayerReverb();
- NSMutableArray<UIMenuElement *> *choices = [NSMutableArray array];
- for (NSNumber *amount in @[@0, @25, @50, @75, @100]) {
- UIAction *choice = [UIAction actionWithTitle:amount.floatValue ? [NSString stringWithFormat:@"%@%%", amount] : @"Off" image:nil identifier:nil
- handler:^(UIAction *action) { SGPlayerSetReverb(amount.floatValue); }];
- choice.state = current == amount.floatValue ? UIMenuElementStateOn : UIMenuElementStateOff;
- [choices addObject:choice];
- }
- UIMenu *menu = [UIMenu menuWithTitle:@"Reverb" image:symbol(@"building.columns") identifier:nil options:0 children:choices];
- menu.subtitle = current > 0 ? [NSString stringWithFormat:@"%.0f%%", current] : @"Off";
- return menu;
-}
-
-// The three under one item, which says what is not as Spotify plays it, or Normal.
-static UIMenu *soundMenu(void) {
+// One item for the three, which says what is not as Spotify plays it, or Normal.
+static UIAction *soundMenu(void) {
NSMutableArray<NSString *> *changed = [NSMutableArray array];
if (SGPlayerSpeedAllowed() && fabs(SGPlayerSpeed() - 1) >= 0.01) [changed addObject:speedText(SGPlayerSpeed())];
if (SGPlayerPitchAvailable() && !pitchFollowing() && SGPlayerPitch() != 0) [changed addObject:semitonesText(SGPlayerPitch())];
if (SGPlayerReverb() > 0) [changed addObject:[NSString stringWithFormat:@"Reverb %.0f%%", SGPlayerReverb()]];
- UIMenu *menu = [UIMenu menuWithTitle:@"Speed, Pitch & Reverb" image:symbol(@"slider.horizontal.3") identifier:nil options:0
- children:@[speedMenu(), pitchMenu(), reverbMenu()]];
- menu.subtitle = changed.count ? [changed componentsJoinedByString:@", "] : @"Normal";
- return menu;
+ UIAction *open = [UIAction actionWithTitle:@"Speed, Pitch & Reverb" image:symbol(@"slider.horizontal.3") identifier:nil
+ handler:^(UIAction *action) { SGPlayerShowSpeedPitchPanel(sg_moreButton); }];
+ open.subtitle = changed.count ? [changed componentsJoinedByString:@", "] : @"Normal";
+ return open;
}
static NSArray<UIMenuElement *> *playerItems(void) {
@@ -145,5 +79,6 @@ static NSString *sheetKind(void) {
}
void SGRPlayerMenuWatch(UIView *button) {
+ sg_moreButton = button;
SGRSystemMenuWatch(button, ^NSArray<UIMenuElement *> *{ return playerItems(); }, ^NSString *{ return sheetKind(); });
}
diff --git a/tweak/Sources/Shared/Player/SpeedPitch.h b/tweak/Sources/Shared/Player/SpeedPitch.h
index 61bc98a5..006f6389 100644
--- a/tweak/Sources/Shared/Player/SpeedPitch.h
+++ b/tweak/Sources/Shared/Player/SpeedPitch.h
@@ -56,6 +56,8 @@ void SGPlayerSetReverb(float amount);
BOOL SGPlayerMenuOffersAnimatedArtwork(void);
BOOL SGPlayerMenuAnimatedArtwork(void);
void SGPlayerMenuSetAnimatedArtwork(BOOL on);
+// The speed, pitch and reverb sliders and Pitch follows speed, in a popover from `from` (the redesign's ⋯).
+void SGPlayerShowSpeedPitchPanel(UIView *from);
// A stage between Spotify's mixer and the rest of the chain (Sing's look-ahead, Shared/Sing): it fills the
// chain's buffers, pulling the mixer through `pull` as much as it likes. NULL passes the mixer straight on.
// Called on the render thread, and only on the music's output (below) while Spotify's connection to it is taken
diff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
index 854fe320..13127baa 100644
--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x
+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
@@ -32,6 +32,7 @@
#import <CoreText/SFNTLayoutTypes.h>
#import <objc/runtime.h>
#import "Core/SGCore.h"
+#import "Settings/SGPageStyle.h"
#import "Shared/AudioEffects/AudioEffects.h"
#import "Shared/Haptics/Haptics.h"
#import "SpeedPitch.h"
@@ -95,6 +96,8 @@ static char kBlockKey, kDecidedKey, kWatchedKey, kShownAtKey, kRowsInKey;
@interface SGSpeedPitchView : UIView
@property (nonatomic, weak) UITableView *table;
@property (nonatomic) BOOL inFooter;
+// The sliders alone, always open, for the redesign's panel under the ⋯ (SGPlayerShowSpeedPitchPanel).
+@property (nonatomic) BOOL panelOnly;
@end
@implementation SGSpeedPitchView {
@@ -267,6 +270,13 @@ static void placeTick(UISlider *slider) {
+ (SGPlayerMenuOffersAnimatedArtwork() ? kRowHeight : 0);
}
+// Set after init, which drew the values for the sheet's closed block: drawn again open.
+- (void)setPanelOnly:(BOOL)panelOnly {
+ _panelOnly = panelOnly;
+ [self showValues];
+ [self setNeedsLayout];
+}
+
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat width = self.bounds.size.width, side = kSideMargin;
@@ -279,7 +289,9 @@ 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, 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);
+ _row.hidden = self.panelOnly;
+ _animatedRow.hidden = self.panelOnly;
+ _panel.frame = CGRectMake(0, self.panelOnly ? kGrid : kRowHeight, width, 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);
CGFloat y = 0;
for (NSArray<UIView *> *line in @[@[_speedName, _speedValue, _speed], @[_pitchName, _pitchValue, _pitch],
@[_reverbName, _reverbValue, _reverb]]) {
@@ -388,8 +400,8 @@ static NSString *pitchText(float pitch) {
_row.accessibilityLabel = changed.count ? [@"Speed and pitch, " stringByAppendingString:[changed componentsJoinedByString:@", "]] : @"Speed and pitch";
_row.accessibilityValue = sg_open ? @"Expanded" : @"Collapsed";
_chevron.transform = sg_open ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformIdentity;
- _panel.alpha = sg_open ? 1 : 0;
- _panel.accessibilityElementsHidden = !sg_open;
+ _panel.alpha = sg_open || self.panelOnly ? 1 : 0;
+ _panel.accessibilityElementsHidden = !sg_open && !self.panelOnly;
}
#pragma mark actions
@@ -509,6 +521,52 @@ static NSString *pitchText(float pitch) {
@end
+#pragma mark - the panel
+
+// A popover, so it takes the system's glass and closes on a tap outside it. On iPhone a popover becomes a
+// sheet unless its delegate says otherwise.
+@interface SGSpeedPitchPanel : UIViewController <UIPopoverPresentationControllerDelegate>
+@end
+
+@implementation SGSpeedPitchPanel
+- (void)loadView {
+ SGSpeedPitchView *block = [SGSpeedPitchView new];
+ block.panelOnly = YES;
+ self.view = block;
+}
+
+- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
+ traitCollection:(UITraitCollection *)traits {
+ return UIModalPresentationNone;
+}
+@end
+
+void SGPlayerShowSpeedPitchPanel(UIView *from) {
+ if (!from.window) return;
+ SGSpeedPitchPanel *panel = [SGSpeedPitchPanel new];
+ panel.modalPresentationStyle = UIModalPresentationPopover;
+ panel.preferredContentSize = CGSizeMake(320, kGrid + 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);
+ UIPopoverPresentationController *popover = panel.popoverPresentationController;
+ popover.sourceView = from;
+ popover.sourceRect = from.bounds;
+ popover.permittedArrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
+ popover.delegate = panel;
+ SGPresentDark(panel);
+ // Picked from the system menu, which is still going away: the panel waits for it.
+ __block int tries = 0;
+ __block void (^present)(void);
+ present = ^{
+ UIViewController *top = SGTopController();
+ if ((top.isBeingDismissed || top.isBeingPresented || top.transitionCoordinator) && ++tries < 20) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), present);
+ return;
+ }
+ present = nil;
+ [top presentViewController:panel animated:YES completion:nil];
+ };
+ dispatch_async(dispatch_get_main_queue(), present);
+}
+
#pragma mark - the player's more button
@interface SGMoreTapWatcher : NSObject <UIGestureRecognizerDelegate>