| 1 |
|
|
| 2 |
1 |
/******************************************************************************
|
| 3 |
|
|
| 4 |
|
* Ben Bengler
|
| 5 |
|
* mail@benbengler.com
|
| 6 |
|
* 02.05.2016
|
|
2 |
* Copyright (C) 2015 Ben Bengler (mail@benbengler.com)
|
|
3 |
* Copyright (C) 2016 Queen Mary University of London
|
|
4 |
* Authors: Ben Bengler, Fiore Martin
|
| 7 |
5 |
*
|
| 8 |
|
* Collidoscope
|
|
6 |
* This file is part of Collidoscope.
|
|
7 |
*
|
|
8 |
* Collidoscope is free software: you can redistribute it and/or modify
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
11 |
* (at your option) any later version.
|
|
12 |
*
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
* GNU General Public License for more details.
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 9 |
20 |
*
|
|
21 |
****************************************************************************
|
|
22 |
*
|
| 10 |
23 |
* Teensy 2 ++ pinout: https://www.pjrc.com/teensy/card4b.pdf
|
| 11 |
24 |
*
|
| 12 |
25 |
* ANALOG INPUTS:
|
| 13 |
26 |
* Wavejet -> F0 (38) [Horizontal rail 1]
|
| 14 |
27 |
* Wavejet -> F1 (39) [Horizontal rail 2]
|
| 15 |
|
* Filter 1 -> F2 (40) [Vertical rail 1]
|
| 16 |
|
* Filter 2 -> F4 (42) [Vertical rail 2]
|
|
28 |
* Filter 1 -> F2 (40) [Fader with moon/sun 1]
|
|
29 |
* Filter 2 -> F4 (42) [Fader with moon/sun 2]
|
|
30 |
* Duration 1-> F3 (41) [Fader with grains 1]
|
|
31 |
* Duration 2-> F5 (43) [Fader with grains 2]
|
| 17 |
32 |
*
|
| 18 |
33 |
* DIGITAL INPUTS [INTERRUPTS]:
|
| 19 |
34 |
* Sel. length 1 -> INT0/INT1 (0, 1) [Encoder 1]
|
| 20 |
|
* Sel. length 2 -> INT2/INT3 (2, 3) [Encoder 2]
|
| 21 |
|
* Duration 1 -> INT4/INT5 (36, 37)[Encoder 3]
|
| 22 |
|
* Duration 2 -> INT6/INT7 (18, 19)[Encoder 4]
|
|
35 |
* Sel. length 2 -> INT2/INT3 (2, 3) [Encoder 2]
|
| 23 |
36 |
*
|
| 24 |
37 |
* DIGITAL INPUTS:
|
| 25 |
38 |
* Play1 toggle -> B0 (20)
|
| ... | ... | |
| 30 |
43 |
* DIGITAL OUTPUTS:
|
| 31 |
44 |
* Record Button 1 Led -> D4 (4)
|
| 32 |
45 |
* Record Button 2 Led -> D5 (5)
|
| 33 |
|
|
|
46 |
*
|
| 34 |
47 |
******************************************************************************/
|
| 35 |
48 |
|
| 36 |
49 |
|
| ... | ... | |
| 47 |
60 |
const int cc_filter = 7; // MIDI cc controlling LP filter
|
| 48 |
61 |
const int cc_play = 4; // MIDI cc controlling PLAY
|
| 49 |
62 |
const int cc_record = 5; // MIDI cc controlling RECORD
|
| 50 |
|
//const int cc_reset = 100; // MIDI cc controlling instrument RESET
|
|
63 |
|
| 51 |
64 |
|
| 52 |
65 |
///////////////////////////////////////////////////
|
| 53 |
66 |
//Default Values:
|
| 54 |
67 |
const int Enc_def = 64; //default selection length
|
| 55 |
68 |
int MIDI_led_state = LOW;
|
| 56 |
|
//boolean reset1 = true;
|
| 57 |
|
//boolean reset2 = true;
|
| 58 |
69 |
|
| 59 |
70 |
///////////////////////////////////////////////////
|
| 60 |
71 |
// Interface Inputs
|
| ... | ... | |
| 166 |
177 |
//Loop/Keymode Switch Instrument 1
|
| 167 |
178 |
|
| 168 |
179 |
if (button1.risingEdge()) {
|
| 169 |
|
//Serial.println("Loop mode");
|
| 170 |
180 |
usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst1);
|
| 171 |
181 |
}
|
| 172 |
182 |
|
| 173 |
183 |
if (button1.fallingEdge()) {
|
| 174 |
|
//Serial.println("Keyboardmode mode");
|
| 175 |
184 |
usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst1);
|
| 176 |
185 |
}
|
| 177 |
186 |
|
| 178 |
187 |
|
| 179 |
188 |
//Record Instrument 1
|
| 180 |
189 |
if (button2.fallingEdge()) {
|
| 181 |
|
//Serial.println("RECORD! Instrument 1");
|
| 182 |
190 |
usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst1);
|
| 183 |
191 |
}
|
| 184 |
192 |
|
| 185 |
193 |
//send MIDI Wavejet 1 [Position Instrument 1]
|
| 186 |
|
|
|
194 |
//Serial.print("W1>"); Serial.println(Jet1_new);
|
| 187 |
195 |
if (Jet1_new > Jet1_old+jitter_thresh || Jet1_new < Jet1_old-jitter_thresh) {
|
| 188 |
|
|
| 189 |
|
int16_t midiVal = constrain( map(Jet1_new, 24, 926, 0, 149), 0, 149 );
|
| 190 |
|
// int16_t midiVal = constrain( map( Jet1_new, 23, 928, 0, 149 ), 0, 149 ); old collidoscope
|
|
196 |
//int16_t midiVal = constrain( map(Jet1_new, 24, 926, 0, 149), 0, 149 );
|
|
197 |
int16_t midiVal = constrain( map(Jet1_new, 18, 800, 0, 149), 0, 149 );
|
| 191 |
198 |
if( midiVal != Jet1_old_MIDI ){
|
| 192 |
199 |
Jet1_old_MIDI = midiVal;
|
| 193 |
200 |
usbMIDI.sendPitchBend( midiVal, midi_chan_inst1 );
|
| ... | ... | |
| 199 |
206 |
|
| 200 |
207 |
|
| 201 |
208 |
//send MIDI Filter 1 [Filter Instrument 1]
|
| 202 |
|
|
| 203 |
|
if ( filter1_new != filter1_old ) { // maybe adding jitter threshold needed, see Jet1_new
|
|
209 |
if ( filter1_new != filter1_old ) {
|
| 204 |
210 |
|
| 205 |
211 |
int16_t midiVal = constrain( map(filter1_new, 0, 1024, 0, 127), 0, 127 );
|
| 206 |
212 |
if( midiVal != filter1_old_MIDI){
|
| ... | ... | |
| 213 |
219 |
digitalWrite(Pin_MIDIled, HIGH);
|
| 214 |
220 |
}
|
| 215 |
221 |
|
| 216 |
|
if ( dur1_new != dur1_old ) { // maybe adding jitter threshold needed, see Jet1_new
|
|
222 |
if ( dur1_new != dur1_old ) {
|
| 217 |
223 |
|
| 218 |
224 |
int16_t midiVal = constrain( map(dur1_new, 0, 1024, 0, 127), 0, 127 );
|
| 219 |
225 |
if( midiVal != dur1_old_MIDI){
|
| ... | ... | |
| 242 |
248 |
//Loop/Keymode Switch Instrument 2
|
| 243 |
249 |
|
| 244 |
250 |
if (button3.risingEdge()) {
|
| 245 |
|
//Serial.println("Loop mode");
|
| 246 |
251 |
usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst2);
|
| 247 |
252 |
}
|
| 248 |
253 |
|
| 249 |
254 |
if (button3.fallingEdge()) {
|
| 250 |
|
//Serial.println("Keyboardmode mode");
|
| 251 |
255 |
usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst2);
|
| 252 |
256 |
}
|
| 253 |
257 |
|
| 254 |
258 |
//Record Instrument 2
|
| 255 |
259 |
if (button4.fallingEdge()) {
|
| 256 |
|
//Serial.println("RECORD! Instrument 2");
|
| 257 |
260 |
usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst2);
|
| 258 |
261 |
}
|
| 259 |
262 |
|
| 260 |
263 |
//send MIDI Wavejet 2 [Position Instrument 2]
|
| 261 |
|
|
|
264 |
// Serial.print("W2>"); Serial.println(Jet2_new);
|
| 262 |
265 |
if (Jet2_new > Jet2_old+jitter_thresh || Jet2_new < Jet2_old-jitter_thresh) {
|
| 263 |
|
//Serial.println("RECORD! Instrument 2");
|
| 264 |
|
int16_t midiVal = constrain( map( Jet2_new, 925, 18, 149, 0 ), 0, 149 );
|
|
266 |
//int16_t midiVal = constrain( map( Jet2_new, 925, 18, 149, 0 ), 0, 149 );
|
|
267 |
int16_t midiVal = constrain( map( Jet2_new, 15, 780, 0, 149 ), 0, 149 );
|
| 265 |
268 |
if( midiVal != Jet2_old_MIDI ){
|
| 266 |
269 |
Jet2_old_MIDI = midiVal;
|
| 267 |
270 |
usbMIDI.sendPitchBend( midiVal, midi_chan_inst2 );
|
| ... | ... | |
| 271 |
274 |
digitalWrite(Pin_MIDIled, HIGH);
|
| 272 |
275 |
}
|
| 273 |
276 |
|
| 274 |
|
//Serial.println(filter2_new);
|
| 275 |
|
if ( filter2_new != filter2_old ) { // maybe adding jitter threshold needed, see Jet1_new
|
|
277 |
if ( filter2_new != filter2_old ) {
|
| 276 |
278 |
int16_t midiVal = constrain( map(filter2_new, 0, 1024, 0, 127), 0, 127 );
|
| 277 |
279 |
if( midiVal != filter2_old_MIDI){
|
| 278 |
280 |
//Serial.println( midiVal );
|
| ... | ... | |
| 284 |
286 |
digitalWrite(Pin_MIDIled, HIGH);
|
| 285 |
287 |
}
|
| 286 |
288 |
|
| 287 |
|
if ( dur2_new != dur2_old ) { // maybe adding jitter threshold needed, see Jet1_new
|
|
289 |
if ( dur2_new != dur2_old ) {
|
| 288 |
290 |
int16_t midiVal = constrain( map(dur2_new, 0, 1024, 0, 127), 0, 127 );
|
| 289 |
291 |
if( midiVal != dur2_old_MIDI){
|
| 290 |
292 |
//Serial.println( midiVal );
|
| ... | ... | |
| 300 |
302 |
//send MIDI Encoder 2 [Selection length Instrument 2]
|
| 301 |
303 |
if (Enc2_new != Enc2_old) {
|
| 302 |
304 |
Enc2_old = Enc2_new;
|
| 303 |
|
//Serial.println("Encoder 2: ");
|
| 304 |
|
//Serial.println(Enc2_new);
|
| 305 |
305 |
usbMIDI.sendControlChange(cc_length, Enc2_new, midi_chan_inst2);
|
| 306 |
306 |
digitalWrite(Pin_MIDIled, HIGH);
|
| 307 |
307 |
}
|