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 Visualizer glows in the cover's colors with the kick at its centre
My-Name-Is-Jeff4c28e0978ec9
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex dcd1a01c..0d943957 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -507,8 +507,13 @@ Redesigned:Contrast), from 0.10 to 0.80 and 0.15 more behind the lyrics. A track that changes while the playercannot be seen (no window, or the app not in front) takes the last clip away at once. Checked in the simulator againstharness/player/ (`motion`). The Visualizer- (PlayerVisualiser.m) draws two soft hills of the song's spectrum across the foot of the player in the- cover's flow colors, over the Fluid field held still, blurred behind the lyrics: the audio effects'+ (PlayerVisualiser.m) draws two soft hills of the song's spectrum across the foot of the player, the kick+ a mound in the middle (the two bands under 80 Hz are left out, and the kick's bands stand at least as+ tall as the bands beside them, so the middle is never a notch), as light in the cover's flow colors+ added to the Fluid field held still (plusL, every color at one luminance with its saturation lifted, so+ a red cover glows warm and a black one is a gray mist, never a silhouette), clear toward the tallest crest so a peak+ thins out instead of ending in an edge, the front hill brightening on the kick, blurred behind the+ lyrics: the audio effects'render notify on the music's output hands what it plays, mixed to mono, to one reader (SGAudioSetOutputReader), andSGRSpectrum.m cuts it into 24 bands with Accelerate's FFT on the render thread, without allocating orlocking, and publishes them atomically; a display link of at most 60 Hz (30 behind the lyrics, 15diff --git a/tweak/Sources/Redesigned/Player/PlayerVisualiser.m b/tweak/Sources/Redesigned/Player/PlayerVisualiser.mindex e7907ec4..0a93868b 100644--- a/tweak/Sources/Redesigned/Player/PlayerVisualiser.m+++ b/tweak/Sources/Redesigned/Player/PlayerVisualiser.m@@ -6,10 +6,14 @@// (SGAudioSetOutputReader, Shared/AudioEffects/AudioEffects.h) into SGRSpectrum.m's bands. Here, on the main// thread, a display link reads the bands, brings them to a share of the song's own loudness (the loudest band of// the last few seconds at the top, so a quiet track moves as much as a loud one), eases each band up quickly-// and down slowly, and draws two soft hills across the foot of the screen, mirrored about its middle, the bass+// and down slowly, and draws two soft hills across the foot of the screen, mirrored about its middle, the kick// in the middle and the treble at either edge: a slow one behind, a quicker one in front. Each is a gradient of-// the cover's colors (SGRPalette's flow colors, kept dark enough that white text on them stays over 5.5:1)-// masked by a shape layer, so the render server does the drawing and the app only hands it two paths a frame.+// the cover's colors (SGRPalette's flow colors, brought to one luminance) masked by a shape layer, so the render+// server does the drawing and the app only hands it two paths a frame. They are light added to the field+// (plusL), never paint over it, so a dark cover's hills are a silver mist and a bright field's are brighter+// still, and the whole fades to clear toward the tallest crest, so a peak thins to light instead of ending in an+// edge. The front hill brightens on the kick and dims over a third of a second: the beat, where the heights are+// the spectrum.//// It moves only while it is in a window, Spotify is in front, the player is not opening or closing, Low Power// Mode is off and the song plays; a pause lets the hills settle and the link stops, and nothing is read from@@ -31,22 +35,40 @@#import "Player.h"#import "SGRSpectrum.h"-enum { kBands = SGRSpectrumBands, kPoints = 2 * kBands - 1 };+// The two bands under 80 Hz stay out of the picture: sub-bass is quieter than the kick above it in most mixes,+// so drawn at the middle it cut a notch into the crest right under the play button.+enum { kBands = SGRSpectrumBands, kFirst = 2, kShown = kBands - kFirst, kPoints = 2 * kShown - 1 };+// The kick: the four bands from kFirst, 80 to 205 Hz; beside it the next six, 205 to 840 Hz.+enum { kKickBands = 4, kBesideBands = 6 };// The loudness a band is drawn against: the loudest band of late at the top, kRange dB under it at the floor,// the top falling kPeakFall dB a second after a loud passage and never under kPeakFloor, so silence stays flat.-static const float kRange = 40, kPeakFall = 4, kPeakFloor = -60;+// 30 dB rather than more: a modern mix keeps every band within 40 of the loudest, which drew one flat plateau.+static const float kRange = 30, kPeakFall = 4, kPeakFloor = -60;// A rise toward the treble, in dB a band (three bands an octave), since music has less there: a tuning knob.static const float kTilt = 0.6f;// How quickly a band eases toward its level, up and down, in seconds; the hill behind is slower. With Reduce// Motion both ease over kStillEase.-static const double kFrontUp = 0.08, kFrontDown = 0.4, kBackUp = 0.3, kBackDown = 0.9, kStillEase = 3;+static const double kFrontUp = 0.12, kFrontDown = 0.5, kBackUp = 0.3, kBackDown = 0.9, kStillEase = 3;+// The beat: the kick's bands within kPulseRange dB of the peak light the front hill up, at once,+// and it dims again over kPulseDown; the hill never goes under kPulseFloor of its brightness.+static const float kPulseRange = 10, kPulseFloor = 0.5f;+static const double kPulseUp = 0.03, kPulseDown = 0.3;+// The luminance the hills add to the field. Under the footer's icons, where both hills lie on the field, white+// measured 7:1 on Currents in the simulator (6:1 at the very foot); 0.08 took them to 5.3:1 and 4.8:1.+static const CGFloat kGlow = 0.075;+// The glow's least saturation, for any flow color that has a hue at all (over kGrayBelow): the flow colors keep+// a dark cover's faint tint, which lifted to kGlow alone reads as silver.+static const CGFloat kGlowSaturation = 0.6, kGrayBelow = 0.08;// No new bands for this long reads as silence (a pause, a stall, a tap that never ran).static const double kStale = 0.3;// The hills' height at their tallest and at rest, as shares of the screen's height; the one behind is taller.-static const CGFloat kFrontHeight = 0.24, kBackHeight = 0.3, kRestHeight = 0.012;+static const CGFloat kFrontHeight = 0.2, kBackHeight = 0.26, kRestHeight = 0.008;+// The crest fade: the hills are opaque from kFadeFoot of the screen's height over the foot and clear from+// kFadeTop up, so the front hill at its tallest and the back one's crests dissolve into the field.+static const CGFloat kFadeFoot = 0.04, kFadeTop = 0.2;// Below this every band has settled (under 2 pt at the top of the front hill), and a paused song's link can stop.static const float kSettled = 0.02f;-// Each band shares this much with either neighbor, twice over, so one loud band is a hill and not a spike.+// Each band shares this much with either neighbor, three times over, so one loud band is a hill and not a spike.static const float kSpread = 0.25f;static const NSTimeInterval kTransitionSlack = 0.05;@@ -89,10 +111,11 @@ static NSDictionary *noActions(void) {UIView *_content; // the hills, faded in and out as oneCAGradientLayer *_backFill, *_frontFill;CAShapeLayer *_backShape, *_frontShape;+ CAGradientLayer *_crestFade; // the content's mask: clear at the tallest crest, opaque over the footUIVisualEffectView *_lyricsBlur;CADisplayLink *_link;BOOL _reading, _idle;- float _front[kBands], _back[kBands], _peak;+ float _front[kBands], _back[kBands], _peak, _pulse;uint64_t _generation;CFTimeInterval _fresh, _last;NSUInteger _palette;@@ -108,17 +131,39 @@ static CAGradientLayer *fill(CAShapeLayer *shape) {layer.actions = noActions();layer.startPoint = CGPointMake(0, 0.5);layer.endPoint = CGPointMake(1, 0.5);+ layer.compositingFilter = @"plusL";shape.actions = noActions();layer.mask = shape;return layer;}+static CGFloat toLinear(CGFloat c) { return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); }+static CGFloat toEncoded(CGFloat c) { return c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1 / 2.4) - 0.055; }++// `color` in its own hue at the relative luminance `luminance`, with its saturation lifted to kGlowSaturation+// so a dark red cover's glow is warm and not silver; black, near-black and gray come out gray.+static UIColor *lit(UIColor *color, CGFloat luminance) {+ CGFloat h = 0, s = 0, v = 0, r = 0, g = 0, b = 0, a = 1;+ [color getHue:&h saturation:&s brightness:&v alpha:&a];+ if (s > kGrayBelow) color = [UIColor colorWithHue:h saturation:MAX(s, kGlowSaturation) brightness:v alpha:1];+ [color getRed:&r green:&g blue:&b alpha:&a];+ CGFloat lr = toLinear(r), lg = toLinear(g), lb = toLinear(b);+ CGFloat have = 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;+ if (have < 0.001) return [UIColor colorWithWhite:toEncoded(luminance) alpha:1];+ CGFloat k = luminance / have;+ return [UIColor colorWithRed:toEncoded(MIN(1, lr * k)) green:toEncoded(MIN(1, lg * k)) blue:toEncoded(MIN(1, lb * k)) alpha:1];+}+- (instancetype)initWithFrame:(CGRect)frame {if (!(self = [super initWithFrame:frame])) return nil;self.userInteractionEnabled = NO;self.accessibilityElementsHidden = YES;_peak = kPeakFloor;_content = [[UIView alloc] initWithFrame:frame];+ _crestFade = [CAGradientLayer layer];+ _crestFade.actions = noActions();+ _crestFade.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.whiteColor.CGColor];+ _content.layer.mask = _crestFade;_backShape = [CAShapeLayer layer];_backFill = fill(_backShape);_backFill.opacity = 0.55f;@@ -157,8 +202,8 @@ static CAGradientLayer *fill(CAShapeLayer *shape) {// lower half under its upper.- (void)applyColors:(NSArray<UIColor *> *)colors {if (colors.count < 5) return;- _frontFill.colors = @[(id)colors[2].CGColor, (id)colors[4].CGColor, (id)colors[3].CGColor];- _backFill.colors = @[(id)colors[0].CGColor, (id)colors[1].CGColor];+ _frontFill.colors = @[(id)lit(colors[2], kGlow).CGColor, (id)lit(colors[4], kGlow).CGColor, (id)lit(colors[3], kGlow).CGColor];+ _backFill.colors = @[(id)lit(colors[0], kGlow).CGColor, (id)lit(colors[1], kGlow).CGColor];}- (void)artworkChanged {@@ -205,6 +250,7 @@ static CAGradientLayer *fill(CAShapeLayer *shape) {_frontFill.frame = bounds;_backShape.frame = bounds;_frontShape.frame = bounds;+ _crestFade.frame = bounds;[self draw];}@@ -316,9 +362,15 @@ static float ease(float value, float target, double dt, double up, double down)}if (!silent) _peak = fmaxf(fmaxf(loudest, _peak - kPeakFall * (float)dt), kPeakFloor);BOOL still = SGRReduceMotion();- float targets[kBands];+ float targets[kBands], kick = kPeakFloor;for (int band = 0; band < kBands; band++) targets[band] = silent ? 0 : fminf(1, fmaxf(0, (levels[band] - (_peak - kRange)) / kRange));- for (int pass = 0; pass < 2; pass++) {+ for (int band = kFirst; band < kFirst + kKickBands; band++) kick = fmaxf(kick, levels[band]);+ // The middle is a mound and never a valley: between kicks the kick's bands stand as tall as the bands beside+ // them (kBesideBands up), so the centre sinks only with the hills on either side and never under them.+ float beside = 0;+ for (int band = kFirst + kKickBands; band < kFirst + kKickBands + kBesideBands; band++) beside = fmaxf(beside, targets[band]);+ for (int band = kFirst; band < kFirst + kKickBands; band++) targets[band] = fmaxf(targets[band], beside);+ for (int pass = 0; pass < 3; pass++) {float before = targets[0];for (int band = 0; band < kBands; band++) {float here = targets[band], next = targets[MIN(band + 1, kBands - 1)];@@ -331,6 +383,8 @@ static float ease(float value, float target, double dt, double up, double down)_front[band] = ease(_front[band], target, dt, still ? kStillEase : kFrontUp, still ? kStillEase : kFrontDown);_back[band] = ease(_back[band], target, dt, still ? kStillEase : kBackUp, still ? kStillEase : kBackDown);}+ float beat = silent ? 0 : fminf(1, fmaxf(0, (kick - (_peak - kPulseRange)) / kPulseRange));+ _pulse = ease(_pulse, beat, dt, still ? kStillEase : kPulseUp, still ? kStillEase : kPulseDown);[self draw];BOOL idle = silent && self.settled;if (idle && !_idle) {@@ -367,7 +421,7 @@ static CGPathRef hillPath(const CGPoint *points, int count, CGFloat foot) {static void shape(CAShapeLayer *layer, const float *bands, CGFloat width, CGFloat baseline, CGFloat foot, CGFloat tallest, CGFloat rest) {CGPoint points[kPoints];for (int i = 0; i < kPoints; i++) {- float value = bands[abs(i - (kBands - 1))];+ float value = bands[kFirst + abs(i - (kShown - 1))];CGFloat height = rest + (tallest - rest) * powf(value, 1.2f);points[i] = CGPointMake(width * i / (kPoints - 1), baseline - height);}@@ -378,7 +432,7 @@ static void shape(CAShapeLayer *layer, const float *bands, CGFloat width, CGFloa- (void)draw {CGRect bounds = self.bounds;- if (bounds.size.width <= 0) return;+ if (bounds.size.width <= 0 || bounds.size.height <= 0) return;CGFloat baseline = _baseline > 0 ? _baseline : bounds.size.height;CGFloat screen = _screenHeight > 0 ? _screenHeight : bounds.size.height;CGFloat foot = MAX(baseline, bounds.size.height), rest = round(screen * kRestHeight);@@ -386,6 +440,9 @@ static void shape(CAShapeLayer *layer, const float *bands, CGFloat width, CGFloa[CATransaction setDisableActions:YES];shape(_backShape, _back, bounds.size.width, baseline, foot, screen * kBackHeight, rest * 1.5);shape(_frontShape, _front, bounds.size.width, baseline, foot, screen * kFrontHeight, rest);+ _frontFill.opacity = kPulseFloor + (1 - kPulseFloor) * _pulse;+ _crestFade.startPoint = CGPointMake(0.5, (baseline - screen * kFadeTop) / bounds.size.height);+ _crestFade.endPoint = CGPointMake(0.5, (baseline - screen * kFadeFoot) / bounds.size.height);[CATransaction commit];}