-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTone.pde
83 lines (77 loc) · 2.5 KB
/
Tone.pde
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
class Tone
{
int channel;
int pitch;
int velocity;
float durationMS;
float startMS;
// int signal; // from which MIDI channel the tone was triggered
int associated_signal_group; // from which signal group the tone was triggered
Tone(int c, int p, int v, float d, int s, int outcome) {
channel = c;
pitch = p;
velocity = v;
durationMS = d;
startMS = millis();
associated_signal_group = s;
// println("DEBUG: sending note with pitch "+pitch+" ...");
myBus.sendNoteOn(channel, pitch, velocity);
if (!(outcome == -1)) {
if(BAYESIAN_MODE_ENABLED && !Phases.Init) {
new Hit(outcome, NULL_OUTCOME_FOR_SIGNAL_GROUP[associated_signal_group]);
}
// append it to the list of active tones unless there is one with same the parameters c,p
boolean is_present = false;
for(int m=0; m<activeTones.length; m++) {
if(activeTones[m].channel == c && activeTones[m].pitch == p) {
activeTones[m].velocity = v;
activeTones[m].durationMS = d;
activeTones[m].startMS = millis();
activeTones[m].associated_signal_group = s;
is_present = true;
break;
}
}
// println("debug in Tone: adding tone, is_present: "+int(is_present));
if(!is_present) {
// add this tone to list
activeTones = (Tone[])append(activeTones, this);
}
// println("DEBUG: new number of active tones: "+activeTones.length);
}
}
void kill() {
myBus.sendNoteOff(this.channel, this.pitch, this.velocity);
}
}
void fadeOutTones() {
Tone ton;
for(int m=0; m<activeTones.length; m++) {
ton = activeTones[m];
if(millis()-ton.startMS > ton.durationMS) {
// remove tone from list and kill it
// println("debug in fadeOutTones: killing tone #"+m+", "+(activeTones.length-1)+" tones remaining active.");
// myBus.sendNoteOff(ton.channel, ton.pitch, ton.velocity);
ton.kill();
Tone[] newActiveTones = new Tone[activeTones.length-1];
int m_added = 0;
for(int mm=0; mm<activeTones.length; mm++) {
if(ton != activeTones[mm]) {
newActiveTones[m_added] = activeTones[mm];
m_added++;
}
}
activeTones = newActiveTones;
}
}
}
// int get_channel_from_pitch(int pitch) {
// int channel = -1;
// for (int w=0; w<NUMBER_OF_SIGNALS; w++) {
// if(MIDI_PITCH_CODES[w%(MIDI_PITCH_CODES.length)] == pitch) {
// channel = w;
// break;
// }
// }
// return channel;
// }