Sequencer - abudaan/qambi GitHub Wiki


#####Properties



#####.activeSongs >Object, read only

Returns an object that contains all currently loaded songs. The id of the songs are the keys of the object.


#####.audioContext >AudioContext, read only

Returns the AudioContext that is used by the sequencer. Note that you should have only one AudioContext instance per document.


#####.debugLevel > Number read & write
  • 0 → logs errors only
  • 1 → logs errors and warnings
  • 2 → logs errors, warnings and info messages
  • 3 → logs everything

The default value is 0


#####.noteNameMode >String, read & write

There are 4 note name modes that you can choose from:

  • sharp → C, C#, D, D#, E, F, F#, G, G#, A, A#, B
  • flat → C, Db, D, Eb, E, F, Gb, G, Ab, A, Bb, B
  • enharmonic-sharp → B#, C#, C##, D#, D##, E#, F#, F##, G#, G##, A#, A##
  • enharmonic-flat → Dbb, Db, Ebb, Eb, Fb, Gbb, Gb, Abb, Ab, Bbb, Bb, Cb

The default note name mode is sharp.

You can also use the following statics:

sequencer.SHARP
sequencer.FLAT
sequencer.ENHARMONIC_SHARP
sequencer.ENHARMONIC_FLAT

In the near feature scales will be added to place the use of accidentals within a more or less harmonic context:

D-major → D, E, F#, G, A, B, C# and for the chromatic notes the accidental # will be used: D#, E#, G#, A#, B#.

D-major-molldur→ the chromatic note A# will be Bb because IV moll-dur in D is G, Bb, D and not G, A#, D.


#####.masterVolume >Float, read & write

Sets or gets the master volume of the sequencer. Besides setting the master volume you can set the volume of a song and of a track.


#####.midiInputs >Array, read only

Array with all available MIDI inports in alphabetical order. The MIDI inports are instances of MIDIPort.


#####.midiOutputs >Array, read only

Array with all available MIDI outports in alphabetical order. The MIDI inports are instances of MIDIPort.


#####.time >Float, read only

Returns the time seconds of the AudioContext that is used by the sequencer.


- - - #####Methods - - -
#####.enableMasterCompressor() > Boolean

Enables or disables the master compressor. The master compressor sits between the output of the songs and the master volume:

output of all songs → master compressor → master volume → destination (your audiocard)


#####.createMidiEvent(ticks, eventType, data1, [data2, channel]) > Number, Number, Number, [Number, Number]

Creates a new MidiEvent of MIDI event type eventType on position ticks. The parameter data2 is optional because not all MIDI event types require this extra parameter.

sequencer.createMidiEvent(0, sequencer.NOTE_ON, 60, 100) // creates a note on event for C4 with velocity 100 at ticks position 0
sequencer.createMidiEvent(480, sequencer.NOTE_OFF, 60) // creates a note off for the same note 480 ticks later

// if you set the velocity of a note on event to 0, it will be interpreted as a note off event
sequencer.createMidiEvent(480, sequencer.NOTE_ON, 60, 0) // same as above


sequencer.createMidiEvent(1920, sequencer.TIME_SIGNATURE, 6, 8) // changes the time signature to 6/8 at ticks 1920

Read more


#####.createPart([name]) > [String]

Creates a new Part, you can provide a name, if left empty the name of the part will be the same as its globally unique id.


#####.createTrack([name]) > [String]

Creates a new Track, you can provide a name, if left empty the name of the track will be the same as its globally unique id.


#####.createSong([config]) > [Object]

Creates a new Song based on the data provided in the configurarion object, see Song.


#####.configureMasterCompressor() > Object

You can configure the master compressor by passing a configuration object. You can use one or more of the following keys:

  threshold; // in Decibels
  knee; // in Decibels
  ratio; // unit-less
  reduction; // in Decibels
  attack; // in Seconds
  release; // in Seconds

See this MDN page for more explanation of the effect of the various keys


#####.init(onFulfilled, [onRejected])

Initializes the sequencer. You must call it before you can use the sequencer. It returns a promise:

sequencer.init().then(

    function onFulFilled(){
      // your stuff
    },

    function onRejected(e){
      // something went wrong
      alert(e);
    }
  );

In general the promise only gets rejected if the browser doesn't support the WebAudio API so it is pretty save to omit an onRejected callback.


#####.createNote(...args)

Returns a note object which with the following read-only properties:

name → the name of the note, a letter from A to G
octave → the octave, a number from -1 to 9
fullName → the name and the octave, e.g. C4 for central C
number → the midi note number
frequency → the frequency of the note
blackKey → whether the note is a black key or not

######arguments

createNote(noteNumber)
createNote(noteNumber, noteNameMode)
createNote(noteName) // actually this is wrong because no value for octave is given; octave will default to 0
createNote(noteName, noteNameMode)
createNote(fullNoteName)
createNote(fullNoteName, noteNameMode)
createNote(noteName, octave)
createNote(noteName, octave, noteNameMode)

All methods return a note object where all the above mentioned properties have the correct value. For instance if you want to know the note number of C#3 you could do this:

console.log(sequencer.createNote('C#3').number);

But there are also special shortcut methods for getting a property of a note based on another property:

  • getNoteName() → createNote(...args).name
  • getNoteOctave() → createNote(...args).octave
  • getFullNoteName() → createNote(...args).fullName
  • getNoteNumber() → createNote(...args).number
  • getFrequency() → createNote(...args).frequency
  • isBlackKey() → createNote(...args).blackKey

These methods can be called with the same parameters as createNote(). For instance:

getNoteOctave(0) → returns -1 because 0 is interpreted as the note number which is the note C-1.

######examples:

getFullNoteName('C#3', 'flat') // returns Db3
getFullNoteName('C#', 3, 'flat') // same as above
getFullNoteName('C#', '3', 'flat') // same as above

getNoteName('Bb', 'sharp') // returns A#
getNoteName('C', 'enharmonic-sharp') // returns B#
getNoteName('C', 'enharmonic-flat') // returns Dbb

getNoteOctave(60) // returns 4

getFrequency('A4') // returns 440
getFrequency('C4') // returns 261.626

sequencer.pitch = 432 // Verdi tuning
getFrequency('A4') // returns 432
getFrequency('C4') // returns 256.869

createNote(102) // returns {name: "F#", octave: 7, fullName: "F#7", number: 102, frequency: 2959.955}
createNote(102, 'flat') // returns {name: "Gb", octave: 7, fullName: "Gb7", number: 102, frequency: 2959.955}

createNote('E7') // returns {name: "E", octave: 7, fullName: "E7", number: 100, frequency: 2637.020}
createNote('e7') // same as above
createNote('E', 7) // same as above
createNote('E', '7') // same as above
createNote('E', '7', 'sharp') // same as above

######standards The naming of the note is according to the scientific pitch notation, and the numbering and the frequency of the notes follows the Midi Tuning Standard. The frequency is based on the pitch set for A4; the standard pitch is 440 Hz but you can change it by setting the value sequencer.pitch. The central C is C4 and has with A4 = 440 Hz a frequency of 261.626 Hz.


#####.getNoteNumber() Shortcut method for `sequencer.createNote(...args).number`
#####.getNoteName() Shortcut method for `sequencer.createNote(...args).name`
#####.getNoteOctave() Shortcut method for `sequencer.createNote(...args).octave`
#####.getFullNoteName() Shortcut method for `sequencer.createNote(...args).fullName`
#####.getFrequency() Shortcut method for `sequencer.createNote(...args).frequency`
#####.isBlackKey() Shortcut method for `sequencer.createNote(...args).blackKey`
#####.unlockWebAudio() On iOS the WebAudio context is initially muted and needs to be unmuted by user interaction, for instance when the user clicks on a button or taps on the screen. In the eventlistener of such a user interaction you can unmute the WebAudio context, see [this article](http://paulbakaus.com/tutorials/html5/web-audio-on-ios/) of Paul Bakaus for more details.

The function sequencer.unlockWebAudio() is called when you call song.play(), which means that if you are calling song.play() in the eventlistener of a user interaction, the WebAudio context will be unmuted automatically and you don't need to worry about anything.

However if you want to start your song by code, you should call sequencer.unlockWebAudio() on beforehand. This also applies if you call sequencer.processEvent() by code.


- - - ######Note name modes - - -
#####.SHARP Notename mode, uses note names: C, C#, D, D#, E, F, F#, G, G#, A, A#, B
#####.FLAT Notename mode, uses note names: C, Db, D, Eb, E, F, Gb, G, Ab, A, Bb, B
#####.ENHARMONIC_SHARP Notename mode, uses note names: B#, C#, C##, D#, D##, E#, F#, F##, G#, G##, A#, A##
#####.ENHARMONIC_FLAT Notename mode, uses note names: Dbb, Db, Ebb, Eb, Fb, Gbb, Gb, Abb, Ab, Bbb, Bb, Cb
- - - ######MIDI Messages - - - *Channel voice commands:*
#####.NOTE_OFF MIDI command 128
#####.NOTE_ON MIDI command 144
#####.POLY_PRESSURE MIDI command 160
#####.CONTROL_CHANGE MIDI command 176
#####.PROGRAM_CHANGE MIDI command 192
#####.CHANNEL_PRESSURE MIDI command 208
#####.PITCH_BEND MIDI command 224
*Other MIDI messages:*
#####.TEMPO Tempo event, used to change the tempo of a song.
#####.TIME_SIGNATURE Time signature event, used to change the time signature of a song.
#####.END_OF_TRACK Event that indicates the end of a track
⚠️ **GitHub.com Fallback** ⚠️