@@ -19,6 +19,7 @@ import org.akanework.gramophone.logic.utils.SemanticLyrics.UnsyncedLyrics
1919import org.akanework.gramophone.logic.utils.SemanticLyrics.Word
2020import org.xmlpull.v1.XmlPullParser
2121import org.xmlpull.v1.XmlPullParserException
22+ import uk.akane.libphonograph.putIfAbsentSupport
2223import java.io.StringReader
2324import java.nio.charset.Charset
2425import java.util.concurrent.atomic.AtomicReference
@@ -1521,6 +1522,19 @@ fun parseTtml(audioMimeType: String?, lyricText: String): SemanticLyrics? {
15211522 } while (cur != - 1 )
15221523 out
15231524 }
1525+ // start left if person is first, and right if sample is first.
1526+ val agentToSide = hashMapOf<String ?, Boolean / * true = right * / >()
1527+ if (Flags .TTML_AGENT_SMART_SIDES ) {
1528+ var agent: String? = null
1529+ var side = state.paragraphs.firstOrNull()?.let { peopleToType[it.agent] == " other" } == true
1530+ state.paragraphs.forEach {
1531+ if (agent != it.agent) {
1532+ agent = it.agent
1533+ agentToSide.putIfAbsentSupport(it.agent, side)
1534+ side = agentToSide[it.agent]!!
1535+ }
1536+ }
1537+ }
15241538 val hasAtLeastTwoPeople = people[" person" ]?.let { it.size > 1 } == true
15251539 if (paragraphs.find { it.time != null } == null ) {
15261540 return UnsyncedLyrics (paragraphs.map {
@@ -1530,10 +1544,10 @@ fun parseTtml(audioMimeType: String?, lyricText: String): SemanticLyrics? {
15301544 val isOther = peopleToType[it.agent] == " other"
15311545 // first person goes left, second right, third left, fourth right, and so on.
15321546 // and the same goes for "other" except that we start on the right here.
1533- val isVoice2 =
1534- it.agent != null && (people[peopleToType[it.agent]] ? : throw NullPointerException (
1547+ val isVoice2 = agentToSide[it.agent] ? :
1548+ ( it.agent != null && (people[peopleToType[it.agent]] ? : throw NullPointerException (
15351549 " expected to find ${it.agent} (${peopleToType[it.agent]} ) in $people "
1536- )).indexOf(it.agent) % 2 == (if (isOther) 0 else 1 )
1550+ )).indexOf(it.agent) % 2 == (if (isOther) 0 else 1 ))
15371551 val speaker = when {
15381552 isGroup && isBg -> SpeakerEntity .GroupBackground
15391553 isGroup -> SpeakerEntity .Group
0 commit comments