Fix playlist swipe bug and disable drawer gestures when no playlist is active
This commit is contained in:
parent
0fc75bd50b
commit
8d6aaa131e
5 changed files with 104 additions and 73 deletions
|
|
@ -103,9 +103,20 @@ object ScreenSolfa : Screen {
|
|||
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
|
||||
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
||||
|
||||
LaunchedEffect(playlistStanzas, activeFilePath) {
|
||||
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) {
|
||||
sharedScreenModel.setStanza(playlistStanzas.first())
|
||||
val nbStanzas by sharedScreenModel.nbStanzas.collectAsState()
|
||||
val isParsing by sharedScreenModel.isParsing.collectAsState()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -311,7 +322,7 @@ object ScreenSolfa : Screen {
|
|||
|
||||
if (dragPressed.isEmpty()) {
|
||||
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")
|
||||
|
||||
|
|
|
|||
|
|
@ -279,76 +279,81 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
|||
//println("37: lFL bien reçu $sourceFile")
|
||||
currentJob?.cancel()
|
||||
currentJob = solfaScope.launch {
|
||||
val lines = try {
|
||||
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>()
|
||||
sharedScreenModel.setParsing(true)
|
||||
try {
|
||||
withContext(Dispatchers.Main) {
|
||||
sharedScreenModel.updateFullTUOList(emptyList())
|
||||
val lines = try {
|
||||
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)
|
||||
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)
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,7 +232,8 @@ fun MainScreenWithDrawer(
|
|||
scope.launch { drawerState.close() }
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(drawerState = drawerState, drawerContent = {
|
||||
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
||||
ModalNavigationDrawer(drawerState = drawerState, gesturesEnabled = playlistActive == null, drawerContent = {
|
||||
SimpleDrawerContent(
|
||||
items,
|
||||
solfaScreenModel,
|
||||
|
|
|
|||
|
|
@ -214,6 +214,7 @@ fun SimpleDrawerContent(
|
|||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
sharedScreenModel.reset()
|
||||
sharedScreenModel.setPlaylistActive(null)
|
||||
solfaScreenModel.loadFromFile(item.path)
|
||||
onSongSelected(midi)
|
||||
},
|
||||
|
|
@ -269,6 +270,7 @@ fun SimpleDrawerContent(
|
|||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
sharedScreenModel.reset()
|
||||
sharedScreenModel.setPlaylistActive(null)
|
||||
solfaScreenModel.loadFromFile(item.path)
|
||||
onSongSelected(midi)
|
||||
},
|
||||
|
|
@ -404,6 +406,7 @@ fun SimpleDrawerContent(
|
|||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
sharedScreenModel.reset()
|
||||
sharedScreenModel.setPlaylistActive(null)
|
||||
solfaScreenModel.loadFromFile(item.path)
|
||||
onSongSelected(midi)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -783,15 +783,19 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
val activeFilePath: State<String> = _activeFilePath
|
||||
|
||||
fun setFileContent(content: String?, path: String) {
|
||||
val isNewSong = !samePath(_activeFilePathFlow.value, path)
|
||||
_fileContent.value = content
|
||||
_activeFilePath.value = path
|
||||
_activeFilePathFlow.value = path
|
||||
|
||||
val active = _activePlaylist.value
|
||||
val entry = active.find { samePath(it.path, path) }
|
||||
if (isNewSong) {
|
||||
_nbStanzas.value = 0
|
||||
}
|
||||
if (entry != null && entry.stanzas.isNotEmpty()) {
|
||||
_stanza.value = entry.stanzas.sorted().first()
|
||||
} else if (_stanza.value == 0) {
|
||||
} else if (isNewSong || _stanza.value <= 0) {
|
||||
_stanza.value = 1
|
||||
}
|
||||
|
||||
|
|
@ -1287,6 +1291,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
_showSearchMenu.value = false
|
||||
_sourceModeState.value = false
|
||||
_harmonyView.value = false
|
||||
_stanza.value = 0
|
||||
setTranspositionInterval(0)
|
||||
setTranspToC(0)
|
||||
setSilentDurBefr(0)
|
||||
|
|
@ -1321,6 +1326,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
|||
_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) {
|
||||
try {
|
||||
_stanza.value = theStanza
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue