Muscript
is a language for typesetting music.
This page describes the use of Variables,
as introduced in muscript 3.1.
This part of the syntax is still under development;
future backward-compatibility is not guaranteed.
Variable-names begin with a $ like Perl variables.
Of the remainder,
the first character must be an upper-case A-Z,
and the rest upper-case letters or digits 0-9.
This makes the variable easy to spot within the text.
Some examples:
$A $B6 $MIDDLE8 $RIFF1 $CODA
$B4 = 8 [D G B'] $RIFF1 = 83 [E 163 e' G G# B 83 d' 163 B 83 A 163 B] 2 restThe variable-definition must have a line to itself. On the left hand side of the equation, the variable-name, as in Perl, has a dollar in front. The right-hand-side may contain variable references; by default, these are not substituted here at definition-time, they are substituted recursively later at substitution-time. So:
$A = cycle? D# : F# : A ?
$B = [$A $A]
=1 treble $B $B $B $B
evaluates to: =1 treble [D# F#] [A D#] [F# A] [D# F#]
If you want to force substitution here at definition-time,
use == a double equal-sign. So:
$A = cycle? D# : F# : A ?
evaluates to:
$B == [$A $A]
=1 treble $B $B $B $B
=1 treble [D# F#] [D# F#] [D# F#] [D# F#]
$B5 = { # comments starting with a # are allowed here | 4.3 =1 treble 4 G A B c =2 bass 8 rest 4 g e d 8 D }This allows whole sections of music to be stored in a variable. When substituted, they are considered not to start with a newline, but they are considered to finish with an inbuilt newline. Therefore whole pieces of music can be expressed on one line, e.g.:
$OPENING $VERSE $CHORUS $VERSE $CHORUS $MIDDLE8 $VERSE $CHORUS $CHORUS
If you want to force substitution here at definition-time, use == a double equal-sign. This can lead to recursion:
$B5 == { | 4.3 $B == [$A $A] =1 4 G $B c $B =2 8 rest 4 g e d 8 D =1 $B $B $B $B $C6 == { $D7 == { $E8 = { $F9 == { =1 1 $B } } } } $C6 | $E8 =1 4 G $B B c =2 8 rest 4 g e d 8 D }In this (absurd) example, the value of the $E8 and $F9 variables will only be set when $B5 is actually used; until then, $E8 and $F9 remain undefined. But the variables $B5, $B, $C6 and $D7 are defined immediately, and $B5 contains no remaining dollar-signs outside the $E8 definition.
To make changing the notes of a chord easier, a very restricted one-line syntax allows :
$B2-4 = G : Bb : dwhich is neater than the equivalent :
$B2 = G $B3 = Bb $B4 = dOnly single-digit suffixes are allowed.
Variables can be generated by one of a number of in-built functions:
aaba,
cycle,
leibnitz,
morse_thue,
rabbit and
random
These functions return one of their arguments each time they are invoked;
they get invoked every time the variable occurs in the text and is substituted.
$B = rabbit? 8 [D G B'] : 8 [Eb G A] ?
Think of the question-mark as introducing the question "which?",
and think of the colon : as a field-separator,
like it is in /etc/passwd.
(These characters are not otherwise used in muscript syntax.)
There must be no space between the function-name
and the first question-mark.
Spaces inside the question-marks, or next to the colons, are stripped away:
you can use them for clarity.
If you want a multi-line field, you have to
define a multiline variable,
then use that variable in the field.
$A = leibnitz? 2 : A : B : c : d : e ?
=1 $A $A $A $A $A $A $A $A $A $A $A $A $A $A $A $A
=1 A B B c B c c d B c c d c d d e
When a variable is encountered within the music (rather than just within a recursion in a variable-definition), then it is substituted, and any new variables which appear as a result are themselves substituted, and so on recursively until there are no variable-names left at all. Then the pre-processing is complete, and the result is interpreted by muscript.
muscript -pp filenameThis -pp command-line option outputs the pre-processed text, so that you can, for example, edit it by hand.
See alberti.txt, fingerpickin.txt and generators.txt in samples/index.html
test.pl,
the test-script that this version passes
index.html,
the muscript home page
Fractals, Chaos, Power Laws, Manfred Schroeder, 1991,
W.H. Freeman, New York
en.wikipedia.org/wiki/Thue-Morse_sequence
en.wikipedia.org/wiki/Fibonacci_word,
about the Rabbit Sequence.
Peter Billam http://www.pjb.com.au