The Tiles API

From MakeProAudio Wiki
Revision as of 12:37, 15 June 2020 by Mklug mpa (talk | contribs) (Created page with "== 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 Chain...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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. Click here for more information on 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);


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.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:

  1. ENCODER8 (TileEncoder8)
  2. ENCODER12 (TileEncoder12)
  3. LEDBUTTON8 (TileLedButton8)
  4. LEDBUTTON12 (TileLedButton12)
  5. FADER4 (TileFader4)


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.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

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)
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


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');

hub.init('localhost', 8192);
if (ENABLEDIAGNOSTICS) diag.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:

  1. Pressing and Releasing any Encoder will cycle colours on the LED Buttons
  2. 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. Clone this repository and take a look at the following in the scripts section of package.json:

  1. diagnostics
  2. autoanimate
  3. encoderevents
  4. buttonevents
  5. buttonapi
  6. motorfaderevents
  7. motorfaderapi

To run any example, execute npm run <name of example from the list above>

Depending on the tiles connected to your hub, examples may produce varying results.