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 Lyrics page previews its styles and opens their sliders in glass
My-Name-Is-Jeff17e27c3ae6df
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 9d316dd2..60827464 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -84,7 +84,9 @@ Shared:Lyrics/ the lyrics engine for the redesign's Apple Music style lyrics and the lock screen: lines read fromcolor-lyrics and the player's clock (KaraokeSource.x), words timed by estimate inside Spotify's linetimes (KaraokeTiming.m, which splits Thai, Lao, Khmer and Burmese at the system's dictionary words), which line to name where two voices sing at once (the one that came in first,- for the lock screen and the Live Activity), and the Lyrics page's parts+ for the lock screen and the Live Activity), and the Lyrics page's parts. Lines are kept in time order+ whatever order a source lists them in. With EeveeSpotify injected (SGEeveeSpotifyInjected), its lyrics+ answer Spotify's requests and the mod's sources and its own requests stand asideLyricsSources/ the sources lyrics come from, asked in the order the Lyrics page puts them in and merged into thebest answer (LyricsSources.m, the list to drag in LyricsSourcesPage.m): Apple Music's TTML fromBiniLyrics.m and Unison.m, read by SGTTML.m, which carries a second voice and the@@ -295,7 +297,11 @@ Redesigned:that breathe and fill over its length on a Core Animation timeline laid against the song's clock; anda line's pronunciation (under the words it spells) and translation, switched on from a glass button inthe lyrics' corner that shows only for a song that has them, in the order of sizes the Lyrics page sets- (LyricsText.h). Laid out on the Mac against harness/lyrics/+ (LyricsText.h). A word held 0.9 s or more glows and its letters rise in a wave as the sweep reaches+ them. The size, the room between lines, the blur, the glow and the wave are the Lyrics page's look+ (LyricsLook.h): five presets and a sheet of sliders, applied at once to every view, under a live+ preview of the view playing a song of its own (LyricsLookSettings.m). Laid out on the Mac against+ harness/lyrics/; the page against harness/lyrics-page/Home/ Home decluttered to music on black (an allow list of its sections: shortcuts, the DJ without its heading andtranscript, the shelves of cards), a large title where the filter pills were with the avatar at the trailingedge, the shelves' headings at the Music app's size, each shortcut tile's cover run across it blurred@@ -385,7 +391,8 @@ file is gone), and the App icon. Everything on the page applies after a restart.(Settings/SGGlowSwitch), its ⓘ says what it changes, and flipping it offers to restart Spotify.The pages show only what the stored look has: a page opened after flipping the switch already showswhat the restart will bring. Then a card of parts. Navbar: the tab editor of the stored look, each with-its own list of tabs. Lyrics, on the main page of its own: Sing first, then the ordered list of lyrics sources,+its own list of tabs. Lyrics, on the main page of its own: in the redesign a live preview of the lyrics first, with the presets of their look+under it and their sliders in a sheet (Text size, Line spacing, Blur, Glow, Wave), applying at once; then Sing, then the ordered list of lyrics sources,lyrics for every track, naming the source in the redesign, the lock screen, and glass lyrics in the native look; inthe redesign also which of the lyrics, their pronunciation and their translation is set largest, and thetranslation's language. Sing, under either look, on the main page and as Lyrics' first row, the row reading out On,diff --git a/harness/lyrics-page/README.md b/harness/lyrics-page/README.mdnew file mode 100644index 00000000..de7c3386--- /dev/null+++ b/harness/lyrics-page/README.md@@ -0,0 +1,20 @@+# Lyrics page harness++The redesign's Lyrics page as `App/Pages.m` opens it (`Redesigned/Lyrics/LyricsLookSettings.m`): the preview+playing the sample song in the real lyrics view, the presets under it, the sliders' sheet, and one stand-in+section under them, on the real Settings/ framework. `../lyrics/stubs.m` stands in for the player.++ ./build.sh+ xcrun simctl install <udid> build/LyricsPageHarness.app+ xcrun simctl launch --console <udid> com.vojta.lyricspageharness -check 1+ xcrun simctl launch <udid> com.vojta.lyricspageharness -preset 4 -sheet 1+ xcrun simctl io <udid> screenshot shot.png++`main.m` lists the arguments. `-check 1` taps the presets, opens the sheet and moves a slider, and checks+what the preview, the presets and the sliders read after each.++2026-10-05, iPhone 17 Pro on iOS 27.0: all checks pass; the sheet rests at half height under the preview,+which plays on undimmed.++What it does not cover: Spotify's navigation stack around the page, the other Lyrics rows, and a finger+on the sliders (the check sets their value as a drag would).diff --git a/harness/lyrics-page/build.sh b/harness/lyrics-page/build.shnew file mode 100755index 00000000..27d294c3--- /dev/null+++ b/harness/lyrics-page/build.sh@@ -0,0 +1,48 @@+#!/bin/sh+# build.sh: the redesign's Lyrics page (Redesigned/Lyrics/LyricsLookSettings.m) for the simulator: its preview,+# the real lyrics view playing the sample song, the presets and the sliders' sheet, on the real Settings/+# framework, with ../lyrics/stubs.m standing in for the player.+set -e+HERE=$(cd "$(dirname "$0")" && pwd)+SRC=$(cd "$HERE/../../tweak/Sources" && pwd)+APP=$HERE/build/LyricsPageHarness.app+rm -rf "$HERE/build"; mkdir -p "$APP"++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 -DSG_HARNESS_SETTINGS \+ -I"$SRC" -I"$SRC/Redesigned/Lyrics" -isysroot "$SDK" -Wall -Wno-deprecated-declarations \+ "$HERE/main.m" "$HERE/../scene.m" "$HERE/../lyrics/stubs.m" "$HERE/../sing/button/sing-stubs.m" \+ "$SRC"/Redesigned/Lyrics/LyricsLookSettings.m "$SRC"/Redesigned/Lyrics/LyricsLook.m \+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Redesigned/Lyrics/SGRSingButton.m \+ "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Shared/LyricsMeanings/Meanings.m \+ "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \+ "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRGlass.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/SGGlass.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreText -framework Foundation -framework Symbols \+ -o "$APP/LyricsPageHarness"++cat > "$APP/Info.plist" <<PLIST+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0"><dict>+<key>CFBundleExecutable</key><string>LyricsPageHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.lyricspageharness</string>+<key>CFBundleName</key><string>Lyrics page</string>+<key>CFBundleVersion</key><string>1</string>+<key>CFBundleShortVersionString</key><string>1.0</string>+<key>UIUserInterfaceStyle</key><string>Dark</string>+<key>UILaunchScreen</key><dict/>+<key>UIApplicationSceneManifest</key><dict>+ <key>UIApplicationSupportsMultipleScenes</key><false/>+ <key>UISceneConfigurations</key><dict>+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>+ <key>UISceneConfigurationName</key><string>Default</string>+ <key>UISceneDelegateClassName</key><string>SGRHarnessScene</string>+ </dict></array>+ </dict>+</dict>+</dict></plist>+PLIST+codesign -f -s - "$APP" >/dev/null 2>&1+echo "built $APP"diff --git a/harness/lyrics-page/main.m b/harness/lyrics-page/main.mnew file mode 100644index 00000000..26a467e4--- /dev/null+++ b/harness/lyrics-page/main.m@@ -0,0 +1,132 @@+// The lyrics page harness: the redesign's Lyrics page as App/Pages.m opens it, its preview playing the sample+// song in the real lyrics view, the presets under it and the sliders' sheet, with one stand-in section under them.+//+// Launch arguments (NSUserDefaults' argument domain):+// -preset N stores preset N before the page opens (0 Apple Music, 1 Large, 2 Compact, 3 Calm, 4 Vivid)+// -sheet S opens the sliders' sheet S seconds in, as a tap on its button would+// -check 1 asserts the page's behaviour (see runChecks), prints PASS and FAIL lines and quits with the+// number of failures+#import <UIKit/UIKit.h>+#import "Settings/SGModPage.h"+#import "Redesigned/Lyrics/LyricsLook.h"+#import "Redesigned/Lyrics/SGRKaraokeView.h"++static int sg_failures;++static void expect(BOOL ok, NSString *what) {+ printf("%s %s\n", ok ? "PASS" : "FAIL", what.UTF8String);+ fflush(stdout);+ if (!ok) sg_failures++;+}++static void after(double seconds, dispatch_block_t block) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);+}++static void collect(UIView *root, Class cls, NSMutableArray *into) {+ if ([root isKindOfClass:cls]) [into addObject:root];+ for (UIView *view in root.subviews) collect(view, cls, into);+}++static NSArray *find(UIView *root, Class cls) {+ NSMutableArray *found = [NSMutableArray array];+ collect(root, cls, found);+ return found;+}++// The preset buttons, in order.+static NSArray<UIButton *> *chipsOf(UIViewController *page) {+ return [page valueForKey:@"chips"];+}++static BOOL lit(UIButton *chip) {+ return (chip.accessibilityTraits & UIAccessibilityTraitSelected) != 0;+}++static void runChecks(UIViewController *page) {+ SGRKaraokeView *preview = [page valueForKey:@"preview"];+ NSArray<UIButton *> *chips = chipsOf(page);+ expect(chips.count == SGRLyricsLookPresetNames().count && lit(chips[0]), @"with nothing stored Apple Music is lit");+ expect([preview valueForKey:@"tops"] != nil && !preview.hidden, @"the preview plays its lines");+ UIView *header = ((UITableViewController *)page).tableView.tableHeaderView;+ expect(CGRectGetMaxY([chips[0] convertRect:chips[0].bounds toView:header]) < header.bounds.size.height,+ [NSString stringWithFormat:@"the header holds the preview and the presets (%.0f pt tall)", header.bounds.size.height]);++ [chips[1] sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];+ expect(lit(chips[1]) && !lit(chips[0]) && [[preview valueForKey:@"fontSize"] doubleValue] == 36,+ @"a tap on Large lights it and sets the preview's lines at 36 pt");++ UIButton *adjust = [page valueForKey:@"adjust"];+ // The fifth preset, past the edge of the strip on a phone, is scrolled into sight when it is picked.+ [chips.lastObject sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];+ [page.view layoutIfNeeded];+ UIScrollView *strip = [page valueForKey:@"strip"];+ after(0.6, ^{+ CGRect shown = [strip convertRect:chips.lastObject.bounds fromView:chips.lastObject];+ expect(CGRectContainsRect(strip.bounds, shown), @"a preset picked past the edge of the strip is scrolled into sight");+ });+ [adjust sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];+ after(1.2, ^{+ UINavigationController *nav = (UINavigationController *)page.presentedViewController;+ UITableViewController *sheet = (UITableViewController *)nav.topViewController;+ expect([nav isKindOfClass:UINavigationController.class] && [NSStringFromClass(sheet.class) isEqualToString:@"SGRLyricsStyleSheet"],+ @"the sliders' button opens the sheet");+ NSArray<UISlider *> *sliders = find(sheet.tableView, UISlider.class);+ expect(sliders.count == 5, [NSString stringWithFormat:@"the sheet has five sliders (%lu)", (unsigned long)sliders.count]);+ UISlider *spacing = nil;+ for (UISlider *slider in sliders) {+ if (slider.maximumValue == 40 && slider.minimumValue == 12) spacing = slider;+ }+ spacing.value = 34;+ [spacing sendActionsForControlEvents:UIControlEventValueChanged];+ expect([[preview valueForKey:@"lineGap"] doubleValue] == 34 && lit(adjust) && [adjust.accessibilityValue isEqualToString:@"Custom"],+ [NSString stringWithFormat:@"a slider moves the preview's lines apart (%@ pt) and the look reads Custom",+ [preview valueForKey:@"lineGap"]]);+ // A preset picked over the sheet is read back into its sliders.+ [chips[0] sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];+ [sheet.tableView layoutIfNeeded];+ UISlider *again = nil;+ for (UISlider *slider in find(sheet.tableView, UISlider.class)) {+ if (slider.maximumValue == 40 && slider.minimumValue == 12) again = slider;+ }+ expect(again.value == 24 && lit(chips[0]), [NSString stringWithFormat:@"Apple Music picked over the sheet puts its slider back to 24 (%.0f)", again.value]);+ after(0.8, ^{+ printf("%d failed\n", sg_failures);+ fflush(stdout);+ exit(sg_failures);+ });+ });+}++@interface SGHarnessDelegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++@implementation SGHarnessDelegate+- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options {+ NSUserDefaults *args = NSUserDefaults.standardUserDefaults;+ [args removeObjectForKey:SGRKeyLyricsLook]; // each launch starts from its own arguments+ if ([args objectForKey:@"preset"]) SGRSetLyricsLook(SGRLyricsLookPreset((NSUInteger)[args integerForKey:@"preset"]), nil);+ SGModSection *stand = SGSection(@"Sources", @[SGSwitchRow(@"Lyrics for every track", @"Even where Spotify has none", @"harness.everyTrack")]);+ UIViewController *page = SGRLyricsSettingsPage(@"Lyrics", SGRestartNote, @[stand]);+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:page];+ nav.navigationBar.prefersLargeTitles = NO;+ nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ self.window.rootViewController = nav;+ [self.window makeKeyAndVisible];+ if ([args objectForKey:@"sheet"]) {+ after([args doubleForKey:@"sheet"], ^{+ [(UIButton *)[page valueForKey:@"adjust"] sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];+ });+ }+ if ([args boolForKey:@"check"]) after(2.5, ^{ runChecks(page); }); // the preview measures its lines off the main thread+ return YES;+}+@end++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGHarnessDelegate.class));+ }+}diff --git a/harness/lyrics/build.sh b/harness/lyrics/build.shindex acf4a8bf..736508e1 100755--- a/harness/lyrics/build.sh+++ b/harness/lyrics/build.sh@@ -19,7 +19,7 @@ SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g ${OPT:--O0} \-I"$SRC" -I"$SRC/Redesigned/Lyrics" -isysroot "$SDK" -Wall -Wno-deprecated-declarations \"$HERE/main.m" "$HERE/../scene.m" "$HERE/stubs.m" \- "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m $( [ -f "$SRC"/Redesigned/Lyrics/LyricsText.m ] && echo "$SRC"/Redesigned/Lyrics/LyricsText.m ) "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m $( [ -f "$SRC"/Redesigned/Lyrics/LyricsText.m ] && echo "$SRC"/Redesigned/Lyrics/LyricsText.m ) $( [ -f "$SRC"/Redesigned/Lyrics/LyricsLook.m ] && echo "$SRC"/Redesigned/Lyrics/LyricsLook.m ) "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/AdBlock/Protobuf.m \"$SRC"/Shared/LyricsSources/SGTTML.m "$SRC"/Redesigned/Kit/SGRTokens.m \$( [ -f "$SRC"/Shared/LyricsMeanings/Meanings.m ] && echo "$SRC"/Shared/LyricsMeanings/Meanings.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m ) \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGGlass.m \diff --git a/harness/lyrics/stubs.m b/harness/lyrics/stubs.mindex af32308f..eb4dc6d4 100644--- a/harness/lyrics/stubs.m+++ b/harness/lyrics/stubs.m@@ -45,6 +45,8 @@ id SGKaraokeTrackFor(NSString *trackID) {track.artistName = [NSUserDefaults.standardUserDefaults stringForKey:@"artist"];return track;}+// lyrics-page links the real Settings/ framework, which has both.+#ifndef SG_HARNESS_SETTINGSid SGChoiceRow(NSString *title, NSString *subtitle, NSString *key, NSArray *choices, NSInteger fallback) { return nil; }UIViewController *SGTopController(void) {UIWindowScene *scene = (UIWindowScene *)UIApplication.sharedApplication.connectedScenes.anyObject;@@ -52,6 +54,7 @@ UIViewController *SGTopController(void) {while (top.presentedViewController) top = top.presentedViewController;return top;}+#endifstatic NSArray<SGKaraokeLine *> *sg_lines;static double sg_from = -1, sg_rate = 1, sg_pauseAt = -1, sg_holdFor = 0;diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex 90f23a58..77e22e0f 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -20,6 +20,7 @@#import "Shared/Haptics/Haptics.h"#import "Shared/LiveActivity/LiveActivity.h"#import "Redesigned/Lyrics/LyricsText.h"+#import "Redesigned/Lyrics/LyricsLook.h"#import "Redesigned/Navbar/Navbar.h"#import "Redesigned/NowPlayingBar/NowPlayingBar.h"#import "Redesigned/Kit/SGRAccent.h"@@ -98,6 +99,8 @@ static UIViewController *lyricsPage(void) {SGGeminiKeyRow()])];}[sections addObject:SGSection(nil, more)];+ // The redesign's page leads with its lyrics playing in the look the page sets, and that look's presets.+ if (redesigned) return SGRLyricsSettingsPage(@"Lyrics", @"The look applies at once. The settings below apply after you restart Spotify.", sections);return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:SGRestartNote sections:sections footer:nil];}diff --git a/tweak/Sources/Redesigned/Lyrics/LyricsLook.h b/tweak/Sources/Redesigned/Lyrics/LyricsLook.hnew file mode 100644index 00000000..8aab985d--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/LyricsLook.h@@ -0,0 +1,36 @@+// How the redesign's lyrics are set, from the Lyrics page: the size of the words, the room between two+// lines, how strongly the lines away from the one sung blur, and how strongly a held word glows and its+// letters wave. A preset sets all five, the sheet of sliders each one; they apply at once to every lyrics+// view there is, the Lyrics page's own preview among them (LyricsLookSettings.m).+#import <UIKit/UIKit.h>+#import "Shared/Lyrics/Lyrics.h"++// size and spacing in points; blur, glow and wave as shares of Apple Music's, 1 being theirs and 0 none.+typedef struct {+ CGFloat size, spacing, blur, glow, wave;+} SGRLyricsLook;++// The five as one dictionary; unset is the first preset, Apple Music's.+#define SGRKeyLyricsLook @"spotifyglass.redesign.lyricsLook"++// Posted on the main queue when the look changes; the object is whoever changed it, nil for none named.+extern NSNotificationName const SGRLyricsLookDidChangeNotification;++SGRLyricsLook SGRLyricsLookNow(void);+void SGRSetLyricsLook(SGRLyricsLook look, id changer);++// The presets, by name, Apple Music's first.+NSArray<NSString *> *SGRLyricsLookPresetNames(void);+SGRLyricsLook SGRLyricsLookPreset(NSUInteger index);+// The preset the look is, or -1 for a look of the sliders' own.+NSInteger SGRLyricsLookPresetIndex(SGRLyricsLook look);++// A few lines of the preview's own, words timed, one held long enough to glow and wave, and how long+// they take to come round again.+NSArray<SGKaraokeLine *> *SGRLyricsSampleLines(void);+NSInteger SGRLyricsSampleLength(void);++// LyricsLookSettings.m: the Lyrics page in the redesign, leading with the preview, the presets under it+// and their sliders in a sheet, then `sections`.+@class SGModSection;+UIViewController *SGRLyricsSettingsPage(NSString *title, NSString *intro, NSArray<SGModSection *> *sections);diff --git a/tweak/Sources/Redesigned/Lyrics/LyricsLook.m b/tweak/Sources/Redesigned/Lyrics/LyricsLook.mnew file mode 100644index 00000000..746c1f2b--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/LyricsLook.m@@ -0,0 +1,109 @@+// The lyrics' look as stored, its presets and the preview's lines. The page is LyricsLookSettings.m.+#import "LyricsLook.h"++NSNotificationName const SGRLyricsLookDidChangeNotification = @"spotifyglass.redesign.lyricsLookDidChange";++// The sliders' ranges, which a stored look is held to as well.+static const SGRLyricsLook kLeast = {22, 12, 0, 0, 0}, kMost = {40, 40, 2, 2, 2};++static SGRLyricsLook presets[] = {+ {30, 24, 1, 1, 1}, // Apple Music: its 30 pt lines, 24 pt apart+ {36, 28, 1, 1, 1}, // Large+ {25, 16, 1, 1, 1}, // Compact+ {30, 24, 0, 0, 0}, // Calm: every line sharp, and nothing held glows or waves+ {32, 26, 1.4, 1.6, 1.8}, // Vivid+};++NSArray<NSString *> *SGRLyricsLookPresetNames(void) {+ return @[@"Apple Music", @"Large", @"Compact", @"Calm", @"Vivid"];+}++SGRLyricsLook SGRLyricsLookPreset(NSUInteger index) {+ return presets[MIN(index, sizeof(presets) / sizeof(*presets) - 1)];+}++static CGFloat held(CGFloat value, CGFloat least, CGFloat most) {+ return isfinite(value) ? MAX(least, MIN(most, value)) : least;+}++static CGFloat stored(NSDictionary *look, NSString *name, CGFloat fallback, CGFloat least, CGFloat most) {+ id value = look[name];+ return [value isKindOfClass:NSNumber.class] ? held([value doubleValue], least, most) : fallback;+}++SGRLyricsLook SGRLyricsLookNow(void) {+ SGRLyricsLook look = presets[0];+ NSDictionary *saved = [NSUserDefaults.standardUserDefaults dictionaryForKey:SGRKeyLyricsLook];+ if (!saved) return look;+ look.size = stored(saved, @"size", look.size, kLeast.size, kMost.size);+ look.spacing = stored(saved, @"spacing", look.spacing, kLeast.spacing, kMost.spacing);+ look.blur = stored(saved, @"blur", look.blur, kLeast.blur, kMost.blur);+ look.glow = stored(saved, @"glow", look.glow, kLeast.glow, kMost.glow);+ look.wave = stored(saved, @"wave", look.wave, kLeast.wave, kMost.wave);+ return look;+}++void SGRSetLyricsLook(SGRLyricsLook look, id changer) {+ [NSUserDefaults.standardUserDefaults setObject:@{+ @"size": @(held(look.size, kLeast.size, kMost.size)),+ @"spacing": @(held(look.spacing, kLeast.spacing, kMost.spacing)),+ @"blur": @(held(look.blur, kLeast.blur, kMost.blur)),+ @"glow": @(held(look.glow, kLeast.glow, kMost.glow)),+ @"wave": @(held(look.wave, kLeast.wave, kMost.wave)),+ } forKey:SGRKeyLyricsLook];+ [NSNotificationCenter.defaultCenter postNotificationName:SGRLyricsLookDidChangeNotification object:changer];+}++// Equal to the slider's step, so a look slid back onto a preset's values reads as that preset again.+static BOOL same(CGFloat a, CGFloat b) {+ return fabs(a - b) < 0.01;+}++NSInteger SGRLyricsLookPresetIndex(SGRLyricsLook look) {+ for (NSUInteger i = 0; i < sizeof(presets) / sizeof(*presets); i++) {+ SGRLyricsLook preset = presets[i];+ if (same(look.size, preset.size) && same(look.spacing, preset.spacing) && same(look.blur, preset.blur)+ && same(look.glow, preset.glow) && same(look.wave, preset.wave)) return (NSInteger)i;+ }+ return -1;+}++#pragma mark - the preview's song++// Each word as [text, start, end] in ms; a line runs from its first word's start to its last word's end.+static SGKaraokeLine *sampleLine(NSArray<NSArray *> *timed) {+ NSMutableArray<SGKaraokeWord *> *words = [NSMutableArray array];+ for (NSArray *piece in timed) {+ SGKaraokeWord *word = [SGKaraokeWord new];+ word.text = piece[0];+ word.start = [piece[1] integerValue];+ word.end = [piece[2] integerValue];+ [words addObject:word];+ }+ SGKaraokeLine *line = [SGKaraokeLine new];+ line.words = words;+ line.start = words.firstObject.start;+ line.end = words.lastObject.end;+ line.timing = SGKaraokeTimingWords;+ return line;+}++// Words of the mod's own. The second line holds its last word for three seconds, so the glow and the wave+// show on every round.+NSArray<SGKaraokeLine *> *SGRLyricsSampleLines(void) {+ static NSArray<SGKaraokeLine *> *lines;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ lines = @[+ sampleLine(@[@[@"Light", @600, @1000], @[@"comes", @1000, @1400], @[@"over", @1400, @1800], @[@"the", @1800, @2000], @[@"water", @2000, @2900]]),+ sampleLine(@[@[@"hold", @3100, @3500], @[@"on", @3500, @3800], @[@"to", @3800, @4000], @[@"the", @4000, @4200], @[@"night", @4200, @7200]]),+ sampleLine(@[@[@"we", @7500, @7800], @[@"sing", @7800, @8300], @[@"it", @8300, @8500], @[@"louder", @8500, @9500]]),+ sampleLine(@[@[@"all", @9800, @10100], @[@"the", @10100, @10300], @[@"way", @10300, @10700], @[@"home", @10700, @12000]]),+ ];+ });+ return lines;+}++NSInteger SGRLyricsSampleLength(void) {+ return 13500; // a pause after the last line, then the first again+}diff --git a/tweak/Sources/Redesigned/Lyrics/LyricsLookSettings.m b/tweak/Sources/Redesigned/Lyrics/LyricsLookSettings.mnew file mode 100644index 00000000..152f538d--- /dev/null+++ b/tweak/Sources/Redesigned/Lyrics/LyricsLookSettings.m@@ -0,0 +1,290 @@+// The Lyrics page in the redesign leads with its lyrics playing: a live preview of the lines in the look+// the page sets, the presets under it as a row of glass buttons, and the sliders behind the button after them+// in a sheet that rests at half height without dimming the page, so the preview shows every change as+// it is made. The rest of the page is App/Pages.m's sections, under them.+#import "Core/SGCore.h"+#import "Settings/SGModPage.h"+#import "Settings/SGPageStyle.h"+#import "Redesigned/Kit/SGRTokens.h"+#import "LyricsLook.h"+#import "SGRKaraokeView.h"++static const CGFloat kPreviewHeight = 230, kCardRadius = 26;+static const CGFloat kChipHeight = 36, kChipGap = 8, kStripGap = 12, kStripPad = 6, kNoteGap = 14;++#pragma mark - the sliders++// A page of the five sliders, each storing as it moves. A preset picked on the page while the sheet is up+// is read back into them; their own changes are not, so a slider is never reloaded under the finger.+@interface SGRLyricsStyleSheet : SGModPage+@property (nonatomic, readonly) CGFloat fittedHeight; // the table's content once laid out, 0 before+@end++@implementation SGRLyricsStyleSheet {+ CGFloat _fitted;+}++// The sheet's own glass shows through, rather than the black every page is given.+- (void)viewDidLoad {+ [super viewDidLoad];+ self.tableView.backgroundColor = UIColor.clearColor;+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(lookChanged:) name:SGRLyricsLookDidChangeNotification object:nil];+}++// The sheet rests as tall as its sliders and note, measured once the table has laid them out.+- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ CGFloat height = self.tableView.contentSize.height;+ if (height <= 0 || height == _fitted) return;+ _fitted = height;+ [self.navigationController.sheetPresentationController animateChanges:^{+ [self.navigationController.sheetPresentationController invalidateDetents];+ }];+}++- (CGFloat)fittedHeight {+ return _fitted;+}++// Translucent cards, so the sheet reads as glass all through.+- (void)tableView:(UITableView *)table willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)path {+ cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.08];+}++- (void)lookChanged:(NSNotification *)note {+ if (note.object != self) [self.tableView reloadData];+}++- (void)close {+ [self dismissViewControllerAnimated:YES completion:nil];+}++@end++typedef void (^SGRLookChange)(SGRLyricsLook *look, double value);++static NSString *share(double value) {+ return value <= 0 ? @"Off" : [NSString stringWithFormat:@"%.0f%%", value * 100];+}++static NSString *points(double value) {+ return [NSString stringWithFormat:@"%.0f pt", value];+}++static SGModRow *lookSlider(NSString *title, double least, double most, double step, CGFloat (^read)(SGRLyricsLook look),+ SGRLookChange change, NSString *(^format)(double value), id __weak *changer) {+ return SGSliderRow(title, nil, least, most, step, ^double { return read(SGRLyricsLookNow()); }, ^(double value) {+ SGRLyricsLook look = SGRLyricsLookNow();+ change(&look, value);+ SGRSetLyricsLook(look, *changer);+ }, format);+}++static void presentStyleSheet(UIViewController *owner) {+ static __weak id sheetPage;+ NSArray<SGModRow *> *rows = @[+ lookSlider(@"Text size", 22, 40, 1, ^CGFloat(SGRLyricsLook l) { return l.size; },+ ^(SGRLyricsLook *l, double v) { l->size = v; }, ^NSString *(double v) { return points(v); }, &sheetPage),+ lookSlider(@"Line spacing", 12, 40, 2, ^CGFloat(SGRLyricsLook l) { return l.spacing; },+ ^(SGRLyricsLook *l, double v) { l->spacing = v; }, ^NSString *(double v) { return points(v); }, &sheetPage),+ lookSlider(@"Blur", 0, 2, 0.1, ^CGFloat(SGRLyricsLook l) { return l.blur; },+ ^(SGRLyricsLook *l, double v) { l->blur = v; }, ^NSString *(double v) { return share(v); }, &sheetPage),+ lookSlider(@"Glow", 0, 2, 0.1, ^CGFloat(SGRLyricsLook l) { return l.glow; },+ ^(SGRLyricsLook *l, double v) { l->glow = v; }, ^NSString *(double v) { return share(v); }, &sheetPage),+ lookSlider(@"Wave", 0, 2, 0.1, ^CGFloat(SGRLyricsLook l) { return l.wave; },+ ^(SGRLyricsLook *l, double v) { l->wave = v; }, ^NSString *(double v) { return share(v); }, &sheetPage),+ ];+ NSString *footer = @"Blur is how much the lines away from the one sung soften. Glow and Wave are how strongly a held "+ @"word glows and its letters rise. 100% is Apple Music's.";+ SGRLyricsStyleSheet *page = [[SGRLyricsStyleSheet alloc] initWithTitle:@"Lyrics Style" intro:nil+ sections:@[SGNotedSection(nil, rows, footer)] footer:nil];+ sheetPage = page;+ page.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemClose+ target:page action:@selector(close)];+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:page];+ nav.view.backgroundColor = UIColor.clearColor;+ // Outside Spotify's own stacks the sheet would take the system's appearance, light in light mode.+ nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ UISheetPresentationController *sheet = nav.sheetPresentationController;+ // As tall as the sliders, half the screen until they are measured, so the preview at the top of the page stays+ // in sight and undimmed, and its buttons live.+ NSString *fit = @"fit";+ __weak SGRLyricsStyleSheet *weakPage = page;+ sheet.detents = @[[UISheetPresentationControllerDetent customDetentWithIdentifier:fit resolver:^CGFloat(id<UISheetPresentationControllerDetentResolutionContext> context) {+ CGFloat measured = weakPage.fittedHeight;+ return measured > 0 ? MIN(measured + 56, context.maximumDetentValue * 0.6) : context.maximumDetentValue * 0.5;+ }]];+ sheet.largestUndimmedDetentIdentifier = fit;+ sheet.prefersGrabberVisible = YES;+ sheet.prefersScrollingExpandsWhenScrolledToEdge = NO; // a slider dragged near the top does not grow it+ [owner presentViewController:nav animated:YES completion:nil];+}++#pragma mark - the page++// Black text on a light accent, white on a dark one.+static UIColor *readableOn(UIColor *color) {+ CGFloat r = 0, g = 0, b = 0, a = 0;+ [color getRed:&r green:&g blue:&b alpha:&a];+ return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.55 ? UIColor.blackColor : UIColor.whiteColor;+}++static UIButtonConfiguration *chipConfiguration(NSString *title, NSString *symbol, BOOL chosen) {+ UIButtonConfiguration *config;+ if (@available(iOS 26.0, *)) {+ config = chosen ? [UIButtonConfiguration prominentGlassButtonConfiguration] : [UIButtonConfiguration glassButtonConfiguration];+ } else {+ config = chosen ? [UIButtonConfiguration filledButtonConfiguration] : [UIButtonConfiguration grayButtonConfiguration];+ }+ config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;+ if (chosen) config.baseBackgroundColor = SGRAccent();+ config.baseForegroundColor = chosen ? readableOn(SGRAccent()) : UIColor.whiteColor;+ config.contentInsets = NSDirectionalEdgeInsetsMake(0, 14, 0, 14);+ config.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{+ NSFontAttributeName: [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold]}];+ if (symbol) {+ config.image = [UIImage systemImageNamed:symbol];+ config.preferredSymbolConfigurationForImage = [UIImageSymbolConfiguration configurationWithPointSize:13 weight:UIImageSymbolWeightSemibold];+ config.imagePadding = 6;+ }+ return config;+}++@interface SGRLyricsPage : SGModPage+- (instancetype)initWithTitle:(NSString *)title note:(NSString *)note sections:(NSArray<SGModSection *> *)sections;+@end++@implementation SGRLyricsPage {+ UIView *_header, *_card;+ SGRKaraokeView *_preview;+ UIScrollView *_strip; // the presets, scrolled sideways when they do not all fit+ NSArray<UIButton *> *_chips;+ UIButton *_adjust; // the sliders' button, after the last preset+ UILabel *_note;+ UISelectionFeedbackGenerator *_feedback;+ BOOL _stripPlaced, _showChosen;+}++- (instancetype)initWithTitle:(NSString *)title note:(NSString *)note sections:(NSArray<SGModSection *> *)sections {+ if (!(self = [super initWithTitle:title intro:nil sections:sections footer:nil])) return nil;+ _note = [UILabel new];+ _note.text = note;+ _note.font = SGSubtitleFont();+ _note.textColor = SGGrey();+ _note.numberOfLines = 0;+ return self;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ _header = [UIView new];+ _card = [UIView new];+ _card.backgroundColor = SGCardBackground();+ _card.layer.cornerRadius = kCardRadius;+ _card.layer.cornerCurve = kCACornerCurveContinuous;+ _card.clipsToBounds = YES;+ _card.isAccessibilityElement = YES;+ _card.accessibilityLabel = @"Preview of the lyrics";+ _preview = [[SGRKaraokeView alloc] initWithSampleLines:SGRLyricsSampleLines() length:SGRLyricsSampleLength()];+ _preview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [_card addSubview:_preview];+ [_header addSubview:_card];++ _strip = [UIScrollView new];+ _strip.showsHorizontalScrollIndicator = NO;+ _strip.alwaysBounceHorizontal = YES;+ NSMutableArray<UIButton *> *chips = [NSMutableArray array];+ for (NSUInteger i = 0; i < SGRLyricsLookPresetNames().count; i++) {+ UIButton *chip = [UIButton buttonWithType:UIButtonTypeSystem];+ chip.tag = (NSInteger)i;+ [chip addTarget:self action:@selector(chipTapped:) forControlEvents:UIControlEventPrimaryActionTriggered];+ [_strip addSubview:chip];+ [chips addObject:chip];+ }+ _chips = chips;+ _adjust = [UIButton buttonWithType:UIButtonTypeSystem];+ [_adjust addTarget:self action:@selector(adjustTapped) forControlEvents:UIControlEventPrimaryActionTriggered];+ [_strip addSubview:_adjust];+ [_header addSubview:_strip];+ [_header addSubview:_note];+ _feedback = [UISelectionFeedbackGenerator new];+ [self showLook];+ self.tableView.tableHeaderView = _header;+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(showLook) name:SGRLyricsLookDidChangeNotification object:nil];+}++// Which preset the look is, lit and scrolled into sight; a look of the sliders' own lights their button.+- (void)showLook {+ NSInteger chosen = SGRLyricsLookPresetIndex(SGRLyricsLookNow());+ NSArray<NSString *> *names = SGRLyricsLookPresetNames();+ for (UIButton *chip in _chips) {+ BOOL lit = chip.tag == chosen;+ chip.configuration = chipConfiguration(names[(NSUInteger)chip.tag], nil, lit);+ chip.accessibilityTraits = UIAccessibilityTraitButton | (lit ? UIAccessibilityTraitSelected : 0);+ }+ UIButtonConfiguration *adjust = chipConfiguration(@"", @"slider.horizontal.3", chosen < 0);+ adjust.attributedTitle = nil;+ adjust.contentInsets = NSDirectionalEdgeInsetsZero;+ _adjust.configuration = adjust;+ _adjust.accessibilityLabel = @"Adjust";+ _adjust.accessibilityValue = chosen < 0 ? @"Custom" : names[(NSUInteger)chosen];+ _adjust.accessibilityHint = @"Opens the sliders";+ _adjust.accessibilityTraits = UIAccessibilityTraitButton | (chosen < 0 ? UIAccessibilityTraitSelected : 0);+ _showChosen = YES;+ [self.view setNeedsLayout];+}++- (void)chipTapped:(UIButton *)chip {+ NSUInteger i = (NSUInteger)chip.tag;+ if (SGRLyricsLookPresetIndex(SGRLyricsLookNow()) == (NSInteger)i) return;+ [_feedback selectionChanged];+ SGRSetLyricsLook(SGRLyricsLookPreset(i), self);+}++- (void)adjustTapped {+ presentStyleSheet(self);+}++// The header keeps the height it is given, so it is measured here and handed back to the table when it+// changes: the card at the table's inset, the presets and then the sliders' button in a strip that scrolls+// from edge to edge of the screen, and the note under them.+- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ UITableView *table = self.tableView;+ CGFloat width = table.bounds.size.width, inset = table.layoutMargins.left, inner = width - 2 * inset;+ if (inner <= 0) return;+ _card.frame = CGRectMake(inset, SGRGrid, inner, kPreviewHeight);+ CGFloat x = 0, top = CGRectGetMaxY(_card.frame) + kStripGap;+ for (UIButton *chip in _chips) {+ CGFloat wide = ceil([chip sizeThatFits:CGSizeMake(CGFLOAT_MAX, kChipHeight)].width);+ chip.frame = CGRectMake(x, kStripPad, wide, kChipHeight);+ x += wide + kChipGap;+ }+ _adjust.frame = CGRectMake(x, kStripPad, kChipHeight, kChipHeight);+ x += kChipHeight + kChipGap;+ // Padded above and below so the glass's shadow is not cut off where the strip clips its sides.+ _strip.frame = CGRectMake(0, top, width, kChipHeight + 2 * kStripPad);+ _strip.contentInset = UIEdgeInsetsMake(0, inset, 0, inset);+ _strip.contentSize = CGSizeMake(MAX(0, x - kChipGap), _strip.bounds.size.height);+ if (!_stripPlaced) { // the first button at the inset, where the card starts+ _strip.contentOffset = CGPointMake(-inset, 0);+ _stripPlaced = YES;+ }+ NSInteger chosen = SGRLyricsLookPresetIndex(SGRLyricsLookNow());+ if (_showChosen && chosen >= 0) {+ [_strip scrollRectToVisible:CGRectInset(_chips[(NSUInteger)chosen].frame, -kChipGap, 0) animated:self.view.window != nil];+ }+ _showChosen = NO;+ CGFloat noteHeight = _note.text.length ? ceil([_note sizeThatFits:CGSizeMake(inner, CGFLOAT_MAX)].height) : 0;+ _note.frame = CGRectMake(inset, CGRectGetMaxY(_strip.frame) + kNoteGap - kStripPad, inner, noteHeight);+ CGSize size = CGSizeMake(width, CGRectGetMaxY(_note.frame));+ if (CGSizeEqualToSize(_header.bounds.size, size)) return;+ _header.frame = (CGRect){CGPointZero, size};+ table.tableHeaderView = _header;+}++@end++UIViewController *SGRLyricsSettingsPage(NSString *title, NSString *intro, NSArray<SGModSection *> *sections) {+ return [[SGRLyricsPage alloc] initWithTitle:title note:intro sections:sections];+}diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.hindex ea41fdbc..31dcabd4 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h@@ -9,6 +9,9 @@#import "Shared/Lyrics/Lyrics.h"@interface SGRKaraokeView : UIView+// The Lyrics page's preview: `lines` played on a clock of its own, round and round every `length` ms, in+// the look the page sets. It takes no touches and asks nothing of the player, the sources, Genius or Sing.+- (instancetype)initWithSampleLines:(NSArray<SGKaraokeLine *> *)lines length:(NSInteger)length;// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.- (void)syncSiblings;// Called as a finger starts to scroll the lines, for a host that hides its controls then.diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mindex 2e4af3ed..11d9e69a 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -10,6 +10,7 @@#import "Core/SGCore.h"#import "SGRKaraokeView.h"#import "LyricsText.h"+#import "LyricsLook.h"#import "MeaningSheet.h"#import "SGRSingButton.h"#import "Shared/LyricsSources/LyricsSources.h"@@ -20,11 +21,12 @@#import "Redesigned/Kit/SGRGlass.h"#import "Redesigned/Kit/SGRTokens.h"-static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;+// The size of the words and the room between lines are the Lyrics page's (LyricsLook.h).+static const CGFloat kMargin = 24, kRowTighten = 2;static const CGFloat kDimAlpha = 0.3, kFillEdge = 22, kLift = 2.5, kDimScale = 0.97;static const CGFloat kAnchor = 0.28; // where the sung line rests, as a share of the heightstatic const CGFloat kEdgeFade = 0.1; // the lines fade out over this share at the top and bottom-static const CGFloat kBlurPerLine = 1.4, kMaxBlur = 6;+static const CGFloat kBlurPerLine = 1.4, kMaxBlur = 6; // Apple Music's, scaled by the Lyrics page's blur// The (oh, aye) hanging under a line: smaller, a little dimmer, and just clear of it.static const CGFloat kBackingScale = 0.62, kBackingAlpha = 0.8, kBackingGap = 4;// The mark of a line Genius explains: a bubble after it for the artist's own word, a dotted underline@@ -44,6 +46,8 @@ static const double kFloatMinMs = 700, kFloatLeadMs = 80; // a short word stil// word and fades over kGlowFadeMs after it.static const double kGlowFromMs = 900, kGlowFullMs = 2400, kGlowFadeMs = 450;static const CGFloat kGlowRadius = 9, kGlowOpacity = 0.85;+// How strongly the glow and the wave below are drawn, the Lyrics page's (LyricsLook.h), 1 being as here.+static CGFloat sgr_glowScale = 1, sgr_waveScale = 1;// A word held long enough to glow lifts its letters one after another as the sweep reaches each, a wave// running through it, as high as this share of the font for the word held longest: a letter starts up a// little before the sweep's edge reaches its middle and is up over this share of the word's time. They come@@ -271,7 +275,7 @@ static double heldStrength(double held) {- (void)glowAt:(double)ms {double held = _word.end - _word.start;CGFloat glow = 0;- if (held >= kGlowFromMs && !_whole) {+ if (held >= kGlowFromMs && !_whole && sgr_glowScale > 0) {double strength = heldStrength(held);double envelope = ms < _word.start ? 0: ms <= _word.end ? (ms - _word.start) / held@@ -285,8 +289,8 @@ static double heldStrength(double held) {[CATransaction setDisableActions:YES];layer.shadowColor = UIColor.whiteColor.CGColor;layer.shadowOffset = CGSizeZero;- layer.shadowRadius = kGlowRadius * (0.5 + glow / 2);- layer.shadowOpacity = kGlowOpacity * glow;+ layer.shadowRadius = kGlowRadius * (0.5 + glow / 2) * (0.75 + sgr_glowScale / 4);+ layer.shadowOpacity = MIN(1, kGlowOpacity * glow * sgr_glowScale);[CATransaction commit];}@@ -296,7 +300,7 @@ static double heldStrength(double held) {if (!_litLetters || _whole) return;double held = _word.end - _word.start, along = (ms - _word.start) / held;double fade = ms <= _word.end ? 1 : MAX(0, 1 - (ms - _word.end) / kGlowFadeMs);- CGFloat height = _waveHeight * heldStrength(held) * fade;+ CGFloat height = _waveHeight * heldStrength(held) * fade * sgr_waveScale;for (NSUInteger i = 0; i < _litLetters.count; i++) {double p = MAX(0, MIN(1, (along - _letterAt[i] + kWaveLead) / kWaveSpan));CGFloat lift = round(height * p * p * (3 - 2 * p) * 4) / 4; // quarter points, so most frames change nothing@@ -1223,6 +1227,9 @@ typedef struct {CFTimeInterval _seekAt; // when, 0 while no seek is waitingBOOL _sweepsEstimates; // the Lyrics page's "Simulate word-by-word timing", read once like the creditBOOL _plain; // the song has no timing at all: every line lit, nothing follows the clock+ NSArray<SGKaraokeLine *> *_sample; // the preview's lines, nil for the player's+ NSInteger _sampleLength;+ CFTimeInterval _sampleEpoch;NSDictionary<NSNumber *, NSArray<SGLyricsMeaning *> *> *_meanings; // Genius's, by lineNSUInteger _meaningsAsked;}@@ -1232,11 +1239,8 @@ typedef struct {if (!self) return nil;self.hidden = YES;_focus = _openBreak = -1;- _fontSize = kFontSize;_margin = kMargin;- _lineGap = kLineGap;- _blurPerLine = kBlurPerLine;- _maxBlur = kMaxBlur;+ [self takeLook];_shown = [NSMutableDictionary dictionary];_sightArrangement = NSUIntegerMax;_fade = [CAGradientLayer layer];@@ -1266,6 +1270,7 @@ typedef struct {[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionNotification object:nil];[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionEndedNotification object:nil];[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(restyle) name:SGRLyricsTextDidChangeNotification object:nil];+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(lookChanged) name:SGRLyricsLookDidChangeNotification object:nil];// A locked phone leaves the card in its window, so the link has to be put down by the app going// away rather than by the view going: see scheduleLink.[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(scheduleLink) name:UIApplicationDidBecomeActiveNotification object:nil];@@ -1273,12 +1278,55 @@ typedef struct {return self;}+- (instancetype)initWithSampleLines:(NSArray<SGKaraokeLine *> *)lines length:(NSInteger)length {+ if (!(self = [self initWithFrame:CGRectZero])) return nil;+ _sample = lines;+ _sampleLength = MAX(length, 1);+ _sampleEpoch = CACurrentMediaTime();+ _crediting = NO;+ [_sing removeFromSuperview];+ _sing = nil;+ self.userInteractionEnabled = NO;+ self.accessibilityElementsHidden = YES; // a picture of the setting, with nothing to read or do+ return self;+}+- (void)dealloc {[NSNotificationCenter.defaultCenter removeObserver:self];free(_spans);free(_breaks);}+// The Lyrics page's look: the size and the room are the lines' layout, the blur their placing, the glow+// and the wave every held word's, so a change is the song measured again in it and crossfaded over.+- (void)takeLook {+ SGRLyricsLook look = SGRLyricsLookNow();+ _fontSize = look.size;+ _lineGap = look.spacing;+ _blurPerLine = kBlurPerLine * look.blur;+ _maxBlur = kMaxBlur * look.blur;+ sgr_glowScale = look.glow;+ sgr_waveScale = look.wave;+}++- (void)lookChanged {+ [self takeLook];+ _font = [UIFont systemFontOfSize:_fontSize weight:UIFontWeightBold];+ [_dots removeFromSuperview]; // made again in the new font, at the next frame with a break open+ _dots = nil;+ [self restyle];+}++// The preview's lines on its own clock, round and round; everything else the player's.+- (NSInteger)positionMs {+ if (!_sample) return SGKaraokePositionMs();+ return (NSInteger)fmod((CACurrentMediaTime() - _sampleEpoch) * 1000, _sampleLength);+}++- (NSArray<SGKaraokeLine *> *)linesFor:(NSString *)track {+ return _sample ?: SGKaraokeLinesForTrack(track);+}+- (void)tapped:(UITapGestureRecognizer *)tap {if (_extrasBox && !_extrasBox.hidden && CGRectContainsPoint(_extrasBox.frame, [tap locationInView:self])) return;if (_sing.userInteractionEnabled && [_sing pointInside:[tap locationInView:_sing] withEvent:nil]) return;@@ -1321,6 +1369,7 @@ typedef struct {// Genius is asked once the song's lines are in; lines that change under it are matched again.- (void)askMeanings {_meanings = nil;+ if (_sample) return;NSUInteger asked = ++_meaningsAsked;NSArray<SGKaraokeLine *> *lines = _lines;__weak SGRKaraokeView *weakSelf = self;@@ -1615,7 +1664,7 @@ static BOOL hasWords(SGKaraokeLine *line) {// what the song has: a switch for each, reading what tapping it will do.- (void)offerExtras {BOOL gemini = SGGeminiKeySet();- BOOL offered = _lines && (_hasSpoken || _hasTranslation || gemini);+ BOOL offered = _lines && !_sample && (_hasSpoken || _hasTranslation || gemini);if (!offered) {_extrasBox.hidden = YES;return;@@ -1900,7 +1949,7 @@ static BOOL hasWords(SGKaraokeLine *line) {// reading, so the sweep follows neither the callback's jitter nor the small jumps of the core's// corrections. A seek or a new track is too far off to ease and is taken at once.- (double)clockMs {- NSInteger raw = SGKaraokePositionMs();+ NSInteger raw = [self positionMs];CFTimeInterval shown = _link ? _link.targetTimestamp : CACurrentMediaTime();if (_seekAt) {// A paused player never moves, so the hold ends by the position or the time, not by motion.@@ -1926,9 +1975,9 @@ static BOOL hasWords(SGKaraokeLine *line) {}- (void)tick {- NSString *track = SGKaraokePlayingTrack();+ NSString *track = _sample ? @"sample" : SGKaraokePlayingTrack();if (!(track == _track || [track isEqualToString:_track])) {- SGLog(@"karaoke: page shows track %@, lyrics %@", track, SGKaraokeLinesForTrack(track) ? @"captured" : @"not captured yet");+ SGLog(@"karaoke: page shows track %@, lyrics %@", track, [self linesFor:track] ? @"captured" : @"not captured yet");_track = track;_lines = nil;_passedOver = nil;@@ -1937,7 +1986,7 @@ static BOOL hasWords(SGKaraokeLine *line) {[self dropLineViews];[self offerExtras];}- NSArray<SGKaraokeLine *> *kept = _lines && track ? SGKaraokeLinesForTrack(track) : nil;+ NSArray<SGKaraokeLine *> *kept = _lines && track ? [self linesFor:track] : nil;if (kept && kept != _lines && kept != _passedOver) {if (!_hasTranslation && kept.count == _lines.count && SGKaraokeLinesTiming(kept) == SGKaraokeLinesTiming(_lines)&& hasTranslations(kept)) {@@ -1966,7 +2015,7 @@ static BOOL hasWords(SGKaraokeLine *line) {_passedOver = kept;}}- if (!_lines && track && (_lines = SGKaraokeLinesForTrack(track))) {+ if (!_lines && track && (_lines = [self linesFor:track])) {SGLog(@"karaoke: showing %lu lines of %@", (unsigned long)_lines.count, track);[self timeLines];[self setNeedsLayout];@@ -1982,7 +2031,7 @@ static BOOL hasWords(SGKaraokeLine *line) {}double now = [self clockMs];- [self arrangeAt:now glide:NO];+ [self arrangeAt:now glide:_sample != nil]; // the preview coming round glides back to its first linefor (NSUInteger i = 0; i < _sungCount; i++) [_shown[@(_sung[i])] showTime:now];if (_dots.superview) [_dots showTime:now running:!_stillSince || _link.targetTimestamp - _stillSince < kStillFor at:_link.targetTimestamp];}