Debian Codegraph @

examples/stk/nylon-guitar-algo1.ck

raw
1 // name: nylon-guitar-algo1.ck
2 // desc: how to turn HnkyTonk (Algorithm 1) into an acoustic guitar!!
3 // now you can transcribe almost directly from a TX81 Patch!!!
4 //
5 // author: Perry R. Cook
6 // date: June 2021, for REPAIRATHON 2021
7 // needs chuck 1.4.1.0 or above
8
9 NRev r => dac; // reverb is output mixer
10 HnkyTonk g => r; // instance for shorthand (you'll see...) , and solo
11 HnkyTonk guit[6];
12 0.1 => r.gain; 0.08 => r.mix;
13
14 [0,0,0,0] @=> int waveForms[];
15 [97,71,77,81] @=> int opGains[];
16 [1.0,3.0,3.02,8.0] @=> float ratios[];
17 [31,28,31,31] @=> int attacks[];
18 [18,6,10,9] @=> int decays[];
19 [14,1,0,0] @=> int sustains[]; // 15,0,0,0 ???
20 [8,8,9,6] @=> int releases[];
21
22 for( int i; i < 6; i++ )
23 {
24 guit[i] => r;
25
26 for( int op; op < 4; op++ )
27 {
28 guit[i].opWave( op,1 ); // sine waves all
29 guit[i].opGain( op,g.getFMTableGain(opGains[op]) );
30 guit[i].opADSR( op, g.getFMTableTime(attacks[op]),
31 g.getFMTableTime(decays[op]),
32 g.getFMTableSusLevel(sustains[op]),
33 g.getFMTableTime(releases[op]) );
34 guit[i].opRatio( op,ratios[op] );
35 g.opWave(op,1); // we do this 6 times, but it's easier
36 g.opGain( op,g.getFMTableGain(opGains[op]) );
37 g.opADSR( op, g.getFMTableTime(attacks[op]),
38 g.getFMTableTime(decays[op]),
39 g.getFMTableSusLevel(sustains[op]),
40 g.getFMTableTime(releases[op]) );
41 g.opRatio( op,ratios[op] );
42 }
43 guit[i].lfoDepth( 0.0 );
44 }
45 g.lfoDepth( 0.0 );
46
47 [38,45,50,55,59,64] @=> int DTuning[];
48 [38,45,50,57,62,66] @=> int DMaj[];
49 [40,47,52,55,59,64] @=> int Emi[];
50
51 slowStrum(DTuning, 0.8);
52 second * 1 => now;
53 allOff();
54 second/2 => now;
55
56 0.2::second => dur E;
57
58 spork ~ solo();
59
60 for( int i; i < 2; i++ )
61 {
62 <<< now/second >>>;
63 spork ~ fastStrum(Emi,1.0); 2*E => now;
64 fastUp(Emi,0.95); E/4 => now; allOff(); 3*E/4 => now;
65 spork ~ fastStrum(Emi,0.97); 2*E => now;
66 fastUp(Emi,0.8); E/4 => now; allOff(); 3*E/4 => now;
67 spork ~ fastStrum(Emi,0.95); 2*E => now;
68 fastUp(Emi,0.9); E/4 => now; allOff(); 3*E/4 => now;
69 spork ~ fastStrum(Emi,0.93); 2*E => now;
70 fastUp(Emi,0.9); E/4 => now; allOff(); 3*E/4 => now;
71 spork ~ fastStrum(DMaj,1.0); E => now; allOff(); E => now;
72 spork ~ fastStrum(DMaj,0.9); E => now;
73 if (maybe) { allOff(); }
74 else { spork ~ fastStrum(DMaj,0.8); }
75 E => now;
76 }
77
78 slowStrum(Emi,0.8);
79 Std.mtof(76) => g.freq;
80 1 => g.noteOn;
81 2*second => now;
82 allOff();
83 second => now;
84
85 fun void allOff() {
86 for (int i; i < 6; i++) 1 => guit[i].noteOff;
87 }
88
89 fun void slowStrum( int chord[], float vel) {
90 for (int i; i < 6; i++) {
91 Std.mtof(chord[i]) => guit[i].freq;
92 vel => guit[i].noteOn;
93 Math.random2f(0.05,0.15)::second => now;
94 }
95 }
96
97 fun void fastStrum( int chord[], float vel) {
98 for (int i; i < 6; i++) {
99 Std.mtof(chord[i]) => guit[i].freq;
100 vel => guit[i].noteOn;
101 Math.random2f(0.005,0.03)::second => now;
102 }
103 }
104
105 fun void fastUp( int chord[], float vel) {
106 for (int i; i < 6; i++) {
107 Std.mtof(chord[5-i]) => guit[5-i].freq;
108 vel => guit[5-i].noteOn;
109 Math.random2f(0.001,0.01)::second => now;
110 }
111 }
112
113 fun void solo() {
114 [71, 69, 71] @=> int solo1[];
115 [71, 72, 74, 72, 71] @=> int solo2[];
116 2*E => now;
117 Std.mtof(solo1[0]) => g.freq; 1 => g.noteOn;
118 E/2 => now;
119 Std.mtof(solo1[1]) => g.freq; 1 => g.noteOn;
120 E/2 => now;
121 Std.mtof(solo1[2]) => g.freq; 1 => g.noteOn;
122 0.8::second => now;
123 1 => g.noteOff;
124 2::second => now;
125 Std.mtof(solo2[0]) => g.freq; 1 => g.noteOn;
126 E/2 => now;
127 Std.mtof(solo2[1]) => g.freq; 1 => g.noteOn;
128 E/2 => now;
129 Std.mtof(solo2[2]) => g.freq; 1 => g.noteOn;
130 E/2 => now;
131 Std.mtof(solo2[3]) => g.freq; 1 => g.noteOn;
132 E/2 => now;
133 Std.mtof(solo2[4]) => g.freq; 1 => g.noteOn;
134 1::second => now;
135 1 => g.noteOff;
136 }