-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightAllWhenPressed.kt
30 lines (26 loc) · 1.16 KB
/
LightAllWhenPressed.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@file:JvmName("LightAllWhenPressedd")
package com.harry1453.klaunchpad.examples
import com.harry1453.klaunchpad.api.Color
import com.harry1453.klaunchpad.api.Launchpad
import com.harry1453.klaunchpad.api.open
import kotlin.random.Random
/**
* This example demonstrates updating all pads.
*/
suspend fun main() {
val inputDeviceInfo = Launchpad.listMidiInputDevices()
.firstOrNull { it.name == "Launchpad MK2" } ?: error("Could not find the Launchpad's MIDI input!")
val outputDeviceInfo = Launchpad.listMidiOutputDevices()
.firstOrNull { it.name == "Launchpad MK2" } ?: error("Could not find the Launchpad's MIDI output!")
val launchpad = Launchpad.connectToLaunchpadMK2(inputDeviceInfo.open(), outputDeviceInfo.open())
Runtime.getRuntime().addShutdownHook(Thread { launchpad.close() })
val random = Random(System.currentTimeMillis())
launchpad.setPadButtonListener { _, pressed, _ ->
val color = Color(random.nextInt(1, 256), random.nextInt(1, 256), random.nextInt(1, 256))
if (pressed) {
launchpad.setAllPadLights(color)
} else {
launchpad.setAllPadLights(Color.BLACK)
}
}
}