Debian Codegraph @

examples/book/digital-artists/chapter5/Listing5.11.ck

raw
1 // Listing 5.11 Using the noteUp and noteDown functions in a main loop
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 // Main Program, gradually rising "melody"
31 while (true) { // (1) Main program to test noteUp and noteDown functions.
32 noteUp(); // (2) Calls noteUp, and when it's done
33 noteDown(); // (3) Calls noteDown, and so on
34 noteUp(); // Then calls noteUp twice.
35 noteUp();
36 noteDown(); // Then calls noteDown and loops.
37
38 }
39