-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeditationMIDI.ck
152 lines (135 loc) · 3.59 KB
/
meditationMIDI.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// argument variables
int INSTR;
float AMP;
GAMELAN gam;
if (me.args())
{
Std.atoi(me.arg(0)) => INSTR;
}
fun void Phrase (int instr, int amp)
{
// OR create a MIDI out object
MidiOut mout;
MidiMsg msg;
//mout.open(0);
//if (!mout.open(0)) {me.exit();}
128 => msg.data1;
0 => msg.data2;
0 => msg.data3;
//mout.send(msg);
// set random panning and amplitude
Math.random2(0, 1) => int lr;
amp => int prevAmp;
115 => int ampOut;
0 => int velCount;
// scale (pentatonic; in semitones)
[ 0, 3, 3, 5, 7, 7, 7, 7, 9, 10, 10, 10 ] @=> int scale[];
["jeg", "jub", "cal", "ugal", "pem1", "pem2", "pem3", "pem4"] @=> string gamelan[];
gamelan[instr] @=> string currentInstr;
// counter to control long vs short dur
0 => int durCount;
2.4 => float longDur;
longDur/3 => float shortDur;
float drt;
while (true) {
int freq;
int mNote;
0 => int oct;
for (0 => int i; i < 10; i++) {
// set random durations
//(Math.pow(2, (Std.rand2(0,4)))*.4)*Std.rand2(1,2) + Std.rand2f(-.002, .002) => drt;
// set altenating short and long durations
if (durCount == 0) {
1 => durCount;
longDur + Std.rand2f(-.001, .001) => drt;
} else {
0 => durCount;
shortDur + Std.rand2f(-.001, .001) => drt;
}
drt::second => dur T;
if (currentInstr == "jeg") {
//-0.6+lr => p.pan;
[2, 1, 3, 2, 1, 3, 4, 5] @=> int motif[];
scale[motif[i%8]] => freq;
0 => oct;
gam.jegogan(freq, amp, drt);
} else if (currentInstr == "jub") {
//-0.5+lr => p.pan;
[3, 4, 5, 2, 1, 3, 2, 1] @=> int motif[];
scale[motif[i%8]] => freq;
1 => oct;
gam.jublag(freq, amp, drt);
} else if (currentInstr == "cal") {
//-0.2+lr => p.pan;
[2, 1, 3, 4, 5, 2, 1, 3] @=> int motif[];
scale[motif[i%8]] => freq;
1 => oct;
gam.calun(freq, amp, drt);
} else if (currentInstr == "ugal") {
//0.2-lr => p.pan;
[2, 1, 3, 4, 5, 7, 8, 9, 6, 10] @=> int motif[];
scale[motif[i]] => freq;
2 => oct;
gam.ugal(freq, amp*1.1, drt);
} else if (currentInstr == "pem1") {
//0.5-lr => p.pan;
[10, 9, 8, 7, 6, 4, 5, 2, 1, 3] @=> int motif[];
scale[motif[i]] => freq;
2 => oct;
gam.pemade(freq, amp, drt);
} else if (currentInstr == "pem2") {
//0.6-lr => p.pan;
[7, 6, 4, 5, 2, 1, 3, 10, 9, 8] @=> int motif[];
scale[motif[i]] => freq;
2 => oct;
gam.pemade(freq, amp, drt);
} else if (currentInstr == "pem3") {
//-0.55+lr => p.pan;
[4, 5, 2, 1, 3, 10, 9, 8, 7, 6] @=> int motif[];
scale[motif[i]] => freq;
3 => oct;
gam.pemade(freq, amp, drt);
} else if (currentInstr == "pem4") {
//-0.65+lr => p.pan;
[1, 3, 10, 9, 8, 7, 6, 4, 5, 2] @=> int motif[];
scale[motif[i]] => freq;
3 => oct;
gam.pemade(freq, amp, drt);
}
24 + freq + oct*12 => mNote;
144 => msg.data1;
mNote => msg.data2;
amp => msg.data3;
//mout.send(msg);
// the notes can repeat
if (Std.rand2(0, 4) != 0) i--;
// occasionally, the duration can shift by 50%
if (Std.rand2(0, 127) == 0) {
T*.5 => now;
} else if (Std.rand2(0, 127) == 0) {
T*2.0 => now;
} else {
T => now;
}
if (i == 9) 0 => i;
128 => msg.data1;
0 => msg.data3;
//mout.send(msg);
// control velocities
if (prevAmp < 116) {
1 +=> prevAmp;
prevAmp => amp;
<<<prevAmp>>>;
} else if (velCount < 20) {
116 => amp;
velCount++;
<<<velCount>>>;
} else if (ampOut > 3) {
2 -=> ampOut;
ampOut => amp;
<<<ampOut>>>;
} else { me.exit(); }
}
}
}
Phrase(INSTR, 8);