Adventures Programming BitWig API

Included Utilities & Language Capabilities

04 Apr 2014

Just as important as learning the BitWig API, is learning how to use the EMCAScript 3 implementation of JavaScript available in BitWig.

This is important, because some of the advanced constructs available in modern browsers are not available in BitWig. As well, certain aspects of the language might be confusing for those of us steeped in web development.

Most of these are fairly esoteric, but good to be aware of.

Looking through the api folder, we see api_v1.js, midi.js, sysex.js and utils.js.

These are helpful to reference occasionally when developing your driver.

Examine midi.js for a ton of helper functions to assist in categorizing and creating MIDI messages. In case you're curious (status & 0xf0) is a way to check the hex code for each channel and find what category it lands in.

Custom Utility Functions

I made these to make my own development process easier, mostly to ease the migration from JS for web development.

log(), which handles multiple parameters.

function log(msg) {
  for (var i = 0, l = arguments.length; i < l; i++) {
    host.println(arguments[i]);
  }
}

alert(), to have messages show in a fading popup.

function alert(msg) {
  host.showPopupNotification(msg);
}

everyone's favorite, setInterval(), with optional args.

function setInterval(cb, args, delay){
  host.scheduleTask(cb, args, delay);
}