diff --git a/Hardware/3rdparty/bugui b/Hardware/3rdparty/bugui index 805aa07..fd4f72a 160000 --- a/Hardware/3rdparty/bugui +++ b/Hardware/3rdparty/bugui @@ -1 +1 @@ -Subproject commit 805aa0773c9330ac7c8db669845ae7485cb2ce8d +Subproject commit fd4f72a6b590a0a07eb1b1dc7842deddcf72d440 diff --git a/Hardware/Controller.cpp b/Hardware/Controller.cpp index 798a02c..91de040 100644 --- a/Hardware/Controller.cpp +++ b/Hardware/Controller.cpp @@ -8,10 +8,11 @@ namespace Hardware { Controller::Controller(const score::DocumentContext& document, - Scenario::IntervalModel& i) - : bugui::controller{"Launchpad_Pro_Standalone"} + Scenario::IntervalModel& interval, + std::string_view device_name) + : bugui::controller{device_name} , doc{document} - , interval{&i} + , interval{&interval} , h_ofset{0.} // initial horizontal ofset , v_ofset{0.} // initial verticalal ofset , h_zoom{.125} // initial horizontal zoom @@ -20,7 +21,7 @@ Controller::Controller(const score::DocumentContext& document, // Connet interval signals // adapted from // src/plugins/score-plugin-scenario/Scenario/Process/MiniScenarioView.cpp#18 - auto scnr = qobject_cast(&*i.processes.begin()); + auto scnr = qobject_cast(&*interval.processes.begin()); scnr->intervals.added.connect<&Controller::on_interval_changed>(this); scnr->intervals.removed.connect<&Controller::on_interval_changed>(this); diff --git a/Hardware/Controller.hpp b/Hardware/Controller.hpp index 1c3ca0c..f174a1e 100644 --- a/Hardware/Controller.hpp +++ b/Hardware/Controller.hpp @@ -18,7 +18,8 @@ class SCORE_ADDON_HARDWARE_EXPORT Controller final public: explicit Controller(const score::DocumentContext& document, - Scenario::IntervalModel& s); + Scenario::IntervalModel& interval, + std::string_view device_name); void paint(bugui::painter& painter) const override; diff --git a/Hardware/DocumentPlugin.cpp b/Hardware/DocumentPlugin.cpp index a9242b2..5d30cb2 100644 --- a/Hardware/DocumentPlugin.cpp +++ b/Hardware/DocumentPlugin.cpp @@ -27,21 +27,13 @@ DocumentPlugin::DocumentPlugin(const score::DocumentContext& doc, QObject* paren , ctrlr{nullptr} { auto& set = m_context.app.settings(); - if(set.getEnabled()) - { - create(); - } + QString d = set.getDevice(); + if (d != "None") create(d); con(set, - &Settings::Model::EnabledChanged, + &Settings::Model::DeviceChanged, this, - [this] (bool b) - { - if (b) - create(); - else - cleanup(); - }, + &DocumentPlugin::create, Qt::QueuedConnection); } @@ -52,15 +44,17 @@ void DocumentPlugin::on_documentClosing() cleanup(); } -void DocumentPlugin::create() +void DocumentPlugin::create(const QString& device_name) { if (ctrlr) cleanup(); + if (device_name == "None") return; + auto& doc = m_context.document.model().modelDelegate(); auto scenar = safe_cast(&doc); auto cstr = &scenar->baseScenario().interval(); - ctrlr = new Controller{m_context, *cstr}; + ctrlr = new Controller{m_context, *cstr, device_name.toStdString()}; } void DocumentPlugin::cleanup() diff --git a/Hardware/DocumentPlugin.hpp b/Hardware/DocumentPlugin.hpp index 0610a61..88e12c0 100644 --- a/Hardware/DocumentPlugin.hpp +++ b/Hardware/DocumentPlugin.hpp @@ -24,7 +24,7 @@ public: Controller* ctrlr; private: - void create(); + void create(const QString& device_name); void cleanup(); }; } diff --git a/Hardware/Settings/Model.cpp b/Hardware/Settings/Model.cpp index f2f62f2..c31dc97 100644 --- a/Hardware/Settings/Model.cpp +++ b/Hardware/Settings/Model.cpp @@ -11,10 +11,10 @@ namespace Settings { namespace Parameters { -SETTINGS_PARAMETER_IMPL(Enabled){QStringLiteral("Hardware/Enabled"), false}; +SETTINGS_PARAMETER_IMPL(Device){QStringLiteral("Hardware/Device"), "None"}; static auto list() { - return std::tie(Enabled); + return std::tie(Device); } } @@ -23,6 +23,6 @@ Model::Model(QSettings& set, const score::ApplicationContext& ctx) score::setupDefaultSettings(set, Parameters::list(), *this); } -SCORE_SETTINGS_PARAMETER_CPP(bool, Model, Enabled) +SCORE_SETTINGS_PARAMETER_CPP(QString, Model, Device) } } diff --git a/Hardware/Settings/Model.hpp b/Hardware/Settings/Model.hpp index 87af966..5962a61 100644 --- a/Hardware/Settings/Model.hpp +++ b/Hardware/Settings/Model.hpp @@ -10,14 +10,14 @@ namespace Settings class SCORE_ADDON_HARDWARE_EXPORT Model : public score::SettingsDelegateModel { W_OBJECT(Model) - bool m_Enabled = false; + QString m_Device = "None"; public: Model(QSettings& set, const score::ApplicationContext& ctx); - SCORE_SETTINGS_PARAMETER_HPP(SCORE_ADDON_HARDWARE_EXPORT, bool, Enabled) + SCORE_SETTINGS_PARAMETER_HPP(SCORE_ADDON_HARDWARE_EXPORT, QString, Device) }; -SCORE_SETTINGS_PARAMETER(Model, Enabled) +SCORE_SETTINGS_PARAMETER(Model, Device) } } diff --git a/Hardware/Settings/Presenter.cpp b/Hardware/Settings/Presenter.cpp index ab3cad7..96b31e5 100644 --- a/Hardware/Settings/Presenter.cpp +++ b/Hardware/Settings/Presenter.cpp @@ -20,18 +20,18 @@ Presenter::Presenter(Model& m, View& v, QObject* parent) { { // view -> model - con(v, &View::enabledChanged, this, [&](auto val) { - if (val != m.getEnabled()) + con(v, &View::deviceChanged, this, [&](auto val) { + if (val != m.getDevice()) { - m_disp.submit(this->model(this), val); + m_disp.submit(this->model(this), val); } }); // model -> view - con(m, &Model::EnabledChanged, &v, &View::setEnabled); + con(m, &Model::DeviceChanged, &v, &View::setDevice); // initial value - v.setEnabled(m.getEnabled()); + v.setDevice(m.getDevice()); } } diff --git a/Hardware/Settings/View.cpp b/Hardware/Settings/View.cpp index 7b9c0b9..8be8483 100644 --- a/Hardware/Settings/View.cpp +++ b/Hardware/Settings/View.cpp @@ -2,57 +2,39 @@ #include -#include #include +#include #include W_OBJECT_IMPL(Hardware::Settings::View) + namespace Hardware { namespace Settings { - View::View() { m_widg = new score::FormWidget{tr("Hardware")}; auto lay = m_widg->layout(); { - m_enabled = new QCheckBox{tr("Enabled")}; + m_device = new QComboBox{m_widg}; + m_device->addItem("None"); + m_device->addItem("Launchpad_Pro_Standalone"); + m_device->addItem("Launchpad_Pro_Live"); - connect(m_enabled, &QCheckBox::stateChanged, this, [&](int t) { - switch(t) - { - case Qt::Unchecked: - enabledChanged(false); - break; - case Qt::Checked: - enabledChanged(true); - break; - default: - break; - } - }); + connect(m_device, + &QComboBox::currentTextChanged, + this, &View::deviceChanged + ); - lay->addRow(m_enabled); + lay->addRow(m_device); } } -void View::setEnabled(bool val) +void View::setDevice(const QString& device) { - switch(m_enabled->checkState()) - { - case Qt::Unchecked: - if(val) - m_enabled->setChecked(true); - break; - case Qt::Checked: - if(!val) - m_enabled->setChecked(false); - break; - default: - break; - } +// TODO : implement me } QWidget* View::getWidget() diff --git a/Hardware/Settings/View.hpp b/Hardware/Settings/View.hpp index 8cf9981..48283b2 100644 --- a/Hardware/Settings/View.hpp +++ b/Hardware/Settings/View.hpp @@ -2,7 +2,6 @@ #include #include -class QCheckBox; namespace score { @@ -12,21 +11,18 @@ namespace Hardware { namespace Settings { - class View : public score::GlobalSettingsView { W_OBJECT(View) public: View(); - void setEnabled(bool); - - void enabledChanged(bool b) W_SIGNAL(enabledChanged, b); + void setDevice(const QString& device); + void deviceChanged(const QString& device) W_SIGNAL(deviceChanged, device); private: QWidget* getWidget() override; score::FormWidget* m_widg{}; - - QCheckBox* m_enabled{}; + QComboBox* m_device{}; }; }