Implement voice labels marker "${v:.....}" for notelines "Nx:"
This commit is contained in:
parent
6ba2af679a
commit
a1c816e603
2 changed files with 194 additions and 31 deletions
|
|
@ -31,6 +31,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
private val L: MutableList<POneStanzaLyrics> = mutableListOf()
|
private val L: MutableList<POneStanzaLyrics> = mutableListOf()
|
||||||
private val O: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
private val O: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
||||||
private val unparsedNote = mutableListOf<String>()
|
private val unparsedNote = mutableListOf<String>()
|
||||||
|
private val voiceMarkers: MutableMap<Int, MutableMap<Int, String>> = mutableMapOf()
|
||||||
private var refrainBeginsAt = -1
|
private var refrainBeginsAt = -1
|
||||||
private var refrainEndsAt = -1
|
private var refrainEndsAt = -1
|
||||||
private var refrainMaxStanza = -1
|
private var refrainMaxStanza = -1
|
||||||
|
|
@ -66,6 +67,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
val REGEX_DC_REFRAIN = Regex("""\$\{R=\}\$\{D:(.*?)\}""")
|
val REGEX_DC_REFRAIN = Regex("""\$\{R=\}\$\{D:(.*?)\}""")
|
||||||
val REGEX_D_BLOCK = Regex("""\$\{D=\}(.*?)\$\{D!\}""", RegexOption.DOT_MATCHES_ALL)
|
val REGEX_D_BLOCK = Regex("""\$\{D=\}(.*?)\$\{D!\}""", RegexOption.DOT_MATCHES_ALL)
|
||||||
val REGEX_OVERRIDE_TOKEN = Regex("""\$\{O:\d+\}""")
|
val REGEX_OVERRIDE_TOKEN = Regex("""\$\{O:\d+\}""")
|
||||||
|
val REGEX_VOICE_MARKER = Regex("\\$\\{v:([^\\}]+)\\}")
|
||||||
val KEEP_MARKERS = listOf("\${L}", "\$T")
|
val KEEP_MARKERS = listOf("\${L}", "\$T")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,6 +127,10 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
N.forEachIndexed { voiceNumber, pOneVoiceNote ->
|
N.forEachIndexed { voiceNumber, pOneVoiceNote ->
|
||||||
run {
|
run {
|
||||||
unitObject.addNote(voiceNumber, pOneVoiceNote.oneVoiceNote, nextNIndex, nextMarker)
|
unitObject.addNote(voiceNumber, pOneVoiceNote.oneVoiceNote, nextNIndex, nextMarker)
|
||||||
|
val vMarker = voiceMarkers[voiceNumber]?.get(nextNIndex)
|
||||||
|
if (vMarker != null) {
|
||||||
|
unitObject.addVoiceMarker(voiceNumber, vMarker)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nextMarker = '0'
|
nextMarker = '0'
|
||||||
|
|
@ -275,6 +281,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
refrainEndsAt = -1
|
refrainEndsAt = -1
|
||||||
refrainMaxStanza = -1
|
refrainMaxStanza = -1
|
||||||
unparsedNote.clear()
|
unparsedNote.clear()
|
||||||
|
voiceMarkers.clear()
|
||||||
templateString = ""
|
templateString = ""
|
||||||
nextTIndex = -1
|
nextTIndex = -1
|
||||||
nextNIndex = -1
|
nextNIndex = -1
|
||||||
|
|
@ -455,6 +462,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
pitches.clear()
|
pitches.clear()
|
||||||
refrainBeginsAt = -1
|
refrainBeginsAt = -1
|
||||||
unparsedNote.clear()
|
unparsedNote.clear()
|
||||||
|
voiceMarkers.clear()
|
||||||
templateString = ""
|
templateString = ""
|
||||||
nextTIndex = -1
|
nextTIndex = -1
|
||||||
nextNIndex = -1
|
nextNIndex = -1
|
||||||
|
|
@ -1983,7 +1991,41 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
|
|
||||||
private fun preloadN(noteLine: String) {
|
private fun preloadN(noteLine: String) {
|
||||||
val voiceNumber = noteLine.substring(0, 1).toInt()
|
val voiceNumber = noteLine.substring(0, 1).toInt()
|
||||||
val parsedNoteLine = parseNoteSplit(noteLine)
|
val rawBody = noteLine.substring(1)
|
||||||
|
|
||||||
|
val vMap = voiceMarkers.getOrPut(voiceNumber) { mutableMapOf() }
|
||||||
|
var lastIdx = 0
|
||||||
|
val cleanBuilder = StringBuilder()
|
||||||
|
|
||||||
|
fun countNotesInSegment(segment: String): Int {
|
||||||
|
val withoutComments = segment
|
||||||
|
.replace(REGEX_TEMPLATE_COMMENT, "")
|
||||||
|
.replace(Regex("#[drmfsltDRFSTz][',]*"), "")
|
||||||
|
.replace(Regex("<\\s*\\{[^\\}]*\\}"), "")
|
||||||
|
.replace(" ", "")
|
||||||
|
val expanded = REGEX_REPETITION.replace(withoutComments) { m ->
|
||||||
|
m.groupValues[1].repeat(m.groupValues[2].toInt())
|
||||||
|
}
|
||||||
|
return expanded.count {
|
||||||
|
it in listOf(
|
||||||
|
'd', 'r', 'm', 'f', 's', 'l', 't',
|
||||||
|
'D', 'R', 'M', 'F', 'S', 'L', 'T',
|
||||||
|
'z', 'Z'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
REGEX_VOICE_MARKER.findAll(rawBody).forEach { match ->
|
||||||
|
val beforeText = rawBody.substring(lastIdx, match.range.first)
|
||||||
|
cleanBuilder.append(beforeText)
|
||||||
|
val noteOffset = countNotesInSegment(cleanBuilder.toString())
|
||||||
|
vMap[noteOffset] = match.groupValues[1].trim()
|
||||||
|
lastIdx = match.range.last + 1
|
||||||
|
}
|
||||||
|
cleanBuilder.append(rawBody.substring(lastIdx))
|
||||||
|
val cleanLineContent = cleanBuilder.toString()
|
||||||
|
|
||||||
|
val parsedNoteLine = parseNoteSplit(voiceNumber.toString() + cleanLineContent)
|
||||||
val templateComments = mutableListOf<String>()
|
val templateComments = mutableListOf<String>()
|
||||||
val templateStripped = REGEX_TEMPLATE_COMMENT.replace(templateString) { matchResult ->
|
val templateStripped = REGEX_TEMPLATE_COMMENT.replace(templateString) { matchResult ->
|
||||||
templateComments.add(matchResult.value)
|
templateComments.add(matchResult.value)
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,14 @@ class TimeUnitObject (val pTemplate: PTemplate, val prevTUO: TimeUnitObject?, co
|
||||||
tuNote.from(thisNote)
|
tuNote.from(thisNote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val voiceMarkers: MutableMap<Int, String> = mutableMapOf()
|
||||||
|
|
||||||
|
fun addVoiceMarker(voiceNumber: Int, markerText: String) {
|
||||||
|
if (markerText.isNotBlank()) {
|
||||||
|
voiceMarkers[voiceNumber] = markerText
|
||||||
|
}
|
||||||
|
}
|
||||||
private fun newTUNote(voiceNumber: Int, thisNote: Note?, newMarker: Char, markerBefore: String): TUNote {
|
private fun newTUNote(voiceNumber: Int, thisNote: Note?, newMarker: Char, markerBefore: String): TUNote {
|
||||||
val prevTUNote: TUNote? = prevTUO?.tuNotes?.getOrNull(voiceNumber)
|
val prevTUNote: TUNote? = prevTUO?.tuNotes?.getOrNull(voiceNumber)
|
||||||
val newNote = TUNote()
|
val newNote = TUNote()
|
||||||
|
|
@ -422,6 +430,10 @@ fun TimeUnitComposable(
|
||||||
}
|
}
|
||||||
val rawLine = rawLines.getOrNull(ta.voiceNumber - 1).orEmpty()
|
val rawLine = rawLines.getOrNull(ta.voiceNumber - 1).orEmpty()
|
||||||
fun shifted(idx: Int) = if (isLitany) idx + SolfaLabels.extraChars(rawLine, idx) else idx
|
fun shifted(idx: Int) = if (isLitany) idx + SolfaLabels.extraChars(rawLine, idx) else idx
|
||||||
|
val lineCount = textLayoutResult?.lineCount ?: 0
|
||||||
|
val targetLineIndex = ta.voiceNumber - 1
|
||||||
|
|
||||||
|
if (targetLineIndex >= 0 && targetLineIndex < lineCount) {
|
||||||
if (us.x > -1) {
|
if (us.x > -1) {
|
||||||
val lineGlobalStartOffset = textLayoutResult?.getLineStart(ta.voiceNumber - 1) ?: 0
|
val lineGlobalStartOffset = textLayoutResult?.getLineStart(ta.voiceNumber - 1) ?: 0
|
||||||
val globalStartIndex = lineGlobalStartOffset + shifted(us.x)
|
val globalStartIndex = lineGlobalStartOffset + shifted(us.x)
|
||||||
|
|
@ -451,6 +463,7 @@ fun TimeUnitComposable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
){
|
){
|
||||||
val annotatedText = remember(multiLineText, MaterialTheme.colorScheme.primary) {
|
val annotatedText = remember(multiLineText, MaterialTheme.colorScheme.primary) {
|
||||||
buildAnnotatedString {
|
buildAnnotatedString {
|
||||||
|
|
@ -795,8 +808,50 @@ fun LazyVerticalGridTUO(
|
||||||
val activeRowIndex by sharedScreenModel.activeIndex.collectAsStateWithLifecycle()
|
val activeRowIndex by sharedScreenModel.activeIndex.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val abModeState by sharedScreenModel.abModeState.collectAsState()
|
val abModeState by sharedScreenModel.abModeState.collectAsState()
|
||||||
val measures = remember(tuoList, gridColumnCount) {
|
val hasVoiceLabels = tuoList.drop(1).any { it.voiceMarkers.isNotEmpty() }
|
||||||
tuoList.drop(1).chunked(gridColumnCount)
|
|
||||||
|
val maxLabelLength = remember(tuoList) {
|
||||||
|
tuoList.drop(1).maxOfOrNull { tuo ->
|
||||||
|
tuo.voiceMarkers.values.maxOfOrNull { it.length } ?: 0
|
||||||
|
} ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
val voiceLabelColumnWidth = remember(maxLabelLength) {
|
||||||
|
println("→$maxLabelLength")
|
||||||
|
when {
|
||||||
|
maxLabelLength > 15 -> 130.dp
|
||||||
|
maxLabelLength > 12 -> 115.dp
|
||||||
|
maxLabelLength > 10 -> 100.dp
|
||||||
|
else -> 65.dp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val reductionCols = when {
|
||||||
|
maxLabelLength > 12 -> 3
|
||||||
|
maxLabelLength > 10 -> 2
|
||||||
|
maxLabelLength > 0 -> 1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
val firstRowCols = if (hasVoiceLabels) (gridColumnCount - reductionCols).coerceAtLeast(1) else gridColumnCount
|
||||||
|
|
||||||
|
|
||||||
|
val validTuosForVoice = tuoList.drop(1)
|
||||||
|
val firstValidTuo = validTuosForVoice.firstOrNull()
|
||||||
|
val measures = remember(tuoList, gridColumnCount, hasVoiceLabels, firstRowCols) {
|
||||||
|
val allTuos = tuoList.drop(1)
|
||||||
|
val result = mutableListOf<List<TimeUnitObject>>()
|
||||||
|
if (allTuos.isEmpty()) return@remember result
|
||||||
|
|
||||||
|
val firstChunkSize = minOf(allTuos.size, firstRowCols)
|
||||||
|
result.add(allTuos.take(firstChunkSize))
|
||||||
|
var currentIndex = firstChunkSize
|
||||||
|
|
||||||
|
while (currentIndex < allTuos.size) {
|
||||||
|
val nextChunkSize = minOf(allTuos.size - currentIndex, gridColumnCount)
|
||||||
|
result.add(allTuos.subList(currentIndex, currentIndex + nextChunkSize))
|
||||||
|
currentIndex += nextChunkSize
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
val hairpinByEndBlock: Map<Int, HairpinRange> = remember(tuoList) {
|
val hairpinByEndBlock: Map<Int, HairpinRange> = remember(tuoList) {
|
||||||
|
|
@ -897,6 +952,14 @@ fun LazyVerticalGridTUO(
|
||||||
){
|
){
|
||||||
measures.forEachIndexed { measureIndex, measureTUOs ->
|
measures.forEachIndexed { measureIndex, measureTUOs ->
|
||||||
key(measureIndex) {
|
key(measureIndex) {
|
||||||
|
val isFirstMeasureWithVoiceCol = (measureIndex == 0 && hasVoiceLabels)
|
||||||
|
val rowColumnCount = if (isFirstMeasureWithVoiceCol) firstRowCols else gridColumnCount
|
||||||
|
val rowCellWidth = if (isFirstMeasureWithVoiceCol) {
|
||||||
|
(gridWidthDp - voiceLabelColumnWidth).coerceAtLeast(0.dp) / rowColumnCount
|
||||||
|
} else {
|
||||||
|
gridWidthDp / gridColumnCount
|
||||||
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
|
|
@ -904,10 +967,13 @@ fun LazyVerticalGridTUO(
|
||||||
horizontalArrangement = Arrangement.Start,
|
horizontalArrangement = Arrangement.Start,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
if (isFirstMeasureWithVoiceCol) {
|
||||||
|
Spacer(modifier = Modifier.width(voiceLabelColumnWidth))
|
||||||
|
}
|
||||||
measureTUOs.forEachIndexed { indexInMeasure, tuo ->
|
measureTUOs.forEachIndexed { indexInMeasure, tuo ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(gridWidthDp / gridColumnCount)
|
.width(rowCellWidth)
|
||||||
) {
|
) {
|
||||||
if (TimeUnitObject._hasMarker) {
|
if (TimeUnitObject._hasMarker) {
|
||||||
val lineHeight = 20.sp
|
val lineHeight = 20.sp
|
||||||
|
|
@ -943,7 +1009,7 @@ fun LazyVerticalGridTUO(
|
||||||
TuoChordRowItem(
|
TuoChordRowItem(
|
||||||
tuo,
|
tuo,
|
||||||
sharedScreenModel,
|
sharedScreenModel,
|
||||||
gridWidthDp,
|
rowCellWidth,
|
||||||
gridColumnCount,
|
gridColumnCount,
|
||||||
toggleWithDegreeAndChord,
|
toggleWithDegreeAndChord,
|
||||||
onToggleChange = {
|
onToggleChange = {
|
||||||
|
|
@ -955,6 +1021,13 @@ fun LazyVerticalGridTUO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Row(modifier = Modifier.fillMaxWidth()) {
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
if (isFirstMeasureWithVoiceCol && hasVoiceLabels) {
|
||||||
|
VoiceLabelCell(
|
||||||
|
tuoList = tuoList,
|
||||||
|
width = voiceLabelColumnWidth
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
measureTUOs.forEachIndexed { indexInMeasure, oneTUO ->
|
measureTUOs.forEachIndexed { indexInMeasure, oneTUO ->
|
||||||
val globalIndex = (measureIndex * gridColumnCount) + indexInMeasure
|
val globalIndex = (measureIndex * gridColumnCount) + indexInMeasure
|
||||||
val loopingState by sharedScreenModel.loopingState.collectAsState()
|
val loopingState by sharedScreenModel.loopingState.collectAsState()
|
||||||
|
|
@ -974,7 +1047,7 @@ fun LazyVerticalGridTUO(
|
||||||
|
|
||||||
val isAbsoluteLastGrid = (globalIndex == tuoList.size - 2)
|
val isAbsoluteLastGrid = (globalIndex == tuoList.size - 2)
|
||||||
if (editMode && isAbsoluteLastGrid) {
|
if (editMode && isAbsoluteLastGrid) {
|
||||||
val lastGridwidth = if(isAndroid) (gridWidthDp / gridColumnCount)*2 else ((gridWidthDp / gridColumnCount)*11)/10
|
val lastGridwidth = if(isAndroid) (rowCellWidth)*2 else ((rowCellWidth)*11)/10
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(lastGridwidth)
|
.width(lastGridwidth)
|
||||||
|
|
@ -1213,6 +1286,10 @@ fun LazyVerticalGridTUO(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.Start
|
horizontalArrangement = Arrangement.Start
|
||||||
) {
|
) {
|
||||||
|
val isFirstMeasureWithVoiceCol = (measureIndex == 0 && hasVoiceLabels)
|
||||||
|
if (isFirstMeasureWithVoiceCol) {
|
||||||
|
Spacer(modifier = Modifier.width(voiceLabelColumnWidth))
|
||||||
|
}
|
||||||
val columnWidthDp = gridWidthDp / gridColumnCount
|
val columnWidthDp = gridWidthDp / gridColumnCount
|
||||||
val cleanAllTemps = allTemps.map { column ->
|
val cleanAllTemps = allTemps.map { column ->
|
||||||
column.map { syllable ->
|
column.map { syllable ->
|
||||||
|
|
@ -1324,7 +1401,7 @@ private fun TuoChordRowItem(
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(gridWidthDp / gridColumnCount)
|
.width(gridWidthDp)
|
||||||
) {
|
) {
|
||||||
val maxFontSize = 12.sp
|
val maxFontSize = 12.sp
|
||||||
val minFontSize = 10.sp
|
val minFontSize = 10.sp
|
||||||
|
|
@ -1860,6 +1937,50 @@ fun EditorActionButtons(isUndoVisible: Boolean, onUndo: () -> Unit, onBuild: ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun VoiceLabelCell(
|
||||||
|
tuoList: List<TimeUnitObject>,
|
||||||
|
width: Dp,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
val aggregatedMarkers = remember(tuoList) {
|
||||||
|
val map = mutableMapOf<Int, String>()
|
||||||
|
tuoList.take(10).forEach { tuo ->
|
||||||
|
tuo.voiceMarkers.forEach { (voiceNum, text) ->
|
||||||
|
if (text.isNotBlank() && !map.containsKey(voiceNum)) {
|
||||||
|
map[voiceNum] = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.toSortedMap()
|
||||||
|
}
|
||||||
|
val maxVoiceNum = maxOf(aggregatedMarkers.keys.maxOrNull() ?: 4, 4)
|
||||||
|
val voiceNumbers = (1..maxVoiceNum).toList()
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.width(width)
|
||||||
|
.padding(end = 0.dp),
|
||||||
|
verticalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
voiceNumbers.forEach { voiceNum ->
|
||||||
|
val labelText = aggregatedMarkers[voiceNum]?.trim().orEmpty()
|
||||||
|
Text(
|
||||||
|
text = labelText,
|
||||||
|
style = MaterialTheme.typography.bodyLarge.copy(
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
fontStyle = FontStyle.Italic,
|
||||||
|
color = MaterialTheme.colorScheme.onSecondary
|
||||||
|
),
|
||||||
|
maxLines = 1,
|
||||||
|
softWrap = false,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun autoFixNote(rawNote: String, template: String): String {
|
fun autoFixNote(rawNote: String, template: String): String {
|
||||||
// println("\n==================================================")
|
// println("\n==================================================")
|
||||||
// println(" ENTRÉE autoFixNote")
|
// println(" ENTRÉE autoFixNote")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue