From 88b38b3f4645b7a30de0f482f0e4b18666c51f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:07:10 +0200 Subject: [PATCH 1/6] Remove trailing whitespace --- NuEVI/NuEVI.ino | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 7da63c5..d394fb1 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -374,7 +374,7 @@ void loop() { } breathFilter.input(analogRead(breathSensorPin)); - pressureSensor = constrain((int) breathFilter.output(), 0, 4095); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP + pressureSensor = constrain((int) breathFilter.output(), 0, 4095); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP readSwitches(); if (mainState == NOTE_OFF) { if (activeMIDIchannel != MIDIchannel) { @@ -503,7 +503,7 @@ void loop() { if (analogRead(breathSensorPin) > (breathCalZero - 800)) programonce = false; specialKey = (touchRead(specialKeyPin) > touch_Thr); //S2 on pcb - if (specialKeyEnable) { + if (specialKeyEnable) { if (lastSpecialKey != specialKey) { if (specialKey) { // special key just pressed, check other keys @@ -563,7 +563,7 @@ void loop() { else midiSendAfterTouch(levelVal); } } else if (lastPinkyKey){ - writeSetting(LEVEL_VAL_ADDR,levelVal); + writeSetting(LEVEL_VAL_ADDR,levelVal); } lastPinkyKey = pinkyKey; } @@ -793,7 +793,7 @@ void loop() { dacModeCopy = dacMode; brZero = breathThrVal; interrupts(); - + midiDiscardInput(); //do menu stuff @@ -919,8 +919,8 @@ void pitch_bend() { if (vibControl){ //bite vibrato if (biteJumper){ //PBITE (if pulled low with jumper, use pressure sensor instead of capacitive bite sensor) vibReadBite = analogRead(bitePressurePin); // alternative kind bite sensor (air pressure tube and sensor) PBITE - } else { - vibReadBite = touchRead(bitePin); // get sensor data, do some smoothing - SENSOR PIN 17 - PCB PINS LABELED "BITE" (GND left, sensor pin right) + } else { + vibReadBite = touchRead(bitePin); // get sensor data, do some smoothing - SENSOR PIN 17 - PCB PINS LABELED "BITE" (GND left, sensor pin right) } if (vibReadBite < vibThrBite) { if (UPWD == vibDirection) { @@ -939,7 +939,7 @@ void pitch_bend() { } } if (vibControl != 1) { //lever vibrato - vibRead = touchRead(vibratoPin); // SENSOR PIN 15 - built in var cap + vibRead = touchRead(vibratoPin); // SENSOR PIN 15 - built in var cap if (vibRead < vibThr) { if (UPWD == vibDirection) { vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibRead, (vibZero - vibMax), vibThr), vibThr, (vibZero - vibMax), 0, calculatedPBdepth * vibDepth[vibrato]); @@ -1073,7 +1073,7 @@ void extraController() { } } else if (pinkySetting == ECSW){ if (pinkyKey){ - //send extra controller CC2 only + //send extra controller CC2 only CC2sw = 1; CC1sw = 0; } else { @@ -1160,7 +1160,7 @@ void portamento_() { 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) + biteSensor = touchRead(bitePin); // get sensor data, do some smoothing - SENSOR PIN 17 - PCB PINS LABELED "BITE" (GND left, sensor pin right) } if (0 == vibControl) { // Portamento is controlled with the bite sensor (variable capacitor) in the mouthpiece @@ -1230,7 +1230,7 @@ void portOff() { void readTeensySwitches() { //these seem to slow things down, so do it less often - pinkyKey = (touchRead(halfPitchBendKeyPin) > touch_Thr); // SENSOR PIN 1 - PCB PIN "S1" + pinkyKey = (touchRead(halfPitchBendKeyPin) > touch_Thr); // SENSOR PIN 1 - PCB PIN "S1" } void readSwitches() { @@ -1248,7 +1248,7 @@ void readSwitches() { R3 = touchKeys[R3Pin]; R4 = touchKeys[R4Pin]; R5 = touchKeys[R5Pin]; - + octaveR = 0; if (R5 && R3) octaveR = 6; //R6 = R5 && R3 else if (R5) octaveR = 5; //R5 From f36129d4bb600587700317ab9f2e53d80b825bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:28:01 +0200 Subject: [PATCH 2/6] Make IntervalTimer stub so simulator works --- NuEVI/NuEVI.ino | 19 ++++++++++--------- simulation/include/interrupts.h | 17 +++++++++++++++++ simulation/src/nuevisim.cpp | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 simulation/include/interrupts.h diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index d394fb1..ff47543 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -261,6 +261,16 @@ bool configManagementMode = false; //_______________________________________________________________________________________________ SETUP +//Update CV output pin, run from timer. +void cvUpdate(){ + int cvPressure = analogRead(breathSensorPin); + if(dacModeCopy == DAC_MODE_PITCH){ + analogWrite(pwmDacPin,cvPressure); + } else { //DAC_MODE_BREATH + analogWrite(dacPin,map(constrain(cvPressure,brZero,4095),brZero,4095,0,4095)); + } +} + void setup() { analogReadResolution(12); // set resolution of ADCs to 12 bit @@ -802,15 +812,6 @@ void loop() { //_______________________________________________________________________________________________ FUNCTIONS -void cvUpdate(){ - int cvPressure = analogRead(breathSensorPin); - if(dacModeCopy == DAC_MODE_PITCH){ - analogWrite(pwmDacPin,cvPressure); - } else { //DAC_MODE_BREATH - analogWrite(dacPin,map(constrain(cvPressure,brZero,4095),brZero,4095,0,4095)); - } -} - // non linear mapping function (http://playground.arduino.cc/Main/MultiMap) // note: the _in array should have increasing values diff --git a/simulation/include/interrupts.h b/simulation/include/interrupts.h new file mode 100644 index 0000000..1da6763 --- /dev/null +++ b/simulation/include/interrupts.h @@ -0,0 +1,17 @@ +#ifndef __INTERRUPTS_H +#define __INTERRUPTS_H + +//Dummy functions, used by macros for interrupts() / noInterrupts() +void __enable_irq() {} +void __disable_irq() {} + + +struct IntervalTimer +{ + public: + IntervalTimer() {}; + bool begin(void (*funct)(), unsigned int microseconds) { }; + +}; + +#endif diff --git a/simulation/src/nuevisim.cpp b/simulation/src/nuevisim.cpp index 3388e1e..6b2d46b 100644 --- a/simulation/src/nuevisim.cpp +++ b/simulation/src/nuevisim.cpp @@ -15,6 +15,7 @@ #include "examples/imgui_impl_opengl3.h" #include "EEPROM.h" #include "simusbmidi.h" +#include "interrupts.h" #include From 7c1aa2c0a435ab334dfb10195818d45784a0b4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:28:23 +0200 Subject: [PATCH 3/6] touchValue never used here, no point in reading touch data. --- NuEVI/NuEVI.ino | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index ff47543..5934dc6 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -1027,10 +1027,7 @@ void pitch_bend() { //*********************************************************** void doorKnobCheck() { - int touchValue[12]; - for (byte i = 0; i < 12; i++) { - touchValue[i] = touchSensor.filteredData(i); - } + if (gateOpenEnable){ if (K4 && R1 && R2 && R3) { // doorknob grip on canister if (!gateOpen && (pbUp > ((pitchbMaxVal + pitchbThrVal) / 2))) { From 0cbb6bde782062f4cb6527fe917647c703775c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:30:49 +0200 Subject: [PATCH 4/6] Explicitly initialize variables, use "bool-specific" values when setting. --- NuEVI/NuEVI.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 5934dc6..ef82a2a 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -1051,8 +1051,8 @@ void doorKnobCheck() { //*********************************************************** void extraController() { - bool CC2sw; - bool CC1sw; + bool CC2sw = false; + bool CC1sw = false; int extracCC; // Extra Controller is the lip touch sensor (proportional) in front of the mouthpiece exSensor = exSensor * 0.6 + 0.4 * touchRead(extraPin); // get sensor data, do some smoothing - SENSOR PIN 16 - PCB PIN "EC" (marked K4 on some prototype boards) @@ -1072,17 +1072,17 @@ void extraController() { } else if (pinkySetting == ECSW){ if (pinkyKey){ //send extra controller CC2 only - CC2sw = 1; - CC1sw = 0; + CC2sw = true; + CC1sw = false; } else { //send extra controller primary CC only - CC2sw = 0; - CC1sw = 1; + CC2sw = false; + CC1sw = true; } } else { //send both primary CC and CC2 - CC2sw = 1; - CC1sw = 1; + CC2sw = true; + CC1sw = true; } if ((extraCT || extraCT2) && (exSensor >= extracThrVal)) { // if we are enabled and over the threshold, send data if (!extracIsOn) { From cb7a4a8b88b29d6ad7eb05389f512215800f554f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:49:52 +0200 Subject: [PATCH 5/6] No need for volatile copies of these variables. --- NuEVI/NuEVI.ino | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index ef82a2a..6621a7e 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -89,9 +89,6 @@ uint16_t trill3_interval; uint16_t fastBoot; uint16_t dacMode; -volatile uint16_t dacModeCopy; -volatile unsigned short brZero; - byte rotatorOn = 0; byte currentRotation = 0; uint16_t rotations[4]; // semitones { -5, -10, -7, -14 }; @@ -264,10 +261,10 @@ bool configManagementMode = false; //Update CV output pin, run from timer. void cvUpdate(){ int cvPressure = analogRead(breathSensorPin); - if(dacModeCopy == DAC_MODE_PITCH){ + if(dacMode == DAC_MODE_PITCH){ analogWrite(pwmDacPin,cvPressure); } else { //DAC_MODE_BREATH - analogWrite(dacPin,map(constrain(cvPressure,brZero,4095),brZero,4095,0,4095)); + analogWrite(dacPin,map(constrain(cvPressure,breathThrVal,4095),breathThrVal,4095,0,4095)); } } @@ -799,10 +796,6 @@ void loop() { } else if(dacMode == DAC_MODE_BREATH) { // else breath CV on DAC pin, directly to unused pin of MIDI DIN jack //analogWrite(dacPin,breathCurve(map(constrain(pressureSensor,breathThrVal,breathMaxVal),breathThrVal,breathMaxVal,0,4095))); } - noInterrupts(); - dacModeCopy = dacMode; - brZero = breathThrVal; - interrupts(); midiDiscardInput(); From 049cb6d4348f862cf5fa312ceb1bf8f8ef57a02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Wed, 16 Oct 2019 15:54:11 +0200 Subject: [PATCH 6/6] Avoid floating-point math for vibrato calculations --- NuEVI/NuEVI.ino | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 6621a7e..9c95ed6 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -916,38 +916,38 @@ void pitch_bend() { } else { vibReadBite = touchRead(bitePin); // get sensor data, do some smoothing - SENSOR PIN 17 - PCB PINS LABELED "BITE" (GND left, sensor pin right) } - if (vibReadBite < vibThrBite) { + if (vibReadBite < vibThrBite) { if (UPWD == vibDirection) { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibReadBite, (vibZeroBite - vibMaxBite), vibThrBite), vibThrBite, (vibZeroBite - vibMaxBite), 0, calculatedPBdepth * vibDepth[vibrato]); + vibSignal = (vibSignal + map(constrain(vibReadBite, (vibZeroBite - vibMaxBite), vibThrBite), vibThrBite, (vibZeroBite - vibMaxBite), 0, calculatedPBdepth * vibDepth[vibrato]))/2; } else { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibReadBite, (vibZeroBite - vibMaxBite), vibThrBite), vibThrBite, (vibZeroBite - vibMaxBite), 0, (0 - calculatedPBdepth * vibDepth[vibrato])); + vibSignal = (vibSignal + map(constrain(vibReadBite, (vibZeroBite - vibMaxBite), vibThrBite), vibThrBite, (vibZeroBite - vibMaxBite), 0, (0 - calculatedPBdepth * vibDepth[vibrato])))/2; } } else if (vibReadBite > vibThrBiteLo) { if (UPWD == vibDirection) { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibReadBite, vibThrBiteLo, (vibZeroBite + vibMaxBite)), vibThrBiteLo, (vibZeroBite + vibMaxBite), 0, (0 - calculatedPBdepth * vibDepth[vibrato])); + vibSignal = (vibSignal + map(constrain(vibReadBite, vibThrBiteLo, (vibZeroBite + vibMaxBite)), vibThrBiteLo, (vibZeroBite + vibMaxBite), 0, (0 - calculatedPBdepth * vibDepth[vibrato])))/2; } else { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibReadBite, vibThrBiteLo, (vibZeroBite + vibMaxBite)), vibThrBiteLo, (vibZeroBite + vibMaxBite), 0, calculatedPBdepth * vibDepth[vibrato]); + vibSignal = (vibSignal + map(constrain(vibReadBite, vibThrBiteLo, (vibZeroBite + vibMaxBite)), vibThrBiteLo, (vibZeroBite + vibMaxBite), 0, calculatedPBdepth * vibDepth[vibrato]))/2; } } else { - vibSignal = vibSignal * 0.5; + vibSignal = vibSignal / 2; } } if (vibControl != 1) { //lever vibrato vibRead = touchRead(vibratoPin); // SENSOR PIN 15 - built in var cap if (vibRead < vibThr) { if (UPWD == vibDirection) { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibRead, (vibZero - vibMax), vibThr), vibThr, (vibZero - vibMax), 0, calculatedPBdepth * vibDepth[vibrato]); + vibSignal = (vibSignal + map(constrain(vibRead, (vibZero - vibMax), vibThr), vibThr, (vibZero - vibMax), 0, calculatedPBdepth * vibDepth[vibrato]))/2; } else { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibRead, (vibZero - vibMax), vibThr), vibThr, (vibZero - vibMax), 0, (0 - calculatedPBdepth * vibDepth[vibrato])); + vibSignal = (vibSignal + map(constrain(vibRead, (vibZero - vibMax), vibThr), vibThr, (vibZero - vibMax), 0, (0 - calculatedPBdepth * vibDepth[vibrato])))/2; } } else if (vibRead > vibThrLo) { if (UPWD == vibDirection) { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibRead, vibThrLo, (vibZero + vibMax)), vibThrLo, (vibZero + vibMax), 0, (0 - calculatedPBdepth * vibDepth[vibrato])); + vibSignal = (vibSignal + map(constrain(vibRead, vibThrLo, (vibZero + vibMax)), vibThrLo, (vibZero + vibMax), 0, (0 - calculatedPBdepth * vibDepth[vibrato])))/2; } else { - vibSignal = vibSignal * 0.5 + 0.5 * map(constrain(vibRead, vibThrLo, (vibZero + vibMax)), vibThrLo, (vibZero + vibMax), 0, calculatedPBdepth * vibDepth[vibrato]); + vibSignal = (vibSignal + map(constrain(vibRead, vibThrLo, (vibZero + vibMax)), vibThrLo, (vibZero + vibMax), 0, calculatedPBdepth * vibDepth[vibrato]))/2; } } else { - vibSignal = vibSignal * 0.5; + vibSignal = vibSignal / 2; } }