Add "k" metadata for optimum column count on source; |k:16
This commit is contained in:
parent
cc71d4c340
commit
544e393b22
3 changed files with 60 additions and 20 deletions
|
|
@ -2050,6 +2050,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
sharedScreenModel.setSongComposer(meta["h"] ?: "")
|
sharedScreenModel.setSongComposer(meta["h"] ?: "")
|
||||||
sharedScreenModel.setSongRhythm(meta["r"] ?: "")
|
sharedScreenModel.setSongRhythm(meta["r"] ?: "")
|
||||||
sharedScreenModel.setBpmFlow(meta["p"]?.toFloat() ?: 120.0f)
|
sharedScreenModel.setBpmFlow(meta["p"]?.toFloat() ?: 120.0f)
|
||||||
|
sharedScreenModel.setOptimColGrid(meta["k"]?.toIntOrNull() ?: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadN(voiceNumber: Int, line: String, templateComments: MutableList<String>) {
|
private fun loadN(voiceNumber: Int, line: String, templateComments: MutableList<String>) {
|
||||||
|
|
|
||||||
|
|
@ -662,32 +662,61 @@ fun LazyVerticalGridTUO(
|
||||||
noteStyle = MaterialTheme.typography.bodyLarge
|
noteStyle = MaterialTheme.typography.bodyLarge
|
||||||
)
|
)
|
||||||
val itemMinBaseWidth = tuoWidthMeasure.width
|
val itemMinBaseWidth = tuoWidthMeasure.width
|
||||||
|
val optimColGrid by sharedScreenModel.getOptimColGrid().collectAsState()
|
||||||
val gridWidthDp = with(density) { gridWidthPx.toDp() }
|
val gridWidthDp = with(density) { gridWidthPx.toDp() }
|
||||||
|
var initialWidthPx by remember { mutableStateOf<Int?>(null) }
|
||||||
|
var hasResized by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// on affiche un loader pour éviter le "saut" visuel
|
LaunchedEffect(gridWidthPx) {
|
||||||
val isLayoutReady = tuoWidthMeasure.isReady && gridWidthDp > 0.dp
|
if (gridWidthPx > 0) {
|
||||||
|
if (initialWidthPx == null) {
|
||||||
|
initialWidthPx = gridWidthPx
|
||||||
|
} else if (gridWidthPx != initialWidthPx) {
|
||||||
|
hasResized = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(optimColGrid, tuoList) {
|
||||||
|
hasResized = false
|
||||||
|
initialWidthPx = null
|
||||||
|
}
|
||||||
|
|
||||||
|
val isLayoutReady = if (optimColGrid > 0 && !hasResized) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
tuoWidthMeasure.isReady && gridWidthDp > 0.dp
|
||||||
|
}
|
||||||
|
|
||||||
val gridCount by sharedScreenModel.gridCount.collectAsState()
|
val gridCount by sharedScreenModel.gridCount.collectAsState()
|
||||||
|
|
||||||
var baseGridColumnCount: Int = remember(gridWidthDp, tuoWidthMeasure.isReady, tuoWidthMeasure.width, multiple) {
|
val baseGridColumnCount: Int = remember(
|
||||||
if (!tuoWidthMeasure.isReady || gridWidthDp <= 0.dp || tuoWidthMeasure.width <= 0.dp) {
|
gridWidthDp,
|
||||||
return@remember multiple
|
tuoWidthMeasure.isReady,
|
||||||
|
tuoWidthMeasure.width,
|
||||||
|
multiple,
|
||||||
|
optimColGrid,
|
||||||
|
hasResized
|
||||||
|
) {
|
||||||
|
if (optimColGrid > 0 && !hasResized) {
|
||||||
|
optimColGrid
|
||||||
|
} else {
|
||||||
|
if (!tuoWidthMeasure.isReady || gridWidthDp <= 0.dp || tuoWidthMeasure.width <= 0.dp) {
|
||||||
|
multiple
|
||||||
|
} else {
|
||||||
|
val rawCapacity = (gridWidthDp + 9.dp) / tuoWidthMeasure.width
|
||||||
|
val rawColsInt = rawCapacity.toInt()
|
||||||
|
val roundedToMultiple = (rawColsInt / multiple) * multiple
|
||||||
|
// println("Largeur écran/grille : $gridWidthDp")
|
||||||
|
// println("Largeur bloc TUO max : ${tuoWidthMeasure.width}")
|
||||||
|
// println("Signature temps (multiple) : $multiple")
|
||||||
|
// println("Capacité brute d'accueil : $rawCapacity blocs ($rawColsInt entiers)")
|
||||||
|
// println("Arrondi au multiple inférieur : $roundedToMultiple colonnes")
|
||||||
|
// println("Nombre final retenu (min $multiple) : $finalCols colonnes")
|
||||||
|
// println("=========================")
|
||||||
|
roundedToMultiple.coerceAtLeast(multiple)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val rawCapacity = (gridWidthDp + 9.dp) / tuoWidthMeasure.width
|
|
||||||
val rawColsInt = rawCapacity.toInt()
|
|
||||||
val roundedToMultiple = (rawColsInt / multiple) * multiple
|
|
||||||
val finalCols = roundedToMultiple.coerceAtLeast(multiple)
|
|
||||||
|
|
||||||
// println("Largeur écran/grille : $gridWidthDp")
|
|
||||||
// println("Largeur bloc TUO max : ${tuoWidthMeasure.width}")
|
|
||||||
// println("Signature temps (multiple) : $multiple")
|
|
||||||
// println("Capacité brute d'accueil : $rawCapacity blocs ($rawColsInt entiers)")
|
|
||||||
// println("Arrondi au multiple inférieur : $roundedToMultiple colonnes")
|
|
||||||
// println("Nombre final retenu (min $multiple) : $finalCols colonnes")
|
|
||||||
// println("=========================")
|
|
||||||
|
|
||||||
finalCols
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val gridColumnCount = (baseGridColumnCount + gridCount).coerceAtLeast(multiple)
|
val gridColumnCount = (baseGridColumnCount + gridCount).coerceAtLeast(multiple)
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,16 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
fun getBpmFlow(): StateFlow<Float> {
|
fun getBpmFlow(): StateFlow<Float> {
|
||||||
return currentBpmFlow
|
return currentBpmFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val _optimColGrid = MutableStateFlow(0)
|
||||||
|
val optimColNbGrid: StateFlow<Int> = _optimColGrid.asStateFlow()
|
||||||
|
|
||||||
|
fun setOptimColGrid(nbGrid: Int) {
|
||||||
|
_optimColGrid.value = nbGrid
|
||||||
|
}
|
||||||
|
fun getOptimColGrid(): StateFlow<Int> {
|
||||||
|
return optimColNbGrid
|
||||||
|
}
|
||||||
val internalItems: StateFlow<List<DrawerItem>> = _drawerItems
|
val internalItems: StateFlow<List<DrawerItem>> = _drawerItems
|
||||||
.map { list -> list.filter { it.path.startsWith("assets://") } }
|
.map { list -> list.filter { it.path.startsWith("assets://") } }
|
||||||
.stateIn(screenModelScope, SharingStarted.Lazily, emptyList())
|
.stateIn(screenModelScope, SharingStarted.Lazily, emptyList())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue