MidiEvent - abudaan/qambi GitHub Wiki

####MIDI Events

Some MIDI events are only sent over a specific channel, these events are called channel events. Note on and note off events are examples of channel events. By default, all MIDI events are sent to channel 1. You only have to worry about channel numbers if you want to use external soft- or hardware devices for playback or processing of MIDI events.

There are 2 ways you can set a channel for an event: 1) add an extra fifth parameter to the constructor, or 2) add the zero-based value of the channel number to value of the event type. For instance we want to send a C4 note with velocity 100 over channel 5 at ticks position 480:

// with additional fifth parameter
sequencer.createMidiEvent(480, sequencer.NOTE_ON, 60, 100, 5)

// add channel to event type, note: 5 zero-based is 4
sequencer.createMidiEvent(480, sequencer.NOTE_ON + 4, 60, 100)

sequencer.createMidiEvent(480, 148, 60, 100) // same a above
sequencer.createMidiEvent(480, 0x94, 60, 100) // same a above, hexadecimal

In the second way, you pass a so called status byte instead of an event type. A status byte is the sum of a command and a zero-based channel number. This is according to the MIDI standard. The MIDI protocol is very efficient and it doesn't want to use an extra byte for the channel number, so instead the event type (command) and channel number are combined in one single byte:

NOTE OFF 128 0x80
channel 1 128 0x80
channel 2 129 0x81
channel 3 130 0x82
channel 4 131 0x83
channel 5 132 0x84
channel 6 133 0x85
channel 7 134 0x86
channel 8 135 0x87
channel 9 136 0x88
channel 10 137 0x89
channel 11 138 0x8A
channel 12 139 0x8B
channel 13 140 0x8C
channel 14 141 0x8D
channel 15 142 0x8E
channel 16 143 0x8F
NOTE ON 144 0x90
channel 1 145 0x90
channel 2 146 0x91
channel 3 147 0x92
channel 4 148 0x93
channel 5 149 0x94
and so on.

#####Properties



#####.id >String, read only

Unique id of the event. The id start with an M, followed by the event number and the date in milliseconds.


#####.eventNumber >Number, read only

Consecutive number of the event. The number starts at 0 every time the sequencer is initialized.


#####.ticks >Number, read only

Position of the event in ticks


#####.type >Number, read only

MIDI type of the event, see Sequencer


#####.data1 >Number, read only

The data1 byte of the MIDI event.


#####.data2 >Number, read only

The data2 byte of the MIDI event.


#####.muted >Boolean, read & write

Mutes or unmutes the event.


- - - *only available for channel events:*

#####.channel

Number, read only

The MIDI channel that this event gets sent to during playback. Has only effect if you send event to an external soft- or hardware MIDI device.


#####.command >Number, read only

Has the same value a type.


#####.status >Number, read only

The sum of command and channel, for example if you create a note on event for channel 3, the value of status will be 144 + 3 = 147.


- - - *only available for note on and note off events:* - - -
#####.note >Object, read only

A Note object based on the event's note number


#####.noteName >String, read only

The full note name of event's note, e.g. C4


#####.noteNumber >Number, read only

The note number, same as data1


#####.velocity >Number, read only

The velocity, same as data1


#####.octave >Number, read only

The octave of the event's note.


#####.frequency >Float, read only

The frequency of the event's note.


- - - *only available for tempo events:* - - -
#####.tempo >Number, read only

The tempo in BPM of the tempo event


- - - *only available for time signature events:* - - -
#####.nominator >Number, read only

The nominator of the new time sigature, e.g. 6/8


#####.denominator >Number, read only

The denominator of the new time sigature, e.g. 6/8


#####Methods



#####.clone()

Returns a clone of the MidiEvent. All members are copied to a new MidiEvent instance, so id and eventNumber of the clone are unique.


#####.move(ticks) >Number

Set the add or subtracts ticks from the ticks value of the event.


#####.moveTo(...position) >Position

Sets the ticks value of the event to the ticks value of the provided position. See position. You can only use this method on events that already have been added to a song. This is because calculating the position depends on the song's tempo and time-signature events.

let event = sequencer.createMidiEvent(0, sequencer.NOTE_ON, 60, 100);

// move event to the first beat of the fifth bar
event.moveTo('barsandbeats', 5, 1, 1, 0)

#####.transpose(semitones) >Number

Transposes the event by the provided number of semitones. Float values are rounded to whole numbers. You can provide both negative and positive numbers.


#####.setPitch(noteNumber) >Number

Transposes the event to the provided MIDI note number.


#####.reset([fromPart=true, fromTrack=true, fromSong=true]) >[Boolean, Boolean, Boolean]

If an event is added to a part, that part is referenced by the member part of the event. If the part is added to a track, that track is referenced by the member track of the event. And if the track is added to a song, that song is referenced by the song member of the event. With the method reset you can clear these references. The method is called automatically as soon as you remove the event from a part, a track or a song, so you shouldn't have to use this method very often.

⚠️ **GitHub.com Fallback** ⚠️