Several optimizations.

Code cleanup.
Fixing midi_devices.hpp setup.
pull/4/head
Holger Wirtz 6 years ago
parent 168eedeb8d
commit f2ef327d97
  1. 99
      MicroDexed.ino
  2. 89
      dexed.cpp
  3. 32
      midi_devices.hpp

@ -274,12 +274,6 @@ void setup()
Serial.print(1000000 / (SAMPLE_RATE / AUDIO_BLOCK_SAMPLES));
Serial.println(F("ms)"));
#ifdef TEST_NOTE
Serial.println(F("MIDI test enabled"));
sched_note_on.begin(note_on, 2000000);
sched_note_off.begin(note_off, 6333333);
#endif
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
show_cpu_and_mem_usage();
#endif
@ -291,20 +285,6 @@ void setup()
AudioInterrupts();
Serial.println(F("<setup end>"));
#ifdef TEST_NOTE
//dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_DEP] = 99; // full pitch mod depth
//dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_SENS] = 99; // full pitch mod sense
//dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_MODWHEEL_ASSIGN] = 7; // mod wheel assign all
//dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_FOOTCTRL_ASSIGN] = 7; // foot ctrl assign all
//dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_BREATHCTRL_ASSIGN] = 7; // breath ctrl assign all
//dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+AT_ASSIGN] = 7; // at ctrl assign all
//queue_midi_event(0xb0, 1, 99); // test mod wheel
//queue_midi_event(0xb0, 2, 99); // test breath ctrl
//queue_midi_event(0xb0, 4, 99); // test food switch
//queue_midi_event(0xd0, 4, 99); // test at
//queue_midi_event(0xe0, 0xff, 0xff); // test pitch bend
#endif
}
void loop()
@ -387,7 +367,12 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
if (checkMidiChannel(inChannel))
{
switch (inCtrl) {
case 0: // ignore BankSelect MSB
case 0:
if (inValue < MAX_BANKS)
{
bank = inValue;
handle_ui();
}
break;
case 1:
dexed->controllers.modwheel_cc = inValue;
@ -454,26 +439,32 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
mixer1.gain(3, 0.0); // original signal off
}
filter1.frequency(EXP_FUNC((float)map(effect_filter_frq, 0, ENC_FILTER_FRQ_STEPS, 0, 1024) / 150.0) * 10.0 + 80.0);
handle_ui();
break;
case 0x67: // CC 103: filter resonance
effect_filter_resonance = map(inValue, 0, 127, 0, ENC_FILTER_RES_STEPS);
filter1.resonance(EXP_FUNC(mapfloat(effect_filter_resonance, 0, ENC_FILTER_RES_STEPS, 0.7, 5.0)) * 0.044 + 0.61);
handle_ui();
break;
case 0x68: // CC 104: filter octave
effect_filter_octave = map(inValue, 0, 127, 0, ENC_FILTER_OCT_STEPS);
filter1.octaveControl(mapfloat(effect_filter_octave, 0, ENC_FILTER_OCT_STEPS, 0.0, 7.0));
handle_ui();
break;
case 0x69: // CC 105: delay time
effect_delay_time = map(inValue, 0, 127, 0, ENC_DELAY_TIME_STEPS);
delay1.delay(0, mapfloat(effect_delay_time, 0, ENC_DELAY_TIME_STEPS, 0.0, DELAY_MAX_TIME));
handle_ui();
break;
case 0x6A: // CC 106: delay feedback
effect_delay_feedback = map(inValue, 0, 127, 0, ENC_DELAY_FB_STEPS);
mixer1.gain(1, mapfloat(float(effect_delay_feedback), 0, ENC_DELAY_FB_STEPS, 0.0, 1.0));
handle_ui();
break;
case 0x6B: // CC 107: delay volume
effect_delay_volume = map(inValue, 0, 127, 0, ENC_DELAY_VOLUME_STEPS);
mixer2.gain(1, mapfloat(effect_delay_volume, 0, ENC_DELAY_VOLUME_STEPS, 0.0, 1.0)); // delay tap1 signal (with added feedback)
handle_ui();
break;
case 120:
dexed->panic();
@ -494,21 +485,24 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
}
}
void handleAfterTouch(byte inChannel, byte inPressure)
{
;
dexed->controllers.aftertouch_cc = inPressure;
dexed->controllers.refresh();
}
void handlePitchBend(byte inChannel, int inPitch)
{
;
dexed->controllers.values_[kControllerPitch] = inPitch;
}
void handleProgramChange(byte inChannel, byte inProgram)
{
;
if (inProgram < MAX_VOICES)
{
load_sysex(bank, inProgram);
handle_ui();
}
}
void handleSystemExclusive(byte *sysex, uint len)
@ -605,7 +599,7 @@ void handleClock(void)
midi_timing_timestep = 0;
// Adjust delay control here
#ifdef DEBUG
Serial.print(F("MIDI Timing: "));
Serial.print(F("MIDI Clock: "));
Serial.print(60000 / midi_timing_quarter, DEC);
Serial.print(F("bpm ("));
Serial.print(midi_timing_quarter, DEC);
@ -989,54 +983,3 @@ void show_patch(void)
Serial.println();
}
#endif
#ifdef TEST_NOTE
void note_on(void)
{
randomSeed(analogRead(A0));
queue_midi_event(0x90, TEST_NOTE, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 1
queue_midi_event(0x90, TEST_NOTE + 5, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 2
queue_midi_event(0x90, TEST_NOTE + 8, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 3
queue_midi_event(0x90, TEST_NOTE + 12, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 4
queue_midi_event(0x90, TEST_NOTE + 17, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 5
queue_midi_event(0x90, TEST_NOTE + 20, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 6
queue_midi_event(0x90, TEST_NOTE + 24, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 7
queue_midi_event(0x90, TEST_NOTE + 29, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 8
queue_midi_event(0x90, TEST_NOTE + 32, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 9
queue_midi_event(0x90, TEST_NOTE + 37, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 10
queue_midi_event(0x90, TEST_NOTE + 40, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 11
queue_midi_event(0x90, TEST_NOTE + 46, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 12
queue_midi_event(0x90, TEST_NOTE + 49, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 13
queue_midi_event(0x90, TEST_NOTE + 52, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 14
queue_midi_event(0x90, TEST_NOTE + 57, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 15
queue_midi_event(0x90, TEST_NOTE + 60, random(TEST_VEL_MIN, TEST_VEL_MAX)); // 16
}
void note_off(void)
{
queue_midi_event(0x80, TEST_NOTE, 0); // 1
queue_midi_event(0x80, TEST_NOTE + 5, 0); // 2
queue_midi_event(0x80, TEST_NOTE + 8, 0); // 3
queue_midi_event(0x80, TEST_NOTE + 12, 0); // 4
queue_midi_event(0x80, TEST_NOTE + 17, 0); // 5
queue_midi_event(0x80, TEST_NOTE + 20, 0); // 6
queue_midi_event(0x80, TEST_NOTE + 24, 0); // 7
queue_midi_event(0x80, TEST_NOTE + 29, 0); // 8
queue_midi_event(0x80, TEST_NOTE + 32, 0); // 9
queue_midi_event(0x80, TEST_NOTE + 37, 0); // 10
queue_midi_event(0x80, TEST_NOTE + 40, 0); // 11
queue_midi_event(0x80, TEST_NOTE + 46, 0); // 12
queue_midi_event(0x80, TEST_NOTE + 49, 0); // 13
queue_midi_event(0x80, TEST_NOTE + 52, 0); // 14
queue_midi_event(0x80, TEST_NOTE + 57, 0); // 15
queue_midi_event(0x80, TEST_NOTE + 60, 0); // 16
bool success = load_sysex(DEFAULT_SYSEXBANK, (++_voice_counter) - 1);
if (success == false)
#ifdef DEBUG
Serial.println(F("E: Cannot load SYSEX data"));
#endif
else
show_patch();
}
#endif

@ -293,95 +293,6 @@ void Dexed::setOPs(uint8_t ops)
controllers.opSwitch = ops;
}
/*
void Dexed::onParam(uint8_t param_num, float param_val)
{
int32_t tune;
if (param_val != data_float[param_num])
{
#ifdef DEBUG
uint8_t tmp = data[param_num];
#endif
_param_change_counter++;
if (param_num == 144 || param_num == 134 || param_num == 172)
panic();
refreshVoice = true;
data[param_num] = static_cast<uint8_t>(param_val);
data_float[param_num] = param_val;
switch (param_num)
{
case 155:
controllers.values_[kControllerPitchRange] = data[param_num];
break;
case 156:
controllers.values_[kControllerPitchStep] = data[param_num];
break;
case 157:
controllers.wheel.setRange(data[param_num]);
controllers.wheel.setTarget(data[param_num + 1]);
controllers.refresh();
break;
case 158:
controllers.wheel.setRange(data[param_num - 1]);
controllers.wheel.setTarget(data[param_num]);
controllers.refresh();
break;
case 159:
controllers.foot.setRange(data[param_num]);
controllers.foot.setTarget(data[param_num + 1]);
controllers.refresh();
break;
case 160:
controllers.foot.setRange(data[param_num - 1]);
controllers.foot.setTarget(data[param_num]);
controllers.refresh();
break;
case 161:
controllers.breath.setRange(data[param_num]);
controllers.breath.setTarget(data[param_num + 1]);
controllers.refresh();
break;
case 162:
controllers.breath.setRange(data[param_num - 1]);
controllers.breath.setTarget(data[param_num]);
controllers.refresh();
break;
case 163:
controllers.at.setRange(data[param_num]);
controllers.at.setTarget(data[param_num + 1]);
controllers.refresh();
break;
case 164:
controllers.at.setRange(data[param_num - 1]);
controllers.at.setTarget(data[param_num]);
controllers.refresh();
break;
case 165:
tune = param_val * 0x4000;
controllers.masterTune = (tune << 11) * (1.0 / 12);
break;
case 166:
case 167:
case 168:
case 169:
case 170:
case 171:
controllers.opSwitch = (data[166] << 5) | (data[167] << 4) | (data[168] << 3) | (data[169] << 2) | (data[170] << 1) | data[171];
break;
case 172:
max_notes = data[param_num];
break;
}
}
}
*/
uint8_t Dexed::getEngineType() {
return engineType;
}

@ -54,7 +54,7 @@ void handleAfterTouch(byte inChannel, byte inPressure);
void handlePitchBend(byte inChannel, int inPitch);
void handleProgramChange(byte inChannel, byte inProgram);
void handleSystemExclusive(byte *data, uint len);
void handleSystemExclusiveChunk(const byte *data, uint len, bool last);
//void handleSystemExclusiveChunk(const byte *data, uint len, bool last);
void handleTimeCodeQuarterFrame(byte data);
void handleAfterTouchPoly(byte inChannel, byte inNumber, byte inVelocity);
void handleSongSelect(byte inSong);
@ -65,7 +65,7 @@ void handleContinue(void);
void handleStop(void);
void handleActiveSensing(void);
void handleSystemReset(void);
void handleRealTimeSystem(void);
//void handleRealTimeSystem(void);
/*****************************************
MIDI_DEVICE_DIN
@ -246,7 +246,7 @@ void handleSystemExclusive_MIDI_DEVICE_DIN(byte *data, uint len)
#endif
}
void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last)
/* void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last)
{
handleSystemExclusiveChunk(data, len, last);
#ifdef DEBUG
@ -269,7 +269,7 @@ void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last)
Serial.println();
#endif
#endif
}
} */
void handleTimeCodeQuarterFrame_MIDI_DEVICE_DIN(byte data)
{
@ -521,7 +521,7 @@ void handleSystemReset_MIDI_DEVICE_DIN(void)
#endif
}
void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime)
/* void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime)
{
handleRealTimeSystem();
#ifdef DEBUG
@ -544,7 +544,7 @@ void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime)
Serial.println();
#endif
#endif
}
} */
#endif // MIDI_DEVICE_DIN
/*****************************************
@ -726,7 +726,7 @@ void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte *data, uint len)
#endif
}
void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool last)
/* void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool last)
{
handleSystemExclusiveChunk(data, len, last);
#ifdef DEBUG
@ -749,7 +749,7 @@ void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool
Serial.println();
#endif
#endif
}
} */
void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST(midi::DataByte data)
{
@ -1000,7 +1000,8 @@ void handleSystemReset_MIDI_DEVICE_USB_HOST(void)
#endif
#endif
}
void handlRealTimeSysteme_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime)
/* void handlRealTimeSysteme_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime)
{
handleRealTimeSystem();
#ifdef DEBUG
@ -1023,7 +1024,7 @@ void handlRealTimeSysteme_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime)
Serial.println();
#endif
#endif
}
} */
#endif // MIDI_DEVICE_USB_HOST
/*****************************************
@ -1205,7 +1206,7 @@ void handleSystemExclusive_MIDI_DEVICE_USB(byte *data, uint len)
#endif
}
void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last)
/* void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last)
{
handleSystemExclusiveChunk(data, len, last);
#ifdef DEBUG
@ -1228,7 +1229,7 @@ void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last)
Serial.println();
#endif
#endif
}
} */
void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB(midi::DataByte data)
{
@ -1479,7 +1480,8 @@ void handleSystemReset_MIDI_DEVICE_USB(void)
#endif
#endif
}
void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime)
/* void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime)
{
handleRealTimeSystem();
#ifdef DEBUG
@ -1502,7 +1504,7 @@ void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime)
Serial.println();
#endif
#endif
}
} */
#endif // MIDI_DEVICE_USB
/*****************************************
@ -1542,7 +1544,7 @@ void setup_midi_devices(void)
midi_usb.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_USB_HOST);
midi_usb.setHandleControlChange(handleControlChange_MIDI_DEVICE_USB_HOST);
midi_usb.setHandleAfterTouchChannel(handleAfterTouch_MIDI_DEVICE_USB_HOST);
//midi_usb.setHandlePitchBend(handlePitchBend_MIDI_DEVICE_USB_HOST);
midi_usb.setHandlePitchChange(handlePitchBend_MIDI_DEVICE_USB_HOST);
midi_usb.setHandleProgramChange(handleProgramChange_MIDI_DEVICE_USB_HOST);
midi_usb.setHandleSystemExclusive(handleSystemExclusive_MIDI_DEVICE_USB_HOST);
//midi_usb.setHandleSystemExclusiveChunk(handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST);

Loading…
Cancel
Save