bitwig-controller-scripts/pc2scene.control.js

71 lines
2.5 KiB
JavaScript
Raw Normal View History

loadAPI(18);
// Remove this if you want to be able to use deprecated methods without causing script to stop.
// This is useful during development.
host.setShouldFailOnDeprecatedUse(true);
host.defineController("Generic", "PC2Scene", "0.1", "d8fd1407-e713-4c83-8ed1-1532c05895ba", "decibyte");
host.defineMidiPorts(1, 0);
function init() {
// Set up the preferences for the controller script. There are 2 available
// settings:
// - The MIDI channel to listen for Program Change messages on.
// - Whether to show Scene changes as notifications on the screen.
preferences = host.getPreferences();
midiChannel = preferences.getNumberSetting("MIDI channel for Program Change", "General", 1, 16, 1, "", 1);
showNotifications = preferences.getBooleanSetting("Show scene change notifications", "General", false);
// Attach a callback to incoming MIDI events.
midiIn = host.getMidiInPort(0);
midiIn.setMidiCallback(onMidiIn);
// Set up a Scene bank and iterate over all of them, in order to mark
// their names interesting (to be able to print them later on).
sceneCount = 128;
scenes = host.createSceneBank(sceneCount);
for (i = 0; i < sceneCount; i++) {
scene = scenes.getScene(i);
scene.name().markInterested();
}
host.println("PC2Scene initialized.");
}
function flush() {
}
function exit() {
host.println("Exited.");
}
function onMidiIn(status, data1, data2) {
// Only look at Program Change messages.
if (isProgramChange(status)) {
// Get the MIDI channel for the incoming Program Change message and
// the MIDI channel from the preferences.
inChannel = MIDIChannel(status);
prefChannel = midiChannel.get() * 15;
// Only change Scene if the Program Change message is from the
// correct channel.
if (inChannel == prefChannel) {
// Get the Scene, launch it and scroll to it.
scene = scenes.getScene(data1);
scene.launch();
scenes.scrollIntoView(data1);
// Print out debug information and optionally show the name of the
// new Scene if toggled on in the preferences.
sceneName = scene.name().get();
host.println("Program Change " + data1 + " received on channel " + (MIDIChannel(status) + 1));
message = 'Launching scene: "' + sceneName + '"';
if (showNotifications.get()) {
host.showPopupNotification(message);
}
host.println(message);
}
}
}