Mondrian Documentation

State

At any given time, Mondrian has a current state consisting of several properties, many of which are familiar MIDI values. The user-accessible properties are listed in the table below. In addition, Mondrian has an internal state that keeps track of timing and such.

If a sequence of commands is enclosed in parentheses (), then any state changes inside the parentheses are local to the contents of the parentheses, i.e., after the closing parenthesis the state reverts to what it was at the opening parenthesis.

PropertyAdmissible valuesDefault
note0..12760
velocity0..12764
off velocity0..12764
controller0..1270
channel0..150
track1..256 (upper bound can be changed)1
scaleascending list of integers between 0 and 11 0 2 4 5 7 9 11 (major scale)
gapnote lengthNone
time shiftvery small integer0
offsetnote lengthNone
xp, xqpositive integers1

Notes on some properties:

scale
The list of integers gives offsets from the current note at the time of the definition of the scale, extended across all octaves. For example, the initial offsets are 0, 2, 4, 5, 7, 9, 11, and the initial note is 60, so that the initial scale contains the notes ..., 48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72,... In order to define a new scale, enter a list of integers enclosed by dollar signs. For instance, $0 3 5 7 10$ defines a minor pentatonic scale starting at the current note.
gap
Defines a short rest between notes to achieve staccato effects. A value of None implies legato. A numerical value defines the amount to be subtracted from the duration of a note.
time shift
A value of 1 means double time (i.e., double the tempo), and a value of -1 means half time. Larger values are possible but probably useless in practice.
offset
Shifts events relative to the official clock. A positive offset will delay events. A value of None means no offset; a numerical value is interpreted as a note length.
xp, xq
See "Odds and Ends" below.
track limitations
According to MIDI specifications, possible track numbers range from 0 to 65535. Mondrian's limitation to track numbers between 1 and 256 reflects that (a) track 0 is typically reserved for tempo information (and Mondrian implicitly writes tempo changes to track 0), and that (b) extremely large track numbers are rather likely to be typos. The upper bound can easily be increased if desired.

Basic commands

Generally speaking, Mondrian commands are words or characters that may be preceded by a number n, such as 160T, or 3+.

CommandBehavior with number n Behavior without number
aaftertouch event for current key with velocity n aftertouch event with current velocity
bpitch bend event with value n pitch bend 0
Bpitch bend event with value -n pitch bend 0
cset current channel to n no action
Cset current controller to n no action
dincrease time shift by n set time shift to 0
Ddecrease time shift by n set time shift to 0
nset current note to n no action
oset off velocity to n no action
pchannel pressure event with value n channel pressure with current velocity
Pprogram change event with value nno action
Rset resolution (MIDI ticks per quarter, 24..960) no action
sshow current state as well as n show current state
tset current track to nno action
Tset tempo to n bpm (1..600)no action
vset current velocity to nno action
Vsend control change event for current controller, value n no action
wset current offset to nset offset to None
>move up n steps in scalemove up one step in scale
<move down n steps in scalemove down one step in scale
+move up n half stepsmove up one half step
-move down n half stepsmove down one half step
/increase velocity by n increase velocity by 16
\decrease velocity by n decrease velocity by 16

Since the resolution of MIDI files cannot be changed once it has been set, the resolution command R must not occur more than once. Moreover, it must occur before the first note event; if the first note event occurs before the resolution has been set, then Mondrian chooses a default resolution of 96 ticks per quarter.

Note events

Note events are triggered by numbers that are not followed by any of the commands listed here, i.e., a note event is a number followed by any of the following: space, tab, newline, #, |, (, ), [, ], !, $, ", even EOF. In other words, note events are the default, which improves keystroke efficiency.

The number n defines the duration of a note in the following way: If n consists of just one digit, then the duration is 2^-n, e.g., 0 means a whole note, 1 a half note, 2 a quarter note, etc. If n consists of more than one digit, then the last digit serves as an exponent, and the rest as a multiplier. For instance, 54 means 5*2^-4=5/16, 33 means 3*2^-3=3/8, 172 means 17*2^-2=17/4, etc.

CommandBehavior with number n Behavior without number
gset gap to duration defined by nset gap to 0
hplay note of duration defined by n, but do not advance time hold note until explicitly turned off
Nsend note off event for note n send note off event for current note
rrest of duration defined by nno action

Lines and stacks

When Mondrian encounters a note event, it schedules the event at the current time and advances the current time by the duration of the note, so that note events are played consecutively. Brackets [] and vertical bars | are used to stack such lines on top of each other and play them simultaneously. Specifically, when Mondrian encounters an opening bracket, it saves the current time t0. When it encounters a vertical bar, it resets the current time to t0. When it encounters a closing bracket, it advances the current time to t0 plus the duration of the longest line enclosed by the brackets.

This construction can be repeated indefinitely, i.e., you can stack up lines, align stacks and notes in sequences, then form stacks of such compound sequences, etc.

Macros

Macros are defined by enclosing the contents of the macro in exclamation marks, followed by a word (a word starts with a letter or an underscore ("_"); the rest of the word may contain letters, digits, and the characters "_-+=;:.,~@"). For instance, !127v!fff will define a new macro called fff, and calling it will set the current velocity to 127 (fortissimo). If a number n precedes the label of the macro, then the macro is called n times. Macros can contain anything except macro definitions.

Odds and ends

Including files
In order to include a file, just enter the file name enclosed by double quotes ("). For instance, "scales.mon" would include the file scales.mon. If the MONDRIANPATH environment variable is set, then it will be interpreted as a search path for include files.
Comments
Comments begin with a pound sign (#) and extend to the end of a line.
Defining x-tuplets
x-tuplets (e.g., triplets) are defined by multiplying regular note durations by a factor xp/xq, which is set with the x command. A number n followed by x is interpreted as follows: The last digit of n is xq, and the rest is xp, unless n only consists of one digit, in which case xq is n and xp is one. For example, 23x results in xp=2, xq=3, which is the setting for triplets. If x is called without a number, then xp and xq are reset to 1.
Exception handling
Mondrian makes a serious attempt to detect errors and recover from them, if possible. The MIDI file generator has an optional strict mode that'll quit at the slightest irregularity, while MondrianLive bends over backwards in its attempt to recover from exceptions (the reasoning being that you don't want to see any exceptions in a live performance).

Examples

The main ideas in a nutshell
The example from the main page introduces some of the most important ideas of Mondrian. Explanations are on the main page.
Basic drumming
The file drums.mon plays a simple drum sequence. It uses stacks in order to decorate the basic pattern with some variations. It reads some macros from the file gm.mon.
Defining scales
The file scales.mon defines some common scales. In order to have it play scales, just uncomment the bottom part of the file.
Some common constructions
There are two basic ways of constructing chords: We can express them as stacks. For example, if the current note is C and the scale is C major, then a whole-note C major chord can be expressed as [0|2>0|2>0]. We can also use the h command, as in 0h 2> 0h 2> 0 (none of the spaces are necessary, but they make this expression easier to parse for the human reader). This line plays the notes C and E without advancing the current time, and then the note G completes the chord and advances the time to the end of the chord. The h command can also be used to hold notes across stacks.

Adding pitch bend to notes is similar to building chords. For instance, in order to play a whole note, pitch bend up after one eighth, then return to normal pitch after another five eights, we can write [0|3r 40B 53r B].


Peter Brinkmann
$Date: 2006/11/20 01:26:55 $