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

Feat/1.1.0 #25

Merged
merged 9 commits into from
Jan 22, 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
100 changes: 100 additions & 0 deletions doc/xtouchmini-mcu-midi-map.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
## input

x90 x28 key 2 x00 off
x01 blink
x7f on
x90 x29 key 3 x00 off
x01 blink
x7f on
x90 x2a key 4 x00 off
x01 blink
x7f on
x90 x2b key 5 x00 off
x01 blink
x7f on
x90 x2c key 6 x00 off
x01 blink
x7f on
x90 x2d key 7 x00 off
x01 blink
x7f on
x90 x54 key 16 x00 off
x01 blink
x7f on
x90 x55 key 17 x00 off
x01 blink
x7f on
x90 x57 key 8 x00 off
x01 blink
x7f on
x90 x58 key 9 x00 off
x01 blink
x7f on
x90 x59 key 0 x00 off
x01 blink
x7f on
x90 x5a key 1 x00 off
x01 blink
x7f on
x90 x5b key 10 x00 off
x01 blink
x7f on
x90 x5c key 11 x00 off
x01 blink
x7f on
x90 x5d key 13 x00 off
x01 blink
x7f on
x90 x5e key 14 x00 off
x01 blink
x7f on
x90 x5f key 15 x00 off
x01 blink
x7f on

xb0 x30--x37 vpot 0--7 x00 off
x01--x0b 0100000000000--0000000000010
x10 off
x11--x15 0111111000000--0000011000000
x17 0000001000000
x17--x1b 0000001100000--0000001111110
x20 off
x21--x2b 0100000000000--0111111111110
x30 off
x31--x36 0000001000000--0111111111110

## output

vpot 0--7 x90 x20--x27 x00 off
x7f on
key 0 x90 x59 x00 off
x7f on
key 1 x90 x5a x00 off
x7f on
key 2--7 x90 x28--x2d x00 off
x7f on
key 8 x90 x57 x00 off
x7f on
key 9 x90 x58 x00 off
x7f on
key 10 x90 x5b x00 off
x7f on
key 11 x90 x5c x00 off
x7f on
key 10 x90 x5b x00 off
x7f on
key 12 x90 x56 x00 off
x7f on
key 13-15 x90 x5d--x5f x00 off
x7f on
key 16 x90 x54 x00 off
x7f on
key 17 x90 x55 x00 off
x7f on

vpot 0--7 xb0 x10--17 x01--x07 up
x41--x47 down

fader xe8 x00 x40--x7f,x00--x3f (-64--63)


2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>saalfx</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>

<name>Saal FX</name>
<description>Saalfeld lab JavaFX tools and extensions</description>
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/org/janelia/saalfeldlab/fx/actions/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ import java.util.function.Consumer
open class Action<E : Event>(val eventType: EventType<E>) {

val logger: Logger by lazy {
LoggerFactory.getLogger(name ?: this.toString())
val simpleName = this::class.simpleName?.let { ".$it" } ?: ""
val name = ".${name ?: "event-${eventType.name}"}"
LoggerFactory.getLogger("saalfx.action$simpleName$name")
}

/**
Expand Down Expand Up @@ -178,7 +180,7 @@ open class Action<E : Event>(val eventType: EventType<E>) {
when {
keysDown!!.isEmpty() && !keysExclusive -> true
keysDown!!.isEmpty() -> noKeysActive().also { if (!it) logger.trace("expected no keys, but some were down") }
keysExclusive -> areOnlyTheseKeysDown(*keysDown!!.toTypedArray()).also { if (!it) logger.trace("expected only these keys: ${keysDown}, but but active keys were: (${getActiveKeyCodes(true)}") }
keysExclusive -> areOnlyTheseKeysDown(*keysDown!!.toTypedArray()).also { if (!it) logger.trace("expected only these keys: ${keysDown}, but active keys were: (${getActiveKeyCodes(true)}") }
else -> areKeysDown(*keysDown!!.toTypedArray()).also { if (!it) logger.trace("expected keys: $keysDown, but some were not down") }
}
} ?: let {
Expand Down Expand Up @@ -303,12 +305,13 @@ open class Action<E : Event>(val eventType: EventType<E>) {
/* isValid(event) will only be true if event is E */
action(event)
} catch (e: Exception) {
logger.debug("Exception caught: ${e.message}")
exceptionHandler?.invoke(e) ?: throw e
}
if (consume) {
event?.consume()
}
logger.trace("$name completed successfully")
logger.debug("completed successfully")
true
} else {
if (!isConsumed) {
Expand Down
116 changes: 62 additions & 54 deletions src/main/kotlin/org/janelia/saalfeldlab/fx/actions/ActionSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
* @return the created and configured [Action]
*/
fun <E : Event> action(eventType: EventType<E>, withAction: Action<E>.() -> Unit = {}): Action<E> {
return Action(eventType)
.also { it.keyTracker = this.keyTracker }
.apply(withAction)
.also { addAction(it) }
return Action(eventType).apply {
keyTracker = [email protected]

/* set the default name */
name = [email protected]

withAction()

}.also { addAction(it) }
}

/**
Expand Down Expand Up @@ -160,10 +165,12 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
*/
@JvmSynthetic
fun keyAction(eventType: EventType<KeyEvent>, withAction: KeyAction.() -> Unit = {}): KeyAction {
return KeyAction(eventType)
.also { it.keyTracker = this.keyTracker }
.apply(withAction)
.also { action -> addAction(action) }
return KeyAction(eventType).apply {
keyTracker = [email protected]
/* set the default name */
name = [email protected]
withAction()
}.also { addAction(it) }
}

/**
Expand All @@ -175,18 +182,19 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
*/
operator fun EventType<KeyEvent>.invoke(withKeys: KeyCodeCombination, withAction: KeyAction.() -> Unit): KeyAction {
/* create the Action*/
val keyAction = KeyAction(this)
.also { it.keyTracker = [email protected] }
return KeyAction(this).apply {
keyTracker = [email protected]

/* configure based on the withKeys paramters*/
keyAction.ignoreKeys()
keyAction.verify { withKeys.match(it) }
/* set the default name */
name = [email protected]

/* configure via the callback*/
keyAction.apply(withAction)
addAction(keyAction)
/* configure based on the withKeys paramters*/
ignoreKeys()
verify { withKeys.match(it) }

return keyAction
/* configure via the callback*/
withAction()
}.also { addAction(it)}
}

/**
Expand All @@ -199,24 +207,23 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
operator fun EventType<KeyEvent>.invoke(vararg withKeys: KeyCode, withAction: KeyAction.() -> Unit): KeyAction {

/* create the Action*/
val keyAction = KeyAction(this)
.also { it.keyTracker = [email protected] }
return KeyAction(this).apply {
keyTracker = [email protected]

/* set the default name */
name = [email protected]

/* configure based on the withKeys paramters*/
keyAction.apply {
if (this.eventType == KeyEvent.KEY_RELEASED) {
/* configure based on the withKeys paramters*/
if (eventType == KeyEvent.KEY_RELEASED) {
ignoreKeys()
keysReleased(*withKeys)
} else if (withKeys.isNotEmpty()) {
keysDown(*withKeys)
}
}

/* configure via the callback*/
keyAction.apply(withAction)
addAction(keyAction)

return keyAction
/* configure via the callback*/
withAction()
}.also { addAction(it) }
}

/**
Expand All @@ -227,20 +234,20 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
* @param withAction [KeyAction] configuration callback
* @return the [KeyAction]
*/
operator fun EventType<KeyEvent>.invoke(keyBindings: NamedKeyCombination.CombinationMap, keyName: String, withAction: KeyAction.() -> Unit): KeyAction {
operator fun EventType<KeyEvent>.invoke(keyBindings: NamedKeyCombination.CombinationMap, keyName: String, keysExclusive: Boolean = false, withAction: KeyAction.() -> Unit): KeyAction {

/* create the Action*/
val keyAction = KeyAction(this)
.also { it.keyTracker = [email protected] }

/* configure based on the keyBinding paramters*/
keyAction.keyMatchesBinding(keyBindings, keyName)
/* create the Action*/
return KeyAction(this).apply {
keyTracker = [email protected]
name = "${[email protected]}.$keyName"

/* configure via the callback*/
keyAction.apply(withAction)
addAction(keyAction)
/* configure based on the withKeys paramters*/
keyMatchesBinding(keyBindings, keyName, keysExclusive)

return keyAction
/* configure via the callback*/
withAction()
}.also { addAction(it) }
}

/**
Expand All @@ -264,11 +271,13 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
): MouseAction {

/* create the Action*/
val mouseAction = MouseAction(this as EventType<MouseEvent>)
.also { it.keyTracker = [email protected] }
return MouseAction(this as EventType<MouseEvent>).apply {
keyTracker = [email protected]

/* set the default name */
name = [email protected]

/* copnfigure based on the parameters */
mouseAction.apply {
/* configure based on the parameters */
mouseButtonTrigger?.let {
/* default to exclusive if pressed, and NOT exclusive if released*/
verifyButtonTrigger(mouseButtonTrigger, released = onRelease, exclusive = !onRelease)
Expand All @@ -278,14 +287,9 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
keysDown(*it, exclusive = keysExclusive)
} ?: ignoreKeys()

}

/* configure based on the callback, and add to ActionSet */
mouseAction
.apply(withAction)
.also { addAction(it) }

return mouseAction
/* configure based on the callback */
withAction()
}.also { addAction(it)}
}

/**
Expand Down Expand Up @@ -360,10 +364,14 @@ open class ActionSet(val name: String, var keyTracker: () -> KeyTracker? = { nul
*/
@JvmSynthetic
fun mouseAction(eventType: EventType<MouseEvent>, withAction: MouseAction.() -> Unit = {}): MouseAction {
return MouseAction(eventType)
.also { it.keyTracker = this.keyTracker }
.apply(withAction)
.also { addAction(it) }
return MouseAction(eventType).apply {
keyTracker = [email protected]

/* set the default name */
name = [email protected]

withAction()
}.also { addAction(it) }
}


Expand Down
Loading
Loading