Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: sweep the lyrics card under the player word by word too
Vojtěch Škopek3dab9e9a91bd
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex fc8451ee..cb1926ae 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -45,8 +45,9 @@ app:rewritten on the way in (AdNetwork.x, Premium.m over the protobuf walker in Protobuf.m), with crossfadeand automix switched on in the player core and crossfade's switch kept in step with its slider (Crossfade.x)ArtistBlock/ tracks by blocked artists skipped as they start (ArtistSkip.x), the list and the Blocked artists page under Player- Karaoke/ Apple Music style lyrics on the full screen page: lines read from color-lyrics and the player's clock (KaraokeSource.x),- words timed by estimate inside Spotify's line times (KaraokeTiming.m), drawn by KaraokeView.m over the page (KaraokePage.x)+ Karaoke/ Apple Music style lyrics on the full screen page and on the card under the player: lines read from color-lyrics+ and the player's clock (KaraokeSource.x), words timed by estimate inside Spotify's line times (KaraokeTiming.m),+ drawn by KaraokeView.m over the page (KaraokePage.x) and, in compact, over the card (KaraokeCard.x)LyricsSources/ 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 is the only shape carrying a second voice and thediff --git a/tweak/Sources/Features/Karaoke/Karaoke.h b/tweak/Sources/Features/Karaoke/Karaoke.hindex e13b01c8..4d1fe6e3 100644--- a/tweak/Sources/Features/Karaoke/Karaoke.h+++ b/tweak/Sources/Features/Karaoke/Karaoke.h@@ -61,6 +61,9 @@ void SGKaraokeSeek(NSInteger ms);id SGKaraokePlayer(void); // SPTEsperantoPlayer, nil before the app asked it for its state@interface SGKaraokeView : UIView+// Compact is the card under the player: Spotify's own type size, no seeking by tap and no margin of+// its own, since the card already insets what it holds. initWithFrame: is the full screen page.+- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact;// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.- (void)syncSiblings;@enddiff --git a/tweak/Sources/Features/Karaoke/KaraokeCard.x b/tweak/Sources/Features/Karaoke/KaraokeCard.xnew file mode 100644index 00000000..201e6fe9--- /dev/null+++ b/tweak/Sources/Features/Karaoke/KaraokeCard.x@@ -0,0 +1,43 @@+// The same Apple Music style lyrics on the card under the player, so the card sweeps word by word+// rather than scrolling whole lines while the page it expands into sweeps. It is the page's view in+// compact: the card is a seventh of the height, so it takes Spotify's own type size and spacing.+//+// The host is Lyrics_CardElementImpl.CardContentView, the card's own content view. The table inside+// it, Lyrics_TextElementImpl.LyricsTextView, is the wrong thing to hook: the full screen page is+// built from that same class, and KaraokePage.x is already over it there. CardContentView belongs+// to the card alone, and is still in the tree while the page is open, behind it.+//+// The view is laid over rather than swapped in, as on the page: Spotify's table keeps running+// underneath and comes back the moment a track has no synced lyrics. It takes no touches, so the+// tap that opens the full screen page is still Spotify's to answer.+#import "Core/SGCore.h"+#import "Karaoke.h"++// Below this the card is collapsed, by Declutter or while it is still being laid out.+static const CGFloat kLivingHeight = 40;++static char kKaraokeKey;++%hook _TtC22Lyrics_CardElementImpl15CardContentView+- (void)layoutSubviews {+ %orig;+ UIView *host = (UIView *)self;+ if (host.bounds.size.height < kLivingHeight) return;+ SGKaraokeView *view = objc_getAssociatedObject(host, &kKaraokeKey);+ if (!view) {+ SGLog(@"karaoke: card laid out, playing %@", SGKaraokePlayingTrack());+ view = [[SGKaraokeView alloc] initWithFrame:host.bounds compact:YES];+ objc_setAssociatedObject(host, &kKaraokeKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ if (view.superview == host) [host bringSubviewToFront:view];+ else [host addSubview:view];+ view.frame = host.bounds;+ [view syncSiblings];+}+%end++%ctor {+ if (!SGFlag(SGKeyKaraokeLyrics, NO)) return;+ %init;+ SGRequireClasses(@[@"_TtC22Lyrics_CardElementImpl15CardContentView"]);+}diff --git a/tweak/Sources/Features/Karaoke/KaraokeView.m b/tweak/Sources/Features/Karaoke/KaraokeView.mindex 120233cd..7f07a4a4 100644--- a/tweak/Sources/Features/Karaoke/KaraokeView.m+++ b/tweak/Sources/Features/Karaoke/KaraokeView.m@@ -3,6 +3,11 @@#import "Features/LyricsSources/LyricsSources.h"static const CGFloat kFontSize = 30, kMargin = 24, kLineGap = 24, kRowTighten = 2;+// The card under the player is a seventh of the page's height, so it gets Spotify's own card type+// size and the spacing its rows sit on, and it dims less: at full strength a card this small is a+// blur with a line in it.+static const CGFloat kCardFontSize = 21, kCardMargin = 0, kCardLineGap = 16;+static const CGFloat kCardBlurPerLine = 0.9, kCardMaxBlur = 3.5;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@@ -304,6 +309,8 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {BOOL _showing;CAGradientLayer *_fade;UILabel *_credit;+ CGFloat _fontSize, _margin, _lineGap, _blurPerLine, _maxBlur;+ BOOL _compact;BOOL _crediting; // the switch is read once: the page asks for the source on every frame until it has onedouble _clock;NSInteger _reported;@@ -311,10 +318,20 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {}- (instancetype)initWithFrame:(CGRect)frame {+ return [self initWithFrame:frame compact:NO];+}++- (instancetype)initWithFrame:(CGRect)frame compact:(BOOL)compact {self = [super initWithFrame:frame];if (!self) return nil;self.hidden = YES;_active = -1;+ _compact = compact;+ _fontSize = compact ? kCardFontSize : kFontSize;+ _margin = compact ? kCardMargin : kMargin;+ _lineGap = compact ? kCardLineGap : kLineGap;+ _blurPerLine = compact ? kCardBlurPerLine : kBlurPerLine;+ _maxBlur = compact ? kCardMaxBlur : kMaxBlur;_fade = [CAGradientLayer layer];_fade.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.whiteColor.CGColor,(id)UIColor.whiteColor.CGColor, (id)UIColor.clearColor.CGColor];@@ -332,16 +349,18 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {_credit.font = [UIFont systemFontOfSize:kCreditSize weight:UIFontWeightSemibold];_credit.textColor = [UIColor colorWithWhite:1 alpha:kCreditAlpha];_credit.hidden = YES;- _crediting = SGFlag(SGKeyLyricsCredit, NO);+ _crediting = !compact && SGFlag(SGKeyLyricsCredit, NO); // the card has no room to name a source[self addSubview:_credit];- [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];+ // A tap on the card is Spotify's, and opens the full screen page; seeking by tap is the page's.+ if (compact) self.userInteractionEnabled = NO;+ else [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];return self;}- (void)tapped:(UITapGestureRecognizer *)tap {CGPoint point = [tap locationInView:_scroll];for (SGKaraokeLineView *view in _lineViews) {- if (!CGRectContainsPoint(CGRectInset(view.frame, -kMargin, -kLineGap / 2), point)) continue;+ if (!CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), point)) continue;SGKaraokeSeek(view.line.start);[self followSong];return;@@ -386,7 +405,9 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {return;}_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick)];- _link.preferredFrameRateRange = CAFrameRateRangeMake(80, 120, 120);+ // The card stays in the window behind the full screen page, so both sweep at once; the card is+ // a few lines tall and gives up the high refresh rate the page keeps.+ _link.preferredFrameRateRange = _compact ? CAFrameRateRangeMake(30, 60, 60) : CAFrameRateRangeMake(80, 120, 120);[_link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];}@@ -398,7 +419,7 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {[CATransaction commit];_scroll.contentSize = self.bounds.size;[_credit sizeToFit];- _credit.frame = CGRectMake(kMargin, self.bounds.size.height - _credit.bounds.size.height - kCreditBottom,+ _credit.frame = CGRectMake(_margin, self.bounds.size.height - _credit.bounds.size.height - kCreditBottom,_credit.bounds.size.width, _credit.bounds.size.height);if (_lines && self.bounds.size.width != _builtWidth) [self rebuild];}@@ -410,9 +431,9 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {_browsing = NO;_scroll.contentOffset = CGPointZero;_builtWidth = self.bounds.size.width;- CGFloat width = _builtWidth - 2 * kMargin;+ CGFloat width = _builtWidth - 2 * _margin;if (width <= 0) return;- UIFont *font = [UIFont systemFontOfSize:kFontSize weight:UIFontWeightBold];+ UIFont *font = [UIFont systemFontOfSize:_fontSize weight:UIFontWeightBold];NSMutableArray<SGKaraokeLineView *> *views = [NSMutableArray array];for (SGKaraokeLine *line in _lines) {SGKaraokeLineView *view = [[SGKaraokeLineView alloc] initWithLine:line width:width font:font backing:NO];@@ -433,19 +454,19 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {for (NSUInteger i = 0; i < _lineViews.count; i++) {if ((NSInteger)i == focus) focusTop = top;[tops addObject:@(top)];- top += _lineViews[i].bounds.size.height + kLineGap;+ top += _lineViews[i].bounds.size.height + _lineGap;}for (NSUInteger i = 0; i < _lineViews.count; i++) {SGKaraokeLineView *view = _lineViews[i];NSInteger distance = (NSInteger)i - _active;CGFloat y = height * kAnchor + tops[i].doubleValue - focusTop;- CGRect frame = CGRectMake(kMargin, y, view.bounds.size.width, view.bounds.size.height);+ CGRect frame = CGRectMake(_margin, y, view.bounds.size.width, view.bounds.size.height);// The anchor sits on the edge the line is aligned to, so it scales toward its own text.BOOL trailing = view.line.align == SGKaraokeAlignTrailing;- CGPoint center = CGPointMake(trailing ? CGRectGetMaxX(frame) : kMargin, CGRectGetMidY(frame));+ CGPoint center = CGPointMake(trailing ? CGRectGetMaxX(frame) : _margin, CGRectGetMidY(frame));CGFloat scale = distance == 0 ? 1 : kDimScale;CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);- view.blur = distance == 0 ? 0 : MIN(kMaxBlur, labs(distance) * kBlurPerLine);+ view.blur = distance == 0 ? 0 : MIN(_maxBlur, labs(distance) * _blurPerLine);BOOL near = CGRectIntersectsRect(CGRectInset(self.bounds, 0, -height / 2), frame)|| CGRectIntersectsRect(CGRectInset(self.bounds, 0, -height / 2), view.frame);if (!animated || !near) {