Track

Object containing all track-specific WebAudioAPI functionality.

Members

name

Name of the Track.

Methods

async applyEffect(effectName, effectType)

Applies a new track effect at the specified time.

Calling this function affects the sequential ordering in which effects will be processed, with each new call appending the corresponding effect to the end of the processing sequence.

If an effect with the specified effectName has already been applied , then calling this function will simply re-order the effect to move it to the very end of the effect processing sequence, without changing its parameter values.

Parameters:
Name Type Description
effectName string

User-defined name to associate with the track effect

effectType number

Track EffectType to apply

See:

clearTrack()

Cancels any current or scheduled audio from playing on the current track.

async connectToAudioInputDevice(audioDeviceID)

Connects the current track to the specified audio input device so that any incoming audio will be automatically played in real-time.

Parameters:
Name Type Description
audioDeviceID string

ID of the audio input device to which to connect the current track

connectToMidiDevice(midiInput)

Connects the current track to the specified MIDI device so that any incoming events will be automatically played in real-time.

Parameters:
Name Type Description
midiInput MIDIInput

MIDI device to which to connect the current track

See:

deleteTrack()

Deletes the current track and cancels any scheduled audio from playing or from starting to play in the future.

disconnectFromAudioInputDevice()

Disconnects the current track from the specified audio input device so that no further audio events will be received.

disconnectFromMidiDevice()

Disconnects the current track from the specified MIDI device so that no further MIDI events will be received.

getAnalysisBuffer(analysisType) → {Uint8Array}

Returns a buffer containing the realtime frequency content of the audio being produced by the current track.

Parameters:
Name Type Description
analysisType number

Audio AnalysisType for which the buffer will be used

Returns:
Uint8Array -

Array containing time or frequency content of the track's current audio output

getCurrentEffectParameters(effectName) → {Object}

Returns the current parameter settings for the specified track effect.

Parameters:
Name Type Description
effectName string

Name of the track effect for which to retrieve current settings

Returns:
Object -

Effect-specific parameter values with keys as returned by getAvailableEffectParameters()

playChord(}, startTime, modifications, areDrumNotes) → {number}

Schedules a chord of notes to be played on the current track.

Note that the chord parameter should be an array of [note, duration, mods] tuples, where the note parameter should correspond to a valid MIDI note number, the duration parameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(), and mods may either be a single modification to the chord, a list of modifications, or omitted completely.

The modifications parameter may either be a single ModificationDetails structure or a list of such structures.

Parameters:
Name Type Description
} Array.<Array>

chord - Array of [note, duration, mods] corresponding to the chord to be played

startTime number

Global API time at which to start playing the chord

modifications Array.<ModificationDetails>

One or more Modifications to apply to the chord

areDrumNotes boolean

Whether this chord contains only drum notes (i.e., not affected by key or duration)

Returns:
number -

Duration (in seconds) of the chord being played

async playClip(audioClip, startTime, opt duration) → {Promise.<number>}

Schedules an audio clip to be played on the current track for some duration of time.

If the duration parameter is not specified or is set to null, the audio clip will play to completion.

Parameters:
Name Type Attributes Description
audioClip ArrayBuffer | AudioBuffer | Blob | MidiClip | AudioClip

Object containing audio data to play

startTime number

Global API time at which to start playing the clip

duration number <optional>

Number of seconds for which to continue playing the clip

Returns:
Promise.<number> -

Duration (in seconds) of the clip being played

See:

async playFile(fileURL, startTime, opt duration) → {Promise.<number>}

Schedules an audio file to be played on the current track for some duration of time.

If the duration parameter is not specified or is set to null, the audio file will play to completion.

Parameters:
Name Type Attributes Description
fileURL string

URL location pointing to an audio file

startTime number

Global API time at which to start playing the file

duration number <optional>

Number of seconds for which to continue playing the file

Returns:
Promise.<number> -

Duration (in seconds) of the file being played

playNote(note, startTime, duration, modifications, isDrumNote, opt fromChord) → {number}

Schedules a note to be played on the current track for some duration of time.

Note that the duration parameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(). Likewise, the note parameter should correspond to a valid MIDI note number.

The modifications parameter may either be a single ModificationDetails structure or a list of such structures.

Parameters:
Name Type Attributes Default Description
note number

MIDI Note number to be played

startTime number

Global API time at which to start playing the note

duration number

Duration for which to continue playing the note

modifications Array.<ModificationDetails>

One or more Modifications to apply to the note

isDrumNote boolean

Whether this note is a drum note (i.e., not affected by key or duration)

fromChord boolean <optional>
false

Whether this note is being played from the playChord() function

Returns:
number -

Duration (in seconds) of the note being played

playNoteAsync(note, velocity) → {Object}

Immediately begins playing a note on the current track. Playback continues until the note is explicitly stopped using the stopNoteAsync() function.

Note that the note parameter should correspond to a valid MIDI note number.

Parameters:
Name Type Description
note number

MIDI Note number to be played

velocity number

Intensity of the note to play between [0.0, 1.0]

Returns:
Object -

Reference to the newly scheduled note

playSequence(sequence, startTime, modifications, areDrumNotes) → {number}

Schedules a musical sequence to be played on the current track.

Note that the sequence parameter should be an array containing either chords (as defined in the playChord() function) or [note, duration, mods] tuples, where the note parameter should correspond to a valid MIDI note number, the duration parameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(), and mods may either be a single modification that affects the whole sequence, a list of modifications, or omitted completely.

The modifications parameter may either be a single ModificationDetails structure or a list of such structures.

Parameters:
Name Type Description
sequence Array.<(Array|Array.<Array>)>

Array of [note, duration, mods] and/or chords corresponding to the sequence to be played

startTime number

Global API time at which to start playing the sequence

modifications Array.<ModificationDetails>

One or more Modifications to apply to the sequence

areDrumNotes boolean

Whether this sequence contains only drum notes (i.e., not affected by key or duration)

Returns:
number -

Duration (in seconds) of the sequence being played

recordAudioClip(startTime, opt duration) → {AudioClip}

Schedules an audio clip to be recorded on the current track for some duration of time.

If the duration parameter is not specified or is set to null, the audio clip will continue to record until manually stopped by the finalize() function on the returned AudioClip object.

Note that the recorded audio clip will not include any effects that might exist on the track. This is so that recording and then immediately playing back on the same track will not cause any underlying effects to be doubled.

Parameters:
Name Type Attributes Description
startTime number

Global API time at which to start recording the audio clip

duration number <optional>

Number of seconds for which to continue recording the audio clip

Returns:
AudioClip -

Reference to an AudioClip object representing the audio data to be recorded

See:

recordMidiClip(startTime, opt duration) → {MidiClip}

Schedules a MIDI clip to be recorded on the current track for some duration of time.

If the duration parameter is not specified or is set to null, the MIDI clip will continue to record until manually stopped by the finalize() function on the returned MidiClip object.

Note that the recorded MIDI clip will not include any effects that might exist on the track. This is so that recording and then immediately playing back on the same track will not cause any underlying effects to be doubled.

Parameters:
Name Type Attributes Description
startTime number

Global API time at which to start recording the MIDI clip

duration number <optional>

Number of seconds for which to continue recording the MIDI clip

Returns:
MidiClip -

Reference to a MidiClip object representing the MIDI data to be recorded

See:

recordOutput(startTime, opt duration) → {AudioRecording}

Schedules an audio recording to be executed on the cumulative output of the current track for some duration of time.

If the duration parameter is not specified or is set to null, the audio recording will continue until manually stopped by the finalize() function on the returned AudioRecording object.

Note that the recorded audio will include all effects that exist on the track.

Parameters:
Name Type Attributes Description
startTime number

Global API time at which to start recording the audio output

duration number <optional>

Number of seconds for which to continue recording the audio output

Returns:
AudioRecording -

Reference to an AudioRecording object representing the audio recording

See:

async removeEffect(effectName) → {Effect|null}

Removes the specified track effect from being applied.

Parameters:
Name Type Description
effectName string

Name of the track effect to be removed

Returns:
Effect | null -

Existing effect or null

removeInstrument()

Removes the instrument used to play back audio on the current track.

stopNoteAsync(noteObject)

Immediately stop playing a note on the current track. The note to be stopped must be a reference to an actively playing note that was previously returned from the playNoteAsync() function.

Parameters:
Name Type Description
noteObject Object

Reference to an active note that was started using playNoteAsync()

async updateEffect(effectName, effectOptions, updateTime, timeConstant)

Updates the parameters of a track effect at the specified time.

Calling this function will not affect the sequential processing order of any applied effects.

Note that the updateTime parameter can be omitted to immediately cause the requested changes to take effect.

Parameters:
Name Type Description
effectName string

Name of the track effect to be updated

effectOptions Object

Effect-specific options as returned by getAvailableEffectParameters()

updateTime number

Global API time at which to update the effect

timeConstant number

Time constant defining an exponential approach to the target

updateInstrument(instrumentData)

Updates the instrument used to play back audio on the current track.

Parameters:
Name Type Description
instrumentData Instrument

Instrument object to use when generating audio on the current track