Procedures (chunks)

Procedures in Handel are called chunks. You can conceptualize a chunk as a song track. When ran, chunks play at the same time as other run chunks and the global track. Chunks must begin with the chunk keyword and end with the endchunk keyword.

Below is an example program with a kick drum and a piano, playing together.

start
chunk backbeat using myplayable
play myplayable
endchunk
chunk mykeys
play E3, G3, A3 for 1b
play G3, A2, C3 for 1b
play F3, A3, C3 for 1b
play D3, F2, A3 for 1b
endchunk
run mykeys with sound piano, loop for 2
save myplayable = A1 for 1b
run backbeat using myplayable with sound kick, loop for 8
finish

Both the 'backbeat' chunk and the 'mykeys' chunk above play together (not one after the other). This behavior allows multitrack songs to be created with Handel.

Note that each chunk has its own scope.

More on procedures (chunks) and their syntax#

Procedure declaration (creating chunks)#

As noted above you can create chunks with the chunk keyword. The name of the chunk (the chunk name) follows the keyword.

This chunk name must be all lowercase letters, no numbers and cannot be one of Handel's reserved keywords. (See the Reserved Keywords section below).

After the chunk name, you can optionally add parameters. A list of comma separated parameters can follow the using keyword.

Together you get the following: chunk somechunkname using someparam, anotherparam

After the optional parameter list, you can add a body to the chunk. This is a function body (what you would like to happen when the chunk is ran).

Lastly the chunk must be ended with the endchunk keyword.

Running Procedures#

There are two ways to run a chunk in Handel.

You can run a chunk using the run keyword. This conceptually creates a new song track, and plays the chunk synchronously with all running chunks.

You can also run a chunk using the call keyword. This runs the chunk in place (in the songtrack the chunk is called in).

The syntax for running a chunk is the run or call command followed by the name of the chunk.

If the chunk has parameters, a you must use the `using keyword followed by a matching number of comma separated arguments.

Here is an example running two chunks. One chunk requires arguments the other does not.

start
chunk playtwo using argone, argtwo
play argone
play argtwo
endchunk
chunk noargs
play C4 for 1b
call playtwo using E4 for 1b, Cb6 for 1b
endchunk
run noargs with sound piano
finish

The run command is used to run noargs in its own conceptual song track.

Within noargs, 1 note plays, and the playtwo chunk is called in place.

Note that saved variables (containing any built-in type in Handel), digits, playables, durations, can be used as arguments when running a chunk.

OK! Now to configuring a run of a chunk.

Configuring a run of a chunk#

You can configure a run of chunk by adding the with keyword and a comma separated list of customizations to the end of a run command.

There are three main customizations: bpm, sound, and loop.

You can use bpm keyword to set the bpm of a run of a chunk.

For example bpm 120

You can use the sound keyword to set the instrument of a run of a chunk.

For example sound piano

The current available sounds to choose from are: piano, synth, casio, kick, snare, hihat

You can use the loop keyword to set the amount of times the run of a chunk shoud loop for.

For example loop for 10

All together you can configure a run of a chunk as follows:

start
chunk withargs using somechord
play somechord
endchunk
run withargs using E3, G3, F3 for 1b with bpm 100, loop for 8, sound piano
finish

Above we've got a chord, played with a piano, looping 8 times, with a bpm of 100!

(see reference below for addition customizations)