diff --git a/Source/OnixSourceEditor.cpp b/Source/OnixSourceEditor.cpp index 5aed8d2..bb52270 100644 --- a/Source/OnixSourceEditor.cpp +++ b/Source/OnixSourceEditor.cpp @@ -416,6 +416,12 @@ void OnixSourceEditor::comboBoxChanged(ComboBox* cb) void OnixSourceEditor::updateComboBox(ComboBox* cb) { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return; + } + bool isPortA = cb == headstageComboBoxA.get(); PortName currentPort = isPortA ? PortName::PortA : PortName::PortB; @@ -432,6 +438,7 @@ void OnixSourceEditor::updateComboBox(ComboBox* cb) std::string headstage = isPortA ? headstageComboBoxA->getText().toStdString() : headstageComboBoxB->getText().toStdString(); source->updateDiscoveryParameters(currentPort, PortController::getHeadstageDiscoveryParameters(headstage)); + canvas->addHub(headstage, PortController::getPortOffset(currentPort)); if (headstage == NEUROPIXELSV2E_HEADSTAGE_NAME || headstage == NEUROPIXELSV1E_HEADSTAGE_NAME) @@ -631,6 +638,12 @@ void OnixSourceEditor::setComboBoxSelection(ComboBox* comboBox, std::string head void OnixSourceEditor::refreshComboBoxSelection() { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return; + } + Array hubTabs = canvas->getHubTabs(); bool resetPortA = true, resetPortB = true; @@ -657,6 +670,12 @@ void OnixSourceEditor::refreshComboBoxSelection() OnixDeviceMap OnixSourceEditor::createTabMapFromCanvas() { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return OnixDeviceMap{}; + } + return canvas->getSelectedDevices(canvas->settingsInterfaces); } @@ -675,6 +694,8 @@ void OnixSourceEditor::saveVisualizerEditorParameters(XmlElement* xml) void OnixSourceEditor::loadVisualizerEditorParameters(XmlElement* xml) { + checkForCanvas(); + LOGD("Loading OnixSourceEditor settings."); if (xml->hasAttribute("headstagePortA")) diff --git a/Source/OnixSourceEditor.h b/Source/OnixSourceEditor.h index 1cdc134..c7a717b 100644 --- a/Source/OnixSourceEditor.h +++ b/Source/OnixSourceEditor.h @@ -137,6 +137,8 @@ namespace OnixSourcePlugin static constexpr int DefaultBlockReadSize = 4096; + static constexpr char* missingCanvasErrorMessage = "The canvas for this plugin could not be found. Some functionality may not work as expected, and you may not be able to acquire or record data. Try removing and replacing the plugin."; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OnixSourceEditor); }; }