ImplantObject

This is the base class for all javascript implant implementations. Inside of server javascript files, this object is accessible via the this keyword or through the variable implant. Every instance is unique to each implant instance executed, so this object cannot shared data between different copies of the same instance, except by using the appropriate objects available as properties on this object.

This guide explains javascript scoping in depth, and tricks like assigning this to another variable. It is far easier to just always use the implant keyword, until you become an advanced javascript programmer.

Simple Examples
The simple examples below will work as the entire source code for a new javascript implant. In these examples, the keyword implant is used instead of this to avoid javascript scoping. this could be used instead, except from within functions, because scoping follows standard javascript scoping rules.

// highlight pressed buttons in red and neighbors in yellow implant.pads.on('press', function(e) {   implant.pads.set(e.x, e.y, 'red');    implant.pads.set(e.x + 1, e.y, 'yellow');    implant.pads.set(e.x - 1, e.y, 'yellow');    implant.pads.set(e.x, e.y + 1, 'yellow');    implant.pads.set(e.x, e.y - 1, 'yellow');  });

// change the color of a pad every half second var colors = ['red','yellow','green']; var colorIndex = 0; implants.setInterval(function {   implant.pads.set(0, 0, colors[colorIndex]);        colorIndex++;    if (colorIndex >= colors.length) colorIndex = 0;  }, 500);

Properties
All interactions available to implants are accessed via the properties of this object.
 * pads - access to lit and unlit button grid MIDI devices, such as the Novation LaunchPad
 * knobs - access to knobs and faders on MIDI devices, such as the Novation LaunchControl (the LaunchControl's pads are accessed via the pads object though)
 * keys - access to note data from a MIDI keyboard
 * osc - sends and receives OSC data
 * gui - system for controlling the GUI displayed in the session view on both the desktop and tablet devices (tested on iPad only so far)
 * time - access to beat synchronization
 * settings - access to program settings for the current implant instance
 * shared - shares data between all running instances of this implant type
 * session - saves current data, such as current fader positions, to the current user session so the implant will have the same values the next time this session is loaded
 * mode - faciliates menus that control which implant is currently active on hardware devices
 * assignedMode - the mode this implant is active on.  Check against implant.mode.current to see if the current implant is visible on the launchpad.

Methods

 * void on(event, callback) - registers a function to be called when the specified event is triggered. See the events section on this page.
 * void print(msg) - prints a literal string to the javascript console.
 * void print(format, args) - prints a message to the javascript console using c# string.format parameters
 * void wait - displays the message "Press enter to continue javascript" on the javascript console and waits for the user to press enter on their keyboard to continue running.
 * int setInterval(fn, delayMsec) - like the web javascript function, this repeatedly calls the provided function every few milliseconds until the return value is passed to clearInterval
 * void clearInterval(id) - stops a repeated call setup by setInterval

Events
These events are available to the on function:
 * devicechange - triggered whenever a MIDI device that is accessible to this implant has been added or removed.