Fix C transposition display and transpose visual for all keys & remove audio transposition
This commit is contained in:
parent
a1c816e603
commit
5c73b79809
1 changed files with 91 additions and 40 deletions
|
|
@ -1124,29 +1124,50 @@ private fun TranspositionDropdown(
|
|||
isLandscapeMode: Boolean
|
||||
) {
|
||||
val appliedInterval by sharedScreenModel.transpositionInterval.collectAsState()
|
||||
var displayInterval by remember(fileContent) { mutableStateOf(appliedInterval) }
|
||||
var tempInterval by remember(fileContent, appliedInterval) { mutableStateOf(appliedInterval) }
|
||||
var transposedFromKey by remember(fileContent) { mutableStateOf<String?>(null) }
|
||||
var isEyeVisible by remember { mutableStateOf(false) }
|
||||
|
||||
val isMinor = songKey.endsWith("m", ignoreCase = true)
|
||||
val cleanSongKey = if (isMinor) songKey.dropLast(1) else songKey
|
||||
val keysOrder = Transpose.keyToNumber
|
||||
val songKeyIndex = keysOrder.indexOf(cleanSongKey).takeIf { it != -1 } ?: 0
|
||||
val rawKeyIndex = (songKeyIndex + tempInterval) % 12
|
||||
|
||||
val rawKeyIndex = (songKeyIndex + displayInterval) % 12
|
||||
val tempUiKey = keysOrder[if (rawKeyIndex < 0) rawKeyIndex + 12 else rawKeyIndex]
|
||||
val isPendingChange = tempInterval != appliedInterval
|
||||
val isCurrentlyTransposed = appliedInterval != 0
|
||||
val formattedKey = if (isMinor) "${tempUiKey}m" else tempUiKey
|
||||
|
||||
val targetCKey = if (isMinor) "Cm" else "C"
|
||||
val isTransposedToC = transposedFromKey != null && appliedInterval != 0
|
||||
val isPendingChange = tempInterval != appliedInterval && !isTransposedToC
|
||||
val isCurrentlyTransposed = appliedInterval != 0
|
||||
|
||||
LaunchedEffect(appliedInterval) {
|
||||
if (appliedInterval == 0) {
|
||||
transposedFromKey = null
|
||||
displayInterval = 0
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.padding(end = 16.dp),
|
||||
contentAlignment = if (isLandscapeMode) Alignment.Center else Alignment.TopCenter
|
||||
) {
|
||||
Row(modifier = if (isLandscapeMode) Modifier.wrapContentSize() else Modifier.fillMaxHeight(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(
|
||||
modifier = if (isLandscapeMode) Modifier.wrapContentSize() else Modifier.fillMaxHeight(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = formattedKey,
|
||||
style = if (isLandscapeMode) MaterialTheme.typography.titleMedium else MaterialTheme.typography.displaySmall,
|
||||
fontWeight = FontWeight.Black,
|
||||
textAlign = TextAlign.Center,
|
||||
color = if (isCurrentlyTransposed || isPendingChange) MaterialTheme.colorScheme.tertiary else Color.White,
|
||||
color = if (isCurrentlyTransposed || isPendingChange || isTransposedToC) {
|
||||
MaterialTheme.colorScheme.tertiary
|
||||
} else {
|
||||
Color.White
|
||||
},
|
||||
modifier = Modifier
|
||||
.clickable(interactionSource = sharedInteractionSource, indication = null) { isEyeVisible = !isEyeVisible }
|
||||
.then(if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.width(65.dp))
|
||||
|
|
@ -1157,79 +1178,109 @@ private fun TranspositionDropdown(
|
|||
expanded = isEyeVisible,
|
||||
onDismissRequest = {
|
||||
tempInterval = appliedInterval
|
||||
if (!isTransposedToC) {
|
||||
displayInterval = appliedInterval
|
||||
}
|
||||
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)) {
|
||||
val isOriginalKeyC = cleanSongKey.equals("C", ignoreCase = true)
|
||||
val isTransposedToC = tempUiKey.equals("C", ignoreCase = true) && !isOriginalKeyC
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceEvenly, modifier = Modifier.padding(horizontal = 4.dp)) {
|
||||
val currentIndex = keysOrder.indexOf(tempUiKey).takeIf { it != -1 } ?: 0
|
||||
|
||||
IconButton(modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp), onClick = { tempInterval-- }) {
|
||||
Icon(imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft, contentDescription = "Transposer de moins", tint = Color.White)
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||
modifier = Modifier.padding(horizontal = 4.dp)
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp),
|
||||
onClick = {
|
||||
if (isTransposedToC) {
|
||||
transposedFromKey = null
|
||||
}
|
||||
displayInterval--
|
||||
tempInterval = displayInterval
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft,
|
||||
contentDescription = "Transposer de moins",
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
|
||||
val centralIcon = if (isPendingChange && !isTransposedToC) Icons.Filled.Check else Icons.Filled.SwapHoriz
|
||||
val centralIcon = if (isPendingChange) Icons.Filled.Check else Icons.Filled.SwapHoriz
|
||||
val centralTint = if (isPendingChange) MaterialTheme.colorScheme.tertiary else Color.White
|
||||
|
||||
Box(
|
||||
modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = centralIcon,
|
||||
contentDescription = "Transposer",
|
||||
tint = centralTint,
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
IconButton(
|
||||
modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp),
|
||||
onClick = {
|
||||
if (isPendingChange) {
|
||||
sharedScreenModel.setTranspositionInterval(tempInterval)
|
||||
sharedScreenModel.stopMidi()
|
||||
sharedScreenModel.seekTo(0f)
|
||||
solfaScreenModel.loadFromFile(sharedScreenModel.activeFilePath.value)
|
||||
} else if (isCurrentlyTransposed) {
|
||||
tempInterval = 0
|
||||
sharedScreenModel.setTranspositionInterval(0)
|
||||
sharedScreenModel.stopMidi()
|
||||
sharedScreenModel.seekTo(0f)
|
||||
solfaScreenModel.loadFromFile(sharedScreenModel.activeFilePath.value)
|
||||
if (isTransposedToC) {
|
||||
transposedFromKey = null
|
||||
}
|
||||
isEyeVisible = false
|
||||
displayInterval++
|
||||
tempInterval = displayInterval
|
||||
}
|
||||
) {
|
||||
Icon(imageVector = centralIcon, contentDescription = "Transposer", tint = centralTint)
|
||||
}
|
||||
|
||||
IconButton(modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp), onClick = { tempInterval++ }) {
|
||||
Icon(imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight, contentDescription = "Transposer de plus", tint = Color.White)
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||
contentDescription = "Transposer de plus",
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val cIndex = keysOrder.indexOf("C")
|
||||
val intervalToC = if (cIndex != -1) cIndex - songKeyIndex else 0
|
||||
val buttonText = if (isTransposedToC) "Revenir en $songKey" else "Transposer en C"
|
||||
val buttonText = if (isTransposedToC) "Revenir en $songKey" else "Transposer en $targetCKey"
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
if (isTransposedToC) {
|
||||
transposedFromKey = null
|
||||
displayInterval = 0
|
||||
tempInterval = 0
|
||||
sharedScreenModel.setTranspositionInterval(0)
|
||||
sharedScreenModel.setTranspToC(0)
|
||||
sharedScreenModel.stopMidi()
|
||||
sharedScreenModel.seekTo(0f)
|
||||
} else {
|
||||
val currentKey = sharedScreenModel.songKey.value
|
||||
val intervalC = getIntervalToC(currentKey)
|
||||
val intervalFromUiToC = getIntervalToC(tempUiKey)
|
||||
|
||||
tempInterval = -intervalC
|
||||
sharedScreenModel.setTranspToC(intervalC)
|
||||
transposedFromKey = songKey
|
||||
sharedScreenModel.setTranspositionInterval(intervalFromUiToC)
|
||||
sharedScreenModel.setTranspToC(intervalFromUiToC)
|
||||
sharedScreenModel.stopMidi()
|
||||
sharedScreenModel.seekTo(0f)
|
||||
}
|
||||
isEyeVisible = false
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().height(if (isLandscapeMode) 32.dp else 36.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(if (isLandscapeMode) 32.dp else 36.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
border = BorderStroke(1.dp, MaterialTheme.colorScheme.tertiary.copy(alpha = 0.5f)),
|
||||
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.tertiary)
|
||||
) {
|
||||
Text(text = buttonText, fontSize = if (isLandscapeMode) 10.sp else 12.sp, fontWeight = FontWeight.Bold)
|
||||
Text(
|
||||
text = buttonText,
|
||||
fontSize = if (isLandscapeMode) 10.sp else 12.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue