Spectral Workbench API
This is a planning page for the upcoming Spectral Workbench API.
Macros
We're going to start with a simple macro language, probably initially in a sandbox so people can try things out. We'll build out this language for a bit, let it stabilize, and then tackle the problems of publishing macros and sharing them amongst users.
Getting started
To create a macro we'll have a simple editor you can enter JavaScript code into. At first you won't be able to save, and it'll just be a sandbox. The basic template will look something like this:
{ setup: function() {
// code to run on startup
},
draw: function() {
// code to run every frame
}
}
Variables and methods
A range of variables and methods will be available to use in your macros. To start with, you can read through the existing framework here:
https://github.com/jywarren/spectral-workbench/blob/master/webserver/public/javascripts/capture.js
- $W.data - returns a nested array of wavelength/intensity pairs, as floats and integers between 0-255, respectively. Example to come; intensities are separated by R, G, and B channels.
- $W.mode - "rgb" or "average", i.e. whether we're currently looking at color channel data or the averaged "monochrome" data
- $W.markers - an array of markers at certain wavelengths, as input by the user. Later we'll make it easy to add new markers (see next)
- $W.add_marker(string name,int wavelength) - not yet implemented - add a new marker to monitor the intensity at this wavelength.
- $W.notify(string msg,string type,boolean expire) - alert the user with a message (msg) of type "notify", "warning" or "error" shown in green, yellow, or red respectively. Defaults to expire = true, which means it disappears after 2 seconds.
- $W.getIntensity(obj data,int x) - Get the intensity from 0-255 for a given x-position in the video frame. Use as follows: $W.getIntensity($W.data[0].data,200)