Variable Declaration (save)

tl;dr Here is a code snippet showing variables in Handel

start
save mynotelist = Cb3, D3
save myduration = for 1b
save myplayable = E4, F4, G3 for 3b
save myotherplayable = mynotelist for myduration
play myplayable
rest myduration
play myotherplayable
finish

You can declare Variables in Handel. Variables store three builtin types in Handel: Notelists, Notegroups, Durations, Playables.

A Digit is a positive or negative integer.

A Notelist is a single note name, or a list of note names separated by commas.

For example:

Bb3
G#2, A2

A Notegroup is a group of notelists (or conceptually an array of notelists). Each notelist is separated by a vertical line.

For example:

Bb3|G#2, A2

A Duration is the keyword for followed by a beat.

Here are some example durations:

for 1b
for 2b
for 16b
for 32b

Lastly, we've already seen Playables above. Playables are a note or notelist (chord) followed by a duration. Here are some example playables.

Bb3 for 1b
D#6, E#6, G3 for 1b

no promises that the above chord sounds pleasing to the ear :p

Finally variables!

To store a notelist, playable or a duration use the save keyword, followed by a variable name, an equal sign and a notelist, playable, duration (or another variable which stores on of these values).

Variable names must contain only lowercase letters, and no numbers. Variable names must also not be any of the reserved keywords in Handel. eSee the Reserved Keywords).

Below is an example program using variables.

start
save mynote = E2
save myplayablenote = mynote for 2b
save myrest = for 2b
play myplayablenote
rest myrest
play myplayablenote
rest myrest
finish

When saving variables, Handel now also provides expressions for generating random numbers and for evaluating expressions.

To generate a random number when setting a variable, use the randint keyword, followed by a range start to end

To evaluate an expression use the eval keyword followed by a mathematical expression (note division is integer division).

Here is an example of the syntax:

save somerandomdigit = randint -5 to 5
save someint = eval 5 * 5 / (1 + 1) % 6

OK! So far so good!