-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtri.ck
More file actions
90 lines (62 loc) · 1.7 KB
/
tri.ck
File metadata and controls
90 lines (62 loc) · 1.7 KB
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
82
83
84
85
86
87
88
89
90
TriOsc osc => ADSR env => dac;
// T-T-S-T-T-T-S
[0, 2, 4, 5, 7, 9, 11, 12] @=> int major[];
// T-S-T-T-S-T-T
[0, 2, 3, 5, 7, 8, 10, 12] @=> int minor[];
// setup envelope
(1::ms, 1000::ms, 0.05, 500::ms) => env.set;
0.4 => osc.gain;
// SETUP MUSICAL
5 => int octave;
"A" => string root;
octave * 12 + note2index(root) => int offset;
minor @=> int notes[];
fun int note2index(string n)
{
n.upper() => string note;
0 => int idx;
if ("C" == note) 0 => idx;
if ("C#" == note) 1 => idx;
if ("DB" == note) 1 => idx;
if ("D" == note) 2 => idx;
if ("D#" == note) 3 => idx;
if ("EB" == note) 3 => idx;
if ("E" == note) 4 => idx;
if ("F" == note) 5 => idx;
if ("F#" == note) 6 => idx;
if ("GB" == note) 6 => idx;
if ("G" == note) 7 => idx;
if ("G#" == note) 8 => idx;
if ("AB" == note) 8 => idx;
if ("A" == note) 9 => idx;
if ("A#" == note) 10 => idx;
if ("BB" == note) 10 => idx;
if ("B" == note) 11 => idx;
return idx;
}
fun string midi2note(int idx)
{
// <<< idx % 12 >>>;
idx % 12 => idx;
if (idx == 0) return "C";
if (idx == 1) return "C#";
if (idx == 2) return "D";
if (idx == 3) return "D#";
if (idx == 4) return "E";
if (idx == 5) return "F";
if (idx == 6) return "F#";
if (idx == 7) return "G";
if (idx == 8) return "G#";
if (idx == 9) return "A";
if (idx == 10) return "A#";
if (idx == 11) return "B";
return "C";
}
for (0 => int i; i < notes.cap(); ++i)
{
Std.mtof(offset + notes[i]) => osc.freq;
// <<< offset + notes[i] + " -> " + osc.freq() >>>;
<<< midi2note(offset + notes[i]) >>>;
1 => env.keyOn;
1::second / 5 => now;
}