Fix: show dialog warning when required M0 metadata is missing
This commit is contained in:
parent
1aa11747b5
commit
570c5e4868
3 changed files with 68 additions and 2 deletions
|
|
@ -58,7 +58,7 @@ object ScreenSolfa : Screen {
|
|||
val tuoList by sharedScreenModel.tuoList.collectAsState()
|
||||
val measure by sharedScreenModel.measure.collectAsState()
|
||||
val stanza by sharedScreenModel.stanza.collectAsState()
|
||||
val nbStanzas: Int by sharedScreenModel.nbStanzas.collectAsState()
|
||||
val missingMetadataModalMessage by sharedScreenModel.missingMetadataModalMessage.collectAsState()
|
||||
val gridTUOData = remember(tuoList, measure, stanza) { GridTUOData(measure, tuoList, stanza) }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val scrollState = rememberScrollState()
|
||||
|
|
@ -634,6 +634,25 @@ object ScreenSolfa : Screen {
|
|||
scrollState = scrollState,
|
||||
modifier = Modifier.align(Alignment.CenterEnd)
|
||||
) {}
|
||||
|
||||
missingMetadataModalMessage?.let { modalMessage ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { sharedScreenModel.dismissMissingMetadataModal() },
|
||||
text = {
|
||||
Text(
|
||||
text = modalMessage,
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = { sharedScreenModel.dismissMissingMetadataModal() }
|
||||
) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,6 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
}
|
||||
fun parse(sourceFile: String) {
|
||||
//println("37: lFL bien reçu $sourceFile")
|
||||
currentFile = sourceFile
|
||||
currentJob?.cancel()
|
||||
currentJob = solfaScope.launch {
|
||||
val lines = try {
|
||||
|
|
@ -286,6 +285,14 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
println("Opening $sourceFile raised exception {${e.message}")
|
||||
emptyList()
|
||||
}
|
||||
if (!hasRequiredM0Metadata(lines)) {
|
||||
withContext(Dispatchers.Main) {
|
||||
sharedScreenModel.showMissingMetadataModal(MISSING_M0_METADATA_MESSAGE)
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
currentFile = sourceFile
|
||||
val contentString = lines.joinToString("\n")
|
||||
sharedScreenModel.setFileContent(contentString, sourceFile)
|
||||
O.clear()
|
||||
|
|
@ -3366,3 +3373,32 @@ private fun finalizeMarkers(listTuos: List<TimeUnitObject>, sharedScreenModel: S
|
|||
sharedScreenModel.updateAndFinalizeMidiData(rawMarkers)
|
||||
return sharedScreenModel.getFullMarkers()
|
||||
}
|
||||
|
||||
private const val MISSING_M0_METADATA_MESSAGE = "La partition ne contient pas les informations nécessaire au Feufar.ooo"
|
||||
|
||||
private fun hasRequiredM0Metadata(lines: List<String>): Boolean {
|
||||
return lines.any { rawLine ->
|
||||
val trimmed = rawLine.trimStart()
|
||||
if (!trimmed.startsWith("M0:")) return@any false
|
||||
|
||||
val afterPrefix = trimmed.removePrefix("M0:")
|
||||
val fields = afterPrefix.split("|")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.mapNotNull { chunk ->
|
||||
val colonIdx = chunk.indexOf(':')
|
||||
if (colonIdx <= 0) null
|
||||
else {
|
||||
val key = chunk.substring(0, colonIdx).trim()
|
||||
val valPart = chunk.substring(colonIdx + 1).trim()
|
||||
key to valPart
|
||||
}
|
||||
}
|
||||
.toMap()
|
||||
|
||||
val hasTitle = !fields["t"].isNullOrBlank()
|
||||
val hasKey = !fields["c"].isNullOrBlank()
|
||||
val hasMeasure = !fields["m"].isNullOrBlank()
|
||||
hasTitle && hasKey && hasMeasure
|
||||
}
|
||||
}
|
||||
|
|
@ -846,6 +846,17 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
}
|
||||
}
|
||||
|
||||
private val _missingMetadataModalMessage = MutableStateFlow<String?>(null)
|
||||
val missingMetadataModalMessage: StateFlow<String?> = _missingMetadataModalMessage.asStateFlow()
|
||||
|
||||
fun showMissingMetadataModal(message: String) {
|
||||
_missingMetadataModalMessage.value = message
|
||||
}
|
||||
|
||||
fun dismissMissingMetadataModal() {
|
||||
_missingMetadataModalMessage.value = null
|
||||
}
|
||||
|
||||
private var _mediaPlayer by mutableStateOf<FMediaPlayer?>(null)
|
||||
val mediaPlayer: FMediaPlayer? get() = _mediaPlayer
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue