Cleanup pair octaves
This commit is contained in:
parent
00cdfc08e0
commit
c09177c0ee
9 changed files with 119 additions and 70 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "led.h"
|
||||
#include "test.h"
|
||||
#include "FilterOnePole.h"
|
||||
#include "icm.h"
|
||||
|
||||
/*
|
||||
NAME: xEVI
|
||||
|
@ -92,6 +93,7 @@ bool configManagementMode = false;
|
|||
bool testMode = false;
|
||||
|
||||
FilterOnePole breathCCFilter;
|
||||
FilterOnePole breathBaselineFilter;
|
||||
|
||||
//_______________________________________________________________________________________________ SETUP
|
||||
|
||||
|
@ -444,33 +446,13 @@ void sendCC() {
|
|||
midiSendControlChange(state.currentPreset->knob4CC, val);
|
||||
break;
|
||||
}
|
||||
|
||||
state.instrument->knobVals[i] = val;
|
||||
state.instrument->lastKnobVal = val;
|
||||
state.instrument->lastKnobTime = millis();
|
||||
}
|
||||
|
||||
state.instrument->knobVals[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
icm_result_t icmSignal = readICM();
|
||||
Serial.print(">roll: ");
|
||||
Serial.println(icmSignal.roll);
|
||||
Serial.print(">tilt: ");
|
||||
Serial.println(icmSignal.tilt);
|
||||
if (ExtraControl::CC == state.currentPreset->icmRollMode) {
|
||||
byte roll = mapConstrain(abs(icmSignal.roll), 0, 40, 127, 0);
|
||||
if (roll != state.instrument->rollCCVal) {
|
||||
midiSendControlChange(state.currentPreset->icmRollCC, roll);
|
||||
state.instrument->rollCCVal = roll;
|
||||
}
|
||||
}
|
||||
|
||||
if (ExtraControl::CC == state.currentPreset->icmTiltMode) {
|
||||
byte tilt = mapConstrain(abs(icmSignal.tilt), -20, 40, 0, 127);
|
||||
if (tilt != state.instrument->tiltCCVal) {
|
||||
midiSendControlChange(state.currentPreset->icmTiltCC, tilt);
|
||||
state.instrument->tiltCCVal = tilt;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Re-zero floating calibration values
|
||||
|
@ -602,7 +584,7 @@ int readOctave() {
|
|||
if (rollers[0]) {
|
||||
octaveR = 1;
|
||||
} else if (rollers[5]) {
|
||||
octaveR = 6;
|
||||
octaveR = 7;
|
||||
}
|
||||
}
|
||||
} else if (rollerMode == RollerMode::PARTIAL || rollerMode == RollerMode::PARTIAL_EXTEND) {
|
||||
|
@ -632,6 +614,8 @@ int readOctave() {
|
|||
if (extend && octaveR == 0) {
|
||||
if (rollerMode == RollerMode::HIGHEST_EXTEND && lastOctaveR == 6) {
|
||||
octaveR = 7;
|
||||
} else if (rollerMode == RollerMode::HIGHEST_PAIR_EXTEND && lastOctaveR == 7) {
|
||||
octaveR = 8;
|
||||
} else if (rollerMode == RollerMode::PARTIAL_EXTEND && lastOctaveR == 7) {
|
||||
octaveR = 8;
|
||||
} else if (lastOctaveR == 1) {
|
||||
|
@ -785,7 +769,8 @@ void initState() {
|
|||
|
||||
instrument.activeMIDIchannel = state.currentPreset->MIDIchannel;
|
||||
midiInitialize(state.currentPreset->MIDIchannel);
|
||||
breathCCFilter.setFilter(LOWPASS, 3, 0.0); // create a one pole (RC) lowpass filter
|
||||
breathCCFilter.setFilter(LOWPASS, 3, 0.0);
|
||||
breathBaselineFilter.setFilter(LOWPASS, 1, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -802,7 +787,7 @@ void readUtil() {
|
|||
/**
|
||||
* Send CC data when needed
|
||||
*/
|
||||
void sendCCs() {
|
||||
void handleCCs() {
|
||||
static unsigned long ccBreathSendTime = 0L; // The last time we sent breath CC values
|
||||
static unsigned long ccSendTime = 0L; // The last time we sent CC values
|
||||
static unsigned long ccSendTime2 = 0L; // The last time we sent CC values 2 (slower)
|
||||
|
@ -819,6 +804,7 @@ void sendCCs() {
|
|||
readUtil();
|
||||
pitch_bend();
|
||||
sendCC();
|
||||
checkICM(state);
|
||||
ccSendTime = currentTime;
|
||||
}
|
||||
if (currentTime - ccSendTime2 > CC_INTERVAL_PORT) {
|
||||
|
@ -833,6 +819,43 @@ void sendCCs() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the breath sensors according to the active mode
|
||||
*/
|
||||
void readBreath() {
|
||||
|
||||
int16_t breathSignal = constrain(readPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP
|
||||
int16_t spikeSignal = constrain(readSpikePressure(), -SPIKE_HI_LIMIT, SPIKE_HI_LIMIT);
|
||||
instrument.breathMovingThrVal = constrain(
|
||||
breathBaselineFilter.input((breathSignal + instrument.breathZero) / 2),
|
||||
instrument.breathThrVal,
|
||||
instrument.breathMaxVal
|
||||
);
|
||||
|
||||
if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset->breathMode == BREATH_ACC_AT) {
|
||||
int delta = breathSignal - instrument.breathZero;
|
||||
if (abs(delta) > state.calibration->breathAltThrValOffset) {
|
||||
instrument.breathSignal = constrain(instrument.breathSignal + delta / 10, instrument.breathZero, instrument.breathMaxVal);
|
||||
}
|
||||
} else {
|
||||
instrument.breathSignal = breathSignal + (spikeSignal > 0 ? spikeSignal * state.currentPreset->spikeOnFactor : spikeSignal * state.currentPreset->spikeOffFactor);
|
||||
}
|
||||
instrument.breathAltSignal = constrain(readAltPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP
|
||||
|
||||
Serial.print(">breathThr:");
|
||||
Serial.println(instrument.breathThrVal);
|
||||
Serial.print(">breathMovingThr:");
|
||||
Serial.println(instrument.breathMovingThrVal);
|
||||
Serial.print(">note:");
|
||||
Serial.println(state.mainState);
|
||||
Serial.print(">spike:");
|
||||
Serial.println(spikeSignal);
|
||||
Serial.print(">breath:");
|
||||
Serial.println(breathSignal);
|
||||
Serial.print(">combo:");
|
||||
Serial.println(instrument.breathSignal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main instrument state machine
|
||||
*/
|
||||
|
@ -842,7 +865,7 @@ void runStateMachine() {
|
|||
int fingeredNote = noteValueCheck(readSwitches() + readOctave());
|
||||
if (state.mainState == NOTE_OFF) {
|
||||
handleOffStateActions();
|
||||
if (instrument.breathSignal > instrument.breathThrVal && state.mainState == NOTE_OFF) {
|
||||
if (instrument.breathSignal > instrument.breathMovingThrVal && state.mainState == NOTE_OFF) {
|
||||
// Value has risen above threshold. Move to the RISE_WAIT
|
||||
// state. Record time and initial breath value.
|
||||
breath_on_time = millis();
|
||||
|
@ -850,7 +873,7 @@ void runStateMachine() {
|
|||
state.mainState = RISE_WAIT; // Go to next state
|
||||
}
|
||||
} else if (state.mainState == RISE_WAIT) {
|
||||
if ((instrument.breathSignal > instrument.breathThrVal)) {
|
||||
if ((instrument.breathSignal > instrument.breathMovingThrVal)) {
|
||||
// Has enough time passed for us to collect our second sample?
|
||||
if ((millis() - breath_on_time > state.currentPreset->velSmpDl) || (0 == state.currentPreset->velSmpDl) || state.currentPreset->fixedVelocity) {
|
||||
noteOn(fingeredNote, instrument.breathSignal, initial_breath_value);
|
||||
|
@ -862,7 +885,7 @@ void runStateMachine() {
|
|||
state.mainState = NOTE_OFF;
|
||||
}
|
||||
} else if (state.mainState == NOTE_ON) {
|
||||
if (instrument.breathSignal < instrument.breathThrVal) {
|
||||
if (instrument.breathSignal < instrument.breathMovingThrVal) {
|
||||
// Value has fallen below threshold - turn the note off
|
||||
midiSendNoteOff(instrument.activeNote); // send Note Off message
|
||||
instrument.breathSignal = 0;
|
||||
|
@ -954,35 +977,10 @@ void loop() {
|
|||
return;
|
||||
}
|
||||
|
||||
int16_t breathSignal = constrain(readPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP
|
||||
int16_t spikeSignal = constrain(readSpikePressure(), -SPIKE_HI_LIMIT, SPIKE_HI_LIMIT);
|
||||
|
||||
|
||||
if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset->breathMode == BREATH_ACC_AT) {
|
||||
int delta = breathSignal - instrument.breathZero;
|
||||
if (abs(delta) > state.calibration->breathAltThrValOffset) {
|
||||
instrument.breathSignal = constrain(instrument.breathSignal + delta / 10, instrument.breathZero, instrument.breathMaxVal);
|
||||
}
|
||||
} else {
|
||||
instrument.breathSignal = breathSignal + (spikeSignal > 0 ? spikeSignal * state.currentPreset->spikeOnFactor : spikeSignal * state.currentPreset->spikeOffFactor);
|
||||
}
|
||||
instrument.breathAltSignal = constrain(readAltPressure(), BREATH_LO_LIMIT, BREATH_HI_LIMIT); // Get the filtered pressure sensor reading from analog pin A0, input from sensor MP3V5004GP
|
||||
|
||||
/*
|
||||
Serial.print(">breathThr:");
|
||||
Serial.println(instrument.breathThrVal);
|
||||
Serial.print(">note:");
|
||||
Serial.println(state.mainState);
|
||||
Serial.print(">spike:");
|
||||
Serial.println(spikeSignal);
|
||||
Serial.print(">breath:");
|
||||
Serial.println(breathSignal);
|
||||
Serial.print(">combo:");
|
||||
Serial.println(instrument.breathSignal);
|
||||
*/
|
||||
readBreath();
|
||||
|
||||
runStateMachine();
|
||||
sendCCs();
|
||||
handleCCs();
|
||||
|
||||
// cvUpdate();
|
||||
midiDiscardInput();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue