-
Notifications
You must be signed in to change notification settings - Fork 0
/
maq.inst.ck
158 lines (110 loc) · 3.81 KB
/
maq.inst.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
150
151
152
153
154
155
156
// maq.inst
// base class for instruments
// define maquinitas base class for instruments
public class maquinitas extends Chugen {
// declare MidiOut variable
MidiOut midiOut;
// declare MidiMsg variable
MidiMsg msg;
// declare midiPort variable
// default value is 0
0 => int midiPort;
// declare channel variable
// default value is 1
// values between 1-16
1 => int midiChannel;
// declare array of integers for MIDI notes
int midiNotes[0];
// declare array of integers for MIDI CC params
int midiControlChange[0];
// function for setup of MIDI channel
function void setupChannel(int channel) {
// define channel of the instrument
channel => midiChannel;
}
// function for setup of MIDI port
function void setupPort(int port) {
// assign midiPort number
// to check your midi interface, you have two options:
// on miniAudicle
// go to Window-Device Browser- MIDI
// on the terminal write
// chuck --probe
port => midiPort;
// check if midiPort is open
if (!midiOut.open(midiPort)) {
me.exit();
}
}
// function for MIDI note on
function void noteOn(int note, int velocity) {
// note on message
// data1: 143 + MIDI channel is note on
// MIDI channel between 1-16
143 + midiChannel => msg.data1;
// data2: note between 0-127
note => msg.data2;
// data3: velocity between 0-127
velocity => msg.data3;
// send MIDI message
midiOut.send(msg);
}
// function for MIDI note off
function void noteOff(int note) {
// do note on message
// data1: 143 + MIDI channel is note on
// MIDI channel between 1-16
143 + midiChannel => msg.data1;
// data2: note between 0-127
note => msg.data2;
// data3: velocity 0 for note off
0 => msg.data3;
// send MIDI message
midiOut.send(msg);
}
// function for turning off all MIDI notes
function void allNotesOff() {
// iterate through every note
for (0 => int note; note < 127; note++) {
// do note on message
// data1: 143 + MIDI channel is note on
// MIDI channel between 1-16
143 + midiChannel => msg.data1;
// data2: note between 0-127
note => msg.data2;
// data3: velocity 0 for note off
0 => msg.data3;
// send midi message
midiOut.send(msg);
}
}
// function for changing a MIDI CC parameter
function void controlChange(int controller, int value) {
// first byte is 175 + MIDI channel for CC
175 + midiChannel => msg.data1;
// second byte of message is controller number
controller => msg.data2;
// third byte of message is the value
value => msg.data3;
// send MIDI message
midiOut.send(msg);
}
// function for starting sequencer
function void startSequencer() {
// start message is 250
250 => msg.data1;
0 => msg.data2;
0 => msg.data3;
// send MIDI message
midiOut.send(msg);
}
// function for stopping sequencer
function void stopSequencer() {
// stop message is 252
252 => msg.data1;
0 => msg.data2;
0 => msg.data3;
// send MIDI message
midiOut.send(msg);
}
}