Fix file permissions.
[ahxm.git] / doc / ahs_overview_i.txt
blob57da7af5238a2017f5743f3215415c10e2d6250b
1 Ann Hell Scripting - I: Basic Commands
2 ======================================
4 This document describes the basic commands for the Ann Hell Scripting
5 language. These commands are those directly related with the music
6 being generated, as notes and their appropriate properties and global
7 song information as tempo and measure. Also, a global description of
8 the AHS syntax is included here.
10 Syntax overview
11 ---------------
13 Ann Hell Ex Machina scripts consist of a sequence of commands and their
14 possible arguments which run from the top to the bottom. Formatting and
15 indentation can be used in a free-form way.
17 At any time, comments can be inserted in C language style as in the following
18 example:
20  /* this is a C style comment,
21         that spans multiple
22         lines */
24 Whitespace separation is not mandatory and commands can be conveniently
25 joined together if they are unambiguous.
27 For example:
29  T120 M4/4 o5 c4 d8 e& f4 g8 a&16 b& c'1
31 can also be written as
33  T120M4/4o5c4d8e&f4g8a&16b&c'1
35 or, grouped by measures,
37  T120 M4/4 o5 c4d8e& f4g8a&16b& c'1
39 Includes
40 --------
42 Script files can be included from each other by enclosing filenames between
43 backticks, as in the example:
45  `path/to/file`
47 The referenced file will be inserted at that exact point.
49 Tempo
50 -----
52 Tempo is expressed in Beats Per Minute (bpm) as in the next example:
54  T120   /* sets tempo to 120 Beats Per Minute */
56 Obviously, tempo changes are global to all tracks. Though it's normally set
57 at the beginning of a song, it can be used anywhere. You can use marks to
58 be sure that tempo changes occur exactly where you want in all tracks (see
59 documentation for marks). The tempo can be a non-integer number.
61 Measure
62 -------
64 Measure is expressed as in standard music notation. For example:
66  M4/4   /* classic 4 quarter notes measure */
68 Measure settings are global to all tracks as tempo.
70 Notes
71 -----
73 Syntax:
75  pitch[length][volume]
77 pitch
78 ~~~~~
80 Syntax:
82  letter[alteration][octave]
84 Letter is any from a to g for english notation notes in the currently selected
85 octave, r for rests, or z for a zero-note, that allows setting the length
86 for subsequent notes without doing anything more.
88 The alteration is optional, and is any of # (sharp) or & (flat). If not
89 specified, natural note is assumed.
91 The octave is also optional, and is one or more ocurrencies of ' (one octave
92 higher for each one) or , (one octave lower for each one). If none is
93 specified, note is assumed to belong to the current octave.
95 Examples:
97  a#     /* A sharp */
98  g&     /* G flat */
99  a      /* normal A */
100  c'     /* C, one octave above */
101  f#,,   /* F sharp, two octaves below */
103 length
104 ~~~~~~
106 Optional, with the following syntax:
108  figure[tuplet][mult]
110 Figure is any of 1, 2, 4, 8, 16, 32, 64 measure partitions. Tuplet, if present,
111 is a / followed by a numeric divisor (3 for triplets, etc.). Currently, only 3
112 or 5 tuplets are supported. Mult, if present, can be expressed as an *
113 followed by a numeric multiplier of the figure meaning the final length is
114 that times longer, or as a more music-standard series of dots, adding each
115 one half the length.
117 If no length is present, the note length is inherited from the last one
118 previously defined.
120 Examples:
122  a4     // an A longing one beat
123  r4.    // a rest, longing one beat and a half
124  g8/3   // a G, in triplets of eighths
125  f1*6   // an F longing 6 complete 4/4 measures
126  r4*1.5 // same as r4.
127  z2     // sets note lengths to a half note (no note inserted)
129 Immediate volume
130 ~~~~~~~~~~~~~~~~
132 Optional, can be expressed as a ~ followed by a real number ranging from
133 0 (silence) to 1 (full volume).
135 If no volume is specified, the full global one is used.
137 Examples:
139  a4~0.8 // a quarter note of A at 80% of global volume
141 Measure marks
142 -------------
144 Measure marks help when writing music by asserting that measures last
145 exactly what the metric says. They are the equivalent of measure bars in
146 standard music notation and are expressed by the character |. Unlike in
147 standard music, though, they are optional. Apart from checking, these marks
148 do not modify the resulting music in any way.
150 This piece of music will trigger an error in the second mark, just before
151 the c2, because it does not fall in a measure boundary.
153  M3/4 a4 b c | c1 | c2
155 Permanent octave changes
156 ------------------------
158 Permanent octave changing can be expressed as an absolute or
159 relative change. Examples:
161  o2     /* sets octave number 2 (absolute) */
162  o+1    /* sets one octave higher (relative) */
163  o-2    /* sets two octaves lower (relative) */
165 Absolute octave numbers range from 0 to 10. Otherwise, for relative
166 changes, a signed integer number can be used.
168 A complete note trip up can be done this way, using absolute and
169 relative changes and blocks:
171  o0 z16 (cdefgab o+1)*10
173 Octaves can be out of range (the previous example will end with
174 an invalid octave number of 11), but inserting a note after it
175 will generate an error. This 'lazy error checking' is done purposely
176 to allow block repetitions like this one; just change to a valid octave
177 before inserting a new note.
179 Permanent volume changes
180 ------------------------
182 Permament volume can be expressed as an absolute or relative change.
183 Examples:
185  v0.75  /* sets global volume to 0.75 (75%) */
186  v+0.1  /* increments current volume by 0.1 */
187  v-0.3  /* decrements current volume by 0.3 */
189 Absolute volume range from 0 (silence) to 1 (full volume).
191 Dynamic (random) volumes
192 ~~~~~~~~~~~~~~~~~~~~~~~~
194 (New in 1.0.10) If the volume command has two arguments separated by
195 a comma, each note will be generated with a random value from within
196 that range.
198  v0.2,0.8 /* next volumes will be from 0.2 to 0.8, randomly chosen */
200 Transpose
201 ---------
203 Transposition is expressed as a negative or positive number of
204 semitones. By default, each track has an initial transposition
205 of 0. This is an example:
207  t5     /* transpose a fifth up */
209 Note that transpose, as octave changing, can lead to out-of-bound
210 notes. No error will be reported until an invalid note is inserted.
212 Staccato
213 --------
215 The staccato is expressed as the partial time of the total note
216 length that the note will really sound. By default, each track
217 has an initial value of 0.8 (80%). Usual values range from 0.5 (staccato)
218 to 1 (tenuto). For example:
220  s0.9   /* sets staccato to 90%: notes sound more tied together */
222 Groups
223 ------
225 To form chords or more complicated sequences of polyphonic notes,
226 groups can be used. They are enclosed by < and > and separated
227 by semicolons. The group's duration is that of the longest of the parts.
229 The simplest example is a basic chord like this one:
231  <c1 ; e& ; g>  /* a C minor chord for a whole 4/4 measure */
233 Each part of the group can contain more than one note:
235  // the classic bass drum, snare, close and open hat beat
236  <c8rrr crrr ; rrdr rrdr ; g#g#g#a# g#g#g#a#>
238 Glissando
239 ~~~~~~~~~
241 By default, each part of a group start at exactly the same time. To
242 implement strumming (as, for example, in guitar chords, where each note
243 is played slightly after the previous one), the glissando command is used,
244 with an argument expressed as a note length:
246  l16 <c;e;g> /* delay each chord note by a sixteenth */
248 Multipliers and tuplets can also be used (see the note length sections
249 for more information).
251 To disable glissando, use a glissando command with a value of 0.
253 Arpeggiator
254 -----------
256 The arpeggiator allows the programming of automatic repetitions for
257 each note, probably modifying some of its features. It's expressed
258 by the x command followed by a comma separated list of repetition
259 specifications with the following syntax:
261  offset[volume][transpose][track]
263 Offset is a length specification (see Notes) and is the delay of
264 the repetition after the start of the original note (it does NOT express
265 the length of the repeated note; each arpeggiated note last the same as
266 the original one). It can be zero for notes that sound at the same time
267 as the original note.
269 Volume, if specified, is a ~ followed by a real number (see also Notes).
270 This volume is multiplied by the original volume of the note. If none is
271 specified, the note is repeated at its original volume.
273 Transpose, if specified, is a signed number of semitones to transpose
274 the original note. If no transpose is specified, the pitch of the repeated
275 note will be the same as the original.
277 Track, if specified, is a / followed by a track offset, meaning the note
278 will be inserted that tracks after current one (and not in the current one).
280 An x command with no repetition specifications effectively disables
281 the arpeggiator.
283 Examples:
285  x4~0.6                 // repeats each note a quarter later at 60% of vol.
286  x4~0.6,2~0.4           // the same, but another repetition later at 40%
287  x8-1,4-2,8*3-3         // 3 chromatic repetitions after each eighth
288  x8-1,4-2,8*3-3/2       // the same, last note is inserted 2 tracks after
289  x                      // disable arpeggiator
291 Marks
292 -----
294 To create a mark, use
296  ^name-of-the-mark
298 and, in tracks defined later, you can set the cursor at the mark by using
300  @name-of-the-mark
302 The mark name can use alphanumeric characters and hyphens. An error
303 is generated if a move to mark command is used but the current track's
304 cursor is already beyond that position (i.e. you cannot move 'backwards').
306 Marks can also be used for synchronization by using
308  !name-of-the-mark
310 if the track's cursor does not match that of the mark position, an
311 error is returned reporting the difference in measures.
313 Special marks
314 ~~~~~~~~~~~~~
316 The START mark defines the starting point of subsequent tracks. By default,
317 it's the very begining of the song. If it's defined, all next songs will
318 start at this point.
320 The END mark is an automatic one that always points to the furthest time
321 seen on a track. So, combining the START and END marks, it's possible to
322 mix different songs to play one after the other, as in
324         /* first song */
325         `song1.ahs`
326         
327         /* move to the furthest point */
328         @END
329         
330         /* set start of new tracks there */
331         ^START
332         
333         \
334         /* second song */
335         `song2.ahs`
337 Moving back
338 -----------
340 Sometimes is useful to move back the internal 'cursor' of the song; for
341 example, when a voice starts just a note before a mark (an _anacrusa_).
342 The back command is implemented with the letter k followed by an optional
343 note length specification.
345  /* this instrument is silent until a quarter before tutti */
346  @tutti
348  /* move back one quarter and play it */
349  k4 g
351  /* tutti really starts here */
352  c'1
354 The back command can also be used to implement rudimentary chords:
356  /* a C major chord, using backs (same as <c1;e;g>) */
357  c1kekg
359 Blocks
360 ------
362 Blocks are marked using pairs of parentheses. The closing one should
363 be followed by a character indicating the operation to do with the
364 block.
366 Repeating blocks
367 ~~~~~~~~~~~~~~~~
369 Blocks that should be repeated a defined number of times can be
370 specified as
372  (code)*times
374 Where code can be anything, from notes to track information, and
375 times the number of times the block will repeat.
377 Named blocks (patterns)
378 ~~~~~~~~~~~~~~~~~~~~~~~
380 A block can be assigned a name to be later inserted. To name it:
382  (code)=name-of-the-block
384 Where code can be anything, from notes to track information, and
385 name-of-the-block the name to be assigned. The name should not
386 contain spaces. The block is not inserted where it's defined; to
387 insert it, the following notation should be used:
389  $name-of-the-block
391 So, for example:
393  (c16defgab)=scale      // define a named block
394  $scale $scale $scale   // insert several times
395  ($scale)*8             // blocks can be nested
397 Named blocks can be redefined anytime:
399  (($drumloop)*8)=phrase         // valid even though drumloop is still undef
400  (cdcdcdcd)=drumloop $phrase    // drumloop resolved when inserting phrase
401  (cdcccdcc)=drumloop $phrase    // inserts now 8 copies of the new drumloop
403 Using blocks for random playing
404 -------------------------------
406 Blocks can be used to select alternatives for random playing. These alternatives
407 are defined inside a block and separated by a : (colon). This way, when inserting
408 a block, one of the subblocks will be randomly selected.
410 For example:
412  /* play 4 whole note chords; they can be CM, FM or GM at random */
413  z1 (<c;e;g> : <c;f;a> : <d;g;b> )*4
415  /* if you want different weights, just do it by repeating */
416  /* this way, CM will be 50%, FM 25% and GM 25% */
417  (<c;e;g> : /* CM again */ <c;e;g> : <c;f;a> : <d;g;b> )=chords1
419  $chords1
421 Alterations
422 -----------
424 (New in 1.0.8). Alterations can be implemented with the A command. The
425 argument to this command is a string specified up to seven alterations for
426 the natural notes c, d, e, f, g, a and b, where each alteration can be #
427 (sharp), & (flat) or - (natural). This command is useful to specify
428 tonalities.
430 For example:
432  /* plays a natural C scale (C Major) */
433  c8defgab c1
435  /* sets the alterations to match the C Minor mode;
436     flats on e, a and b, no change on the rest. From now on,
437     all references to those notes will be altered */
438  A--&--&&
440  /* and now play a C Minor scale */
441  c8defgab c1
443  /* set now to G Major (notes not specified are naturals) */
444  A---#
445  g8abcdef g1
447  /* set back to C Major */
450 Standard tonalities
451 ~~~~~~~~~~~~~~~~~~~
453 Major and minor modes for classic tonalities are predefined as named
454 blocks and implemented as alterations. The name is formed by the uppercase
455 note, an optional modifier (# for sharp and & for flat, as always) and
456 an M or m (for Major and minor):
458  /* set tonality to C Major */
459  $CM
460  /* set tonality to B flat Major */
461  B&M
462  /* set tonality to F sharp minor */
463  F#m
465 Library path
466 ------------
468 (New in 1.0.12) Source and data files are seeked from a number of directories
469 or paths, as the ~/ahxmlib directory, for example. From the very start, the
470 Ann Hell Scripting compiler always have supported the -L switch, to add more
471 directories to that library path. Now, the L directive can also be used to do
472 the same from a source file:
474  /* also search for files in /usr/share/sounds/sf2 */
475  L/usr/share/sounds/sf2
477 Command reference table
478 -----------------------
480 Note commands
481 ~~~~~~~~~~~~~
483  a      Insert note A
484  b      Insert note B
485  c      Insert note C
486  d      Insert note D
487  e      Insert note E
488  f      Insert note F
489  g      Insert note G
490  r      Insert rest (silence)
491  z      Zero note (set length for future notes)
492  o      Set default octave
493  t      Set transpose
494  s      Set staccato
495  v      Set volume
496  A      Set alterations
498 Group commands
499 ~~~~~~~~~~~~~~
501  <      Start of group
502  ;      Group delimiter
503  >      End of group
504  l      Set glissando delay
506 Block commands
507 ~~~~~~~~~~~~~~
509  (      Start of block
510  )      End of block
511  *      Block repetition if following )
512  =      Named block assignment if following )
513  $      Named block insertion
514  `      Include script
516 Mark commands
517 ~~~~~~~~~~~~~
519  ^      Set mark
520  @      Move to mark
521  !      Mark assertion
523 Global commands
524 ~~~~~~~~~~~~~~~
526  T      Set tempo
527  M      Set measure
529 Special commands
530 ~~~~~~~~~~~~~~~~
532  |      Measure mark
533  k      Move back
534  x      Arpeggiator
535  L      Add to library path
537 ----
538 Angel Ortega - http://triptico.com