This tutorial gathers in one place the rules for writing Bol Processor scores and grammars. Each section gives the essentials with short examples, and links to the pages that treat the topic in depth. They are listed on the Syntax page. If you are new to the Bol Processor, start with A beginner's tutorial.
👉 All the examples can be copied into a data project (-da file) and played. Most of them come from the projects of the ctests folder distributed with the Bol Processor, such as -da.checkPoly, -da.trySerialTools or -gr.tryTimePatterns.
Scores and grammars
A Bol Processor score is a line of text describing a piece of music: notes, silences, structures and performance controls. Scores are written by hand in data projects (-da files), produced by grammars (-gr files), or created by importing MIDI or MusicXML files.
The same score can be played in real-time MIDI, saved as a MIDI file, turned into a Csound score, or sent in real time to Csound, SuperCollider or any program listening to OSC messages. The syntax doesn't depend on the output.
A grammar is a set of rules that rewrite symbols until only playable elements remain. The result of this process (an item) is a score that follows the rules below. The syntax of grammars is described in the second half of this page.
Part 1. Writing scores
Simple notes
A simple note is a pitch name followed by an octave number. Four conventions are available, chosen in the settings of the project:
| Convention | Note names | Middle C (key 60) |
|---|---|---|
| English | C C# D D# E F F# G G# A A# B, also Db Eb Gb Ab Bb, Cb Fb B# E# | C4 |
| Italian/French | do do# re re# mi fa fa# sol sol# la la# si, also reb mib solb lab sib… | do3 |
| Indian | sa rek re gak ga ma ma# pa dhak dha nik ni | sa4 |
| Key numbers | key#0 to key#127 | key#60 |
In the Italian/French convention, octave numbers are one less than in the English one: do3 is C4. The lowest octave is written 00: C00 is key 0 in English, and do000 in French. Whatever the convention, key# followed by a number is always accepted.
The pitch of a note can be changed by a microtonal scale (see _scale() below and the Microtonality page).
Sound-objects and other terminal symbols
Besides simple notes, a score can contain terminal symbols declared in an alphabet file (-al), such as the bols of tabla drumming: dha ti ge na. When a prototype file (-so) gives them MIDI codes or Csound score lines, they become sound-objects, which carry their own timing properties (pivot, dilation limits, cyclic part…). See Sound-objects, Time-setting of sound-objects and Csound objects.
A terminal with no sound attached is a silent sound-object: it occupies time like a note but plays nothing. Symbols that might be confused with other elements can be written between single quotes, for example '1' and '2' in a grammar spelling out a sequence of digits.
When the alphabet makes it unambiguous, terminals may be written without spaces: with an alphabet containing a, b and c, the string abc is read as a b c.
Sequences, beats and silences
Elements written one after the other form a sequence. Each note or sound-object lasts one beat, whose duration is set by the metronome of the project (60 beats per minute by default).
| Symbol | Meaning | Example |
|---|---|---|
_ | prolongation: the preceding note lasts one more beat | C4 _ _ D4 (C4 lasts 3 beats) |
- | silence of one beat | C4 - D4 |
| integer or fraction | silence of that number of beats | C4 1/2 D4, C4 3/2 D4 |
. (period) | beat separator: the groups it separates take one beat each | C4 D4 . E4 F4 G4 |
_rest or … | undetermined rest: a silence whose duration the Bol Processor calculates | C5 .D5 .G5 . _rest F5 G5 C5 |
& | tie between two notes of the same pitch | C4& &C4 |
<< >> | out-time object, with no duration | <<C4>> |
With the period notation, each group between periods lasts one beat, so its notes are compressed accordingly. C4 D4 . E4 F4 G4 gives two notes of half a beat followed by three notes of a third of a beat. It is equivalent to the polymetric expression {C4 D4 . E4 F4 G4}.
An undetermined rest lets the Bol Processor find a silence that fits the structure. In C5 .D5 .G5 . _rest F5 G5 C5, it finds a silence of a quarter of a beat, so that the last group, _rest F5 G5 C5, lasts one beat with four equal parts. See Undetermined rests in dance.
Ties: & after a note starts a tie, and & before a note of the same pitch ends it, so that both make a single sound. Ties also work across the fields of polymetric expressions: {C4 D4& E4 F4, C3 D3 &D4 F3}. A tie with no matching note is ignored. See Tied notes.
Out-time objects such as <<C4>> are played at their date with no duration (a NoteOn and its NoteOff at the same time). They are used as synchronisation signals or for percussive sounds.
Polymetric expressions
Polymetric expressions are the basic model of time in the Bol Processor. Between braces { }, fields separated by commas are played at the same time:
{C4 D4 B3, A#3 G3}
The rules are simple:
- The first field (the leftmost one) sets the duration of the expression. The other fields are stretched or compressed to the same duration. Above,
C4 D4 B3lasts 3 beats, soA#3andG3last one beat and a half each. - The order of the fields therefore matters:
{A#3 G3, C4 D4 B3}lasts 2 beats, and the three notes of its second field last 2/3 of a beat each. - A first field made of a number sets the duration explicitly:
{3, C4 D4 E4 F4}plays four notes in 3 beats. A field{4}alone is a silence of 4 beats. - Expressions can be nested at any depth:
{{C4 D4, E4 F4 G4}, E5}. - At the top level of a line, braces may be omitted:
C4 D4, E4 F4 G4is read as{C4 D4, E4 F4 G4}.
Polymetric expressions are expanded before time-setting. In the -da.checkPoly project, select an expression and click Expand selection to see how it is read. See Polymetric structures and AI recognition of polymetric notation.
Tempo and time
| Notation | Meaning |
|---|---|
_tempo(x) | multiplies the speed of what follows by x, an integer, decimal or fraction: _tempo(2), _tempo(0.7), _tempo(2/3). Inside a polymetric expression it applies until the end of its field. |
/n | absolute speed marker (older notation): /3 {C4 D4 B3, A#3 G3} is played at speed 3. Prefer _tempo(). |
_mm(x) | metronome in beats per minute, at the start of a grammar: _mm(120) |
_striated | striated time: beats are regular, set by the metronome (the default) |
_smooth | smooth time: no regular beats; durations may follow time patterns |
_breath | marks the next silence as a breath, which also pauses the ticks of a time base |
For example, abc . ab _tempo(2) de . cd forces d e to tempo 2 within the period structure. In smooth time, durations can be given by time patterns t1, t2… defined in a grammar (see Part 2) and placed in the first field of a polymetric expression, for example {10, t1 t2, Part1 Part2}. See Time patterns (smooth time).
Performance controls
Performance controls start with an underscore and modify the notes and sound-objects that follow them, until another value is given or until the end of the enclosing field or expression. They are carried over from one item to the next only as explained on the Carrying over controls page.
_chan(1) _vel(50) _volumecont _volume(80) C4 D4 E4 F4 _volume(30)
| Control | Effect |
|---|---|
_chan(n) | MIDI channel 1 to 16 |
_ins(n), _ins(name) | Csound (or SuperCollider, OSC) instrument, by number or name |
_part(n) | part of a score imported from MusicXML |
_vel(x) | velocity of the notes, 0 to 127 |
_volume(x) | volume (MIDI controller 7 by default, see _volumecontrol(n)) |
_pan(x) | panoramic (controller 10 by default, see _pancontrol(n)) |
_mod(x) | modulation |
_press(x) | channel pressure (aftertouch) |
_pitchbend(x) | pitch bend, in cents if _pitchrange(cents) has been set: _pitchrange(200) _pitchbend(-200) |
_legato(x), _staccato(x) | lengthens or shortens the notes by x percent; _legato(0) restores them |
_transpose(x) | transposition in semitones (may be fractional) |
_scale(name,key) | plays the following notes in a microtonal scale of the tonality file, with its block key: _scale(just intonation,0) |
_switchon(n,c), _switchoff(n,c) | MIDI switch n (64 to 95) on channel c, e.g. the sustain pedal _switchon(64,1) |
_rndvel(x) | random variation of velocities, 0 to 64 |
_rndtime(x) | random shift of dates, in milliseconds |
_srand(n) | seed of the random generator, for repeatable results |
_script(...) | script instruction executed during the performance, e.g. _script(wait for do#2 channel 1) |
_capture(n) | captures incoming MIDI events (see Capture MIDI input) |
Stepwise, continuous and fixed values. By default, a value changes at the next note (step mode). Controls ending with cont make changes continuous between two values: _velcont, _volumecont, _pancont, _modcont, _presscont, _pitchcont, _articulcont, _transposecont. The corresponding step and fixed forms (_volumestep, _volumefixed…) restore stepwise changes or keep the value fixed. The rate forms (_volumerate(n), _pitchrate(n)…) set how often continuous MIDI changes are sent.
_velcont _vel(10) Bb4 A5 Bb4 A5 Bb4 A5 Bb4 A5 _vel(80)
Additional parameters of Csound, SuperCollider or OSC instruments are named in the instrument file and set with _value(name,x), in the mode given by _cont(name), _step(name) or _fixed(name). Values may be placed between the prolongations of a note, so that they change during it:
_ins(Flute) _cont(blurb) _value(blurb,544.5) C4__ _value(blurb,120) __ _value(blurb,-37)___ _value(blurb,0)
See Continuous parameters in Csound and Csound instrument files. Script instructions are described on Interactions in MIDI and Csound.
Serial tools
Serial tools transform the expression that follows them, once the item has been produced:
| Tool | Effect |
|---|---|
_retro | plays the expression backwards |
_rndseq | plays its elements in a random order |
_ordseq | sorts its elements by pitch |
_randomize | resets the random sequence |
_rotate(n) | rotates the sequence by n positions (negative to the left) |
_keyxpand(key,x) | multiplies intervals around a pivot key; _keyxpand(C3,-1) mirrors the melody around C3 |
_keymap(...) | remaps a range of keys onto another |
_retro {A4 B4, C4 D4 E4}
_transpose(-6) _rotate(-2) {{M1 M2}, {_keyxpand(C3,-1) M1}}
See Serial tools (examples of -da.trySerialTools), and the Redesigning grammars page for a grammar using _rotate().
Comments
- A line starting with
//is a comment. - Text between square brackets is a comment inside a line:
[good] C4 D4& E4 &D4 F4. In data projects, a bracketed comment on its own line serves as the title of the item below it.
Part 2. Writing grammars
A grammar rewrites a starting symbol, S, by applying rules until no rule applies. The theory is presented on Bol Processor grammars and Modelling music with grammars.
Layout of a grammar file
-se.tryTimePatterns
RND
_mm(120)
_smooth
gram#1[1] S --> {10,t1 t2,Part1 Part2}
gram#1[2] Part1 --> {t1 t3 t4, C4 D4 E4 F4 - A4}
gram#1[3] Part2 --> {t3 t1, B4 C5 _ E5}
-----
TIMEPATTERNS:
t1=1/1 t2=3/2 t3=4/3 t4=1/2
- The first lines name the files the grammar needs: settings (
-se), alphabet (-al), sound-object prototypes (-so), tonality (-to), Csound or SuperCollider instruments (-cs,-sc), time base (-tb)… - The grammar is divided into subgrammars, separated by a line of dashes (
-----). They are applied in order: once no rule of a subgrammar applies, the next one starts. - Each subgrammar starts with its mode (
RND,ORD…) and may be followed by procedures such as_mm()or_smooth. - Each rule is labelled
gram#i[j]: rule j of subgrammar i. - Sections
TIMEPATTERNS:andTEMPLATES:may follow the last subgrammar.
Rules
A rule has a left argument, an arrow and a right argument: A --> {E1, A#1 F#1} {Tr2 D}. The left argument may contain several symbols ('1' '1' --> '2' '1'). The symbols that are rewritten are variables, such as S, Part1 or Theme32; the others are terminals or notes.
| Arrow | Use |
|---|---|
--> | production only (generating items) |
<-- | analysis only (parsing items) |
<-> | both production and analysis |
An empty right argument is written lambda (or nil, empty, null): D --> lambda erases D. Analysis is described on Parsing music.
Subgrammar modes
| Mode | How rules are chosen and applied |
|---|---|
RND | a rule is chosen at random among the applicable ones, according to their weights |
ORD | the applicable rules are tried in the order they are written |
LIN | the rule is applied at the leftmost (or rightmost) position where a candidate rule matches |
POSLONG | the leftmost position, and there the longest left argument, wins |
SUB | substitution: all occurrences are rewritten in parallel, repeatedly |
SUB1 | substitution in a single pass, often used to replace variables by their values |
TEM | templates, used for analysis |
A rule may also start with LEFT or RIGHT, to rewrite the leftmost or rightmost occurrence of its left argument: gram#2[1] LEFT /steps-1/ '1' --> '1' '1'. See Derivation modes.
Rule weights
A weight between angle brackets, after the label, sets the probability of a rule in RND mode:
| Weight | Meaning |
|---|---|
<12> | weight 12, relative to the weights of the other candidate rules |
<0> | the rule is never chosen |
<inf> | infinite weight: the rule is chosen whenever it applies |
<100-10> | decreasing weight: 100, reduced by 10 each time the rule is used |
<K1=1>, <K1> | weight given by parameter K1, with an initial value; it can be changed in real time by a MIDI controller |
Weights can be learnt from examples: see Learning rule weights.
Flags
Flags are numeric variables written between slashes. On the left of a rule they are conditions; on the right they change values:
gram#1[1] S --> A A2 A3 A1 A A /times=5/
gram#1[2] /times > 0/ #A1 #A2 #A3 A A --> #A1 #A2 A A #A3 /times-1/
- Conditions:
/flag/(not zero),/flag > 0/,/flag = 3/,/flag ≥ 1/… - Changes:
/flag=5/(assignment),/flag+1/,/flag-1/.
See Flags in grammars.
Contexts and wildcards
A rule can require, or forbid, symbols around the part it rewrites:
#Xis a negative context: the rule applies only ifXis not found at that place.- A group between parentheses on the left side is a remote context, which may be found anywhere on that side. Preceded by
#, it must not be found:#(?1 ?3 ?2 ?4). - Wildcards
?1,?2… match any single symbol. The same wildcard on the right side copies the symbol it matched:
gram#2[2] #(?1 ?3 ?2 ?4) ?1 ?2 ?3 ?4 X1234 --> ?1 ?2 ?3 ?4 New ?1 ?3 ?2 ?4 X23
Repetitions and homomorphisms
A master expression (= X) is copied into its slaves (: X). Whatever X becomes during the derivation, its slaves become the same:
S --> _pitchrange(200) (= Tihai) _transpose(-2) (: Tihai) _pitchcont _pitchbend(-200) _transpose(-2) (: Tihai) _pitchbend(+200)
A homomorphism is a mapping of terminals declared in the alphabet file under a label, for example * mapping the open bols of tabla to closed ones (dha --> ta, dhee --> tee). Placed before a master or a slave, the label transforms its copy: (= A) * (: A) plays A, then A with dha replaced by ta. This is how the closed sections of qa'ida are modelled in -gr.dhadhatite (see Qa'ida).
Grammar procedures
Procedures written on a rule, or after the mode of a subgrammar, control the derivation:
| Procedure | Effect |
|---|---|
_goto(g,r) | after applying the rule, continue at rule r of subgrammar g |
_failed(g,r) | if the rule can't be applied, continue at rule r of subgrammar g |
_repeat(n) | applies the rule up to n times (or a K parameter: _repeat(K1)) |
_stop | stops the derivation |
_destru | removes the structural marks (masters, slaves, + marks) from the item |
_randomize, _srand(n) | resets the random sequence, or sets its seed |
_mm(x), _striated, _smooth | metronome and nature of time |
_print, _printOn, _printOff, _stepOn, _stepOff, _traceOn, _traceOff | display or trace the derivation, to check a grammar |
Time patterns and templates
The TIMEPATTERNS: section defines durations as ratios, used in smooth time: t1=1/1 t2=3/2 t3=4/3 t4=1/2. The TEMPLATES: section lists the structures of the items a grammar can produce. It is created with the Produce templates action and used to analyse items.
Summary of files
| Prefix | Content |
|---|---|
-gr | grammar |
-da | data (scores) |
-se | settings: note convention, metronome, nature of time… |
-al | alphabet of terminals, and homomorphisms |
-so | prototypes of sound-objects |
-to | tonality: microtonal scales |
-cs, -sc | Csound and SuperCollider instruments |
-tb | time base |
-wg | rule weights |
+sc | script |
