Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: the animated cover is dimmed only where text sits (#132)
My-Name-Is-Jeffe16cf05d8595
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 399e3bda..a98cd669 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -568,11 +568,12 @@ Redesigned:a restart. The clip holds its frame while the song is paused, goes whileSpotify's music video shows, is given up when it has drawn nothing in 5 s on screen, and on a skipstays a moment for the next track's to cross over it. Under Reduce Motion and in Low Power Mode no- clip plays: the cover stays over Fluid. A black layer dims the clip by its brightness (the 75th+ clip plays: the cover stays over Fluid. A black gradient dims the clip by its brightness (the 75thpercentile of the linear luminance of three frames), so white text keeps 4.5:1 (7:1 with Increase- Contrast), from 0.10 to 0.80 and 0.15 more behind the lyrics. A track that changes while the player- cannot be seen (no window, or the app not in front) takes the last clip away at once. Checked in the simulator against- harness/player/ (`motion`). The Visualizer+ Contrast), from 0.10 to 0.80, only where text is: a band under the header and from above the title+ down; behind the lyrics it covers the whole clip, 0.15 darker (issue #101). A track that changes+ while the player cannot be seen (no window, or the app not in front) takes the last clip away at+ once. Checked in the simulator against harness/player/ (`motion`). The Visualizer(PlayerVisualiser.m) draws two soft hills of the song's spectrum across the foot of the player, the kicka mound in the middle (the two bands under 80 Hz are left out, and the kick's bands stand at least astall as the bands beside them, so the middle is never a notch), as light in the cover's flow colorsdiff --git a/harness/player/main.m b/harness/player/main.mindex 1658443a..a97a6bc7 100644--- a/harness/player/main.m+++ b/harness/player/main.m@@ -651,6 +651,11 @@ static UIViewController *unitOf(UIView *view) {static UIView *firstOfClass(UIView *root, NSString *name);+// The alpha of a gradient's stop `index`.+static CGFloat stopAlpha(CAGradientLayer *gradient, NSUInteger index) {+ return CGColorGetAlpha((__bridge CGColorRef)gradient.colors[index]);+}+static void after(NSTimeInterval seconds, dispatch_block_t block) {dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);}@@ -936,14 +941,17 @@ static BOOL fieldCovered(void) {[[seam.maskView.layer.sublayers.firstObject valueForKey:@"locations"] componentsJoinedByString:@" to "], lyricsBlurred ? @"on" : @"off"]];// Dimmed by its brightness: HARNESS_DIM is what the clip in HARNESS_CANVAS_FILE should get (0.54 for white,// 0.10 for black); the rule itself is checked at its ends.- CALayer *dim = [motion valueForKey:@"_dim"];+ CAGradientLayer *dim = [motion valueForKey:@"_dim"];+ // Only where text is: whole at the top and from the seam's blur down, clear between (issue #101).+ BOOL banded = dim && stopAlpha(dim, 1) == 1 && stopAlpha(dim, 2) == 0 && stopAlpha(dim, 4) == 1;const char *expected = getenv("HARNESS_DIM");BOOL rule = fabs(SGRPlayerClipDim(1, NO, NO) - 0.54) < 0.01 && fabs(SGRPlayerClipDim(1, YES, NO) - 0.65) < 0.01&& SGRPlayerClipDim(0, NO, NO) == 0.10 && fabs(SGRPlayerClipDim(0, NO, YES) - 0.25) < 1e-6&& fabs(SGRPlayerClipDim(0.5, NO, NO) - 0.37) < 0.01;self->_dimAlone = dim.opacity;- [self expect:rule && dim && dim.superlayer == clip.superlayer.superlayer && (!expected || fabs(dim.opacity - atof(expected)) < 0.02)- step:@"the dim" detail:[NSString stringWithFormat:@"rule %@, dim %.2f over the clip%@", rule ? @"right" : @"wrong", dim.opacity,+ [self expect:rule && banded && dim && dim.superlayer == clip.superlayer.superlayer && (!expected || fabs(dim.opacity - atof(expected)) < 0.02)+ step:@"the dim" detail:[NSString stringWithFormat:@"rule %@, dim %.2f %@%@", rule ? @"right" : @"wrong", dim.opacity,+ banded ? [NSString stringWithFormat:@"whole to %@ and from %@", dim.locations[1], dim.locations[4]] : @"not banded",expected ? [NSString stringWithFormat:@", %s expected", expected] : @""]];NSLog(@"[harness] motion: screenshot the clip now");});@@ -955,8 +963,11 @@ static BOOL fieldCovered(void) {if ([NSStringFromClass(view.class) isEqualToString:@"SGRPlayerLyricsOverlay"]) thumb = [view valueForKey:@"thumb"];}BOOL away = thumb && !CGAffineTransformIsIdentity(thumb.transform) && thumb.alpha > 0.99;- float dim = ((CALayer *)[motionView() valueForKey:@"_dim"]).opacity;- [self expect:fabsf(dim - self->_dimAlone - 0.15f) < 0.01f step:@"the dim under the lyrics"+ CAGradientLayer *shade = [motionView() valueForKey:@"_dim"];+ float dim = shade.opacity;+ // The lyrics run down the whole screen, so the dim covers all of it.+ BOOL whole = shade && stopAlpha(shade, 2) == 1;+ [self expect:whole && fabsf(dim - self->_dimAlone - 0.15f) < 0.01f step:@"the dim under the lyrics"detail:[NSString stringWithFormat:@"%.2f, %.2f without them", dim, self->_dimAlone]];[self expect:SGRPlayerLyricsOpen() && lyricsBlurred && away step:@"the lyrics"detail:[NSString stringWithFormat:@"lyrics %@, clip blurred %@, thumbnail %@ at alpha %.2f", SGRPlayerLyricsOpen() ? @"up" : @"down",diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 8ba4944e..b4011061 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -157,9 +157,9 @@ BOOL SGRPlayerMotionShowing(void);// `arrived` runs once on the main queue when a call would return it (never when nothing is found, or the// track changed). Without `arrived` it only answers with a clip already in.UIView *SGRPlayerMotionPreview(void (^arrived)(void));-// How dark the clip is drawn (a black layer's opacity) for white text over it to keep 4.5:1, or 7:1 with-// `contrast` (Increase Contrast), when `luminance` is the clip's bright end, its 75th percentile of linear-// luminance; between 0.10 and 0.80, 0.15 more while the lyrics are up.+// How dark the clip is drawn (the dim's opacity, where its gradient is whole) for white text over it to keep+// 4.5:1, or 7:1 with `contrast` (Increase Contrast), when `luminance` is the clip's bright end, its 75th+// percentile of linear luminance; between 0.10 and 0.80, 0.15 more while the lyrics are up.CGFloat SGRPlayerClipDim(CGFloat luminance, BOOL contrast, BOOL lyrics);#pragma mark - the Visualizer (PlayerVisualiser.m)diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.xindex 649bf529..1cdd8dd8 100644--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x@@ -19,7 +19,9 @@// hidden (the field's covered): the field's color is what shows above the clip on the pull that dismisses.//// The clip is dimmed by how bright it is (SGRPlayerClipDim): three of its frames are measured as it comes in,-// so a white Canvas is drawn darker than a black one and the white text over it keeps its contrast.+// so a white Canvas is drawn darker than a black one and the white text over it keeps its contrast. The dim+// lies only where text does, a band under the header and from above the title down, as the Music app's does:+// over the whole clip it took up to four fifths of its light (issue #101). Behind the lyrics it covers the clip.//// A track that changes while the player cannot be seen (out of a window, or with the app not in front, which a// locked phone's player is while it stays in its window) takes the last clip away at once, without a fade, so@@ -59,6 +61,9 @@ static const NSTimeInterval kGiveUp = 5;static const NSTimeInterval kHandOver = 0.4;// The dim's floor and ceiling, and what the lyrics add to it.static const CGFloat kDimLeast = 0.10, kDimMost = 0.80, kDimLyrics = 0.15;+// The dim's band at the top, under the status bar and the header: whole down to this share of the screen, so+// the header's text gets all of it, then gone over kDimFade points.+static const CGFloat kDimTop = 0.14, kDimFade = 48;// The frames measured for the dim besides the poster, in seconds into the clip (one past its end is skipped).static const double kMeasuredAt[] = {1, 2};// Behind the lyrics the clip itself is blurred, a plain Gaussian blur with no material's gray tint over it@@ -153,7 +158,7 @@ static UIColor *footColor(CGImageRef poster) {AVPlayerLayer *_clip;CAGradientLayer *_clipMask, *_seamMask;CALayer *_foot; // the color of the poster's last rows, from the seam down- CALayer *_dim; // black over the clip and its foot, as dark as the clip is bright+ CAGradientLayer *_dim; // black over the clip's top and from above the title down, as dark as the clip is brightNSMutableData *_luminances; // of the frames measured so farBOOL _lyricsUp;NSUInteger _blurTurn; // counts the lyrics' turns, so a fade cut short leaves the filter to the turn after it@@ -164,6 +169,13 @@ static UIColor *footColor(CGImageRef poster) {// What fades is the effect views' effect, never their alpha or an ancestor's: UIKit draws a blur under a// fading alpha or a mask wrongly or not at all.+// The dim's stops: black at the top and from above the title down, clear between; black all over behind the+// lyrics, which run down the whole screen.+static NSArray *dimColors(BOOL whole) {+ id black = (__bridge id)UIColor.blackColor.CGColor, between = whole ? black : (__bridge id)UIColor.clearColor.CGColor;+ return @[black, black, between, between, black];+}+static UIBlurEffect *blurEffect(void) {return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark];}@@ -190,8 +202,8 @@ static UIBlurEffect *blurEffect(void) {_clipMask.locations = @[@0, @(kFootFrom), @1];_still.mask = _clipMask;[_picture.layer addSublayer:_still];- _dim = [CALayer layer];- _dim.backgroundColor = UIColor.blackColor.CGColor;+ _dim = [CAGradientLayer layer];+ _dim.colors = dimColors(NO);_dim.opacity = kDimLeast;[_picture.layer addSublayer:_dim];@@ -248,8 +260,12 @@ static UIBlurEffect *blurEffect(void) {_clipMask.frame = _still.bounds;_foot.frame = CGRectMake(0, seam, width, MAX(0, total - seam));_dim.frame = bounds;+ NSNumber *(^at)(CGFloat) = ^NSNumber *(CGFloat y) { return @(MIN(1, y / total)); };+ // Whole again by where the seam's blur starts, so over the title and the controls below it.+ CGFloat topEnd = MIN(screen * kDimTop, blurFrom), rampFrom = MAX(topEnd, blurFrom - kBlurRamp);+ _dim.locations = @[@0, at(topEnd), at(MIN(topEnd + kDimFade, rampFrom)), at(rampFrom), at(blurFrom)];_seamMask.frame = bounds;- _seamMask.locations = @[@(MIN(1, blurFrom / total)), @(MIN(1, (blurFrom + kBlurRamp) / total))];+ _seamMask.locations = @[at(blurFrom), at(blurFrom + kBlurRamp)];[CATransaction commit];}@@ -355,6 +371,7 @@ static UIBlurEffect *blurEffect(void) {[CATransaction begin];[CATransaction setDisableActions:!animated];[CATransaction setAnimationDuration:SGRCrossfade];+ _dim.colors = dimColors(blurred);[self updateDim];if (layer.filters) {__weak SGRPlayerMotionView *weakSelf = self;