-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofferingMIDI.ck
104 lines (95 loc) · 2.46 KB
/
offeringMIDI.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
// the period
.5::second => dur T;
int freq;
// set random octave
0 => int oct;
// synchronize to period (for on-the-fly synchronization)
// disable to create a more 'cloud-like' texture
T - (now % T) => now;
// the oscialtor/cheesy reverb patch
//SinOsc s => JCRev r => dac;
// OR create a MIDI out object
MidiOut mout;
MidiMsg msg;
mout.open(3);
//if (!mout.open(0)) {me.exit();}
// initialize
//.005 => s.gain;
//.85 => r.mix;
// scale (pentatonic; in semitones)
[ 0, 2, 7, 9, 10, 14 ] @=> int scale[];
// variables for components that encourage variation
1=> int counter;
0=> int advance;
1=> int root;
int mNote;
float Tscale;
.35=> float lngNote;
.3=> float medNote;
.25=> float shrtNote;
// infinite time loop
while( true )
{
// random weights for creating variation
Math.rand2(1, 6) => int weight1;
Math.rand2(1, 5) => int weight2;
Math.rand2(1, 10) => int weight3;
// if counter == 1, first note is either C or D depending on weight1
if (counter == 1) {
if (weight1 < 2) {
if (root == 1) {
0 => root;
} else {
1 => root;
}
scale[root] => freq;
} else {
scale[root] => freq;
}
lngNote=> Tscale;
// cycle through middle portion of phrase
} else if (counter < (scale.cap()-1)) {
scale[counter] => freq;
if (counter == (scale.cap()-2)) {
medNote=> Tscale;
} else {
shrtNote=> Tscale;
}
// sometimes a high D is added to the ended depending of weight2
} else {
if (weight2 > 1) {
// a value of 1 for advance causes no note to be played
1 => advance;
} else {
// occassionally it will be Eb depending on weight3
if (weight3 > 1) {
scale[counter] => freq;
} else {
scale[counter]+1 => freq;
}
}
0 => counter;
medNote=> Tscale;
}
counter++;
// get the final freq
(48 + freq + oct*12)=> mNote;
// send MIDI data
144=> msg.data1;
mNote => msg.data2;
32 => msg.data3;
mout.send(msg);
//<<<msg.data2>>>;
// advance time
if (advance == 1) {
// skip this note
0 => advance;
now => now;
} else {
Tscale::T => now;
// stop previous note
//0=> msg.data3;
128=> msg.data1;
mout.send(msg);
}
}