Skip to content

Commit 09d6287

Browse files
committed
wip
1 parent 3be15fd commit 09d6287

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

app/src/main/cpp/NativeTrack.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
628628
.offload_buffer_size = (uint32_t)offloadBufferSize,
629629
.usage = usage,
630630
.encapsulation_mode = encapsulationMode, // tuner
631-
.content_id = contentType, // tuner
631+
.content_id = contentId, // tuner
632632
.sync_id = syncId, // tuner
633633
};
634634
audioAttributes.newAttrs = {
@@ -637,7 +637,7 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
637637
.source = LEGACY_AUDIO_SOURCE_DEFAULT,
638638
.flags = (uint32_t)attrFlags,
639639
};
640-
audioAttributes.newAttrs.tags[0] = '\0';
640+
memset(&audioAttributes.newAttrs.tags[0], '\0', 256);
641641
} else {
642642
offloadInfo.oldInfo = {
643643
.version = AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1),
@@ -662,7 +662,7 @@ Java_org_akanework_gramophone_logic_utils_NativeTrack_set(
662662
.source = LEGACY_AUDIO_SOURCE_DEFAULT,
663663
.flags = (uint32_t)attrFlags,
664664
};
665-
audioAttributes.oldAttrs.tags[0] = '\0';
665+
memset(&audioAttributes.newAttrs.tags[0], '\0', 256);
666666
}
667667
if (android_get_device_api_level() >= 31) { // Android 12.0 (SDK 31) or later
668668
auto refs = holder->callback->createWeak(holder);

app/src/main/kotlin/org/akanework/gramophone/logic/utils/NativeTrack.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ class NativeTrack(context: Context, attributes: AudioAttributes, streamType: Int
197197
.setUsage(AudioAttributes.USAGE_MEDIA)
198198
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
199199
.build(),
200-
AudioManager.STREAM_MUSIC,
201-
sampleRate = 48000,
202-
AudioFormatDetector.Encoding.ENCODING_PCM_16BIT,
200+
0,
201+
sampleRate = 13370,
202+
AudioFormatDetector.Encoding.ENCODING_PCM_8BIT,
203203
channelMask = 3,
204204
frameCount = null,
205-
trackFlags = 0,
205+
trackFlags = 1,
206206
AudioManager.AUDIO_SESSION_ID_GENERATE,
207207
maxRequiredSpeed = 1.0f,
208208
selectedDeviceId = null,
@@ -299,7 +299,7 @@ class NativeTrack(context: Context, attributes: AudioAttributes, streamType: Int
299299
AudioAttributes.ALLOW_CAPTURE_BY_NONE -> 0x1400
300300
AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM -> 0x400
301301
else -> 0x0
302-
} else 0x0) or (if (hasOutputFlagDeepBufferSet) 0x200 else 0x0)
302+
} else 0) or (if (hasOutputFlagDeepBufferSet) 0x200 else 0x0)
303303
val bitWidth = bitsPerSampleForFormat(format)
304304
// java streamType is compatible with native streamType
305305
val ret = try {

app/src/main/kotlin/org/akanework/gramophone/logic/utils/SemanticLyrics.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ sealed class SemanticLyrics : Parcelable {
488488
) : Parcelable {
489489
val isClickable: Boolean
490490
get() = text.isNotBlank()
491+
val timeRange: ULongRange
492+
get() = start..end
491493
}
492494

493495
@Parcelize

app/src/main/kotlin/org/akanework/gramophone/ui/components/NewLyricsView.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
367367
var timeUntilNext = 0uL
368368
var firstHighlight: Int? = null
369369
var lastHighlight: Int? = null
370+
var lastNonTranslated: SemanticLyrics.LyricLine? = null
370371
canvas.save()
371372
canvas.translate(globalPaddingHorizontal, heightSoFar.toFloat())
372373
val width = width - globalPaddingHorizontal * 2
@@ -432,6 +433,8 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
432433
}
433434
heightSoFarWithoutTranslated = heightSoFar
434435
}
436+
if (it.line?.isTranslated != true)
437+
lastNonTranslated = it.line
435438
if (highlight && firstHighlight == null) {
436439
firstHighlight = heightSoFarWithoutTranslated
437440
determineTimeUntilNext = true
@@ -451,11 +454,11 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
451454
if (highlight) {
452455
canvas.save()
453456
canvas.scale(1f / hlScaleFactor, 1f / hlScaleFactor)
454-
if (it.line?.words != null) {
455-
wordIdx = it.line.words.indexOfLast { it.timeRange.start <= posForRender }
457+
if (it.theWords != null) {
458+
wordIdx = it.theWords.indexOfLast { it.timeRange.start <= posForRender }
456459
if (wordIdx == -1) wordIdx = null
457460
if (wordIdx != null) {
458-
val word = it.line.words[wordIdx]
461+
val word = it.theWords[wordIdx]
459462
spanEnd = word.charRange.last + 1 // get exclusive end
460463
val gradientEndTime = min(
461464
lastTs.toFloat() - timeOffsetForUse,
@@ -481,11 +484,11 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
481484
it.layout.getLineForOffset(word.charRange.endInclusive)
482485
val firstCharOnStartLine = it.layout.getLineStart(wordStartLine)
483486
val lastCharOnEndLineExcl = it.layout.getLineEnd(wordEndLine)
484-
realGradientStart = it.line.words.lastOrNull {
487+
realGradientStart = it.theWords.lastOrNull {
485488
it.charRange.first >= firstCharOnStartLine && it.charRange.last <
486489
word.charRange.first && it.isRtl != word.isRtl
487490
}?.charRange?.last?.plus(1) ?: firstCharOnStartLine
488-
realGradientEnd = it.line.words.firstOrNull {
491+
realGradientEnd = it.theWords.firstOrNull {
489492
it.charRange.first > word.charRange.last && it.charRange.last <
490493
lastCharOnEndLineExcl && it.isRtl != word.isRtl
491494
}?.charRange?.first ?: lastCharOnEndLineExcl
@@ -662,8 +665,16 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
662665
val pixels = b?.let { IntArray(it.width * it.height) }
663666
val c = b?.let { Canvas(it) }
664667
val tmpPaint = b?.let { TextPaint() }
668+
var lastNonTranslated: SemanticLyrics.LyricLine? = null
665669
val spLines = lines.mapIndexed { i, it ->
666670
val syncedLine = syncedLines?.get(i)
671+
if (syncedLine?.isTranslated != true)
672+
lastNonTranslated = syncedLine
673+
val words = syncedLine?.words ?:
674+
if (syncedLine?.isTranslated == true && lastNonTranslated?.words != null)
675+
listOf(SemanticLyrics.Word(lastNonTranslated.timeRange, 0..<syncedLine.text.length,
676+
findBidirectionalBarriers(syncedLine.text).firstOrNull()?.second == true
677+
)) else null
667678
val sb = SpannableStringBuilder(it.first)
668679
val speaker = syncedLine?.speaker ?: it.second
669680
val align = if (prefs.getBooleanStrict("lyric_center", false) || speaker?.isGroup == true)
@@ -694,7 +705,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
694705
val alignmentNormal = if (paragraphRtl) align == Layout.Alignment.ALIGN_OPPOSITE
695706
else align == Layout.Alignment.ALIGN_NORMAL
696707
var l: StaticLayout? = null
697-
val lineOffsets = syncedLine?.words?.map {
708+
val lineOffsets = words?.map {
698709
val ia = mutableListOf<Int>()
699710
val firstLine = layout.getLineForOffset(it.charRange.first)
700711
val lastLine = layout.getLineForOffset(it.charRange.last + 1)
@@ -764,7 +775,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
764775
return@map ia
765776
}
766777
SbItem(layout, sb, paddingTop.dpToPx(context), paddingBottom.dpToPx(context),
767-
lineOffsets, lineOffsets?.let { _ ->
778+
words, lineOffsets, lineOffsets?.let { _ ->
768779
(0..<layout.lineCount).map { line ->
769780
findBidirectionalBarriers(layout.text.subSequence(
770781
layout.getLineStart(line), layout.getLineEnd(line))).flatMap {
@@ -880,8 +891,9 @@ class NewLyricsView(context: Context, attrs: AttributeSet?) : View(context, attr
880891

881892
data class SbItem(
882893
val layout: StaticLayout, val text: SpannableStringBuilder,
883-
val paddingTop: Int, val paddingBottom: Int, val words: List<List<Int>>?,
884-
val rlm: List<Int>?, val speaker: SpeakerEntity?, val line: SemanticLyrics.LyricLine?
894+
val paddingTop: Int, val paddingBottom: Int, val theWords: List<SemanticLyrics.Word>?,
895+
val words: List<List<Int>>?, val rlm: List<Int>?, val speaker: SpeakerEntity?,
896+
val line: SemanticLyrics.LyricLine?
885897
)
886898

887899
}

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
val agpVersion = "8.9.1"
3+
val agpVersion = "8.10.0-rc01"
44
id("com.android.application") version agpVersion apply false
55
id("com.android.library") version agpVersion apply false
66
id("com.android.test") version agpVersion apply false
7-
id("androidx.baselineprofile") version "1.3.3" apply false
7+
id("androidx.baselineprofile") version "1.3.4" apply false
88
val kotlinVersion = "2.0.21"
99
kotlin("android") version kotlinVersion apply false
1010
kotlin("plugin.parcelize") version kotlinVersion apply false

libphonograph

0 commit comments

Comments
 (0)