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(lyrics): show romanized lyrics in place of original script (#159)

anna03731476c1fe
diff --git a/harness/now-playing/build.sh b/harness/now-playing/build.sh
index 2782436e..bc0dc4eb 100755
--- a/harness/now-playing/build.sh
+++ b/harness/now-playing/build.sh
@@ -18,7 +18,7 @@ SDK=$(xcrun --sdk macosx --show-sdk-path)
xcrun clang -target arm64-apple-ios18.0-macabi -isysroot "$SDK" -iframework "$SDK/System/iOSSupport/System/Library/Frameworks" \
-fobjc-arc -g -O0 -Wall -I"$SRC" -I"$SRC/Shared/LockScreenLyrics" \
"$(dirname "$0")/main.m" "$OUT/gen/LockScreenLyrics.m" "$OUT/gen/NowPlayingExtras.m" \
- "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/AdBlock/Protobuf.m" \
+ "$SRC/Shared/Lyrics/KaraokeTiming.m" "$SRC/Shared/Lyrics/Romanise.m" "$SRC/Shared/AdBlock/Protobuf.m" \
-framework UIKit -framework MediaPlayer -o "$OUT/now-playing"
"$OUT/now-playing"
diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.m
index bbb6d24c..b1ee79f1 100644
--- a/tweak/Sources/App/Pages.m
+++ b/tweak/Sources/App/Pages.m
@@ -116,7 +116,7 @@ static UIViewController *lyricsPage(void) {
@"Every line shows this much later than the song, for Bluetooth headphones that play a little behind the lyrics. Applies at once.");
if (redesigned) {
[sections addObjectsFromArray:@[
- SGSection(@"Display", @[SGRLyricsTextSizesRow(), SGLyricsWordTimingRow(), SGLyricsRomanisedRow(),
+ SGSection(@"Display", @[SGRLyricsTextSizesRow(), SGLyricsWordTimingRow(), SGLyricsRomanisedRow(), SGLyricsRomanisedReplaceRow(),
SGRLyricsHideRow(),
SGSwitchRow(@"Landscape lyrics", @"Turn the phone with the lyrics open", SGRKeyLyricsLandscape)]),
timing,
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
index e333e91b..b3212620 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m
@@ -365,6 +365,7 @@ static double heldStrength(double held) {
// it off. A backing row has none.
@property (nonatomic, readonly) UIFont *romanised;
@property (nonatomic) BOOL japanese; // the song has kana, so its kanji are read the Japanese way
+@property (nonatomic) BOOL romanisedReplace; // show the Latin letters in place of the line's words
- (instancetype)initWithSize:(CGFloat)size order:(NSArray<NSNumber *> *)order pronunciation:(BOOL)pronunciation translation:(BOOL)translation
romanised:(BOOL)romanised;
@end
@@ -406,6 +407,8 @@ static const CGFloat kSecondShare = 0.67, kThirdShare = 0.54;
NSMutableArray<NSNumber *> *order = [_order mutableCopy];
[order removeObject:@(SGRLyricsTextTranslation)];
backing->_order = order;
+ backing.japanese = _japanese;
+ backing.romanisedReplace = _romanisedReplace;
return backing;
}
@@ -612,22 +615,27 @@ static CGRect blockFrame(NSString *text, UIFont *font, CGFloat width, CGFloat to
// row keeps to, its line's; -1 for a line of its own, which takes its side from its voice and script.
static SGRKaraokeLayout *layOut(SGKaraokeLine *line, CGFloat width, SGRKaraokeStyle *style, NSInteger right) {
SGRKaraokeLayout *layout = [SGRKaraokeLayout new];
- layout.right = right >= 0 ? right : alignsRight(line);
+ SGKaraokeLine *activeLine = line;
+ if (style.romanisedReplace) {
+ SGKaraokeLine *romanised = SGLyricsRomanisedLine(line, style.japanese);
+ if (romanised) activeLine = romanised;
+ }
+ layout.right = right >= 0 ? right : alignsRight(activeLine);
layout.translation = layout.romanised = CGRectNull;
- NSArray<SGKaraokeWord *> *spoken = style.pronunciation ? line.pronunciation.words : nil;
- NSString *translation = style.translation ? line.translation : nil;
+ NSArray<SGKaraokeWord *> *spoken = (style.pronunciation && !style.romanisedReplace) ? line.pronunciation.words : nil;
+ NSString *translation = style.translation ? activeLine.translation : nil;
// A translator hands back a line already in the language as it was; the line says it once. It stays
// translated, so it is not asked again.
- NSString *lineText = translation.length || style.romanised ? SGKaraokeLineText(line) : nil;
+ NSString *lineText = translation.length || (style.romanised && !style.romanisedReplace) ? SGKaraokeLineText(line) : nil;
if (translation.length && [SGLyricsBareText(translation) isEqualToString:SGLyricsBareText(lineText)]) translation = nil;
// A source's own pronunciation, hidden, still reads better than the transform's.
- if (style.romanised && !spoken.count) {
+ if (style.romanised && !style.romanisedReplace && !spoken.count) {
layout.romanisedText = line.pronunciation ? SGKaraokeLineText(line.pronunciation)
: SGLyricsRomanised(lineText, style.japanese);
}
NSMutableArray<NSNumber *> *parts = [NSMutableArray array];
for (NSNumber *text in style.order) {
- if (text.integerValue == SGRLyricsTextPronunciation && !spoken.count) continue;
+ if (text.integerValue == SGRLyricsTextPronunciation && (!spoken.count || style.romanisedReplace)) continue;
if (text.integerValue == SGRLyricsTextTranslation && !translation.length) continue;
[parts addObject:text];
}
@@ -647,8 +655,8 @@ static SGRKaraokeLayout *layOut(SGKaraokeLine *line, CGFloat width, SGRKaraokeSt
if (paired) {
NSArray<NSValue *> *pairedFrames;
NSArray<NSNumber *> *pairedOffsets;
- y = layPair(lyrics ? line.words : spoken, lyrics ? style.lyrics : style.pronunciation,
- lyrics ? spoken : line.words, lyrics ? style.pronunciation : style.lyrics,
+ y = layPair(lyrics ? activeLine.words : spoken, lyrics ? style.lyrics : style.pronunciation,
+ lyrics ? spoken : activeLine.words, lyrics ? style.pronunciation : style.lyrics,
width, layout.right, y, &frames, &offsets, &pairedFrames, &pairedOffsets);
layout.lyricFrames = lyrics ? frames : pairedFrames;
layout.lyricOffsets = lyrics ? offsets : pairedOffsets;
@@ -657,7 +665,7 @@ static SGRKaraokeLayout *layOut(SGKaraokeLine *line, CGFloat width, SGRKaraokeSt
p++;
lyrics = YES;
} else {
- y = layRun(lyrics ? line.words : spoken, lyrics ? style.lyrics : style.pronunciation, width, layout.right, y, &frames, &offsets);
+ y = layRun(lyrics ? activeLine.words : spoken, lyrics ? style.lyrics : style.pronunciation, width, layout.right, y, &frames, &offsets);
if (lyrics) {
layout.lyricFrames = frames;
layout.lyricOffsets = offsets;
@@ -670,9 +678,9 @@ static SGRKaraokeLayout *layOut(SGKaraokeLine *line, CGFloat width, SGRKaraokeSt
layout.romanised = blockFrame(layout.romanisedText, style.romanised, width, y + kPartGap);
y = CGRectGetMaxY(layout.romanised);
}
- if (lyrics && right < 0 && line.backing.words.count) {
+ if (lyrics && right < 0 && activeLine.backing.words.count) {
layout.backingTop = y + kBackingGap;
- y = layout.backingTop + layOut(line.backing, width, style.backing, layout.right).height;
+ y = layout.backingTop + layOut(activeLine.backing, width, style.backing, layout.right).height;
}
}
layout.height = y;
@@ -858,16 +866,21 @@ static double wholeFrom(SGKaraokeLine *run, BOOL sweepsEstimates) {
self = [super initWithFrame:CGRectZero];
if (!self) return nil;
_line = line;
+ BOOL backing = under != nil;
+ SGKaraokeLine *activeLine = line;
+ if (style.romanisedReplace) {
+ SGKaraokeLine *romanised = SGLyricsRomanisedLine(line, style.japanese);
+ if (romanised) activeLine = romanised;
+ }
self.isAccessibilityElement = under == nil;
- self.accessibilityLabel = SGKaraokeLineText(line);
+ self.accessibilityLabel = SGKaraokeLineText(activeLine);
self.accessibilityTraits = UIAccessibilityTraitButton;
- BOOL backing = under != nil;
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
- wholeFrom:wholeFrom(line, sweepsEstimates)];
- SGRKaraokeSweep *spoken = [self sweepOf:line.pronunciation.words font:style.pronunciation frames:layout.spokenFrames
+ SGRKaraokeSweep *sung = [self sweepOf:activeLine.words font:style.lyrics frames:layout.lyricFrames offsets:layout.lyricOffsets
+ wholeFrom:wholeFrom(activeLine, sweepsEstimates)];
+ SGRKaraokeSweep *spoken = style.romanisedReplace ? nil : [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];
@@ -875,10 +888,10 @@ static double wholeFrom(SGKaraokeLine *run, BOOL sweepsEstimates) {
_words = [sung.words ?: @[] arrayByAddingObjectsFromArray:spoken.words ?: @[]];
_lyricWords = sung.words;
- if (!CGRectIsNull(layout.translation)) _translation = [self asideAt:layout.translation font:style.translation text:line.translation];
+ if (!CGRectIsNull(layout.translation)) _translation = [self asideAt:layout.translation font:style.translation text:activeLine.translation];
if (!CGRectIsNull(layout.romanised)) _romanised = [self asideAt:layout.romanised font:style.romanised text:layout.romanisedText];
if (layout.backingTop > 0) {
- _backing = [[SGRKaraokeLineView alloc] initWithLine:line.backing width:width style:style.backing under:self blurred:NO
+ _backing = [[SGRKaraokeLineView alloc] initWithLine:activeLine.backing ?: 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);
@@ -887,8 +900,8 @@ static double wholeFrom(SGKaraokeLine *run, BOOL sweepsEstimates) {
NSMutableArray<NSString *> *asides = [NSMutableArray array];
if (_translation.text.length) [asides addObject:_translation.text];
if (_romanised.text.length) [asides addObject:_romanised.text];
- if (layout.spokenFrames.count && line.pronunciation) [asides addObject:SGKaraokeLineText(line.pronunciation) ?: @""];
- if (line.backing) [asides addObject:SGKaraokeLineText(line.backing) ?: @""];
+ if (layout.spokenFrames.count && line.pronunciation && !style.romanisedReplace) [asides addObject:SGKaraokeLineText(line.pronunciation) ?: @""];
+ if (activeLine.backing) [asides addObject:SGKaraokeLineText(activeLine.backing) ?: @""];
self.accessibilityValue = [asides componentsJoinedByString:@". "];
for (UIView *child in self.subviews) child.accessibilityElementsHidden = YES;
self.frame = CGRectMake(0, 0, width, layout.height);
@@ -1904,11 +1917,13 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
// What a line shows besides its words: what the song has, of what the lyrics menu has switched on.
- (SGRKaraokeStyle *)styleNow {
BOOL romanised = SGFlag(SGKeyLyricsRomanised, NO);
+ BOOL replace = romanised && SGFlag(SGKeyLyricsRomanisedReplace, NO);
SGRKaraokeStyle *style = [[SGRKaraokeStyle alloc] initWithSize:_fontSize order:SGRLyricsTextOrder()
- pronunciation:_hasSpoken && SGFlag(SGRKeyLyricsPronunciation, NO)
+ pronunciation:!replace && _hasSpoken && SGFlag(SGRKeyLyricsPronunciation, NO)
translation:_hasTranslation && SGFlag(SGRKeyLyricsTranslation, NO)
- romanised:romanised];
+ romanised:romanised && !replace];
style.japanese = romanised && SGLyricsLooksJapanese(_lines);
+ style.romanisedReplace = replace;
return style;
}
@@ -2348,14 +2363,24 @@ static BOOL anyUntranslated(NSArray<SGKaraokeLine *> *lines) {
_dotsLine = -1;
}
if (_dotsLine != _openBreak) {
- _dots.rightToLeft = readsRightToLeft(SGKaraokeLineText(_lines[(NSUInteger)_openBreak]));
+ SGKaraokeLine *breakLine = _lines[(NSUInteger)_openBreak];
+ if (_style.romanisedReplace) {
+ SGKaraokeLine *rom = SGLyricsRomanisedLine(breakLine, _style.japanese);
+ if (rom) breakLine = rom;
+ }
+ _dots.rightToLeft = readsRightToLeft(SGKaraokeLineText(breakLine));
for (NSUInteger i = 0; i < _breakCount; i++) {
if (_breaks[i].line == _openBreak) [_dots playFrom:_breaks[i].start to:_breaks[i].end];
}
_dotsLine = _openBreak;
}
if (_dots.superview != _scroll) [_scroll addSubview:_dots];
- _dots.right = alignsRight(_lines[(NSUInteger)_openBreak]);
+ SGKaraokeLine *dotLine = _lines[(NSUInteger)_openBreak];
+ if (_style.romanisedReplace) {
+ SGKaraokeLine *rom = SGLyricsRomanisedLine(dotLine, _style.japanese);
+ if (rom) dotLine = rom;
+ }
+ _dots.right = alignsRight(dotLine);
CGFloat top = [self topOfLine:_openBreak] - [self breakRoom];
_dots.frame = CGRectMake(_margin, top, _builtWidth - 2 * _margin, _dots.bounds.size.height);
}
diff --git a/tweak/Sources/Shared/LiveActivity/LiveActivity.x b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
index 66a1029b..4a907263 100644
--- a/tweak/Sources/Shared/LiveActivity/LiveActivity.x
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivity.x
@@ -194,9 +194,18 @@ static NSString *lyricsLine(NSString *trackID, NSString **next, NSString **trans
if (position >= 0) position -= SGKaraokeDelayMs();
// 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);
- *next = index + 1 < (NSInteger)lines.count ? SGKaraokeLineText(lines[index + 1]) : @"";
+ BOOL replace = SGFlag(SGKeyLyricsRomanised, NO) && SGFlag(SGKeyLyricsRomanisedReplace, NO);
+ BOOL japanese = replace && SGLyricsLooksJapanese(lines);
+ if (index + 1 < (NSInteger)lines.count) {
+ SGKaraokeLine *nextLine = lines[index + 1];
+ if (replace) nextLine = SGLyricsRomanisedLine(nextLine, japanese) ?: nextLine;
+ *next = SGKaraokeLineText(nextLine);
+ } else {
+ *next = @"";
+ }
if (index < 0) return @"♪";
SGKaraokeLine *current = lines[index];
+ if (replace) current = SGLyricsRomanisedLine(current, japanese) ?: current;
BOOL nextFarOff = index + 1 == (NSInteger)lines.count || lines[index + 1].start - position > kBreakMs;
if (position > current.end + kBreakMs && nextFarOff) return @"♪";
*translation = current.translation;
diff --git a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
index 60248327..746ac6b1 100644
--- a/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
+++ b/tweak/Sources/Shared/LockScreenLyrics/LockScreenLyrics.x
@@ -109,10 +109,20 @@ static NSString *lineFor(NSDictionary *info, double elapsed, NSTimeInterval *wai
if (index < 0) return nil;
BOOL nextFarOff = index + 1 == (NSInteger)lines.count || lines[index + 1].start - position > SGKaraokeBreakMs;
if (position > lines[index].end + SGKaraokeBreakMs && nextFarOff) return nil;
- SGKaraokeLine *line = (sg_translation ? translatedLine(lines[index]) : nil) ?: lines[index];
+ SGKaraokeLine *line = (sg_translation ? translatedLine(lines[index]) : nil);
+ if (!line && SGFlag(SGKeyLyricsRomanised, NO) && SGFlag(SGKeyLyricsRomanisedReplace, NO)) {
+ line = SGLyricsRomanisedLine(lines[index], SGLyricsLooksJapanese(lines));
+ }
+ if (!line) line = lines[index];
NSString *shown = nil;
for (NSArray<SGKaraokeWord *> *piece in piecesOf(line)) {
- if (!shown || piece.firstObject.start <= position) shown = textOf(piece);
+ NSInteger pieceStart = piece.firstObject.start;
+ if (!shown || pieceStart <= position) {
+ shown = textOf(piece);
+ } else if (pieceStart > position && (ms <= 0 || pieceStart - position < ms)) {
+ ms = pieceStart - position;
+ *wait = (ms + 1) / 1000.0;
+ }
}
return shown;
}
diff --git a/tweak/Sources/Shared/Lyrics/Lyrics.h b/tweak/Sources/Shared/Lyrics/Lyrics.h
index 59615d0b..cd618f11 100644
--- a/tweak/Sources/Shared/Lyrics/Lyrics.h
+++ b/tweak/Sources/Shared/Lyrics/Lyrics.h
@@ -18,19 +18,25 @@ SGModRow *SGLockScreenTranslationRow(void);
SGModRow *SGLyricsTranslationLanguageRow(void);
SGModRow *SGLyricsWordTimingRow(void);
SGModRow *SGLyricsRomanisedRow(void);
+SGModRow *SGLyricsRomanisedReplaceRow(void);
SGModRow *SGLyricsDelayRow(void);
// Shows a line written in another alphabet (Japanese, Korean, Chinese, Cyrillic, Greek, Thai, Arabic,
// Hebrew, Devanagari...) again under itself in Latin letters, before its translation. Off by default.
// Only the redesign's lyrics view draws it, and it applies at once: the switch posts the notification.
#define SGKeyLyricsRomanised @"spotifyglass.lyricsRomanised"
+// Shows the line in Latin letters in place of the original script, instead of under it.
+#define SGKeyLyricsRomanisedReplace @"spotifyglass.lyricsRomanisedReplace"
extern NSNotificationName const SGLyricsRomanisedDidChangeNotification;
+@class SGKaraokeLine;
// Romanise.m: the text in Latin letters, offline; nil where it has no letter of another script, or
// reads the same. `japanese` reads kanji the Japanese way, for a song SGLyricsLooksJapanese says is
// (a line of kanji alone would read as Chinese). Safe off the main thread, and kept per text.
NSString *SGLyricsRomanised(NSString *text, BOOL japanese);
+// The line in Latin letters: the source's pronunciation where it has one, or SGLyricsRomanised over the line's words.
+// nil where it has no letter of another script.
+SGKaraokeLine *SGLyricsRomanisedLine(SGKaraokeLine *line, BOOL japanese);
// Whether any of the lines has kana in it.
-@class SGKaraokeLine;
BOOL SGLyricsLooksJapanese(NSArray<SGKaraokeLine *> *lines);
// Sweeps a line timed only by the line word by word, on the estimate of when each word is sung, as if
diff --git a/tweak/Sources/Shared/Lyrics/LyricsSettings.m b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
index 9b1ae92d..018956f5 100644
--- a/tweak/Sources/Shared/Lyrics/LyricsSettings.m
+++ b/tweak/Sources/Shared/Lyrics/LyricsSettings.m
@@ -63,6 +63,15 @@ SGModRow *SGLyricsRomanisedRow(void) {
return row;
}
+SGModRow *SGLyricsRomanisedReplaceRow(void) {
+ SGModRow *row = SGOptionRow(@"In place of original", @"Show the Latin letters instead of the original script", SGKeyLyricsRomanisedReplace);
+ row.waitsOn = SGKeyLyricsRomanised;
+ row.changed = ^(BOOL on) {
+ [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsRomanisedDidChangeNotification object:nil];
+ };
+ return row;
+}
+
// Only the redesign's lyrics view sweeps words.
SGModRow *SGLyricsWordTimingRow(void) {
return SGOptionRow(@"Simulate word timing", nil, SGKeyLyricsSimulateWords);
diff --git a/tweak/Sources/Shared/Lyrics/Romanise.m b/tweak/Sources/Shared/Lyrics/Romanise.m
index 18b8e96c..b7f49743 100644
--- a/tweak/Sources/Shared/Lyrics/Romanise.m
+++ b/tweak/Sources/Shared/Lyrics/Romanise.m
@@ -8,6 +8,7 @@
// ("mrhba"), Thai in ISO 11940's spelling rather than the one signs use, and a line mixing Latin with
// another script loses the Latin part's accents ("Café" as "Cafe"). A reading per language is the upgrade.
#import "Lyrics.h"
+#import <objc/runtime.h>
NSNotificationName const SGLyricsRomanisedDidChangeNotification = @"spotifyglass.lyricsRomanisedDidChange";
@@ -81,3 +82,70 @@ NSString *SGLyricsRomanised(NSString *text, BOOL japanese) {
[kept setObject:romanised forKey:key];
return romanised.length ? romanised : nil;
}
+
+static char kRomanisedLineKey;
+
+SGKaraokeLine *SGLyricsRomanisedLine(SGKaraokeLine *line, BOOL japanese) {
+ if (!line) return nil;
+ id cached = objc_getAssociatedObject(line, &kRomanisedLineKey);
+ if (cached) {
+ if (cached == NSNull.null) return nil;
+ SGKaraokeLine *r = (SGKaraokeLine *)cached;
+ r.translation = line.translation;
+ r.translationMade = line.translationMade;
+ return r;
+ }
+
+ NSString *text = SGKaraokeLineText(line);
+ NSString *pronText = line.pronunciation.words.count ? SGKaraokeLineText(line.pronunciation) : nil;
+ SGKaraokeLine *romanised = nil;
+ if (pronText.length && has(text, SGScriptNotLatin) && !has(pronText, SGScriptNotLatin)) {
+ romanised = [line.pronunciation copy];
+ romanised.translation = line.translation;
+ romanised.translationMade = line.translationMade;
+ if (line.backing) {
+ romanised.backing = SGLyricsRomanisedLine(line.backing, japanese) ?: line.backing;
+ }
+ } else {
+ NSString *romanisedText = SGLyricsRomanised(text, japanese);
+ if (romanisedText.length && [romanisedText caseInsensitiveCompare:text] != NSOrderedSame) {
+ if (line.timing == SGKaraokeTimingNone) {
+ romanised = SGKaraokeStaticLines(@[romanisedText]).firstObject;
+ } else {
+ NSInteger start = line.start;
+ NSInteger end = line.end > line.start ? line.end : line.start + 3000;
+ romanised = SGKaraokeEstimatedLines(@[@(start), @(end)], @[romanisedText, @""]).firstObject;
+ if (romanised && line.end > start) {
+ NSInteger targetSpan = line.end - start;
+ NSInteger genSpan = romanised.end - start;
+ if (genSpan > 0 && genSpan != targetSpan) {
+ for (SGKaraokeWord *w in romanised.words) {
+ w.start = start + (NSInteger)llround((double)(w.start - start) * targetSpan / genSpan);
+ w.end = start + (NSInteger)llround((double)(w.end - start) * targetSpan / genSpan);
+ }
+ }
+ romanised.start = start;
+ romanised.end = line.end;
+ }
+ }
+ if (romanised) {
+ romanised.align = line.align;
+ romanised.voice = line.voice;
+ romanised.translation = line.translation;
+ romanised.translationMade = line.translationMade;
+ if (line.backing) {
+ romanised.backing = SGLyricsRomanisedLine(line.backing, japanese) ?: line.backing;
+ }
+ }
+ } else if (line.backing) {
+ SGKaraokeLine *romanisedBacking = SGLyricsRomanisedLine(line.backing, japanese);
+ if (romanisedBacking) {
+ romanised = [line copy];
+ romanised.backing = romanisedBacking;
+ }
+ }
+ }
+
+ objc_setAssociatedObject(line, &kRomanisedLineKey, romanised ?: NSNull.null, OBJC_ASSOCIATION_RETAIN);
+ return romanised;
+}