Debian Codegraph @

examples/stk/jacobass-algo1.ck

raw
1 // name: JacoBass-algo1.ck
2 // desc: ALL NEW for 2024! JacoBass 4op FM (TX81Z Algorithm 1)
3 // This Algorithm can also do many other classic patches
4 // See honkeytonk-algo1.ck, nylon-guitar-algo1.ck, etc.
5 // for how to do this
6 //
7 // author: Perry R. Cook
8 // date: June 2024, for Hackathon 2024
9 // needs chuck 1.4.1.0 or above
10
11 // to learn more about FM Algorithm 1, uncomment this:
12 // HnkyTonk.help();
13
14 public class JacoBass extends Chugraph {
15 // use Algorithm 1
16 HnkyTonk b => Pan2 p => Chorus c => NRev r => outlet;
17 0.04 => r.mix;
18
19 [1,1,1,7] @=> int waveForms[];
20 // [99,80,81,67] @=> int opGains[]; // from the actual patch, too bright
21 [99,80,81,37] @=> int opGains[];
22 [0.5,0.48,0.52,1.0] @=> float ratios[];
23 // [17,16,21,7] @=> int attacks[]; // from the actual patch
24 [17,21,21,7] @=> int attacks[]; // I like these better
25 [8,11,11,2] @=> int decays[];
26 [11,12,11,15] @=> int sustains[];
27 [8,8,8,8] @=> int releases[];
28
29 for (int op; op < 4; op++) {
30 // b.setOpWave(op,waveForms[op]); // sine waves all
31 b.opGain(op,b.getFMTableGain(opGains[op]));
32 b.opADSR(op, b.getFMTableTime(attacks[op]),
33 b.getFMTableTime(decays[op]),
34 b.getFMTableSusLevel(sustains[op]),
35 b.getFMTableTime(releases[op]));
36 b.opRatio(op,ratios[op]);
37 b.lfoDepth(0.1);
38 }
39
40 fun void freq(float f) {
41 f => b.freq;
42 }
43
44 fun void noteOn(int n) {
45 n => b.noteOn;
46 }
47
48 fun void noteOff(int n) {
49 n => b.noteOff;
50 }
51 }
52
53 JacoBass b => NRev rev => dac; // solo bass
54 0.03 => rev.mix;
55 Noise n => ADSR e => ResonZ rez => Pan2 p => rev; // "hi hat"
56 0.4 => p.pan;
57 Impulse imp => ResonZ rez2 => rev; // "kick drum"
58 9000 => rez.freq; 12 => rez.Q; 3.0 => rez.gain; // hi hat
59 100 => rez2.freq; 8 => rez2.Q; // kick drum
60 .5 => rev.gain; // a volume knob
61
62 0.12::second => dur S;
63 0 => int beat;
64 0 => int meas; // 0 = flag to start, > 0 = measure#
65 1 => int notDone;
66
67 Std.mtof(48) => b.freq; // a couple of solo bass notes
68 1 => b.noteOn;
69 second/2 => now;
70 Std.mtof(64) => b.freq; // to start things off
71 //1 => b.noteOn;
72 1.3*second => now;
73
74 Std.mtof(60) => b.freq;
75 // 1 => b.noteOn; 0.12::second;
76 // 1 => b.noteOn; 3*0.12::second;
77
78 while( notDone ) {
79 // do drums and keep track of song position
80 spork ~ teenTown();
81 for (1 => int meas; meas < 33; meas++)
82 {
83 300 => imp.next; // kick drum
84 (0.001,0.12,0.0,0.001) => e.set; // hi hat closed
85 1 => e.keyOn;
86 S => now;
87 if (maybe) 1 => e.keyOn;
88 S => now;
89 (0.001,0.24,0.0,0.001) => e.set; // hi hat open
90 1 => e.keyOn;
91 S => now;
92 if (beat % 4 == 3) 1 => e.keyOn;
93 S => now;
94 beat++;
95 }
96 }
97
98 fun void teenTown() {
99 // transcription of the 1st few bars
100 [36,48,36,46,36,43,36,39,40,43,45,43,40,38,37,45,
101 42,35,35,29,32,33,36,38,36,41,33,43,44,45,48,50,
102 51,52,47,45,47,38,38,39,40,43,38,38,35,36,37,45,
103 42,36,35,40,37,38,38,36,29,29,36,37,38,40,41,42,
104 43,44,45,39] @=> int notes[];
105 [0.00, 0.12, 0.23, 0.35, 0.47, 0.59, 0.70, 0.82,
106 0.94, 1.05, 1.17, 1.29, 1.41, 1.52, 1.64, 1.88,
107 1.99, 2.11, 2.34, 3.75, 3.98, 4.10, 4.22, 4.34,
108 4.45, 4.57, 4.69, 4.80, 4.92, 5.04, 5.16, 5.27,
109 5.39, 5.51, 5.62, 5.74, 5.86, 5.98, 6.09, 7.85,
110 7.97, 8.09, 8.20, 8.44, 9.49, 9.61, 9.73, 9.84,
111 9.96, 10.08, 10.20, 10.31, 10.43, 11.60, 11.72, 11.84,
112 11.95, 12.29, 13.69, 13.81, 13.93, 14.16, 14.28, 14.40,
113 14.63, 14.85, 14.87, 14.95] @=> float ons[];
114
115 [S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
116 S, S, S, 0.23::second, S, S, S, S, S, S, S, S, S, S, S, S,
117 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
118 S, S, S, S, 0.70::second, S, S, S, S, S, S, S, S, S, S, S,
119 S, S, S, S] @=> dur durs[];
120
121 3*S => now; // rests to begin
122 now => time start;
123 for (int i; i < notes. cap(); i++) {
124 Std.mtof(notes[i]+12) => b.freq;
125 1 => b.noteOn;
126 <<< Std.ftoa(now/second,2), i, notes[i] >>>;
127 durs[i] => now;
128 1 => b.noteOff;
129 while (ons[i] > ((now-start)/second)) ms => now;
130 }
131 }