Add "k" metadata for optimum column count on source; |k:16

This commit is contained in:
Hasinjato 2026-09-28 16:01:35 +03:00
parent cc71d4c340
commit 544e393b22
3 changed files with 60 additions and 20 deletions

View file

@ -2050,6 +2050,7 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
sharedScreenModel.setSongComposer(meta["h"] ?: "")
sharedScreenModel.setSongRhythm(meta["r"] ?: "")
sharedScreenModel.setBpmFlow(meta["p"]?.toFloat() ?: 120.0f)
sharedScreenModel.setOptimColGrid(meta["k"]?.toIntOrNull() ?: 0)
}
private fun loadN(voiceNumber: Int, line: String, templateComments: MutableList<String>) {

View file

@ -662,32 +662,61 @@ fun LazyVerticalGridTUO(
noteStyle = MaterialTheme.typography.bodyLarge
)
val itemMinBaseWidth = tuoWidthMeasure.width
val optimColGrid by sharedScreenModel.getOptimColGrid().collectAsState()
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
val isLayoutReady = tuoWidthMeasure.isReady && gridWidthDp > 0.dp
LaunchedEffect(gridWidthPx) {
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()
var baseGridColumnCount: Int = remember(gridWidthDp, tuoWidthMeasure.isReady, tuoWidthMeasure.width, multiple) {
val baseGridColumnCount: Int = remember(
gridWidthDp,
tuoWidthMeasure.isReady,
tuoWidthMeasure.width,
multiple,
optimColGrid,
hasResized
) {
if (optimColGrid > 0 && !hasResized) {
optimColGrid
} else {
if (!tuoWidthMeasure.isReady || gridWidthDp <= 0.dp || tuoWidthMeasure.width <= 0.dp) {
return@remember multiple
}
multiple
} else {
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
// 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 gridColumnCount = (baseGridColumnCount + gridCount).coerceAtLeast(multiple)

View file

@ -78,6 +78,16 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
fun getBpmFlow(): StateFlow<Float> {
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
.map { list -> list.filter { it.path.startsWith("assets://") } }
.stateIn(screenModelScope, SharingStarted.Lazily, emptyList())