The Tiles API
Introduction
The Tiles API Client (nodejs) is a minimalistic nodejs client to speak to the MakeProAudio Tiles Hub. Using this client API, you can speak to Tile Chains connected to a Tiles Hub running on a local or remote computer. For more information, refer to The Tiles Hub. Currently you can only speak to a single Tile Chain. Multiplicity of Tile Chains will be supported later.
Installing The Package
In order to install the package, in your nodejs environment run:
npm i @makeproaudio/makehaus-js
You’ll need a node version (>=6.0) in order to run the Tiles API Client.
Connection To The Tiles Hub
Ensure that the Tiles Hub is running before you start using the client. Once you know the host
and port
of the Tiles Hub, use the following command to establish a connection:
const { hub } = require('@makeproaudio/makehaus-js'); hub.init('localhost', 8192);
Tile
hub
is an EventEmitter
. You can register to Tiles
being found on the Hub. For example, if you’re looking to work with a 12 Button Tile:
const { hub, Tile } = require('@makeproaudio/makehaus-js'); hub.init('localhost', 8192); hub.on(Tile.LEDBUTTON12, tile => { console.log('A new Led Button 12 tile was found. There may be more tiles on the chain!') });
The Tile
enum defines the type of Tiles currently supported by the Client:
- ENCODER8 (
TileEncoder8
) - ENCODER12 (
TileEncoder12
) - LEDBUTTON8 (
TileLedButton8
) - LEDBUTTON12 (
TileLedButton12
) - FADER4 (
TileFader4
)
Widget
A Tile has a widgets array. Each Widget has a widgetId property. Continuing from the previous example, the following gives a demonstration of accessing Widgets from a Tile, and the id from the widget:
const widget = tile.widgets[0].widgetId;
widget
is an EventEmitter
. Depending on the type of tile
, you can register to Widget
events. For example, if you want to listen to Button Pressed and Released events:
const { hub, Tile, LedButtonEvents } = require('@makeproaudio/makehaus-js'); hub.init('localhost', 8192); hub.on(Tile.LEDBUTTON12, tile => { tile.widgets.forEach(w => { w.on(LedButtonEvents.PRESSED, button => { console.log(`${button.widgetId} pressed`); }); w.on(LedButtonEvents.RELEASED, button => { console.log(`${button.widgetId} released`); }); }); });
All Widget Events come with a widget
argument. Additionally, here is a list of Events by Widget type:
Widget | Enum | Events | Comments |
---|---|---|---|
Button | LedButtonEvents
|
PRESSED | RELEASED
|
|
Encoder | EncoderEvents
|
PRESSED | RELEASED | TOUCHED | UNTOUCHED | LEFT | RIGHT
|
LEFT and RIGHT have an additional event argument: acceleratedValue: number
|
Fader | MotorFaderEvents
|
TOUCHED | UNTOUCHED | UPDATED
|
Some Widgets have extra functions. Here is a list of these functions by Widget type:
Widget | Functions | Comments |
---|---|---|
Button | setColor(colorInHex: string) setHsl(hue: number, saturation: number, lightness: number) startFlash(destinationColorInHex: string, repCount: number, periodBefore: number, periodDestination: number, periodAfter: number, periodSource: number) stopFlash()
|
|
Fader | setValue(value: number) getValue(): number getRangedValue(): number
|
while setValue and getValue are ranged between 0 and 65536, getRangedValue gives you the value ranged from 0 to 1
|
Diagnostics
A simple Diagnostics
module has been added to get you started out of the box. If started, each Event from each Widget for each Tile will be logged to the console.
const { hub, diagnostics } = require('@makeproaudio/makehaus-js'); const ENABLEDIAGNOSTICS = true; hub.init('localhost', 8192); if (ENABLEDIAGNOSTICS) diagnostics.start(hub);
You should not leave the
Diagnostics
module started for your own applications.
A Simple Animation
You can do pretty cool things with Tiles! Depending on what is present on your Chain, if started, the AutoAnimate
module will animate an Encoder Tile, a Fader Tile and a Button Tile in the following manner:
- Pressing and Releasing any Encoder will cycle colours on the LED Buttons
- Turning Encoders right and left will move Motor Faders up and down
const { hub, autoAnimate } = require('@makeproaudio/makehaus-js'); const AUTOANIMATE = true; hub.init('localhost', 8192); if (AUTOANIMATE) autoAnimate.start(hub);
For a full example, refer to
autoanimate.ts
in the src folder.
Running The Examples
There are several examples bundled with the repository. Visit MakeHaus Examples to learn more.