Skip to content

Commit

Permalink
Increase threshold for CV change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chysn committed Nov 8, 2018
1 parent 7f4db7d commit 132a048
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
18 changes: 5 additions & 13 deletions software/o_c_REV/APP_MIDI.ino
Expand Up @@ -144,6 +144,7 @@ struct CaptainMIDILog {
if (app_code == 'E') graphics.print("Scale Ed");
if (app_code == 'T') graphics.print("Enigma");
if (app_code == 'W') graphics.print("Waveform Ed");
if (app_code == '_') graphics.print("O_C EEPROM");
}
} else {
graphics.setPrintPos(1, y);
Expand Down Expand Up @@ -400,7 +401,6 @@ private:
int note_out[4]; // Most recent note from this input channel
int last_channel[4]; // Keep track of the actual send channel, in case it's changed while the note is on
int legato_on[4]; // The note handler may currently respond to legato note changes
int last_cv[4]; // To determine whether a new CV value needs to be handled for MIDI controllers
uint16_t indicator_out[4]; // A MIDI indicator will display next to MIDI Out assignment

void DrawSetupScreens() {
Expand Down Expand Up @@ -583,10 +583,7 @@ private:
}

// Handle other messages
int this_cv = In(ch);
if (cv_has_changed(this_cv, last_cv[ch])) {
last_cv[ch] = this_cv;

if (Changed(ch)) {
// Modulation wheel
if (out_fn == MIDI_OUT_MOD || out_fn >= MIDI_OUT_EXPRESSION) {
int cc = 1; // Modulation wheel
Expand All @@ -596,7 +593,7 @@ private:
if (out_fn == MIDI_OUT_BREATH) cc = 2;
if (out_fn == MIDI_OUT_Y_AXIS) cc = 74;

int value = Proportion(this_cv, HSAPPLICATION_5V, 127);
int value = Proportion(In(ch), HSAPPLICATION_5V, 127);
value = constrain(value, 0, 127);
if (cc == 64) value = (value >= 60) ? 127 : 0; // On or off for sustain pedal

Expand All @@ -607,7 +604,7 @@ private:

// Aftertouch
if (out_fn == MIDI_OUT_AFTERTOUCH) {
int value = Proportion(this_cv, HSAPPLICATION_5V, 127);
int value = Proportion(In(ch), HSAPPLICATION_5V, 127);
value = constrain(value, 0, 127);
usbMIDI.sendAfterTouch(value, out_ch);
UpdateLog(0, ch, 3, out_ch, 0, value);
Expand All @@ -616,7 +613,7 @@ private:

// Pitch Bend
if (out_fn == MIDI_OUT_PITCHBEND) {
int16_t bend = Proportion(this_cv + HSAPPLICATION_3V, HSAPPLICATION_3V * 2, 16383);
int16_t bend = Proportion(In(ch) + HSAPPLICATION_3V, HSAPPLICATION_3V * 2, 16383);
bend = constrain(bend, 0, 16383);
usbMIDI.sendPitchBend(bend, out_ch);
UpdateLog(0, ch, 4, out_ch, 0, bend - 8192);
Expand Down Expand Up @@ -811,11 +808,6 @@ private:
return (note >= range_low && note <= range_high);
}

bool cv_has_changed(int this_cv, int last_cv) {
int diff = this_cv - last_cv;
return (diff > 50 || diff < -50) ? 1 : 0;
}

void UpdateLog(bool midi_in, int ch, uint8_t message, uint8_t channel, int16_t data1, int16_t data2) {
// Don't log SysEx unless the user is on the log display screen
if (message == 5 && display == 0) return;
Expand Down
17 changes: 4 additions & 13 deletions software/o_c_REV/HEM_hMIDIOut.ino
Expand Up @@ -97,13 +97,10 @@ public:

// Handle other messages
if (function != HEM_MIDI_VEL_IN) {
int this_cv = In(1);
if (cv_has_changed(this_cv, last_cv)) {
last_cv = this_cv;

if (Changed(1)) {
// Modulation wheel
if (function == HEM_MIDI_CC_IN) {
int value = ProportionCV(this_cv, 127);
int value = ProportionCV(In(1), 127);
usbMIDI.sendControlChange(1, value, channel + 1);
usbMIDI.send_now();
UpdateLog(HEM_MIDI_CC, value, 0);
Expand All @@ -112,7 +109,7 @@ public:

// Aftertouch
if (function == HEM_MIDI_AT_IN) {
int value = ProportionCV(this_cv, 127);
int value = ProportionCV(In(1), 127);
usbMIDI.sendAfterTouch(value, channel + 1);
usbMIDI.send_now();
UpdateLog(HEM_MIDI_AFTERTOUCH, value, 0);
Expand All @@ -121,7 +118,7 @@ public:

// Pitch Bend
if (function == HEM_MIDI_PB_IN) {
uint16_t bend = Proportion(this_cv + HEMISPHERE_3V_CV, HEMISPHERE_3V_CV * 2, 16383);
uint16_t bend = Proportion(In(1) + HEMISPHERE_3V_CV, HEMISPHERE_3V_CV * 2, 16383);
bend = constrain(bend, 0, 16383);
usbMIDI.sendPitchBend(bend, channel + 1);
usbMIDI.send_now();
Expand Down Expand Up @@ -191,7 +188,6 @@ private:
bool legato_on; // The note handler may currently respond to legato note changes
int last_tick; // Most recent MIDI message sent
int adc_lag_countdown;
int last_cv; // For checking for changes
const char* fn_name[4];

// Logging
Expand Down Expand Up @@ -255,11 +251,6 @@ private:
}
}

bool cv_has_changed(int this_cv, int last_cv) {
int diff = this_cv - last_cv;
return (diff > 50 || diff < -50) ? 1 : 0;
}

void log_entry(int y, int index) {
if (log[index].message == HEM_MIDI_NOTE_ON) {
gfxBitmap(1, y, 8, NOTE_ICON);
Expand Down
3 changes: 2 additions & 1 deletion software/o_c_REV/HSApplication.h
Expand Up @@ -39,6 +39,7 @@ typedef int32_t simfloat;
#define HSAPPLICATION_CURSOR_TICKS 12000
#define HSAPPLICATION_5V 7680
#define HSAPPLICATION_3V 4608
#define HSAPPLICATION_CHANGE_THRESHOLD 32

class HSApplication {
public:
Expand All @@ -52,7 +53,7 @@ class HSApplication {
{
// Set ADC input values
inputs[ch] = OC::ADC::raw_pitch_value((ADC_CHANNEL)ch);
if (abs(inputs[ch] - last_cv[ch]) > 16) {
if (abs(inputs[ch] - last_cv[ch]) > HSAPPLICATION_CHANGE_THRESHOLD) {
changed_cv[ch] = 1;
last_cv[ch] = inputs[ch];
} else changed_cv[ch] = 0;
Expand Down
5 changes: 3 additions & 2 deletions software/o_c_REV/HemisphereApplet.h
Expand Up @@ -31,7 +31,8 @@
#define HEMISPHERE_3V_CV 4608
#define HEMISPHERE_CLOCK_TICKS 100
#define HEMISPHERE_CURSOR_TICKS 12000
#define HEMISPHERE_ADC_LAG 33;
#define HEMISPHERE_ADC_LAG 33
#define HEMISPHERE_CHANGE_THRESHOLD 32

// Codes for help system sections
#define HEMISPHERE_HELP_DIGITALS 0
Expand Down Expand Up @@ -106,7 +107,7 @@ class HemisphereApplet {

ADC_CHANNEL channel = (ADC_CHANNEL)(ch + io_offset);
inputs[ch] = OC::ADC::raw_pitch_value(channel);
if (abs(inputs[ch] - last_cv[ch]) > 16) {
if (abs(inputs[ch] - last_cv[ch]) > HEMISPHERE_CHANGE_THRESHOLD) {
changed_cv[ch] = 1;
last_cv[ch] = inputs[ch];
} else changed_cv[ch] = 0;
Expand Down

0 comments on commit 132a048

Please sign in to comment.