From 7342de4d82901f95606cab2ff782d0a8b98d6a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 08:20:08 +0200 Subject: [PATCH 1/6] Annotate "fingering math" for readability --- NuEVI/NuEVI.ino | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 8579820..17c595e 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -1296,12 +1296,24 @@ void readSwitches() { // Calculate midi note number from pressed keys #if defined(CASSIDY) - fingeredNote = startNote - 2*K1 - K2 - 3*K3 - 5*K4 + 2*K5 + K6 + 3*K7 + octaveR*12 + (octave - 3)*12 + transpose - 12 + qTransp; - fingeredNoteUntransposed = startNote - 2*K1 - K2 - 3*K3 - 5*K4 + 2*K5 + K6 + 3*K7 + octaveR*12; + + fingeredNoteUntransposed = startNote + - 2*K1 - K2 - 3*K3 //"Trumpet valves" + - 5*K4 //Fifth key + + 2*K5 + K6 + 3*K7 //Trill keys (different from standard) + + octaveR*12; //Octave rollers + #else - fingeredNote = startNote - 2*K1 - K2 - 3*K3 - 5*K4 + 2*K5 + K6 + 4*K7 + octaveR*12 + (octave - 3)*12 + transpose - 12 + qTransp; - fingeredNoteUntransposed = startNote - 2*K1 - K2 - 3*K3 - 5*K4 + 2*K5 + K6 + 4*K7 + octaveR*12; + + fingeredNoteUntransposed = startNote + - 2*K1 - K2 - 3*K3 //"Trumpet valves" + - 5*K4 //Fifth key + + 2*K5 + K6 + 4*K7 //Trill keys + + octaveR*12; //Octave rollers + #endif + fingeredNote = fingeredNoteUntransposed + transpose - 12 + qTransp; + if (pinkyKey) pitchlatch = fingeredNoteUntransposed; //use pitchlatch to make settings based on note fingered } From 549c2797b047ff52d00a13b1febc59265a84f1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 08:28:34 +0200 Subject: [PATCH 2/6] Use pin names rather than hardcoding --- NuEVI/NuEVI.ino | 14 +++++++------- NuEVI/hardware.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 17c595e..820a73a 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -257,7 +257,7 @@ void setup() { writeSetting(VERSION_ADDR,VERSION); writeSetting(BREATH_THR_ADDR,BREATH_THR_FACTORY); writeSetting(BREATH_MAX_ADDR,BREATH_MAX_FACTORY); - if (digitalRead(biteJumperPin)){ //PBITE (if pulled low with jumper, pressure sensor on A7 instead of capacitive bite sensing) + if (digitalRead(biteJumperPin)){ //PBITE (if pulled low with jumper, pressure sensor is used instead of capacitive bite sensing) writeSetting(PORTAM_THR_ADDR,PORTAM_THR_FACTORY); writeSetting(PORTAM_MAX_ADDR,PORTAM_MAX_FACTORY); } else { @@ -443,10 +443,10 @@ void loop() { if (legacy || legacyBrAct) { #if defined(CASSIDY) if (((pbUp > ((pitchbMaxVal + pitchbThrVal) / 2)) && (pbDn > ((pitchbMaxVal + pitchbThrVal) / 2)) && legacy) || - ((analogRead(0) < breathCalZero - 900) && legacyBrAct)) { // both pb pads touched or br suck + ((analogRead(breathSensorPin) < breathCalZero - 900) && legacyBrAct)) { // both pb pads touched or br suck #else if (((pbUp > ((pitchbMaxVal + pitchbThrVal) / 2)) && (pbDn > ((pitchbMaxVal + pitchbThrVal) / 2)) && legacy) || - ((analogRead(0) < breathCalZero - 800) && legacyBrAct && (pbUp > (pitchbMaxVal + pitchbThrVal) / 2) && (pbDn < (pitchbMaxVal + pitchbThrVal) / 2))) { // both pb pads touched or br suck + ((analogRead(breathSensorPin) < breathCalZero - 800) && legacyBrAct && (pbUp > (pitchbMaxVal + pitchbThrVal) / 2) && (pbDn < (pitchbMaxVal + pitchbThrVal) / 2))) { // both pb pads touched or br suck #endif readSwitches(); fingeredNoteUntransposed = patchLimit(fingeredNoteUntransposed + 1); @@ -495,7 +495,7 @@ void loop() { } } } else { - if (pbDn > (pitchbMaxVal + pitchbThrVal) / 2 && (analogRead(0) < (breathCalZero - 800)) && programonce == false) { // down bend for suck programming button + if (pbDn > (pitchbMaxVal + pitchbThrVal) / 2 && (analogRead(breathSensorPin) < (breathCalZero - 800)) && programonce == false) { // down bend for suck programming button programonce = true; readSwitches(); @@ -564,7 +564,7 @@ void loop() { } } - if (analogRead(0) > (breathCalZero - 800)) programonce = false; + if (analogRead(breathSensorPin) > (breathCalZero - 800)) programonce = false; specialKey = (touchRead(specialKeyPin) > touch_Thr); //S2 on pcb if (lastSpecialKey != specialKey) { @@ -1206,8 +1206,8 @@ void extraController() { void portamento_() { // Portamento is controlled with the bite sensor (variable capacitor) in the mouthpiece - if (biteJumper){ //PBITE (if pulled low with jumper, use pressure sensor on A7) - biteSensor = analogRead(A7); // alternative kind bite sensor (air pressure tube and sensor) PBITE + if (biteJumper){ //PBITE (if pulled low with jumper, use pressure sensor instead of capacitive bite sensor) + biteSensor=analogRead(bitePressurePin); // alternative kind bite sensor (air pressure tube and sensor) PBITE } else { biteSensor = touchRead(bitePin); // get sensor data, do some smoothing - SENSOR PIN 17 - PCB PINS LABELED "BITE" (GND left, sensor pin right) } diff --git a/NuEVI/hardware.h b/NuEVI/hardware.h index cbe9a75..3b9c64a 100644 --- a/NuEVI/hardware.h +++ b/NuEVI/hardware.h @@ -21,6 +21,7 @@ #define biteJumperGndPin 12 //PBITE #define breathSensorPin A0 +#define bitePressurePin A7 #define dPin 3 #define ePin 4 From bc31cb9eefa84c8926921cc7050dd691d67a22c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 09:51:23 +0200 Subject: [PATCH 3/6] Remove stale commented-out code --- NuEVI/NuEVI.ino | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 820a73a..ae57791 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -924,26 +924,6 @@ unsigned int breathCurve(unsigned int inputVal) { } } -//************************************************************** -/* -int smooth(int data, float filterVal, float smoothedVal){ - - - if (filterVal > 1){ // check to make sure param's are within range - filterVal = .99; - } - else if (filterVal <= 0){ - filterVal = 0; - } - - smoothedVal = (data * (1 - filterVal)) + (smoothedVal * filterVal); - - return (int)smoothedVal; -} - -*/ -//************************************************************** - // MIDI note value check with out of range octave repeat int noteValueCheck(int note) { if (note > 127) { @@ -1064,16 +1044,7 @@ void pitch_bend() { int pbNeg = map(constrain(pbDn, pitchbThrVal, pitchbMaxVal), pitchbThrVal, pitchbMaxVal, 0, calculatedPBdepth); int pbSum = 8193 + pbPos - pbNeg; int pbDif = abs(pbPos - pbNeg); - /* - if ((pbUp > pitchbThrVal) && PBdepth){ - pitchBend=pitchBend*0.6+0.4*map(constrain(pbUp,pitchbThrVal,pitchbMaxVal),pitchbThrVal,pitchbMaxVal,8192,(8193 + calculatedPBdepth)); - pbTouched++; - } - if ((pbDn > pitchbThrVal) && PBdepth){ - pitchBend=pitchBend*0.6+0.4*map(constrain(pbDn,pitchbThrVal,pitchbMaxVal),pitchbThrVal,pitchbMaxVal,8192,(8192 - calculatedPBdepth)); - pbTouched++; - } - */ + if (((pbUp > pitchbThrVal) && PBdepth) || ((pbDn > pitchbThrVal) && PBdepth)) { if (pbDif < 10) { pitchBend = 8192; From 416b2a17303b5ab441dd05cbf4d714c9613cff0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 13:20:40 +0200 Subject: [PATCH 4/6] Restructure and clarify defined constants --- NuEVI/NuEVI.ino | 27 ++++++++++++++++++++------- NuEVI/hardware.h | 17 ++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index ae57791..ad918e6 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -25,6 +25,18 @@ PROGRAMME FUNCTION: EVI Wind Controller using the Freescale MP3V5004GP breath */ +//Make sure compiler is set to the appropriate platform +#ifndef __MK20DX256__ + #error "Wrong target platform. Please set to Teensy 3.1/3.2 (MK20DX256)." +#endif + +#if !defined(USB_MIDI) && !defined(USB_MIDI_SERIAL) + #error "USB MIDI not enabled. Please set USB type to 'MIDI' or 'Serial + MIDI'." +#endif + + + + // The three states of our main state machine // No note is sounding @@ -38,14 +50,15 @@ PROGRAMME FUNCTION: EVI Wind Controller using the Freescale MP3V5004GP breath // A note is sounding #define NOTE_ON 3 -//Make sure compiler is set to the appropriate platform -#ifndef __MK20DX256__ - #error "Wrong target platform. Please set to Teensy 3.1/3.2 (MK20DX256)." -#endif -#if !defined(USB_MIDI) && !defined(USB_MIDI_SERIAL) - #error "USB MIDI not enabled. Please set USB type to 'MIDI' or 'Serial + MIDI'." -#endif +//Magic value where pinky button means "pitch bend" +#define PBD 12 + +//Vibrato direction +#define UPWD 1 +#define DNWD 0 + + //_______________________________________________________________________________________________ DECLARATIONS diff --git a/NuEVI/hardware.h b/NuEVI/hardware.h index 3b9c64a..965b636 100644 --- a/NuEVI/hardware.h +++ b/NuEVI/hardware.h @@ -10,37 +10,40 @@ #define specialKeyPin 0 // SK or S2 #define halfPitchBendKeyPin 1 // PD or S1 + +//Capacitive sensor pins (on-board teensy) #define bitePin 17 #define extraPin 16 #define pbUpPin 23 #define pbDnPin 22 #define vibratoPin 15 +//Pins jumpered to enable bite pressure sensor +#define biteJumperPin 11 +#define biteJumperGndPin 12 -#define biteJumperPin 11 //PBITE -#define biteJumperGndPin 12 //PBITE - +//Analog pressure sensors. Breath and optional bite #define breathSensorPin A0 #define bitePressurePin A7 +//Digital pins for menu buttons #define dPin 3 #define ePin 4 #define uPin 5 #define mPin 6 +//Output pins for LEDs (breath, power, status) #define bLedPin 10 #define pLedPin 9 #define statusLedPin 13 +//Analog input for measuring voltage #define vMeterPin A11 +//DAC outputs for analog and pwm #define dacPin A14 #define pwmDacPin 20 -#define PBD 12 -#define UPWD 1 -#define DNWD 0 - //Which serial port to use for MIDI #define MIDI_SERIAL Serial3 From cc86c357a051df4b8dcae233cb6a269409946b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 13:40:17 +0200 Subject: [PATCH 5/6] Move defines elsewhere as they're used in multiple places --- NuEVI/NuEVI.ino | 25 ------------------------- NuEVI/globals.h | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index ad918e6..2f280c8 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -36,31 +36,6 @@ PROGRAMME FUNCTION: EVI Wind Controller using the Freescale MP3V5004GP breath - -// The three states of our main state machine - -// No note is sounding -#define NOTE_OFF 1 - -// We've observed a transition from below to above the -// threshold value. We wait a while to see how fast the -// breath velocity is increasing -#define RISE_WAIT 2 - -// A note is sounding -#define NOTE_ON 3 - - -//Magic value where pinky button means "pitch bend" -#define PBD 12 - -//Vibrato direction -#define UPWD 1 -#define DNWD 0 - - - - //_______________________________________________________________________________________________ DECLARATIONS //variables setup diff --git a/NuEVI/globals.h b/NuEVI/globals.h index 98776a3..6ec0e44 100644 --- a/NuEVI/globals.h +++ b/NuEVI/globals.h @@ -3,6 +3,29 @@ #include "Wiring.h" + +// The three states of our main state machine + +// No note is sounding +#define NOTE_OFF 1 + +// We've observed a transition from below to above the +// threshold value. We wait a while to see how fast the +// breath velocity is increasing +#define RISE_WAIT 2 + +// A note is sounding +#define NOTE_ON 3 + + +//Magic value where pinky button means "pitch bend" +#define PBD 12 + +//Vibrato direction +#define UPWD 1 +#define DNWD 0 + + extern unsigned short breathThrVal; extern unsigned short breathMaxVal; extern unsigned short portamThrVal; From 4df0bf068cd322700b2d515a07ea62b129705264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Tue, 25 Jun 2019 13:40:45 +0200 Subject: [PATCH 6/6] More stale code removal --- NuEVI/hardware.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuEVI/hardware.h b/NuEVI/hardware.h index 965b636..53c456f 100644 --- a/NuEVI/hardware.h +++ b/NuEVI/hardware.h @@ -74,7 +74,7 @@ * */ -# else +# else //REV A // MPR121 pins Rev A (upright pins below MPR121 for main keys and rollers)