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: line-timed lyrics light line by line, plain lyrics show unsynced (#61)

Vojtěch Škopekfa0ae4f02746
diff --git a/harness/lyrics/README.md b/harness/lyrics/README.md
index b8cad2b1..be5d5b27 100644
--- a/harness/lyrics/README.md
+++ b/harness/lyrics/README.md
@@ -22,9 +22,20 @@ The fixtures are real TTML and LRC with every word swapped for filler of the sam
- `translated` Spanish with Apple's English translation and backing rows carried into it
- `both` Korean with both, and English lines the pronunciation leaves out
- `plain` line timed LRC, the words estimated, with a 13 s intro and a break after the first line
+- `linetimed` TTML timed by the line only (BiniLyrics' line timed shape): two voices, two lines sung
+ over each other at 42.4 s, a Hebrew line at 50.6 s, a 9 s break at 85.4 s, translations
+- `spotify-line`, `spotify-static` Spotify's own color-lyrics JSON, LINE_SYNCED and UNSYNCED, read by
+ the real `SGKaraokeLinesFromBody`; `static` plain text, as LRCLIB's plainLyrics or Spicy's Static
+ (these four are written by `fixtures/linetimed.py` from `plain`'s timing)
- `rtl` (built in) right to left lines among left to right ones, a second voice, a break before the
last line; `rtlx` the same with translations and a romanization
+Lines timed by the line light up whole; `-spotifyglass.lyricsSimulateWords 1` sweeps them on the
+estimate instead, as the Lyrics page's switch does. Untimed lyrics show every line lit, whatever `-at`.
+
+Run it on an iOS 26 simulator, by UDID: iOS 27 refuses an app without a scene delegate and crashes it
+at launch. `-dumpTo PATH` writes the dump to a file, for when `--console` shows nothing.
+
A real file goes in with `-file /path/song.ttml`: the simulator reads the Mac's paths.
`-perf LABEL` logs the view's per frame cost (its display link's `tick`) every 240 frames; run with
diff --git a/harness/lyrics/build.sh b/harness/lyrics/build.sh
index 8f980042..9a513cae 100755
--- a/harness/lyrics/build.sh
+++ b/harness/lyrics/build.sh
@@ -25,7 +25,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreText -framework Foundation \
-o "$APP/LyricsHarness"
-cp "$HERE"/fixtures/*.ttml "$HERE"/fixtures/*.lrc "$APP/"
+cp "$HERE"/fixtures/*.ttml "$HERE"/fixtures/*.lrc "$HERE"/fixtures/*.json "$HERE"/fixtures/*.txt "$APP/"
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">
diff --git a/harness/lyrics/fixtures/linetimed.py b/harness/lyrics/fixtures/linetimed.py
new file mode 100644
index 00000000..ecc584be
--- /dev/null
+++ b/harness/lyrics/fixtures/linetimed.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+"""Writes the fixtures for lyrics timed by the line and not at all (issue 61), from plain.lrc's timing
+and filler words, so they carry no song's lyrics:
+
+- linetimed.ttml Apple Music TTML with itunes:timing="Line": two voices, a pair of lines sung over
+ each other, a right to left line, an 11 s break, and an English translation of some
+ lines in the head, as BiniLyrics serves its line timed songs
+- spotify-line.json Spotify's color-lyrics JSON, syncType LINE_SYNCED
+- spotify-static.json the same, UNSYNCED, every start 0
+- static.txt plain text with stanza breaks, as LRCLIB's plainLyrics or Spicy's Static come
+
+ ./linetimed.py # rewrites all four next to this script
+"""
+import json
+import re
+from pathlib import Path
+
+HERE = Path(__file__).parent
+rows = []
+for row in (HERE / 'plain.lrc').read_text().splitlines():
+ m = re.match(r'\[(\d+):(\d+\.\d+)\]\s?(.*)', row)
+ if m:
+ rows.append((round((int(m[1]) * 60 + float(m[2])) * 1000), m[3]))
+
+
+def clock(ms):
+ return f'{ms // 60000}:{ms % 60000 / 1000:06.3f}'
+
+
+lines = [] # (start, end, text, voice)
+for i, (start, text) in enumerate(rows):
+ if not text or text == '♪':
+ continue
+ nxt = rows[i + 1][0] if i + 1 < len(rows) else start + 3000
+ lines.append([start, min(nxt, start + 4000), text, 'v1'])
+# The second voice takes every fourth line; the sixth line is sung over by the seventh, which comes in
+# half way through it; the ninth reads right to left.
+for n, line in enumerate(lines):
+ if n % 4 == 3:
+ line[3] = 'v2'
+lines[5][1] = lines[6][0] + 1500
+lines[6][0] = lines[5][0] + 1200
+lines[8][2] = 'שלום עולם אני שר לך'
+lines.sort(key=lambda l: l[0])
+
+translations = ''.join(f'<text for="L{n}">Translated {n}: {line[2].lower()}</text>'
+ for n, line in enumerate(lines) if n % 2 == 0)
+body = ''.join(f'<p begin="{clock(s)}" end="{clock(e)}" itunes:key="L{n}" ttm:agent="{v}">{t}</p>'
+ for n, (s, e, t, v) in enumerate(lines))
+(HERE / 'linetimed.ttml').write_text(
+ '<tt xmlns="http://www.w3.org/ns/ttml" xmlns:itunes="http://music.apple.com/lyric-ttml-internal" '
+ 'xmlns:ttm="http://www.w3.org/ns/ttml#metadata" itunes:timing="Line" xml:lang="en"><head><metadata>'
+ '<ttm:agent type="person" xml:id="v1"/><ttm:agent type="person" xml:id="v2"/>'
+ '<iTunesMetadata xmlns="http://music.apple.com/lyric-ttml-internal"><translations>'
+ f'<translation type="subtitle" xml:lang="en-US">{translations}</translation></translations>'
+ '</iTunesMetadata></metadata></head><body><div>' + body + '</div></body></tt>\n')
+
+
+def spotify(synced):
+ return json.dumps({'lyrics': {
+ 'syncType': 'LINE_SYNCED' if synced else 'UNSYNCED',
+ 'lines': [{'startTimeMs': str(s if synced else 0), 'words': t, 'syllables': [], 'endTimeMs': '0'}
+ for s, t in rows],
+ }}, ensure_ascii=False, indent=1) + '\n'
+
+
+(HERE / 'spotify-line.json').write_text(spotify(True))
+(HERE / 'spotify-static.json').write_text(spotify(False))
+(HERE / 'static.txt').write_text('\n'.join('' if t in ('', '♪') else t for _, t in rows) + '\n')
diff --git a/harness/lyrics/fixtures/linetimed.ttml b/harness/lyrics/fixtures/linetimed.ttml
new file mode 100644
index 00000000..44b3ad51
--- /dev/null
+++ b/harness/lyrics/fixtures/linetimed.ttml
@@ -0,0 +1 @@
+<tt xmlns="http://www.w3.org/ns/ttml" xmlns:itunes="http://music.apple.com/lyric-ttml-internal" xmlns:ttm="http://www.w3.org/ns/ttml#metadata" itunes:timing="Line" xml:lang="en"><head><metadata><ttm:agent type="person" xml:id="v1"/><ttm:agent type="person" xml:id="v2"/><iTunesMetadata xmlns="http://music.apple.com/lyric-ttml-internal"><translations><translation type="subtitle" xml:lang="en-US"><text for="L0">Translated 0: elit</text><text for="L2">Translated 2: e'te iusm su ps met emi rinc porinc</text><text for="L4">Translated 4: e'o usmo' ipsumdo ingelitsedd</text><text for="L6">Translated 6: ors tem ddoe du su sumd eddo m lorsi, etur</text><text for="L8">Translated 8: שלום עולם אני שר לך</text><text for="L10">Translated 10: e tem'p sed tempori tlor ors'ur mdol</text><text for="L12">Translated 12: um, e tem'p etcon uradi e mpor tetu lorsi"</text><text for="L14">Translated 14: di, tlor e'o lits rinc, ors'ur emi ita e tetur"</text><text for="L16">Translated 16: e'o orincid odt am elit</text><text for="L18">Translated 18: el e por emi dipi in itseddoei, etur, di</text><text for="L20">Translated 20: um ita's etcons do didun du (di)</text><text for="L22">Translated 22: e orem, "oei, e'o sumdolo mi emi didunt</text><text for="L24">Translated 24: e orem, "oei, e'o ididuntl in emi iusmo</text><text for="L26">Translated 26: e'o eddo ingelit mi do dte ors idid (mi do dte ors idid)</text><text for="L28">Translated 28: doei etura dte ors di rinc elit (oei)</text><text for="L30">Translated 30: um, e tem'p etcon uradi e mpor tetu lorsi"</text><text for="L32">Translated 32: (lor, lor, lor)</text><text for="L34">Translated 34: um, e tem'p etcon uradi e mpor tetu lorsi"</text></translation></translations></iTunesMetadata></metadata></head><body><div><p begin="0:13.130" end="0:16.560" itunes:key="L0" ttm:agent="v1">Elit</p><p begin="0:27.160" end="0:29.960" itunes:key="L1" ttm:agent="v1">E'te iusm turad dunt</p><p begin="0:29.960" end="0:32.710" itunes:key="L2" ttm:agent="v1">E'te iusm su ps met emi rinc porinc</p><p begin="0:32.710" end="0:36.710" itunes:key="L3" ttm:agent="v2">Didun ors tem orem du por do ngel, didun</p><p begin="0:38.290" end="0:41.230" itunes:key="L4" ttm:agent="v1">E'o usmo' ipsumdo ingelitsedd</p><p begin="0:41.230" end="0:45.620" itunes:key="L5" ttm:agent="v1">Ors tet'p empo oeiu do or tlo tura</p><p begin="0:42.430" end="0:48.120" itunes:key="L6" ttm:agent="v1">Ors tem ddoe du su sumd eddo m lorsi, etur</p><p begin="0:49.570" end="0:50.620" itunes:key="L7" ttm:agent="v2">E scin etcons tem</p><p begin="0:50.620" end="0:53.530" itunes:key="L8" ttm:agent="v1">שלום עולם אני שר לך</p><p begin="0:53.530" end="0:56.240" itunes:key="L9" ttm:agent="v1">Um ita's etcons do didun du (di)</p><p begin="0:56.240" end="1:00.240" itunes:key="L10" ttm:agent="v1">E tem'p sed tempori tlor ors'ur mdol</p><p begin="1:00.730" end="1:04.730" itunes:key="L11" ttm:agent="v2">E orem, "Oei, E'o sumdolo mi emi didunt</p><p begin="1:06.690" end="1:10.690" itunes:key="L12" ttm:agent="v1">Um, E tem'p etcon uradi E mpor tetu lorsi"</p><p begin="1:11.790" end="1:15.790" itunes:key="L13" ttm:agent="v1">E orem, "Oei, E'o ididuntl in emi iusmo</p><p begin="1:17.890" end="1:21.890" itunes:key="L14" ttm:agent="v1">Di, tlor E'o lits rinc, ors'ur emi ita E tetur"</p><p begin="1:22.160" end="1:25.440" itunes:key="L15" ttm:agent="v2">(Lor, lor, lor)</p><p begin="1:34.360" end="1:37.030" itunes:key="L16" ttm:agent="v1">E'o orincid odt am elit</p><p begin="1:37.030" end="1:40.040" itunes:key="L17" ttm:agent="v1">'Dtemp E tem sed emi ura cinge in emi doe</p><p begin="1:40.040" end="1:44.040" itunes:key="L18" ttm:agent="v1">El E por emi dipi in itseddoei, etur, di</p><p begin="1:46.640" end="1:49.520" itunes:key="L19" ttm:agent="v2">Emi isci's tetu tem iusmo (di)</p><p begin="1:49.520" end="1:52.470" itunes:key="L20" ttm:agent="v1">Um ita's etcons do didun du (di)</p><p begin="1:52.470" end="1:56.470" itunes:key="L21" ttm:agent="v1">E tem'p sed tempori tlor ors'ur mdol</p><p begin="1:56.980" end="2:00.980" itunes:key="L22" ttm:agent="v1">E orem, "Oei, E'o sumdolo mi emi didunt</p><p begin="2:02.700" end="2:06.700" itunes:key="L23" ttm:agent="v2">Um, E tem'p etcon uradi E mpor tetu lorsi"</p><p begin="2:07.940" end="2:11.940" itunes:key="L24" ttm:agent="v1">E orem, "Oei, E'o ididuntl in emi iusmo</p><p begin="2:14.000" end="2:18.000" itunes:key="L25" ttm:agent="v1">Di, tlor E'o lits rinc, ors'ur emi ita E tetur"</p><p begin="2:19.170" end="2:22.160" itunes:key="L26" ttm:agent="v1">E'o eddo ingelit mi do dte ors idid (mi do dte ors idid)</p><p begin="2:22.160" end="2:25.370" itunes:key="L27" ttm:agent="v2">E rsita etura its or su emi ectet (its or su emi ectet)</p><p begin="2:25.370" end="2:29.370" itunes:key="L28" ttm:agent="v1">Doei etura dte ors di rinc elit (oei)</p><p begin="2:30.270" end="2:34.270" itunes:key="L29" ttm:agent="v1">E orem, "Oei, E'o sumdolo mi emi didunt</p><p begin="2:36.330" end="2:40.330" itunes:key="L30" ttm:agent="v1">Um, E tem'p etcon uradi E mpor tetu lorsi"</p><p begin="2:40.500" end="2:43.980" itunes:key="L31" ttm:agent="v2">(Lor, lor, lor)</p><p begin="2:51.730" end="2:55.200" itunes:key="L32" ttm:agent="v1">(Lor, lor, lor)</p><p begin="3:03.900" end="3:07.900" itunes:key="L33" ttm:agent="v1">E orem, "Oei, E'o sumdolo mi emi didunt</p><p begin="3:10.120" end="3:14.120" itunes:key="L34" ttm:agent="v1">Um, E tem'p etcon uradi E mpor tetu lorsi"</p></div></body></tt>
diff --git a/harness/lyrics/fixtures/spotify-line.json b/harness/lyrics/fixtures/spotify-line.json
new file mode 100644
index 00000000..2a964e94
--- /dev/null
+++ b/harness/lyrics/fixtures/spotify-line.json
@@ -0,0 +1,247 @@
+{
+ "lyrics": {
+ "syncType": "LINE_SYNCED",
+ "lines": [
+ {
+ "startTimeMs": "13130",
+ "words": "Elit",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "16560",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "27160",
+ "words": "E'te iusm turad dunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "29960",
+ "words": "E'te iusm su ps met emi rinc porinc",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "32710",
+ "words": "Didun ors tem orem du por do ngel, didun",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "38290",
+ "words": "E'o usmo' ipsumdo ingelitsedd",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "41230",
+ "words": "Ors tet'p empo oeiu do or tlo tura",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "44120",
+ "words": "Ors tem ddoe du su sumd eddo m lorsi, etur",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "49570",
+ "words": "E scin etcons tem",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "50620",
+ "words": "Dol Isci's tetu tem iusmo (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "53530",
+ "words": "Um ita's etcons do didun du (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "56240",
+ "words": "E tem'p sed tempori tlor ors'ur mdol",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "60730",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "66690",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "71790",
+ "words": "E orem, \"Oei, E'o ididuntl in emi iusmo",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "77890",
+ "words": "Di, tlor E'o lits rinc, ors'ur emi ita E tetur\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "82160",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "85440",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "94360",
+ "words": "E'o orincid odt am elit",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "97030",
+ "words": "'Dtemp E tem sed emi ura cinge in emi doe",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "100040",
+ "words": "El E por emi dipi in itseddoei, etur, di",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "106640",
+ "words": "Emi isci's tetu tem iusmo (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "109520",
+ "words": "Um ita's etcons do didun du (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "112470",
+ "words": "E tem'p sed tempori tlor ors'ur mdol",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "116980",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "122700",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "127940",
+ "words": "E orem, \"Oei, E'o ididuntl in emi iusmo",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "134000",
+ "words": "Di, tlor E'o lits rinc, ors'ur emi ita E tetur\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "139170",
+ "words": "E'o eddo ingelit mi do dte ors idid (mi do dte ors idid)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "142160",
+ "words": "E rsita etura its or su emi ectet (its or su emi ectet)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "145370",
+ "words": "Doei etura dte ors di rinc elit (oei)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "150270",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "156330",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "160500",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "163980",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "171730",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "175200",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "183900",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "190120",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "194430",
+ "words": "",
+ "syllables": [],
+ "endTimeMs": "0"
+ }
+ ]
+ }
+}
diff --git a/harness/lyrics/fixtures/spotify-static.json b/harness/lyrics/fixtures/spotify-static.json
new file mode 100644
index 00000000..e35d1970
--- /dev/null
+++ b/harness/lyrics/fixtures/spotify-static.json
@@ -0,0 +1,247 @@
+{
+ "lyrics": {
+ "syncType": "UNSYNCED",
+ "lines": [
+ {
+ "startTimeMs": "0",
+ "words": "Elit",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E'te iusm turad dunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E'te iusm su ps met emi rinc porinc",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Didun ors tem orem du por do ngel, didun",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E'o usmo' ipsumdo ingelitsedd",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Ors tet'p empo oeiu do or tlo tura",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Ors tem ddoe du su sumd eddo m lorsi, etur",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E scin etcons tem",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Dol Isci's tetu tem iusmo (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um ita's etcons do didun du (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E tem'p sed tempori tlor ors'ur mdol",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o ididuntl in emi iusmo",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Di, tlor E'o lits rinc, ors'ur emi ita E tetur\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E'o orincid odt am elit",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "'Dtemp E tem sed emi ura cinge in emi doe",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "El E por emi dipi in itseddoei, etur, di",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Emi isci's tetu tem iusmo (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um ita's etcons do didun du (di)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E tem'p sed tempori tlor ors'ur mdol",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o ididuntl in emi iusmo",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Di, tlor E'o lits rinc, ors'ur emi ita E tetur\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E'o eddo ingelit mi do dte ors idid (mi do dte ors idid)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E rsita etura its or su emi ectet (its or su emi ectet)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Doei etura dte ors di rinc elit (oei)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "(Lor, lor, lor)",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "♪",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "E orem, \"Oei, E'o sumdolo mi emi didunt",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "Um, E tem'p etcon uradi E mpor tetu lorsi\"",
+ "syllables": [],
+ "endTimeMs": "0"
+ },
+ {
+ "startTimeMs": "0",
+ "words": "",
+ "syllables": [],
+ "endTimeMs": "0"
+ }
+ ]
+ }
+}
diff --git a/harness/lyrics/fixtures/static.txt b/harness/lyrics/fixtures/static.txt
new file mode 100644
index 00000000..16bb83fa
--- /dev/null
+++ b/harness/lyrics/fixtures/static.txt
@@ -0,0 +1,40 @@
+Elit
+
+E'te iusm turad dunt
+E'te iusm su ps met emi rinc porinc
+Didun ors tem orem du por do ngel, didun
+E'o usmo' ipsumdo ingelitsedd
+Ors tet'p empo oeiu do or tlo tura
+Ors tem ddoe du su sumd eddo m lorsi, etur
+E scin etcons tem
+Dol Isci's tetu tem iusmo (di)
+Um ita's etcons do didun du (di)
+E tem'p sed tempori tlor ors'ur mdol
+E orem, "Oei, E'o sumdolo mi emi didunt
+Um, E tem'p etcon uradi E mpor tetu lorsi"
+E orem, "Oei, E'o ididuntl in emi iusmo
+Di, tlor E'o lits rinc, ors'ur emi ita E tetur"
+(Lor, lor, lor)
+
+E'o orincid odt am elit
+'Dtemp E tem sed emi ura cinge in emi doe
+El E por emi dipi in itseddoei, etur, di
+Emi isci's tetu tem iusmo (di)
+Um ita's etcons do didun du (di)
+E tem'p sed tempori tlor ors'ur mdol
+E orem, "Oei, E'o sumdolo mi emi didunt
+Um, E tem'p etcon uradi E mpor tetu lorsi"
+E orem, "Oei, E'o ididuntl in emi iusmo
+Di, tlor E'o lits rinc, ors'ur emi ita E tetur"
+E'o eddo ingelit mi do dte ors idid (mi do dte ors idid)
+E rsita etura its or su emi ectet (its or su emi ectet)
+Doei etura dte ors di rinc elit (oei)
+E orem, "Oei, E'o sumdolo mi emi didunt
+Um, E tem'p etcon uradi E mpor tetu lorsi"
+(Lor, lor, lor)
+
+(Lor, lor, lor)
+
+E orem, "Oei, E'o sumdolo mi emi didunt
+Um, E tem'p etcon uradi E mpor tetu lorsi"
+
diff --git a/harness/lyrics/main.m b/harness/lyrics/main.m
index 02a87aa4..d30e300b 100644
--- a/harness/lyrics/main.m
+++ b/harness/lyrics/main.m
@@ -3,7 +3,8 @@
// without the phone. The songs are TTML read by the real SGTTML.m, or LRC timed by the real estimate.
//
// Launch arguments (the argument domain of NSUserDefaults, so a setting's key works as one too):
-// -song NAME fixtures/NAME.ttml or NAME.lrc in the app, or rtl, built here (default duet)
+// -song NAME fixtures/NAME.ttml, .lrc, .json (Spotify's own) or .txt (plain) in the app, or rtl,
+// built here (default duet)
// -file PATH a TTML or LRC file on the Mac instead
// -at MS where the clock starts (default 0)
// -rate X how fast it runs (default 1)
@@ -15,7 +16,8 @@
// -dump 1 prints the lines as read, with their pronunciations and translations, and quits
// -openMenu S opens the pronunciation and translation menu S seconds in, as a tap on its button would
// -toggleAt S switches the pronunciation and the translation over S seconds in, as the menu would
-// and the lyrics' own settings by their keys: -spotifyglass.redesign.lyricsPronunciation 1,
+// and the lyrics' own settings by their keys: -spotifyglass.lyricsSimulateWords 1 (sweep line timed
+// lines on the estimate), -spotifyglass.redesign.lyricsPronunciation 1,
// -spotifyglass.redesign.lyricsTranslation 1, -spotifyglass.redesign.lyricsTextOrder '(translation, lyrics, pronunciation)'.
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@@ -106,15 +108,27 @@ static NSArray<SGKaraokeLine *> *linesOfLRC(NSString *lrc) {
static NSArray<SGKaraokeLine *> *songNamed(NSString *name, NSString *file) {
if (!file && [name isEqualToString:@"rtl"]) return rightToLeftSong();
if (!file && [name isEqualToString:@"rtlx"]) return rightToLeftSongWithExtras();
- NSString *path = file ?: [NSBundle.mainBundle pathForResource:name ofType:@"ttml"] ?: [NSBundle.mainBundle pathForResource:name ofType:@"lrc"];
+ NSString *path = file;
+ for (NSString *type in @[@"ttml", @"lrc", @"json", @"txt"]) path = path ?: [NSBundle.mainBundle pathForResource:name ofType:type];
NSString *text = path ? [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil] : nil;
if (!text) NSLog(@"harness: no song at %@", path ?: name);
- return [path.pathExtension isEqualToString:@"lrc"] ? linesOfLRC(text) : SGTTMLLines(text);
+ NSString *type = path.pathExtension;
+ // Spotify's own color-lyrics JSON, read by the real parser, and plain text as the sources hand it on.
+ if ([type isEqualToString:@"json"]) return SGKaraokeLinesFromBody([text dataUsingEncoding:NSUTF8StringEncoding]);
+#ifdef SGKeyLyricsSimulateWords
+ if ([type isEqualToString:@"txt"]) return SGKaraokeStaticLines([text componentsSeparatedByString:@"\n"]);
+#endif
+ return [type isEqualToString:@"lrc"] ? linesOfLRC(text) : SGTTMLLines(text);
}
static void dump(NSArray<SGKaraokeLine *> *lines) {
for (SGKaraokeLine *line in lines) {
- printf("%7ld-%7ld %s %s\n", (long)line.start, (long)line.end, line.align ? "R" : "L", SGKaraokeLineText(line).UTF8String);
+#ifdef SGKeyLyricsSimulateWords
+ const char *timing = line.timing == SGKaraokeTimingWords ? "W" : line.timing == SGKaraokeTimingLine ? "~" : "-";
+#else
+ const char *timing = "?";
+#endif
+ printf("%7ld-%7ld %s%s %s\n", (long)line.start, (long)line.end, timing, line.align ? "R" : "L", SGKaraokeLineText(line).UTF8String);
if (line.backing) printf(" bg %s\n", SGKaraokeLineText(line.backing).UTF8String);
#ifdef SGRKeyLyricsTextOrder
// A pronunciation's words with the time each starts, "+" before one joined to the word before.
@@ -176,7 +190,9 @@ static void timedTick(id self, SEL _cmd) {
#endif
NSString *song = [args stringForKey:@"song"] ?: @"duet";
SGKaraokeKeepLines(@"harness", songNamed(song, [args stringForKey:@"file"]));
- if ([args boolForKey:@"dump"]) {
+ // -dumpTo PATH: the dump into a file on the Mac, for when simctl launch --console shows nothing.
+ if ([args stringForKey:@"dumpTo"]) freopen([args stringForKey:@"dumpTo"].fileSystemRepresentation, "w", stdout);
+ if ([args boolForKey:@"dump"] || [args stringForKey:@"dumpTo"]) {
dump(SGKaraokeLinesForTrack(@"harness"));
exit(0);
}
diff --git a/harness/lyrics/stubs.m b/harness/lyrics/stubs.m
index 3f601ad4..8a56f877 100644
--- a/harness/lyrics/stubs.m
+++ b/harness/lyrics/stubs.m
@@ -11,6 +11,7 @@ NSString *const SGPlayerTransitionEndedNotification = @"spotifyglass.playerTrans
CFTimeInterval SGPlayerTransitionEnds(void) { return 0; }
void SGRPlayFeedback(NSInteger feedback) {}
+void SGPlayFeedback(NSInteger feedback) {} // the name it has had since Haptics moved to Shared
NSString *SGLyricsCreditFor(NSString *trackID) { return @"the harness"; }
// -translateTo es: the language the Lyrics page would ask translations for.
NSString *SGLyricsTranslationLanguage(void) { return [NSUserDefaults.standardUserDefaults stringForKey:@"translateTo"]; }
diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.m
index 105032f4..7e3795ba 100644
--- a/tweak/Sources/App/Pages.m
+++ b/tweak/Sources/App/Pages.m
@@ -79,6 +79,7 @@ static UIViewController *lyricsPage(void) {
if (redesigned) {
[sections addObject:SGNotedSection(@"Pronunciation and translation", @[SGRLyricsTextSizesRow(), SGLyricsTranslationLanguageRow()],
@"BiniLyrics and Unison carry Apple Music's own for many songs. The button in the corner of the lyrics shows them.")];
+ [sections addObject:SGLyricsWordTimingSection()];
}
[sections addObject:SGSection(nil, more)];
return [[SGModPage alloc] initWithTitle:@"Lyrics" intro:SGRestartNote sections:sections footer:nil];
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
index 5a27245b..f0d4cbb0 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
@@ -2,6 +2,11 @@
// rest dim and blur with distance. Lines two voices sing at once are lit together, an instrumental
// break holds three dots, and a line can show its pronunciation and its translation under it. The
// lines and the clock are Shared/Lyrics/Lyrics.h's.
+//
+// Only words the source timed are swept. A line timed by the line lights up whole as it starts, as
+// Apple Music lights such a line, unless the Lyrics page's "Simulate word-by-word timing" asks for
+// its estimated words to be swept; lyrics with no timing at all are shown as plain text, every line
+// lit, nothing following the clock.
#import "Core/SGCore.h"
#import "SGRKaraokeView.h"
#import "LyricsText.h"
@@ -25,6 +30,9 @@ static const CGFloat kExtrasSide = 44, kExtrasBottom = 12, kExtrasGlyph = 17, kE
static const NSTimeInterval kRestyleFade = 0.3; // the lines crossfading to a new style
static const NSTimeInterval kBrowseHold = 3; // after scrolling by hand, how long until it follows the song again
static const double kFloatMinMs = 700, kFloatLeadMs = 80; // a short word still floats up this slowly
+// A line lit whole: how long its words take to come up to full white, and to float up together.
+static const NSTimeInterval kWholeFade = 0.35;
+static const double kWholeRiseMs = 900;
static const double kClockSnapMs = 250, kClockPull = 0.08;
// Lines get views this far outside the visible part, in screen heights: half a screen above it
// and below, and a quarter more before a view is let go. Every view held is one more for the window
@@ -108,6 +116,10 @@ static UILabel *wordLabel(NSString *text, UIFont *font, UIColor *color, CGRect f
@property (nonatomic, readonly) SGKaraokeWord *word;
@property (nonatomic, readonly) UILabel *lit;
@property (nonatomic) CGFloat offset; // where the word starts along its line, rows laid end to end
+// Lit with the rest of its line at once rather than swept, and floated up with it over riseStart to
+// riseEnd, which are the word's own times until the sweep says otherwise.
+@property (nonatomic) BOOL whole;
+@property (nonatomic) double riseStart, riseEnd;
- (void)fillTo:(CGFloat)cursor;
- (void)floatAt:(double)ms;
- (void)settle;
@@ -124,6 +136,8 @@ static UILabel *wordLabel(NSString *text, UIFont *font, UIColor *color, CGRect f
self = [super initWithFrame:CGRectMake(0, 0, ceil(size.width), ceil(font.lineHeight))];
if (!self) return nil;
_word = word;
+ _riseStart = word.start;
+ _riseEnd = word.end;
_rightToLeft = rightToLeft;
[self addSubview:wordLabel(word.text, font, [UIColor colorWithWhite:1 alpha:kDimAlpha], self.bounds, rightToLeft)];
_lit = wordLabel(word.text, font, UIColor.whiteColor, self.bounds, rightToLeft);
@@ -162,7 +176,7 @@ static UILabel *wordLabel(NSString *text, UIFont *font, UIColor *color, CGRect f
// Rises like a critically damped spring let go as the word starts: no jolt, a long soft landing.
// x = 5 at the end of the word is 96 % of the way up.
- (void)floatAt:(double)ms {
- double x = MAX(0, ms - _word.start + kFloatLeadMs) / MAX(_word.end - _word.start, kFloatMinMs) * 5;
+ double x = MAX(0, ms - _riseStart + kFloatLeadMs) / MAX(_riseEnd - _riseStart, kFloatMinMs) * 5;
CGFloat lift = kLift * (1 - (1 + x) * exp(-x));
if (lift == _lift) return;
_lift = lift;
@@ -494,20 +508,32 @@ typedef struct {
} SGSweepKnot;
// One run of words lit by one sweep: a line's own, or its pronunciation's, each timed by its own words.
+// A whole one lights every word of the run at once from `start`, for a run whose words are not timed.
@interface SGRKaraokeSweep : NSObject
@property (nonatomic, readonly) NSArray<SGRKaraokeWordView *> *words;
-- (instancetype)initWithWords:(NSArray<SGRKaraokeWordView *> *)words;
+- (instancetype)initWithWords:(NSArray<SGRKaraokeWordView *> *)words wholeFrom:(double)start;
- (void)showTime:(double)ms;
@end
@implementation SGRKaraokeSweep {
SGSweepKnot *_knots;
NSUInteger _knotCount;
+ BOOL _whole;
}
-- (instancetype)initWithWords:(NSArray<SGRKaraokeWordView *> *)words {
+// start: NAN to sweep the words by their own times.
+- (instancetype)initWithWords:(NSArray<SGRKaraokeWordView *> *)words wholeFrom:(double)start {
if (!(self = [super init])) return nil;
_words = words;
+ _whole = !isnan(start);
+ if (_whole) {
+ for (SGRKaraokeWordView *word in words) {
+ word.whole = YES;
+ word.riseStart = start;
+ word.riseEnd = start + kWholeRiseMs;
+ }
+ return self;
+ }
[self buildSweep];
return self;
}
@@ -562,7 +588,8 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {
}
- (void)showTime:(double)ms {
- CGFloat cursor = [self cursorAt:ms];
+ // A whole run is only ever shown while its line is sung, so it is lit throughout.
+ CGFloat cursor = _whole ? CGFLOAT_MAX : [self cursorAt:ms];
for (SGRKaraokeWordView *word in _words) {
[word fillTo:cursor];
[word floatAt:ms];
@@ -580,9 +607,13 @@ static double secant(SGSweepKnot *knots, NSUInteger i) {
@property (nonatomic, readonly) BOOL right;
@property (nonatomic) BOOL active;
@property (nonatomic) CGFloat blur;
-// under: the line a backing row hangs under, nil for a line of its own.
-- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width style:(SGRKaraokeStyle *)style under:(SGRKaraokeLineView *)under blurred:(BOOL)blurred;
+// under: the line a backing row hangs under, nil for a line of its own. sweepsEstimates: the words of a
+// line timed only by the line are swept on their estimated times, rather than lit whole.
+- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width style:(SGRKaraokeStyle *)style under:(SGRKaraokeLineView *)under
+ blurred:(BOOL)blurred sweepsEstimates:(BOOL)sweepsEstimates;
- (void)showTime:(double)ms;
+// Every word lit and left so, for lyrics with no timing: nothing is sung, so nothing is dim.
+- (void)showPlain;
@end
// The translation of a line being sung, brighter than a line waiting but never as bright as the words.
@@ -597,7 +628,9 @@ static const CGFloat kTranslationLit = 0.6;
}
// A sweep's word views, each put where the layout has it and told where it sits along the sweep.
-- (SGRKaraokeSweep *)sweepOf:(NSArray<SGKaraokeWord *> *)words font:(UIFont *)font frames:(NSArray<NSValue *> *)frames offsets:(NSArray<NSNumber *> *)offsets {
+// start: NAN for words timed one by one, else when the run lights up whole.
+- (SGRKaraokeSweep *)sweepOf:(NSArray<SGKaraokeWord *> *)words font:(UIFont *)font frames:(NSArray<NSValue *> *)frames
+ offsets:(NSArray<NSNumber *> *)offsets wholeFrom:(double)start {
if (!words.count || frames.count != words.count) return nil;
BOOL rightToLeft = readsRightToLeft([[words valueForKey:@"text"] componentsJoinedByString:@""]);
NSMutableArray<SGRKaraokeWordView *> *views = [NSMutableArray arrayWithCapacity:words.count];
@@ -609,10 +642,18 @@ static const CGFloat kTranslationLit = 0.6;
[self addSubview:view];
[views addObject:view];
}
- return [[SGRKaraokeSweep alloc] initWithWords:views];
+ return [[SGRKaraokeSweep alloc] initWithWords:views wholeFrom:start];
+}
+
+// When a run of the line lights up whole, or NAN to sweep it: only words the source timed are swept,
+// unless the estimate is asked for.
+static double wholeFrom(SGKaraokeLine *run, BOOL sweepsEstimates) {
+ if (run.timing == SGKaraokeTimingWords || (run.timing == SGKaraokeTimingLine && sweepsEstimates)) return NAN;
+ return run.start;
}
-- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width style:(SGRKaraokeStyle *)style under:(SGRKaraokeLineView *)under blurred:(BOOL)blurred {
+- (instancetype)initWithLine:(SGKaraokeLine *)line width:(CGFloat)width style:(SGRKaraokeStyle *)style under:(SGRKaraokeLineView *)under
+ blurred:(BOOL)blurred sweepsEstimates:(BOOL)sweepsEstimates {
self = [super initWithFrame:CGRectZero];
if (!self) return nil;
_line = line;
@@ -620,8 +661,10 @@ static const CGFloat kTranslationLit = 0.6;
SGRKaraokeLayout *layout = layOut(line, width, style, backing ? under.right : -1);
_right = layout.right;
NSMutableArray<SGRKaraokeSweep *> *sweeps = [NSMutableArray array];
- SGRKaraokeSweep *sung = [self sweepOf:line.words font:style.lyrics frames:layout.lyricFrames offsets:layout.lyricOffsets];
- SGRKaraokeSweep *spoken = [self sweepOf:line.pronunciation.words font:style.pronunciation frames:layout.spokenFrames offsets:layout.spokenOffsets];
+ SGRKaraokeSweep *sung = [self sweepOf:line.words font:style.lyrics frames:layout.lyricFrames offsets:layout.lyricOffsets
+ wholeFrom:wholeFrom(line, sweepsEstimates)];
+ SGRKaraokeSweep *spoken = [self sweepOf:line.pronunciation.words font:style.pronunciation frames:layout.spokenFrames
+ offsets:layout.spokenOffsets wholeFrom:wholeFrom(line.pronunciation, sweepsEstimates)];
if (sung) [sweeps addObject:sung];
if (spoken) [sweeps addObject:spoken];
_sweeps = sweeps;
@@ -638,7 +681,8 @@ static const CGFloat kTranslationLit = 0.6;
[self addSubview:_translation];
}
if (layout.backingTop > 0) {
- _backing = [[SGRKaraokeLineView alloc] initWithLine:line.backing width:width style:style.backing under:self blurred:NO];
+ _backing = [[SGRKaraokeLineView alloc] initWithLine:line.backing width:width style:style.backing under:self blurred:NO
+ sweepsEstimates:sweepsEstimates];
_backing.alpha = kBackingAlpha;
_backing.frame = CGRectMake(0, layout.backingTop, width, _backing.bounds.size.height);
[self addSubview:_backing];
@@ -683,14 +727,21 @@ static const NSUInteger kLinesPerFrame = 4;
animations:^{ self->_translation.alpha = active ? kTranslationLit : kDimAlpha; } completion:nil];
}
if (active) {
+ NSMutableArray<SGRKaraokeWordView *> *whole = [NSMutableArray array];
for (SGRKaraokeWordView *word in _words) {
[word.layer removeAllAnimations];
[word.lit.layer removeAllAnimations];
word.lit.alpha = 1;
word.lit.hidden = NO;
- [word fillTo:-CGFLOAT_MAX];
+ [word fillTo:word.whole ? CGFLOAT_MAX : -CGFLOAT_MAX];
[word settle];
+ if (word.whole) [whole addObject:word];
}
+ // A line lit whole comes up to white together rather than popping on, as Apple Music's do.
+ if (!whole.count) return;
+ for (SGRKaraokeWordView *word in whole) word.lit.alpha = 0;
+ [UIView animateWithDuration:kWholeFade delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
+ animations:^{ for (SGRKaraokeWordView *word in whole) word.lit.alpha = 1; } completion:nil];
return;
}
// A sung line fades back to dim rather than dropping its fill at once, and its words sink back
@@ -717,6 +768,16 @@ static const NSUInteger kLinesPerFrame = 4;
[_backing showTime:ms]; // timed on its own, so it lags the line as it is sung
}
+- (void)showPlain {
+ for (SGRKaraokeWordView *word in _words) {
+ word.lit.hidden = NO;
+ word.lit.alpha = 1;
+ [word fillTo:CGFLOAT_MAX];
+ }
+ _translation.alpha = kTranslationLit;
+ [_backing showPlain];
+}
+
@end
#pragma mark - a break
@@ -940,6 +1001,8 @@ typedef struct {
double _clock;
NSInteger _reported;
CFTimeInterval _clockTime;
+ BOOL _sweepsEstimates; // the Lyrics page's "Simulate word-by-word timing", read once like the credit
+ BOOL _plain; // the song has no timing at all: every line lit, nothing follows the clock
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -972,6 +1035,7 @@ typedef struct {
_credit.textColor = [UIColor colorWithWhite:1 alpha:kCreditAlpha];
_credit.hidden = YES;
_crediting = SGFlag(SGKeyLyricsCredit, NO);
+ _sweepsEstimates = SGFlag(SGKeyLyricsSimulateWords, NO);
[self addSubview:_credit];
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(playerTransitionChanged:) name:SGPlayerTransitionNotification object:nil];
@@ -992,6 +1056,7 @@ typedef struct {
- (void)tapped:(UITapGestureRecognizer *)tap {
if (_extras && !_extras.hidden && CGRectContainsPoint(_extras.frame, [tap locationInView:self])) return;
+ if (_plain) return; // a line with no time has nowhere to seek to
CGPoint point = [tap locationInView:_scroll];
for (SGRKaraokeLineView *view in _shown.allValues) {
if (!CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), point)) continue;
@@ -1016,12 +1081,13 @@ typedef struct {
[self showLinesInSight];
}
+// Plain text has no song to follow back to: it stays where it was scrolled to, as a page of text does.
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- if (!decelerate) [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];
+ if (!decelerate && !_plain) [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];
+ if (!_plain) [self performSelector:@selector(followSong) withObject:nil afterDelay:kBrowseHold];
}
- (void)followSong {
@@ -1132,11 +1198,12 @@ typedef struct {
_breaks = calloc(count + 1, sizeof(SGRKaraokeBreak));
_breakCount = 0;
_hasSpoken = _hasTranslation = NO;
+ _plain = SGKaraokeLinesTiming(_lines) == SGKaraokeTimingNone;
NSInteger sungTo = 0; // the top of the song counts as where the singing before the first line ends
for (NSUInteger i = 0; i < count; i++) {
SGKaraokeLine *line = _lines[i];
_spans[i] = (SGRKaraokeSpan){line.start, SGKaraokeSungEnd(line)};
- if (line.start - sungTo >= kBreakMinMs) _breaks[_breakCount++] = (SGRKaraokeBreak){sungTo, line.start, (NSInteger)i};
+ if (!_plain && line.start - sungTo >= kBreakMinMs) _breaks[_breakCount++] = (SGRKaraokeBreak){sungTo, line.start, (NSInteger)i};
sungTo = MAX(sungTo, _spans[i].end);
_hasSpoken = _hasSpoken || line.pronunciation || line.backing.pronunciation;
_hasTranslation = _hasTranslation || line.translation.length;
@@ -1284,6 +1351,7 @@ typedef struct {
// nearest line being sung, from an open break as if it were a line of its own, and before the first
// line from the line before it, as ever.
- (NSInteger)distanceOf:(NSInteger)index {
+ if (_plain) return 0; // nothing is sung, so every line reads as clearly as the rest
if (_openBreak >= 0) return index >= _openBreak ? index - _openBreak + 1 : _openBreak - index;
if (!_sungCount) return labs(index - _focus);
NSInteger nearest = NSIntegerMax;
@@ -1295,7 +1363,9 @@ typedef struct {
- (SGRKaraokeLineView *)viewForLine:(NSInteger)index {
SGRKaraokeLineView *view = _shown[@(index)];
if (view || !_tops || index < 0 || index >= (NSInteger)_tops.count) return view;
- view = [[SGRKaraokeLineView alloc] initWithLine:_lines[index] width:_builtWidth - 2 * _margin style:_style under:nil blurred:_maxBlur > 0];
+ view = [[SGRKaraokeLineView alloc] initWithLine:_lines[index] width:_builtWidth - 2 * _margin style:_style under:nil
+ blurred:_maxBlur > 0 && !_plain sweepsEstimates:_sweepsEstimates];
+ if (_plain) [view showPlain];
[_scroll addSubview:view];
_shown[@(index)] = view;
[self placeLine:view at:index animated:NO];
@@ -1468,6 +1538,15 @@ typedef struct {
[self dropLineViews];
[self offerExtras];
}
+ // Plain text is shown while Spotify is asked whether it has the song timed; its answer replaces it.
+ NSArray<SGKaraokeLine *> *kept = _plain && _lines && track ? SGKaraokeLinesForTrack(track) : nil;
+ if (kept && kept != _lines) {
+ SGLog(@"karaoke: timed lines of %@ came in over the plain text", track);
+ _lines = nil;
+ _builtWidth = 0;
+ [self creditTo:nil];
+ [self dropLineViews];
+ }
if (!_lines && track && (_lines = SGKaraokeLinesForTrack(track))) {
SGLog(@"karaoke: showing %lu lines of %@", (unsigned long)_lines.count, track);
[self timeLines];
@@ -1478,6 +1557,10 @@ typedef struct {
if (_crediting && _lines && !_credit.text.length) [self creditTo:SGLyricsCreditFor(track)];
if (!_tops) return;
[self alignFade];
+ if (_plain) {
+ [self showLinesInSight]; // it moves only when scrolled by hand
+ return;
+ }
double now = [self clockMs];
NSInteger sung[kMostSung], focus, openBreak;
diff --git a/tweak/Sources/Shared/LiveActivity/LiveActivity.x b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
index 1db5bc0d..4e1eb6d8 100644
--- a/tweak/Sources/Shared/LiveActivity/LiveActivity.x
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
@@ -112,6 +112,8 @@ static NSString *lyricsLine(NSString *trackID, NSString **next) {
SGLog(@"live activity: no lyrics yet for %@", trackID);
}
}
+ // Plain text has no line being sung: the note, as for a track with no lyrics.
+ if (lines && SGKaraokeLinesTiming(lines) == SGKaraokeTimingNone) lines = nil;
NSInteger position = SGKaraokePositionMs();
// With two voices at once, the one that came in first, and the one singing over it as the next.
NSInteger index = SGKaraokeLeadLine(lines, position);
diff --git a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
index 1bda0299..c7a906e9 100644
--- a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
+++ b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
@@ -60,7 +60,7 @@ static double elapsedAt(NSDictionary *info, CFAbsoluteTime reportedAt, CFAbsolut
return [info[MPNowPlayingInfoPropertyElapsedPlaybackTime] doubleValue] + rate * (now - reportedAt);
}
-// nil between lines and for a track without synced lyrics.
+// nil between lines and for a track without synced lyrics, plain text included.
static NSString *lineFor(NSDictionary *info, double elapsed) {
SPTPlayerState *state = [(id<SPTPlayer>)SGKaraokePlayer() state];
// The player's track can lag behind the now playing info; its lyrics would then be another song's.
@@ -71,6 +71,8 @@ static NSString *lineFor(NSDictionary *info, double elapsed) {
SGKaraokeRequestLyrics(trackID);
return nil;
}
+ // Plain text has no line being sung to show.
+ if (SGKaraokeLinesTiming(lines) == SGKaraokeTimingNone) return nil;
NSInteger position = (NSInteger)(elapsed * 1000);
NSInteger index = SGKaraokeLeadLine(lines, position);
if (index < 0) return nil;
diff --git a/tweak/Sources/Shared/Lyrics/KaraokeSource.x b/tweak/Sources/Shared/Lyrics/KaraokeSource.x
index 91617064..d84ab8b5 100644
--- a/tweak/Sources/Shared/Lyrics/KaraokeSource.x
+++ b/tweak/Sources/Shared/Lyrics/KaraokeSource.x
@@ -55,11 +55,14 @@ static void rememberHeaders(NSURLSession *session, NSURLRequest *request) {
dispatch_async(dispatch_get_main_queue(), ^{ sg_spclientHeaders = headers; });
}
+// Main queue only.
+static void keep(NSString *track, NSArray<SGKaraokeLine *> *lines) {
+ if (sg_lyrics.count >= kKeptTracks && !sg_lyrics[track]) [sg_lyrics removeAllObjects];
+ sg_lyrics[track] = lines;
+}
+
void SGKaraokeKeepLines(NSString *track, NSArray<SGKaraokeLine *> *lines) {
- dispatch_async(dispatch_get_main_queue(), ^{
- if (sg_lyrics.count >= kKeptTracks) [sg_lyrics removeAllObjects];
- sg_lyrics[track] = lines;
- });
+ dispatch_async(dispatch_get_main_queue(), ^{ keep(track, lines); });
}
static void received(NSURLSession *session, NSURLSessionTask *task, NSData *data) {
@@ -107,15 +110,27 @@ static void requestFromSpotify(NSString *trackID) {
[NSURLProtocol setProperty:@YES forKey:SGLyricsOwnRequestKey inRequest:request];
[[NSURLSession.sharedSession dataTaskWithRequest:request completionHandler:^(NSData *body, NSURLResponse *response, NSError *error) {
NSArray<SGKaraokeLine *> *lines = SGKaraokeLinesFromBody(body);
- SGLog(@"karaoke: fetched lyrics for %@: status %ld, %lu synced lines, error %@", trackID,
- (long)[(NSHTTPURLResponse *)response statusCode], (unsigned long)lines.count, error);
- if (lines) {
- SGKaraokeKeepLines(trackID, lines);
+ SGLog(@"karaoke: fetched lyrics for %@: status %ld, %lu lines (%@), error %@", trackID,
+ (long)[(NSHTTPURLResponse *)response statusCode], (unsigned long)lines.count,
+ SGKaraokeLinesTiming(lines) == SGKaraokeTimingNone ? @"untimed" : @"line timed", error);
+ if (!lines) return;
+ // Asked after the chain found plain text only: Spotify's replace it only when they are timed.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSArray<SGKaraokeLine *> *kept = sg_lyrics[trackID];
+ if (kept && SGKaraokeLinesTiming(kept) <= SGKaraokeLinesTiming(lines)) return;
+ keep(trackID, lines);
SGLyricsSetCredit(trackID, @"Spotify");
- }
+ });
}] resume];
}
+void SGKaraokeAskSpotifyForTiming(NSString *trackID) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (!trackID || [sg_requested containsObject:trackID]) return;
+ requestFromSpotify(trackID);
+ });
+}
+
void SGKaraokeRequestLyrics(NSString *trackID) {
if (!trackID || sg_lyrics[trackID] || [sg_requested containsObject:trackID]) return;
if (!sg_ownSources) {
@@ -125,9 +140,10 @@ void SGKaraokeRequestLyrics(NSString *trackID) {
[sg_requested addObject:trackID];
SGLyricsFetch(trackID, ^(SGLyricsResult *lyrics) {
if (lyrics.karaokeLines) {
- SGKaraokeKeepLines(trackID, lyrics.karaokeLines);
+ keep(trackID, lyrics.karaokeLines); // on the main queue, where the fetch answers
SGLyricsSetCredit(trackID, lyrics.provider);
- return;
+ // Plain text is shown while Spotify is asked whether it has the song timed.
+ if (SGKaraokeLinesTiming(lyrics.karaokeLines) != SGKaraokeTimingNone) return;
}
[sg_requested removeObject:trackID];
requestFromSpotify(trackID);
diff --git a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
index 9a781cbd..25dbde4e 100644
--- a/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
+++ b/tweak/Sources/Shared/Lyrics/KaraokeTiming.m
@@ -164,6 +164,7 @@ static SGKaraokeLine *timedLine(NSString *text, NSInteger start, NSInteger gap)
line.words = words;
line.start = start;
line.end = start + sung;
+ line.timing = SGKaraokeTimingLine;
return line;
}
@@ -178,30 +179,58 @@ NSArray<SGKaraokeLine *> *SGKaraokeEstimatedLines(NSArray<NSNumber *> *starts, N
return lines.count ? lines : nil;
}
+NSArray<SGKaraokeLine *> *SGKaraokeStaticLines(NSArray<NSString *> *texts) {
+ NSMutableArray<SGKaraokeLine *> *lines = [NSMutableArray array];
+ for (NSString *text in texts) {
+ if (![text isKindOfClass:NSString.class] || isBreak(text)) continue;
+ NSArray<SGKaraokeWord *> *words = piecesOf(text);
+ if (!words.count) continue;
+ SGKaraokeLine *line = [SGKaraokeLine new];
+ line.words = words;
+ line.timing = SGKaraokeTimingNone;
+ [lines addObject:line];
+ }
+ return lines.count ? lines : nil;
+}
+
+SGKaraokeTiming SGKaraokeLinesTiming(NSArray<SGKaraokeLine *> *lines) {
+ SGKaraokeTiming finest = SGKaraokeTimingNone;
+ for (SGKaraokeLine *line in lines) finest = MIN(finest, line.timing);
+ return finest;
+}
+
#pragma mark - Spotify's own bodies
// Lyrics { 1 data: { 1 time_synchronized, 2 repeated line: { 1 offset_ms, 2 content } }, 2 colors }
+// Not time_synchronized, the lines are plain text and their offsets all 0. The flag alone is not
+// trusted: Spotify's page body has come without it for lines its JSON calls LINE_SYNCED, so any
+// offset past 0 counts as timed too.
static NSArray<SGKaraokeLine *> *fromProtobuf(NSData *body) {
SGPBField *data = SGPBFirst(SGPBParse(body), 1);
if (data.wire != 2) return nil;
NSArray<SGPBField *> *fields = SGPBParse(data.payload);
- if (!SGPBFirst(fields, 1).varint) return nil;
+ BOOL synced = SGPBFirst(fields, 1).varint != 0;
NSMutableArray<NSNumber *> *starts = [NSMutableArray array];
NSMutableArray<NSString *> *texts = [NSMutableArray array];
for (SGPBField *field in fields) {
if (field.number != 2 || field.wire != 2) continue;
NSArray<SGPBField *> *line = SGPBParse(field.payload);
- [starts addObject:@((int32_t)SGPBFirst(line, 1).varint)];
+ int32_t start = (int32_t)SGPBFirst(line, 1).varint;
+ if (start > 0) synced = YES;
+ [starts addObject:@(start)];
[texts addObject:SGPBText(SGPBFirst(line, 2)) ?: @""];
}
- return SGKaraokeEstimatedLines(starts, texts);
+ return synced ? SGKaraokeEstimatedLines(starts, texts) : SGKaraokeStaticLines(texts);
}
-// { "lyrics": { "syncType": "LINE_SYNCED", "lines": [ { "startTimeMs": "1234", "words": "..." } ] } }
+// { "lyrics": { "syncType": "LINE_SYNCED", "lines": [ { "startTimeMs": "1234", "words": "..." } ] } },
+// or "UNSYNCED" with every start 0.
static NSArray<SGKaraokeLine *> *fromJSON(NSData *body) {
NSDictionary *root = [NSJSONSerialization JSONObjectWithData:body options:0 error:nil];
NSDictionary *lyrics = [root isKindOfClass:NSDictionary.class] ? root[@"lyrics"] : nil;
- if (![lyrics isKindOfClass:NSDictionary.class] || ![lyrics[@"syncType"] isEqual:@"LINE_SYNCED"]) return nil;
+ if (![lyrics isKindOfClass:NSDictionary.class]) return nil;
+ BOOL synced = [lyrics[@"syncType"] isEqual:@"LINE_SYNCED"];
+ if (!synced && ![lyrics[@"syncType"] isEqual:@"UNSYNCED"]) return nil;
NSMutableArray<NSNumber *> *starts = [NSMutableArray array];
NSMutableArray<NSString *> *texts = [NSMutableArray array];
for (NSDictionary *line in lyrics[@"lines"]) {
@@ -210,7 +239,7 @@ static NSArray<SGKaraokeLine *> *fromJSON(NSData *body) {
[starts addObject:@([line[@"startTimeMs"] integerValue])];
[texts addObject:[words isKindOfClass:NSString.class] ? words : @""];
}
- return SGKaraokeEstimatedLines(starts, texts);
+ return synced ? SGKaraokeEstimatedLines(starts, texts) : SGKaraokeStaticLines(texts);
}
NSArray<SGKaraokeLine *> *SGKaraokeLinesFromBody(NSData *body) {
diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.h
index 61097e40..437961cb 100644
--- a/tweak/Sources/Shared/Lyrics/Lyrics.h
+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h
@@ -1,18 +1,35 @@
// The lyrics engine: timed lines and the player's clock, for the redesign's Apple Music style lyrics
// (Redesigned/Lyrics/SGRKaraokeView.h) and the lock screen (Shared/LockScreenLyrics). Spotify only
-// times whole lines, so the words inside a line are timed by an estimate (KaraokeTiming.m), unless a
-// source of the mod's times them. The lines are read from the color-lyrics response as it arrives, or
-// handed over by Shared/LyricsSources, and the position from the player's state (KaraokeSource.x).
+// times whole lines, and so do many sources; every line says how finely it was really timed
+// (SGKaraokeTiming), so a line timed by the line lights up whole unless the user asks for the words
+// inside it to be estimated (KaraokeTiming.m) and swept. The lines are read from the color-lyrics
+// response as it arrives, or handed over by Shared/LyricsSources, and the position from the player's
+// state (KaraokeSource.x).
#import <UIKit/UIKit.h>
@class SGModRow, SGModSection;
// LyricsSettings.m: the Lyrics page's parts (App/Pages.m puts the page together): where lyrics come
-// from, naming the source (read by the redesign's lyrics view only), the lock screen, and which
+// from, naming the source (read by the redesign's lyrics view only), the lock screen, which
// language a line's translation is taken in, of those the lyrics come with (the redesign's lyrics
-// being where translations show).
+// being where translations show), and whether lines timed only by the line are swept word by word.
SGModSection *SGLyricsSourcesSection(BOOL namingSource);
SGModRow *SGLockScreenLyricsRow(void);
SGModRow *SGLyricsTranslationLanguageRow(void);
+SGModSection *SGLyricsWordTimingSection(void);
+
+// Sweeps a line timed only by the line word by word, on the estimate of when each word is sung, as if
+// the source had timed them. Off, such a line lights up whole as it starts. Off by default: the
+// estimate is a guess dressed up as timing.
+#define SGKeyLyricsSimulateWords @"spotifyglass.lyricsSimulateWords"
+
+// How finely a line was timed by where it came from. The words of a line timed by the line are still
+// there, each with an estimated time, for a page that wants to sweep them anyway; a line with no time
+// at all has start and end 0. Ordered finest first, so a line built from timed words is the default.
+typedef NS_ENUM(NSUInteger, SGKaraokeTiming) {
+ SGKaraokeTimingWords = 0, // every word or syllable timed by the source
+ SGKaraokeTimingLine, // the line's start (and maybe its end); the words estimated
+ SGKaraokeTimingNone, // plain text, nothing timed
+};
// Which edge a line is laid against. Apple Music puts a duet's second voice against the far one, so
// the two sides of the song read apart; a track sung by one voice stays leading throughout.
@@ -37,6 +54,8 @@ typedef NS_ENUM(NSUInteger, SGKaraokeAlign) {
// SGKaraokeAlignVoices turns these into alignments; nothing else reads it.
@property (nonatomic, copy) NSString *voice;
@property (nonatomic) SGKaraokeAlign align;
+// How finely the source timed it; the words of a line built here from timed words are timed.
+@property (nonatomic) SGKaraokeTiming timing;
// The (oh, aye) sung under the line, smaller and dimmer, nil for nearly every line. Its words are
// timed like any other and it is lit by the same sweep, a beat behind the line it hangs off.
@property (nonatomic, strong) SGKaraokeLine *backing;
@@ -64,16 +83,24 @@ BOOL SGKaraokeUnspacedScript(NSString *text);
// named trails, and any after that lead again. A track naming one voice or none is left alone.
void SGKaraokeAlignVoices(NSArray<SGKaraokeLine *> *lines);
-// A color-lyrics body, protobuf or JSON, as timed lines; nil unless Spotify synced it by line.
+// A color-lyrics body, protobuf or JSON, as lines: timed by the line where Spotify synced it, plain
+// (SGKaraokeTimingNone) where it did not; nil for a body with no lines.
NSArray<SGKaraokeLine *> *SGKaraokeLinesFromBody(NSData *body);
// Lines timed only by their starts, the words inside them estimated; a ♪ or empty text is a break.
NSArray<SGKaraokeLine *> *SGKaraokeEstimatedLines(NSArray<NSNumber *> *starts, NSArray<NSString *> *texts);
+// Lines with no time at all, for lyrics that come as plain text; a ♪ or empty text is dropped.
+NSArray<SGKaraokeLine *> *SGKaraokeStaticLines(NSArray<NSString *> *texts);
+// The finest timing any of the lines has; SGKaraokeTimingNone for none at all.
+SGKaraokeTiming SGKaraokeLinesTiming(NSArray<SGKaraokeLine *> *lines);
NSArray<SGKaraokeLine *> *SGKaraokeLinesForTrack(NSString *trackID); // nil until the lyrics came
void SGKaraokeKeepLines(NSString *trackID, NSArray<SGKaraokeLine *> *lines);
// Asks spclient for a track's lyrics once, with the headers of Spotify's own requests, for when no
// page of Spotify's has asked for them, e.g. with the app in the background.
void SGKaraokeRequestLyrics(NSString *trackID);
+// Asks Spotify's JSON lyrics for the track once, and keeps its lines only if they are more finely
+// timed than the ones kept: the lyrics view was left with plain text, and Spotify may have it timed.
+void SGKaraokeAskSpotifyForTiming(NSString *trackID);
// The Authorization header Spotify's own requests carry, "Bearer ..." and the account's own token;
// nil until one has gone out. Only for a source that answers no one who cannot show they are a
// signed-in Spotify client, and only with the mod's user having switched that source on.
diff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
index bfc10828..c6c069c8 100644
--- a/tweak/Sources/Shared/Lyrics/LyricsSettings.m
+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
@@ -28,3 +28,10 @@ SGModRow *SGLyricsTranslationLanguageRow(void) {
return SGChoiceRow(@"Translation language", @"Of the translations the lyrics come with, the one to show; Any shows the first",
SGKeyLyricsTranslationLanguage, SGLyricsTranslationLanguageNames(), 0);
}
+
+// Read by the redesign's lyrics view, the one place words are swept, so the page offers it there only.
+SGModSection *SGLyricsWordTimingSection(void) {
+ SGModRow *row = SGOptionRow(@"Simulate word-by-word timing", @"Guesses when each word of a line-synced line is sung, and sweeps it as if the source had timed it", SGKeyLyricsSimulateWords);
+ return SGNotedSection(@"Word timing", @[row],
+ @"Off, lyrics synced by the line light up a line at a time, and lyrics with no timing show as plain text. Word-synced lyrics sweep word by word either way.");
+}
diff --git a/tweak/Sources/Shared/LyricsSources/LrcLib.m b/tweak/Sources/Shared/LyricsSources/LrcLib.m
index 6d6fa492..48c1ea6d 100644
--- a/tweak/Sources/Shared/LyricsSources/LrcLib.m
+++ b/tweak/Sources/Shared/LyricsSources/LrcLib.m
@@ -91,6 +91,7 @@ static SGLyricsResult *resultFrom(NSDictionary *record) {
}
result.starts = starts;
result.texts = texts;
+ result.karaokeLines = SGKaraokeStaticLines(texts);
return result;
}
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsHook.x b/tweak/Sources/Shared/LyricsSources/LyricsHook.x
index fa6e3786..9d42a5f8 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsHook.x
+++ b/tweak/Sources/Shared/LyricsSources/LyricsHook.x
@@ -93,12 +93,19 @@ static NSData *lyricsBody(SGLyricsResult *lyrics, NSData *spotify) {
// only when the server made them from the track's own artwork, which it names in the URL.
static NSData *chosenBody(NSString *track, SGLyricsResult *lyrics, NSData *spotify, BOOL donor, BOOL donorColors) {
NSArray<SGKaraokeLine *> *spotifyLines = donor ? nil : SGKaraokeLinesFromBody(spotify);
- BOOL ours = lyrics.texts.count && (lyrics.synced || !spotifyLines);
- NSArray<SGKaraokeLine *> *karaoke = lyrics.wordTimed || ours ? lyrics.karaokeLines : spotifyLines;
+ SGKaraokeTiming spotifyTiming = SGKaraokeLinesTiming(spotifyLines);
+ // Spotify's own page keeps its own lines when they are timed and the chain's are not.
+ BOOL ours = lyrics.texts.count && (lyrics.synced || spotifyTiming == SGKaraokeTimingNone);
+ // The lyrics view takes the more finely timed of the two, the chain's on a tie.
+ BOOL oursFiner = lyrics.karaokeLines.count && (!spotifyLines || SGKaraokeLinesTiming(lyrics.karaokeLines) <= spotifyTiming);
+ NSArray<SGKaraokeLine *> *karaoke = oursFiner ? lyrics.karaokeLines : spotifyLines;
if (karaoke) SGKaraokeKeepLines(track, karaoke);
SGLyricsSetCredit(track, karaoke == lyrics.karaokeLines ? lyrics.provider : @"Spotify");
- SGLog(@"lyrics: page of %@ gets %@, %@ word timing", track, ours ? [NSString stringWithFormat:@"%@'s lines", lyrics.provider] : spotifyLines ? @"Spotify's own lines" : @"no lyrics",
- lyrics.wordTimed ? @"real" : @"estimated");
+ // Plain text for the view while Spotify has lyrics of its own: its JSON may still have them timed.
+ if (!donor && spotify.length && SGKaraokeLinesTiming(karaoke) == SGKaraokeTimingNone) SGKaraokeAskSpotifyForTiming(track);
+ SGLog(@"lyrics: page of %@ gets %@; the lyrics view %@'s, %@", track, ours ? [NSString stringWithFormat:@"%@'s lines", lyrics.provider] : spotifyLines ? @"Spotify's own lines" : @"no lyrics",
+ oursFiner ? lyrics.provider : @"Spotify", SGKaraokeLinesTiming(karaoke) == SGKaraokeTimingWords ? @"word timed"
+ : SGKaraokeLinesTiming(karaoke) == SGKaraokeTimingLine ? @"line timed" : @"untimed");
return ours ? lyricsBody(lyrics, donor && !donorColors ? nil : spotify) : nil;
}
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.m b/tweak/Sources/Shared/LyricsSources/LyricsSources.m
index 3145d26c..566925bd 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.m
+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.m
@@ -247,10 +247,19 @@ static void setUp(void) {
}
// Whether the source's lines are better than what the walk already has: any lines beat none, and
-// timing every word beats estimating them.
+// finer timing beats coarser — words timed beat a line's start, which beats plain text. Read off the
+// lines themselves, which say how they were really timed, rather than off what the source claimed.
static BOOL betterLines(SGLyricsResult *merged, SGLyricsResult *fresh) {
if (!fresh.karaokeLines.count) return NO;
- return !merged.karaokeLines.count || (fresh.wordTimed && !merged.wordTimed);
+ return !merged.karaokeLines.count || SGKaraokeLinesTiming(fresh.karaokeLines) < SGKaraokeLinesTiming(merged.karaokeLines);
+}
+
+static NSString *timingName(NSArray<SGKaraokeLine *> *lines) {
+ switch (SGKaraokeLinesTiming(lines)) {
+ case SGKaraokeTimingWords: return @"word timed";
+ case SGKaraokeTimingLine: return @"line timed";
+ default: return @"untimed";
+ }
}
// The same for the text Spotify's own page shows: any text beats none, timed beats untimed.
@@ -304,7 +313,7 @@ static void finish(SGLyricsWalk *walk) {
}
SGLog(@"lyrics: %@ ends with %@", trackID, lyrics
? [NSString stringWithFormat:@"%lu %@ lines from %@, %lu page lines",
- (unsigned long)lyrics.karaokeLines.count, lyrics.wordTimed ? @"word timed" : @"estimated",
+ (unsigned long)lyrics.karaokeLines.count, timingName(lyrics.karaokeLines),
lyrics.provider, (unsigned long)lyrics.texts.count]
: everyoneAsked && failed ? @"nothing, a request failed on the way; not kept, so the next request asks again"
: everyoneAsked ? @"nothing"
diff --git a/tweak/Sources/Shared/LyricsSources/Musixmatch.m b/tweak/Sources/Shared/LyricsSources/Musixmatch.m
index cffc6ad4..54c88ecb 100644
--- a/tweak/Sources/Shared/LyricsSources/Musixmatch.m
+++ b/tweak/Sources/Shared/LyricsSources/Musixmatch.m
@@ -212,6 +212,7 @@ static SGLyricsResult *fromPlain(id body) {
SGLyricsResult *lyrics = [SGLyricsResult new];
lyrics.starts = starts;
lyrics.texts = texts;
+ lyrics.karaokeLines = SGKaraokeStaticLines(texts);
return lyrics;
}
diff --git a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m
index ad127195..3bb422df 100644
--- a/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m
+++ b/tweak/Sources/Shared/LyricsSources/SpicyLyrics.m
@@ -399,6 +399,7 @@ SGLyricsAsk SGSpicyLyricsAsk = ^(SGLyricsQuery *query, void (^done)(SGLyricsResu
}
result.starts = starts;
result.texts = texts;
+ result.karaokeLines = SGKaraokeStaticLines(texts);
}
if (!result.texts.count) {
SGLog(@"spicy: %@ came back as %@ with nothing the page could show", query.trackID, type ?: @"no shape at all");