Add Transpose to C btn on key tools

This commit is contained in:
Hasinjato 2026-06-10 15:00:25 +03:00
parent 93797089d8
commit 89d0b850f8
2 changed files with 130 additions and 90 deletions

View file

@ -63,11 +63,8 @@ class Transpose {
val totalAlter = interval + currentModulationInterval val totalAlter = interval + currentModulationInterval
val transposedBody = NOTE_UNIT_REGEX.replace(remaining) { matchResult -> val transposedBody = NOTE_UNIT_REGEX.replace(remaining) { matchResult ->
val noteCore = matchResult.groupValues[1] val fullNote = matchResult.value
val octave = matchResult.groupValues[2] transpose(note = fullNote, fromKey = "C", toKey = "C", alter = totalAlter)
val transposedCore = transpose(note = noteCore, fromKey = "C", toKey = "C", alter = totalAlter)
transposedCore + octave
} }
val result = separators + transposedBody val result = separators + transposedBody

View file

@ -2,7 +2,6 @@ package mg.dot.feufaro.ui
import SharedScreenModel import SharedScreenModel
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.* import androidx.compose.foundation.*
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -107,6 +106,11 @@ fun MainScreenWithDrawer(
} }
} }
val isEditMode by sharedScreenModel.modeEditor.collectAsState() val isEditMode by sharedScreenModel.modeEditor.collectAsState()
LaunchedEffect(isEditMode) {
if(isEditMode) {
drawerState.close()
}
}
val currentActiveFilePath = sharedScreenModel.activeFilePath.value val currentActiveFilePath = sharedScreenModel.activeFilePath.value
val fileName = currentActiveFilePath.substringAfterLast('/') val fileName = currentActiveFilePath.substringAfterLast('/')
@ -238,24 +242,49 @@ fun MainScreenWithDrawer(
val isPendingChange = tempInterval != appliedInterval val isPendingChange = tempInterval != appliedInterval
val isCurrentlyTransposed = appliedInterval != 0 val isCurrentlyTransposed = appliedInterval != 0
Box(
modifier = Modifier.padding(end = 16.dp),
contentAlignment = Alignment.TopEnd
) {
Row( Row(
modifier = Modifier.fillMaxHeight(), modifier = Modifier.fillMaxHeight(),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
AnimatedVisibility( Text(
visible = isEyeVisible, text = tempUiKey,
enter = expandHorizontally(expandFrom = Alignment.End) + fadeIn(tween(300)), fontSize = 25.sp,
exit = shrinkHorizontally(shrinkTowards = Alignment.End) + fadeOut(tween(300)) fontWeight = FontWeight.Black,
textAlign = TextAlign.Center,
color = if (isCurrentlyTransposed && !isPendingChange) Color(0xFFFFD700) else Color.White,
modifier = Modifier
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) { ) {
isEyeVisible = !isEyeVisible
}
.width(45.dp)
)
}
DropdownMenu(
expanded = isEyeVisible,
onDismissRequest = { isEyeVisible = false },
containerColor = Color(0xFF2C3135).copy(alpha = 0.75f),
shape = RoundedCornerShape(16.dp),
modifier = Modifier.padding(12.dp)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
/* < = > */
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly, horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier modifier = Modifier.padding(horizontal = 4.dp)
.padding(end = 8.dp)
.background(Color.White.copy(alpha = 0.15f), RoundedCornerShape(50))
.padding(horizontal = 4.dp)
) { ) {
/* <*/ /* < */
val currentIndex = keysOrder.indexOf(tempUiKey).takeIf { it != -1 } ?: 0 val currentIndex = keysOrder.indexOf(tempUiKey).takeIf { it != -1 } ?: 0
val targetKeyLeft = keysOrder[(currentIndex - 1 + 12) % 12] val targetKeyLeft = keysOrder[(currentIndex - 1 + 12) % 12]
@ -278,7 +307,7 @@ fun MainScreenWithDrawer(
val centralIcon = if (isPendingChange) Icons.Filled.Check else Icons.Filled.SwapHoriz val centralIcon = if (isPendingChange) Icons.Filled.Check else Icons.Filled.SwapHoriz
val centralTint = if (isPendingChange) Color(0xFFFFD700) else Color.White val centralTint = if (isPendingChange) Color(0xFFFFD700) else Color.White
val tooltipText = if (isPendingChange) "Transposer en $tempUiKey" else if (isCurrentlyTransposed) "Revenir au ($songKey)" else "Transposer" val tooltipText = if (isPendingChange) "Transposer en $tempUiKey" else if (isCurrentlyTransposed) "Revenir en $songKey" else "Transposer"
TooltipBox( TooltipBox(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
@ -327,25 +356,39 @@ fun MainScreenWithDrawer(
} }
} }
} }
}
Text( val cIndex = keysOrder.indexOf("C")
text = tempUiKey, val intervalToC = if (cIndex != -1) cIndex - songKeyIndex else 0
fontSize = 25.sp,
fontWeight = FontWeight.Black, TooltipBox(
textAlign = TextAlign.Center, positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
color = if (isCurrentlyTransposed && !isPendingChange) Color(0xFFFFD700) else Color.White, tooltip = {
modifier = Modifier PlainTooltip(containerColor = Color.DarkGray, contentColor = Color.White) { Text(text = "Transposer en Do (C)", fontSize = 12.sp) }
.clickable( },
interactionSource = remember { MutableInteractionSource() }, state = rememberTooltipState()
indication = null
) { ) {
isEyeVisible = !isEyeVisible OutlinedButton(
} onClick = {
.padding(end = 16.dp) tempInterval = intervalToC
.width(45.dp) sharedScreenModel.setTranspositionInterval(intervalToC)
solfaScreenModel.loadFromFile(sharedScreenModel.activeFilePath.value)
isEyeVisible = false
},
modifier = Modifier.fillMaxWidth().height(36.dp),
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, Color(0xFFFFD700).copy(alpha = 0.5f)),
colors = ButtonDefaults.outlinedButtonColors(contentColor = Color(0xFFFFD700))
) {
Text(
text = "Transposer en C",
fontSize = 12.sp,
fontWeight = FontWeight.Bold
) )
} }
}
}
}
}
}, colors = TopAppBarColors( }, colors = TopAppBarColors(
containerColor = MaterialTheme.colorScheme.primary, containerColor = MaterialTheme.colorScheme.primary,
titleContentColor = MaterialTheme.colorScheme.onPrimary, titleContentColor = MaterialTheme.colorScheme.onPrimary,