Creating

Extension development

Build visualizers and themes as Toxen extensions and publish them to the store.

Extensions add things to Toxen without touching the app: custom visualizers (drawn with JavaScript on a canvas) and themes (data only, no code). They are installed from the extension store with one click, or by hand.

Extensions run inside Toxen with the same access as the app itself. Only install extensions you trust. Store submissions are reviewed by an admin before they are listed, but you should still read what you install.

What an extension is

An extension is a folder with an extension.json manifest and, if it has visualizers, a JavaScript entry file. Zip that folder to distribute it. Toxen keeps installed extensions in its data folder under extensions/<id>/, and loads every enabled one at startup.

whaleshark/
  extension.json
  index.js

The manifest

{
  "id": "whaleshark",
  "name": "Whale Shark Visualizer",
  "version": "1.0.0",
  "author": "Toxen",
  "description": "A whale shark that swims across the screen, reacting to audio frequencies.",
  "main": "index.js",
  "visualizers": [
    {
      "id": "whaleshark",
      "name": "Whale Shark",
      "options": [
        { "name": "Size", "key": "size", "type": "range", "defaultValue": 0, "min": 0, "max": 1000, "step": 0.1 },
        { "name": "Swimming", "key": "swimming", "type": "boolean", "defaultValue": false }
      ]
    }
  ]
}
Field Meaning
id Unique identifier, also the folder name. Keep it lowercase and simple
name, description, author, version Shown in the extension list and the store
main Entry file. Default is index.js
visualizers Visualizers this extension provides, each with an id, a name and optional settings
themes Themes this extension provides (see below)

Visualizer options

Every entry in a visualizer’s options becomes a control in the song and global settings. The key is what your code reads with getOption(key).

type Extra fields
range min, max, step, defaultValue
boolean defaultValue
select options: [{ "label": "...", "value": "..." }], defaultValue
songImage An image chosen from the song’s files

The code

The entry file exports an activate(api) function, and optionally deactivate() to clean up. The API is currently version 1.

exports.activate = function (api) {
  api.registerVisualizer("bars", function (rc) {
    var unitW = rc.vWidth / rc.len;
    var maxHeight = rc.getMaxHeight(0.3);

    for (var i = 0; i < rc.len; i++) {
      var barHeight = rc.dataArray[i] / rc.dataSize * maxHeight;
      rc.setBarShadowBlur(barHeight);
      rc.setRainbowIfEnabled(i * unitW, rc.vHeight - barHeight, unitW, barHeight, i);
      rc.ctx.fillRect(i * unitW, rc.vHeight - barHeight, unitW, barHeight);
    }
  });
};

exports.deactivate = function () {};

registerVisualizer(localId, renderFn) registers a visualizer. The localId must match an id in the manifest’s visualizers list. The render function runs every animation frame with a render context (rc):

Member What it is
ctx The 2D canvas context to draw on. Fill and stroke styles are already set to the user’s colour
dataArray, len, dataSize Frequency data: len bins, each 0 to dataSize
vWidth, vHeight, vLeft, vTop The drawing area in pixels
time Playback time in milliseconds
dynLight Overall audio intensity, for pulses and glows
opacity Current opacity, 0 to 1
storedColor The user’s visualizer colour as a CSS string
isRainbow, isGlow, pulseEnabled The user’s rainbow, glow and background pulse settings
intensityMultiplier The user’s intensity setting (default 1)
getMaxHeight(mult), getMaxWidth(mult) A fraction of the area, scaled by the intensity setting
setBarShadowBlur(value) Applies the glow for a bar, if glow is on
setRainbowIfEnabled(x, y, w, h, i) In rainbow mode, sets a gradient colour for bin i
getOption(key) The value of one of your manifest options, or null for the default

The full type declarations are in src/app/toxen/extensions/toxen-extension-api.d.ts in the Toxen repository. Copy it next to your extension for editor completion, and use a JSDoc type on api to get hints in plain JavaScript:

/** @param {import("./toxen-extension-api").ToxenExtensionAPI} api */
exports.activate = function (api) { /* ... */ };

The Whale Shark extension in the repository is a complete example with options.

Themes

A theme extension needs no JavaScript. Add a themes list to the manifest:

{
  "id": "midnight",
  "name": "Midnight",
  "version": "1.0.0",
  "author": "You",
  "description": "A deep blue theme.",
  "themes": [
    {
      "name": "midnight",
      "displayName": "Midnight",
      "description": "Deep blue with a cyan accent.",
      "styles": {
        "primaryBg": { "value": [11, 18, 32] },
        "accentColor": { "value": [110, 231, 249] }
      },
      "customCSS": ""
    }
  ]
}

styles uses the same keys as the theme editor (primaryBg, accentColor, textPrimary and so on) and colours are [r, g, b] arrays. The easiest way to find them is to build the theme in the editor in Toxen and copy the values. The theme appears in the theme dropdown while the extension is enabled.

Package it

Zip the contents of the folder, so that extension.json is at the top level of the zip (not inside a subfolder):

cd whaleshark
zip -r ../whaleshark.zip .

To test locally, unzip it into Toxen’s extensions/<id>/ data folder and restart Toxen, or enable it from the extension list.

Publish it to the store

  1. Sign in on toxen.net. Any account can submit, no subscription needed.
  2. Go to Submit an extension, fill in the id, name, description, version and API version (1), and upload the zip.
  3. An admin reviews the submission. Once approved it shows up in the store and can be installed from there.
  4. To ship an update, submit again with a higher version.

Submissions that do things a visualizer or theme has no reason to do (reading files, calling out to the network) are likely to be rejected.