Added named block and file insertion code to lexer/parser.
[ahxm.git] / doc / language.txt
blobdfed712f60a495667f7e6774af030736c50ccaa3
1 Markup language description - DRAFT
2 ===================================
4 Overview
5 --------
7 Ann Hell Ex Machina scripts consist of a sequence of commands and their
8 possible arguments which run from the top to the bottom. Formatting and
9 indentation can be used in a free-form way.
11 At any time, comments can be inserted in C or C++ style as in the following
12 example:
14  /* this is a C style comment,
15         that spans multiple
16         lines */
17  // this is a C++ style comment, from the double / to the end of the line
19 Whitespace separation is not mandatory and commands can be conveniently
20 joined together if they are unambiguous.
22 For example:
24  T120 M4/4 o5 c4 d8 e% f4 g8 a%16 b% c'1
26 can also be written as
28  T120M4/4o5c4d8e%f4g8a%16b%c'1
30 or, grouped by measures,
32  T120 M4/4 o5 c4d8e% f4g8a%16b% c'1
34 Includes
35 --------
37 Script files can be included from each other by enclosing filenames between
38 backticks, as in the example:
40  `path/to/file`
42 The referenced file will be inserted at that exact point.
44 Tempo
45 -----
47 Tempo is expressed in Beats Per Minute (bpm) as in the next example:
49  T120   /* sets tempo to 120 Beats Per Minute */
51 Obviously, tempo changes are global to all tracks. Though it's normally set
52 at the beginning of a song, it can be used anywhere. You can use marks to
53 be sure that tempo changes occur exactly where you want in all tracks (see
54 documentation for marks). The tempo can be a non-integer number.
56 Measure
57 -------
59 Measure is expressed as in standard music. For example:
61  M4/4   /* classic 4 quarter notes measure */
63 Measure settings are global to all tracks as tempo.
65 Notes
66 -----
68 Syntax:
70  pitch[length][volume]
72 pitch
73 ~~~~~
75 Syntax:
77  letter[alteration][octave]
79 Letter is any from a to g for english notation notes in the currently selected
80 octave, r for rests, or z for a zero-note, that allows setting the length
81 for subsequent notes.
83 The alteration is optional, and is any of # (sharp) or % (flat). If not
84 specified, natural note is assumed.
86 The octave is also optional, and is one or more ocurrencies of ' (one octave
87 higher for each one) or , (one octave lower for each one). If none is
88 specified, note is assumed to belong to the current octave.
90 Examples:
92  a#     /* A sharp */
93  g%     /* G flat */
94  a      /* normal A */
95  c'     /* C, one octave above */
96  f#,,   /* F sharp, two octaves below */
98 length
99 ~~~~~~
101 Optional, with the following syntax:
103  figure[tuplet][mult]
105 Figure is any of 1, 2, 4, 8, 16, 32, 64 measure partitions. Tuplet, if present,
106 is a / followed by a numeric divisor (3 for triplets, etc.). Currently, only 3
107 or 5 tuplets are supported. Mult, if present, can be expressed as an *
108 followed by a numeric multiplier of the figure meaning the final length is
109 that times longer, or as a more music-standard series of dots, adding each
110 one half the length.
112 If no length is present, the note length is inherited from the last one
113 previously defined.
115 Examples:
117  a4     // an A longing one beat
118  r4.    // a rest, longing one beat and a half
119  g8/3   // a G, in triplets of eighths
120  f1*6   // an F longing 6 complete 4/4 measures
121  r4*1.5 // same as r4.
122  z2     // sets note lengths to a half note (no note inserted)
124 Immediate volume
125 ~~~~~~~~~~~~~~~~
127 Optional, can be expressed as a ~ followed by a real number. Numbers below
128 1 will result in quieter notes, and above 1 in louder ones, as this number
129 will be multiplied by the global volume.
131 If no volume is specified, the full global one is used.
133 Examples:
135  a4~0.8 // a quarter note of A at 80% of global volume
137 Measure marks
138 -------------
140 Measure marks help when writing music by asserting that measures last
141 exactly what the key says. They are the equivalent of measure bars in
142 standard music notation and are expressed by the character |. Unlike in
143 standard music, though, they are optional. Apart from checking, these marks
144 do not modify the resulting music in any way.
146 This piece of music will trigger an error in the second mark, just before
147 the c2, because it does not fall in a measure boundary.
149  M3/4 a4 b c | c1 | c2
151 Permanent octave changes
152 ------------------------
154 Permanent octave changing can be expressed as an absolute or
155 relative change. Examples:
157  o2     /* sets octave number 2 (absolute) */
158  o+1    /* sets one octave higher (relative) */
159  o-2    /* sets two octaves lower (relative) */
161 Absolute octave numbers range from 0 to 10. Otherwise, for relative
162 changes, a signed integer number can be used.
164 A complete note trip up can be done this way, using absolute and
165 relative changes and blocks:
167  o0 z16 (cdefgab o+1)*10
169 Octaves can be out of range (the previous example will end with
170 an invalid octave number of 11), but inserting a note after it
171 will generate an error. This is done purposely to allow block
172 repetitions like this one; just change to a valid octave
173 before inserting a new note.
175 Permanent volume changes
176 ------------------------
178 Permament volume can be expressed as an absolute or relative change.
179 Examples:
181  v0.75  /* sets global volume to 0.75 (75%) */
182  v+0.1  /* increments current volume by 0.1 */
183  v-0.3  /* decrements current volume by 0.3 */
185 Absolute volume range from 0 (silence) to 1 (full volume for current
186 samples). Values bigger than 1 can also be used.
188 Transpose
189 ---------
191 Transposition is expressed as a negative or positive number of
192 semitones. By default, each track has an initial transposition
193 of 0. This is an example:
195  t5     /* transpose a fifth up */
197 Note that transpose, as octave changing, can lead to out-of-bound
198 notes. No error will be reported until an invalid note is inserted.
200 Staccato
201 --------
203 The staccato is expressed as the partial time of the total note
204 length that the note will really sound. By default, each track
205 has an initial value of 0.8 (80%). Usual values range from 0.5 (staccato)
206 to 1 (tenuto). For example:
208  s0.9   /* sets staccato to 90%: notes sound more tied together */
210 Groups
211 ------
213 To form chords or more complicated sequences of polyphonic notes,
214 groups can be used. They are enclosed by < and > and separated
215 by semicolons. The group's duration is that of the longest of the parts.
217 The simplest example is a basic chord like this one:
219  <c1 ; e% ; g>  /* a C minor chord for a whole 4/4 measure */
221 Each part of the group can contain more than one note:
223  // the classic bass drum, snare, close and open hat beat
224  <c8rrr crrr ; rrdr rrdr ; g#g#g#a# g#g#g#a#>
226 Glissando
227 ~~~~~~~~~
229 By default, each part of a group start at exactly the same time. To
230 implement strumming (as, for example, in guitar chords, where each note
231 is played slightly after the previous one), the glissando command is used,
232 with an argument expressed as a note length:
234  l16 <c;e;g> /* delay each chord note by a sixteenth */
236 Multipliers and tuplets can also be used (see the note length sections
237 for more information).
239 To disable glissando, use a glissando command with a value of 0.
241 Arpeggiator
242 -----------
244 The arpeggiator allows the programming of automatic repetitions for
245 each note, probably modifying some of its features. It's expressed
246 by the x command followed by a comma separated list of repetition
247 specifications with the following syntax:
249  offset[volume][transpose][track]
251 Offset is a length specification (see Notes) and is the delay of
252 the repetition after the start of the original note (it does NOT express
253 the length of the repeated note; each arpeggiated note last the same as
254 the original one). It can be zero for notes that sound at the same time
255 as the original note.
257 Volume, if specified, is a ~ followed by a real number (see also Notes).
258 This volume is relative to the original volume of the note. If none is
259 specified, the note is repeated at its original volume.
261 Transpose, if specified, is a signed number of semitones to transpose
262 the original note. If no transpose is specified, the pitch of the repeated
263 note will be the same as the original.
265 Track, if specified, is a @ followed by a track number, meaning the note
266 will be inserted in that track (and not in the current one). This allows
267 generating stereo or multichannel arpeggios by having different channel
268 maps on each track.
270 An x command with no repetition specifications effectively disables
271 the arpeggiator.
273 Examples:
275  x4~0.6                 // repeats each note a quarter later at 60% of vol.
276  x4~0.6,2~0.4           // the same, but another repetition later at 40%
277  x8-1,4-2,8*3-3         // 3 chromatic repetitions after each eighth
278  x                      // disable arpeggiator
280 Marks
281 -----
283 To create a mark, use
285  ^name-of-the-mark
287 and, in tracks defined later, you can set the cursor at the mark by using
289  @name-of-the-mark
291 The mark name can use alphanumeric characters and hyphens. An error
292 is generated if a move to mark command is used but the current track's
293 cursor is already beyond that position (i.e. you cannot move 'backwards').
295 Marks can also be used for synchronization by using
297  !name-of-the-mark
299 if the track's cursor does not match that of the mark position, an
300 error is returned reporting the difference in measures.
302 Blocks
303 ------
305 Blocks are marked using pairs of parentheses. The closing one should
306 be followed by a character indicating the operation to do with the
307 block.
309 Repeating blocks
310 ~~~~~~~~~~~~~~~~
312 Blocks that should be repeated a defined number of times can be
313 specified as
315  (code)*times
317 Where code can be anything, from notes to track information, and
318 times the number of times the block will repeat.
320 Named blocks (patterns)
321 ~~~~~~~~~~~~~~~~~~~~~~~
323 A block can be assigned a name to be later inserted. To name it:
325  (code)=name-of-the-block
327 Where code can be anything, from notes to track information, and
328 name-of-the-block the name to be assigned. The name should not
329 contain spaces. The block is not inserted where it's defined; to
330 insert it, the following notation should be used:
332  $name-of-the-block
334 So, for example:
336  (c16defgab)=scale      // define a named block
337  $scale $scale $scale   // insert several times
338  ($scale)*8             // blocks can be nested
340 Named blocks can be redefined anytime:
342  (($drumloop)*8)=phrase         // valid even though drumloop is still undef
343  (cdcdcdcd)=drumloop $phrase    // drumloop resolved when inserting phrase
344  (cdcccdcc)=drumloop $phrase    // inserts now 8 copies of the new drumloop
346 Time specifications
347 -------------------
349 Time should be followed by a unit. That unit can be ms (for milliseconds),
350 b (for beats) or s (for samples). So, for example, sustain can be expressed
353  :sustain=100ms         // sets sustain to 100 milliseconds
354  :sustain=2b            // sets sustain to two quarter notes
355  :sustain=44100s        // sets sustain to 44100 samples
357 Specifying a time in number of samples is not recommended, as it's
358 dependent of the current output frequency; use it only when you know what
359 you are doing.
361 instrument / track options
362 --------------------------
364  :sustain=100ms         // sets instr. sustain to 100 milliseconds
366 Command reference table
367 -----------------------
369 Note commands
370 ~~~~~~~~~~~~~
372  a      Insert note A
373  b      Insert note B
374  c      Insert note C
375  d      Insert note D
376  e      Insert note E
377  f      Insert note F
378  g      Insert note G
379  r      Insert rest (silence)
380  z      Zero note (set length for future notes)
381  o      Set default octave
382  t      Set transpose
383  s      Set staccato
384  v      Set volume
386 Group commands
387 ~~~~~~~~~~~~~~
389  <      Start of group
390  ;      Group delimiter
391  >      End of group
392  l      Set glissando delay
394 Block commands
395 ~~~~~~~~~~~~~~
397  (      Start of block
398  )      End of block
399  *      Block repetition if following )
400  =      Named block assignment if following )
401  $      Named block insertion
402  `      Include script
404 Mark commands
405 ~~~~~~~~~~~~~
407  ^      Set mark
408  @      Move to mark
409  !      Mark assertion
411 Global commands
412 ~~~~~~~~~~~~~~~
414  T      Set tempo
415  M      Set measure
417 Special commands
418 ~~~~~~~~~~~~~~~~
420  |      Measure mark
421  x      Arpeggiator