| 1 |
// Listing 5.10 Void functions on global variables, for scalar musical fun |
| 2 |
|
| 3 |
// global variables |
| 4 |
Mandolin mand => dac; // (1) Makes and connects a Mandolin instrument UGen. |
| 5 |
60 => int note; // (2) Global note variable |
| 6 |
|
| 7 |
// functions |
| 8 |
fun void noteUp() // (3) noteUp function definition |
| 9 |
{ |
| 10 |
1 +=> note; // note half-step up, (4) Adds 1 to global note variable |
| 11 |
<<< note >>>; // (5) Prints it out |
| 12 |
play(); // call play function // (6) Plays it |
| 13 |
} |
| 14 |
|
| 15 |
fun void noteDown() // (7) noteDown function |
| 16 |
{ // (8) Subtracts 1 from global note variable |
| 17 |
1 -=> note; // note half-step down |
| 18 |
<<< note >>>; // print new note value |
| 19 |
play(); // call play function |
| 20 |
} |
| 21 |
|
| 22 |
// play global note on global mand UG |
| 23 |
fun void play() // (9) Defines play function |
| 24 |
{ |
| 25 |
Std.mtof(note) => mand.freq; // (10) Sets global Mandolin frequency using global note |
| 26 |
1 => mand.noteOn; // (11) Plays note on Mandolin |
| 27 |
second => now; // (12) Hangs out for a second before returning to main loop |
| 28 |
} |
| 29 |
|
| 30 |
<<< "This code makes no sound.", "Run Listing 5.11 to hear something" >>>; |