-
Notifications
You must be signed in to change notification settings - Fork 13
Classes
Arguably, the core of the API. It holds every aspect of a MIDI note "process". I call it process because it requires two signals: one to start and another to end the note. There's also the delta-time, which is not an intuitive concept. So, the NoteEvent class wraps it all and is, therefore, a bridge between an easily readable note concept and the MIDI format NoteOn+NoteOff event(s).
-- Creates a simple C note
NoteEvent.new({pitch = 'C4'})
-- Alternatively
NoteEvent.new({pitch = 60})
-- Creates an E5 chord (with default length of a quarter note)
NoteEvent.new({pitch = {'E3', 'B3'}})
-- Creates an A minor chord arpeggio event(s sequence) (with each note lasting an eighth note)
NoteEvent.new({pitch = {'A3', 'C4', 'E4', 'C5', 'E5'}, duration = '8', sequential = true})| Name | Type | Description |
|---|---|---|
| pitch | string, number or array | Note (or array of notes) to be triggered. Can be a string or valid MIDI note code. Format for string is C#4. |
| duration | string or array |
How long the note should sound.
|
| rest | string | Rest before sounding note. Takes same values as duration. |
| velocity | number | How loud the note should sound, values 1-100. Default: 50
|
| sequential | boolean | If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
|
| repetition | number | How many times this event should be repeated. Default: 1
|
| channel | number | MIDI channel to use. Default: 1
|
| NoteEvent:new (fields) | Creates a new NoteEvent. |
| NoteEvent:print () | Prints event's data in a human-friendly style |
| NoteEvent:set_pitch (pitch) | Sets NoteEvent's pitch |
| NoteEvent:set_duration (duration) | Sets NoteEvent's duration |
| NoteEvent:set_rest (rest) | Sets NoteEvent's rest |
| NoteEvent:set_velocity (velocity) | Sets NoteEvent's velocity |
| NoteEvent:set_sequential (sequential) | Sets NoteEvent's sequential property |
| NoteEvent:set_repetition (repetition) | Sets NoteEvent's repetition |
| NoteEvent:set_channel (channel) | Sets NoteEvent's channel |
| NoteEvent:get_pitch () | Gets pitch(es) of NoteEvent |
| NoteEvent:get_duration () | Gets duration of NoteEvent |
| NoteEvent:get_rest () | Gets rest duration of NoteEvent |
| NoteEvent:get_velocity () | Gets velocity of NoteEvent |
| NoteEvent:get_sequential () | Gets sequentiallity of NoteEvent |
| NoteEvent:get_repetition () | Gets repetition value of NoteEvent |
| NoteEvent:get_channel () | Gets channel # of NoteEvent |
- https://www.noterepeat.com/articles/how-to/213-midi-basics-common-terms-explained#F
- https://www.cs.cmu.edu/~music/cmsip/readings/MIDI%20tutorial%20for%20programmers.html
- http://entertainment.howstuffworks.com/midi1.htm
- http://www.homerecordinghub.com/midi.html
- http://midi.teragonaudio.com/tutr/notenum.htm
- http://midi.teragonaudio.com/tech/midispec/noteon.htm
- http://midi.teragonaudio.com/tech/midispec/noteoff.htm
A ProgramChangeEvent makes it possible to change the "program" of a channel, which is, for the first 15 channels and most of MIDI devices, changing the instrument sound. This event is mostly the same as the raw MIDI data. That's due to the fact that this is one of the shortest events, being just 2 bytes long.
-- Sets the instrument sound or "program" to #25, which is usually the Nylon Guitar
ProgramChangeEvent.new(25)| Name | Type | Description |
|---|---|---|
| pcnumber | number | a valid MIDI patch change number |
| ProgramChangeEvent:new (pcnumber) | Creates a new ProgramChangeEvent to change the track's instrument |
| ProgramChangeEvent:print () | Prints event's data in a human-friendly style |
| ProgramChangeEvent:set_value (value) | Sets ProgramChangeEvent's value |
| ProgramChangeEvent:get_value () | Gets ProgramChangeEvent's value |
- https://en.wikipedia.org/wiki/General_MIDI#Program_change_events
- http://midi.teragonaudio.com/tech/midispec/pgm.htm
- http://midi.teragonaudio.com/tech/midispec.htm
- https://www.noterepeat.com/articles/how-to/213-midi-basics-common-terms-explained#H
An abstraction to represent a MIDI track. It comprises the events (Note, Meta and ProgramChange) and handles it's own setup data, as its header (MTrk) and its meta-event ending. Because MIDI meta events are always tied to tracks, LuaMidi ♫ doesn't expect the user to directly create MetaEvents (which is an API class) objects, but to use Track's methods instead. These methods manage to create these objects and configure them.
-- Creates a new Track
Track.new()
-- Creates a new Track with a "name" meta event (set as "Track1")
local trk = Track.new("Track1")
-- Adds a NoteEvent to the Track
trk:add_events(NoteEvent.new({pitch='C4'}))
-- Adds a ProgramChangeEvent and adds a MetaEvent to describe which instrument it is supposed to be
trk:add_events(ProgramChangeEvent.new(25)):set_instrument_name("Nylon Guitar")| Name | Type | Description |
|---|---|---|
| data | array | events' binary data to be built by the Writer |
| size | array | binary data size to be built by the Writer |
| events | array | events' objects |
| metadata | array | readable metadata |