diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-04-22 18:18:53 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-04-22 18:45:49 +0200 |
commit | 28096a402947b05c7e923e075f926263a3279a42 (patch) | |
tree | 0dd68b8ab1f84e6fb5ec246ad0d456eb30ff5fd3 | |
parent | fcfaa7affa0ac8afeaf38346226beb30fca09733 (diff) |
Fix crash when doing async-load in cli.
-rw-r--r-- | drumgizmo/drumgizmoc.cc | 29 | ||||
-rw-r--r-- | plugin/drumgizmo_plugin.cc | 1 | ||||
-rw-r--r-- | plugingui/drumkitframecontent.cc | 2 | ||||
-rw-r--r-- | plugingui/statusframecontent.cc | 2 | ||||
-rw-r--r-- | src/drumkitloader.cc | 5 | ||||
-rw-r--r-- | src/settings.h | 1 |
6 files changed, 39 insertions, 1 deletions
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc index c6b43f0..cec96f7 100644 --- a/drumgizmo/drumgizmoc.cc +++ b/drumgizmo/drumgizmoc.cc @@ -326,6 +326,7 @@ int main(int argc, char* argv[]) } oe = factory.createOutput(engine); if(ie == NULL) + if(oe == NULL) { std::cerr << "Invalid output engine: " << engine << std::endl; return 1; @@ -700,6 +701,34 @@ int main(int argc, char* argv[]) } std::cout << "\ndone" << std::endl; } + else + { + // Async loading in progress + + // Wait until the loader has passed the kit parsing step before proceeding. + bool parsing_done{false}; + while(!parsing_done) + { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + switch(settings.drumkit_load_status.load()) + { + case LoadStatus::Idle: + case LoadStatus::Parsing: + // Not yet past the parsing step + break; + case LoadStatus::Loading: + case LoadStatus::Done: + // Past parsing step + parsing_done = true; + break; + case LoadStatus::Error: + // Kit parser error? + std::cout << "\nFailed to load " << kitfile << std::endl; + return 1; + } + } + } gizmo.setSamplerate(oe->getSamplerate()); oe->onLatencyChange(gizmo.getLatency()); diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 671fab6..82c0ee9 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -281,6 +281,7 @@ void DrumGizmoPlugin::onInlineRedraw(std::size_t width, bar_green.setSize(val, bar_height); painter.drawImage(brd, height - bar_height, bar_green); break; + case LoadStatus::Parsing: case LoadStatus::Loading: case LoadStatus::Idle: bar_blue.setSize(val, bar_height); diff --git a/plugingui/drumkitframecontent.cc b/plugingui/drumkitframecontent.cc index 9549d75..2ae298b 100644 --- a/plugingui/drumkitframecontent.cc +++ b/plugingui/drumkitframecontent.cc @@ -233,6 +233,7 @@ void DrumkitframeContent::setDrumKitLoadStatus(LoadStatus load_status) switch(load_status) { case LoadStatus::Idle: + case LoadStatus::Parsing: case LoadStatus::Loading: state = dggui::ProgressBarState::Blue; break; @@ -255,6 +256,7 @@ void DrumkitframeContent::setMidiMapLoadStatus(LoadStatus load_status) case LoadStatus::Idle: midimap_file_progress.setValue(0); break; + case LoadStatus::Parsing: case LoadStatus::Loading: midimap_file_progress.setValue(1); state = dggui::ProgressBarState::Blue; diff --git a/plugingui/statusframecontent.cc b/plugingui/statusframecontent.cc index 0fe8bf2..7990d3e 100644 --- a/plugingui/statusframecontent.cc +++ b/plugingui/statusframecontent.cc @@ -88,6 +88,7 @@ void StatusframeContent::updateDrumkitLoadStatus(LoadStatus load_status) case LoadStatus::Idle: drumkit_load_status = _("No Kit Loaded"); break; + case LoadStatus::Parsing: case LoadStatus::Loading: drumkit_load_status = _("Loading..."); break; @@ -130,6 +131,7 @@ void StatusframeContent::updateMidimapLoadStatus(LoadStatus load_status) case LoadStatus::Idle: midimap_load_status = _("No Midimap Loaded"); break; + case LoadStatus::Parsing: case LoadStatus::Loading: midimap_load_status = _("Loading..."); break; diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index 6a4c9f4..9167201 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -138,7 +138,7 @@ bool DrumKitLoader::loadkit(const std::string& file) settings.drumkit_samplerate.store(44100); settings.load_status_text.store(""); - settings.drumkit_load_status.store(LoadStatus::Loading); + settings.drumkit_load_status.store(LoadStatus::Parsing); // Parse drumkit and instrument xml @@ -226,6 +226,9 @@ bool DrumKitLoader::loadkit(const std::string& file) settings.midimap_file = drumkit_path + "/" + drumkitdom.metadata.default_midimap_file; } + // Done parsing. Now start loading the audio + settings.midimap_load_status.store(LoadStatus::Loading); + loadKitAudio(kit); DEBUG(loadkit, "loadkit: Success\n"); diff --git a/src/settings.h b/src/settings.h index 7507827..fb93d79 100644 --- a/src/settings.h +++ b/src/settings.h @@ -38,6 +38,7 @@ enum class LoadStatus : unsigned int { Idle, + Parsing, Loading, Done, Error |