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

Fix/1.4.2 #31

Merged
merged 3 commits into from
Jun 24, 2024
Merged
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 @@ -50,8 +50,8 @@ class KeyAction(eventType: EventType<KeyEvent>) : Action<KeyEvent>(eventType) {
/* always valid here if the event is null; it indicates we are triggering the action programmatically, not via an Event */
event ?: return@verify true

namedKeyBinding.matches(event, keysExclusive).also { match ->
if (!match) logger.trace("key did not match bindings")
namedKeyBinding.matches(event, keyTracker(), keysExclusive).also { match ->
if (!match) logger.trace { "key did not match bindings" }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import javafx.beans.property.SimpleObjectProperty
import javafx.scene.input.*
import org.apache.commons.lang.builder.ToStringBuilder
import org.apache.commons.lang.builder.ToStringStyle
import org.janelia.saalfeldlab.fx.event.KeyTracker
import org.janelia.saalfeldlab.fx.extensions.nonnull
import kotlin.collections.set

Expand Down Expand Up @@ -39,9 +40,9 @@ interface NamedKeyBinding {
return codes.toSet()
}

fun matches(event : KeyEvent, keysExclusive: Boolean = true) : Boolean {
fun matches(event : KeyEvent, keyTracker : KeyTracker?, keysExclusive: Boolean = true) : Boolean {
return if (keysExclusive) {
primaryCombinationProperty.get().match(event)
keyTracker?.areOnlyTheseKeysDown(*keyCodes.toTypedArray()) ?: primaryCombination.match(event)
} else {
val codesMatchIfCodeCombo = (primaryCombinationProperty.get() as? KeyCodeCombination)?.code?.let { it == event.code } ?: true
codesMatchIfCodeCombo && event.modifierCodes.containsAll(primaryCombinationProperty.get().modifierCodes)
Expand Down Expand Up @@ -88,10 +89,6 @@ open class NamedKeyCombination(override val keyBindingName: String, primaryCombi
this[keyCombination.keyBindingName] = keyCombination
}

fun matches(name: String, event: KeyEvent, keysExclusive : Boolean = true) : Boolean {
return get(name)!!.matches(event, keysExclusive)
}

operator fun plusAssign(keyCombination: NamedKeyBinding) = addCombination(keyCombination)

operator fun plus(keyCombination: NamedKeyBinding) = this.also { it.plusAssign(keyCombination) }
Expand Down
35 changes: 25 additions & 10 deletions src/main/kotlin/org/janelia/saalfeldlab/fx/midi/MidiActionSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.janelia.saalfeldlab.control.mcu.MCUButtonControl.TOGGLE_ON
import org.janelia.saalfeldlab.fx.actions.Action
import org.janelia.saalfeldlab.fx.actions.ActionSet
import org.janelia.saalfeldlab.fx.event.KeyTracker
import org.janelia.saalfeldlab.fx.util.InvokeOnJavaFXApplicationThread
import java.util.function.IntConsumer
import kotlin.math.absoluteValue

Expand Down Expand Up @@ -139,7 +140,7 @@ class PotentiometerAction(eventType: EventType<MidiPotentiometerEvent>, device:
field = control.max
}

var displayType : DisplayType = (if (absolute) DisplayType.PAN else DisplayType.TRIM).also { control.setDisplayType(it) }
var displayType: DisplayType = (if (absolute) DisplayType.PAN else DisplayType.TRIM).also { control.setDisplayType(it) }

var converter: (Int) -> Number = { it }

Expand All @@ -164,7 +165,7 @@ class PotentiometerAction(eventType: EventType<MidiPotentiometerEvent>, device:
}
}

private var controlValue : Int = let {
private var controlValue: Int = let {
control.setValueSilently(0)
control.display()
control.value
Expand All @@ -188,7 +189,10 @@ class PotentiometerAction(eventType: EventType<MidiPotentiometerEvent>, device:
initializeControlState()
eventFiringListener = IntConsumer {
if (supressEvents) return@IntConsumer
Event.fireEvent(target, MidiPotentiometerEvent(handle, converter(it), eventType))
val value = converter(it)
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiPotentiometerEvent(handle, value, eventType))
}
}
control.addListener(eventFiringListener)
afterRegisterEvent()
Expand Down Expand Up @@ -231,11 +235,17 @@ class ButtonAction(eventType: EventType<MidiButtonEvent>, device: MCUControlPane
if (supressEvents) return@IntConsumer

if (eventType == MidiButtonEvent.BUTTON_PRESSED && it != 0) {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
}
} else if (eventType == MidiButtonEvent.BUTTON_RELEASED && it == 0) {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
}
} else if (eventType == MidiButtonEvent.BUTTON) {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiButtonEvent(handle, it, eventType))
}
}
}
}
Expand Down Expand Up @@ -269,7 +279,9 @@ class ToggleAction(eventType: EventType<MidiToggleEvent>, device: MCUControlPane
initializeControlState()
eventFiringListener = IntConsumer {
if (supressEvents) return@IntConsumer
Event.fireEvent(target, MidiToggleEvent(handle, it, eventType))
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiToggleEvent(handle, it, eventType))
}
}
control.addListener(eventFiringListener)
afterRegisterEvent()
Expand Down Expand Up @@ -300,11 +312,11 @@ class FaderAction(eventType: EventType<MidiFaderEvent>, device: MCUControlPanel,
*/
var max: Number = control.max

val convertToPerecent = { it : Int ->
val convertToPerecent = { it: Int ->
(it.toDouble() - control.min) / (control.max - control.min)
}

val convertToNumber = { it : Int ->
val convertToNumber = { it: Int ->
(min.toDouble() + (max.toDouble() - min.toDouble()) * convertToPerecent(it))
}

Expand Down Expand Up @@ -332,7 +344,10 @@ class FaderAction(eventType: EventType<MidiFaderEvent>, device: MCUControlPanel,
initializeControlState()
eventFiringListener = IntConsumer {
if (supressEvents) return@IntConsumer
Event.fireEvent(target, MidiFaderEvent(handle, converter(it), eventType))
val value = converter(it)
InvokeOnJavaFXApplicationThread {
Event.fireEvent(target, MidiFaderEvent(handle, value, eventType))
}
}
control.addListener(eventFiringListener)
afterRegisterEvent()
Expand Down
Loading