-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguitar.ck
81 lines (66 loc) · 2.26 KB
/
guitar.ck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public class Guitar {
[ 0, 2, 3, 5, 7, 8, 10 ] @=> int buttons[];
[ 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0 ] @=> int pressed[];
4 => int octave;
0 => int pick;
0 => int lifted;
0 => float bend;
4 => int base;
0 => int offset;
fun static int button_cap() { return 10; }
static GuitarSynth buttonSynth[];
fun static int setup(string mode, UGen u) {
new GuitarSynth[10] @=> buttonSynth;
if (mode == "sub") {
for (0 => int i; i < button_cap(); i++) {
new SubSynth @=> buttonSynth[i];
buttonSynth[i].connect(u);
}
} else if (mode == "stk") {
for (0 => int i; i < button_cap(); i++) {
new StkSynth @=> buttonSynth[i];
new Moog => buttonSynth[i].synth;
buttonSynth[i].connect(u);
}
} else if (mode == "midi") {
for (0 => int i; i < button_cap(); i++) {
new MidiSynth @=> buttonSynth[i];
buttonSynth[i].connect(blackhole);
}
} else {
<<< "Unrecognized guitar mode: ", mode, "\nAvailable: midi stk sub" >>>;
return 0;
}
return 1;
}
public int getPitch(int i) {
// just need a proper mod function
int octave_offset;
if (offset < 0) {
-1 + (i+offset)/buttons.cap() => int octave_offset;
buttons.cap() + offset%buttons.cap() => offset;
} else {
(i+offset)/buttons.cap() => octave_offset;
}
(offset + i)%buttons.cap() => int noteIndex;
return base + (octave+octave_offset)*12 + buttons[noteIndex];
}
public void bendNote(float f) {
for (0=> int i; i < pressed.cap(); i++) {
if (pressed[i]) {
buttonSynth[i].pitchBend(f);
}
}
}
public void update(int K, int down) {}
public void pickNote() {
for (0=> int i; i < pressed.cap(); i++) {
if (pressed[i]) {
getPitch(i) => buttonSynth[i].setNote;
buttonSynth[i].noteOn(1);
}
}
}
public void octaveUp() { if (octave > 5) return; octave++; }
public void octaveDown() { if (octave < 2) return; octave--; }
}