Revision 13:69d60ae38d62 CollidoscopeTeensy
| CollidoscopeTeensy/CollidoscopeTeensy_new.ino | ||
|---|---|---|
| 2 | 2 |
/****************************************************************************** |
| 3 | 3 |
* Copyright (C) 2015 Ben Bengler (mail@benbengler.com) |
| 4 | 4 |
* Copyright (C) 2016 Queen Mary University of London |
| 5 |
* Authors: Ben Bengler, Fiore Martin |
|
| 5 |
* Authors: Ben Bengler, Fiore Martin, Christopher Paton (christopher.paton@gmail.com)
|
|
| 6 | 6 |
* |
| 7 | 7 |
* This file is part of Collidoscope. |
| 8 | 8 |
* |
| ... | ... | |
| 47 | 47 |
* |
| 48 | 48 |
******************************************************************************/ |
| 49 | 49 |
|
| 50 |
|
|
| 51 | 50 |
#include <Encoder.h> |
| 52 | 51 |
#include <Bounce.h> |
| 53 | 52 |
|
| ... | ... | |
| 71 | 70 |
/////////////////////////////////////////////////// |
| 72 | 71 |
// Interface Inputs |
| 73 | 72 |
|
| 74 |
//Buttons:
|
|
| 73 |
//Buttons |
|
| 75 | 74 |
|
| 76 | 75 |
const int Pin_play1 = 20; //B0 |
| 77 | 76 |
const int Pin_record1 = 21; //B1 |
| ... | ... | |
| 81 | 80 |
const int Pin_record2_led = 5; //D5 |
| 82 | 81 |
const int Pin_MIDIled = 6; |
| 83 | 82 |
|
| 84 |
//const int Pin_reset1 = 22; //B2, not in use |
|
| 85 |
//const int Pin_reset2 = 25; //B5, not in use |
|
| 86 |
|
|
| 87 | 83 |
Bounce button1 = Bounce(Pin_play1, 5); |
| 88 | 84 |
Bounce button2 = Bounce(Pin_record1, 5); |
| 89 | 85 |
Bounce button3 = Bounce(Pin_play2, 5); |
| 90 | 86 |
Bounce button4 = Bounce(Pin_record2, 5); |
| 91 | 87 |
|
| 92 | 88 |
|
| 93 |
//Encoder |
|
| 89 |
//Encoders
|
|
| 94 | 90 |
Encoder Enc1 (0, 1); //Encoder for section length on Wavejet 1 |
| 95 | 91 |
Encoder Enc2 (2, 3); //Encoder for section length on Wavejet 2 |
| 96 |
Encoder Enc3 (36, 37); //Encoder for duration of Wavejet 1 [granularisation effect] |
|
| 97 |
Encoder Enc4 (18, 19); //Encoder for duration of Wavejet 2 [granularisation effect] |
|
| 92 |
Encoder Enc3 (36, 37); //Encoder for duration of Wavejet 1 [granularisation effect] |
|
| 93 |
Encoder Enc4 (18, 19); //Encoder for duration of Wavejet 2 [granularisation effect] |
|
| 94 |
|
|
| 98 | 95 |
|
| 99 | 96 |
// Variables |
| 100 |
const int jitter_thresh = 10; //7threshold value for analog INs to suppress sending MIDI due to input jitter |
|
| 101 |
const int jitter_thresh_short = 5; |
|
| 102 |
|
|
| 103 |
void setup() {
|
|
| 104 |
|
|
| 105 |
pinMode(Pin_play1, INPUT_PULLUP); |
|
| 106 |
pinMode(Pin_record1, INPUT_PULLUP); |
|
| 107 |
pinMode(Pin_play2, INPUT_PULLUP); |
|
| 108 |
pinMode(Pin_record2, INPUT_PULLUP); |
|
| 109 |
|
|
| 110 |
|
|
| 111 |
pinMode(Pin_MIDIled, OUTPUT); |
|
| 112 |
pinMode(Pin_record1_led, OUTPUT); |
|
| 113 |
pinMode(Pin_record2_led, OUTPUT); |
|
| 114 |
} |
|
| 97 |
const int jitter_thresh = 10; // threshold value for analog INs to make up for input jitter |
|
| 115 | 98 |
|
| 116 | 99 |
//Store recent values to detect parameter change |
| 117 | 100 |
long Enc1_old = -999; |
| 118 | 101 |
long Enc2_old = -999; |
| 119 |
long Enc3_old = -999; |
|
| 120 |
long Enc4_old = -999; |
|
| 102 |
|
|
| 103 |
long Enc3_old = 0; |
|
| 104 |
long Enc4_old = 0; |
|
| 121 | 105 |
|
| 122 | 106 |
uint16_t Jet1_old = 0; |
| 123 | 107 |
int16_t Jet1_old_MIDI = -1; |
| 124 | 108 |
uint16_t Jet2_old = 0; |
| 125 | 109 |
int16_t Jet2_old_MIDI = -1; |
| 110 |
|
|
| 126 | 111 |
uint16_t filter1_old = 0; |
| 127 | 112 |
int16_t filter1_old_MIDI = -1; |
| 128 | 113 |
uint16_t filter2_old = 0; |
| 129 | 114 |
int16_t filter2_old_MIDI = -1; |
| 130 | 115 |
|
| 131 |
void loop() {
|
|
| 116 |
uint16_t dur1_old = 0; |
|
| 117 |
int16_t dur1_old_MIDI = -1; |
|
| 118 |
uint16_t dur2_old = 0; |
|
| 119 |
int16_t dur2_old_MIDI = -1; |
|
| 132 | 120 |
|
| 121 |
|
|
| 122 |
void setup() |
|
| 123 |
{
|
|
| 124 |
pinMode(Pin_play1, INPUT_PULLUP); |
|
| 125 |
pinMode(Pin_record1, INPUT_PULLUP); |
|
| 126 |
pinMode(Pin_play2, INPUT_PULLUP); |
|
| 127 |
pinMode(Pin_record2, INPUT_PULLUP); |
|
| 128 |
|
|
| 129 |
|
|
| 130 |
pinMode(Pin_MIDIled, OUTPUT); |
|
| 131 |
pinMode(Pin_record1_led, OUTPUT); |
|
| 132 |
pinMode(Pin_record2_led, OUTPUT); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
void loop() |
|
| 136 |
{
|
|
| 133 | 137 |
digitalWrite(Pin_MIDIled, LOW); |
| 134 | 138 |
digitalWrite(Pin_record1_led, HIGH); |
| 135 | 139 |
digitalWrite(Pin_record2_led, HIGH); |
| 140 |
|
|
| 136 | 141 |
button1.update(); |
| 137 | 142 |
button2.update(); |
| 138 | 143 |
button3.update(); |
| 139 | 144 |
button4.update(); |
| 140 | 145 |
|
| 146 |
uint16_t Jet1_new = analogRead(0); //read Wavejet/Rail 1; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 147 |
uint16_t Jet2_new = analogRead(1); //read Wavejet/Rail 2; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 148 |
uint16_t filter1_new = analogRead(2); //read filter Instrument 1; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 149 |
uint16_t filter2_new = analogRead(4); //read filter Instrument 2; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 150 |
uint16_t dur1_new = analogRead(3); |
|
| 151 |
uint16_t dur2_new = analogRead(5); |
|
| 141 | 152 |
|
| 142 |
uint16_t Jet1_new = analogRead(0); //read Wavejet/Rail 1; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 143 |
uint16_t Jet2_new = analogRead(1); //read Wavejet/Rail 2; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 144 |
uint16_t filter1_new = analogRead(2); //read filter Instrument 1; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 145 |
uint16_t filter2_new = analogRead(4); //read filter Instrument 2; ADJUST INPUT RANGE ACCORDING TO SENSOR |
|
| 146 |
|
|
| 147 |
|
|
| 153 |
//------ SEND INSTRUMENT 1 MIDI ----------- |
|
| 148 | 154 |
|
| 149 |
//Encoder 1 [Controls selection length of wave 1] |
|
| 150 |
long Enc1_new = Enc1.read(); |
|
| 151 |
Enc1_new = constrain(Enc1_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 152 |
|
|
| 153 |
//Dynamic reset of counter to MIDI range |
|
| 154 |
if (Enc1_new <= 0){
|
|
| 155 |
Enc1.write(0); |
|
| 155 |
// Play button instrument 1 |
|
| 156 |
if (button1.fallingEdge()){
|
|
| 157 |
usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst1); |
|
| 156 | 158 |
} |
| 157 |
else if (Enc1_new >= 127){
|
|
| 158 |
Enc1.write(127); |
|
| 159 |
} |
|
| 160 |
|
|
| 161 |
//Encoder 2 [Controls selection length of wave 2] |
|
| 162 |
long Enc2_new = Enc2.read(); |
|
| 163 |
Enc2_new = constrain(Enc2_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 164 |
|
|
| 165 |
//Dynamic reset of counter to MIDI range |
|
| 166 |
if (Enc2_new <= 0){
|
|
| 167 |
Enc2.write(0); |
|
| 168 |
} |
|
| 169 |
else if (Enc2_new >= 127){
|
|
| 170 |
Enc2.write(127); |
|
| 159 |
|
|
| 160 |
if (button1.risingEdge()){
|
|
| 161 |
usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst1); |
|
| 171 | 162 |
} |
| 172 | 163 |
|
| 173 |
//Encoder 3 [Controls duration of wave 1] |
|
| 174 |
long Enc3_new = Enc3.read(); |
|
| 175 |
Enc3_new = constrain(Enc3_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 176 |
|
|
| 177 |
//Dynamic reset of counter to MIDI range |
|
| 178 |
if (Enc3_new <= 0){
|
|
| 179 |
Enc3.write(0); |
|
| 180 |
} |
|
| 181 |
else if (Enc3_new >= 127){
|
|
| 182 |
Enc3.write(127); |
|
| 164 |
|
|
| 165 |
// Record button instrument 1 |
|
| 166 |
if (button2.fallingEdge()){
|
|
| 167 |
usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst1); |
|
| 183 | 168 |
} |
| 184 | 169 |
|
| 185 |
//Encoder 4 [Controls duration of wave 2] |
|
| 186 |
long Enc4_new = Enc4.read(); |
|
| 187 |
Enc4_new = constrain(Enc4_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 188 |
|
|
| 189 |
//Dynamic reset of counter to MIDI range |
|
| 190 |
if (Enc4_new <= 0){
|
|
| 191 |
Enc4.write(0); |
|
| 192 |
} |
|
| 193 |
else if (Enc4_new >= 127){
|
|
| 194 |
Enc4.write(127); |
|
| 195 |
} |
|
| 170 |
// Selection start position instrument 1 |
|
| 171 |
// <calibrate> |
|
| 172 |
if (Jet1_new > Jet1_old+jitter_thresh || Jet1_new < Jet1_old-jitter_thresh){
|
|
| 196 | 173 |
|
| 197 |
|
|
| 198 |
//Instrument 1 Controls////////////////////////////////////// |
|
| 199 |
|
|
| 200 |
//Loop/Keymode Switch Instrument 1 |
|
| 201 |
if (button1.risingEdge()) {
|
|
| 202 |
usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst1); |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
if (button1.fallingEdge()) {
|
|
| 206 |
usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst1); |
|
| 207 |
} |
|
| 208 |
|
|
| 209 |
|
|
| 210 |
//Record Instrument 1 |
|
| 211 |
if (button2.fallingEdge()) {
|
|
| 212 |
usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst1); |
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
//send MIDI Wavejet 1 [Position Instrument 1] |
|
| 216 |
//<calibrate> |
|
| 217 |
if (Jet1_new > Jet1_old+jitter_thresh || Jet1_new < Jet1_old-jitter_thresh) {
|
|
| 218 |
|
|
| 219 |
int16_t midiVal = constrain( map(Jet1_new, 988, 121, 0, 149), 0, 149 ); |
|
| 174 |
int16_t midiVal = constrain( map(Jet1_new, 994, 121, 0, 149), 0, 149 ); |
|
| 220 | 175 |
if( midiVal != Jet1_old_MIDI ){
|
| 221 | 176 |
Jet1_old_MIDI = midiVal; |
| 222 | 177 |
usbMIDI.sendPitchBend( midiVal, midi_chan_inst1 ); |
| ... | ... | |
| 224 | 179 |
|
| 225 | 180 |
Jet1_old = Jet1_new; |
| 226 | 181 |
digitalWrite(Pin_MIDIled, HIGH); |
| 227 |
} |
|
| 182 |
}
|
|
| 228 | 183 |
|
| 184 |
//Filter instrument 1 |
|
| 185 |
// <calibrate> |
|
| 186 |
if ( filter1_new != filter1_old ) {
|
|
| 229 | 187 |
|
| 230 |
//send MIDI Filter 1 [Filter Instrument 1] |
|
| 231 |
//<calibrate> |
|
| 232 |
if ( filter1_new > filter1_old+jitter_thresh_short || filter1_new < filter1_old-jitter_thresh_short ) {
|
|
| 233 |
|
|
| 234 |
int16_t midiVal = constrain( map(filter1_new, 145, 756, 0, 127), 0, 127 ); |
|
| 188 |
int16_t midiVal = constrain( map(filter1_new, 137, 734, 0, 127), 0, 127 ); |
|
| 235 | 189 |
if( midiVal != filter1_old_MIDI){
|
| 236 |
//Serial.println( midiVal ); |
|
| 237 | 190 |
filter1_old_MIDI = midiVal; |
| 238 | 191 |
usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst1); |
| 239 | 192 |
} |
| ... | ... | |
| 241 | 194 |
filter1_old = filter1_new; |
| 242 | 195 |
digitalWrite(Pin_MIDIled, HIGH); |
| 243 | 196 |
} |
| 244 |
|
|
| 245 |
//send MIDI Encoder 1 [Selection length Instrument 1] |
|
| 197 |
|
|
| 198 |
//Selection length instrument 1 |
|
| 199 |
long Enc1_new = Enc1.read(); |
|
| 200 |
Enc1_new = constrain(Enc1_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 201 |
|
|
| 202 |
if (Enc1_new <= 0){ //Dynamic reset of counter to MIDI range
|
|
| 203 |
Enc1.write(0); |
|
| 204 |
} |
|
| 205 |
else if (Enc1_new >= 127){
|
|
| 206 |
Enc1.write(127); |
|
| 207 |
} |
|
| 208 |
|
|
| 246 | 209 |
if (Enc1_new != Enc1_old) {
|
| 247 | 210 |
Enc1_old = Enc1_new; |
| 248 | 211 |
usbMIDI.sendControlChange(cc_length, Enc1_new, midi_chan_inst1); |
| 249 | 212 |
digitalWrite(Pin_MIDIled, HIGH); |
| 250 | 213 |
} |
| 214 |
|
|
| 215 |
//Grain duration instrument 1 |
|
| 216 |
long Enc3_new = Enc3.read(); |
|
| 217 |
Enc3_new = constrain(Enc3_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 251 | 218 |
|
| 252 |
//send MIDI Encoder 3 [Duration Instrument 1] |
|
| 219 |
if (Enc3_new <= 0){
|
|
| 220 |
Enc3.write(0); |
|
| 221 |
} |
|
| 222 |
else if (Enc3_new >= 127){
|
|
| 223 |
Enc3.write(127); |
|
| 224 |
} |
|
| 225 |
|
|
| 253 | 226 |
if (Enc3_new != Enc3_old) {
|
| 254 | 227 |
Enc3_old = Enc3_new; |
| 255 | 228 |
usbMIDI.sendControlChange(cc_duration, Enc3_new, midi_chan_inst1); |
| 256 | 229 |
digitalWrite(Pin_MIDIled, HIGH); |
| 257 | 230 |
} |
| 231 |
|
|
| 232 |
//------ SEND INSTRUMENT 2 MIDI ----------- |
|
| 258 | 233 |
|
| 259 | 234 |
|
| 260 |
//Instrument 2 Controls////////////////////////////////////// |
|
| 261 |
|
|
| 262 |
//Loop/Keymode Switch Instrument 2 |
|
| 263 |
if (button3.risingEdge()) {
|
|
| 235 |
//Play button instrument 2 |
|
| 236 |
if (button3.fallingEdge()) {
|
|
| 264 | 237 |
usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst2); |
| 265 | 238 |
} |
| 266 | 239 |
|
| 267 |
if (button3.fallingEdge()) {
|
|
| 240 |
if (button3.risingEdge()) {
|
|
| 268 | 241 |
usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst2); |
| 269 | 242 |
} |
| 270 | 243 |
|
| 271 |
//Record Instrument 2
|
|
| 244 |
//Record button instrument 2
|
|
| 272 | 245 |
if (button4.fallingEdge()) {
|
| 273 | 246 |
usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst2); |
| 274 | 247 |
} |
| 275 | 248 |
|
| 276 |
//send MIDI Wavejet 2 [Position Instrument 2]
|
|
| 277 |
// <calibrate> |
|
| 249 |
// Selection start position instrument 2
|
|
| 250 |
// <calibrate>
|
|
| 278 | 251 |
if (Jet2_new > Jet2_old+jitter_thresh || Jet2_new < Jet2_old-jitter_thresh) {
|
| 279 |
int16_t midiVal = constrain( map( Jet2_new, 109, 992, 149, 0 ), 0, 149 ); |
|
| 252 |
|
|
| 253 |
int16_t midiVal = constrain( map( Jet2_new, 103, 993, 149, 0 ), 0, 149 ); |
|
| 254 |
|
|
| 280 | 255 |
if( midiVal != Jet2_old_MIDI ){
|
| 281 | 256 |
Jet2_old_MIDI = midiVal; |
| 282 | 257 |
usbMIDI.sendPitchBend( midiVal, midi_chan_inst2 ); |
| ... | ... | |
| 286 | 261 |
digitalWrite(Pin_MIDIled, HIGH); |
| 287 | 262 |
} |
| 288 | 263 |
|
| 289 |
//send MIDI Filter 2 [Filter Instrument 2] |
|
| 290 |
//<calibrate> |
|
| 291 |
if ( filter2_new > filter2_old+jitter_thresh_short || filter2_new < filter2_old-jitter_thresh_short ) {
|
|
| 292 |
int16_t midiVal = constrain( map(filter2_new, 132, 700, 0, 127), 0, 127 ); |
|
| 264 |
//Filter instrument 2 |
|
| 265 |
// <calibrate> |
|
| 266 |
if ( filter2_new != filter2_old ) {
|
|
| 267 |
|
|
| 268 |
int16_t midiVal = constrain( map(filter2_new, 125, 684, 0, 127), 0, 127 ); |
|
| 293 | 269 |
if( midiVal != filter2_old_MIDI){
|
| 294 | 270 |
filter2_old_MIDI = midiVal; |
| 295 | 271 |
usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst2); |
| ... | ... | |
| 297 | 273 |
|
| 298 | 274 |
filter2_old = filter2_new; |
| 299 | 275 |
digitalWrite(Pin_MIDIled, HIGH); |
| 276 |
} |
|
| 277 |
|
|
| 278 |
//Selection length instrument 2 |
|
| 279 |
long Enc2_new = Enc2.read(); |
|
| 280 |
Enc2_new = constrain(Enc2_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 281 |
|
|
| 282 |
if (Enc2_new <= 0){ //Dynamic reset of counter to MIDI range
|
|
| 283 |
Enc2.write(0); |
|
| 300 | 284 |
} |
| 301 |
|
|
| 302 |
|
|
| 303 |
//send MIDI Encoder 2 [Selection length Instrument 2] |
|
| 285 |
else if (Enc2_new >= 127){
|
|
| 286 |
Enc2.write(127); |
|
| 287 |
} |
|
| 288 |
|
|
| 304 | 289 |
if (Enc2_new != Enc2_old) {
|
| 305 | 290 |
Enc2_old = Enc2_new; |
| 306 | 291 |
usbMIDI.sendControlChange(cc_length, Enc2_new, midi_chan_inst2); |
| 307 | 292 |
digitalWrite(Pin_MIDIled, HIGH); |
| 308 | 293 |
} |
| 294 |
|
|
| 295 |
//Grain duration instrument 2 |
|
| 296 |
long Enc4_new = Enc4.read(); |
|
| 297 |
Enc4_new = constrain(Enc4_new, 0, 127); //constrain to 7-bit MIDI range |
|
| 298 |
|
|
| 299 |
if (Enc4_new <= 0){
|
|
| 300 |
Enc4.write(0); |
|
| 301 |
} |
|
| 302 |
else if (Enc4_new >= 127){
|
|
| 303 |
Enc4.write(127); |
|
| 304 |
} |
|
| 309 | 305 |
|
| 310 |
//send MIDI Encoder 4 [Duration Instrument 2] |
|
| 311 | 306 |
if (Enc4_new != Enc4_old) {
|
| 312 | 307 |
Enc4_old = Enc4_new; |
| 313 | 308 |
usbMIDI.sendControlChange(cc_duration, Enc4_new, midi_chan_inst2); |
Also available in: Unified diff