[orx-midi] Add bindMidiNote
This commit is contained in:
@@ -13,8 +13,28 @@ import org.openrndr.math.map
|
|||||||
|
|
||||||
import kotlin.reflect.KMutableProperty0
|
import kotlin.reflect.KMutableProperty0
|
||||||
import kotlin.reflect.full.findAnnotations
|
import kotlin.reflect.full.findAnnotations
|
||||||
|
|
||||||
|
fun bindMidiNote(on: () -> Unit, off: () -> Unit, transceiver: MidiTransceiver, channel: Int, note: Int) {
|
||||||
|
transceiver.noteOn.listen {
|
||||||
|
if ((channel == -1 || it.channel == channel) && it.note == note) {
|
||||||
|
on()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transceiver.noteOff.listen {
|
||||||
|
if ((channel == -1 || it.channel == channel) && it.note == note) {
|
||||||
|
on()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@JvmName("bindMidiControlDouble")
|
@JvmName("bindMidiControlDouble")
|
||||||
fun Program.bindMidiControl(property: KMutableProperty0<Double>, transceiver: MidiTransceiver, channel: Int, control: Int) {
|
fun Program.bindMidiControl(
|
||||||
|
property: KMutableProperty0<Double>,
|
||||||
|
transceiver: MidiTransceiver,
|
||||||
|
channel: Int,
|
||||||
|
control: Int
|
||||||
|
) {
|
||||||
val anno = property.findAnnotations(DoubleParameter::class).firstOrNull()
|
val anno = property.findAnnotations(DoubleParameter::class).firstOrNull()
|
||||||
|
|
||||||
val low = anno?.low ?: 0.0
|
val low = anno?.low ?: 0.0
|
||||||
@@ -40,7 +60,12 @@ fun Program.bindMidiControl(property: KMutableProperty0<Double>, transceiver: Mi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("bindMidiControlBoolean")
|
@JvmName("bindMidiControlBoolean")
|
||||||
fun Program.bindMidiControl(property: KMutableProperty0<Boolean>, transceiver: MidiTransceiver, channel: Int, control: Int) {
|
fun Program.bindMidiControl(
|
||||||
|
property: KMutableProperty0<Boolean>,
|
||||||
|
transceiver: MidiTransceiver,
|
||||||
|
channel: Int,
|
||||||
|
control: Int
|
||||||
|
) {
|
||||||
transceiver.controlChanged.listen {
|
transceiver.controlChanged.listen {
|
||||||
if (it.eventType == MidiEventType.CONTROL_CHANGED && it.channel == channel && it.control == control) {
|
if (it.eventType == MidiEventType.CONTROL_CHANGED && it.channel == channel && it.control == control) {
|
||||||
property.set(it.value >= 64)
|
property.set(it.value >= 64)
|
||||||
@@ -61,9 +86,11 @@ fun Program.bindMidiControl(property: KMutableProperty0<Boolean>, transceiver: M
|
|||||||
|
|
||||||
|
|
||||||
@JvmName("bindMidiControlVector2")
|
@JvmName("bindMidiControlVector2")
|
||||||
fun Program.bindMidiControl(property: KMutableProperty0<Vector2>, transceiver: MidiTransceiver,
|
fun Program.bindMidiControl(
|
||||||
|
property: KMutableProperty0<Vector2>, transceiver: MidiTransceiver,
|
||||||
channelX: Int, controlX: Int,
|
channelX: Int, controlX: Int,
|
||||||
channelY: Int = channelX, controlY: Int = controlX + 1) {
|
channelY: Int = channelX, controlY: Int = controlX + 1
|
||||||
|
) {
|
||||||
val anno = property.findAnnotations(Vector2Parameter::class).firstOrNull()
|
val anno = property.findAnnotations(Vector2Parameter::class).firstOrNull()
|
||||||
|
|
||||||
val low = anno?.min ?: 0.0
|
val low = anno?.min ?: 0.0
|
||||||
@@ -106,10 +133,12 @@ fun Program.bindMidiControl(property: KMutableProperty0<Vector2>, transceiver: M
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("bindMidiControlVector3")
|
@JvmName("bindMidiControlVector3")
|
||||||
fun Program.bindMidiControl(property: KMutableProperty0<Vector3>, transceiver: MidiTransceiver,
|
fun Program.bindMidiControl(
|
||||||
|
property: KMutableProperty0<Vector3>, transceiver: MidiTransceiver,
|
||||||
channelX: Int, controlX: Int,
|
channelX: Int, controlX: Int,
|
||||||
channelY: Int = channelX, controlY: Int = controlX + 1,
|
channelY: Int = channelX, controlY: Int = controlX + 1,
|
||||||
channelZ: Int = channelY, controlZ: Int = controlY + 1) {
|
channelZ: Int = channelY, controlZ: Int = controlY + 1
|
||||||
|
) {
|
||||||
val anno = property.findAnnotations(Vector3Parameter::class).firstOrNull()
|
val anno = property.findAnnotations(Vector3Parameter::class).firstOrNull()
|
||||||
|
|
||||||
val low = anno?.min ?: 0.0
|
val low = anno?.min ?: 0.0
|
||||||
@@ -160,7 +189,8 @@ fun Program.bindMidiControl(property: KMutableProperty0<Vector3>, transceiver: M
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("bindMidiControlColorRGBa")
|
@JvmName("bindMidiControlColorRGBa")
|
||||||
fun Program.bindMidiControl(property: KMutableProperty0<ColorRGBa>, transceiver: MidiTransceiver,
|
fun Program.bindMidiControl(
|
||||||
|
property: KMutableProperty0<ColorRGBa>, transceiver: MidiTransceiver,
|
||||||
channelR: Int, controlR: Int,
|
channelR: Int, controlR: Int,
|
||||||
channelG: Int = channelR, controlG: Int = controlR + 1,
|
channelG: Int = channelR, controlG: Int = controlR + 1,
|
||||||
channelB: Int = channelG, controlB: Int = controlG + 1,
|
channelB: Int = channelG, controlB: Int = controlG + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user