Instruments

InstrumentComposer

Create new instruments with session.instrument():

session.instrument('synth', () => {
  return new Tone.MonoSynth();
});

Import built-in instruments with session.use():

session.use('core.instrument.piano');

In order to play notes, an instrument must be associated with a track and sent to the main output. The latter is important, or else you won't hear any audio.

// Create a track called "synth-pad"
session.track('synth-pad', ({ track }) => {
  track.at(0).play(whole.note('Cmaj7'));
});

// Route the "synth" instrument to the "synth-pad" track:
session.send.instrument('synth').to.track('synth-pad');

// Send the "synth-pad" track to the main output:
session.send.track('synth-pad').to.main();

Built-in Instruments

Tone.js

Any Tone.js instrument can be used out of the box:

session.instrument('my-synth', () => {
  return new Tone.MetalSynth();
});

Core Library

The core library contains a basic set of sample-based instruments. Refer to the Library panel in the Harmonicon UI for the full list.

Writing Custom Instruments

At its core, an instrument is simply an AudioNode instance.

session.instrument('custom-instrument', () => {
  // ...example needed
  return myAudioNode;
})

Methods

group(group)

Assign instrument to a library group.

Parameters:
Name Type Description
group string
Source:

description(description)

Give the instrument a description.

Parameters:
Name Type Description
description string
Source:

author(author)

Denote the author of the instrument, if applicable.

Parameters:
Name Type Description
author string
Source:

url(url)

Set website of the instrument, if applicable.

Parameters:
Name Type Description
url string
Source:

documentationUrl(documentationUrl)

Set documentation URL.

Parameters:
Name Type Description
documentationUrl string
Source:

options(options)

Options that should be passed to the builder function at runtime.

Parameters:
Name Type Description
options object
Source:

defaultOptions(defaultOptions)

Default options passed to builder function at runtime; overridden by #options.

Parameters:
Name Type Description
defaultOptions object
Source:

suggestedOctave(suggestedOctave)

Octave most relevant to the instrument's pitch and timbre.

Parameters:
Name Type Description
suggestedOctave integer
Source:

fn(defaultOptions)

Set runtime builder function that returns an Web Audio Node.

Parameters:
Name Type Description
defaultOptions object
Source:

pitchAliases(pitchAliases)

Map of pitch aliases, for example "snare" may refer to "c4".

Parameters:
Name Type Description
pitchAliases object
Source: