Skip to content

Commit

Permalink
Improve startup robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Dempsey committed Oct 27, 2023
1 parent 59761c2 commit a57e81c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/HC-1/HC-1-draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void Hc1ModuleWidget::drawLayer(const DrawArgs& args, int layer)
text = "processing favorites ...";
} else
if (InitState::Uninitialized == my_module->config_state) {
text = "preparing current preset ...";
text = "preparing configuration ...";
} else
if (InitState::Pending == my_module->config_state) {
text = "processing preset details ...";
Expand Down
46 changes: 27 additions & 19 deletions src/HC-1/HC-1-midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ void Hc1Module::transmitDeviceHello()

void Hc1Module::transmitRequestConfiguration()
{
clearCCValues();
current_preset = nullptr;
config_state = InitState::Pending;
#ifdef VERBOSE_LOG
log_midi = true;
#endif
beginPreset(); // force preset
config_state = InitState::Pending;
set_init_midi_rate();
sendEditorPresent(false);
sendControlChange(EM_SettingsChannel, EMCC_Download, EM_DownloadItem::gridToFlash);
Expand Down Expand Up @@ -148,21 +146,20 @@ void Hc1Module::transmitRequestUserPresets()

void Hc1Module::setPreset(std::shared_ptr<Preset> preset)
{
current_preset = nullptr;
beginPreset(); // force preset
notifyPresetChanged();
notifyPedalsChanged();

current_preset = preset;
if (!preset) return;

set_init_midi_rate();
sendEditorPresent(false);
sendControlChange(15, EMCC_Download, EM_DownloadItem::gridToFlash);

config_state = InitState::Pending;
sendControlChange(15, MidiCC_BankSelect, preset->bank_hi);
sendControlChange(15, EMCC_Category, preset->bank_lo);
sendProgramChange(15, preset->number);
sendEditorPresent(false);
sendControlChange(EM_SettingsChannel, EMCC_Download, EM_DownloadItem::gridToFlash);
sendControlChange(EM_SettingsChannel, MidiCC_BankSelect, preset->bank_hi);
sendControlChange(EM_SettingsChannel, EMCC_Category, preset->bank_lo);
sendProgramChange(EM_SettingsChannel, preset->number);
}

void Hc1Module::sendSavedPreset()
Expand All @@ -172,13 +169,12 @@ void Hc1Module::sendSavedPreset()
return;
}
set_init_midi_rate();
saved_preset_state = InitState::Pending;
sendEditorPresent(false);
sendControlChange(EM_SettingsChannel, EMCC_Download, EM_DownloadItem::gridToFlash);

saved_preset_state = InitState::Pending;
sendControlChange(15, MidiCC_BankSelect, saved_preset->bank_hi);
sendControlChange(15, EMCC_Category, saved_preset->bank_lo);
sendProgramChange(15, saved_preset->number);
sendControlChange(EM_SettingsChannel, MidiCC_BankSelect, saved_preset->bank_hi);
sendControlChange(EM_SettingsChannel, EMCC_Category, saved_preset->bank_lo);
sendProgramChange(EM_SettingsChannel, saved_preset->number);
}

void Hc1Module::silence(bool reset)
Expand Down Expand Up @@ -228,11 +224,23 @@ void Hc1Module::setRecirculatorCCValue(int id, uint8_t value)
}
}

void Hc1Module::clearPreset()
{
current_preset = nullptr;
preset0.clear();
clearCCValues();

rounding.clear();
pedal1.clear();
pedal2.clear();
recirculator = 0;
middle_c = 60;
}

void Hc1Module::beginPreset()
{
in_preset = true;
preset0.clear();
//clearCCValues();
clearPreset();
dsp[2] = dsp[1] = dsp[0] = 0;
}

Expand Down Expand Up @@ -496,6 +504,7 @@ void Hc1Module::onChannel16Message(const midi::Message& msg)
device_hello_state = InitState::Complete;
notifyDeviceChanged();
notifyPresetChanged();
notifyPedalsChanged();
} else
if (configPending()) {
#ifdef VERBOSE_LOG
Expand Down Expand Up @@ -582,7 +591,7 @@ void Hc1Module::onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity)
void Hc1Module::onSoundOff()
{
if (!in_preset) {
clearCCValues();
current_preset = nullptr;
beginPreset();
if (saved_preset_state != InitState::Pending) {
config_state = InitState::Pending;
Expand Down Expand Up @@ -778,7 +787,6 @@ void MidiInputWorker::post_message(uMidiMessage msg)
std::unique_lock<std::mutex> lock(m);
midi_consume.push(msg);
cv.notify_one();
//system::sleep(.000001);
}

void MidiInputWorker::run() {
Expand Down
1 change: 1 addition & 0 deletions src/HC-1/HC-1-process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ void Hc1Module::process(const ProcessArgs& args)

if (InitState::Uninitialized == request_updates_state) {
transmitRequestUpdates();
heart_time = 1.f;
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/HC-1/HC-1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ struct Hc1Module : IPresetHolder, ISendMidi, ISetDevice, IMidiDeviceChange, midi
void sendEditorPresent(bool init_handshake);
void silence(bool reset);
void beginPreset();
void clearPreset();
void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity);
void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity);
void setMacroCCValue(int id, uint8_t value);
Expand Down

0 comments on commit a57e81c

Please sign in to comment.