Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key action support in multi-edit mode #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ enum class KeyAction(
KeySet(Key.P),
false,
),
SetCurrentEntryLeft(listOf(Strings.ActionSetCurrentEntryLeft), null, false),
SetCurrentEntryRight(listOf(Strings.ActionSetCurrentEntryRight), null, false),
SetProperty1(listOf(Strings.ActionSetProperty1), null, false),
SetProperty2(listOf(Strings.ActionSetProperty2), null, false),
SetProperty3(listOf(Strings.ActionSetProperty3), null, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MarkerState(
val canvasHeightState: MutableState<Float>,
val waveformsHeightRatio: Float,
private val snapDrag: SnapDrag,
val currentIndex: MutableState<Int>,
) {
val entryBorders: List<Float> = entriesInPixel.fold<EntryInPixel, List<Float>>(listOf()) { acc, entryInPixel ->
val lastEntryEnd = acc.lastOrNull()
Expand Down Expand Up @@ -415,6 +416,15 @@ class MarkerState(
return null
}

fun getEntryIndexByCursorPosition(position: Float): Int? {
entriesInPixel.forEachIndexed { index, entry ->
if (entry.getActualStart(labelerConf) <= position && entry.getActualEnd(labelerConf) >= position) {
return index
}
}
return null
}

fun isValidCutPosition(position: Float) = entriesInPixel.any { it.isValidCutPosition(position) }

fun isValidPlaybackPosition(position: Float) = position < entryConverter.convertToPixel(sampleLengthMillis)
Expand Down Expand Up @@ -448,21 +458,41 @@ class MarkerState(
KeyAction.SetValue8 -> 7
KeyAction.SetValue9 -> 8
KeyAction.SetValue10 -> 9
KeyAction.SetCurrentEntryLeft -> 0
KeyAction.SetCurrentEntryRight -> 1
else -> return null
}

// Only used in single edit mode
if (entries.size != 1) return null

val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size
val pointIndex = when {
paramIndex == 0 -> MarkerCursorState.START_POINT_INDEX
paramIndex == fieldCount + 1 -> MarkerCursorState.END_POINT_INDEX
paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex }
.takeIf { it >= 0 } ?: return null
else -> return null
}
val pointIndex: Int?
val cursorPosition = cursorState.value.position ?: return null
if (entries.size != 1) {
// filedCount might be wrong
// and would not work on potential variant fields like dv label
val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size
val index = if (action == KeyAction.SetCurrentEntryLeft || action == KeyAction.SetCurrentEntryRight) {
currentIndex.value
} else {
getEntryIndexByCursorPosition(cursorPosition) ?: return null
}
pointIndex = when {
paramIndex == 0 -> if (index == 0) MarkerCursorState.START_POINT_INDEX else index * (fieldCount + 1) - 1
paramIndex == fieldCount + 1 ->
if (index == entries.size - 1) MarkerCursorState.END_POINT_INDEX else index * (fieldCount + 1)
paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex }
.takeIf { it > 0 }?.plus(index * (fieldCount + 1)) ?: return null
else -> return null
}
} else {
val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size
pointIndex = when {
paramIndex == 0 -> MarkerCursorState.START_POINT_INDEX
paramIndex == fieldCount + 1 -> MarkerCursorState.END_POINT_INDEX
paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex }
.takeIf { it >= 0 } ?: return null
else -> return null
}
}

val lockDrag = appConf.editor.lockedSettingParameterWithCursor &&
when (appConf.editor.lockedDrag) {
AppConf.Editor.LockedDrag.UseLabeler -> {
Expand Down Expand Up @@ -571,6 +601,7 @@ fun rememberMarkerState(
entryConverter,
)
}
val currentIndex = mutableStateOf(project.currentModule.currentIndex)

return remember(
sampleRate,
Expand Down Expand Up @@ -608,6 +639,7 @@ fun rememberMarkerState(
canvasHeightState,
waveformsHeightRatio,
snapDrag,
currentIndex
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ enum class Strings {
ActionSetValue8,
ActionSetValue9,
ActionSetValue10,
ActionSetCurrentEntryLeft,
ActionSetCurrentEntryRight,
ActionSetProperty1,
ActionSetProperty2,
ActionSetProperty3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ fun Strings.zhHans(): String? = when (this) {
ActionInputResolution -> "输入画布分辨率"
ActionCancelDialog -> "关闭对话框"
ActionScissorsCut -> "在当前光标位置切割"
ActionSetValue1 -> "将参数1设置到光标位置"
ActionSetValue2 -> "将参数2设置到光标位置"
ActionSetValue1 -> "将参数1设置到光标位置(多条目编辑模式下为光标位置左边第一条参数)"
ActionSetValue2 -> "将参数2设置到光标位置(多条目编辑模式下为光标位置右边第一条参数)"
ActionSetValue3 -> "将参数3设置到光标位置"
ActionSetValue4 -> "将参数4设置到光标位置"
ActionSetValue5 -> "将参数5设置到光标位置"
Expand All @@ -563,6 +563,8 @@ fun Strings.zhHans(): String? = when (this) {
ActionSetValue8 -> "将参数8设置到光标位置"
ActionSetValue9 -> "将参数9设置到光标位置"
ActionSetValue10 -> "将参数10设置到光标位置"
ActionSetCurrentEntryLeft -> "多条目编辑模式下,将当前条目的左边界设置到光标位置"
ActionSetCurrentEntryRight -> "多条目编辑模式下,将当前条目的右边界设置到光标位置"
ActionSetProperty1 -> "输入属性1的值"
ActionSetProperty2 -> "输入属性2的值"
ActionSetProperty3 -> "输入属性3的值"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ fun Strings.en(): String = when (this) {
ActionInputResolution -> "Input Canvas Resolution"
ActionCancelDialog -> "Close Dialog"
ActionScissorsCut -> "Cut at Current Cursor Position"
ActionSetValue1 -> "Set Parameter 1 To Cursor Position"
ActionSetValue2 -> "Set Parameter 2 To Cursor Position"
ActionSetValue1 -> "Set Parameter 1 To Cursor Position (Start Parameter In Multiple Entry Edit Mode)"
ActionSetValue2 -> "Set Parameter 2 To Cursor Position (End Parameter In Multiple Entry Edit Mode)"
ActionSetValue3 -> "Set Parameter 3 To Cursor Position"
ActionSetValue4 -> "Set Parameter 4 To Cursor Position"
ActionSetValue5 -> "Set Parameter 5 To Cursor Position"
Expand All @@ -628,6 +628,8 @@ fun Strings.en(): String = when (this) {
ActionSetValue8 -> "Set Parameter 8 To Cursor Position"
ActionSetValue9 -> "Set Parameter 9 To Cursor Position"
ActionSetValue10 -> "Set Parameter 10 To Cursor Position"
ActionSetCurrentEntryLeft -> "Set Current Entry Left Parameter To Cursor Position In Multiple Entry Edit Mode"
ActionSetCurrentEntryRight -> "Set Current Entry Right Parameter To Cursor Position In Multiple Entry Edit Mode"
ActionSetProperty1 -> "Input Value for Property 1"
ActionSetProperty2 -> "Input Value for Property 2"
ActionSetProperty3 -> "Input Value for Property 3"
Expand Down
Loading