Fix! A-B looping ux
This commit is contained in:
parent
1d7273a531
commit
e2db1c2f20
2 changed files with 38 additions and 19 deletions
|
|
@ -909,20 +909,24 @@ fun LazyVerticalGridTUO(
|
||||||
selectedIndex = globalIndex
|
selectedIndex = globalIndex
|
||||||
showEditDialog = true
|
showEditDialog = true
|
||||||
} else {
|
} else {
|
||||||
|
val enableSmartP = prefs.getBoolean("smartBpoint", true)
|
||||||
when (abModeState) {
|
when (abModeState) {
|
||||||
ABModeState.WAITING_FOR_A -> {
|
ABModeState.WAITING_FOR_A -> {
|
||||||
sharedScreenModel.mediaPlayer?.setPointA(globalIndex)
|
val smartIndexA = if (enableSmartP) {
|
||||||
sharedScreenModel.setABModeState(ABModeState.WAITING_FOR_B)
|
sharedScreenModel.calculateSmartPointA(globalIndex)
|
||||||
}
|
|
||||||
ABModeState.WAITING_FOR_B -> {
|
|
||||||
val enableSmartB = prefs.getBoolean("smartBpoint", true)
|
|
||||||
val smartIndex = if (enableSmartB) {
|
|
||||||
sharedScreenModel.calculateSmartPointB(globalIndex, isZeroIndexed = true)
|
|
||||||
} else {
|
} else {
|
||||||
globalIndex
|
globalIndex
|
||||||
}
|
}
|
||||||
sharedScreenModel.mediaPlayer?.setPointB(smartIndex)
|
sharedScreenModel.mediaPlayer?.setPointA(smartIndexA)
|
||||||
|
sharedScreenModel.setABModeState(ABModeState.WAITING_FOR_B)
|
||||||
|
}
|
||||||
|
ABModeState.WAITING_FOR_B -> {
|
||||||
|
val smartIndexB = if (enableSmartP) {
|
||||||
|
sharedScreenModel.calculateSmartPointB(globalIndex)
|
||||||
|
} else {
|
||||||
|
globalIndex
|
||||||
|
}
|
||||||
|
sharedScreenModel.mediaPlayer?.setPointB(smartIndexB)
|
||||||
sharedScreenModel.setABModeState(ABModeState.LOOP_ACTIVE)
|
sharedScreenModel.setABModeState(ABModeState.LOOP_ACTIVE)
|
||||||
}
|
}
|
||||||
ABModeState.IDLE, ABModeState.LOOP_ACTIVE -> {
|
ABModeState.IDLE, ABModeState.LOOP_ACTIVE -> {
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,8 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
fun setABModeState(state: ABModeState) {
|
fun setABModeState(state: ABModeState) {
|
||||||
_abModeState.value = state
|
_abModeState.value = state
|
||||||
}
|
}
|
||||||
fun calculateSmartPointB(rawPointB: Int, isZeroIndexed: Boolean = false): Int {
|
|
||||||
|
fun calculateSmartPointA(rawPointA: Int): Int {
|
||||||
val currentMeasure = _measure.value
|
val currentMeasure = _measure.value
|
||||||
val numerator = currentMeasure.substringBefore("/").toIntOrNull() ?: 4
|
val numerator = currentMeasure.substringBefore("/").toIntOrNull() ?: 4
|
||||||
|
|
||||||
|
|
@ -492,18 +493,31 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
else -> 2
|
else -> 2
|
||||||
}
|
}
|
||||||
|
|
||||||
val remainder = rawPointB % multiple
|
val remainder = rawPointA % multiple
|
||||||
var finalPointB = if (remainder == 0) {
|
return rawPointA - remainder
|
||||||
rawPointB
|
|
||||||
} else {
|
|
||||||
rawPointB + (multiple - remainder)
|
|
||||||
}
|
|
||||||
if (isZeroIndexed) {
|
|
||||||
finalPointB -= 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalPointB
|
fun calculateSmartPointB(rawPointB: Int): Int {
|
||||||
|
val currentMeasure = _measure.value
|
||||||
|
val numerator = currentMeasure.substringBefore("/").toIntOrNull() ?: 4
|
||||||
|
|
||||||
|
val multiple = when (numerator) {
|
||||||
|
2, 4, 8, 10 -> 4
|
||||||
|
3, 6, 9, 12 -> 3
|
||||||
|
else -> 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val offset = rawPointB % multiple
|
||||||
|
val distToPrev = offset + 1
|
||||||
|
val distToCurr = multiple - 1 - offset
|
||||||
|
|
||||||
|
return if (distToPrev <= distToCurr) {
|
||||||
|
(rawPointB - offset - 1).coerceAtLeast(0)
|
||||||
|
} else {
|
||||||
|
rawPointB + (multiple - 1 - offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val _gridCount = MutableStateFlow(0)
|
private val _gridCount = MutableStateFlow(0)
|
||||||
val gridCount: StateFlow<Int> = _gridCount.asStateFlow()
|
val gridCount: StateFlow<Int> = _gridCount.asStateFlow()
|
||||||
|
|
||||||
|
|
@ -823,6 +837,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
setTranspToC(0)
|
setTranspToC(0)
|
||||||
setSilentDurBefr(0)
|
setSilentDurBefr(0)
|
||||||
updateLoopingState(0, 0)
|
updateLoopingState(0, 0)
|
||||||
|
_abModeState.value = ABModeState.IDLE
|
||||||
_midiMarkersList.value = emptyList()
|
_midiMarkersList.value = emptyList()
|
||||||
_tuoTimestamps.value = emptyList()
|
_tuoTimestamps.value = emptyList()
|
||||||
_searchTitle.value = ""
|
_searchTitle.value = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue