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
|
isLandscapeMode: Boolean
|
||||||
) {
|
) {
|
||||||
val appliedInterval by sharedScreenModel.transpositionInterval.collectAsState()
|
val appliedInterval by sharedScreenModel.transpositionInterval.collectAsState()
|
||||||
|
var displayInterval by remember(fileContent) { mutableStateOf(appliedInterval) }
|
||||||
var tempInterval by remember(fileContent, appliedInterval) { mutableStateOf(appliedInterval) }
|
var tempInterval by remember(fileContent, appliedInterval) { mutableStateOf(appliedInterval) }
|
||||||
|
var transposedFromKey by remember(fileContent) { mutableStateOf<String?>(null) }
|
||||||
var isEyeVisible by remember { mutableStateOf(false) }
|
var isEyeVisible by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val isMinor = songKey.endsWith("m", ignoreCase = true)
|
val isMinor = songKey.endsWith("m", ignoreCase = true)
|
||||||
val cleanSongKey = if (isMinor) songKey.dropLast(1) else songKey
|
val cleanSongKey = if (isMinor) songKey.dropLast(1) else songKey
|
||||||
val keysOrder = Transpose.keyToNumber
|
val keysOrder = Transpose.keyToNumber
|
||||||
val songKeyIndex = keysOrder.indexOf(cleanSongKey).takeIf { it != -1 } ?: 0
|
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 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 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(
|
Box(
|
||||||
modifier = if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.padding(end = 16.dp),
|
modifier = if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.padding(end = 16.dp),
|
||||||
contentAlignment = if (isLandscapeMode) Alignment.Center else Alignment.TopCenter
|
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(
|
||||||
text = formattedKey,
|
text = formattedKey,
|
||||||
style = if (isLandscapeMode) MaterialTheme.typography.titleMedium else MaterialTheme.typography.displaySmall,
|
style = if (isLandscapeMode) MaterialTheme.typography.titleMedium else MaterialTheme.typography.displaySmall,
|
||||||
fontWeight = FontWeight.Black,
|
fontWeight = FontWeight.Black,
|
||||||
textAlign = TextAlign.Center,
|
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
|
modifier = Modifier
|
||||||
.clickable(interactionSource = sharedInteractionSource, indication = null) { isEyeVisible = !isEyeVisible }
|
.clickable(interactionSource = sharedInteractionSource, indication = null) { isEyeVisible = !isEyeVisible }
|
||||||
.then(if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.width(65.dp))
|
.then(if (isLandscapeMode) Modifier.padding(vertical = 4.dp) else Modifier.width(65.dp))
|
||||||
|
|
@ -1157,79 +1178,109 @@ private fun TranspositionDropdown(
|
||||||
expanded = isEyeVisible,
|
expanded = isEyeVisible,
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
tempInterval = appliedInterval
|
tempInterval = appliedInterval
|
||||||
|
if (!isTransposedToC) {
|
||||||
|
displayInterval = appliedInterval
|
||||||
|
}
|
||||||
isEyeVisible = false
|
isEyeVisible = false
|
||||||
},
|
},
|
||||||
containerColor = Color(0xFF2C3135).copy(alpha = 0.75f),
|
containerColor = Color(0xFF2C3135).copy(alpha = 0.75f),
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
modifier = Modifier.padding(12.dp)
|
modifier = Modifier.padding(12.dp)
|
||||||
) {
|
) {
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(
|
||||||
val isOriginalKeyC = cleanSongKey.equals("C", ignoreCase = true)
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
val isTransposedToC = tempUiKey.equals("C", ignoreCase = true) && !isOriginalKeyC
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceEvenly, modifier = Modifier.padding(horizontal = 4.dp)) {
|
) {
|
||||||
val currentIndex = keysOrder.indexOf(tempUiKey).takeIf { it != -1 } ?: 0
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
IconButton(modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp), onClick = { tempInterval-- }) {
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
Icon(imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft, contentDescription = "Transposer de moins", tint = Color.White)
|
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
|
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(
|
IconButton(
|
||||||
modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp),
|
modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (isPendingChange) {
|
if (isTransposedToC) {
|
||||||
sharedScreenModel.setTranspositionInterval(tempInterval)
|
transposedFromKey = null
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
isEyeVisible = false
|
displayInterval++
|
||||||
|
tempInterval = displayInterval
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Icon(imageVector = centralIcon, contentDescription = "Transposer", tint = centralTint)
|
Icon(
|
||||||
}
|
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = "Transposer de plus",
|
||||||
IconButton(modifier = Modifier.size(if (isLandscapeMode) 32.dp else 36.dp), onClick = { tempInterval++ }) {
|
tint = Color.White
|
||||||
Icon(imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight, contentDescription = "Transposer de plus", tint = Color.White)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val cIndex = keysOrder.indexOf("C")
|
val buttonText = if (isTransposedToC) "Revenir en $songKey" else "Transposer en $targetCKey"
|
||||||
val intervalToC = if (cIndex != -1) cIndex - songKeyIndex else 0
|
|
||||||
val buttonText = if (isTransposedToC) "Revenir en $songKey" else "Transposer en C"
|
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (isTransposedToC) {
|
if (isTransposedToC) {
|
||||||
|
transposedFromKey = null
|
||||||
|
displayInterval = 0
|
||||||
tempInterval = 0
|
tempInterval = 0
|
||||||
sharedScreenModel.setTranspositionInterval(0)
|
sharedScreenModel.setTranspositionInterval(0)
|
||||||
sharedScreenModel.setTranspToC(0)
|
sharedScreenModel.setTranspToC(0)
|
||||||
sharedScreenModel.stopMidi()
|
sharedScreenModel.stopMidi()
|
||||||
sharedScreenModel.seekTo(0f)
|
sharedScreenModel.seekTo(0f)
|
||||||
} else {
|
} else {
|
||||||
val currentKey = sharedScreenModel.songKey.value
|
val intervalFromUiToC = getIntervalToC(tempUiKey)
|
||||||
val intervalC = getIntervalToC(currentKey)
|
|
||||||
|
|
||||||
tempInterval = -intervalC
|
transposedFromKey = songKey
|
||||||
sharedScreenModel.setTranspToC(intervalC)
|
sharedScreenModel.setTranspositionInterval(intervalFromUiToC)
|
||||||
|
sharedScreenModel.setTranspToC(intervalFromUiToC)
|
||||||
sharedScreenModel.stopMidi()
|
sharedScreenModel.stopMidi()
|
||||||
sharedScreenModel.seekTo(0f)
|
sharedScreenModel.seekTo(0f)
|
||||||
}
|
}
|
||||||
isEyeVisible = false
|
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),
|
shape = RoundedCornerShape(8.dp),
|
||||||
border = BorderStroke(1.dp, MaterialTheme.colorScheme.tertiary.copy(alpha = 0.5f)),
|
border = BorderStroke(1.dp, MaterialTheme.colorScheme.tertiary.copy(alpha = 0.5f)),
|
||||||
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.tertiary)
|
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