diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bf8d15..ffc8d7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.13 FATAL_ERROR) +project(score_addon_hardware LANGUAGES CXX) if(NOT TARGET score_lib_base) include(ScoreExternalAddon) @@ -9,26 +9,34 @@ if(NOT TARGET libremidi) return() endif() -project(score_addon_hardware LANGUAGES CXX) score_common_setup() set(HDRS - "Hardware/ApplicationPlugin.hpp" + # "Hardware/Hardware.hpp" + # "Hardware/Controller.hpp" + # "Hardware/MidiController.hpp" - "Hardware/Hardware.hpp" - "Hardware/Controller.hpp" - "Hardware/MidiController.hpp" + "Hardware/Settings/Model.hpp" + "Hardware/Settings/Presenter.hpp" + "Hardware/Settings/View.hpp" + "Hardware/Settings/Factory.hpp" + + "Hardware/ApplicationPlugin.hpp" "score_addon_hardware.hpp" ) set(SRCS - "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Hardware.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/MidiController.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Hardware.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/MidiController.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Settings/Model.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Settings/Presenter.cpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Settings/View.cpp" + + "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp" ) @@ -39,3 +47,5 @@ target_link_libraries(${PROJECT_NAME} PUBLIC score_plugin_scenario libremidi ) + +setup_score_plugin(${PROJECT_NAME}) diff --git a/Hardware/ApplicationPlugin.cpp b/Hardware/ApplicationPlugin.cpp index 7cad36c..334d28f 100644 --- a/Hardware/ApplicationPlugin.cpp +++ b/Hardware/ApplicationPlugin.cpp @@ -1,8 +1,10 @@ -#include "ApplicationPlugin.hpp" +#include + +#include namespace Hardware { -ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationPlugin& app) +ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationContext& app) : GUIApplicationPlugin{app} { } } diff --git a/Hardware/ApplicationPlugin.hpp b/Hardware/ApplicationPlugin.hpp index 7840195..abd465a 100644 --- a/Hardware/ApplicationPlugin.hpp +++ b/Hardware/ApplicationPlugin.hpp @@ -7,5 +7,6 @@ namespace Hardware class ApplicationPlugin final : public score::GUIApplicationPlugin { public: - ApplicationPlugin(const score::GUIApplicationPlugin& app); + ApplicationPlugin(const score::GUIApplicationContext& app); }; +} diff --git a/Hardware/Controller.hpp b/Hardware/Controller.hpp index c014165..be5b0cc 100644 --- a/Hardware/Controller.hpp +++ b/Hardware/Controller.hpp @@ -1,7 +1,7 @@ #ifndef CONTROLLER_HPP #define CONTROLLER_HPP -namespace RemoteControl +namespace Hardware { struct Controller diff --git a/Hardware/Hardware.cpp b/Hardware/Hardware.cpp index be85c99..30b7de8 100644 --- a/Hardware/Hardware.cpp +++ b/Hardware/Hardware.cpp @@ -7,7 +7,7 @@ #include "Hardware.hpp" -namespace RemoteControl +namespace Hardware { Hardware::Hardware(const score::DocumentContext& doc) : m_dev{doc.plugin()} @@ -142,4 +142,4 @@ void Hardware::draw_intervals() } } -W_OBJECT_IMPL(RemoteControl::Hardware) +W_OBJECT_IMPL(Hardware::Hardware) diff --git a/Hardware/Hardware.hpp b/Hardware/Hardware.hpp index 28d165f..dbdec84 100644 --- a/Hardware/Hardware.hpp +++ b/Hardware/Hardware.hpp @@ -1,16 +1,15 @@ -#ifndef HARDWARE_HPP -#define HARDWARE_HPP +#pragma once -#include +// #include #include #include #include "MidiController.hpp" -namespace RemoteControl +namespace Hardware { -class SCORE_PLUGIN_REMOTECONTROL_EXPORT Hardware +class /*SCORE_PLUGIN_HARDWARE_EXPORT*/ Hardware : public QObject { W_OBJECT(Hardware) @@ -38,4 +37,3 @@ private: }; } -#endif // HARDWARE_HPP diff --git a/Hardware/MidiController.cpp b/Hardware/MidiController.cpp index b7457da..921818c 100644 --- a/Hardware/MidiController.cpp +++ b/Hardware/MidiController.cpp @@ -2,8 +2,8 @@ #include "MidiController.hpp" -namespace RemoteControl { - +namespace Hardware +{ MidiController::MidiController() : grid{GRID} , previous_grid{BLACK} diff --git a/Hardware/MidiController.hpp b/Hardware/MidiController.hpp index 77bf2ff..b9b4e1f 100644 --- a/Hardware/MidiController.hpp +++ b/Hardware/MidiController.hpp @@ -44,9 +44,8 @@ namespace Explorer class DeviceDocumentPlugin; } -namespace RemoteControl +namespace Hardware { - class MidiController : public Controller { public: diff --git a/Hardware/Settings/Factory.hpp b/Hardware/Settings/Factory.hpp new file mode 100644 index 0000000..995ad81 --- /dev/null +++ b/Hardware/Settings/Factory.hpp @@ -0,0 +1,15 @@ +#pragma once +#include + +#include +#include +#include + +namespace Hardware +{ +namespace Settings +{ +SCORE_DECLARE_SETTINGS_FACTORY( + Factory, Model, Presenter, View, "995020ed-304a-42b5-8e3b-eb050a7305ed") +} +} diff --git a/Hardware/Settings/Model.cpp b/Hardware/Settings/Model.cpp new file mode 100644 index 0000000..f2f62f2 --- /dev/null +++ b/Hardware/Settings/Model.cpp @@ -0,0 +1,28 @@ +#include "Model.hpp" + +#include + +#include +W_OBJECT_IMPL(Hardware::Settings::Model) + +namespace Hardware +{ +namespace Settings +{ +namespace Parameters +{ +SETTINGS_PARAMETER_IMPL(Enabled){QStringLiteral("Hardware/Enabled"), false}; +static auto list() +{ + return std::tie(Enabled); +} +} + +Model::Model(QSettings& set, const score::ApplicationContext& ctx) +{ + score::setupDefaultSettings(set, Parameters::list(), *this); +} + +SCORE_SETTINGS_PARAMETER_CPP(bool, Model, Enabled) +} +} diff --git a/Hardware/Settings/Model.hpp b/Hardware/Settings/Model.hpp new file mode 100644 index 0000000..269468b --- /dev/null +++ b/Hardware/Settings/Model.hpp @@ -0,0 +1,25 @@ +#pragma once +#include + +#include + +#include + +namespace Hardware +{ +namespace Settings +{ +class SCORE_ADDON_HARDWARE_EXPORT Model : public score::SettingsDelegateModel +{ + W_OBJECT(Model) + bool m_Enabled = false; + +public: + Model(QSettings& set, const score::ApplicationContext& ctx); + + SCORE_SETTINGS_PARAMETER_HPP(SCORE_ADDON_HARDWARE_EXPORT, bool, Enabled) +}; + +SCORE_SETTINGS_PARAMETER(Model, Enabled) +} +} diff --git a/Hardware/Settings/Presenter.cpp b/Hardware/Settings/Presenter.cpp new file mode 100644 index 0000000..ab3cad7 --- /dev/null +++ b/Hardware/Settings/Presenter.cpp @@ -0,0 +1,52 @@ +#include "Presenter.hpp" + +#include "Model.hpp" +#include "View.hpp" + +#include +#include +#include +#include + +#include +#include + +namespace Hardware +{ +namespace Settings +{ +Presenter::Presenter(Model& m, View& v, QObject* parent) + : score::GlobalSettingsPresenter{m, v, parent} +{ + { + // view -> model + con(v, &View::enabledChanged, this, [&](auto val) { + if (val != m.getEnabled()) + { + m_disp.submit(this->model(this), val); + } + }); + + // model -> view + con(m, &Model::EnabledChanged, &v, &View::setEnabled); + + // initial value + v.setEnabled(m.getEnabled()); + } +} + +QString Presenter::settingsName() +{ + return tr("Hardware"); +} + +QIcon Presenter::settingsIcon() +{ + return makeIcons( + QStringLiteral(":/icons/settings_remote_control_on.png"), + QStringLiteral(":/icons/settings_remote_control_off.png"), + QStringLiteral(":/icons/settings_remote_control_off.png")); +} + +} +} diff --git a/Hardware/Settings/Presenter.hpp b/Hardware/Settings/Presenter.hpp new file mode 100644 index 0000000..6c3a8cc --- /dev/null +++ b/Hardware/Settings/Presenter.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace Hardware +{ +namespace Settings +{ +class Model; +class View; +class Presenter : public score::GlobalSettingsPresenter +{ +public: + using model_type = Model; + using view_type = View; + Presenter(Model&, View&, QObject* parent); + +private: + QString settingsName() override; + QIcon settingsIcon() override; +}; +} +} + diff --git a/Hardware/Settings/View.cpp b/Hardware/Settings/View.cpp new file mode 100644 index 0000000..7b9c0b9 --- /dev/null +++ b/Hardware/Settings/View.cpp @@ -0,0 +1,64 @@ +#include "View.hpp" + +#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")}; + + connect(m_enabled, &QCheckBox::stateChanged, this, [&](int t) { + switch(t) + { + case Qt::Unchecked: + enabledChanged(false); + break; + case Qt::Checked: + enabledChanged(true); + break; + default: + break; + } + }); + + lay->addRow(m_enabled); + } +} + +void View::setEnabled(bool val) +{ + 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; + } +} + +QWidget* View::getWidget() +{ + return m_widg; +} + +} +} diff --git a/Hardware/Settings/View.hpp b/Hardware/Settings/View.hpp new file mode 100644 index 0000000..8cf9981 --- /dev/null +++ b/Hardware/Settings/View.hpp @@ -0,0 +1,33 @@ +#pragma once +#include + +#include +class QCheckBox; + +namespace score +{ +class FormWidget; +} +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); + +private: + QWidget* getWidget() override; + score::FormWidget* m_widg{}; + + QCheckBox* m_enabled{}; +}; + +} +} diff --git a/score_addon_hardware.cpp b/score_addon_hardware.cpp index d6114ca..4310a9d 100644 --- a/score_addon_hardware.cpp +++ b/score_addon_hardware.cpp @@ -1,12 +1,18 @@ #include "score_addon_hardware.hpp" -#include "Hardware/ApplicationPlugin.hpp" + +#include + +#include +#include + +#include score_addon_hardware::score_addon_hardware() { } score_addon_hardware::~score_addon_hardware() { } -score::GUIApplicationPlugin *score_addon_hardware::make_guiApplicationPlugin( - const score::GUIApplicationContext& app) const +score::GUIApplicationPlugin* score_addon_hardware::make_guiApplicationPlugin( + const score::GUIApplicationContext& app) { return new Hardware::ApplicationPlugin{app}; } @@ -14,6 +20,21 @@ score::GUIApplicationPlugin *score_addon_hardware::make_guiApplicationPlugin( std::vector> score_addon_hardware::factoryFamilies() { - return make_ptr_vector< - score::InterfaceListBase>(); + return make_ptr_vector(); } + +std::vector score_addon_hardware::factories( + const score::ApplicationContext& ctx, const score::InterfaceKey& key) const +{ + return instantiate_factories< + score::ApplicationContext, + FW>(ctx, key); +} + +auto score_addon_hardware::required() const -> std::vector +{ + return {score_plugin_scenario::static_key()}; +} + +#include +SCORE_EXPORT_PLUGIN(score_addon_hardware) diff --git a/score_addon_hardware.hpp b/score_addon_hardware.hpp index 4a3a538..5ee637a 100644 --- a/score_addon_hardware.hpp +++ b/score_addon_hardware.hpp @@ -1,14 +1,16 @@ #pragma once - #include -#include -#include +#include #include #include #include +#include #include +#include +#include + class score_addon_hardware final : public score::Plugin_QtInterface , public score::FactoryList_QtInterface @@ -22,9 +24,9 @@ public: private: score::GUIApplicationPlugin* - make_guiApplicationPlugin(const score::GUIApplicationContext& app) const; + make_guiApplicationPlugin(const score::GUIApplicationContext& app) override; - std::vector> factoryFamilies() override; + std::vector> factoryFamilies() override; std::vector factories( const score::ApplicationContext& ctx, @@ -32,4 +34,3 @@ private: std::vector required() const override; }; -