[Device] very rough instatiation with device name

This commit is contained in:
thibaud keller 2024-12-13 00:10:19 +00:00
parent 51046a8ca1
commit 6db3099e7e
10 changed files with 44 additions and 70 deletions

@ -1 +1 @@
Subproject commit 805aa0773c9330ac7c8db669845ae7485cb2ce8d
Subproject commit fd4f72a6b590a0a07eb1b1dc7842deddcf72d440

View file

@ -8,10 +8,11 @@
namespace Hardware
{
Controller::Controller(const score::DocumentContext& document,
Scenario::IntervalModel& i)
: bugui::controller<Controller>{"Launchpad_Pro_Standalone"}
Scenario::IntervalModel& interval,
std::string_view device_name)
: bugui::controller<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<Scenario::ProcessModel*>(&*i.processes.begin());
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval.processes.begin());
scnr->intervals.added.connect<&Controller::on_interval_changed>(this);
scnr->intervals.removed.connect<&Controller::on_interval_changed>(this);

View file

@ -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;

View file

@ -27,21 +27,13 @@ DocumentPlugin::DocumentPlugin(const score::DocumentContext& doc, QObject* paren
, ctrlr{nullptr}
{
auto& set = m_context.app.settings<Settings::Model>();
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<Scenario::ScenarioDocumentModel*>(&doc);
auto cstr = &scenar->baseScenario().interval();
ctrlr = new Controller{m_context, *cstr};
ctrlr = new Controller{m_context, *cstr, device_name.toStdString()};
}
void DocumentPlugin::cleanup()

View file

@ -24,7 +24,7 @@ public:
Controller* ctrlr;
private:
void create();
void create(const QString& device_name);
void cleanup();
};
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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<SetModelEnabled>(this->model(this), val);
m_disp.submit<SetModelDevice>(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());
}
}

View file

@ -2,57 +2,39 @@
#include <score/widgets/FormWidget.hpp>
#include <QCheckBox>
#include <QFormLayout>
#include <QComboBox>
#include <wobjectimpl.h>
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()

View file

@ -2,7 +2,6 @@
#include <score/plugins/settingsdelegate/SettingsDelegateView.hpp>
#include <Hardware/Settings/Model.hpp>
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{};
};
}