Extends:

Sampler → BeatTrack

An instance of this class has a single "sound" (comprised of one or multiple audio sources) but provides methods to play that sound repeatedly, mixed with "rests," in a rhythmic way. An instance of this class behaves very similarly to a "lane" on a drum machine.

Property Summary

Public Properties
public

Computed property. An array of Beat instances. The number of Beat instances in the array is always the same as the numBeats property. If 'numBeats' or duration changes. This property will be recomputed, but any beats that previously existed are reused so that they will maintain their active state.

public

If specified, Determines length of time, in milliseconds, before isPlaying and currentTimeIsPlaying are automatically switched back to false after having been switched to true for each beat. 100ms is used by default.

public
public

Determines the number of beats in a BeatTrack instance.

public
public
Private Properties
private

Method Summary

Public Methods
public
play( )
public
playActiveBeats(bpm, noteType)

Calls play on active Beat instances in the beats array. Any beat that is not marked active is effectively a "rest".

public
playAt(time)
public
playBeats(bpm, noteType)

Calls play on all Beat instances in the beats array.

public
playIn(seconds)
Private Methods
private
_callPlayMethodOnBeats(method, bpm, noteType)

The underlying method behind playBeats and playActiveBeats.

private
private
private

Public Properties

Computed property. An array of Beat instances. The number of Beat instances in the array is always the same as the numBeats property. If 'numBeats' or duration changes. This property will be recomputed, but any beats that previously existed are reused so that they will maintain their active state.

If specified, Determines length of time, in milliseconds, before isPlaying and currentTimeIsPlaying are automatically switched back to false after having been switched to true for each beat. 100ms is used by default.

Determines the gain applied to each sample.

Determines the number of beats in a BeatTrack instance.

Determines the stereo pan position of each sample.
Acts as a register for loaded audio sources. Audio sources can be anything that uses {{#crossLink "Playable"}}{{/crossLink}}. If not set on instantiation, automatically set to new Set() via _initSounds.

Private Properties

addon/classes/sampler.js:50

private _soundIterator: Iterator

Temporary storage for the iterable that comes from the sounds Set. This iterable is meant to be replaced with a new copy every time it reaches it's end, resulting in an infinite stream of Sound instances.

Public Methods

Inherited from Sampler
Gets the next audio source and plays it immediately.
addon/classes/beat-track.js:112

public playActiveBeats(bpm, noteType)

Calls play on active Beat instances in the beats array. Any beat that is not marked active is effectively a "rest".

Parameters:

Name Type Attribute Description
bpm Number

The tempo at which the beats and rests should be played.

noteType Number

The (rhythmic) length of each beat/rest. Fractions are suggested here so that it's easy to reason about. For example, for eighth notes, pass in 1/8.

addon/classes/sampler.js:96

public playAt(time)

Inherited from Sampler
Gets the next Sound and plays it at the specified moment in time. A "moment in time" is measured in seconds from the moment that the {{#crossLink "AudioContext"}}{{/crossLink}} was instantiated.

Parameters:

Name Type Attribute Description
time Number
The moment in time (in seconds, relative to the {{#crossLink "AudioContext"}}AudioContext's{{/crossLink}} "beginning of time") when the next Sound should be played.
addon/classes/beat-track.js:96

public playBeats(bpm, noteType)

Calls play on all Beat instances in the beats array.

Parameters:

Name Type Attribute Description
bpm Number

The tempo at which the beats should be played.

noteType Number

The (rhythmic) length of each beat. Fractions are suggested here so that it's easy to reason about. For example, for eighth notes, pass in 1/8.

addon/classes/sampler.js:83

public playIn(seconds)

Inherited from Sampler
Gets the next Sound and plays it after the specified offset has elapsed.

Parameters:

Name Type Attribute Description
seconds Number
Number of seconds from "now" that the next Sound should be played.

Private Methods

addon/classes/beat-track.js:129

private _callPlayMethodOnBeats(method, bpm, noteType)

The underlying method behind playBeats and playActiveBeats.

Parameters:

Name Type Attribute Description
method String

The method that should be called on each beat.

bpm Number

The tempo that should be used to calculate the length of a beat/rest.

noteType Number

The (rhythmic) length of each beat/rest that should be used to calculate the length of a beat/rest in seconds.

addon/classes/sampler.js:112

private _getNextSound( ): Sound

Inherited from Sampler
Gets _soundIterator and returns it's next value. If _soundIterator has reached it's end, replaces _soundIterator with a fresh copy from sounds and returns the first value from that.

Return:

addon/classes/sampler.js:156

private _initSounds( )

Inherited from Sampler
Sets sounds to new Set() if null on instantiation.
addon/classes/sampler.js:141

private _setGainAndPan( ): Sound

Inherited from Sampler
Applies the gain and pan properties from the Sampler instance to a Sound instance and returns the Sound instance.

Return:

Sound The input sound after having it's gain and pan set