Debian Codegraph @

examples/stk/frenchrn-algo2.ck

raw
1 // name: frenchrn-algo2.ck
2 // desc: FM 4 Operator (TX81Z Algorithm 2) French Horn Demo
3 //
4 // author: Perry R. Cook
5 // date: June 2021, for REPAIRATHON 2021
6 // needs chuck 1.4.1.0 or above
7
8 // patch
9 FrencHrn f => NRev r => dac;
10 // turn down the volume a bit
11 .5 => r.gain;
12 // reverb mix
13 0.07 => r.mix;
14
15 // to learn more about FrencHrn, uncomment this:
16 // f.help();
17
18 36 => Std.mtof => f.freq; // Play an unually low note
19 1 => f.noteOn; second => now;
20 1 => f.noteOff; second => now;
21
22 // Test the controllers
23 <<< f.controlOne(), f.controlTwo() >>>;
24 arpeg();
25
26 1.0 => f.controlOne; 1.0 => f.controlTwo;
27 <<< f.controlOne(), f.controlTwo() >>>;
28 arpeg();
29
30 0.0 => f.controlTwo;
31 <<< f.controlOne(), f.controlTwo() >>>;
32 arpeg();
33
34 0.0 => f.controlOne; 1.0 => f.controlTwo;
35 <<< f.controlOne(), f.controlTwo() >>>;
36 arpeg();
37
38 // Now play a proper French Horn solo
39 0.5 => f.controlOne; 0.8 => f.controlTwo;
40
41 // PBDSL: Perry's Bizarre Demo Score Language //
42 // Integer part is MIDI note#
43 // Fractional part is duration
44 // If only fractional, then it's a rest duration
45 // Negative cause slur or hold (no notOn rearticulation)
46 // if MIDI note illegal (>127) then it's vibrato
47 [60.2,0.1,65.2,0.05,67.2,0.05,68.7,-69.3,0.1,
48 60.2,0.05,65.25,67.25,68.7,-69.3,0.1,
49 60.2,65.2,67.2,68.4,69.4,71.25,72.2,74.2,72.2,69.2,67.2,65.3,60.3,57.3,53.4,0.2,48.4,0.4,41.9,600.0,-41.9,1] @=> float notes[];
50
51 0.0 => float lastNote;
52 for (int i; i < notes.cap()-1; i++) {
53 Std.abs(Std.ftoi(notes[i])) => int note;
54 if (Std.fabs(notes[i]) < 1.0) {
55 Std.fabs(notes[i])::second => now;
56 }
57 else if (notes[i] > 128.0) { // illegal note# = vibrato amt * 10000
58 notes[i]/10000.0 => f.lfoDepth;
59 <<< "Vibrato!!", f.lfoDepth() >>>;
60 }
61 else {
62 Std.mtof(note) => f.freq;
63 if (notes[i] > 0.0) {
64 <<< "New Note:", note >>>;
65 1 => f.noteOn;
66 }
67 0.8*(Std.fabs(notes[i])-note)::second => now;
68 if (notes[i+1] < 128 & notes[i+1] > 0.0) {
69 1 => f.noteOff;
70 }
71 else <<< "Slur!", "or Hold" >>> ;
72 0.2*(Std.fabs(notes[i])-note)::second => now;
73 }
74 }
75
76 // let ring...
77 2*second => now;
78
79 fun void arpeg() {
80 Std.mtof(48) => f.freq;
81 1 => f.noteOn; second => now; 1 => f.noteOff; 0.2*second => now;
82 Std.mtof(52) => f.freq;
83 1 => f.noteOn; second => now; 1 => f.noteOff; 0.2*second => now;
84 Std.mtof(55) => f.freq;
85 1 => f.noteOn; second => now; 1 => f.noteOff; 0.2*second => now;
86 Std.mtof(60) => f.freq;
87 1 => f.noteOn; second => now; 1 => f.noteOff; 0.2*second => now;
88 }