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

feat: the redesign is offered only on iOS 26, and what does not need its glass works under both looks

Vojtěch Škopek1bbfca223518
diff --git a/AGENTS.md b/AGENTS.md
index 5c8d0bc4..31d4174a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -16,7 +16,15 @@ A Theos tweak (Objective-C + Logos) injected into the decrypted Spotify iOS app.
own accent colour. No native tweak runs.
Anything that doesn't draw on Spotify's screens works the same under both: ads, privacy, lyrics
-sources, gestures, blocked artists, flags.
+sources, gestures, blocked artists, flags, Vibrations, Speed and pitch, and the Live Activity. Those
+last three were the redesign's until they moved to `Shared/`, so their keys lost the `.redesign.` and
+`Core/SGPrefs.h`'s `SGMigrateKey` carries the old ones over at launch.
+
+**The redesign needs iOS 26.** It is Liquid Glass, which the system draws from 26 on and no older OS
+can be given, so `SGRedesignAvailable()` (`Core/SGUIMode.h`) holds it there: below 26 both
+`SGRedesignedUI()` and `SGRedesignedUIStored()` answer NO whatever is stored, the switch becomes a
+"Needs iOS 26" row and the tour greys its card out. The native look's floor is iOS 16.1, which is
+Spotify 9.1.78's own.
## Where code goes (`tweak/Sources/`)
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 46336781..a426897a 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -16,7 +16,7 @@
tweak/Sources/App/ what brings the layers together: Mod Settings' root and composed pages, the Mod page,
backup and signing, the welcome tour
tweak/Sources/Diagnostics/ screen dumps, the tree server and the main thread hang sampler of FLEX builds
- extension/LiveActivity/ the redesign's Live Activity widget, a WidgetKit extension of its own
+ extension/LiveActivity/ the Live Activity widget, a WidgetKit extension of its own
extension/AppGroups/ a dylib loaded by Spotify and its home screen widget that moves Spotify's App Groups
into a group the re-signed IPA has; without it the widget stays a placeholder
scripts/ pipeline.sh (build + inject), build-extension.sh (the widget extension, without an
@@ -45,6 +45,13 @@ screens works under both. So the sources are four layers, each a directory of fe
Redesigned/ the redesign; every %ctor starts with `if (!SGRedesignedUI()) return;`
App/ Mod Settings' root and the pages that combine the layers, the Mod page, the tour
+`SGRedesignAvailable()` (Core/SGUIMode.h) holds the redesign to iOS 26 and up: it is Liquid Glass, and
+`UIGlassEffect` is the system's, so on an older OS the glass calls fall back to a blur and the redesign
+runs untested against an older UIKit (issue #37, an iOS 17 scene-update watchdog). Below 26 both
+`SGRedesignedUI()` and `SGRedesignedUIStored()` answer NO whatever is stored, so no Redesigned/ %ctor
+runs, App/Pages.m draws the switch as a "Needs iOS 26" row and the tour greys its card out. The stored
+key is left alone, so a phone that updates gets its redesign back.
+
The two looks never run together, so each hooks the same Spotify class in its own way, and a part of
the look is edited on its own side without touching the other: where both need the same thing, each
has its own copy (the tab bar's composition and its editor, the lyrics page's glass, the soft top edge,
@@ -93,7 +100,13 @@ Shared:
source is on
LockScreenLyrics/ the line being sung in the system's now playing
Navigation/ the page transition fix (PageTransition.x) and opening a spotify: link (Links.x)
- Player/ the player's open and close announced (PlayerEvents.x), the lock screen widget's flags
+ Player/ the player's open and close announced (PlayerEvents.x), what the player is doing read through
+ one hook for every feature that wants it (PlayerState.x), the lock screen widget's flags, and in the
+ more button's menu Speed and pitch: both done to Spotify's audio by Apple's time and pitch unit, put
+ between its mixer and its RemoteIO unit by taking over the connection Spotify makes between them
+ (SpeedPitchMenu.x, SpeedPitch.x, SGTimePitch.m). The block goes into Spotify's own context menu sheet
+ and is drawn from its own measures, not the Kit's, so it sits there under either look. Tested on the
+ Mac against harness/pitch/ and in the simulator against harness/speed/ and harness/menu/
JamesDSP/ JamesDSP's effects on Spotify's sound (JamesDSP.h has the keys and the page's calls): Spotify's import of
AudioOutputUnitStart is rebound, as Music Haptics does, and a render notify on its RemoteIO unit runs
each finished buffer through SGDSPEngine.m, libjamesdsp re-blocked to 1024 frames one block late, in
@@ -101,6 +114,24 @@ Shared:
Spotify sets. Settings apply as they change, on a queue of its own; the file effects read their files
from Documents/spoti.pw/JamesDSP (JamesDSPFiles.m). Tested on the Mac against harness/jamesdsp/,
the hook in the simulator against its sim/
+ Haptics/ Vibrations (Haptics.h lists its files): a tap of UIKit's feedback generators for the player's and the now
+ playing bar's controls, the scrubber's tenths and ends, cover swipes, gestures and the lyrics page's tap to
+ seek, at the strength set for them (ControlHaptics.x, SGFeedback.m); and Music Haptics, Core Haptics
+ playing along with the song: Spotify's import of AudioOutputUnitStart is rebound so its RemoteIO output
+ unit gets a render notify, the samples, in the unit's output format (the hardware's), go through a drum
+ and bass analyzer on the render thread (SGMusicAnalyzer.m, plain C), and a thread of its own schedules
+ the taps and the rumble for when the sound is heard, at their strength and leaving out what Follows
+ leaves out (MusicHaptics.x). Everything applies at once; nothing plays while Spotify is not the active
+ app. The analyzer is scored on the Mac against harness/haptics/, the hook in the simulator against its
+ sim/, the settings against harness/haptics-page/
+ LiveActivity/ a Live Activity on the lock screen and in the Dynamic Island in one of three views, the line being
+ sung with the next one under it, the tracks up next (a tap on one skipping ahead to it), or a control
+ menu of tabs, Controls (previous, play and pause, next, shuffle, repeat), Queue and a sleep Timer of
+ the mod's own that pauses Spotify (LiveActivity.h lists its files): a timer polls the player and
+ sends a new state only when what the view shows changes, local updates only, no push. Taps are
+ LiveActivityIntents run inside Spotify and take a second or two to show on the card. The widget is extension/LiveActivity; ActivityKit pairs the two
+ by the attributes' type in LiveActivityShared.swift, compiled into both. It starts only with Spotify
+ in front; its switch and its view apply at once
Native:
@@ -126,10 +157,8 @@ Redesigned:
the Mac against harness/tabbar/
NowPlayingBar/ the glass now playing bar (NowPlayingBar.x), with Spotify's device button on it hidden on request
(BarConnect.x, its own key and its own Now playing page, apart from the native look's)
- Player/ the redesigned full screen player (Player.h lists its files), and in its more menu Speed and pitch:
- both done to Spotify's audio by Apple's time and pitch unit, put between its mixer and its RemoteIO unit
- by taking over the connection Spotify makes between them (PlayerSpeedPitch.x, SGRTimePitch.m). Tested on the Mac against harness/pitch/ and
- harness/menu/
+ Player/ the redesigned full screen player (Player.h lists its files); its more button is handed to
+ Shared/Player's Speed and pitch, which draws in the menu it opens
Lyrics/ the full screen lyrics page on glass with Apple Music style lyrics over it, always on (SGRKaraokeView,
which the player shows in itself too, Player/PlayerLyrics.x): lines sung over each other lit together,
the stack moving on once the first is sung out; an instrumental break of 7 s or more held by three dots
@@ -166,24 +195,6 @@ Redesigned:
like, and whatever it adds next -- but the album's own line and its copyright (Album.h lists its
files). A podcast's episode page is the same template, so it is given the same field, and what it
paints over it is taken off. Laid out on the Mac against harness/album/
- Haptics/ Vibrations (Haptics.h lists its files): a tap of UIKit's feedback generators for the player's and the now
- playing bar's controls, the scrubber's tenths and ends, cover swipes, gestures and the lyrics page's tap to
- seek, at the strength set for them (ControlHaptics.x, SGRFeedback.m); and Music Haptics, Core Haptics
- playing along with the song: Spotify's import of AudioOutputUnitStart is rebound so its RemoteIO output
- unit gets a render notify, the samples, in the unit's output format (the hardware's), go through a drum
- and bass analyzer on the render thread (SGRMusicAnalyzer.m, plain C), and a thread of its own schedules
- the taps and the rumble for when the sound is heard, at their strength and leaving out what Follows
- leaves out (MusicHaptics.x). Everything applies at once; nothing plays while Spotify is not the active
- app. The analyzer is scored on the Mac against harness/haptics/, the hook in the simulator against its
- sim/, the settings against harness/haptics-page/
- LiveActivity/ a Live Activity on the lock screen and in the Dynamic Island in one of three views, the line being
- sung with the next one under it, the tracks up next (a tap on one skipping ahead to it), or a control
- menu of tabs, Controls (previous, play and pause, next, shuffle, repeat), Queue and a sleep Timer of
- the mod's own that pauses Spotify (LiveActivity.h lists its files): a timer polls the player and
- sends a new state only when what the view shows changes, local updates only, no push. Taps are
- LiveActivityIntents run inside Spotify and take a second or two to show on the card. The widget is extension/LiveActivity; ActivityKit pairs the two
- by the attributes' type in LiveActivityShared.swift, compiled into both. It starts only with Spotify
- in front; its switch and its view apply at once
App:
@@ -201,8 +212,8 @@ which makes every unset switch read off, so a reset is stock Spotify whatever sw
A hook reads its switch when it runs (`SGEnabled`, `SGHidden`, `SGFlag` from Core/SGPrefs.h), so a
change shows after Spotify restarts; the tab editor on the Navbar page is the exception and applies as soon as the bar lays
-out again, as are the Home gradient's colour, strength and height, but not the switch that turns it on, and the redesign's
-Vibrations and Live Activity. The root page in `App/ModSettings.x` holds the Appearance card and links the page of each part of Spotify, and only the stored look's.
+out again, as are the Home gradient's colour, strength and height, but not the switch that turns it on, and Vibrations
+and Live Activity. The root page in `App/ModSettings.x` holds the Appearance card and links the page of each part of Spotify, and only the stored look's.
## Make targets
@@ -234,13 +245,14 @@ which of the lyrics, their pronunciation and their translation is set largest, a
in the native look also Now playing bar (its device button and its flags), Queue & devices, and
Spotify's own player screen (artwork background, glass header buttons, Disable Canvas and the sheet,
header, slider and sticky header flags, the cards under the player and the lyrics preview and player
-buttons to hide); in the redesign instead Now playing (its device button) and Vibrations, a card for
+buttons to hide); in the redesign instead Now playing (its device button). Then Vibrations under either look, a card for
Controls (on until switched off) and one for Music Haptics (off until switched on, with an ⓘ saying it
follows the sound this iPhone plays while Spotify is open), each opening out while its switch is on:
Controls into its Strength (10 to 100%, a tap at the new strength with each step), Music Haptics into its
Strength (20 to 200%, 100% being how it first shipped) and Follows, Everything (a tap on each kick and
snare and a rumble under the bass), Beat (the taps without the rumble) or Bass (the kicks' taps and the
-rumble), all applying straight away. Live Activity, in the redesign only: its switch and which view it shows, Lyrics, Queue or Control menu, both
+rumble), all applying straight away. Live Activity, on iOS 17 and up under either look: its switch and which view it
+shows, Lyrics, Queue or Control menu, both
applying straight away, the row reading out the view or Off. Audio effects, in either look (Shared/JamesDSP/JamesDSPPage.m):
JamesDSP's switch with what the engine is doing under it, then a card per effect in RootlessJamesDSP's order, each
opening out into its sliders, choices, curve or file library while its switch is on, everything applying as it
diff --git a/extension/LiveActivity/LiveActivityWidget.swift b/extension/LiveActivity/LiveActivityWidget.swift
index 24cbb491..3b1ea3ae 100644
--- a/extension/LiveActivity/LiveActivityWidget.swift
+++ b/extension/LiveActivity/LiveActivityWidget.swift
@@ -168,7 +168,7 @@ private struct QueueView: View {
}
ForEach(Array(state.tracks.prefix(upNext).enumerated()), id: \.offset) { _, track in
// A tap skips ahead to the track.
- Button(intent: SGRPlayQueuedTrackIntent(track.uri)) {
+ Button(intent: SGPlayQueuedTrackIntent(track.uri)) {
(Text(track.title).fontWeight(.semibold) + Text(" " + track.artist).foregroundColor(.white.opacity(0.5)))
.font(.subheadline)
.lineLimit(1)
@@ -217,7 +217,7 @@ private struct PanelView: View {
VStack(spacing: 8) {
HStack(spacing: 6) {
ForEach(Tab.allCases, id: \.self) { tab in
- Toggle(isOn: tab == state.tab, intent: SGRLiveActivityActionIntent("tab:\(tab.rawValue)")) {
+ Toggle(isOn: tab == state.tab, intent: SGLiveActivityActionIntent("tab:\(tab.rawValue)")) {
EmptyView()
}
.toggleStyle(TabStyle(tab: tab))
@@ -294,7 +294,7 @@ private struct ChipButton: View {
var lit = false
var body: some View {
- Button(intent: SGRLiveActivityActionIntent(action)) {
+ Button(intent: SGLiveActivityActionIntent(action)) {
ChipLabel(symbol: symbol, label: label)
.background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(lit ? green.opacity(0.22) : idle))
.foregroundStyle(lit ? green : .white)
@@ -319,10 +319,10 @@ private struct ControlsPage: View {
.invalidatableContent()
HStack(spacing: 6) {
ChipButton(action: "previous", symbol: "backward.fill", label: "Previous")
- Toggle(isOn: !state.paused, intent: SGRLiveActivityActionIntent("toggle")) { EmptyView() }
+ Toggle(isOn: !state.paused, intent: SGLiveActivityActionIntent("toggle")) { EmptyView() }
.toggleStyle(ChipStyle(symbol: "play.fill", onSymbol: "pause.fill", label: "Play", onLabel: "Pause", lights: false))
ChipButton(action: "next", symbol: "forward.fill", label: "Next")
- Toggle(isOn: state.shuffle, intent: SGRLiveActivityActionIntent("shuffle")) { EmptyView() }
+ Toggle(isOn: state.shuffle, intent: SGLiveActivityActionIntent("shuffle")) { EmptyView() }
.toggleStyle(ChipStyle(symbol: "shuffle", label: "Shuffle"))
// Three states, so a button: the new one shows once the render lands.
ChipButton(action: "repeat", symbol: state.repeatMode == 2 ? "repeat.1" : "repeat",
@@ -345,7 +345,7 @@ private struct QueuePage: View {
.frame(maxWidth: .infinity, minHeight: 60)
}
ForEach(Array(state.tracks.prefix(3).enumerated()), id: \.offset) { _, track in
- Button(intent: SGRPlayQueuedTrackIntent(track.uri)) {
+ Button(intent: SGPlayQueuedTrackIntent(track.uri)) {
HStack(spacing: 10) {
Image(systemName: "play.fill")
.font(.caption)
diff --git a/harness/haptics-page/README.md b/harness/haptics-page/README.md
index 32240352..d37772f2 100644
--- a/harness/haptics-page/README.md
+++ b/harness/haptics-page/README.md
@@ -1,8 +1,8 @@
# Vibrations settings harness
-Mod Settings > Player's Vibrations cards (`tweak/Sources/Redesigned/Haptics/HapticsSettings.m`) on an SGModPage laid
+Mod Settings > Player's Vibrations cards (`tweak/Sources/Shared/Haptics/HapticsSettings.m`) on an SGModPage laid
out like the Player page in the redesign: the real Settings/ framework (its slider row and its rows shown while a
-switch is on), the real control taps (`SGRFeedback.m`, which the simulator plays silently), and `stubs.m` for Music
+switch is on), the real control taps (`SGFeedback.m`, which the simulator plays silently), and `stubs.m` for Music
Haptics' engine, which logs each call with the strength and the Follows choice the hook would read.
THEOS=$HOME/theos ./build.sh
diff --git a/harness/haptics-page/build.sh b/harness/haptics-page/build.sh
index 0c182e02..fd0f8e12 100755
--- a/harness/haptics-page/build.sh
+++ b/harness/haptics-page/build.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Builds the Vibrations settings harness for the simulator: Redesigned/Haptics' settings and control taps, the
+# Builds the Vibrations settings harness for the simulator: Shared/Haptics' settings and control taps, the
# Settings/ framework as they are in the tweak, stubs.m for Music Haptics.
set -e
SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
@@ -10,7 +10,7 @@ SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \
-I"$SRC" -isysroot "$SDK" -Wall -Werror -Wno-deprecated-declarations \
"$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" \
- "$SRC"/Redesigned/Haptics/HapticsSettings.m "$SRC"/Redesigned/Haptics/SGRFeedback.m \
+ "$SRC"/Shared/Haptics/HapticsSettings.m "$SRC"/Shared/Haptics/SGFeedback.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 \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation \
diff --git a/harness/haptics-page/main.m b/harness/haptics-page/main.m
index 00ff4d2d..56e5322e 100644
--- a/harness/haptics-page/main.m
+++ b/harness/haptics-page/main.m
@@ -1,5 +1,5 @@
-// Mod Settings > Player's Vibrations cards (Redesigned/Haptics/HapticsSettings.m) on an SGModPage laid out like the
-// Player page in the redesign, with the real Settings/ framework and SGRFeedback.m behind them and stubs.m for
+// Mod Settings > Player's Vibrations cards (Shared/Haptics/HapticsSettings.m) on an SGModPage laid out like the
+// Player page in the redesign, with the real Settings/ framework and SGFeedback.m behind them and stubs.m for
// Music Haptics' engine. The launch line sets the switches up and then plays actions, one every 0.7 s from 1 s
// in; screenshot after.
//
@@ -17,7 +17,7 @@
#import <UIKit/UIKit.h>
#import "Core/SGCore.h"
#import "Settings/SGModPage.h"
-#import "Redesigned/Haptics/Haptics.h"
+#import "Shared/Haptics/Haptics.h"
static void findViews(UIView *root, Class kind, NSMutableArray *found) {
if ([root isKindOfClass:kind]) [found addObject:root];
@@ -42,7 +42,7 @@ static void findViews(UIView *root, Class kind, NSMutableArray *found) {
SGSection(nil, @[SGWithSymbol(SGPageRow(@"Now playing", none), @"rectangle.bottomthird.inset.filled"),
SGWithSymbol(SGPageRow(@"Lock screen widget", none), @"lock")]),
]];
- [sections addObjectsFromArray:SGRVibrationsSections()];
+ [sections addObjectsFromArray:SGVibrationsSections()];
return [[SGModPage alloc] initWithTitle:@"Player" intro:@"Changes apply after you restart Spotify. Gestures, Blocked artists and Vibrations apply straight away."
sections:sections footer:nil];
}
@@ -57,9 +57,9 @@ static void findViews(UIView *root, Class kind, NSMutableArray *found) {
}
NSMutableArray<NSString *> *actions = [NSMutableArray array];
for (NSString *arg in [args subarrayWithRange:NSMakeRange(1, args.count - 1)]) {
- if ([arg isEqualToString:@"controls-off"]) SGSetEnabled(SGRKeyControlHaptics, NO);
- else if ([arg isEqualToString:@"music"]) SGSetEnabled(SGRKeyMusicHaptics, YES);
- else if ([arg hasPrefix:@"follows="]) SGSetInt(SGRKeyMusicFollows, [arg substringFromIndex:8].integerValue);
+ if ([arg isEqualToString:@"controls-off"]) SGSetEnabled(SGKeyControlHaptics, NO);
+ else if ([arg isEqualToString:@"music"]) SGSetEnabled(SGKeyMusicHaptics, YES);
+ else if ([arg hasPrefix:@"follows="]) SGSetInt(SGKeyMusicFollows, [arg substringFromIndex:8].integerValue);
else if (![@[@"keep", @"slow"] containsObject:arg]) [actions addObject:arg];
}
@@ -140,9 +140,9 @@ static void findViews(UIView *root, Class kind, NSMutableArray *found) {
for (NSString *key in [all.allKeys sortedArrayUsingSelector:@selector(compare:)]) {
if ([key hasPrefix:@"spotifyglass.redesign.haptics"]) NSLog(@"[harness] stored %@ = %@", key, all[key]);
}
- NSLog(@"[harness] the hooks read: Controls %@ at %.0f%%, Music Haptics %@ at %.0f%% following %ld", SGEnabled(SGRKeyControlHaptics) ? @"on" : @"off",
- SGRHapticsStrength(SGRKeyControlStrength) * 100, SGFlag(SGRKeyMusicHaptics, NO) ? @"on" : @"off",
- SGRHapticsStrength(SGRKeyMusicStrength) * 100, (long)SGRMusicHapticsFollows());
+ NSLog(@"[harness] the hooks read: Controls %@ at %.0f%%, Music Haptics %@ at %.0f%% following %ld", SGEnabled(SGKeyControlHaptics) ? @"on" : @"off",
+ SGHapticsStrength(SGKeyControlStrength) * 100, SGFlag(SGKeyMusicHaptics, NO) ? @"on" : @"off",
+ SGHapticsStrength(SGKeyMusicStrength) * 100, (long)SGMusicHapticsFollows());
for (NSInteger section = 0; section < table.numberOfSections; section++) {
NSMutableArray<NSString *> *rows = [NSMutableArray array];
for (NSInteger row = 0; row < [table numberOfRowsInSection:section]; row++) {
diff --git a/harness/haptics-page/stubs.m b/harness/haptics-page/stubs.m
index d782895a..5a65f10c 100644
--- a/harness/haptics-page/stubs.m
+++ b/harness/haptics-page/stubs.m
@@ -1,12 +1,12 @@
// Music Haptics' side of Haptics.h (MusicHaptics.x in the tweak), which the page calls as its switch and its
// settings change: each call is logged with what the hook would read at that moment.
#import "Core/SGCore.h"
-#import "Redesigned/Haptics/Haptics.h"
+#import "Shared/Haptics/Haptics.h"
-void SGRSetMusicHapticsEnabled(BOOL on) {
+void SGSetMusicHapticsEnabled(BOOL on) {
NSLog(@"[harness] Music Haptics %@", on ? @"on" : @"off");
}
-void SGRMusicHapticsSettingsChanged(void) {
- NSLog(@"[harness] Music Haptics reads strength %.0f%%, follows %ld", SGRHapticsStrength(SGRKeyMusicStrength) * 100, (long)SGRMusicHapticsFollows());
+void SGMusicHapticsSettingsChanged(void) {
+ NSLog(@"[harness] Music Haptics reads strength %.0f%%, follows %ld", SGHapticsStrength(SGKeyMusicStrength) * 100, (long)SGMusicHapticsFollows());
}
diff --git a/harness/haptics/README.md b/harness/haptics/README.md
index 8677e715..d987a60b 100644
--- a/harness/haptics/README.md
+++ b/harness/haptics/README.md
@@ -4,7 +4,7 @@ Two halves: the analyzer on the Mac, and the hook in the simulator.
## The analyzer on the Mac (`main.m`, `score.py`)
-`SGRMusicAnalyzer.m` as the tweak compiles it, over a song decoded at the output's rate and handed over in IO
+`SGMusicAnalyzer.m` as the tweak compiles it, over a song decoded at the output's rate and handed over in IO
buffers, the way `MusicHaptics.x` hands it the output's buffers. Every event goes to a CSV (K a kick's tap, S a
snare's, L the rumble's level); `score.py` matches the taps one to one within 50 ms (mir_eval) against librosa's
onsets for each Follows choice, beside what random taps at the same rate score. With demucs' stems beside the
diff --git a/harness/haptics/build-sim.sh b/harness/haptics/build-sim.sh
index 727be3b8..6e3117c0 100755
--- a/harness/haptics/build-sim.sh
+++ b/harness/haptics/build-sim.sh
@@ -5,14 +5,14 @@
# takes as it does in Spotify.
# THEOS=$HOME/theos ./build-sim.sh
# THEOS=$HOME/theos ./build-sim.sh before <dir> the same against <dir>/MusicHaptics.x, <dir>/Haptics.h and
-# <dir>/SGRMusicAnalyzer.{h,m} of an older commit, format steps only
+# <dir>/SGMusicAnalyzer.{h,m} of an older commit, format steps only
set -e
cd "$(dirname "$0")"
SRC=../../tweak/Sources
OUT=build/sim
-HAPTICS="$SRC/Redesigned/Haptics"
+HAPTICS="$SRC/Shared/Haptics"
EXTRA=""
-SETTINGS="$SRC/Redesigned/Haptics/HapticsSettings.m $SRC/Redesigned/Haptics/SGRFeedback.m $SRC/Settings/SGPage.m $SRC/Settings/SGPageStyle.m $SRC/Settings/SGModPage.m $SRC/Settings/SGGlowSwitch.m"
+SETTINGS="$SRC/Shared/Haptics/HapticsSettings.m $SRC/Shared/Haptics/SGFeedback.m $SRC/Settings/SGPage.m $SRC/Settings/SGPageStyle.m $SRC/Settings/SGModPage.m $SRC/Settings/SGGlowSwitch.m"
if [ "$1" = before ]; then
HAPTICS=$2
OUT=build/sim-before
@@ -24,8 +24,8 @@ mkdir -p "$OUT/gen" "$OUT/HapticsHarness.app"
"$THEOS/bin/logos.pl" -c generator=internal "$HAPTICS/MusicHaptics.x" > "$OUT/gen/MusicHaptics.m"
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O1 -isysroot "$SDK" -Wno-deprecated-declarations \
- $EXTRA -I"$SRC" -I"$SRC/Redesigned/Haptics" -Isim \
- sim/main.m sim/fakehaptics.m "$OUT/gen/MusicHaptics.m" "$HAPTICS/SGRMusicAnalyzer.m" $SETTINGS \
+ $EXTRA -I"$SRC" -I"$SRC/Shared/Haptics" -Isim \
+ sim/main.m sim/fakehaptics.m "$OUT/gen/MusicHaptics.m" "$HAPTICS/SGMusicAnalyzer.m" $SETTINGS \
"$SRC/Core/SGRebind.m" "$SRC/Core/SGLog.m" "$SRC/Core/SGPrefs.m" "$SRC/Core/SGUIMode.m" "$SRC/Core/SGViewTree.m" "$SRC/Core/SGFlagForce.m" \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework AudioToolbox -framework AVFoundation -framework Foundation \
-o "$OUT/HapticsHarness.app/HapticsHarness"
diff --git a/harness/haptics/build.sh b/harness/haptics/build.sh
index 073c3f53..e735c591 100755
--- a/harness/haptics/build.sh
+++ b/harness/haptics/build.sh
@@ -1,8 +1,8 @@
#!/bin/sh
-# Builds the Music Haptics analyzer harness for the Mac: SGRMusicAnalyzer.m as the tweak compiles it, and main.m.
+# Builds the Music Haptics analyzer harness for the Mac: SGMusicAnalyzer.m as the tweak compiles it, and main.m.
set -e
cd "$(dirname "$0")"
mkdir -p build
xcrun clang -fobjc-arc -O2 -Wall -Werror -I ../../tweak/Sources -framework Foundation -framework AudioToolbox \
- main.m ../../tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.m -o build/haptics
+ main.m ../../tweak/Sources/Shared/Haptics/SGMusicAnalyzer.m -o build/haptics
echo "built build/haptics"
diff --git a/harness/haptics/main.m b/harness/haptics/main.m
index 601a0103..7aa2fe32 100644
--- a/harness/haptics/main.m
+++ b/harness/haptics/main.m
@@ -1,4 +1,4 @@
-// Music Haptics' analyzer (Redesigned/Haptics/SGRMusicAnalyzer.m, as the tweak compiles it) over a song on the
+// Music Haptics' analyzer (Shared/Haptics/SGMusicAnalyzer.m, as the tweak compiles it) over a song on the
// Mac: the song is decoded at the rate asked for (the output's, 48 kHz on an iPhone), mixed to mono the way
// MusicHaptics.x mixes the output's buffers, handed over in IO buffers of the size asked for, and every event
// is written out one a line: K (a kick's tap), S (a snare's), L (the rumble's level), then the time in seconds,
@@ -8,7 +8,7 @@
// ./build.sh && build/haptics <song> <events.csv> [rate] [frames]
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
-#import "Redesigned/Haptics/SGRMusicAnalyzer.h"
+#import "Shared/Haptics/SGMusicAnalyzer.h"
typedef struct {
FILE *out;
@@ -16,9 +16,9 @@ typedef struct {
double lastTime;
} Run;
-static void emit(const SGRMusicEvent *event, void *context) {
+static void emit(const SGMusicEvent *event, void *context) {
Run *run = context;
- char kind = event->kind == SGRMusicEventKick ? 'K' : event->kind == SGRMusicEventSnare ? 'S' : 'L';
+ char kind = event->kind == SGMusicEventKick ? 'K' : event->kind == SGMusicEventSnare ? 'S' : 'L';
fprintf(run->out, "%c,%.5f,%.4f,%.4f\n", kind, event->hostTime / 1e9, event->intensity, event->sharpness);
if (kind == 'K') run->kicks++;
else if (kind == 'S') run->snares++;
@@ -45,8 +45,8 @@ int main(int argc, char **argv) {
AudioStreamBasicDescription format = {rate, kAudioFormatLinearPCM, kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked, 8, 1, 8, 2, 32, 0};
ExtAudioFileSetProperty(file, kExtAudioFileProperty_ClientDataFormat, sizeof format, &format);
Run run = {fopen(argv[2], "w")};
- SGRMusicAnalyzer analyzer;
- SGRMusicAnalyzerReset(&analyzer, rate, 1e9);
+ SGMusicAnalyzer analyzer;
+ SGMusicAnalyzerReset(&analyzer, rate, 1e9);
float *stereo = malloc(frames * 2 * sizeof(float)), *mono = malloc(frames * sizeof(float));
uint64_t done = 0;
for (;;) {
@@ -54,7 +54,7 @@ int main(int argc, char **argv) {
UInt32 count = frames;
if (ExtAudioFileRead(file, &count, &list) || !count) break;
for (UInt32 i = 0; i < count; i++) mono[i] = 0.5f * (stereo[2 * i] + stereo[2 * i + 1]);
- SGRMusicAnalyzerProcess(&analyzer, mono, count, (uint64_t)(done / rate * 1e9), emit, &run);
+ SGMusicAnalyzerProcess(&analyzer, mono, count, (uint64_t)(done / rate * 1e9), emit, &run);
done += count;
}
fclose(run.out);
diff --git a/harness/haptics/sim/main.m b/harness/haptics/sim/main.m
index 4c714a93..5c1ae658 100644
--- a/harness/haptics/sim/main.m
+++ b/harness/haptics/sim/main.m
@@ -22,7 +22,7 @@
#import <QuartzCore/QuartzCore.h>
#import <stdatomic.h>
#import "Core/SGCore.h"
-#import "Redesigned/Haptics/Haptics.h"
+#import "Shared/Haptics/Haptics.h"
#import "fakehaptics.h"
static atomic_uint_fast64_t sg_frame;
@@ -191,29 +191,29 @@ static int sg_failures;
}]];
#ifndef BEFORE
void (^set)(NSInteger, NSInteger) = ^(NSInteger follows, NSInteger strength) {
- SGSetInt(SGRKeyMusicFollows, follows);
- SGSetInt(SGRKeyMusicStrength, strength);
- SGRMusicHapticsSettingsChanged();
+ SGSetInt(SGKeyMusicFollows, follows);
+ SGSetInt(SGKeyMusicStrength, strength);
+ SGMusicHapticsSettingsChanged();
};
[steps addObjectsFromArray:@[
- @[@"Beat: no rumble", ^{ set(SGRMusicFollowsBeat, 100); }, ^(double s) {
+ @[@"Beat: no rumble", ^{ set(SGMusicFollowsBeat, 100); }, ^(double s) {
[self report:@"Beat: no rumble" seconds:s kicks:1 snares:1 rumble:NO intensity:tap100 level:NAN];
}],
- @[@"Bass: no snares", ^{ set(SGRMusicFollowsBass, 100); }, ^(double s) {
+ @[@"Bass: no snares", ^{ set(SGMusicFollowsBass, 100); }, ^(double s) {
[self report:@"Bass: no snares" seconds:s kicks:1 snares:0 rumble:YES intensity:NAN level:level100];
}],
- @[@"Everything at 50%", ^{ set(SGRMusicFollowsEverything, 50); }, ^(double s) {
+ @[@"Everything at 50%", ^{ set(SGMusicFollowsEverything, 50); }, ^(double s) {
[self report:@"Everything at 50%" seconds:s kicks:1 snares:1 rumble:YES intensity:tap100 / 2 level:level100 / 2];
}],
- @[@"Everything at 200%", ^{ set(SGRMusicFollowsEverything, 200); }, ^(double s) {
+ @[@"Everything at 200%", ^{ set(SGMusicFollowsEverything, 200); }, ^(double s) {
[self report:@"Everything at 200%" seconds:s kicks:1 snares:1 rumble:YES intensity:NAN level:MIN(1, level100 * 2)];
}],
- @[@"the switch off", ^{ SGRSetMusicHapticsEnabled(NO); }, ^(double s) {
+ @[@"the switch off", ^{ SGSetMusicHapticsEnabled(NO); }, ^(double s) {
[self report:@"the switch off" seconds:s kicks:0 snares:0 rumble:NO intensity:NAN level:NAN];
}],
@[@"on again, Everything, 100%", ^{
- set(SGRMusicFollowsEverything, 100);
- SGRSetMusicHapticsEnabled(YES);
+ set(SGMusicFollowsEverything, 100);
+ SGSetMusicHapticsEnabled(YES);
}, ^(double s) {
[self report:@"on again, Everything, 100%" seconds:s kicks:1 snares:1 rumble:YES intensity:tap100 level:level100];
}],
@@ -255,7 +255,7 @@ __attribute__((constructor(101))) static void sgr_harnessDefaults(void) {
if ([key hasPrefix:@"spotifyglass."]) [defaults removeObjectForKey:key];
}
[defaults setBool:YES forKey:SGKeyRedesign];
- [defaults setBool:YES forKey:SGRKeyMusicHaptics];
+ [defaults setBool:YES forKey:SGKeyMusicHaptics];
}
int main(int argc, char *argv[]) {
diff --git a/harness/menu/build.sh b/harness/menu/build.sh
index 57d9533d..bc2b0c42 100755
--- a/harness/menu/build.sh
+++ b/harness/menu/build.sh
@@ -1,19 +1,18 @@
#!/bin/sh
-# Builds the menu harness for the simulator: PlayerMenu.x's hook run for real on a mock of Spotify's
-# context menu sheet.
+# Builds the menu harness for the simulator: SpeedPitchMenu.x's hook run for real on a mock of
+# Spotify's context menu sheet.
set -e
SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/MenuHarness.app"
-"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Redesigned/Player/PlayerMenu.x" > "$OUT/gen/PlayerMenu.m"
+"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Shared/Player/SpeedPitchMenu.x" > "$OUT/gen/SpeedPitchMenu.m"
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \
- -I"$SRC" -I"$SRC/Redesigned/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
+ -I"$SRC" -I"$SRC/Shared/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
"$(dirname "$0")/main.m" "$OUT"/gen/*.m \
"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \
"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \
- "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRRestyle.m "$SRC"/Redesigned/Kit/SGRedesign.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation \
-o "$OUT/MenuHarness.app/MenuHarness"
diff --git a/harness/menu/main.m b/harness/menu/main.m
index 6dd268ed..0b720a01 100644
--- a/harness/menu/main.m
+++ b/harness/menu/main.m
@@ -12,14 +12,14 @@ static double sg_speed = 1;
static float sg_pitch;
static BOOL sg_speedAllowed = YES;
UIColor *SGRAccentColor(void) { return nil; }
-void SGRPlayFeedback(NSInteger feedback) { NSLog(@"[harness] feedback %ld", (long)feedback); }
-void SGRPrepareFeedback(NSInteger feedback) {}
-double SGRPlayerSpeed(void) { return sg_speed; }
-BOOL SGRPlayerSpeedAllowed(void) { return sg_speedAllowed; }
-void SGRSetPlayerSpeed(double speed) { sg_speed = speed; NSLog(@"[harness] speed %.2f", speed); }
-float SGRPlayerPitch(void) { return sg_pitch; }
-void SGRSetPlayerPitch(float semitones) { sg_pitch = semitones; NSLog(@"[harness] pitch %.0f", semitones); }
-BOOL SGRPlayerPitchAvailable(void) { return YES; }
+void SGPlayFeedback(NSInteger feedback) { NSLog(@"[harness] feedback %ld", (long)feedback); }
+void SGPrepareFeedback(NSInteger feedback) {}
+double SGPlayerSpeed(void) { return sg_speed; }
+BOOL SGPlayerSpeedAllowed(void) { return sg_speedAllowed; }
+void SGSetPlayerSpeed(double speed) { sg_speed = speed; NSLog(@"[harness] speed %.2f", speed); }
+float SGPlayerPitch(void) { return sg_pitch; }
+void SGSetPlayerPitch(float semitones) { sg_pitch = semitones; NSLog(@"[harness] pitch %.0f", semitones); }
+BOOL SGPlayerPitchAvailable(void) { return YES; }
#pragma mark - Spotify's sheet
@@ -97,7 +97,7 @@ BOOL SGRPlayerPitchAvailable(void) { return YES; }
@end
static UIView *findBlock(UIView *root) {
- if ([NSStringFromClass(root.class) isEqualToString:@"SGRSpeedPitchView"]) return root;
+ if ([NSStringFromClass(root.class) isEqualToString:@"SGSpeedPitchView"]) return root;
for (UIView *child in root.subviews) {
UIView *found = findBlock(child);
if (found) return found;
diff --git a/harness/pitch/README.md b/harness/pitch/README.md
index b8ebf6a0..08e46dd4 100644
--- a/harness/pitch/README.md
+++ b/harness/pitch/README.md
@@ -1,6 +1,6 @@
# Pitch harness
-`SGRTimePitch.m` run on the Mac both ways the tweak runs it: in place over IO buffers of 1024, 4096
+`SGTimePitch.m` run on the Mac both ways the tweak runs it: in place over IO buffers of 1024, 4096
and odd sizes (pitch alone), and pulling a source at rates from 0.5 to 2 (speed). Checks a 440 Hz sine
comes out at the pitch asked for and the source is consumed at the rate asked for, and reports the
unit's pulls, underruns, delay and cost. With a song path it also writes the song shifted up 3 and down 4
diff --git a/harness/pitch/build.sh b/harness/pitch/build.sh
index 9a0387e9..27328df8 100755
--- a/harness/pitch/build.sh
+++ b/harness/pitch/build.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-# Builds the pitch harness for the Mac: SGRTimePitch.m as the tweak compiles it, and main.m.
+# Builds the pitch harness for the Mac: SGTimePitch.m as the tweak compiles it, and main.m.
set -e
cd "$(dirname "$0")"
mkdir -p build
xcrun clang -fobjc-arc -O2 -I ../../tweak/Sources -framework Foundation -framework AudioToolbox \
- main.m ../../tweak/Sources/Redesigned/Player/SGRTimePitch.m -o build/pitch
+ main.m ../../tweak/Sources/Shared/Player/SGTimePitch.m -o build/pitch
diff --git a/harness/pitch/main.m b/harness/pitch/main.m
index 96c716fe..73d214a9 100644
--- a/harness/pitch/main.m
+++ b/harness/pitch/main.m
@@ -1,4 +1,4 @@
-// Runs SGRTimePitch.m on the Mac both ways the tweak runs it: in place over IO buffers of Spotify's sizes
+// Runs SGTimePitch.m on the Mac both ways the tweak runs it: in place over IO buffers of Spotify's sizes
// (pitch alone), and pulling a source at a rate (speed, with or without pitch). Checks a sine comes out
// at the pitch asked for and the source is consumed at the rate asked for, reports the unit's pulls,
// underruns, delay and cost, and writes a song shifted up and down to listen to.
@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <mach/mach_time.h>
-#import "Redesigned/Player/SGRTimePitch.h"
+#import "Shared/Player/SGTimePitch.h"
static const double kRate = 44100;
@@ -41,19 +41,19 @@ static void runSine(float semitones, int pattern) {
size_t total = (size_t)(kRate * 3);
float *left = calloc(total, sizeof(float)), *right = calloc(total, sizeof(float));
for (size_t i = 0; i < total; i++) left[i] = right[i] = 0.5f * sinf(2 * M_PI * 440 * i / kRate);
- SGRTimePitch *shifter = SGRTimePitchCreate(kRate, 2, NULL, NULL);
+ SGTimePitch *shifter = SGTimePitchCreate(kRate, 2, NULL, NULL);
if (!shifter) {
printf("no shifter\n");
exit(1);
}
- SGRTimePitchSetSemitones(shifter, semitones);
- SGRTimePitchReset(shifter);
+ SGTimePitchSetSemitones(shifter, semitones);
+ SGTimePitchReset(shifter);
uint64_t start = mach_absolute_time();
size_t done = 0, index = 0;
while (done < total) {
UInt32 frames = (UInt32)MIN((size_t)bufferSize(index++, pattern), total - done);
float *channels[2] = {left + done, right + done};
- if (!SGRTimePitchProcess(shifter, channels, frames)) printf(" process failed at %zu\n", done);
+ if (!SGTimePitchProcess(shifter, channels, frames)) printf(" process failed at %zu\n", done);
done += frames;
}
mach_timebase_info_data_t timebase;
@@ -63,8 +63,8 @@ static void runSine(float semitones, int pattern) {
double measured = frequency(left + (size_t)kRate, total - (size_t)kRate);
printf("sine %+5.1f st, buffers %-8s: %6.1f Hz (want %6.1f, %+.2f%%), delay %4zu frames (unit %.1f ms), largest pull %u, underruns %u, failures %u, cost %.2f%% of real time\n",
semitones, pattern == 0 ? "1024" : pattern == 1 ? "4096" : "mixed", measured, expected, (measured / expected - 1) * 100,
- onset(left, total), SGRTimePitchLatency(shifter) * 1000, SGRTimePitchLargestPull(shifter),
- SGRTimePitchUnderruns(shifter), SGRTimePitchFailures(shifter), seconds / 3 * 100);
+ onset(left, total), SGTimePitchLatency(shifter) * 1000, SGTimePitchLargestPull(shifter),
+ SGTimePitchUnderruns(shifter), SGTimePitchFailures(shifter), seconds / 3 * 100);
free(left);
free(right);
}
@@ -89,8 +89,8 @@ static void runSong(NSString *path, float semitones, NSString *outPath) {
};
ExtAudioFileCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:outPath], kAudioFileWAVEType, &wav, NULL, kAudioFileFlags_EraseFile, &output);
ExtAudioFileSetProperty(output, kExtAudioFileProperty_ClientDataFormat, sizeof format, &format);
- SGRTimePitch *shifter = SGRTimePitchCreate(kRate, 2, NULL, NULL);
- SGRTimePitchSetSemitones(shifter, semitones);
+ SGTimePitch *shifter = SGTimePitchCreate(kRate, 2, NULL, NULL);
+ SGTimePitchSetSemitones(shifter, semitones);
float left[1024], right[1024];
size_t seconds = 0;
for (;;) {
@@ -98,7 +98,7 @@ static void runSong(NSString *path, float semitones, NSString *outPath) {
UInt32 frames = 1024;
if (ExtAudioFileRead(file, &frames, &buffers.list) || !frames) break;
float *channels[2] = {left, right};
- SGRTimePitchProcess(shifter, channels, frames);
+ SGTimePitchProcess(shifter, channels, frames);
buffers.list.mBuffers[0].mDataByteSize = buffers.second.mDataByteSize = frames * 4;
ExtAudioFileWrite(output, frames, &buffers.list);
seconds += frames;
@@ -106,7 +106,7 @@ static void runSong(NSString *path, float semitones, NSString *outPath) {
}
ExtAudioFileDispose(file);
ExtAudioFileDispose(output);
- printf("wrote %s (%+.0f st), underruns %u\n", outPath.UTF8String, semitones, SGRTimePitchUnderruns(shifter));
+ printf("wrote %s (%+.0f st), underruns %u\n", outPath.UTF8String, semitones, SGTimePitchUnderruns(shifter));
}
typedef struct { double phase; } Sine;
@@ -123,20 +123,20 @@ static OSStatus sineSource(void *context, UInt32 frames, AudioBufferList *data)
static void runPull(float rate, float semitones) {
Sine sine = {0};
- SGRTimePitch *unit = SGRTimePitchCreate(kRate, 2, sineSource, &sine);
- SGRTimePitchSetRate(unit, rate);
- SGRTimePitchSetSemitones(unit, semitones);
+ SGTimePitch *unit = SGTimePitchCreate(kRate, 2, sineSource, &sine);
+ SGTimePitchSetRate(unit, rate);
+ SGTimePitchSetSemitones(unit, semitones);
size_t total = (size_t)(kRate * 4);
float *left = calloc(total, sizeof(float)), *right = calloc(total, sizeof(float));
for (size_t done = 0; done < total; done += 1024) {
struct { AudioBufferList list; AudioBuffer second; } buffers = {{2, {{1, 4096, left + done}}}, {1, 4096, right + done}};
- if (SGRTimePitchRender(unit, 1024, &buffers.list) != noErr) printf(" render failed\n");
+ if (SGTimePitchRender(unit, 1024, &buffers.list) != noErr) printf(" render failed\n");
}
double measured = frequency(left + (size_t)kRate, total - (size_t)kRate);
double expected = 440 * pow(2, semitones / 12);
- double consumedRate = (double)SGRTimePitchConsumed(unit) / total;
+ double consumedRate = (double)SGTimePitchConsumed(unit) / total;
printf("pull rate %.2f %+3.0f st: %6.1f Hz (want %6.1f, %+.2f%%), consumed %.3fx, largest pull %u, failures %u\n", rate, semitones,
- measured, expected, (measured / expected - 1) * 100, consumedRate, SGRTimePitchLargestPull(unit), SGRTimePitchFailures(unit));
+ measured, expected, (measured / expected - 1) * 100, consumedRate, SGTimePitchLargestPull(unit), SGTimePitchFailures(unit));
free(left);
free(right);
}
diff --git a/harness/player/stubs.m b/harness/player/stubs.m
index dd89b667..ce0b43dc 100644
--- a/harness/player/stubs.m
+++ b/harness/player/stubs.m
@@ -19,18 +19,20 @@ NSString *const SGPlayerTransitionNotification = @"spotifyglass.playerTransition
NSString *const SGPlayerTransitionEndedNotification = @"spotifyglass.playerTransitionEnded";
CFTimeInterval SGPlayerTransitionEnds(void) { return 0; }
-#pragma mark - Redesigned/Kit/SGRBridges.x
+#pragma mark - Shared/Player/PlayerState.x
-NSNotificationName const SGRNowPlayingArtworkDidChangeNotification = @"spotifyglass.redesign.artwork";
-static UIImage *sg_artwork;
-
-NSString *SGRURIString(id uri) {
+NSString *SGURIString(id uri) {
if ([uri isKindOfClass:NSString.class]) return uri;
if ([uri isKindOfClass:NSURL.class]) return ((NSURL *)uri).absoluteString;
return nil;
}
-void SGRAddPlayerStateObserver(id observer) {}
-SPTPlayerState *SGRPlayerState(void) { return nil; }
+void SGAddPlayerStateObserver(id observer) {}
+SPTPlayerState *SGPlayerState(void) { return nil; }
+
+#pragma mark - Redesigned/Kit/SGRBridges.x
+
+NSNotificationName const SGRNowPlayingArtworkDidChangeNotification = @"spotifyglass.redesign.artwork";
+static UIImage *sg_artwork;
void SGRSetNowPlayingArtwork(UIImage *image, NSString *trackURI, NSInteger quality) { sg_artwork = image; }
UIImage *SGRNowPlayingArtwork(NSString **trackURI, NSString **identity) {
if (trackURI) *trackURI = @"spotify:track:harness";
@@ -49,10 +51,10 @@ void SGRPlayerVanish(UIView *view) {
view.accessibilityElementsHidden = YES;
}
-#pragma mark - Redesigned/Haptics
+#pragma mark - Shared/Haptics
-void SGRPlayFeedback(NSInteger feedback) {}
-void SGRPrepareFeedback(NSInteger feedback) {}
+void SGPlayFeedback(NSInteger feedback) {}
+void SGPrepareFeedback(NSInteger feedback) {}
#pragma mark - Shared/LyricsSources
diff --git a/harness/speed/build.sh b/harness/speed/build.sh
index 1e82d907..4ef83be5 100755
--- a/harness/speed/build.sh
+++ b/harness/speed/build.sh
@@ -5,11 +5,11 @@ set -e
SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/SpeedHarness.app"
-"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Redesigned/Player/PlayerSpeedPitch.x" > "$OUT/gen/PlayerSpeedPitch.m"
+"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Shared/Player/SpeedPitch.x" > "$OUT/gen/PlayerSpeedPitch.m"
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O1 \
- -I"$SRC" -I"$SRC/Redesigned/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
- "$(dirname "$0")/main.m" "$OUT"/gen/*.m "$SRC"/Redesigned/Player/SGRTimePitch.m "$SRC"/Core/SGRebind.m \
+ -I"$SRC" -I"$SRC/Shared/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
+ "$(dirname "$0")/main.m" "$OUT"/gen/*.m "$SRC"/Shared/Player/SGTimePitch.m "$SRC"/Core/SGRebind.m \
"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGUIMode.m "$SRC"/Core/SGFlagForce.m \
-framework UIKit -framework QuartzCore -framework AudioToolbox -framework AVFoundation -framework Foundation \
-o "$OUT/SpeedHarness.app/SpeedHarness"
diff --git a/harness/speed/main.m b/harness/speed/main.m
index cdf37721..bb2668f3 100644
--- a/harness/speed/main.m
+++ b/harness/speed/main.m
@@ -11,10 +11,10 @@
#import <AVFoundation/AVFoundation.h>
#import <stdatomic.h>
-double SGRPlayerSpeed(void);
-void SGRSetPlayerSpeed(double speed);
-void SGRSetPlayerPitch(float semitones);
-BOOL SGRPlayerSpeedAllowed(void);
+double SGPlayerSpeed(void);
+void SGSetPlayerSpeed(double speed);
+void SGSetPlayerPitch(float semitones);
+BOOL SGPlayerSpeedAllowed(void);
static const double kRate = 44100;
static atomic_uint_fast64_t sg_decoded;
@@ -116,7 +116,7 @@ static void check(OSStatus status, const char *what) {
self.window.rootViewController = [UIViewController new];
[self.window makeKeyAndVisible];
[self startChain];
- NSLog(@"[harness] speed allowed: %d", SGRPlayerSpeedAllowed());
+ NSLog(@"[harness] speed allowed: %d", SGPlayerSpeedAllowed());
[self after:1 do:^{ [self playerReports]; self->_lastDecoded = atomic_load(&sg_decoded); self->_lastAt = CACurrentMediaTime(); }];
NSArray *script = @[
@[@3, @"normal", @1, @0],
@@ -131,8 +131,8 @@ static void check(OSStatus status, const char *what) {
[self after:[step[0] doubleValue] do:^{
[self report:label];
label = step[1];
- SGRSetPlayerSpeed([step[2] doubleValue]);
- SGRSetPlayerPitch([step[3] floatValue]);
+ SGSetPlayerSpeed([step[2] doubleValue]);
+ SGSetPlayerPitch([step[3] floatValue]);
}];
// A report mid step, the way Spotify's player reports now and then.
[self after:[step[0] doubleValue] + 1.5 do:^{ [self playerReports]; }];
diff --git a/scripts/build-extension.sh b/scripts/build-extension.sh
index 335ed312..c0fdc83e 100755
--- a/scripts/build-extension.sh
+++ b/scripts/build-extension.sh
@@ -14,7 +14,7 @@ HOST_PLIST="${1:?usage: $0 <host Info.plist> <out dir>}"
OUT="${2:?usage: $0 <host Info.plist> <out dir>}"
NAME=SpotifyGlassLiveActivity
APPEX="$OUT/$NAME.appex"
-SHARED="$ROOT/tweak/Sources/Redesigned/LiveActivity/LiveActivityShared.swift"
+SHARED="$ROOT/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift"
WIDGET="$ROOT/extension/LiveActivity/LiveActivityWidget.swift"
SDK="$(xcrun --sdk iphoneos --show-sdk-path)"
diff --git a/scripts/pipeline.sh b/scripts/pipeline.sh
index bd4846a8..ace99a47 100755
--- a/scripts/pipeline.sh
+++ b/scripts/pipeline.sh
@@ -83,7 +83,7 @@ echo " $TWEAK_DEB"
FILES=("$TWEAK_DEB")
[ "$WITH_FLEX" = 1 ] && FILES+=("$FLEX_DEB")
-# The redesign's Live Activity (Redesigned/LiveActivity) draws in a widget extension of its own.
+# The Live Activity (Shared/LiveActivity) draws in a widget extension of its own.
if xcrun --sdk iphoneos --find swiftc >/dev/null 2>&1; then
EXT_DIR="$ROOT/out/extension"
unzip -p "$IN" "${APP_DIR}Info.plist" > "$ROOT/out/.info.plist"
diff --git a/tweak/Sources/App/ModSettings.x b/tweak/Sources/App/ModSettings.x
index e5cdd463..e2e09cb8 100644
--- a/tweak/Sources/App/ModSettings.x
+++ b/tweak/Sources/App/ModSettings.x
@@ -20,7 +20,7 @@
#import "Shared/AdBlock/AdBlock.h"
#import "Shared/Flags/Flags.h"
#import "Shared/JamesDSP/JamesDSPPage.h"
-#import "Redesigned/LiveActivity/LiveActivity.h"
+#import "Shared/LiveActivity/LiveActivity.h"
#import "App/About/About.h"
#import "Pages.h"
@@ -45,19 +45,18 @@ static UIViewController *modSettingsPage(void) {
SGModRow *audioEffects = pageRow(@"Audio effects", @"slider.vertical.3", ^UIViewController *{ return SGDSPSettingsPage(); });
audioEffects.value = ^NSString *{ return SGDSPSummary(); };
// Home & Library holds only the native look's switches, so the redesign has no such page; the
- // Live Activity is the redesign's alone.
+ // Live Activity works under both, and only where ActivityKit's card does.
NSMutableArray<SGModRow *> *parts = [NSMutableArray arrayWithArray:@[
pageRow(@"Navbar", @"dock.rectangle", ^UIViewController *{ return SGNavbarPage(); }),
pageRow(@"Player", @"play.circle", ^UIViewController *{ return SGPlayerSettingsPage(); }),
audioEffects,
]];
- if (SGRedesignedUIStored()) {
- SGModRow *liveActivity = pageRow(@"Live Activity", @"platter.filled.top.iphone", ^UIViewController *{ return SGRLiveActivitySettingsPage(); });
- liveActivity.value = ^NSString *{ return SGRLiveActivitySummary(); };
+ if (@available(iOS 17.0, *)) {
+ SGModRow *liveActivity = pageRow(@"Live Activity", @"platter.filled.top.iphone", ^UIViewController *{ return SGLiveActivitySettingsPage(); });
+ liveActivity.value = ^NSString *{ return SGLiveActivitySummary(); };
[parts addObject:liveActivity];
- } else {
- [parts addObject:pageRow(@"Home & Library", @"house", ^UIViewController *{ return SGHomeSettingsPage(); })];
}
+ if (!SGRedesignedUIStored()) [parts addObject:pageRow(@"Home & Library", @"house", ^UIViewController *{ return SGHomeSettingsPage(); })];
[sections addObjectsFromArray:@[
SGAppearanceSection(),
SGSection(nil, parts),
diff --git a/tweak/Sources/App/Onboarding/Tour.m b/tweak/Sources/App/Onboarding/Tour.m
index fcaf2f5c..0acd178d 100644
--- a/tweak/Sources/App/Onboarding/Tour.m
+++ b/tweak/Sources/App/Onboarding/Tour.m
@@ -45,11 +45,14 @@ static UIButton *glassButton(NSString *title) {
// when it is the one picked.
@interface SGLookCard : UIControl
- (instancetype)initWithSymbol:(NSString *)symbol title:(NSString *)title subtitle:(NSString *)subtitle;
+// A look this phone cannot run: the card stays on the page, greyed and untappable, and says why.
+- (void)makeUnavailable:(NSString *)reason;
@end
@implementation SGLookCard {
SGGlassView *_glass;
UIImageView *_check;
+ UILabel *_line;
}
- (instancetype)initWithSymbol:(NSString *)symbol title:(NSString *)title subtitle:(NSString *)subtitle {
@@ -69,6 +72,7 @@ static UIButton *glassButton(NSString *title) {
line.font = [UIFont systemFontOfSize:13];
line.textColor = SGGrey();
line.numberOfLines = 0;
+ _line = line;
UIStackView *text = [[UIStackView alloc] initWithArrangedSubviews:@[name, line]];
text.axis = UILayoutConstraintAxisVertical;
text.spacing = 2;
@@ -118,7 +122,17 @@ static UIButton *glassButton(NSString *title) {
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
- self.alpha = highlighted ? 0.6 : 1;
+ if (self.enabled) self.alpha = highlighted ? 0.6 : 1;
+}
+
+- (void)makeUnavailable:(NSString *)reason {
+ self.selected = NO;
+ self.enabled = NO;
+ self.alpha = 0.45;
+ _line.text = reason;
+ _check.image = [UIImage systemImageNamed:@"lock.fill"
+ withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:17 weight:UIImageSymbolWeightSemibold]];
+ _check.tintColor = SGGrey();
}
@end
@@ -190,8 +204,9 @@ static UIButton *glassButton(NSString *title) {
UIView *strip = [UIView new];
[strip addSubview:halo];
+ BOOL glass = SGRedesignAvailable();
UILabel *heading = [UILabel new];
- heading.text = @"Pick your look.";
+ heading.text = glass ? @"Pick your look." : @"Your look.";
heading.font = [UIFont systemFontOfSize:30 weight:UIFontWeightBold];
heading.textColor = UIColor.whiteColor;
heading.numberOfLines = 0;
@@ -200,9 +215,15 @@ static UIButton *glassButton(NSString *title) {
_legacy = [[SGLookCard alloc] initWithSymbol:@"slider.horizontal.3" title:@"Legacy" subtitle:@"More options, still looks like Spotify."];
for (SGLookCard *card in @[_redesigned, _legacy]) [card addTarget:self action:@selector(picked:) forControlEvents:UIControlEventTouchUpInside];
// The first launch offers the redesign; the tour again from the Mod page shows the stored look.
- BOOL redesign = SGFlag(SGKeyOnboardingSeen, NO) ? SGRedesignedUIStored() : YES;
+ BOOL redesign = glass && (SGFlag(SGKeyOnboardingSeen, NO) ? SGRedesignedUIStored() : YES);
_redesigned.selected = redesign;
_legacy.selected = !redesign;
+ // Liquid Glass is drawn by iOS 26 and by nothing before it, so on an older phone the card stays
+ // on the page to say so and the legacy look is the only one left.
+ if (!glass) {
+ [_redesigned makeUnavailable:[NSString stringWithFormat:@"Needs iOS 26. This phone runs iOS %@.", UIDevice.currentDevice.systemVersion]];
+ _legacy.enabled = NO;
+ }
_beta = [self betaNote];
_beta.hidden = !redesign;
diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.m
index 08312c5f..105032f4 100644
--- a/tweak/Sources/App/Pages.m
+++ b/tweak/Sources/App/Pages.m
@@ -10,8 +10,8 @@
#import "Native/Navbar/Navbar.h"
#import "Native/NowPlayingBar/NowPlayingBar.h"
#import "Native/Player/NowPlaying.h"
-#import "Redesigned/Haptics/Haptics.h"
-#import "Redesigned/LiveActivity/LiveActivity.h"
+#import "Shared/Haptics/Haptics.h"
+#import "Shared/LiveActivity/LiveActivity.h"
#import "Redesigned/Lyrics/LyricsText.h"
#import "Redesigned/Navbar/Navbar.h"
#import "Redesigned/NowPlayingBar/NowPlayingBar.h"
@@ -21,8 +21,6 @@ NSString *const SGRedesignedUIInfo = @"The newest version of spoti.pw, leaning t
void SGSetRedesignedUI(BOOL on) {
SGSetEnabled(SGKeyRedesign, on);
- // The native look has no Live Activity to end one the redesign left on the lock screen.
- if (!on) SGRSetLiveActivityEnabled(NO);
}
// The whole look changes hands at launch, so the switch asks for the restart straight away rather than
@@ -36,7 +34,25 @@ static void offerRestart(BOOL on) {
[SGTopController() presentViewController:alert animated:YES completion:nil];
}
+// Below iOS 26 the row is not a switch: Liquid Glass is the redesign, and the system draws it from
+// that version on, so the row reads out what is missing and the card carries the native look's rows alone.
+static SGModRow *unavailableRow(void) {
+ SGModRow *row = SGStatActionRow(@"Redesigned UI", nil, ^NSString *{ return @"Needs iOS 26"; }, ^{
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Redesigned UI"
+ message:[NSString stringWithFormat:@"The redesign is built on Liquid Glass, which iOS 26 draws and no earlier version can. This phone runs iOS %@, so the mod gives you its legacy look instead: Spotify's own screens with everything else the mod adds on them.", UIDevice.currentDevice.systemVersion]
+ preferredStyle:UIAlertControllerStyleAlert];
+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];
+ [SGTopController() presentViewController:alert animated:YES completion:nil];
+ });
+ return SGWithSymbol(row, @"sparkles");
+}
+
SGModSection *SGAppearanceSection(void) {
+ if (!SGRedesignAvailable()) {
+ NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObject:unavailableRow()];
+ [rows addObjectsFromArray:SGNativeAppearanceRows()];
+ return SGNotedSection(@"Appearance", rows, @"Changes apply after you restart Spotify.");
+ }
SGModRow *redesign = SGOptionRow(@"Redesigned UI", nil, SGKeyRedesign);
redesign.glows = YES;
redesign.info = SGRedesignedUIInfo;
@@ -90,9 +106,9 @@ UIViewController *SGPlayerSettingsPage(void) {
[pages addObject:SGWithSymbol(SGPageRow(@"Lock screen widget", ^UIViewController *{ return SGLockScreenWidgetPage(); }), @"lock")];
[sections addObject:SGSection(nil, pages)];
if (native) [sections addObjectsFromArray:SGNativePlayerScreenSections()];
- else [sections addObjectsFromArray:SGRVibrationsSections()];
+ // Vibrations hook Spotify's own controls and its audio, so they answer under either look.
+ [sections addObjectsFromArray:SGVibrationsSections()];
- NSString *intro = native ? @"Changes apply after you restart Spotify. Gestures and Blocked artists apply straight away."
- : @"Changes apply after you restart Spotify. Gestures, Blocked artists and Vibrations apply straight away.";
+ NSString *intro = @"Changes apply after you restart Spotify. Gestures, Blocked artists and Vibrations apply straight away.";
return [[SGModPage alloc] initWithTitle:@"Player" intro:intro sections:sections footer:nil];
}
diff --git a/tweak/Sources/Core/SGPrefs.h b/tweak/Sources/Core/SGPrefs.h
index f0e2f8a1..d5b724cc 100644
--- a/tweak/Sources/Core/SGPrefs.h
+++ b/tweak/Sources/Core/SGPrefs.h
@@ -24,5 +24,10 @@ extern NSString *const SGFlagOverridePrefix;
id SGFlagOverride(NSString *key);
void SGSetFlagOverride(NSString *key, id value);
+// Moves a stored setting to another key, once: nothing happens unless `from` is set and `to` is not.
+// A feature that leaves Redesigned/ for Shared/ loses the ".redesign." from its keys this way, so the
+// switch someone already flipped is still the one they get.
+void SGMigrateKey(NSString *from, NSString *to);
+
// Quits Spotify so the hooks read the switches afresh on the next launch; the writes reach cfprefsd first.
void SGRestartSpotify(void);
diff --git a/tweak/Sources/Core/SGPrefs.m b/tweak/Sources/Core/SGPrefs.m
index 985012d0..f9d3ce93 100644
--- a/tweak/Sources/Core/SGPrefs.m
+++ b/tweak/Sources/Core/SGPrefs.m
@@ -40,6 +40,14 @@ void SGSetFlagOverride(NSString *key, id value) {
else [NSUserDefaults.standardUserDefaults removeObjectForKey:key];
}
+void SGMigrateKey(NSString *from, NSString *to) {
+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;
+ id value = [store objectForKey:from];
+ if (!value || [store objectForKey:to]) return;
+ [store setObject:value forKey:to];
+ [store removeObjectForKey:from];
+}
+
void SGRestartSpotify(void) {
[NSUserDefaults.standardUserDefaults synchronize];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ exit(0); });
diff --git a/tweak/Sources/Core/SGUIMode.h b/tweak/Sources/Core/SGUIMode.h
index 94a5a938..be6801ed 100644
--- a/tweak/Sources/Core/SGUIMode.h
+++ b/tweak/Sources/Core/SGUIMode.h
@@ -11,6 +11,14 @@
#define SGKeyRedesign @"spotifyglass.redesign"
+// The redesign is Liquid Glass, and Liquid Glass is UIGlassEffect, which the system renders and which
+// no older OS can be given. Below iOS 26 the glass calls in Core/SGGlass.m and Redesigned/Kit/SGRGlass.m
+// fall back to a blur, so the redesign does not refuse to run, it runs untested against an older UIKit
+// and hangs its layout (issue #37, iOS 17: a scene-update watchdog). So it is offered only where its
+// material exists, and below that the native look is the whole mod. Everything this answers NO to
+// leaves the switch, the tour's card and the redesign's settings pages out, whatever is stored.
+BOOL SGRedesignAvailable(void);
+
BOOL SGRedesignedUI(void);
BOOL SGNativeUI(void);
// The stored switch rather than the launch's, for settings pages opened after it was flipped: they
diff --git a/tweak/Sources/Core/SGUIMode.m b/tweak/Sources/Core/SGUIMode.m
index 9450ea76..ffa2bc3a 100644
--- a/tweak/Sources/Core/SGUIMode.m
+++ b/tweak/Sources/Core/SGUIMode.m
@@ -2,12 +2,17 @@
#import "SGLog.h"
#import "SGPrefs.h"
+BOOL SGRedesignAvailable(void) {
+ if (@available(iOS 26.0, *)) return YES;
+ return NO;
+}
+
BOOL SGRedesignedUI(void) {
static BOOL on;
static dispatch_once_t once;
dispatch_once(&once, ^{
- on = SGFlag(SGKeyRedesign, NO);
- SGLog(@"ui: %@", on ? @"redesigned" : @"native");
+ on = SGRedesignedUIStored();
+ SGLog(@"ui: %@%@", on ? @"redesigned" : @"native", SGRedesignAvailable() ? @"" : @" (the redesign needs iOS 26)");
});
return on;
}
@@ -17,5 +22,7 @@ BOOL SGNativeUI(void) {
}
BOOL SGRedesignedUIStored(void) {
- return SGFlag(SGKeyRedesign, NO);
+ // The stored switch is left alone rather than turned off: a phone updated to iOS 26 gets the
+ // redesign it was last asked for back.
+ return SGRedesignAvailable() && SGFlag(SGKeyRedesign, NO);
}
diff --git a/tweak/Sources/Redesigned/Haptics/Haptics.h b/tweak/Sources/Redesigned/Haptics/Haptics.h
deleted file mode 100644
index 493d296a..00000000
--- a/tweak/Sources/Redesigned/Haptics/Haptics.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Vibrations, the redesign's haptics (Mod Settings > Player > Vibrations): the Taptic Engine answering
-// what a finger does to playback (Controls), and playing along with the music (Music Haptics).
-//
-// SGRFeedback.m which tap each kind of control gets, played while Controls is on
-// ControlHaptics.x the player's and the now playing bar's controls, the scrubber, the cover swipes, the gestures
-// MusicHaptics.x Spotify's audio output listened to, and Core Haptics played along with it
-// SGRMusicAnalyzer.m the listening: taps and a rumble out of the samples
-// HapticsSettings.m the Vibrations cards, with each switch's strength and what Music Haptics follows
-//
-// Everything on them applies at once, without a restart. The lyrics page's tap to seek plays its feedback
-// from Redesigned/Lyrics/SGRKaraokeView.m.
-// Threading: main thread only.
-#import <UIKit/UIKit.h>
-
-#define SGRKeyControlHaptics @"spotifyglass.redesign.haptics.controls"
-#define SGRKeyMusicHaptics @"spotifyglass.redesign.haptics.music"
-// How hard the taps are, a percentage within the range below; 100 is the feel each shipped with.
-#define SGRKeyControlStrength @"spotifyglass.redesign.haptics.controls.strength"
-#define SGRKeyMusicStrength @"spotifyglass.redesign.haptics.music.strength"
-// What Music Haptics plays along with, an SGRMusicFollows.
-#define SGRKeyMusicFollows @"spotifyglass.redesign.haptics.music.follows"
-
-// Controls go softer only: most of their taps are UIKit's at full intensity already. Music Haptics goes
-// either way: at 200% the rumble reaches 0.7 of the Taptic Engine's most, and most taps their most.
-enum {
- SGRControlStrengthMin = 10, SGRControlStrengthMax = 100,
- SGRMusicStrengthMin = 20, SGRMusicStrengthMax = 200,
- SGRStrengthStep = 10,
-};
-
-typedef NS_ENUM(NSInteger, SGRMusicFollows) {
- SGRMusicFollowsEverything, // a tap on each kick and snare, and the rumble under the bass
- SGRMusicFollowsBeat, // a tap on each kick and snare, no rumble
- SGRMusicFollowsBass, // a tap on each kick, and the rumble
-};
-
-typedef NS_ENUM(NSInteger, SGRFeedback) {
- SGRFeedbackPlay, // playback starts
- SGRFeedbackPause, // playback stops
- SGRFeedbackSkip, // previous, next, a jump in the song (a double tap, a lyric line)
- SGRFeedbackToggle, // shuffle, repeat
- SGRFeedbackAdd, // the add button: liked songs, a playlist
- SGRFeedbackGrab, // a finger takes the scrubber
- SGRFeedbackDetent, // the scrubber passing a tenth of the song, a cover swipe passing halfway
- SGRFeedbackEdge, // the scrubber reaching the start or the end
- SGRFeedbackRelease, // the scrubber let go
-};
-
-// Plays `feedback` while Controls is on.
-void SGRPlayFeedback(SGRFeedback feedback);
-// Wakes the Taptic Engine for feedback about to follow quickly (a finger on the scrubber).
-void SGRPrepareFeedback(SGRFeedback feedback);
-
-// From the Music Haptics switch: starts or stops listening at once.
-void SGRSetMusicHapticsEnabled(BOOL on);
-// From its strength and its choice of what to follow: reads them again, for the next tap.
-void SGRMusicHapticsSettingsChanged(void);
-
-// A strength key's percentage as a factor, 1 for 100%, kept within its range.
-double SGRHapticsStrength(NSString *key);
-SGRMusicFollows SGRMusicHapticsFollows(void);
-
-@class SGModSection;
-// The Vibrations sections of the Player page: a card for Controls and one for Music Haptics, each opening
-// out into its settings while its switch is on.
-NSArray<SGModSection *> *SGRVibrationsSections(void);
diff --git a/tweak/Sources/Redesigned/Kit/SGRBridges.h b/tweak/Sources/Redesigned/Kit/SGRBridges.h
index e4c7326c..37fa6fcf 100644
--- a/tweak/Sources/Redesigned/Kit/SGRBridges.h
+++ b/tweak/Sources/Redesigned/Kit/SGRBridges.h
@@ -1,10 +1,7 @@
// What the redesigned screens read from Spotify and ask of it, through one hook each, so no screen
// hooks the player a second time.
//
-// Player state: -[_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation player:stateDidChange:]
-// (objc-methods.txt:60654), the now playing platform's own player observer, and until that has reported,
-// an observer of the Kit's added to the first SPTEsperantoPlayer the app adds one to
-// (-[SPTEsperantoPlayer addPlayerObserver:], :35729). Installed while any screen is redesigned.
+// Player state is Shared/Player/PlayerState.h's, imported here so a redesigned screen needs one header.
// Artwork: the now playing bar's 40pt cover (trees/clean/artist/01.txt: id=SPTNowPlayingBar > Encore.ImageView >
// UIImageView 40x40), read after the bar's layout and after a track change; installed while the player
// is redesigned. Screens publish better copies of their own (the player's cover).
@@ -12,20 +9,7 @@
// Threading: everything here is main thread only; the player's reports are moved onto it.
#import <UIKit/UIKit.h>
#import "Headers/SPTPlayer.h"
-
-// A URI Spotify types as id (NSURL or NSString) as a string; nil for anything else.
-NSString *SGRURIString(id uri);
-
-#pragma mark - player state
-
-@protocol SGRPlayerStateObserver <NSObject>
-// Called when the track, the context, paused, playing, loading or shuffle changed, not for position.
-- (void)playerStateDidChange:(SPTPlayerState *)state;
-@end
-// Observers are held weakly and need no removal.
-void SGRAddPlayerStateObserver(id<SGRPlayerStateObserver> observer);
-// The last state reported, nil before the player has reported one.
-SPTPlayerState *SGRPlayerState(void);
+#import "Shared/Player/PlayerState.h"
#pragma mark - now playing artwork
diff --git a/tweak/Sources/Redesigned/Kit/SGRBridges.x b/tweak/Sources/Redesigned/Kit/SGRBridges.x
index 47c0fa21..60eb1b60 100644
--- a/tweak/Sources/Redesigned/Kit/SGRBridges.x
+++ b/tweak/Sources/Redesigned/Kit/SGRBridges.x
@@ -1,105 +1,12 @@
-// The Kit's bridges into Spotify: the player's state and the now playing artwork. Links and the
-// player's open and close are Shared's (Shared/Navigation/Links.h, Shared/Player/PlayerEvents.h).
-// SGRBridges.h names the hooks and why they are the ones.
+// The Kit's bridge into Spotify: the now playing artwork. The player's state, its open and close and
+// links are Shared's (Shared/Player/PlayerState.h, Shared/Player/PlayerEvents.h,
+// Shared/Navigation/Links.h). SGRBridges.h names the hook and why it is the one.
#import "Core/SGCore.h"
#import "Shared/Player/PlayerEvents.h"
#import "SGRBridges.h"
#import "SGRedesign.h"
#import "SGRRestyle.h"
-NSString *SGRURIString(id uri) {
- if ([uri isKindOfClass:NSString.class]) return uri;
- if ([uri isKindOfClass:NSURL.class]) return ((NSURL *)uri).absoluteString;
- return nil;
-}
-
-#pragma mark - player state
-
-static NSHashTable<id<SGRPlayerStateObserver>> *sg_stateObservers;
-static SPTPlayerState *sg_playerState;
-static NSString *sg_stateKey;
-// Set once the now playing platform has reported; the Kit's own observer on the player stands down.
-static BOOL sg_platformReported = NO;
-
-void SGRAddPlayerStateObserver(id<SGRPlayerStateObserver> observer) {
- if (!observer) return;
- if (!sg_stateObservers) sg_stateObservers = [NSHashTable weakObjectsHashTable];
- [sg_stateObservers addObject:observer];
-}
-
-SPTPlayerState *SGRPlayerState(void) {
- return sg_playerState;
-}
-
-// What an observer is told about; the state object itself is new with every position report.
-static NSString *keyOf(SPTPlayerState *state) {
- SPTPlayerOptions *options = [state respondsToSelector:@selector(options)] ? state.options : nil;
- BOOL shuffling = [options respondsToSelector:@selector(shufflingContext)] && options.shufflingContext;
- return [NSString stringWithFormat:@"%@|%@|%d%d%d%d", SGRURIString(state.track.URI), SGRURIString(state.contextURI),
- state.isPaused, state.isPlaying, [state respondsToSelector:@selector(isLoading)] && state.isLoading, shuffling];
-}
-
-static void publish(SPTPlayerState *state) {
- sg_playerState = state;
- NSString *key = keyOf(state);
- if ([key isEqualToString:sg_stateKey]) return;
- sg_stateKey = key;
- for (id<SGRPlayerStateObserver> observer in sg_stateObservers.allObjects) [observer playerStateDidChange:state];
-}
-
-static void report(id state, BOOL platform) {
- if (![state isKindOfClass:objc_getClass("SPTPlayerState")]) return;
- dispatch_block_t apply = ^{
- if (platform) sg_platformReported = YES;
- else if (sg_platformReported) return;
- publish(state);
- };
- if (NSThread.isMainThread) apply();
- else dispatch_async(dispatch_get_main_queue(), apply);
-}
-
-@interface SGRPlayerObserver : NSObject
-@end
-
-@implementation SGRPlayerObserver
-- (void)player:(id)player stateDidChange:(id)state {
- report(state, NO);
-}
-@end
-
-static SGRPlayerObserver *sg_kitObserver;
-
-%group SGRPlayerStateHooks
-%hook _TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation
-- (void)player:(id)player stateDidChange:(id)state {
- %orig;
- static dispatch_once_t once;
- dispatch_once(&once, ^{
- SGLog(@"redesign kit: player state from %@, a %@, on the main thread %d", [player class], [state class], NSThread.isMainThread);
- });
- report(state, YES);
-}
-%end
-
-// Observers are added from several threads as the app starts; the first player seen is the one
-// watched, the way KaraokeSource.x takes the first player the app asks.
-%hook SPTEsperantoPlayer
-- (void)addPlayerObserver:(id)observer {
- %orig;
- id player = self;
- static dispatch_once_t once;
- dispatch_once(&once, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- sg_kitObserver = [SGRPlayerObserver new];
- [(id<SPTPlayer>)player addPlayerObserver:sg_kitObserver];
- id state = [player respondsToSelector:@selector(state)] ? [(id<SPTPlayer>)player state] : nil;
- if (state) report(state, NO);
- });
- });
-}
-%end
-%end
-
#pragma mark - now playing artwork
NSNotificationName const SGRNowPlayingArtworkDidChangeNotification = @"spotifyglass.redesign.nowPlayingArtworkDidChange";
@@ -145,7 +52,7 @@ static void publishBarArtwork(void) {
if ([sub isKindOfClass:UIImageView.class]) cover = (UIImageView *)sub;
}
UIImage *image = cover.image;
- NSString *uri = SGRURIString(SGRPlayerState().track.URI);
+ NSString *uri = SGURIString(SGPlayerState().track.URI);
if (!image || !uri) return;
if (image != sg_barImage) {
sg_barImage = image;
@@ -157,7 +64,7 @@ static void publishBarArtwork(void) {
// The bar sets its picture when the image has loaded, which lays nothing out, so a track change looks
// again a few times while the picture comes in.
-@interface SGRBarArtworkWatcher : NSObject <SGRPlayerStateObserver>
+@interface SGRBarArtworkWatcher : NSObject <SGPlayerStateObserver>
@end
@implementation SGRBarArtworkWatcher {
@@ -165,7 +72,7 @@ static void publishBarArtwork(void) {
}
- (void)playerStateDidChange:(SPTPlayerState *)state {
- NSString *track = SGRURIString(state.track.URI);
+ NSString *track = SGURIString(state.track.URI);
if (!track || [track isEqualToString:_track]) return;
// The first track of the launch has no last cover to mistake for its own.
if (_track) sg_trackChangedAt = CACurrentMediaTime();
@@ -236,10 +143,8 @@ void SGRObservePlayerTransition(id owner, void (^began)(id owner), void (^ended)
%ctor {
if (!SGRedesignedUI()) return;
- %init(SGRPlayerStateHooks);
- SGRequireClasses(@[@"_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation", @"SPTEsperantoPlayer", @"SPTPlayerState"]);
sg_barWatcher = [SGRBarArtworkWatcher new];
- SGRAddPlayerStateObserver(sg_barWatcher);
+ SGAddPlayerStateObserver(sg_barWatcher);
%init(SGRBarArtworkHooks);
SGRequireClasses(@[@"_TtC18NowPlaying_BarImpl27NowPlayingBarViewController"]);
}
diff --git a/tweak/Sources/Redesigned/LiveActivity/LiveActivitySettings.m b/tweak/Sources/Redesigned/LiveActivity/LiveActivitySettings.m
deleted file mode 100644
index fced0c03..00000000
--- a/tweak/Sources/Redesigned/LiveActivity/LiveActivitySettings.m
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Live Activity page, in the redesign only (App/ModSettings.x links it from the root).
-#import "Core/SGCore.h"
-#import "Settings/SGModPage.h"
-#import "LiveActivity.h"
-
-static NSArray<NSString *> *viewNames(void) {
- return @[@"Lyrics", @"Queue", @"Control menu"];
-}
-
-UIViewController *SGRLiveActivitySettingsPage(void) {
- SGModRow *on = SGOptionRow(@"Live Activity", @"On the lock screen and in the Dynamic Island", SGRKeyLiveActivity);
- on.changed = ^(BOOL value) { SGRSetLiveActivityEnabled(value); };
- SGModRow *view = SGChoiceRow(@"Shows", nil, SGRKeyLiveActivityView, viewNames(), SGRLiveActivityLyrics);
- return [[SGModPage alloc] initWithTitle:@"Live Activity" intro:nil sections:@[
- SGSection(nil, @[on, view]),
- ] footer:nil];
-}
-
-NSString *SGRLiveActivitySummary(void) {
- if (!SGFlag(SGRKeyLiveActivity, NO)) return @"Off";
- NSInteger index = SGInt(SGRKeyLiveActivityView, SGRLiveActivityLyrics);
- NSArray<NSString *> *names = viewNames();
- return index >= 0 && index < (NSInteger)names.count ? names[index] : names.firstObject;
-}
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
index 24a8602b..a4100a0d 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
@@ -7,7 +7,7 @@
#import "LyricsText.h"
#import "Shared/LyricsSources/LyricsSources.h"
#import "Shared/Player/PlayerEvents.h"
-#import "Redesigned/Haptics/Haptics.h"
+#import "Shared/Haptics/Haptics.h"
#import "Redesigned/Kit/SGRTokens.h"
static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;
@@ -992,7 +992,7 @@ typedef struct {
for (SGRKaraokeLineView *view in _shown.allValues) {
if (!CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), point)) continue;
SGKaraokeSeek(view.line.start);
- SGRPlayFeedback(SGRFeedbackSkip);
+ SGPlayFeedback(SGFeedbackSkip);
[self followSong];
return;
}
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index 309973d3..9cd8dc3b 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -15,9 +15,9 @@
// PlayerLyrics.x the lyrics in the player: the cover as a thumbnail, the title up beside it
// PlayerGestures.x the gestures' hookup
// PlayerMorph.x the open and close grown out of the now playing bar's card, the cover flown
-// PlayerMenu.x Speed and pitch, an expandable row with two sliders in the more button's menu
-// PlayerSpeedPitch.x speed and pitch done to Spotify's audio, between its mixer and its speaker unit
-// SGRTimePitch.m Apple's time and pitch unit, pulling the mixer or working in place
+//
+// Speed and pitch, once the redesign's own, are Shared/Player/SpeedPitch.h's; PlayerHeader.x still hands
+// the more button over, so a menu opened from it is taken for the player's.
//
// Every hook installs only while Redesigned UI is on (SGRedesignedUI); the native look's do not then.
// Threading: main thread only.
@@ -54,22 +54,6 @@ void SGRPlayerToggleLyrics(void);
// (PlayerFooter.x). It returns at once when nothing changed.
void SGRPlayerLyricsChanged(void);
-#pragma mark - the more menu's speed and pitch (PlayerMenu.x, PlayerSpeedPitch.x)
-
-// Marks a menu opened soon after a tap on `button`, the player's more button, as the player's, so it gets
-// Speed and pitch (PlayerHeader.x hands it over; watching it twice does nothing).
-void SGRPlayerMenuWatchMoreButton(UIView *button);
-// The speed Spotify's sound plays at, 1 when normal; lasts until Spotify quits.
-double SGRPlayerSpeed(void);
-// Whether speed can apply: Spotify's output was taken over when it wired it.
-BOOL SGRPlayerSpeedAllowed(void);
-void SGRSetPlayerSpeed(double speed);
-// Semitones Spotify's output is moved by, 0 when it is not; lasts until Spotify quits.
-float SGRPlayerPitch(void);
-void SGRSetPlayerPitch(float semitones);
-// Whether the output could be reached to change its pitch.
-BOOL SGRPlayerPitchAvailable(void);
-
// Alpha 0, no touches, hidden from accessibility, set again on every call: for Spotify's Swift views,
// which SGRSuppress cannot keep (PlayerControls.x).
void SGRPlayerVanish(UIView *view);
diff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
index c3694807..b21ff536 100644
--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x
+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
@@ -25,7 +25,7 @@ static NSHashTable<UIView *> *sg_tilts;
static NSMapTable<UIView *, UIView *> *sg_covers;
static CGFloat currentScale(void) {
- SPTPlayerState *state = SGRPlayerState();
+ SPTPlayerState *state = SGPlayerState();
if (!state.isPaused || SGRPlayerIsTransitioning()) return 1;
return SGRReduceMotion() ? kPausedScaleReduceMotion : kPausedScale;
}
@@ -171,7 +171,7 @@ static void scaleEveryCover(BOOL animated) {
}
%end
-@interface SGRPlayerArtworkWatcher : NSObject <SGRPlayerStateObserver>
+@interface SGRPlayerArtworkWatcher : NSObject <SGPlayerStateObserver>
@end
@implementation SGRPlayerArtworkWatcher {
@@ -203,7 +203,7 @@ static SGRPlayerArtworkWatcher *sg_artworkWatcher;
sg_tilts = [NSHashTable weakObjectsHashTable];
sg_covers = [NSMapTable weakToWeakObjectsMapTable];
sg_artworkWatcher = [SGRPlayerArtworkWatcher new];
- SGRAddPlayerStateObserver(sg_artworkWatcher);
+ SGAddPlayerStateObserver(sg_artworkWatcher);
SGRObservePlayerTransition(sg_artworkWatcher, ^(id owner) {
scaleEveryCover(YES);
}, ^(id owner) {
diff --git a/tweak/Sources/Redesigned/Player/PlayerControls.x b/tweak/Sources/Redesigned/Player/PlayerControls.x
index 5d5552c7..86088f10 100644
--- a/tweak/Sources/Redesigned/Player/PlayerControls.x
+++ b/tweak/Sources/Redesigned/Player/PlayerControls.x
@@ -107,7 +107,7 @@ static NSString *symbolFor(BOOL paused) {
static void refreshPlayGlyph(BOOL animated) {
SGRGlyphView *glyph = sg_playGlyph;
- SPTPlayerState *state = SGRPlayerState();
+ SPTPlayerState *state = SGPlayerState();
if (!glyph || !state) return;
glyph.alpha = spinnerShowing(sg_playButton) ? 0 : 1;
CFTimeInterval now = CACurrentMediaTime();
@@ -137,7 +137,7 @@ static void playGlyph(UIView *host) {
return;
}
// Before the player has reported a state the glyph could only guess, so the disc stays.
- SPTPlayerState *state = SGRPlayerState();
+ SPTPlayerState *state = SGPlayerState();
if (!state) return;
UIButton *button = nil;
for (UIView *sub in play.subviews) {
@@ -186,7 +186,7 @@ static void playGlyph(UIView *host) {
}
%end
-@interface SGRPlayerControlsWatcher : NSObject <SGRPlayerStateObserver>
+@interface SGRPlayerControlsWatcher : NSObject <SGPlayerStateObserver>
@end
@implementation SGRPlayerControlsWatcher
@@ -246,7 +246,7 @@ static UILabel *monospaced(UIView *host, NSString *identifier, const void *findK
if (!SGRedesignedUI()) return;
%init;
sg_controlsWatcher = [SGRPlayerControlsWatcher new];
- SGRAddPlayerStateObserver(sg_controlsWatcher);
+ SGAddPlayerStateObserver(sg_controlsWatcher);
SGRequireClasses(@[
@"_TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit",
@"_TtC20NowPlaying_ModesImpl19DurationElementUnit",
diff --git a/tweak/Sources/Redesigned/Player/PlayerField.x b/tweak/Sources/Redesigned/Player/PlayerField.x
index 68f35827..70d1fc57 100644
--- a/tweak/Sources/Redesigned/Player/PlayerField.x
+++ b/tweak/Sources/Redesigned/Player/PlayerField.x
@@ -108,7 +108,7 @@ static UIImage *settledCover(UIScrollView *list) {
static void publishCover(void) {
UIImage *cover = settledCover(sg_coverList);
if (!cover) return;
- NSString *uri = SGRURIString(SGRPlayerState().track.URI);
+ NSString *uri = SGURIString(SGPlayerState().track.URI);
if (!uri || (cover == sg_lastCover && [uri isEqualToString:sg_lastCoverURI])) return;
sg_lastCover = cover;
sg_lastCoverURI = uri;
@@ -127,7 +127,7 @@ static void publishCover(void) {
// A cover that loads after the track changed sets an image and lays nothing out, so the list is looked
// at again a few times while it comes in, as the Kit does for the bar.
-@interface SGRPlayerCoverWatcher : NSObject <SGRPlayerStateObserver>
+@interface SGRPlayerCoverWatcher : NSObject <SGPlayerStateObserver>
@end
@implementation SGRPlayerCoverWatcher {
@@ -135,7 +135,7 @@ static void publishCover(void) {
}
- (void)playerStateDidChange:(SPTPlayerState *)state {
- NSString *track = SGRURIString(state.track.URI);
+ NSString *track = SGURIString(state.track.URI);
if (!track || [track isEqualToString:_track]) return;
_track = track;
for (NSNumber *delay in @[@0.3, @1, @2.5]) {
@@ -173,7 +173,7 @@ static SGRPlayerCoverWatcher *sg_coverWatcher;
if (!SGRedesignedUI()) return;
%init;
sg_coverWatcher = [SGRPlayerCoverWatcher new];
- SGRAddPlayerStateObserver(sg_coverWatcher);
+ SGAddPlayerStateObserver(sg_coverWatcher);
[NSNotificationCenter.defaultCenter addObserverForName:SGRNowPlayingArtworkDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
showArtwork(sg_field, YES);
}];
diff --git a/tweak/Sources/Redesigned/Player/PlayerHeader.x b/tweak/Sources/Redesigned/Player/PlayerHeader.x
index d163c857..4596a8f7 100644
--- a/tweak/Sources/Redesigned/Player/PlayerHeader.x
+++ b/tweak/Sources/Redesigned/Player/PlayerHeader.x
@@ -18,6 +18,7 @@
// between them.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
+#import "Shared/Player/SpeedPitch.h"
#import "Player.h"
static char kGlassKey, kCloseKey, kMoreKey;
@@ -38,7 +39,7 @@ static void glassInside(UIViewController *unit, NSArray<NSString *> *identifiers
continue;
}
SGRGlassInside(button, &kGlassKey, SGRGlassCircleSize);
- if ([identifiers[i] isEqualToString:@"Context menu"]) SGRPlayerMenuWatchMoreButton(button);
+ if ([identifiers[i] isEqualToString:@"Context menu"]) SGPlayerMenuWatchMoreButton(button);
found++;
}
diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.x
index 2de4571f..2a6f15be 100644
--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x
+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x
@@ -442,7 +442,7 @@ static void replace(void) {
#pragma mark - the track changing under them
-@interface SGRPlayerLyricsWatcher : NSObject <SGRPlayerStateObserver>
+@interface SGRPlayerLyricsWatcher : NSObject <SGPlayerStateObserver>
@end
@implementation SGRPlayerLyricsWatcher {
@@ -450,7 +450,7 @@ static void replace(void) {
}
- (void)playerStateDidChange:(SPTPlayerState *)state {
- NSString *track = SGRURIString(state.track.URI);
+ NSString *track = SGURIString(state.track.URI);
if (!track || [track isEqualToString:_track]) return;
_track = track;
// Lyrics arrive a moment after the track does, and nothing announces them: the glyph is asked again
@@ -474,7 +474,7 @@ static SGRPlayerLyricsWatcher *sg_watcher;
if (!SGRedesignedUI()) return;
%init;
sg_watcher = [SGRPlayerLyricsWatcher new];
- SGRAddPlayerStateObserver(sg_watcher);
+ SGAddPlayerStateObserver(sg_watcher);
[NSNotificationCenter.defaultCenter addObserverForName:SGRNowPlayingArtworkDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
if (!sg_open) return;
SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(sg_host, &kOverlayKey);
diff --git a/tweak/Sources/Redesigned/Haptics/ControlHaptics.x b/tweak/Sources/Shared/Haptics/ControlHaptics.x
similarity index 88%
rename from tweak/Sources/Redesigned/Haptics/ControlHaptics.x
rename to tweak/Sources/Shared/Haptics/ControlHaptics.x
index c12f9e48..09562574 100644
--- a/tweak/Sources/Redesigned/Haptics/ControlHaptics.x
+++ b/tweak/Sources/Shared/Haptics/ControlHaptics.x
@@ -1,5 +1,5 @@
// Vibrations > Controls: a tap for what a finger does to playback, in the full screen player and the
-// now playing bar (SGRFeedback.m holds which tap each gets).
+// now playing bar (SGFeedback.m holds which tap each gets).
//
// Buttons: every control's action passes -[UIControl sendAction:to:forEvent:] (target and action) or
// -[UIControl sendAction:] (a UIAction), so the controls are told apart there by accessibility
@@ -23,8 +23,8 @@
// Gestures (Shared/Gestures) tell of each action a double tap performs; the lyrics page's tap to seek
// plays its tap in Redesigned/Lyrics/SGRKaraokeView.m.
#import "Core/SGCore.h"
-#import "Redesigned/Kit/SGRKit.h"
#import "Shared/Gestures/Gestures.h"
+#import "Shared/Player/PlayerState.h"
#import "Haptics.h"
// How close to either end the scrubber is at it.
@@ -84,10 +84,10 @@ static void controlActed(UIControl *control, ControlKind kind, BOOL wasPaused) {
lastTime = now;
switch (kind) {
case ControlNone: return;
- case ControlPlay: SGRPlayFeedback(wasPaused ? SGRFeedbackPlay : SGRFeedbackPause); break;
- case ControlSkip: SGRPlayFeedback(SGRFeedbackSkip); break;
- case ControlToggle: SGRPlayFeedback(SGRFeedbackToggle); break;
- case ControlAdd: SGRPlayFeedback(SGRFeedbackAdd); break;
+ case ControlPlay: SGPlayFeedback(wasPaused ? SGFeedbackPlay : SGFeedbackPause); break;
+ case ControlSkip: SGPlayFeedback(SGFeedbackSkip); break;
+ case ControlToggle: SGPlayFeedback(SGFeedbackToggle); break;
+ case ControlAdd: SGPlayFeedback(SGFeedbackAdd); break;
}
static NSMutableSet<NSNumber *> *logged;
if (!logged) logged = [NSMutableSet set];
@@ -103,7 +103,7 @@ static void controlActed(UIControl *control, ControlKind kind, BOOL wasPaused) {
%orig;
return;
}
- BOOL wasPaused = SGRPlayerState().isPaused;
+ BOOL wasPaused = SGPlayerState().isPaused;
%orig;
controlActed(self, kind, wasPaused);
}
@@ -114,7 +114,7 @@ static void controlActed(UIControl *control, ControlKind kind, BOOL wasPaused) {
%orig;
return;
}
- BOOL wasPaused = SGRPlayerState().isPaused;
+ BOOL wasPaused = SGPlayerState().isPaused;
%orig;
controlActed(self, kind, wasPaused);
}
@@ -140,15 +140,15 @@ static void scrubBegan(UISlider *slider) {
sg_scrubTenth = (int)floor(MIN(position, 0.9999f) * 10);
sg_scrubAtEdge = atEdge(position);
sg_scrubTicks = 0;
- SGRPlayFeedback(SGRFeedbackGrab);
- SGRPrepareFeedback(SGRFeedbackDetent);
+ SGPlayFeedback(SGFeedbackGrab);
+ SGPrepareFeedback(SGFeedbackDetent);
}
static void scrubMoved(UISlider *slider) {
float position = positionOf(slider);
BOOL edge = atEdge(position);
if (edge) {
- if (!sg_scrubAtEdge) SGRPlayFeedback(SGRFeedbackEdge);
+ if (!sg_scrubAtEdge) SGPlayFeedback(SGFeedbackEdge);
sg_scrubAtEdge = YES;
sg_scrubTenth = (int)floor(MIN(position, 0.9999f) * 10);
return;
@@ -160,7 +160,7 @@ static void scrubMoved(UISlider *slider) {
if (fabsf(position - boundary) < kScrubHysteresis) return;
sg_scrubTenth = tenth;
sg_scrubTicks++;
- SGRPlayFeedback(SGRFeedbackDetent);
+ SGPlayFeedback(SGFeedbackDetent);
}
%hook _TtCO17NowPlaying_ECMKit11ProgressBar6Slider
@@ -178,7 +178,7 @@ static void scrubMoved(UISlider *slider) {
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
%orig;
- SGRPlayFeedback(SGRFeedbackRelease);
+ SGPlayFeedback(SGFeedbackRelease);
static NSUInteger logged;
if (logged++ < 3) SGLog(@"redesign haptics: scrubbed to %.2f of the song, %lu ticks", positionOf((UISlider *)self), (unsigned long)sg_scrubTicks);
}
@@ -197,7 +197,7 @@ static void pageDetent(UIScrollView *list, NSInteger *lastPage) {
}
if (page == *lastPage || fabs(position - *lastPage) < 0.5 + kPageHysteresis) return;
*lastPage = page;
- SGRPlayFeedback(SGRFeedbackDetent);
+ SGPlayFeedback(SGFeedbackDetent);
}
%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView
@@ -221,18 +221,19 @@ static void pageDetent(UIScrollView *list, NSInteger *lastPage) {
static void gesturePerformed(SGGestureAction action) {
switch (action) {
case SGGestureNothing: break;
- case SGGesturePlayPause: SGRPlayFeedback(SGRPlayerState().isPaused ? SGRFeedbackPlay : SGRFeedbackPause); break;
+ case SGGesturePlayPause: SGPlayFeedback(SGPlayerState().isPaused ? SGFeedbackPlay : SGFeedbackPause); break;
case SGGestureSeekBack:
case SGGestureSeekForward:
case SGGestureNextTrack:
- case SGGesturePreviousTrack: SGRPlayFeedback(SGRFeedbackSkip); break;
+ case SGGesturePreviousTrack: SGPlayFeedback(SGFeedbackSkip); break;
case SGGestureShuffle:
- case SGGestureRepeat: SGRPlayFeedback(SGRFeedbackToggle); break;
+ case SGGestureRepeat: SGPlayFeedback(SGFeedbackToggle); break;
}
}
%ctor {
- if (!SGRedesignedUI()) return;
+ SGMigrateKey(SGKeyControlHapticsWas, SGKeyControlHaptics);
+ SGMigrateKey(SGKeyControlStrengthWas, SGKeyControlStrength);
%init;
SGGestureSetObserver(^(SGGestureAction action) { gesturePerformed(action); });
SGRequireClasses(@[
diff --git a/tweak/Sources/Shared/Haptics/Haptics.h b/tweak/Sources/Shared/Haptics/Haptics.h
new file mode 100644
index 00000000..883265b4
--- /dev/null
+++ b/tweak/Sources/Shared/Haptics/Haptics.h
@@ -0,0 +1,74 @@
+// Vibrations (Mod Settings > Player > Vibrations), under either look: the Taptic Engine answering
+// what a finger does to playback (Controls), and playing along with the music (Music Haptics).
+//
+// SGFeedback.m which tap each kind of control gets, played while Controls is on
+// ControlHaptics.x the player's and the now playing bar's controls, the scrubber, the cover swipes, the gestures
+// MusicHaptics.x Spotify's audio output listened to, and Core Haptics played along with it
+// SGMusicAnalyzer.m the listening: taps and a rumble out of the samples
+// HapticsSettings.m the Vibrations cards, with each switch's strength and what Music Haptics follows
+//
+// Everything on them applies at once, without a restart. Everything hooked is Spotify's own (its controls
+// by accessibility identifier, its scrubber, its cover and title lists, its audio unit), so all of it works
+// on Spotify's own screens and on the redesign's alike. The redesigned lyrics page's tap to seek plays its
+// feedback from Redesigned/Lyrics/SGRKaraokeView.m.
+// Threading: main thread only.
+#import <UIKit/UIKit.h>
+
+#define SGKeyControlHaptics @"spotifyglass.haptics.controls"
+#define SGKeyMusicHaptics @"spotifyglass.haptics.music"
+// How hard the taps are, a percentage within the range below; 100 is the feel each shipped with.
+#define SGKeyControlStrength @"spotifyglass.haptics.controls.strength"
+#define SGKeyMusicStrength @"spotifyglass.haptics.music.strength"
+// What Music Haptics plays along with, an SGMusicFollows.
+#define SGKeyMusicFollows @"spotifyglass.haptics.music.follows"
+// What the keys were called while this was the redesign's alone; the %ctors move them over.
+#define SGKeyControlHapticsWas @"spotifyglass.redesign.haptics.controls"
+#define SGKeyMusicHapticsWas @"spotifyglass.redesign.haptics.music"
+#define SGKeyControlStrengthWas @"spotifyglass.redesign.haptics.controls.strength"
+#define SGKeyMusicStrengthWas @"spotifyglass.redesign.haptics.music.strength"
+#define SGKeyMusicFollowsWas @"spotifyglass.redesign.haptics.music.follows"
+
+// Controls go softer only: most of their taps are UIKit's at full intensity already. Music Haptics goes
+// either way: at 200% the rumble reaches 0.7 of the Taptic Engine's most, and most taps their most.
+enum {
+ SGControlStrengthMin = 10, SGControlStrengthMax = 100,
+ SGMusicStrengthMin = 20, SGMusicStrengthMax = 200,
+ SGStrengthStep = 10,
+};
+
+typedef NS_ENUM(NSInteger, SGMusicFollows) {
+ SGMusicFollowsEverything, // a tap on each kick and snare, and the rumble under the bass
+ SGMusicFollowsBeat, // a tap on each kick and snare, no rumble
+ SGMusicFollowsBass, // a tap on each kick, and the rumble
+};
+
+typedef NS_ENUM(NSInteger, SGFeedback) {
+ SGFeedbackPlay, // playback starts
+ SGFeedbackPause, // playback stops
+ SGFeedbackSkip, // previous, next, a jump in the song (a double tap, a lyric line)
+ SGFeedbackToggle, // shuffle, repeat
+ SGFeedbackAdd, // the add button: liked songs, a playlist
+ SGFeedbackGrab, // a finger takes the scrubber
+ SGFeedbackDetent, // the scrubber passing a tenth of the song, a cover swipe passing halfway
+ SGFeedbackEdge, // the scrubber reaching the start or the end
+ SGFeedbackRelease, // the scrubber let go
+};
+
+// Plays `feedback` while Controls is on.
+void SGPlayFeedback(SGFeedback feedback);
+// Wakes the Taptic Engine for feedback about to follow quickly (a finger on the scrubber).
+void SGPrepareFeedback(SGFeedback feedback);
+
+// From the Music Haptics switch: starts or stops listening at once.
+void SGSetMusicHapticsEnabled(BOOL on);
+// From its strength and its choice of what to follow: reads them again, for the next tap.
+void SGMusicHapticsSettingsChanged(void);
+
+// A strength key's percentage as a factor, 1 for 100%, kept within its range.
+double SGHapticsStrength(NSString *key);
+SGMusicFollows SGMusicHapticsFollows(void);
+
+@class SGModSection;
+// The Vibrations sections of the Player page: a card for Controls and one for Music Haptics, each opening
+// out into its settings while its switch is on.
+NSArray<SGModSection *> *SGVibrationsSections(void);
diff --git a/tweak/Sources/Redesigned/Haptics/HapticsSettings.m b/tweak/Sources/Shared/Haptics/HapticsSettings.m
similarity index 61%
rename from tweak/Sources/Redesigned/Haptics/HapticsSettings.m
rename to tweak/Sources/Shared/Haptics/HapticsSettings.m
index 2a8a3693..9a301200 100644
--- a/tweak/Sources/Redesigned/Haptics/HapticsSettings.m
+++ b/tweak/Sources/Shared/Haptics/HapticsSettings.m
@@ -1,4 +1,4 @@
-// The Vibrations sections of the Player page, in the redesign only (App/Pages.m puts them there): a card
+// The Vibrations sections of the Player page, under either look (App/Pages.m puts them there): a card
// per switch, the way the Audio effects page has one per effect, each opening out into its settings while
// its switch is on. Controls has its strength; Music Haptics its strength and what it follows, a choice
// that also says whether the rumble plays, rather than a switch of its own that one choice would leave
@@ -20,28 +20,28 @@ static NSArray<NSString *> *followsNotes(void) {
}
static void strengthRange(NSString *key, NSInteger *minimum, NSInteger *maximum) {
- BOOL music = [key isEqualToString:SGRKeyMusicStrength];
- *minimum = music ? SGRMusicStrengthMin : SGRControlStrengthMin;
- *maximum = music ? SGRMusicStrengthMax : SGRControlStrengthMax;
+ BOOL music = [key isEqualToString:SGKeyMusicStrength];
+ *minimum = music ? SGMusicStrengthMin : SGControlStrengthMin;
+ *maximum = music ? SGMusicStrengthMax : SGControlStrengthMax;
}
-double SGRHapticsStrength(NSString *key) {
+double SGHapticsStrength(NSString *key) {
NSInteger minimum, maximum;
strengthRange(key, &minimum, &maximum);
return MAX(minimum, MIN(maximum, SGInt(key, 100))) / 100.0;
}
-SGRMusicFollows SGRMusicHapticsFollows(void) {
- NSInteger follows = SGInt(SGRKeyMusicFollows, SGRMusicFollowsEverything);
- return follows >= SGRMusicFollowsEverything && follows <= SGRMusicFollowsBass ? (SGRMusicFollows)follows : SGRMusicFollowsEverything;
+SGMusicFollows SGMusicHapticsFollows(void) {
+ NSInteger follows = SGInt(SGKeyMusicFollows, SGMusicFollowsEverything);
+ return follows >= SGMusicFollowsEverything && follows <= SGMusicFollowsBass ? (SGMusicFollows)follows : SGMusicFollowsEverything;
}
// A percentage slider over a strength key, telling `changed` each step it stores.
static SGModRow *strengthRow(NSString *key, void (^changed)(void)) {
NSInteger minimum, maximum;
strengthRange(key, &minimum, &maximum);
- return SGSliderRow(@"Strength", nil, minimum, maximum, SGRStrengthStep,
- ^double { return SGRHapticsStrength(key) * 100; },
+ return SGSliderRow(@"Strength", nil, minimum, maximum, SGStrengthStep,
+ ^double { return SGHapticsStrength(key) * 100; },
^(double value) {
SGSetInt(key, lround(value));
if (changed) changed();
@@ -49,23 +49,23 @@ static SGModRow *strengthRow(NSString *key, void (^changed)(void)) {
^NSString *(double value) { return [NSString stringWithFormat:@"%ld%%", lround(value)]; });
}
-NSArray<SGModSection *> *SGRVibrationsSections(void) {
- SGModRow *controls = SGSwitchRow(@"Controls", @"Play, pause, skipping, scrubbing, shuffle, repeat and adding a song", SGRKeyControlHaptics);
- SGModRow *controlStrength = strengthRow(SGRKeyControlStrength, ^{
+NSArray<SGModSection *> *SGVibrationsSections(void) {
+ SGModRow *controls = SGSwitchRow(@"Controls", @"Play, pause, skipping, scrubbing, shuffle, repeat and adding a song", SGKeyControlHaptics);
+ SGModRow *controlStrength = strengthRow(SGKeyControlStrength, ^{
// Felt as it is set: a tap at the new strength with each step.
- SGRPlayFeedback(SGRFeedbackAdd);
+ SGPlayFeedback(SGFeedbackAdd);
});
- controlStrength.visible = ^BOOL { return SGEnabled(SGRKeyControlHaptics); };
+ controlStrength.visible = ^BOOL { return SGEnabled(SGKeyControlHaptics); };
- SGModRow *music = SGOptionRow(@"Music Haptics", @"Taps and rumbles along with the music", SGRKeyMusicHaptics);
+ SGModRow *music = SGOptionRow(@"Music Haptics", @"Taps and rumbles along with the music", SGKeyMusicHaptics);
music.info = kMusicHapticsInfo;
- music.changed = ^(BOOL on) { SGRSetMusicHapticsEnabled(on); };
- BOOL (^musicOn)(void) = ^BOOL { return SGFlag(SGRKeyMusicHaptics, NO); };
- SGModRow *musicStrength = strengthRow(SGRKeyMusicStrength, ^{ SGRMusicHapticsSettingsChanged(); });
+ music.changed = ^(BOOL on) { SGSetMusicHapticsEnabled(on); };
+ BOOL (^musicOn)(void) = ^BOOL { return SGFlag(SGKeyMusicHaptics, NO); };
+ SGModRow *musicStrength = strengthRow(SGKeyMusicStrength, ^{ SGMusicHapticsSettingsChanged(); });
musicStrength.visible = musicOn;
- SGModRow *follows = SGChoiceRow(@"Follows", nil, SGRKeyMusicFollows, followsNames(), SGRMusicFollowsEverything);
+ SGModRow *follows = SGChoiceRow(@"Follows", nil, SGKeyMusicFollows, followsNames(), SGMusicFollowsEverything);
follows.choiceNotes = followsNotes();
- follows.chosen = ^(NSInteger index) { SGRMusicHapticsSettingsChanged(); };
+ follows.chosen = ^(NSInteger index) { SGMusicHapticsSettingsChanged(); };
follows.visible = musicOn;
return @[
diff --git a/tweak/Sources/Redesigned/Haptics/MusicHaptics.x b/tweak/Sources/Shared/Haptics/MusicHaptics.x
similarity index 94%
rename from tweak/Sources/Redesigned/Haptics/MusicHaptics.x
rename to tweak/Sources/Shared/Haptics/MusicHaptics.x
index 74f2a730..ba688f0a 100644
--- a/tweak/Sources/Redesigned/Haptics/MusicHaptics.x
+++ b/tweak/Sources/Shared/Haptics/MusicHaptics.x
@@ -5,7 +5,7 @@
// and a RemoteIO output unit, started with AudioOutputUnitStart(_outputUnit)), with no Objective-C
// method between it and the unit. So Spotify's import of AudioOutputUnitStart is rebound
// (Core/SGRebind.h), and every RemoteIO unit it starts gets a render notify: after each render, the
-// buffer bound for the speaker is mixed to mono and handed to the analyzer (SGRMusicAnalyzer.h) on
+// buffer bound for the speaker is mixed to mono and handed to the analyzer (SGMusicAnalyzer.h) on
// the render thread, which puts what it hears into a ring of events. That buffer is in the unit's output
// format, the hardware's, not the one Spotify hands the unit (in the simulator 48 kHz float with a buffer
// per channel, whatever the client: harness/jamesdsp/sim, harness/haptics/sim), so the analyzer runs at
@@ -17,7 +17,7 @@
// what Music Haptics follows leaves out the snares' taps (Bass) or the rumble (Beat) there too, so a change
// applies to the next event.
//
-// The rebinding and the notify are in place while Redesigned UI is on, so the switch works at once;
+// The rebinding and the notify are in place under either look, so the switch works at once;
// with the switch off the notify returns straight away. Nothing listens while Spotify is not the active
// app, since iOS plays no haptics for an app in the background. Sound that is not Spotify's own
// output (Connect, AirPlay to another device, video) never passes the unit, and plays no haptics.
@@ -35,7 +35,7 @@
#import "Core/SGCore.h"
#import "Core/SGRebind.h"
#import "Haptics.h"
-#import "SGRMusicAnalyzer.h"
+#import "SGMusicAnalyzer.h"
// Core Haptics takes about this long from a scheduled time to the Taptic Engine's peak.
static const double kHapticLead = 0.012;
@@ -72,7 +72,7 @@ static atomic_uint_fast64_t sg_skipped; // renders whose buffers were not laid
static atomic_uint_fast64_t sg_strengthBits;
static atomic_int sg_follows;
-static SGRMusicEvent sg_ring[kRingSize];
+static SGMusicEvent sg_ring[kRingSize];
static atomic_uint sg_head, sg_tail; // head moved by the render thread, tail by the player thread
static dispatch_semaphore_t sg_wake;
@@ -93,10 +93,10 @@ static double loadDouble(atomic_uint_fast64_t *slot) {
#pragma mark - the render thread
-static SGRMusicAnalyzer sg_analyzer;
+static SGMusicAnalyzer sg_analyzer;
static float sg_mono[kMonoFrames];
-static void pushEvent(const SGRMusicEvent *event, void *context) {
+static void pushEvent(const SGMusicEvent *event, void *context) {
unsigned head = atomic_load_explicit(&sg_head, memory_order_relaxed);
unsigned tail = atomic_load_explicit(&sg_tail, memory_order_relaxed);
if (head - tail >= kRingSize) return;
@@ -143,7 +143,7 @@ static OSStatus rendered(void *refCon, AudioUnitRenderActionFlags *flags, const
unsigned generation = atomic_load_explicit(&sg_generation, memory_order_relaxed);
if (sampleRate <= 0) return noErr;
if (sampleRate != analyzedRate || generation != analyzedGeneration) {
- SGRMusicAnalyzerReset(&sg_analyzer, sampleRate, 1 / sg_secondsPerTick);
+ SGMusicAnalyzerReset(&sg_analyzer, sampleRate, 1 / sg_secondsPerTick);
analyzedRate = sampleRate;
analyzedGeneration = generation;
}
@@ -162,7 +162,7 @@ static OSStatus rendered(void *refCon, AudioUnitRenderActionFlags *flags, const
sg_mono[i] = 0.5f * (sampleAt(left, at, bytes, isFloat, fraction) + sampleAt(right, at + rightOffset, bytes, isFloat, fraction));
}
uint64_t chunkTime = hostTime + (uint64_t)(done / sampleRate / sg_secondsPerTick);
- SGRMusicAnalyzerProcess(&sg_analyzer, sg_mono, count, chunkTime, pushEvent, NULL);
+ SGMusicAnalyzerProcess(&sg_analyzer, sg_mono, count, chunkTime, pushEvent, NULL);
done += count;
}
if (atomic_load_explicit(&sg_head, memory_order_relaxed) != headBefore) dispatch_semaphore_signal(sg_wake);
@@ -332,7 +332,7 @@ static CHHapticEventParameter *parameter(CHHapticEventParameterID identifier, fl
return [[CHHapticEventParameter alloc] initWithParameterID:identifier value:value];
}
-static void playTap(const SGRMusicEvent *event) {
+static void playTap(const SGMusicEvent *event) {
double lead;
NSTimeInterval at = engineTime(event->hostTime, &lead);
if (lead < -kLatestTap) {
@@ -363,7 +363,7 @@ static void stopRumble(NSTimeInterval at) {
sg_rumbling = NO;
}
-static void playLevel(const SGRMusicEvent *event) {
+static void playLevel(const SGMusicEvent *event) {
sg_stats.levels++;
double lead;
NSTimeInterval at = engineTime(event->hostTime, &lead);
@@ -453,17 +453,17 @@ static void *playerLoop(void *unused) {
idle = YES;
continue;
}
- SGRMusicFollows follows = (SGRMusicFollows)atomic_load(&sg_follows);
- BOOL rumbles = follows != SGRMusicFollowsBeat, snares = follows != SGRMusicFollowsBass;
+ SGMusicFollows follows = (SGMusicFollows)atomic_load(&sg_follows);
+ BOOL rumbles = follows != SGMusicFollowsBeat, snares = follows != SGMusicFollowsBass;
if (!rumbles) stopRumble(CHHapticTimeImmediate);
BOOL any = NO;
unsigned head = atomic_load(&sg_head), tail = atomic_load(&sg_tail);
if (tail != head && startEngine()) {
for (; tail != head; tail++) {
- SGRMusicEvent event = sg_ring[tail & (kRingSize - 1)];
- if (event.kind == SGRMusicEventLevel) {
+ SGMusicEvent event = sg_ring[tail & (kRingSize - 1)];
+ if (event.kind == SGMusicEventLevel) {
if (rumbles) playLevel(&event);
- } else if (event.kind == SGRMusicEventKick || snares) {
+ } else if (event.kind == SGMusicEventKick || snares) {
playTap(&event);
}
}
@@ -514,26 +514,28 @@ static void updateListening(void) {
dispatch_semaphore_signal(sg_wake);
}
-void SGRSetMusicHapticsEnabled(BOOL on) {
- if (!SGRedesignedUI() || !sg_wake) return;
+void SGSetMusicHapticsEnabled(BOOL on) {
+ if (!sg_wake) return;
atomic_store(&sg_enabled, on);
updateListening();
}
static void readSettings(void) {
- storeDouble(&sg_strengthBits, SGRHapticsStrength(SGRKeyMusicStrength));
- atomic_store(&sg_follows, (int)SGRMusicHapticsFollows());
+ storeDouble(&sg_strengthBits, SGHapticsStrength(SGKeyMusicStrength));
+ atomic_store(&sg_follows, (int)SGMusicHapticsFollows());
}
-void SGRMusicHapticsSettingsChanged(void) {
- if (!SGRedesignedUI() || !sg_wake) return;
+void SGMusicHapticsSettingsChanged(void) {
+ if (!sg_wake) return;
readSettings();
// A rumble that is not to play any more stops now rather than with the next event.
dispatch_semaphore_signal(sg_wake);
}
%ctor {
- if (!SGRedesignedUI()) return;
+ SGMigrateKey(SGKeyMusicHapticsWas, SGKeyMusicHaptics);
+ SGMigrateKey(SGKeyMusicStrengthWas, SGKeyMusicStrength);
+ SGMigrateKey(SGKeyMusicFollowsWas, SGKeyMusicFollows);
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
sg_secondsPerTick = (double)timebase.numer / timebase.denom / 1e9;
@@ -543,7 +545,7 @@ void SGRMusicHapticsSettingsChanged(void) {
}
sg_wake = dispatch_semaphore_create(0);
readSettings();
- atomic_store(&sg_enabled, SGFlag(SGRKeyMusicHaptics, NO));
+ atomic_store(&sg_enabled, SGFlag(SGKeyMusicHaptics, NO));
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
[center addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
atomic_store(&sg_active, true);
diff --git a/tweak/Sources/Redesigned/Haptics/SGRFeedback.m b/tweak/Sources/Shared/Haptics/SGFeedback.m
similarity index 68%
rename from tweak/Sources/Redesigned/Haptics/SGRFeedback.m
rename to tweak/Sources/Shared/Haptics/SGFeedback.m
index 53063887..6dd2e267 100644
--- a/tweak/Sources/Redesigned/Haptics/SGRFeedback.m
+++ b/tweak/Sources/Shared/Haptics/SGFeedback.m
@@ -19,24 +19,24 @@ static const NSInteger kSelection = -1;
// A rigid impact at this intensity stands in for a selection tick (a bet: UIKit gives the tick no number).
static const CGFloat kTickIntensity = 0.5;
-static Tap tapFor(SGRFeedback feedback) {
+static Tap tapFor(SGFeedback feedback) {
switch (feedback) {
- case SGRFeedbackPlay: return (Tap){UIImpactFeedbackStyleRigid, 0.8};
- case SGRFeedbackPause: return (Tap){UIImpactFeedbackStyleSoft, 1};
- case SGRFeedbackSkip: return (Tap){UIImpactFeedbackStyleLight, 1};
- case SGRFeedbackToggle: return (Tap){kSelection, 1};
- case SGRFeedbackAdd: return (Tap){UIImpactFeedbackStyleMedium, 0.8};
- case SGRFeedbackGrab: return (Tap){UIImpactFeedbackStyleLight, 0.7};
- case SGRFeedbackDetent: return (Tap){kSelection, 1};
- case SGRFeedbackEdge: return (Tap){UIImpactFeedbackStyleRigid, 0.6};
- case SGRFeedbackRelease: return (Tap){UIImpactFeedbackStyleSoft, 0.8};
+ case SGFeedbackPlay: return (Tap){UIImpactFeedbackStyleRigid, 0.8};
+ case SGFeedbackPause: return (Tap){UIImpactFeedbackStyleSoft, 1};
+ case SGFeedbackSkip: return (Tap){UIImpactFeedbackStyleLight, 1};
+ case SGFeedbackToggle: return (Tap){kSelection, 1};
+ case SGFeedbackAdd: return (Tap){UIImpactFeedbackStyleMedium, 0.8};
+ case SGFeedbackGrab: return (Tap){UIImpactFeedbackStyleLight, 0.7};
+ case SGFeedbackDetent: return (Tap){kSelection, 1};
+ case SGFeedbackEdge: return (Tap){UIImpactFeedbackStyleRigid, 0.6};
+ case SGFeedbackRelease: return (Tap){UIImpactFeedbackStyleSoft, 0.8};
}
return (Tap){kSelection, 1};
}
-static Tap tapAtStrength(SGRFeedback feedback) {
+static Tap tapAtStrength(SGFeedback feedback) {
Tap tap = tapFor(feedback);
- double strength = SGRHapticsStrength(SGRKeyControlStrength);
+ double strength = SGHapticsStrength(SGKeyControlStrength);
if (strength >= 1) return tap;
if (tap.style == kSelection) return (Tap){UIImpactFeedbackStyleRigid, kTickIntensity * strength};
return (Tap){tap.style, tap.intensity * strength};
@@ -53,15 +53,15 @@ static UIFeedbackGenerator *generatorFor(NSInteger style) {
return generator;
}
-void SGRPlayFeedback(SGRFeedback feedback) {
- if (!SGEnabled(SGRKeyControlHaptics)) return;
+void SGPlayFeedback(SGFeedback feedback) {
+ if (!SGEnabled(SGKeyControlHaptics)) return;
Tap tap = tapAtStrength(feedback);
UIFeedbackGenerator *generator = generatorFor(tap.style);
if (tap.style == kSelection) [(UISelectionFeedbackGenerator *)generator selectionChanged];
else [(UIImpactFeedbackGenerator *)generator impactOccurredWithIntensity:tap.intensity];
}
-void SGRPrepareFeedback(SGRFeedback feedback) {
- if (!SGEnabled(SGRKeyControlHaptics)) return;
+void SGPrepareFeedback(SGFeedback feedback) {
+ if (!SGEnabled(SGKeyControlHaptics)) return;
[generatorFor(tapAtStrength(feedback).style) prepare];
}
diff --git a/tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.h b/tweak/Sources/Shared/Haptics/SGMusicAnalyzer.h
similarity index 70%
rename from tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.h
rename to tweak/Sources/Shared/Haptics/SGMusicAnalyzer.h
index 1a3cfda5..80e8cb59 100644
--- a/tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.h
+++ b/tweak/Sources/Shared/Haptics/SGMusicAnalyzer.h
@@ -17,37 +17,37 @@
#import <Foundation/Foundation.h>
// A hit says which band it came from, so what Music Haptics follows (Haptics.h) can leave some out.
-typedef NS_ENUM(uint8_t, SGRMusicEventKind) {
- SGRMusicEventKick, // a hit in the bass (a kick, an 808): one transient
- SGRMusicEventSnare, // a hit in the top (a snare, a clap): one transient
- SGRMusicEventLevel, // the continuous vibration from here on, sent about 60 times a second
+typedef NS_ENUM(uint8_t, SGMusicEventKind) {
+ SGMusicEventKick, // a hit in the bass (a kick, an 808): one transient
+ SGMusicEventSnare, // a hit in the top (a snare, a clap): one transient
+ SGMusicEventLevel, // the continuous vibration from here on, sent about 60 times a second
};
typedef struct {
uint64_t hostTime; // mach absolute time of the sound, as the render timestamp gave it
float intensity; // 0...1
float sharpness; // 0...1
- SGRMusicEventKind kind;
-} SGRMusicEvent;
+ SGMusicEventKind kind;
+} SGMusicEvent;
-typedef void (*SGRMusicEmit)(const SGRMusicEvent *event, void *context);
+typedef void (*SGMusicEmit)(const SGMusicEvent *event, void *context);
-enum { SGRMusicHistoryLength = 256, SGRMusicAttackHops = 4, SGRMusicWindowHops = 4 };
+enum { SGMusicHistoryLength = 256, SGMusicAttackHops = 4, SGMusicWindowHops = 4 };
typedef struct {
double b0, b1, b2, a1, a2;
double z1, z2;
-} SGRMusicBiquad;
+} SGMusicBiquad;
typedef struct {
- float history[SGRMusicHistoryLength]; // the energy of each hop of the last second
+ float history[SGMusicHistoryLength]; // the energy of each hop of the last second
int count, next;
double sum;
- float window[SGRMusicWindowHops]; // the energy of the last hops
+ float window[SGMusicWindowHops]; // the energy of the last hops
int windowNext;
float lastInstant;
float peakDb; // the loudest this band has been lately, falling slowly
- float recentDb[SGRMusicAttackHops];
+ float recentDb[SGMusicAttackHops];
int recentNext;
int rest; // hops before the band may hit again
int pending; // hops a hit has been rising for, 0 when none
@@ -59,7 +59,7 @@ typedef struct {
float pendingBright;
uint64_t pendingTime;
int armed;
-} SGRMusicBand;
+} SGMusicBand;
typedef struct {
double sampleRate;
@@ -68,15 +68,15 @@ typedef struct {
int historyHops;
uint64_t hopTime;
double lowSum, highSum, midSum, fullSum;
- SGRMusicBiquad lowPass[2], highPass[2], midPass[2];
- SGRMusicBand kick, snap, mid; // the bass, the top, and the middle (only its average is read)
+ SGMusicBiquad lowPass[2], highPass[2], midPass[2];
+ SGMusicBand kick, snap, mid; // the bass, the top, and the middle (only its average is read)
double bassEnvelope, brightness;
int levelCountdown;
int sinceKick; // hops since the bass last hit
-} SGRMusicAnalyzer;
+} SGMusicAnalyzer;
// Before the first buffer, and again when the sample rate changes or the sound jumps (a seek).
-void SGRMusicAnalyzerReset(SGRMusicAnalyzer *analyzer, double sampleRate, double ticksPerSecond);
+void SGMusicAnalyzerReset(SGMusicAnalyzer *analyzer, double sampleRate, double ticksPerSecond);
// `mono` holds `frames` samples in -1...1, the first reaching the output at `hostTime`.
-void SGRMusicAnalyzerProcess(SGRMusicAnalyzer *analyzer, const float *mono, uint32_t frames, uint64_t hostTime,
- SGRMusicEmit emit, void *context);
+void SGMusicAnalyzerProcess(SGMusicAnalyzer *analyzer, const float *mono, uint32_t frames, uint64_t hostTime,
+ SGMusicEmit emit, void *context);
diff --git a/tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.m b/tweak/Sources/Shared/Haptics/SGMusicAnalyzer.m
similarity index 86%
rename from tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.m
rename to tweak/Sources/Shared/Haptics/SGMusicAnalyzer.m
index 977b2941..7140abd6 100644
--- a/tweak/Sources/Redesigned/Haptics/SGRMusicAnalyzer.m
+++ b/tweak/Sources/Shared/Haptics/SGMusicAnalyzer.m
@@ -1,7 +1,7 @@
#import <limits.h>
#import <math.h>
#import <string.h>
-#import "SGRMusicAnalyzer.h"
+#import "SGMusicAnalyzer.h"
static const double kHopSeconds = 0.0058; // 256 frames at 44.1 kHz
static const double kAverageSeconds = 1.0; // what a hit is measured against
@@ -11,7 +11,7 @@ static const float kFloorDb = -62; // quieter than this is silence
static const float kPeakFallDbPerSecond = 0.5;
// How far over its average a band's energy has to go to hit, how far under it to hit again, how much it
-// has to have risen over the last SGRMusicAttackHops (a swell rises too slowly), the rest after a hit,
+// has to have risen over the last SGMusicAttackHops (a swell rises too slowly), the rest after a hit,
// the dB over the threshold that makes a tap as strong as it gets, how quiet the band may be and still
// hit, and the level a band is called loud at even when it has not been louder lately. The energy a
// band is judged by is the mean of its last `windowHops`, which for the bass has to span a cycle of a
@@ -53,7 +53,7 @@ static inline float decibels(double energy) {
}
// RBJ's cookbook, Q 0.707; two in a row make 24 dB an octave.
-static void setBiquad(SGRMusicBiquad *filter, double sampleRate, double cutoff, int highPass) {
+static void setBiquad(SGMusicBiquad *filter, double sampleRate, double cutoff, int highPass) {
double w = 2 * M_PI * cutoff / sampleRate;
double cosw = cos(w), alpha = sin(w) / (2 * M_SQRT1_2);
double a0 = 1 + alpha;
@@ -67,33 +67,33 @@ static void setBiquad(SGRMusicBiquad *filter, double sampleRate, double cutoff,
filter->z1 = filter->z2 = 0;
}
-static inline double runBiquad(SGRMusicBiquad *filter, double x) {
+static inline double runBiquad(SGMusicBiquad *filter, double x) {
double y = filter->b0 * x + filter->z1;
filter->z1 = filter->b1 * x - filter->a1 * y + filter->z2;
filter->z2 = filter->b2 * x - filter->a2 * y;
return y;
}
-static void resetBand(SGRMusicBand *band) {
+static void resetBand(SGMusicBand *band) {
memset(band, 0, sizeof(*band));
band->peakDb = kFloorDb;
- for (int i = 0; i < SGRMusicAttackHops; i++) band->recentDb[i] = kFloorDb;
+ for (int i = 0; i < SGMusicAttackHops; i++) band->recentDb[i] = kFloorDb;
band->armed = 1;
}
// A band is loud at its recent peak, or at the tuning's loud level when it has been quieter than that.
-static inline float loudDbOf(const SGRMusicBand *band, const BandTuning *tuning) {
+static inline float loudDbOf(const SGMusicBand *band, const BandTuning *tuning) {
return band->peakDb > tuning->loudDb ? band->peakDb : tuning->loudDb;
}
-void SGRMusicAnalyzerReset(SGRMusicAnalyzer *analyzer, double sampleRate, double ticksPerSecond) {
+void SGMusicAnalyzerReset(SGMusicAnalyzer *analyzer, double sampleRate, double ticksPerSecond) {
memset(analyzer, 0, sizeof(*analyzer));
analyzer->sampleRate = sampleRate;
analyzer->ticksPerSecond = ticksPerSecond;
analyzer->hopFrames = (int)lround(sampleRate * kHopSeconds);
if (analyzer->hopFrames < 64) analyzer->hopFrames = 64;
int hops = (int)lround(kAverageSeconds * sampleRate / analyzer->hopFrames);
- analyzer->historyHops = hops < 8 ? 8 : hops > SGRMusicHistoryLength ? SGRMusicHistoryLength : hops;
+ analyzer->historyHops = hops < 8 ? 8 : hops > SGMusicHistoryLength ? SGMusicHistoryLength : hops;
for (int i = 0; i < 2; i++) {
setBiquad(&analyzer->lowPass[i], sampleRate, kLowCutoff, 0);
setBiquad(&analyzer->highPass[i], sampleRate, kHighCutoff, 1);
@@ -106,17 +106,17 @@ void SGRMusicAnalyzerReset(SGRMusicAnalyzer *analyzer, double sampleRate, double
analyzer->sinceKick = 1 << 20;
}
-static double hopDuration(const SGRMusicAnalyzer *analyzer) {
+static double hopDuration(const SGMusicAnalyzer *analyzer) {
return analyzer->hopFrames / analyzer->sampleRate;
}
// Moves a band on by one hop's energy: the energy of its last `windowHops` hops, and the average of the
// last second before this hop in `average`.
-static float track(SGRMusicAnalyzer *analyzer, SGRMusicBand *band, int windowHops, double energy, double *average) {
+static float track(SGMusicAnalyzer *analyzer, SGMusicBand *band, int windowHops, double energy, double *average) {
band->window[band->windowNext] = (float)energy;
- band->windowNext = (band->windowNext + 1) % SGRMusicWindowHops;
+ band->windowNext = (band->windowNext + 1) % SGMusicWindowHops;
double sum = 0;
- for (int i = 1; i <= windowHops; i++) sum += band->window[(band->windowNext - i + SGRMusicWindowHops) % SGRMusicWindowHops];
+ for (int i = 1; i <= windowHops; i++) sum += band->window[(band->windowNext - i + SGMusicWindowHops) % SGMusicWindowHops];
float instant = (float)(sum / windowHops);
*average = band->count ? band->sum / band->count : instant;
@@ -130,8 +130,8 @@ static float track(SGRMusicAnalyzer *analyzer, SGRMusicBand *band, int windowHop
}
// Takes one hop's energy; returns 1 and fills `event` when a hit that was rising has peaked.
-static int listen(SGRMusicAnalyzer *analyzer, SGRMusicBand *band, const BandTuning *tuning, double energy,
- uint64_t time, float brightness, float midRatio, SGRMusicEvent *event) {
+static int listen(SGMusicAnalyzer *analyzer, SGMusicBand *band, const BandTuning *tuning, double energy,
+ uint64_t time, float brightness, float midRatio, SGMusicEvent *event) {
double hop = hopDuration(analyzer);
double average;
float instant = track(analyzer, band, tuning->windowHops, energy, &average);
@@ -141,7 +141,7 @@ static int listen(SGRMusicAnalyzer *analyzer, SGRMusicBand *band, const BandTuni
if (band->peakDb < kFloorDb) band->peakDb = kFloorDb;
float attack = db - band->recentDb[band->recentNext];
band->recentDb[band->recentNext] = db;
- band->recentNext = (band->recentNext + 1) % SGRMusicAttackHops;
+ band->recentNext = (band->recentNext + 1) % SGMusicAttackHops;
if (band->rest > 0) band->rest--;
if (band->sinceHit < INT_MAX) band->sinceHit++;
@@ -191,7 +191,7 @@ static int listen(SGRMusicAnalyzer *analyzer, SGRMusicBand *band, const BandTuni
return fired;
}
-static void endHop(SGRMusicAnalyzer *analyzer, SGRMusicEmit emit, void *context) {
+static void endHop(SGMusicAnalyzer *analyzer, SGMusicEmit emit, void *context) {
double n = analyzer->hopFrames;
double low = analyzer->lowSum / n, high = analyzer->highSum / n, full = analyzer->fullSum / n;
analyzer->lowSum = analyzer->highSum = analyzer->fullSum = 0;
@@ -208,17 +208,17 @@ static void endHop(SGRMusicAnalyzer *analyzer, SGRMusicEmit emit, void *context)
float midRatio = midAverage > 0 ? (float)(midInstant / midAverage) : 0;
analyzer->midSum = 0;
- SGRMusicEvent event;
+ SGMusicEvent event;
analyzer->sinceKick++;
if (listen(analyzer, &analyzer->kick, &kKickTuning, low, time, bright, midRatio, &event)) {
- event.kind = SGRMusicEventKick;
+ event.kind = SGMusicEventKick;
event.sharpness = 0.15f + 0.3f * event.sharpness;
analyzer->sinceKick = 0;
emit(&event, context);
}
if (listen(analyzer, &analyzer->snap, &kSnapTuning, high, time, bright, midRatio, &event)) {
if (analyzer->sinceKick * hop > kSnapAfterKickSeconds) {
- event.kind = SGRMusicEventSnare;
+ event.kind = SGMusicEventSnare;
event.intensity *= 0.8f;
event.sharpness = 0.55f + 0.4f * event.sharpness;
emit(&event, context);
@@ -232,8 +232,8 @@ static void endHop(SGRMusicAnalyzer *analyzer, SGRMusicEmit emit, void *context)
float db = decibels(analyzer->bassEnvelope);
float loud = loudDbOf(&analyzer->kick, &kKickTuning);
float level = decibels(full) < kFloorDb ? 0 : clamp01((db - (loud - kLevelRangeDb)) / kLevelRangeDb);
- SGRMusicEvent rumble = {
- .kind = SGRMusicEventLevel,
+ SGMusicEvent rumble = {
+ .kind = SGMusicEventLevel,
.hostTime = time,
.intensity = level * level * kLevelMax,
.sharpness = 0.1f + 0.25f * (float)analyzer->brightness,
@@ -242,8 +242,8 @@ static void endHop(SGRMusicAnalyzer *analyzer, SGRMusicEmit emit, void *context)
}
}
-void SGRMusicAnalyzerProcess(SGRMusicAnalyzer *analyzer, const float *mono, uint32_t frames, uint64_t hostTime,
- SGRMusicEmit emit, void *context) {
+void SGMusicAnalyzerProcess(SGMusicAnalyzer *analyzer, const float *mono, uint32_t frames, uint64_t hostTime,
+ SGMusicEmit emit, void *context) {
if (analyzer->sampleRate <= 0) return;
double ticksPerFrame = analyzer->ticksPerSecond / analyzer->sampleRate;
for (uint32_t i = 0; i < frames; i++) {
diff --git a/tweak/Sources/Redesigned/LiveActivity/LiveActivity.h b/tweak/Sources/Shared/LiveActivity/LiveActivity.h
similarity index 55%
rename from tweak/Sources/Redesigned/LiveActivity/LiveActivity.h
rename to tweak/Sources/Shared/LiveActivity/LiveActivity.h
index 8cbe78d7..a4a0d933 100644
--- a/tweak/Sources/Redesigned/LiveActivity/LiveActivity.h
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivity.h
@@ -1,5 +1,5 @@
-// The redesign's Live Activity (Mod Settings > Live Activity), on the lock screen and in the Dynamic
-// Island (iOS 17+), in one of three views: the line being sung with the next one under it, the tracks
+// The Live Activity (Mod Settings > Live Activity), on the lock screen and in the Dynamic
+// Island (iOS 17+), under either look: it draws on no Spotify screen of its own. In one of three views: the line being sung with the next one under it, the tracks
// up next (a tap on one skipping ahead to it), or the control menu, tabs of Controls (previous, play and
// pause, next, shuffle, repeat), Queue and a sleep Timer of the mod's own that pauses Spotify.
//
@@ -14,24 +14,31 @@
// intent runs in Spotify, so scripts/merge-appintents.py adds it to Spotify's App Intents metadata. The lines and
// the clock come from Shared/Lyrics, the queue from the player's state. The switch and the view apply at
// once: iOS lets an activity start only while the app is in front, which it is when the switch is flipped.
+//
+// The Swift names crossing into the widget (SGLyricsAttributes, the two intents, the notifications)
+// are a contract with extension/LiveActivity and with the App Intents metadata merged into Spotify:
+// ActivityKit and App Intents pair the two processes by type name, so a change here is a change there.
// Threading: main thread only.
#import <Foundation/Foundation.h>
-#define SGRKeyLiveActivity @"spotifyglass.redesign.liveActivity"
+#define SGKeyLiveActivity @"spotifyglass.liveActivity"
// Which view it shows, the index into the page's list.
-#define SGRKeyLiveActivityView @"spotifyglass.redesign.liveActivity.view"
+#define SGKeyLiveActivityView @"spotifyglass.liveActivity.view"
+// What the keys were called while this was the redesign's alone; LiveActivity.x's %ctor moves them over.
+#define SGKeyLiveActivityWas @"spotifyglass.redesign.liveActivity"
+#define SGKeyLiveActivityViewWas @"spotifyglass.redesign.liveActivity.view"
-typedef NS_ENUM(NSInteger, SGRLiveActivityView) {
- SGRLiveActivityLyrics = 0,
- SGRLiveActivityQueue,
- SGRLiveActivityPanel, // the control menu
+typedef NS_ENUM(NSInteger, SGLiveActivityView) {
+ SGLiveActivityLyrics = 0,
+ SGLiveActivityQueue,
+ SGLiveActivityPanel, // the control menu
};
// From the switch: starts following the player (and the activity, the app being in front) or ends both.
-void SGRSetLiveActivityEnabled(BOOL on);
+void SGSetLiveActivityEnabled(BOOL on);
@class UIViewController;
// The Live Activity page: its switch and which view it shows.
-UIViewController *SGRLiveActivitySettingsPage(void);
+UIViewController *SGLiveActivitySettingsPage(void);
// What the root's row reads out beside its chevron: the view shown, or Off.
-NSString *SGRLiveActivitySummary(void);
+NSString *SGLiveActivitySummary(void);
diff --git a/tweak/Sources/Redesigned/LiveActivity/LiveActivity.x b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
similarity index 88%
rename from tweak/Sources/Redesigned/LiveActivity/LiveActivity.x
rename to tweak/Sources/Shared/LiveActivity/LiveActivity.x
index f6c2fcdf..fbe13178 100644
--- a/tweak/Sources/Redesigned/LiveActivity/LiveActivity.x
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
@@ -11,7 +11,7 @@
#import "LiveActivity.h"
API_AVAILABLE(ios(17.0))
-@interface SGRLiveActivityBridge : NSObject
+@interface SGLiveActivityBridge : NSObject
@property (class, nonatomic, readonly) BOOL isShowing;
+ (void)showWithView:(NSInteger)view paused:(BOOL)paused line:(NSString *)line nextLine:(NSString *)nextLine
titles:(NSArray<NSString *> *)titles artists:(NSArray<NSString *> *)artists uris:(NSArray<NSString *> *)uris
@@ -21,10 +21,10 @@ API_AVAILABLE(ios(17.0))
@end
// The control menu's tabs, SGLyricsAttributes.Tab's values.
-typedef NS_ENUM(NSInteger, SGRLiveActivityTab) {
- SGRLiveActivityTabControls = 0,
- SGRLiveActivityTabQueue,
- SGRLiveActivityTabTimer,
+typedef NS_ENUM(NSInteger, SGLiveActivityTab) {
+ SGLiveActivityTabControls = 0,
+ SGLiveActivityTabQueue,
+ SGLiveActivityTabTimer,
};
static const NSTimeInterval kTick = 0.25;
@@ -43,7 +43,7 @@ static NSTimer *sg_timer;
static NSString *sg_shown;
static NSString *sg_missingLyrics;
static NSDate *sg_lastStart;
-static SGRLiveActivityTab sg_tab;
+static SGLiveActivityTab sg_tab;
// The sleep timer: an end, or the end of the track it was set on.
static NSDate *sg_sleepEnd;
static NSString *sg_sleepTrack;
@@ -51,7 +51,7 @@ static NSString *sg_sleepTrack;
// Sends `shown`, what the activity is to show as one string, unless it is showing that already; starts
// the activity when there is none and the app is in front.
static void send(NSString *shown, void (^show)(void)) API_AVAILABLE(ios(17.0)) {
- if (SGRLiveActivityBridge.isShowing) {
+ if (SGLiveActivityBridge.isShowing) {
if ([shown isEqualToString:sg_shown]) return;
} else {
if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) return;
@@ -138,14 +138,14 @@ static void tick(void) API_AVAILABLE(ios(17.0)) {
NSString *trackID = SGKaraokePlayingTrack();
checkSleepTimer(player, state, trackID);
- NSInteger view = SGInt(SGRKeyLiveActivityView, SGRLiveActivityLyrics);
+ NSInteger view = SGInt(SGKeyLiveActivityView, SGLiveActivityLyrics);
BOOL paused = state.isPaused;
NSString *line = @"", *next = @"";
- if (view == SGRLiveActivityLyrics) line = lyricsLine(trackID, &next);
+ if (view == SGLiveActivityLyrics) line = lyricsLine(trackID, &next);
NSMutableArray<NSString *> *titles = [NSMutableArray array], *artists = [NSMutableArray array], *uris = [NSMutableArray array];
- if (view != SGRLiveActivityLyrics) {
- NSUInteger limit = view == SGRLiveActivityQueue ? kUpNextQueue : kUpNextPanel;
+ if (view != SGLiveActivityLyrics) {
+ NSUInteger limit = view == SGLiveActivityQueue ? kUpNextQueue : kUpNextPanel;
for (SPTPlayerTrack *upcoming in upNext(state)) {
if (titles.count == limit) break;
[titles addObject:upcoming.trackTitle];
@@ -154,7 +154,7 @@ static void tick(void) API_AVAILABLE(ios(17.0)) {
}
}
- BOOL panel = view == SGRLiveActivityPanel;
+ BOOL panel = view == SGLiveActivityPanel;
NSString *title = panel ? track.trackTitle : @"", *artist = panel ? track.artistName ?: @"" : @"";
BOOL shuffle = panel && state.options.shufflingContext;
NSInteger repeatMode = panel ? repeatModeOf(state.options) : 0;
@@ -167,7 +167,7 @@ static void tick(void) API_AVAILABLE(ios(17.0)) {
@((long long)sleepEnd.timeIntervalSince1970).stringValue, endOfTrack ? @"1" : @"0", nil];
for (NSUInteger i = 0; i < titles.count; i++) [parts addObject:[NSString stringWithFormat:@"%@\t%@\t%@", titles[i], artists[i], uris[i]]];
send([parts componentsJoinedByString:@"\n"], ^{
- [SGRLiveActivityBridge showWithView:view paused:paused line:line nextLine:next titles:titles artists:artists uris:uris
+ [SGLiveActivityBridge showWithView:view paused:paused line:line nextLine:next titles:titles artists:artists uris:uris
tab:tab title:title artist:artist shuffle:shuffle repeatMode:repeatMode
timerEnd:sleepEnd timerEndOfTrack:endOfTrack];
});
@@ -189,7 +189,7 @@ static void playQueued(NSString *uri) {
SGLog(@"live activity: play %@ -> %@", uri, result);
}
-// A tap in the control menu, one of SGRLiveActivityActionIntent's actions.
+// A tap in the control menu, one of SGLiveActivityActionIntent's actions.
static void runAction(NSString *action) {
id<SPTPlayer> player = SGKaraokePlayer();
SPTPlayerState *state = player.state;
@@ -197,7 +197,7 @@ static void runAction(NSString *action) {
NSString *name = parts.firstObject, *value = parts.count > 1 ? parts[1] : @"";
id result = nil;
if ([name isEqualToString:@"tab"]) {
- sg_tab = MAX(SGRLiveActivityTabControls, MIN(SGRLiveActivityTabTimer, value.integerValue));
+ sg_tab = MAX(SGLiveActivityTabControls, MIN(SGLiveActivityTabTimer, value.integerValue));
} else if ([name isEqualToString:@"toggle"]) {
result = state.isPaused ? [player resume:nil] : [player pause:nil];
} else if ([name isEqualToString:@"previous"]) {
@@ -235,8 +235,7 @@ static void runAction(NSString *action) {
SGLog(@"live activity: %@ -> %@", action, result);
}
-void SGRSetLiveActivityEnabled(BOOL on) {
- if (!SGRedesignedUI()) return;
+void SGSetLiveActivityEnabled(BOOL on) {
if (@available(iOS 17.0, *)) {
[sg_timer invalidate];
sg_timer = nil;
@@ -244,18 +243,18 @@ void SGRSetLiveActivityEnabled(BOOL on) {
sg_lastStart = nil;
clearSleepTimer();
if (!on) {
- [SGRLiveActivityBridge end];
+ [SGLiveActivityBridge end];
SGLog(@"live activity: off");
return;
}
static dispatch_once_t observing;
dispatch_once(&observing, ^{
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
- [center addObserverForName:@"SGRLiveActivityPlay" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
+ [center addObserverForName:@"SGLiveActivityPlay" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
if ([note.object isKindOfClass:NSString.class]) playQueued(note.object);
}];
// The new state goes out at once rather than on the next tick, the card being slow enough to redraw.
- [center addObserverForName:@"SGRLiveActivityAction" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
+ [center addObserverForName:@"SGLiveActivityAction" object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
if (![note.object isKindOfClass:NSString.class]) return;
runAction(note.object);
if (sg_timer) tick();
@@ -268,13 +267,15 @@ void SGRSetLiveActivityEnabled(BOOL on) {
}
%ctor {
- if (!SGRedesignedUI()) return;
if (@available(iOS 17.0, *)) {
- BOOL on = SGFlag(SGRKeyLiveActivity, NO);
+ // It was the redesign's alone until it moved to Shared/; whoever had it on keeps it on.
+ SGMigrateKey(SGKeyLiveActivityWas, SGKeyLiveActivity);
+ SGMigrateKey(SGKeyLiveActivityViewWas, SGKeyLiveActivityView);
+ BOOL on = SGFlag(SGKeyLiveActivity, NO);
// Off, one left from a launch before the switch went off is ended.
dispatch_async(dispatch_get_main_queue(), ^{
- if (on) SGRSetLiveActivityEnabled(YES);
- else [SGRLiveActivityBridge end];
+ if (on) SGSetLiveActivityEnabled(YES);
+ else [SGLiveActivityBridge end];
});
}
}
diff --git a/tweak/Sources/Redesigned/LiveActivity/LiveActivityBridge.swift b/tweak/Sources/Shared/LiveActivity/LiveActivityBridge.swift
similarity index 93%
rename from tweak/Sources/Redesigned/LiveActivity/LiveActivityBridge.swift
rename to tweak/Sources/Shared/LiveActivity/LiveActivityBridge.swift
index 8e781bc4..cd4cf919 100644
--- a/tweak/Sources/Redesigned/LiveActivity/LiveActivityBridge.swift
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivityBridge.swift
@@ -4,8 +4,8 @@ import Foundation
import os
@available(iOS 17.0, *)
-@objc(SGRLiveActivityBridge)
-public final class SGRLiveActivityBridge: NSObject {
+@objc(SGLiveActivityBridge)
+public final class SGLiveActivityBridge: NSObject {
private static let log = Logger(subsystem: "spotifyglass", category: "live activity")
private static var current: Activity<SGLyricsAttributes>? {
@@ -15,7 +15,7 @@ public final class SGRLiveActivityBridge: NSObject {
@objc public static var isShowing: Bool { current != nil }
// A new activity can only be requested while the app is in the foreground; an update works from the background.
- // One call per new state. View and tab are SGRLiveActivityView's and SGRLiveActivityTab's values;
+ // One call per new state. View and tab are SGLiveActivityView's and SGLiveActivityTab's values;
// titles, artists and URIs pair up by index, the tracks up next; timerEnd is nil without a timer.
@objc public static func show(view: Int, paused: Bool, line: String, nextLine: String,
titles: [String], artists: [String], uris: [String],
diff --git a/tweak/Sources/Shared/LiveActivity/LiveActivitySettings.m b/tweak/Sources/Shared/LiveActivity/LiveActivitySettings.m
new file mode 100644
index 00000000..66cab462
--- /dev/null
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivitySettings.m
@@ -0,0 +1,24 @@
+// The Live Activity page (App/ModSettings.x links it from the root, under either look).
+#import "Core/SGCore.h"
+#import "Settings/SGModPage.h"
+#import "LiveActivity.h"
+
+static NSArray<NSString *> *viewNames(void) {
+ return @[@"Lyrics", @"Queue", @"Control menu"];
+}
+
+UIViewController *SGLiveActivitySettingsPage(void) {
+ SGModRow *on = SGOptionRow(@"Live Activity", @"On the lock screen and in the Dynamic Island", SGKeyLiveActivity);
+ on.changed = ^(BOOL value) { SGSetLiveActivityEnabled(value); };
+ SGModRow *view = SGChoiceRow(@"Shows", nil, SGKeyLiveActivityView, viewNames(), SGLiveActivityLyrics);
+ return [[SGModPage alloc] initWithTitle:@"Live Activity" intro:nil sections:@[
+ SGSection(nil, @[on, view]),
+ ] footer:nil];
+}
+
+NSString *SGLiveActivitySummary(void) {
+ if (!SGFlag(SGKeyLiveActivity, NO)) return @"Off";
+ NSInteger index = SGInt(SGKeyLiveActivityView, SGLiveActivityLyrics);
+ NSArray<NSString *> *names = viewNames();
+ return index >= 0 && index < (NSInteger)names.count ? names[index] : names.firstObject;
+}
diff --git a/tweak/Sources/Redesigned/LiveActivity/LiveActivityShared.swift b/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
similarity index 80%
rename from tweak/Sources/Redesigned/LiveActivity/LiveActivityShared.swift
rename to tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
index fdcf591c..94548ff6 100644
--- a/tweak/Sources/Redesigned/LiveActivity/LiveActivityShared.swift
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
@@ -6,7 +6,7 @@ import Foundation
@available(iOS 16.1, *)
struct SGLyricsAttributes: ActivityAttributes {
- // Which of the three the activity shows, SGRLiveActivityView's values.
+ // Which of the three the activity shows, SGLiveActivityView's values.
enum View: Int, Codable, Hashable {
case lyrics, queue, panel
}
@@ -43,11 +43,11 @@ struct SGLyricsAttributes: ActivityAttributes {
}
// LiveActivityIntents run in the app's process, where the tweak acts on these notifications.
-let SGRLiveActivityPlayNotification = Notification.Name("SGRLiveActivityPlay")
-let SGRLiveActivityActionNotification = Notification.Name("SGRLiveActivityAction")
+let SGLiveActivityPlayNotification = Notification.Name("SGLiveActivityPlay")
+let SGLiveActivityActionNotification = Notification.Name("SGLiveActivityAction")
@available(iOS 17.0, *)
-struct SGRPlayQueuedTrackIntent: LiveActivityIntent {
+struct SGPlayQueuedTrackIntent: LiveActivityIntent {
static let title: LocalizedStringResource = "Play a track up next"
static let isDiscoverable = false
@@ -61,14 +61,14 @@ struct SGRPlayQueuedTrackIntent: LiveActivityIntent {
}
func perform() async throws -> some IntentResult {
- NotificationCenter.default.post(name: SGRLiveActivityPlayNotification, object: uri)
+ NotificationCenter.default.post(name: SGLiveActivityPlayNotification, object: uri)
return .result()
}
}
// A control menu action: tab:N, toggle, previous, next, shuffle, repeat, timer:15|30|60|track|add|cancel.
@available(iOS 17.0, *)
-struct SGRLiveActivityActionIntent: LiveActivityIntent {
+struct SGLiveActivityActionIntent: LiveActivityIntent {
static let title: LocalizedStringResource = "Control menu action"
static let isDiscoverable = false
@@ -82,7 +82,7 @@ struct SGRLiveActivityActionIntent: LiveActivityIntent {
}
func perform() async throws -> some IntentResult {
- NotificationCenter.default.post(name: SGRLiveActivityActionNotification, object: action)
+ NotificationCenter.default.post(name: SGLiveActivityActionNotification, object: action)
return .result()
}
}
diff --git a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.h b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.h
index 5730b4ca..4e92f637 100644
--- a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.h
+++ b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.h
@@ -1,5 +1,5 @@
// The line being sung in place of the artist in the system's now playing: lock screen, Dynamic Island,
-// Control Center, CarPlay. The redesign also has a Live Activity for it (Redesigned/LiveActivity). The
+// Control Center, CarPlay. There is a Live Activity for it too (Shared/LiveActivity). The
// lines and the clock come from Karaoke.
#import <Foundation/Foundation.h>
diff --git a/tweak/Sources/Shared/Player/PlayerState.h b/tweak/Sources/Shared/Player/PlayerState.h
new file mode 100644
index 00000000..4b6e0dcf
--- /dev/null
+++ b/tweak/Sources/Shared/Player/PlayerState.h
@@ -0,0 +1,24 @@
+// What Spotify's player is doing, read through one hook so no feature of the mod hooks the player a
+// second time, and under either look: the state is data, not a screen.
+//
+// -[_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation player:stateDidChange:]
+// (objc-methods.txt:60654) is the now playing platform's own player observer, and until that has
+// reported, an observer of the mod's added to the first SPTEsperantoPlayer the app adds one to
+// (-[SPTEsperantoPlayer addPlayerObserver:], :35729).
+//
+// Threading: the player reports from several threads and everything here is moved onto the main one,
+// so observers are called there.
+#import <UIKit/UIKit.h>
+#import "Headers/SPTPlayer.h"
+
+// A URI Spotify types as id (NSURL or NSString) as a string; nil for anything else.
+NSString *SGURIString(id uri);
+
+@protocol SGPlayerStateObserver <NSObject>
+// Called when the track, the context, paused, playing, loading or shuffle changed, not for position.
+- (void)playerStateDidChange:(SPTPlayerState *)state;
+@end
+// Observers are held weakly and need no removal.
+void SGAddPlayerStateObserver(id<SGPlayerStateObserver> observer);
+// The last state reported, nil before the player has reported one.
+SPTPlayerState *SGPlayerState(void);
diff --git a/tweak/Sources/Shared/Player/PlayerState.x b/tweak/Sources/Shared/Player/PlayerState.x
new file mode 100644
index 00000000..a9e8ad71
--- /dev/null
+++ b/tweak/Sources/Shared/Player/PlayerState.x
@@ -0,0 +1,97 @@
+// PlayerState.h names the hooks and why they are the ones.
+#import "Core/SGCore.h"
+#import "PlayerState.h"
+
+NSString *SGURIString(id uri) {
+ if ([uri isKindOfClass:NSString.class]) return uri;
+ if ([uri isKindOfClass:NSURL.class]) return ((NSURL *)uri).absoluteString;
+ return nil;
+}
+
+static NSHashTable<id<SGPlayerStateObserver>> *sg_stateObservers;
+static SPTPlayerState *sg_playerState;
+static NSString *sg_stateKey;
+// Set once the now playing platform has reported; the mod's own observer on the player stands down.
+static BOOL sg_platformReported = NO;
+
+void SGAddPlayerStateObserver(id<SGPlayerStateObserver> observer) {
+ if (!observer) return;
+ if (!sg_stateObservers) sg_stateObservers = [NSHashTable weakObjectsHashTable];
+ [sg_stateObservers addObject:observer];
+}
+
+SPTPlayerState *SGPlayerState(void) {
+ return sg_playerState;
+}
+
+// What an observer is told about; the state object itself is new with every position report.
+static NSString *keyOf(SPTPlayerState *state) {
+ SPTPlayerOptions *options = [state respondsToSelector:@selector(options)] ? state.options : nil;
+ BOOL shuffling = [options respondsToSelector:@selector(shufflingContext)] && options.shufflingContext;
+ return [NSString stringWithFormat:@"%@|%@|%d%d%d%d", SGURIString(state.track.URI), SGURIString(state.contextURI),
+ state.isPaused, state.isPlaying, [state respondsToSelector:@selector(isLoading)] && state.isLoading, shuffling];
+}
+
+static void publish(SPTPlayerState *state) {
+ sg_playerState = state;
+ NSString *key = keyOf(state);
+ if ([key isEqualToString:sg_stateKey]) return;
+ sg_stateKey = key;
+ for (id<SGPlayerStateObserver> observer in sg_stateObservers.allObjects) [observer playerStateDidChange:state];
+}
+
+static void report(id state, BOOL platform) {
+ if (![state isKindOfClass:objc_getClass("SPTPlayerState")]) return;
+ dispatch_block_t apply = ^{
+ if (platform) sg_platformReported = YES;
+ else if (sg_platformReported) return;
+ publish(state);
+ };
+ if (NSThread.isMainThread) apply();
+ else dispatch_async(dispatch_get_main_queue(), apply);
+}
+
+@interface SGPlayerObserver : NSObject
+@end
+
+@implementation SGPlayerObserver
+- (void)player:(id)player stateDidChange:(id)state {
+ report(state, NO);
+}
+@end
+
+static SGPlayerObserver *sg_ownObserver;
+
+%hook _TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation
+- (void)player:(id)player stateDidChange:(id)state {
+ %orig;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ SGLog(@"player state: from %@, a %@, on the main thread %d", [player class], [state class], NSThread.isMainThread);
+ });
+ report(state, YES);
+}
+%end
+
+// Observers are added from several threads as the app starts; the first player seen is the one
+// watched, the way KaraokeSource.x takes the first player the app asks.
+%hook SPTEsperantoPlayer
+- (void)addPlayerObserver:(id)observer {
+ %orig;
+ id player = self;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ sg_ownObserver = [SGPlayerObserver new];
+ [(id<SPTPlayer>)player addPlayerObserver:sg_ownObserver];
+ id state = [player respondsToSelector:@selector(state)] ? [(id<SPTPlayer>)player state] : nil;
+ if (state) report(state, NO);
+ });
+ });
+}
+%end
+
+%ctor {
+ %init;
+ SGRequireClasses(@[@"_TtC23NowPlaying_PlatformImpl28StatefulPlayerImplementation", @"SPTEsperantoPlayer", @"SPTPlayerState"]);
+}
diff --git a/tweak/Sources/Redesigned/Player/SGRTimePitch.h b/tweak/Sources/Shared/Player/SGTimePitch.h
similarity index 64%
rename from tweak/Sources/Redesigned/Player/SGRTimePitch.h
rename to tweak/Sources/Shared/Player/SGTimePitch.h
index 2f9dbe37..abbcd976 100644
--- a/tweak/Sources/Redesigned/Player/SGRTimePitch.h
+++ b/tweak/Sources/Shared/Player/SGTimePitch.h
@@ -12,44 +12,44 @@
// Measured on the Mac (harness/pitch): the pitch exact to 0.01% at any rate, the rate exact in frames
// consumed, about 0.2% of a core, and the sound 4096 frames (93 ms at 44.1 kHz) later than it went in.
//
-// Plain C over audio units: SGRTimePitchRender and SGRTimePitchProcess run on Core Audio's render
+// Plain C over audio units: SGTimePitchRender and SGTimePitchProcess run on Core Audio's render
// thread, so they never allocate, lock, log or send a message. The rest is for any other thread.
// Compiles on the Mac as is.
#import <AudioToolbox/AudioToolbox.h>
#import <stdbool.h>
-enum { kSGRTimePitchMaxChannels = 2, kSGRTimePitchMaxFrames = 4096 };
+enum { kSGTimePitchMaxChannels = 2, kSGTimePitchMaxFrames = 4096 };
-typedef struct SGRTimePitch SGRTimePitch;
+typedef struct SGTimePitch SGTimePitch;
// Fills `data` (the unit's buffers, one per channel) with the next `frames` frames of input.
-typedef OSStatus (*SGRTimePitchSource)(void *context, UInt32 frames, AudioBufferList *data);
+typedef OSStatus (*SGTimePitchSource)(void *context, UInt32 frames, AudioBufferList *data);
-// Float, non-interleaved, `channels` of them, at `sampleRate`, in buffers of up to kSGRTimePitchMaxFrames
+// Float, non-interleaved, `channels` of them, at `sampleRate`, in buffers of up to kSGTimePitchMaxFrames
// frames. With a source it pulls from it, without one it works in place. NULL when the unit could not be
// made. Not on the render thread.
-SGRTimePitch *SGRTimePitchCreate(double sampleRate, UInt32 channels, SGRTimePitchSource source, void *context);
-double SGRTimePitchSampleRate(const SGRTimePitch *unit);
-UInt32 SGRTimePitchChannels(const SGRTimePitch *unit);
+SGTimePitch *SGTimePitchCreate(double sampleRate, UInt32 channels, SGTimePitchSource source, void *context);
+double SGTimePitchSampleRate(const SGTimePitch *unit);
+UInt32 SGTimePitchChannels(const SGTimePitch *unit);
// Any thread, taking effect with the next buffer. Rate 1 is normal speed (0.25...4); semitones up or down.
-void SGRTimePitchSetRate(SGRTimePitch *unit, float rate);
-void SGRTimePitchSetSemitones(SGRTimePitch *unit, float semitones);
+void SGTimePitchSetRate(SGTimePitch *unit, float rate);
+void SGTimePitchSetSemitones(SGTimePitch *unit, float semitones);
// Forgets the sound held, so the next buffer starts over from silence. Only while nothing renders.
-void SGRTimePitchReset(SGRTimePitch *unit);
+void SGTimePitchReset(SGTimePitch *unit);
// Pull mode: `frames` frames of output into `data`, float non-interleaved buffers of the unit's channels.
-OSStatus SGRTimePitchRender(SGRTimePitch *unit, UInt32 frames, AudioBufferList *data);
+OSStatus SGTimePitchRender(SGTimePitch *unit, UInt32 frames, AudioBufferList *data);
// In place mode: replaces `frames` samples of each channel with the same sound moved in pitch, the unit's
// latency later. Returns false, leaving them as they were, when it cannot (too many frames, the unit failed).
-bool SGRTimePitchProcess(SGRTimePitch *unit, float *const *channels, UInt32 frames);
+bool SGTimePitchProcess(SGTimePitch *unit, float *const *channels, UInt32 frames);
// Diagnostics, read from any thread: pulls the FIFO could not fully answer, render errors, the unit's own
// delay in seconds, the most frames it asked its input for at once, and the input frames it consumed.
-UInt32 SGRTimePitchUnderruns(const SGRTimePitch *unit);
-UInt32 SGRTimePitchFailures(const SGRTimePitch *unit);
-double SGRTimePitchLatency(const SGRTimePitch *unit);
-UInt32 SGRTimePitchLargestPull(const SGRTimePitch *unit);
-uint64_t SGRTimePitchConsumed(const SGRTimePitch *unit);
+UInt32 SGTimePitchUnderruns(const SGTimePitch *unit);
+UInt32 SGTimePitchFailures(const SGTimePitch *unit);
+double SGTimePitchLatency(const SGTimePitch *unit);
+UInt32 SGTimePitchLargestPull(const SGTimePitch *unit);
+uint64_t SGTimePitchConsumed(const SGTimePitch *unit);
diff --git a/tweak/Sources/Redesigned/Player/SGRTimePitch.m b/tweak/Sources/Shared/Player/SGTimePitch.m
similarity index 78%
rename from tweak/Sources/Redesigned/Player/SGRTimePitch.m
rename to tweak/Sources/Shared/Player/SGTimePitch.m
index ed9f42da..045ebb8b 100644
--- a/tweak/Sources/Redesigned/Player/SGRTimePitch.m
+++ b/tweak/Sources/Shared/Player/SGTimePitch.m
@@ -1,4 +1,4 @@
-#import "SGRTimePitch.h"
+#import "SGTimePitch.h"
#import <stdatomic.h>
#import <stdlib.h>
#import <string.h>
@@ -6,20 +6,20 @@
// The FIFO of in place mode, a power of two with room for a few of the largest buffers.
enum { kFifoFrames = 16384 };
-struct SGRTimePitch {
+struct SGTimePitch {
AudioUnit unit;
double sampleRate;
UInt32 channels;
- SGRTimePitchSource source;
+ SGTimePitchSource source;
void *context;
- float *fifo[kSGRTimePitchMaxChannels];
+ float *fifo[kSGTimePitchMaxChannels];
uint64_t written, read; // render thread only
Float64 sampleTime;
struct {
AudioBufferList list;
- AudioBuffer more[kSGRTimePitchMaxChannels - 1];
+ AudioBuffer more[kSGTimePitchMaxChannels - 1];
} output;
- float *outputData[kSGRTimePitchMaxChannels];
+ float *outputData[kSGTimePitchMaxChannels];
atomic_uint underruns, failures, largestPull;
atomic_uint_fast64_t consumed;
double latency;
@@ -27,7 +27,7 @@ struct SGRTimePitch {
static OSStatus input(void *refCon, AudioUnitRenderActionFlags *flags, const AudioTimeStamp *timestamp, UInt32 bus,
UInt32 frames, AudioBufferList *data) {
- SGRTimePitch *unit = refCon;
+ SGTimePitch *unit = refCon;
if (frames > atomic_load_explicit(&unit->largestPull, memory_order_relaxed)) {
atomic_store_explicit(&unit->largestPull, frames, memory_order_relaxed);
}
@@ -48,8 +48,8 @@ static OSStatus input(void *refCon, AudioUnitRenderActionFlags *flags, const Aud
return noErr;
}
-SGRTimePitch *SGRTimePitchCreate(double sampleRate, UInt32 channels, SGRTimePitchSource source, void *context) {
- if (sampleRate <= 0 || channels < 1 || channels > kSGRTimePitchMaxChannels) return NULL;
+SGTimePitch *SGTimePitchCreate(double sampleRate, UInt32 channels, SGTimePitchSource source, void *context) {
+ if (sampleRate <= 0 || channels < 1 || channels > kSGTimePitchMaxChannels) return NULL;
AudioComponentDescription description = {
.componentType = kAudioUnitType_FormatConverter,
.componentSubType = kAudioUnitSubType_NewTimePitch,
@@ -57,7 +57,7 @@ SGRTimePitch *SGRTimePitchCreate(double sampleRate, UInt32 channels, SGRTimePitc
};
AudioComponent component = AudioComponentFindNext(NULL, &description);
if (!component) return NULL;
- SGRTimePitch *unit = calloc(1, sizeof *unit);
+ SGTimePitch *unit = calloc(1, sizeof *unit);
if (!unit) return NULL;
unit->sampleRate = sampleRate;
unit->channels = channels;
@@ -77,7 +77,7 @@ SGRTimePitch *SGRTimePitchCreate(double sampleRate, UInt32 channels, SGRTimePitc
.mChannelsPerFrame = channels,
.mBitsPerChannel = 32,
};
- UInt32 maxFrames = kSGRTimePitchMaxFrames;
+ UInt32 maxFrames = kSGTimePitchMaxFrames;
AURenderCallbackStruct callback = {input, unit};
OSStatus status = AudioUnitSetProperty(unit->unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof format);
if (!status) status = AudioUnitSetProperty(unit->unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &format, sizeof format);
@@ -98,35 +98,35 @@ SGRTimePitch *SGRTimePitchCreate(double sampleRate, UInt32 channels, SGRTimePitc
unit->output.list.mNumberBuffers = channels;
for (UInt32 c = 0; c < channels; c++) {
if (!source) unit->fifo[c] = calloc(kFifoFrames, sizeof(float));
- unit->outputData[c] = calloc(kSGRTimePitchMaxFrames, sizeof(float));
+ unit->outputData[c] = calloc(kSGTimePitchMaxFrames, sizeof(float));
}
return unit;
}
-double SGRTimePitchSampleRate(const SGRTimePitch *unit) {
+double SGTimePitchSampleRate(const SGTimePitch *unit) {
return unit->sampleRate;
}
-UInt32 SGRTimePitchChannels(const SGRTimePitch *unit) {
+UInt32 SGTimePitchChannels(const SGTimePitch *unit) {
return unit->channels;
}
-void SGRTimePitchSetRate(SGRTimePitch *unit, float rate) {
+void SGTimePitchSetRate(SGTimePitch *unit, float rate) {
AudioUnitSetParameter(unit->unit, kNewTimePitchParam_Rate, kAudioUnitScope_Global, 0, rate, 0);
}
-void SGRTimePitchSetSemitones(SGRTimePitch *unit, float semitones) {
+void SGTimePitchSetSemitones(SGTimePitch *unit, float semitones) {
AudioUnitSetParameter(unit->unit, kNewTimePitchParam_Pitch, kAudioUnitScope_Global, 0, semitones * 100, 0);
}
-void SGRTimePitchReset(SGRTimePitch *unit) {
+void SGTimePitchReset(SGTimePitch *unit) {
AudioUnitReset(unit->unit, kAudioUnitScope_Global, 0);
unit->written = unit->read = 0;
unit->sampleTime = 0;
}
-OSStatus SGRTimePitchRender(SGRTimePitch *unit, UInt32 frames, AudioBufferList *data) {
- if (!frames || frames > kSGRTimePitchMaxFrames) return kAudioUnitErr_TooManyFramesToProcess;
+OSStatus SGTimePitchRender(SGTimePitch *unit, UInt32 frames, AudioBufferList *data) {
+ if (!frames || frames > kSGTimePitchMaxFrames) return kAudioUnitErr_TooManyFramesToProcess;
AudioTimeStamp timestamp = {.mSampleTime = unit->sampleTime, .mFlags = kAudioTimeStampSampleTimeValid};
AudioUnitRenderActionFlags flags = 0;
OSStatus status = AudioUnitRender(unit->unit, &flags, &timestamp, 0, frames, data);
@@ -135,8 +135,8 @@ OSStatus SGRTimePitchRender(SGRTimePitch *unit, UInt32 frames, AudioBufferList *
return status;
}
-bool SGRTimePitchProcess(SGRTimePitch *unit, float *const *channels, UInt32 frames) {
- if (unit->source || !frames || frames > kSGRTimePitchMaxFrames) return false;
+bool SGTimePitchProcess(SGTimePitch *unit, float *const *channels, UInt32 frames) {
+ if (unit->source || !frames || frames > kSGTimePitchMaxFrames) return false;
// A FIFO that would overflow (the unit stopped pulling) starts over rather than wrap onto itself.
if (unit->written - unit->read + frames > kFifoFrames) {
unit->written = unit->read = 0;
@@ -152,7 +152,7 @@ bool SGRTimePitchProcess(SGRTimePitch *unit, float *const *channels, UInt32 fram
for (UInt32 c = 0; c < unit->channels; c++) {
unit->output.list.mBuffers[c] = (AudioBuffer){1, frames * (UInt32)sizeof(float), unit->outputData[c]};
}
- if (SGRTimePitchRender(unit, frames, &unit->output.list) != noErr) return false;
+ if (SGTimePitchRender(unit, frames, &unit->output.list) != noErr) return false;
for (UInt32 c = 0; c < unit->channels; c++) {
const float *out = unit->output.list.mBuffers[c].mData;
if (out) memcpy(channels[c], out, frames * sizeof(float));
@@ -160,22 +160,22 @@ bool SGRTimePitchProcess(SGRTimePitch *unit, float *const *channels, UInt32 fram
return true;
}
-UInt32 SGRTimePitchUnderruns(const SGRTimePitch *unit) {
+UInt32 SGTimePitchUnderruns(const SGTimePitch *unit) {
return atomic_load((atomic_uint *)&unit->underruns);
}
-UInt32 SGRTimePitchFailures(const SGRTimePitch *unit) {
+UInt32 SGTimePitchFailures(const SGTimePitch *unit) {
return atomic_load((atomic_uint *)&unit->failures);
}
-double SGRTimePitchLatency(const SGRTimePitch *unit) {
+double SGTimePitchLatency(const SGTimePitch *unit) {
return unit->latency;
}
-UInt32 SGRTimePitchLargestPull(const SGRTimePitch *unit) {
+UInt32 SGTimePitchLargestPull(const SGTimePitch *unit) {
return atomic_load((atomic_uint *)&unit->largestPull);
}
-uint64_t SGRTimePitchConsumed(const SGRTimePitch *unit) {
+uint64_t SGTimePitchConsumed(const SGTimePitch *unit) {
return atomic_load((atomic_uint_fast64_t *)&unit->consumed);
}
diff --git a/tweak/Sources/Shared/Player/SpeedPitch.h b/tweak/Sources/Shared/Player/SpeedPitch.h
new file mode 100644
index 00000000..384c4a65
--- /dev/null
+++ b/tweak/Sources/Shared/Player/SpeedPitch.h
@@ -0,0 +1,27 @@
+// Speed and pitch: two sliders in the more button's menu, done to Spotify's sound, under either look.
+// Nothing here draws on a Spotify screen of its own: the block goes into Spotify's own context menu
+// sheet, and the rest is audio.
+//
+// SpeedPitchMenu.x the expandable row and its two sliders, put into Spotify's context menu
+// SpeedPitch.x speed and pitch done to Spotify's audio, between its mixer and its speaker unit
+// SGTimePitch.m Apple's time and pitch unit, pulling the mixer or working in place
+//
+// Speed and pitch last until Spotify quits; neither is stored.
+// Threading: main thread only, except what SGTimePitch.h says runs on the render thread.
+#import <UIKit/UIKit.h>
+
+// Marks a menu opened soon after a tap on `button`, the player's more button, as the player's, so it gets
+// Speed and pitch (watching it twice does nothing). The redesign's PlayerHeader.x hands its button over;
+// a menu presented from a now playing controller is taken for the player's without it, which is how the
+// native look's player gets the block.
+void SGPlayerMenuWatchMoreButton(UIView *button);
+// The speed Spotify's sound plays at, 1 when normal.
+double SGPlayerSpeed(void);
+// Whether speed can apply: Spotify's output was taken over when it wired it.
+BOOL SGPlayerSpeedAllowed(void);
+void SGSetPlayerSpeed(double speed);
+// Semitones Spotify's output is moved by, 0 when it is not.
+float SGPlayerPitch(void);
+void SGSetPlayerPitch(float semitones);
+// Whether the output could be reached to change its pitch.
+BOOL SGPlayerPitchAvailable(void);
diff --git a/tweak/Sources/Redesigned/Player/PlayerSpeedPitch.x b/tweak/Sources/Shared/Player/SpeedPitch.x
similarity index 89%
rename from tweak/Sources/Redesigned/Player/PlayerSpeedPitch.x
rename to tweak/Sources/Shared/Player/SpeedPitch.x
index 37a192bb..73387c63 100644
--- a/tweak/Sources/Redesigned/Player/PlayerSpeedPitch.x
+++ b/tweak/Sources/Shared/Player/SpeedPitch.x
@@ -1,8 +1,8 @@
-// The player menu's Speed and Pitch (PlayerMenu.x draws them), both done on Spotify's audio.
+// Speed and Pitch (SpeedPitchMenu.x draws them), both done on Spotify's audio, under either look.
//
// Spotify's player takes a speed only for podcasts: for songs its restrictions refuse it (device test,
// 2026-09-18: the slider read "Unavailable here"), its own music speed being a per track setting kept on
-// playlist items. So speed, like pitch, is done to the sound, by SGRTimePitch between Spotify's mixer and
+// playlist items. So speed, like pitch, is done to the sound, by SGTimePitch between Spotify's mixer and
// its speaker unit.
//
// Spotify's audio (AudioUnitDriver2 in the binary) is a chain of units it wires with MakeConnection:
@@ -38,8 +38,8 @@
#import "Core/SGCore.h"
#import "Core/SGRebind.h"
#import "Headers/SPTPlayer.h"
-#import "Player.h"
-#import "SGRTimePitch.h"
+#import "SpeedPitch.h"
+#import "SGTimePitch.h"
// The unit stays in this long after speed and pitch both came back to normal.
static const double kOffAfter = 1.5;
@@ -57,7 +57,7 @@ static atomic_uint sg_chunk = 1024;
static Float64 sg_sourceTime; // render thread only
// The unit in use and whether the render thread runs it: in the chain (pull), else in place (pitch only).
-static _Atomic(SGRTimePitch *) sg_pull, sg_inPlace;
+static _Atomic(SGTimePitch *) sg_pull, sg_inPlace;
static atomic_bool sg_engaged, sg_busy;
static pthread_mutex_t sg_buildLock = PTHREAD_MUTEX_INITIALIZER;
@@ -131,8 +131,8 @@ static OSStatus pullForUnit(void *context, UInt32 frames, AudioBufferList *data)
return pullSource(source, NULL, frames, data);
}
-static BOOL fitsUnit(const AudioBufferList *data, UInt32 frames, SGRTimePitch *unit) {
- if (data->mNumberBuffers != SGRTimePitchChannels(unit) || frames > kSGRTimePitchMaxFrames) return NO;
+static BOOL fitsUnit(const AudioBufferList *data, UInt32 frames, SGTimePitch *unit) {
+ if (data->mNumberBuffers != SGTimePitchChannels(unit) || frames > kSGTimePitchMaxFrames) return NO;
for (UInt32 b = 0; b < data->mNumberBuffers; b++) {
if (!data->mBuffers[b].mData || data->mBuffers[b].mDataByteSize < frames * sizeof(float)) return NO;
}
@@ -150,8 +150,8 @@ static OSStatus feed(void *refCon, AudioUnitRenderActionFlags *flags, const Audi
}
atomic_store(&sg_busy, true);
OSStatus status = -1;
- SGRTimePitch *unit = atomic_load(&sg_pull);
- if (atomic_load(&sg_engaged) && unit && fitsUnit(data, frames, unit)) status = SGRTimePitchRender(unit, frames, data);
+ SGTimePitch *unit = atomic_load(&sg_pull);
+ if (atomic_load(&sg_engaged) && unit && fitsUnit(data, frames, unit)) status = SGTimePitchRender(unit, frames, data);
if (status != noErr) status = pullSource(source, timestamp, frames, data);
atomic_store(&sg_busy, false);
return status;
@@ -159,7 +159,7 @@ static OSStatus feed(void *refCon, AudioUnitRenderActionFlags *flags, const Audi
#pragma mark - the render thread: in place, the fallback
-static float sg_scratch[kSGRTimePitchMaxChannels][kSGRTimePitchMaxFrames];
+static float sg_scratch[kSGTimePitchMaxChannels][kSGTimePitchMaxFrames];
static inline float readSample(const void *data, UInt32 index, UInt32 bytes, BOOL isFloat, UInt32 fraction) {
if (bytes == 4) {
@@ -184,14 +184,14 @@ static inline void writeSample(void *data, UInt32 index, float value, UInt32 byt
}
}
-static void shiftInPlace(SGRTimePitch *unit, AudioUnitRenderActionFlags *flags, UInt32 frames, AudioBufferList *data) {
+static void shiftInPlace(SGTimePitch *unit, AudioUnitRenderActionFlags *flags, UInt32 frames, AudioBufferList *data) {
UInt32 formatFlags = atomic_load_explicit(&sg_hardware.flags, memory_order_relaxed);
UInt32 bytes = atomic_load_explicit(&sg_hardware.bytes, memory_order_relaxed);
- UInt32 channels = SGRTimePitchChannels(unit);
+ UInt32 channels = SGTimePitchChannels(unit);
BOOL isFloat = (formatFlags & kAudioFormatFlagIsFloat) != 0;
BOOL split = (formatFlags & kAudioFormatFlagIsNonInterleaved) != 0;
UInt32 fraction = (formatFlags & kLinearPCMFormatFlagsSampleFractionMask) >> kLinearPCMFormatFlagsSampleFractionShift;
- if (frames > kSGRTimePitchMaxFrames || (bytes != 2 && bytes != 4)) return;
+ if (frames > kSGTimePitchMaxFrames || (bytes != 2 && bytes != 4)) return;
if (split ? data->mNumberBuffers != channels : data->mNumberBuffers != 1 || data->mBuffers[0].mNumberChannels != channels) return;
for (UInt32 b = 0; b < data->mNumberBuffers; b++) {
if (!data->mBuffers[b].mData || data->mBuffers[b].mDataByteSize < frames * bytes * (split ? 1 : channels)) return;
@@ -199,7 +199,7 @@ static void shiftInPlace(SGRTimePitch *unit, AudioUnitRenderActionFlags *flags,
// Silence still goes through, so the sound the unit holds plays out rather than coming back later.
BOOL silent = (*flags & kAudioUnitRenderAction_OutputIsSilence) != 0;
- float *lanes[kSGRTimePitchMaxChannels];
+ float *lanes[kSGTimePitchMaxChannels];
BOOL direct = split && isFloat && bytes == 4 && !silent;
for (UInt32 c = 0; c < channels; c++) {
if (direct) {
@@ -212,7 +212,7 @@ static void shiftInPlace(SGRTimePitch *unit, AudioUnitRenderActionFlags *flags,
lanes[c][i] = silent ? 0 : readSample(source, split ? i : i * channels + c, bytes, isFloat, fraction);
}
}
- if (!SGRTimePitchProcess(unit, lanes, frames) || direct) return;
+ if (!SGTimePitchProcess(unit, lanes, frames) || direct) return;
for (UInt32 c = 0; c < channels; c++) {
void *target = data->mBuffers[split ? c : 0].mData;
for (UInt32 i = 0; i < frames; i++) writeSample(target, split ? i : i * channels + c, lanes[c][i], bytes, isFloat, fraction);
@@ -225,7 +225,7 @@ static OSStatus rendered(void *refCon, AudioUnitRenderActionFlags *flags, const
if (!(*flags & kAudioUnitRenderAction_PostRender) || bus != 0 || !data || !data->mNumberBuffers || !frames) return noErr;
if (tapped() || !atomic_load(&sg_engaged)) return noErr;
atomic_store(&sg_busy, true);
- SGRTimePitch *unit = atomic_load(&sg_inPlace);
+ SGTimePitch *unit = atomic_load(&sg_inPlace);
if (atomic_load(&sg_engaged) && unit) shiftInPlace(unit, flags, frames, data);
atomic_store(&sg_busy, false);
return noErr;
@@ -325,7 +325,7 @@ static void disengage(void) {
// The unit for the output's format and the way in use, made when there is none or the format changed. A
// replaced one is never freed: the render thread may still hold it, and a format change is rare.
-static SGRTimePitch *unitForFormat(void) {
+static SGTimePitch *unitForFormat(void) {
BOOL pull = tapped();
Format *format = pull ? &sg_client : &sg_hardware;
double rate;
@@ -342,17 +342,17 @@ static SGRTimePitch *unitForFormat(void) {
return NULL;
}
}
- if (rate <= 0 || channels < 1 || channels > kSGRTimePitchMaxChannels) return NULL;
- _Atomic(SGRTimePitch *) *slot = pull ? &sg_pull : &sg_inPlace;
+ if (rate <= 0 || channels < 1 || channels > kSGTimePitchMaxChannels) return NULL;
+ _Atomic(SGTimePitch *) *slot = pull ? &sg_pull : &sg_inPlace;
pthread_mutex_lock(&sg_buildLock);
- SGRTimePitch *unit = atomic_load(slot);
- if (!unit || SGRTimePitchSampleRate(unit) != rate || SGRTimePitchChannels(unit) != channels) {
+ SGTimePitch *unit = atomic_load(slot);
+ if (!unit || SGTimePitchSampleRate(unit) != rate || SGTimePitchChannels(unit) != channels) {
BOOL wasEngaged = atomic_load(&sg_engaged);
disengage();
- unit = SGRTimePitchCreate(rate, channels, pull ? pullForUnit : NULL, NULL);
+ unit = SGTimePitchCreate(rate, channels, pull ? pullForUnit : NULL, NULL);
if (unit) {
- SGRTimePitchSetRate(unit, pull ? sg_speed : 1);
- SGRTimePitchSetSemitones(unit, sg_semitones);
+ SGTimePitchSetRate(unit, pull ? sg_speed : 1);
+ SGTimePitchSetSemitones(unit, sg_semitones);
}
atomic_store(slot, unit);
SGLog(@"redesign speed: %@ %@ for %.0f Hz, %u channels", unit ? @"a unit" : @"no unit", pull ? @"in the chain" : @"in place", rate, (unsigned)channels);
@@ -363,11 +363,11 @@ static SGRTimePitch *unitForFormat(void) {
}
static void report(void) {
- SGRTimePitch *unit = atomic_load(tapped() ? &sg_pull : &sg_inPlace);
+ SGTimePitch *unit = atomic_load(tapped() ? &sg_pull : &sg_inPlace);
if (!unit) return;
SGLog(@"redesign speed: %.2fx, %+.0f st, %u underruns, %u failures, largest pull %u, %.1f s of input", sg_speed, sg_semitones,
- SGRTimePitchUnderruns(unit), SGRTimePitchFailures(unit), SGRTimePitchLargestPull(unit),
- SGRTimePitchConsumed(unit) / SGRTimePitchSampleRate(unit));
+ SGTimePitchUnderruns(unit), SGTimePitchFailures(unit), SGTimePitchLargestPull(unit),
+ SGTimePitchConsumed(unit) / SGTimePitchSampleRate(unit));
}
// Puts the unit in or takes it out for the current speed and pitch.
@@ -382,49 +382,49 @@ static void apply(void) {
disengage();
});
}
- SGRTimePitch *unit = unitForFormat();
+ SGTimePitch *unit = unitForFormat();
if (!unit) {
static int logged;
if (!normal && logged++ < 3) SGLog(@"redesign speed: Spotify's output has not started, nothing to change yet");
return;
}
- SGRTimePitchSetRate(unit, tapped() ? sg_speed : 1);
- SGRTimePitchSetSemitones(unit, sg_semitones);
+ SGTimePitchSetRate(unit, tapped() ? sg_speed : 1);
+ SGTimePitchSetSemitones(unit, sg_semitones);
if (!normal && !atomic_load(&sg_engaged)) {
disengage();
- SGRTimePitchReset(unit);
+ SGTimePitchReset(unit);
atomic_store(&sg_engaged, true);
}
}
#pragma mark - the menu's calls
-double SGRPlayerSpeed(void) {
+double SGPlayerSpeed(void) {
return sg_speed;
}
-BOOL SGRPlayerSpeedAllowed(void) {
+BOOL SGPlayerSpeedAllowed(void) {
return tapped();
}
-void SGRSetPlayerSpeed(double speed) {
+void SGSetPlayerSpeed(double speed) {
if (!tapped()) return;
sg_speed = (float)speed;
storeFloat(&sg_speedBits, sg_speed);
apply();
}
-float SGRPlayerPitch(void) {
+float SGPlayerPitch(void) {
return sg_semitones;
}
-void SGRSetPlayerPitch(float semitones) {
+void SGSetPlayerPitch(float semitones) {
if (!sg_startOutput && !tapped()) return;
sg_semitones = semitones;
apply();
}
-BOOL SGRPlayerPitchAvailable(void) {
+BOOL SGPlayerPitchAvailable(void) {
return sg_startOutput != NULL || tapped();
}
@@ -439,7 +439,6 @@ BOOL SGRPlayerPitchAvailable(void) {
%end
%ctor {
- if (!SGRedesignedUI()) return;
storeFloat(&sg_speedBits, 1);
if (!SGRebindImport("AudioUnitSetProperty", setProperty, (void **)&sg_setProperty) || !sg_setProperty) {
sg_setProperty = NULL;
diff --git a/tweak/Sources/Redesigned/Player/PlayerMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
similarity index 73%
rename from tweak/Sources/Redesigned/Player/PlayerMenu.x
rename to tweak/Sources/Shared/Player/SpeedPitchMenu.x
index 68f5d95d..691422ab 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMenu.x
+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
@@ -1,6 +1,6 @@
-// The player's more menu gets Speed and pitch: one row in Spotify's own context menu sheet that opens,
-// right there in the sheet, onto two sliders, the playback speed and the pitch (PlayerSpeedPitch.x
-// applies them).
+// The player's more menu gets Speed and pitch, under either look: one row in Spotify's own context menu
+// sheet that opens, right there in the sheet, onto two sliders, the playback speed and the pitch
+// (SpeedPitch.x applies them).
//
// The sheet is Spotify's ContextMenu_InternalImpl.ContextMenuViewController, a table of its rows
// (ContextMenuTableView, sized to its content). Its rows come from Swift item factories with no way in,
@@ -10,21 +10,68 @@
// follow.
//
// Only the menu the player's more button opens gets it: the button (id=Context menu,
-// trees/lyrics.txt:183, an Encore Tertiary button) is watched from PlayerHeader.x, and a menu shown
-// within a few seconds of its tap, or presented from a now playing controller, is the player's. The
-// first time, the menu's structure is logged, since no recorded tree shows it yet.
+// trees/lyrics.txt:183, an Encore Tertiary button) is watched from the redesign's PlayerHeader.x, and a
+// menu shown within a few seconds of its tap, or presented from a now playing controller, is the
+// player's. Under the native look nothing hands the button over, so the block rides on the second test
+// alone, the presenter being Spotify's own now playing controller. The first time, the menu's structure
+// is logged, since no recorded tree shows it yet.
+//
+// The block is drawn from its own measures and type (below), not from the redesign's Kit, so it sits on
+// Spotify's sheet under either look.
//
// The block keeps whether it was open for the rest of the session; speed and pitch last until Spotify
// quits.
+#import <CoreText/SFNTLayoutTypes.h>
#import <objc/runtime.h>
#import "Core/SGCore.h"
-#import "Redesigned/Kit/SGRKit.h"
-#import "Redesigned/Haptics/Haptics.h"
-#import "Player.h"
+#import "Shared/Haptics/Haptics.h"
+#import "SpeedPitch.h"
// A menu this soon after the more button's tap is the player's.
static const NSTimeInterval kMenuAfterTap = 3;
static const CGFloat kRowHeight = 56, kSliderBlockHeight = 72, kPanelBottom = 12;
+// The block's own measures and type, so it stands on Spotify's sheet under either look rather than on
+// the redesign's Kit: the sheet's side margin, the gap everything else is a multiple of, and a spring
+// that settles without overshooting.
+static const CGFloat kSideMargin = 16, kGrid = 8;
+static const NSTimeInterval kOpenDuration = 0.45;
+
+static UIColor *primary(void) {
+ return UIColor.whiteColor;
+}
+
+// White at the weight the sheet's own secondary text is, a step firmer with Increase Contrast.
+static UIColor *secondary(void) {
+ return [UIColor colorWithWhite:1 alpha:UIAccessibilityDarkerSystemColorsEnabled() ? 0.80 : 0.65];
+}
+
+// The system font at a text style's size, which stops growing past `largest` so the row still fits.
+static UIFont *font(UIFontTextStyle style, UIFontWeight weight, UIContentSizeCategory largest) {
+ UIContentSizeCategory current = UIApplication.sharedApplication.preferredContentSizeCategory;
+ if (largest && UIContentSizeCategoryCompareToCategory(current, largest) == NSOrderedDescending) current = largest;
+ UITraitCollection *traits = [UITraitCollection traitCollectionWithPreferredContentSizeCategory:current];
+ CGFloat size = [UIFont preferredFontForTextStyle:style compatibleWithTraitCollection:traits].pointSize;
+ return [UIFont systemFontOfSize:size weight:weight];
+}
+
+// Digits of one width, so a value does not shuffle as it counts.
+static UIFont *monospacedDigits(UIFont *base) {
+ if (!base) return nil;
+ NSArray *features = @[@{UIFontFeatureTypeIdentifierKey: @(kNumberSpacingType), UIFontFeatureSelectorIdentifierKey: @(kMonospacedNumbersSelector)}];
+ UIFontDescriptor *descriptor = [base.fontDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorFeatureSettingsAttribute: features}];
+ return [UIFont fontWithDescriptor:descriptor size:base.pointSize];
+}
+
+static void animateOpen(void (^animations)(void), void (^completion)(BOOL finished)) {
+ if (UIAccessibilityIsReduceMotionEnabled()) {
+ [UIView performWithoutAnimation:animations];
+ if (completion) completion(YES);
+ return;
+ }
+ [UIView animateWithDuration:kOpenDuration delay:0 usingSpringWithDamping:1 initialSpringVelocity:0
+ options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
+ animations:animations completion:completion];
+}
static const float kMinSpeed = 0.5f, kMaxSpeed = 2, kSpeedStep = 0.05f;
static const float kMaxPitch = 12;
// Speed is applied at most this often while the slider moves.
@@ -36,12 +83,12 @@ static char kBlockKey, kDecidedKey, kWatchedKey;
#pragma mark - the block
-@interface SGRSpeedPitchView : UIView
+@interface SGSpeedPitchView : UIView
@property (nonatomic, weak) UITableView *table;
@property (nonatomic) BOOL inFooter;
@end
-@implementation SGRSpeedPitchView {
+@implementation SGSpeedPitchView {
UIControl *_row;
UIImageView *_icon, *_chevron;
UILabel *_title, *_summary;
@@ -68,8 +115,8 @@ static UILabel *makeLabel(UIFont *font, UIColor *color) {
- (UIButton *)valueButton:(SEL)reset {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
- button.titleLabel.font = SGRMonospacedDigitsFont(SGRFont(UIFontTextStyleSubheadline, UIFontWeightSemibold, UIContentSizeCategoryExtraLarge));
- button.tintColor = SGRPrimary();
+ button.titleLabel.font = monospacedDigits(font(UIFontTextStyleSubheadline, UIFontWeightSemibold, UIContentSizeCategoryExtraLarge));
+ button.tintColor = primary();
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
button.accessibilityHint = @"Resets it";
[button addTarget:self action:reset forControlEvents:UIControlEventTouchUpInside];
@@ -78,7 +125,7 @@ static UILabel *makeLabel(UIFont *font, UIColor *color) {
// A glyph centred in a box of one size, so both sliders' tracks start and end at the same x.
static UIImage *endImage(NSString *name, CGFloat size) {
- UIImage *glyph = [symbol(name, size, UIImageSymbolWeightMedium) imageWithTintColor:SGRSecondary() renderingMode:UIImageRenderingModeAlwaysOriginal];
+ UIImage *glyph = [symbol(name, size, UIImageSymbolWeightMedium) imageWithTintColor:secondary() renderingMode:UIImageRenderingModeAlwaysOriginal];
CGSize box = CGSizeMake(24, 24);
return [[[UIGraphicsImageRenderer alloc] initWithSize:box] imageWithActions:^(UIGraphicsImageRendererContext *context) {
[glyph drawAtPoint:CGPointMake((box.width - glyph.size.width) / 2, (box.height - glyph.size.height) / 2)];
@@ -97,7 +144,7 @@ static UIImage *endImage(NSString *name, CGFloat size) {
slider.minimumValueImage = endImage(minImage, 13);
slider.maximumValueImage = endImage(maxImage, 17);
UIView *tick = [UIView new];
- tick.backgroundColor = SGRSecondary();
+ tick.backgroundColor = secondary();
tick.layer.cornerRadius = 1;
tick.userInteractionEnabled = NO;
tick.tag = (NSInteger)(normal * 1000);
@@ -132,14 +179,14 @@ static void placeTick(UISlider *slider) {
[self addSubview:_row];
_icon = [[UIImageView alloc] initWithImage:symbol(@"slider.horizontal.3", 20, UIImageSymbolWeightRegular)];
- _icon.tintColor = SGRSecondary();
+ _icon.tintColor = secondary();
_icon.contentMode = UIViewContentModeCenter;
- _title = makeLabel(SGRFont(UIFontTextStyleBody, UIFontWeightRegular, UIContentSizeCategoryExtraLarge), SGRPrimary());
+ _title = makeLabel(font(UIFontTextStyleBody, UIFontWeightRegular, UIContentSizeCategoryExtraLarge), primary());
_title.text = @"Speed and pitch";
- _summary = makeLabel(SGRMonospacedDigitsFont(SGRFont(UIFontTextStyleSubheadline, UIFontWeightRegular, UIContentSizeCategoryExtraLarge)), SGRSecondary());
+ _summary = makeLabel(monospacedDigits(font(UIFontTextStyleSubheadline, UIFontWeightRegular, UIContentSizeCategoryExtraLarge)), secondary());
_summary.textAlignment = NSTextAlignmentRight;
_chevron = [[UIImageView alloc] initWithImage:symbol(@"chevron.down", 13, UIImageSymbolWeightSemibold)];
- _chevron.tintColor = SGRSecondary();
+ _chevron.tintColor = secondary();
_chevron.contentMode = UIViewContentModeCenter;
for (UIView *view in @[_icon, _title, _summary, _chevron]) {
view.userInteractionEnabled = NO;
@@ -148,10 +195,10 @@ static void placeTick(UISlider *slider) {
_panel = [UIView new];
[self addSubview:_panel];
- UIFont *nameFont = SGRFont(UIFontTextStyleSubheadline, UIFontWeightRegular, UIContentSizeCategoryExtraLarge);
- _speedName = makeLabel(nameFont, SGRSecondary());
+ UIFont *nameFont = font(UIFontTextStyleSubheadline, UIFontWeightRegular, UIContentSizeCategoryExtraLarge);
+ _speedName = makeLabel(nameFont, secondary());
_speedName.text = @"Speed";
- _pitchName = makeLabel(nameFont, SGRSecondary());
+ _pitchName = makeLabel(nameFont, secondary());
_pitchName.text = @"Pitch";
_speedValue = [self valueButton:@selector(resetSpeed)];
_pitchValue = [self valueButton:@selector(resetPitch)];
@@ -171,15 +218,15 @@ static void placeTick(UISlider *slider) {
- (void)layoutSubviews {
[super layoutSubviews];
- CGFloat width = self.bounds.size.width, side = SGRSideMargin;
+ CGFloat width = self.bounds.size.width, side = kSideMargin;
_row.frame = CGRectMake(0, 0, width, kRowHeight);
_icon.frame = CGRectMake(side, (kRowHeight - 24) / 2, 24, 24);
_chevron.frame = CGRectMake(width - side - 20, (kRowHeight - 20) / 2, 20, 20);
CGFloat titleX = side + 24 + side;
- CGFloat titleWidth = MIN([_title sizeThatFits:CGSizeMake(CGFLOAT_MAX, kRowHeight)].width, CGRectGetMinX(_chevron.frame) - titleX - SGRGrid);
+ CGFloat titleWidth = MIN([_title sizeThatFits:CGSizeMake(CGFLOAT_MAX, kRowHeight)].width, CGRectGetMinX(_chevron.frame) - titleX - kGrid);
_title.frame = CGRectMake(titleX, 0, titleWidth, kRowHeight);
- CGFloat summaryX = CGRectGetMaxX(_title.frame) + SGRGrid;
- _summary.frame = CGRectMake(summaryX, 0, MAX(0, CGRectGetMinX(_chevron.frame) - SGRGrid - summaryX), kRowHeight);
+ 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 + kPanelBottom);
CGFloat y = 0;
@@ -211,9 +258,9 @@ static NSString *pitchText(float pitch) {
// What the player and the pitch say now, onto the controls (not while a finger is on one).
- (void)refresh {
- BOOL speedAllowed = SGRPlayerSpeedAllowed(), pitchAvailable = SGRPlayerPitchAvailable();
- if (!_speed.tracking) _shownSpeed = snappedSpeed(SGRPlayerSpeed());
- if (!_pitch.tracking) _shownPitch = SGRPlayerPitch();
+ BOOL speedAllowed = SGPlayerSpeedAllowed(), pitchAvailable = SGPlayerPitchAvailable();
+ if (!_speed.tracking) _shownSpeed = snappedSpeed(SGPlayerSpeed());
+ if (!_pitch.tracking) _shownPitch = SGPlayerPitch();
_speed.value = _shownSpeed;
_pitch.value = _shownPitch;
_speed.enabled = speedAllowed;
@@ -224,7 +271,7 @@ static NSString *pitchText(float pitch) {
}
- (void)showValues {
- BOOL speedAllowed = SGRPlayerSpeedAllowed(), pitchAvailable = SGRPlayerPitchAvailable();
+ BOOL speedAllowed = SGPlayerSpeedAllowed(), pitchAvailable = SGPlayerPitchAvailable();
[UIView performWithoutAnimation:^{
[_speedValue setTitle:speedAllowed ? speedText(_shownSpeed) : @"Unavailable here" forState:UIControlStateNormal];
[_pitchValue setTitle:pitchAvailable ? [pitchText(_shownPitch) stringByAppendingString:_shownPitch ? @" st" : @""] : @"Unavailable" forState:UIControlStateNormal];
@@ -233,8 +280,8 @@ static NSString *pitchText(float pitch) {
}];
_speedValue.enabled = speedAllowed && _shownSpeed != 1;
_pitchValue.enabled = pitchAvailable && _shownPitch != 0;
- [_speedValue setTitleColor:SGRPrimary() forState:UIControlStateDisabled];
- [_pitchValue setTitleColor:SGRPrimary() forState:UIControlStateDisabled];
+ [_speedValue setTitleColor:primary() forState:UIControlStateDisabled];
+ [_pitchValue setTitleColor:primary() forState:UIControlStateDisabled];
_speed.accessibilityValue = speedAllowed ? speedText(_shownSpeed) : @"Unavailable";
_pitch.accessibilityValue = _shownPitch == 0 ? @"Original pitch" : [NSString stringWithFormat:@"%.0f semitones %@", fabsf(_shownPitch), _shownPitch > 0 ? @"up" : @"down"];
@@ -264,8 +311,8 @@ static NSString *pitchText(float pitch) {
if (sg_open) [self refresh];
UITableView *table = self.table;
CGRect frame = self.frame;
- frame.size.height = [SGRSpeedPitchView heightOpen:sg_open];
- SGRAnimate(SGRMotionLayout, ^{
+ frame.size.height = [SGSpeedPitchView heightOpen:sg_open];
+ animateOpen(^{
[table beginUpdates];
self.frame = frame;
if (self.inFooter) table.tableFooterView = self;
@@ -280,37 +327,37 @@ static NSString *pitchText(float pitch) {
UIView *sheet = table.superview;
for (int i = 0; sheet && i < 4; i++, sheet = sheet.superview) [sheet setNeedsLayout];
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, sg_open ? _speed : nil);
- SGLog(@"redesign menu: speed and pitch %@, table %.0f tall showing %.0f", sg_open ? @"opened" : @"closed", table.contentSize.height, table.bounds.size.height);
+ SGLog(@"speed and pitch: speed and pitch %@, table %.0f tall showing %.0f", sg_open ? @"opened" : @"closed", table.contentSize.height, table.bounds.size.height);
}
- (void)sendSpeed {
_speedPending = NO;
_speedSentAt = CACurrentMediaTime();
- SGRSetPlayerSpeed(_shownSpeed);
+ SGSetPlayerSpeed(_shownSpeed);
}
- (void)sliderMoved:(UISlider *)slider {
if (slider == _speed) {
float speed = snappedSpeed(slider.value);
if (speed == _shownSpeed) return;
- if (speed == 1 || _shownSpeed == 1) SGRPlayFeedback(SGRFeedbackDetent);
+ if (speed == 1 || _shownSpeed == 1) SGPlayFeedback(SGFeedbackDetent);
_shownSpeed = speed;
NSTimeInterval wait = kSpeedInterval - (CACurrentMediaTime() - _speedSentAt);
if (wait <= 0) [self sendSpeed];
else if (!_speedPending) {
_speedPending = YES;
- __weak SGRSpeedPitchView *weakSelf = self;
+ __weak SGSpeedPitchView *weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(wait * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- SGRSpeedPitchView *view = weakSelf;
+ SGSpeedPitchView *view = weakSelf;
if (view && view->_speedPending) [view sendSpeed];
});
}
} else {
float pitch = roundf(slider.value);
if (pitch == _shownPitch) return;
- if (pitch == 0 || _shownPitch == 0) SGRPlayFeedback(SGRFeedbackDetent);
+ if (pitch == 0 || _shownPitch == 0) SGPlayFeedback(SGFeedbackDetent);
_shownPitch = pitch;
- SGRSetPlayerPitch(pitch);
+ SGSetPlayerPitch(pitch);
}
[self showValues];
}
@@ -318,7 +365,7 @@ static NSString *pitchText(float pitch) {
- (void)sliderReleased:(UISlider *)slider {
if (slider == _speed) {
slider.value = _shownSpeed;
- if (_speedPending || snappedSpeed(SGRPlayerSpeed()) != _shownSpeed) [self sendSpeed];
+ if (_speedPending || snappedSpeed(SGPlayerSpeed()) != _shownSpeed) [self sendSpeed];
} else {
slider.value = _shownPitch;
}
@@ -333,7 +380,7 @@ static NSString *pitchText(float pitch) {
- (void)resetPitch {
_shownPitch = 0;
- SGRSetPlayerPitch(0);
+ SGSetPlayerPitch(0);
[_pitch setValue:0 animated:YES];
[self showValues];
}
@@ -342,10 +389,10 @@ static NSString *pitchText(float pitch) {
#pragma mark - the player's more button
-@interface SGRMoreTapWatcher : NSObject <UIGestureRecognizerDelegate>
+@interface SGMoreTapWatcher : NSObject <UIGestureRecognizerDelegate>
@end
-@implementation SGRMoreTapWatcher
+@implementation SGMoreTapWatcher
- (void)tapped {
sg_moreTappedAt = CACurrentMediaTime();
}
@@ -354,10 +401,10 @@ static NSString *pitchText(float pitch) {
}
@end
-void SGRPlayerMenuWatchMoreButton(UIView *button) {
+void SGPlayerMenuWatchMoreButton(UIView *button) {
if (!button || objc_getAssociatedObject(button, &kWatchedKey)) return;
- static SGRMoreTapWatcher *watcher;
- if (!watcher) watcher = [SGRMoreTapWatcher new];
+ static SGMoreTapWatcher *watcher;
+ if (!watcher) watcher = [SGMoreTapWatcher new];
objc_setAssociatedObject(button, &kWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// An Encore button may read its touches through a gesture recognizer rather than as a control, so
// both are watched.
@@ -414,7 +461,7 @@ static BOOL isPlayerMenu(UIViewController *menu) {
if (tapped) sg_moreTappedAt = 0;
objc_setAssociatedObject(menu, &kDecidedKey, @(ours), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
UIViewController *presenter = menu.navigationController.presentingViewController ?: menu.presentingViewController;
- SGLog(@"redesign menu: a context menu, %@ (tapped %d, presented by %@)", ours ? @"the player's" : @"not the player's", tapped,
+ SGLog(@"speed and pitch: a context menu, %@ (tapped %d, presented by %@)", ours ? @"the player's" : @"not the player's", tapped,
presenter ? NSStringFromClass(presenter.class) : @"nothing");
return ours;
}
@@ -423,10 +470,10 @@ static void install(UIViewController *menu) {
UIView *root = menu.viewIfLoaded;
if (!root || !isPlayerMenu(menu)) return;
UITableView *table = findTable(root, 0);
- SGRSpeedPitchView *block = objc_getAssociatedObject(menu, &kBlockKey);
+ SGSpeedPitchView *block = objc_getAssociatedObject(menu, &kBlockKey);
if (!table) {
static int logged;
- if (logged++ < 3) SGLog(@"redesign menu: no table in %@, speed and pitch left out", NSStringFromClass(menu.class));
+ if (logged++ < 3) SGLog(@"speed and pitch: no table in %@, speed and pitch left out", NSStringFromClass(menu.class));
return;
}
CGFloat width = table.bounds.size.width;
@@ -437,18 +484,18 @@ static void install(UIViewController *menu) {
described = YES;
NSMutableString *structure = [NSMutableString string];
logStructure(root, 0, structure);
- SGLog(@"redesign menu: table %@ header %@ footer %@, structure:%@", NSStringFromClass(table.class),
+ SGLog(@"speed and pitch: table %@ header %@ footer %@, structure:%@", NSStringFromClass(table.class),
table.tableHeaderView ? NSStringFromClass(table.tableHeaderView.class) : @"none",
table.tableFooterView ? NSStringFromClass(table.tableFooterView.class) : @"none", structure);
}
BOOL headerFree = !table.tableHeaderView || table.tableHeaderView.bounds.size.height < 1;
BOOL footerFree = !table.tableFooterView || table.tableFooterView.bounds.size.height < 1;
if (!headerFree && !footerFree) {
- SGLog(@"redesign menu: the table's header and footer are both Spotify's, speed and pitch left out");
+ SGLog(@"speed and pitch: the table's header and footer are both Spotify's, speed and pitch left out");
objc_setAssociatedObject(menu, &kDecidedKey, @NO, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return;
}
- block = [[SGRSpeedPitchView alloc] initWithFrame:CGRectMake(0, 0, width, [SGRSpeedPitchView heightOpen:sg_open])];
+ block = [[SGSpeedPitchView alloc] initWithFrame:CGRectMake(0, 0, width, [SGSpeedPitchView heightOpen:sg_open])];
block.table = table;
block.inFooter = !headerFree;
objc_setAssociatedObject(menu, &kBlockKey, block, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
@@ -460,7 +507,7 @@ static void install(UIViewController *menu) {
// Spotify replaced the view, or the table changed width: put it back at the table's width.
UIView *placed = block.inFooter ? table.tableFooterView : table.tableHeaderView;
if (placed != block || fabs(block.frame.size.width - width) > 0.5) {
- block.frame = CGRectMake(0, block.frame.origin.y, width, [SGRSpeedPitchView heightOpen:sg_open]);
+ block.frame = CGRectMake(0, block.frame.origin.y, width, [SGSpeedPitchView heightOpen:sg_open]);
if (block.inFooter) table.tableFooterView = block;
else table.tableHeaderView = block;
[table invalidateIntrinsicContentSize];
@@ -475,13 +522,12 @@ static void install(UIViewController *menu) {
- (void)viewDidAppear:(BOOL)animated {
%orig;
- SGRSpeedPitchView *block = objc_getAssociatedObject(self, &kBlockKey);
+ SGSpeedPitchView *block = objc_getAssociatedObject(self, &kBlockKey);
[block refresh];
}
%end
%ctor {
- if (!SGRedesignedUI()) return;
%init;
SGRequireClasses(@[@"_TtC24ContextMenu_InternalImpl25ContextMenuViewController"]);
}