-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.html
More file actions
275 lines (256 loc) · 10.4 KB
/
variables.html
File metadata and controls
275 lines (256 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<HTML><HEAD> <TITLE>Muscript Variables</TITLE> </HEAD>
<LINK rel=stylesheet type="text/css" href="styles.css" title="Muscript Styles">
<META HTTP-EQUIV="Keywords"
CONTENT="music publishing, music typesetting, Peter Billam, muscript, MIDI">
</HEAD><BODY LINK="#000066" VLINK="#000066" ALINK="#000066"><DIV>
<H1><A NAME="top"><IMG SRC="logo.gif" ALT=" " WIDTH=81 HEIGHT=32></A>
<FONT COLOR="#800000">
<B><I>Muscript Variables</I></B></FONT></H1>
<TABLE ALIGN="center" WIDTH="95%" BORDER=0 CELLSPACING=0>
<TR><TD ALIGN="left">
<UL><LI>
<A HREF="#names">VARIABLE NAMES</A>
</LI><LI>
<A HREF="#definition">VARIABLE DEFINITION</A>
</LI><LI>
<A HREF="#multiline">MULTILINE VARIABLES</A>
</LI></UL>
</TD><TD ALIGN="left">
<UL><LI>
<A HREF="#array">ARRAY VARIABLES</A>
</LI><LI>
<A HREF="#generators">THE GENERATOR-FUNCTIONS</A>
</LI><LI>
<A HREF="#substitution">VARIABLE SUBSTITUTION</A>
</LI></UL>
</TD><TD ALIGN="left">
<UL><LI>
<A HREF="#preprocessor">PREPROCESSOR</A>
</LI><LI>
<A HREF="#examples">EXAMPLES</A>
</LI><LI>
<A HREF="#seealso">SEE ALSO</A>
</LI></UL>
</TD></TR>
</TABLE>
<P>
<A HREF="index.html"><I>Muscript</I>
is a language for typesetting music.</A><BR>
This page describes the use of Variables,
as introduced in <I>muscript</I> 3.1.<BR>
This part of the syntax is still under development;
future backward-compatibility is not guaranteed.
</P>
<A NAME="names"><HR></A><H3>Variable Names</H3><P>
Variable-names begin with a <B>$</B> like <I>Perl</I> 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:<BR>
<CODE> $A $B6 $MIDDLE8 $RIFF1 $CODA</CODE>
</P><A NAME="definition"><HR></A><H3>Variable Definition</H3><P>
<PRE> $B4 = 8 [D G B']
$RIFF1 = 83 [E 163 e' G G# B 83 d' 163 B 83 A 163 B] 2 rest
</PRE>
The variable-definition must have a line to itself.
On the left hand side of the equation,
the variable-name, as in <I>Perl</I>, 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
<A HREF="#substitution">at substitution-time</A>. So:<BR>
<CODE> $A = <A HREF="#cycle">cycle?</A> D# : F# : A ?<BR>
$B = [$A $A]<BR>
=1 treble $B $B $B $B<BR>
</CODE>
evaluates to:<BR>
<CODE> =1 treble [D# F#] [A D#] [F# A] [D# F#]<BR>
</CODE>
</P><P>
If you want to force substitution here at definition-time,
use <B>==</B> a double equal-sign. So:<BR>
<CODE> $A = <A HREF="#cycle">cycle?</A> D# : F# : A ?<BR>
$B <B>==</B> [$A $A]<BR>
=1 treble $B $B $B $B<BR>
</CODE>
evaluates to:<BR>
<CODE> =1 treble [D# F#] [D# F#] [D# F#] [D# F#]<BR>
</CODE>
</P><A NAME="multiline"><HR></A><H3>Multiline Variables</H3><P>
<PRE> $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
}
</PRE>
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.:
<PRE> $OPENING $VERSE $CHORUS $VERSE $CHORUS $MIDDLE8 $VERSE $CHORUS $CHORUS
</PRE>
</P><P>
If you want to force substitution here at definition-time,
use <B>==</B> a double equal-sign. This can lead to recursion:
<PRE> $B5 <B>==</B> {
| 4.3
$B <B>==</B> [$A $A]
=1 4 G $B c $B
=2 8 rest 4 g e d 8 D
=1 $B $B $B $B
$C6 <B>==</B> {
$D7 <B>==</B> {
$E8 <B>=</B> {
$F9 <B>==</B> {
=1 1 $B
}
}
}
}
$C6
|
$E8
=1 4 G $B B c
=2 8 rest 4 g e d 8 D
}
</PRE>
In this (absurd) example, the value of the $E8 and $F9 variables will
only be set when $B5 is actually <I>used</I>;
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.
</P><A NAME="array"><HR></A><H3>Array Variables</H3><P>
To make changing the notes of a chord easier,
a very restricted one-line syntax allows :
<PRE> $B2-4 = G : Bb : d
</PRE>
which is neater than the equivalent :
<PRE> $B2 = G
$B3 = Bb
$B4 = d
</PRE>
Only single-digit suffixes are allowed.
</P><A NAME="generators"><HR></A><H3>Generator Functions</H3><P>
Variables can be generated by one of a number of in-built functions:<BR>
<B><A HREF="#aaba">aaba</A></B>,
<B><A HREF="#cycle">cycle</A></B>,
<B><A HREF="#leibnitz">leibnitz</A></B>,
<B><A HREF="#morse_thue">morse_thue</A></B>,
<B><A HREF="#rabbit">rabbit</A></B> and
<B><A HREF="#random">random</A></B>
<BR>
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.
<BR>
<CODE> $B = rabbit? 8 [D G B'] : 8 [Eb G A] ?<BR>
</CODE>
Think of the question-mark as introducing the question "<I>which?</I>",
and think of the colon <B>:</B> as a field-separator,
like it is in <I>/etc/passwd</I>.
(These characters are not otherwise used in <I>muscript</I> syntax.)<BR>
There must be no space between the function-name
and the first question-mark.<BR>
Spaces inside the question-marks, or next to the colons, are stripped away:
you can use them for clarity.<BR>
If you want a multi-line field, you have to
<A HREF="#multiline">define a multiline variable</A>,
then use that variable in the field.
</P>
<DL><DT><B><A NAME="aaba">aaba</A></B></DT><DD>
The Aaba sequence can be generated by starting with 0 0 1 0,
then repeatedly appending to it the same thing,
the inverse, and the same thing again.
It's reminiscent of the "Sentence" or a minimalised "Sonata-Form",
but it's fractal.
It needs just two arguments.
The first three stages are 0 0 1 0<BR>
then: 0 0 1 0 0 0 1 0 1 1 0 1 0 0 1 0<BR>
then:<BR>
0 0 1 0 0 0 1 0 1 1 0 1 0 0 1 0<BR>
0 0 1 0 0 0 1 0 1 1 0 1 0 0 1 0<BR>
1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 1<BR>
0 0 1 0 0 0 1 0 1 1 0 1 0 0 1 0<BR>
In general, if you generate 4<sup>n</sup> elements, the ratio of a/b
is (2<sup>n</sup> + 1) / 2<sup>n</sup> - 1), which tends towards 1.0
</DD><DT><B><A NAME="cycle">cycle</A></B></DT><DD>
This function just generates its arguments cyclically, in a loop.
</DD><DT><B><A NAME="leibnitz">leibnitz</A></B></DT><DD>
The Leibnitz sequence with n=2 can be generated
by repeatedly appending the current sequence with one added to it.
The first five stages are 0, then 0 1, then 0 1 1 2,
then 0 1 1 2 1 2 2 3, then 0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4.
<BR>
The Leibnitz sequence with n=3 can be generated
by repeatedly appending the current sequence with one added to it
and then with two added to it.
The first four stages are 0, then 0 1 2, then 0 1 2 1 2 3 2 3 4,
then 0 1 2 1 2 3 2 3 4 1 2 3 2 3 4 3 4 5 2 3 4 3 4 5 4 5 6.
<BR>
Since it's necessary to specify <B>n</B>,
this is done as the first argument. For example,<BR>
<CODE> $A = leibnitz? 2 : A : B : c : d : e ?<BR>
=1 $A $A $A $A $A $A $A $A $A $A $A $A $A $A $A $A</CODE><BR>
results in:<BR>
<CODE> =1 A B B c B c c d B c c d c d d e<BR></CODE>
</DD><DT><B><A NAME="morse_thue">morse_thue</A></B></DT><DD>
The Morse-Thue sequence is named in honour of
the Norwegian mathematician Axel Thue (1863-1922)
and of Marston Morse of Princeton (1892-1977).
It is now more commonly known as the Thue-Morse Sequence.<BR>
With 2 arguments, the sequence can be generated by repeatedly
appending the complement; the first five stages are 0, then 0 1, then
0 1 1 0, then 0 1 1 0 1 0 0 1, then 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0.<BR>
With K=3 it can be generated by recursively by adding 1 and then 2, modulo 3.
The first three stages are 0, then 0 1 2, then 0 1 2 1 2 0 2 0 1.<BR>
See:
<A HREF="https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence">
en.wikipedia.org/wiki/Thue-Morse_sequence</A>
</DD><DT><B><A NAME="rabbit">rabbit</A></B></DT><DD>
The Rabbit sequence arises from Fibonacci's rabbit-problem
in the Liber Abaci (1202). It needs just two arguments.
The sequence can be generated by starting with the first two stages 1,
then 1 0, and then appending to each stage the previous stage;
so the next four stages are 1 0 1, then 1 0 1 1 0,
then 1 0 1 1 0 1 0 1, then 1 0 1 1 0 1 0 1 1 0 1 1 0.<BR>
See: <A HREF="https://en.wikipedia.org/wiki/Fibonacci_word">
en.wikipedia.org/wiki/Fibonacci_word</A>
</DD><DT><B><A NAME="random">random</A></B></DT><DD>
The Random sequence always returns one of its elements at random.
</DD></DL>
</P><A NAME="substitution"><HR></A><H3>Variable Substitution</H3><P>
When a variable is encountered within the music
(rather than just within a recursion in a
<A HREF="#definition">variable-definition</A>),
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
<I>muscript</I>.
</P><A NAME="preprocessor"><HR></A><H3>The Preprocessor</H3><P>
<PRE> muscript -pp filename</PRE>
This <B>-pp</B> command-line option outputs the pre-processed text,
so that you can, for example, edit it by hand.
</P><A NAME="examples"><HR></A><H3>Examples</H3><P>
See <I><A HREF="samples/alberti.txt">alberti.txt</A></I>,
<I><A HREF="samples/fingerpickin.txt">fingerpickin.txt</A></I> and
<I><A HREF="samples/generators.txt">generators.txt</A></I> in
<B><A HREF="samples/index.html">samples/index.html</A></B>
</P><A NAME="seealso"><HR></A><H3>See Also</H3><P>
<B><A HREF="test_pl.txt">test.pl</A></B>,
the test-script that this version passes<BR>
<B><A HREF="index.html">index.html</A></B>,
the <I>muscript</I> home page<BR>
<B>Fractals, Chaos, Power Laws</B>, Manfred Schroeder, 1991,
W.H. Freeman, New York<BR>
<B><A HREF="https://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence">
en.wikipedia.org/wiki/Thue-Morse_sequence</A></B><BR>
<B><A HREF="https://en.wikipedia.org/wiki/Fibonacci_word">
en.wikipedia.org/wiki/Fibonacci_word</A></B>,
about the Rabbit Sequence.
</P><HR>
<CENTER>
<P><I>Peter Billam</I>
<A HREF="http://www.pjb.com.au"><I>http://www.pjb.com.au</I></A></P>
</CENTER>
</DIV></BODY></HTML>