Fix playlist swipe bug and disable drawer gestures when no playlist is active

This commit is contained in:
Hasinjato 2026-11-30 17:24:03 +03:00
parent 0fc75bd50b
commit 8d6aaa131e
5 changed files with 104 additions and 73 deletions

View file

@ -103,9 +103,20 @@ object ScreenSolfa : Screen {
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState() val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
val playlistActive by sharedScreenModel.playlistActive.collectAsState() val playlistActive by sharedScreenModel.playlistActive.collectAsState()
LaunchedEffect(playlistStanzas, activeFilePath) { val nbStanzas by sharedScreenModel.nbStanzas.collectAsState()
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) { val isParsing by sharedScreenModel.isParsing.collectAsState()
sharedScreenModel.setStanza(playlistStanzas.first())
LaunchedEffect(activeFilePath, nbStanzas, playlistStanzas, isParsing, stanza) {
if (isParsing || activeFilePath.isBlank() || nbStanzas <= 0) return@LaunchedEffect
val effectiveAllowed = if (playlistStanzas.isEmpty()) {
(1..nbStanzas).toList()
} else {
playlistStanzas.filter { it in 1..nbStanzas }
}
if (effectiveAllowed.isNotEmpty() && stanza !in effectiveAllowed) {
sharedScreenModel.setStanza(effectiveAllowed.first())
scrollState.scrollTo(0) scrollState.scrollTo(0)
} }
} }
@ -311,7 +322,7 @@ object ScreenSolfa : Screen {
if (dragPressed.isEmpty()) { if (dragPressed.isEmpty()) {
val totalDragX = currentX - startPos.x val totalDragX = currentX - startPos.x
val threshold = screenWidthPx * 0.30f val threshold = screenWidthPx * 0.10f
// println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f") // println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f")

View file

@ -279,76 +279,81 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
//println("37: lFL bien reçu $sourceFile") //println("37: lFL bien reçu $sourceFile")
currentJob?.cancel() currentJob?.cancel()
currentJob = solfaScope.launch { currentJob = solfaScope.launch {
val lines = try { sharedScreenModel.setParsing(true)
fileRepository.readFileLines(sourceFile)
} catch (e: Exception) {
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()
T.clear()
N.clear()
L.clear()
globalDComments.clear()
meta.clear()
if (pitches.isNotEmpty()) {
pitches[0].reset()
}
pitches.clear()
refrainBeginsAt = -1
refrainEndsAt = -1
refrainMaxStanza = -1
unparsedNote.clear()
voiceMarkers.clear()
templateString = ""
nextTIndex = -1
nextNIndex = -1
nextLIndex = -1
lyricsComment.clear()
if (sharedScreenModel.stanza.value == 0) {
sharedScreenModel.setStanza(1)
}
sharedScreenModel.setNbStanzas(0)
TimeUnitObject.hasMarker(false)
lines.forEach { line ->
parseOneLine(line)
}
unparsedNote.forEach {
preloadN(it)
}
val localAccumulator = mutableListOf<TimeUnitObject>()
try { try {
withContext(Dispatchers.Main) { val lines = try {
sharedScreenModel.updateFullTUOList(emptyList()) fileRepository.readFileLines(sourceFile)
} catch (e: Exception) {
println("Opening $sourceFile raised exception {${e.message}")
emptyList()
}
if (!hasRequiredM0Metadata(lines)) {
withContext(Dispatchers.Main) {
sharedScreenModel.showMissingMetadataModal(MISSING_M0_METADATA_MESSAGE)
}
return@launch
} }
nextTimeUnitObject(localAccumulator)
} catch (e: Exception) {
println("Erreur parseScope Solfa:150 : ${e.message} iter: ${TimeUnitObject.nbBlock}")
}
attachLyricsToPitches(localAccumulator)
val pitches = pitches.sortedWith(compareBy({ it.tick }, { it.voiceNumber }))
val midiWriter = MidiWriterKotlin(fileRepository)
val markers = finalizeMarkers(localAccumulator, sharedScreenModel)
val originalKey = sharedScreenModel.songKey.value.ifEmpty { meta["C"] ?: "C" }
midiWriter.process(pitches, markers, originalKey) currentFile = sourceFile
midiWriter.save("whawyd3.mid") val contentString = lines.joinToString("\n")
val allowed = sharedScreenModel.allowedStanzas.value sharedScreenModel.setFileContent(contentString, sourceFile)
val currentStz = sharedScreenModel.stanza.value O.clear()
if (currentStz !in allowed && allowed.isNotEmpty()) { T.clear()
sharedScreenModel.setStanza(allowed.first()) N.clear()
} else if (currentStz == 0) { L.clear()
sharedScreenModel.setStanza(1) globalDComments.clear()
meta.clear()
if (pitches.isNotEmpty()) {
pitches[0].reset()
}
pitches.clear()
refrainBeginsAt = -1
refrainEndsAt = -1
refrainMaxStanza = -1
unparsedNote.clear()
voiceMarkers.clear()
templateString = ""
nextTIndex = -1
nextNIndex = -1
nextLIndex = -1
lyricsComment.clear()
if (sharedScreenModel.stanza.value == 0) {
sharedScreenModel.setStanza(1)
}
sharedScreenModel.setNbStanzas(0)
TimeUnitObject.hasMarker(false)
lines.forEach { line ->
parseOneLine(line)
}
unparsedNote.forEach {
preloadN(it)
}
val localAccumulator = mutableListOf<TimeUnitObject>()
try {
withContext(Dispatchers.Main) {
sharedScreenModel.updateFullTUOList(emptyList())
}
nextTimeUnitObject(localAccumulator)
} catch (e: Exception) {
println("Erreur parseScope Solfa:150 : ${e.message} iter: ${TimeUnitObject.nbBlock}")
}
attachLyricsToPitches(localAccumulator)
val pitches = pitches.sortedWith(compareBy({ it.tick }, { it.voiceNumber }))
val midiWriter = MidiWriterKotlin(fileRepository)
val markers = finalizeMarkers(localAccumulator, sharedScreenModel)
val originalKey = sharedScreenModel.songKey.value.ifEmpty { meta["C"] ?: "C" }
midiWriter.process(pitches, markers, originalKey)
midiWriter.save("whawyd3.mid")
val allowed = sharedScreenModel.allowedStanzas.value
val currentStz = sharedScreenModel.stanza.value
if (currentStz !in allowed && allowed.isNotEmpty()) {
sharedScreenModel.setStanza(allowed.first())
} else if (currentStz == 0) {
sharedScreenModel.setStanza(1)
}
} finally {
sharedScreenModel.setParsing(false)
} }
} }
} }

View file

@ -232,7 +232,8 @@ fun MainScreenWithDrawer(
scope.launch { drawerState.close() } scope.launch { drawerState.close() }
} }
ModalNavigationDrawer(drawerState = drawerState, drawerContent = { val playlistActive by sharedScreenModel.playlistActive.collectAsState()
ModalNavigationDrawer(drawerState = drawerState, gesturesEnabled = playlistActive == null, drawerContent = {
SimpleDrawerContent( SimpleDrawerContent(
items, items,
solfaScreenModel, solfaScreenModel,

View file

@ -214,6 +214,7 @@ fun SimpleDrawerContent(
onClick = { onClick = {
scope.launch { drawerState.close() } scope.launch { drawerState.close() }
sharedScreenModel.reset() sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path) solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi) onSongSelected(midi)
}, },
@ -269,6 +270,7 @@ fun SimpleDrawerContent(
onClick = { onClick = {
scope.launch { drawerState.close() } scope.launch { drawerState.close() }
sharedScreenModel.reset() sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path) solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi) onSongSelected(midi)
}, },
@ -404,6 +406,7 @@ fun SimpleDrawerContent(
onClick = { onClick = {
scope.launch { drawerState.close() } scope.launch { drawerState.close() }
sharedScreenModel.reset() sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path) solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi) onSongSelected(midi)
}, },

View file

@ -783,15 +783,19 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
val activeFilePath: State<String> = _activeFilePath val activeFilePath: State<String> = _activeFilePath
fun setFileContent(content: String?, path: String) { fun setFileContent(content: String?, path: String) {
val isNewSong = !samePath(_activeFilePathFlow.value, path)
_fileContent.value = content _fileContent.value = content
_activeFilePath.value = path _activeFilePath.value = path
_activeFilePathFlow.value = path _activeFilePathFlow.value = path
val active = _activePlaylist.value val active = _activePlaylist.value
val entry = active.find { samePath(it.path, path) } val entry = active.find { samePath(it.path, path) }
if (isNewSong) {
_nbStanzas.value = 0
}
if (entry != null && entry.stanzas.isNotEmpty()) { if (entry != null && entry.stanzas.isNotEmpty()) {
_stanza.value = entry.stanzas.sorted().first() _stanza.value = entry.stanzas.sorted().first()
} else if (_stanza.value == 0) { } else if (isNewSong || _stanza.value <= 0) {
_stanza.value = 1 _stanza.value = 1
} }
@ -1287,6 +1291,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
_showSearchMenu.value = false _showSearchMenu.value = false
_sourceModeState.value = false _sourceModeState.value = false
_harmonyView.value = false _harmonyView.value = false
_stanza.value = 0
setTranspositionInterval(0) setTranspositionInterval(0)
setTranspToC(0) setTranspToC(0)
setSilentDurBefr(0) setSilentDurBefr(0)
@ -1321,6 +1326,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
_songTitle.value = theTitle _songTitle.value = theTitle
} }
private val _isParsing = MutableStateFlow(false)
val isParsing: StateFlow<Boolean> = _isParsing.asStateFlow()
fun setParsing(parsing: Boolean) {
_isParsing.value = parsing
}
fun setStanza(theStanza: Int) { fun setStanza(theStanza: Int) {
try { try {
_stanza.value = theStanza _stanza.value = theStanza