Added ICM, knob CCs

This commit is contained in:
Brian Hrebec 2023-08-30 23:54:06 -05:00
parent e757ebc885
commit 00cdfc08e0
7 changed files with 125 additions and 46 deletions

View file

@ -231,17 +231,17 @@ int breath() {
// send midi cc
midiSendControlChange(state.currentPreset->breathCC, breathCCval);
}
if (state.currentPreset->breathMode == BreathMode::BREATH_AT
|| state.currentPreset->breathMode == BreathMode::BREATH_LSB_AT
|| state.currentPreset->breathMode == BreathMode::BREATH_ACC_AT) {
if (state.currentPreset->breathMode == BreathMode::BREATH_AT
|| state.currentPreset->breathMode == BreathMode::BREATH_LSB_AT
|| state.currentPreset->breathMode == BreathMode::BREATH_ACC_AT) {
// send aftertouch
midiSendAfterTouch(breathCCval);
}
oldbreath = breathCCval;
}
if (breathCCvalHires != oldbreathhires
&& (state.currentPreset->breathMode == BreathMode::BREATH_LSB || state.currentPreset->breathMode == BreathMode::BREATH_LSB_AT)) {
if (breathCCvalHires != oldbreathhires
&& (state.currentPreset->breathMode == BreathMode::BREATH_LSB || state.currentPreset->breathMode == BreathMode::BREATH_LSB_AT)) {
midiSendControlChange(state.currentPreset->breathCC + 32, breathCCvalFine);
}
@ -299,13 +299,13 @@ void pitch_bend() {
if (ExtraControl::VIBRATO == state.currentPreset->leverControl) { // lever vibrato
vibRead = instrument.leverSignal;
if (vibRead > instrument.vibThr) {
instrument.vibSignal = (instrument.vibSignal +
mapConstrain(vibRead, (instrument.vibZero - vibMax), instrument.vibThr, calculatedDepth, 0)
) / 2;
instrument.vibSignal = (instrument.vibSignal +
mapConstrain(vibRead, (instrument.vibZero - vibMax), instrument.vibThr, calculatedDepth, 0)
) / 2;
} else if (vibRead < instrument.vibThrLo) {
instrument.vibSignal = (instrument.vibSignal +
mapConstrain(vibRead, (instrument.vibZero + vibMax), instrument.vibThr, calculatedDepth, 0)
) / 2;
instrument.vibSignal = (instrument.vibSignal +
mapConstrain(vibRead, (instrument.vibZero + vibMax), instrument.vibThr, calculatedDepth, 0)
) / 2;
} else {
instrument.vibSignal = instrument.vibSignal / 2;
}
@ -425,6 +425,52 @@ void sendCC() {
}
instrument.extraVal = extraVal;
}
if (!inMenu()) {
for (int i = 0; i < 4; i++) {
byte val = constrain((int)state.instrument->knobVals[i] + readKnob(i), 0, 127);
if (state.instrument->knobVals[i] != val) {
switch (i) {
case 0:
midiSendControlChange(state.currentPreset->knob1CC, val);
break;
case 1:
midiSendControlChange(state.currentPreset->knob2CC, val);
break;
case 2:
midiSendControlChange(state.currentPreset->knob3CC, val);
break;
case 3:
midiSendControlChange(state.currentPreset->knob4CC, val);
break;
}
}
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
@ -444,7 +490,7 @@ void autoCal() {
instrument.vibZero = instrument.vibZeroBite = 0;
long int bZero = 0;
long int bAltZero = 0;
for(int i = 1 ; i <= CALIBRATE_SAMPLE_COUNT; ++i) {
for (int i = 1; i <= CALIBRATE_SAMPLE_COUNT; ++i) {
bZero += readPressure();
bAltZero += readAltPressure();
instrument.vibZero += readTouchUtil(leverPin);
@ -464,9 +510,9 @@ void fullAutoCal() {
int calReadNext;
calibration.breathAltThrValOffset = 5;
calibration.breathAltMaxValOffset = 1500 ;
calibration.breathAltMaxValOffset = 1500;
calibration.breathThrValOffset = 5;
calibration.breathMaxValOffset = 1500 ;
calibration.breathMaxValOffset = 1500;
autoCal();
// Lever
@ -841,7 +887,7 @@ void setup() {
Serial.begin(9600); // debug
Serial.println("Debug Startup");
if (CrashReport) {
while (!Serial) ; // wait for serial monitor open
while (!Serial); // wait for serial monitor open
Serial.print(CrashReport);
}
@ -912,7 +958,7 @@ void loop() {
int16_t spikeSignal = constrain(readSpikePressure(), -SPIKE_HI_LIMIT, SPIKE_HI_LIMIT);
if (state.currentPreset->breathMode == BREATH_ACC || state.currentPreset-> breathMode == BREATH_ACC_AT) {
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);
@ -922,18 +968,18 @@ void loop() {
}
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);
*/
/*
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);
*/
runStateMachine();
sendCCs();