Skip to content

Classes

Pedro Alves Valentim edited this page Feb 22, 2018 · 11 revisions

Summary

NoteEvent

Description

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).

Usage

-- 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})

Properties

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.
  • 1 : whole
  • 2 : half
  • d2 : dotted half
  • 4 : quarter
  • d4 : dotted quarter
  • 8 : eighth
  • 8t : eighth triplet
  • d8 : dotted eighth
  • 16 : sixteenth
  • Tn : where n is an explicit number of ticks
If an array of durations is passed then the sum of the durations will be used.
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

Methods

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

External links

ProgramChangeEvent

Description

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.

Usage

-- Sets the instrument sound or "program" to #25, which is usually the Nylon Guitar
ProgramChangeEvent.new(25)

Properties

Name Type Description
pcnumber number a valid MIDI patch change number

Methods

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

External links

Track

Description

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.

Usage

-- 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")

Properties

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

Methods

Track:new ([name]) Creates a new Track
Track:add_events (events, map_function) Adds an event-list (or single event) to the track.
Track:get_events (filter) Gets events from Track
Track:set_tempo (bpm) Sets Track's tempo
Track:set_time_signature (num, den[, midi_clocks_tick=24[, notes_midi_clock=8]]) Sets Track's time signature
Track:set_key_signature (sf, mi) Sets Track's key signature
Track:set_text (text) Sets text to Track
Track:set_copyright (copyright) Sets copyright to Track
Track:set_name (name) Sets a name to Track
Track:set_instrument_name (instrument_name) Sets instrument name to Track
Track:set_lyric (lyric) Sets lyric to Track
Track:set_marker (marker) Sets marker text to Track
Track:set_cue_point (cue_point) Sets cue point to Track
Track:poly_mode_on () Activates poly mode
Track:get_text () Gets text from Track
Track:get_copyright () Gets copyright from Track
Track:get_name () Gets name from Track
Track:get_instrument_name () Gets instrument name from Track
Track:get_lyric () Gets lyric from Track
Track:get_marker () Gets marker from Track
Track:get_cue_point () Gets cue point from Track

External links

Writer

Description

Properties

Methods

LuaMidi

Description

Properties

Methods