Class: Instrument

Instrument

Instrument Class. Use it to play music from the browser

Constructor

new Instrument()

Create an instrument. It will import audio context and prepare its internal state.
Source:

Methods

get()

Loads instrument from the web and stores it as a resolvable promise
Parameters:
Name Type Description
instrumentName. List of all instrument names in src/constants/INSTRUMENTS
Source:
Returns:
Promise

play(notes, meta, note)

play array of notes
Parameters:
Name Type Description
notes
meta
note settings
Source:
Returns:
Promise

startPlayingChordByChordName(firstNoteName, chordName, note)

startPlayingChordByChordName
Parameters:
Name Type Description
firstNoteName
chordName
note settings
Source:
Returns:
Promise
Example
const instrument = new Instrument();
instrument.startPlayingChordByChordName('A3', 'maj', {instrumentName: 'acoustic_grand_piano', startTimeInMS: 0, durationInMS: 1000, endTimeInMS: 1000})

startPlayingChordByNoteNames(noteNames, note)

Start playing chord by note names
Parameters:
Name Type Description
noteNames
note settings
Source:
Returns:
Promise
Example
const instrument = new Instrument();
instrument.startPlayingChordByNoteNames(['A3','C3','E3'], {instrumentName: 'acoustic_grand_piano', startTimeInMS: 0, durationInMS: 1000, endTimeInMS: 1000})

startPlayingNote(note)

Start playing note, if note.payload.durationInMS is -1 it will keep playing infinitely until it is explicitly stopped. { payload: { id, instrumentName, startTimeInMS, instrumentName, name, gain, duration }}
Parameters:
Name Type Description
note
Source:
Returns:
Promise

stop(notes, meta, note)

stop playing array of notes
Parameters:
Name Type Description
notes
meta
note settings
Source:
Returns:
Promise

stopPlayingChordByChordName(firstNoteName, chordName, note)

stopPlayingChordByChordName
Parameters:
Name Type Description
firstNoteName
chordName
note settings
Source:
Returns:
Promise
Example
const instrument = new Instrument();
instrument.stopPlayingChordByChordName('A3', 'maj', {instrumentName: 'acoustic_grand_piano', startTimeInMS: 0, durationInMS: 1000, endTimeInMS: 1000})

stopPlayingChordByNoteNames(noteNames, note)

Stop playing chord by note names
Parameters:
Name Type Description
noteNames
note settings
Source:
Returns:
Promise
Example
const instrument = new Instrument();
instrument.stopPlayingChordByNoteNames(['A3','C3','E3'], {instrumentName: 'acoustic_grand_piano', startTimeInMS: 0, durationInMS: 1000, endTimeInMS: 1000})

stopPlayingNote(note)

Stop playing note { payload: { id, instrumentName, startTimeInMS, instrumentName, name, gain, duration }}
Parameters:
Name Type Description
note
Source:
Returns:
Promise