class: mMML
Music Macro Language for basic sequencing
Description
Music Macro Language is a family of string based languages for describing the notation of music. It was originally created for computers running Basic for writing simple audio alerts and soundtracking video games. It has a simple syntax for quickly notating melodies. There are several different implementations of MML-like languages out there all with slighty different syntax. MEAP’s MML syntax is described below.
An mMML string consists of a series of commands, specified using a letter. Each command may be followed by one or more modifiers. Spaces are allowed between commands but not between a command and its modifier (ie. “cd ef” is valid but “cd 8ef” is not)
Command: “a,b,c,d,e,f,g”
play the specified note
Modifiers:
-: note will be played as a flat (ie. moved down a half step)
+: note will be played as a sharp
>: note will be played an octave up
<: note will be played an octave down
any integer: divisor of note. 8 means 8th note, 16 means 16th note, 43 means 1/43rd of a whole note, etc
.: dotted note length (multiplies previous note length by 1.5). Can chain multiple dots together. For example : “c4.” plays a dotted quarter note while “c4..” plays a dotted dotted quarter note (aka one and a half dotted quarter notes aka nine sixteenth notes)
Command: o
Set octave. Following notes will be played in the specified octave until another “o” command is encountered
Modifier:
- any integer: octave number
Command: v
Set velocity. Following notes will be played with the specified volume until another “v” command is encountered
Modifier:
- integer in range 0-127: Specifies MIDI-like velocity of notes
Command: t
Set tempo. Stays at this tempo until another “t” command is encountered.
Modifier:
- any integer: tempo in beats per minute
Command: r Rest.
Modifiers:
- any integer: divisor of note. 8 means 8th note, 16 means 16th note, 43 means 1/43rd of a whole note, etc
Command: l
Set note length. Following notes will be played with the specified length until another “v” command is encountered
Modifier:
- any integer: divisor of note. 8 means 8th note, 16 means 16th note, 43 means one 1/43rd of a whole note, etc
Class Methods
Constructor
mMML(void(*noteOn_)(uint16_t note uint16_t vel), void (*noteOff_)(uint16_t note), String mml_string;noteOn_: Function pointer to user-provided note on function. Whenever the MML string wants to turn on a note, it will call this function. The function can do/be named whatever you want but MUST be in the specified format (ie two uint16_t arguments and a void return type). The first argument specifies the MIDI note number to turn on and the second specifies the MIDI velocity (0-127) of that note.
noteOff_: Function pointer to user-provided note off function. Whenever the MML string wants to turn off a note, it will call this function. The function can do/be named whatever you want but MUST be in the specified format (ie one uint16_t argument which specifies the MIDI note number to turn off and a void return type)
mml_string: a string describing your musical sequence in the MML format specified above.
void next()Polls the MML string and moves through it if needed. Called in either updateAudio or updateControl depending on your timing requirements
Example