[repo] probably way to much copy from score_plugin_remotecontrol

This commit is contained in:
thibaud keller 2024-10-06 00:31:31 +01:00
parent 8cdc113508
commit 42f28e2b2f
17 changed files with 310 additions and 37 deletions

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(score_addon_hardware LANGUAGES CXX)
if(NOT TARGET score_lib_base) if(NOT TARGET score_lib_base)
include(ScoreExternalAddon) include(ScoreExternalAddon)
@ -9,26 +9,34 @@ if(NOT TARGET libremidi)
return() return()
endif() endif()
project(score_addon_hardware LANGUAGES CXX)
score_common_setup() score_common_setup()
set(HDRS set(HDRS
"Hardware/ApplicationPlugin.hpp" # "Hardware/Hardware.hpp"
# "Hardware/Controller.hpp"
# "Hardware/MidiController.hpp"
"Hardware/Hardware.hpp" "Hardware/Settings/Model.hpp"
"Hardware/Controller.hpp" "Hardware/Settings/Presenter.hpp"
"Hardware/MidiController.hpp" "Hardware/Settings/View.hpp"
"Hardware/Settings/Factory.hpp"
"Hardware/ApplicationPlugin.hpp"
"score_addon_hardware.hpp" "score_addon_hardware.hpp"
) )
set(SRCS 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/Settings/Model.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp" # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Settings/Presenter.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/MidiController.cpp" # "${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Settings/View.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
) )
@ -39,3 +47,5 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
score_plugin_scenario score_plugin_scenario
libremidi libremidi
) )
setup_score_plugin(${PROJECT_NAME})

View file

@ -1,8 +1,10 @@
#include "ApplicationPlugin.hpp" #include <score/tools/IdentifierGeneration.hpp>
#include <Hardware/ApplicationPlugin.hpp>
namespace Hardware namespace Hardware
{ {
ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationPlugin& app) ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationContext& app)
: GUIApplicationPlugin{app} : GUIApplicationPlugin{app}
{ } { }
} }

View file

@ -7,5 +7,6 @@ namespace Hardware
class ApplicationPlugin final : public score::GUIApplicationPlugin class ApplicationPlugin final : public score::GUIApplicationPlugin
{ {
public: public:
ApplicationPlugin(const score::GUIApplicationPlugin& app); ApplicationPlugin(const score::GUIApplicationContext& app);
}; };
}

View file

@ -1,7 +1,7 @@
#ifndef CONTROLLER_HPP #ifndef CONTROLLER_HPP
#define CONTROLLER_HPP #define CONTROLLER_HPP
namespace RemoteControl namespace Hardware
{ {
struct Controller struct Controller

View file

@ -7,7 +7,7 @@
#include "Hardware.hpp" #include "Hardware.hpp"
namespace RemoteControl namespace Hardware
{ {
Hardware::Hardware(const score::DocumentContext& doc) Hardware::Hardware(const score::DocumentContext& doc)
: m_dev{doc.plugin<Explorer::DeviceDocumentPlugin>()} : m_dev{doc.plugin<Explorer::DeviceDocumentPlugin>()}
@ -142,4 +142,4 @@ void Hardware::draw_intervals()
} }
} }
W_OBJECT_IMPL(RemoteControl::Hardware) W_OBJECT_IMPL(Hardware::Hardware)

View file

@ -1,16 +1,15 @@
#ifndef HARDWARE_HPP #pragma once
#define HARDWARE_HPP
#include <score_plugin_remotecontrol_export.h> // #include <score_addon_hardware_export.h>
#include <Scenario/Document/Interval/IntervalModel.hpp> #include <Scenario/Document/Interval/IntervalModel.hpp>
#include <Scenario/Process/ScenarioModel.hpp> #include <Scenario/Process/ScenarioModel.hpp>
#include "MidiController.hpp" #include "MidiController.hpp"
namespace RemoteControl namespace Hardware
{ {
class SCORE_PLUGIN_REMOTECONTROL_EXPORT Hardware class /*SCORE_PLUGIN_HARDWARE_EXPORT*/ Hardware
: public QObject : public QObject
{ {
W_OBJECT(Hardware) W_OBJECT(Hardware)
@ -38,4 +37,3 @@ private:
}; };
} }
#endif // HARDWARE_HPP

View file

@ -2,8 +2,8 @@
#include "MidiController.hpp" #include "MidiController.hpp"
namespace RemoteControl { namespace Hardware
{
MidiController::MidiController() MidiController::MidiController()
: grid{GRID} : grid{GRID}
, previous_grid{BLACK} , previous_grid{BLACK}

View file

@ -44,9 +44,8 @@ namespace Explorer
class DeviceDocumentPlugin; class DeviceDocumentPlugin;
} }
namespace RemoteControl namespace Hardware
{ {
class MidiController : public Controller class MidiController : public Controller
{ {
public: public:

View file

@ -0,0 +1,15 @@
#pragma once
#include <score/plugins/settingsdelegate/SettingsDelegateFactory.hpp>
#include <Hardware/Settings/Model.hpp>
#include <Hardware/Settings/Presenter.hpp>
#include <Hardware/Settings/View.hpp>
namespace Hardware
{
namespace Settings
{
SCORE_DECLARE_SETTINGS_FACTORY(
Factory, Model, Presenter, View, "995020ed-304a-42b5-8e3b-eb050a7305ed")
}
}

View file

@ -0,0 +1,28 @@
#include "Model.hpp"
#include <QSettings>
#include <wobjectimpl.h>
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)
}
}

View file

@ -0,0 +1,25 @@
#pragma once
#include <score/plugins/settingsdelegate/SettingsDelegateModel.hpp>
#include <score_addon_hardware_export.h>
#include <tuple>
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)
}
}

View file

@ -0,0 +1,52 @@
#include "Presenter.hpp"
#include "Model.hpp"
#include "View.hpp"
#include <score/command/Command.hpp>
#include <score/command/Dispatchers/ICommandDispatcher.hpp>
#include <score/command/SettingsCommand.hpp>
#include <score/widgets/SetIcons.hpp>
#include <QApplication>
#include <QStyle>
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<SetModelEnabled>(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"));
}
}
}

View file

@ -0,0 +1,24 @@
#pragma once
#include <score/plugins/settingsdelegate/SettingsDelegatePresenter.hpp>
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;
};
}
}

View file

@ -0,0 +1,64 @@
#include "View.hpp"
#include <score/widgets/FormWidget.hpp>
#include <QCheckBox>
#include <QFormLayout>
#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")};
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;
}
}
}

View file

@ -0,0 +1,33 @@
#pragma once
#include <score/plugins/settingsdelegate/SettingsDelegateView.hpp>
#include <Hardware/Settings/Model.hpp>
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{};
};
}
}

View file

@ -1,12 +1,18 @@
#include "score_addon_hardware.hpp" #include "score_addon_hardware.hpp"
#include "Hardware/ApplicationPlugin.hpp"
#include <score/plugins/FactorySetup.hpp>
#include <Hardware/ApplicationPlugin.hpp>
#include <Hardware/Settings/Factory.hpp>
#include <score_plugin_scenario.hpp>
score_addon_hardware::score_addon_hardware() { } score_addon_hardware::score_addon_hardware() { }
score_addon_hardware::~score_addon_hardware() { } score_addon_hardware::~score_addon_hardware() { }
score::GUIApplicationPlugin *score_addon_hardware::make_guiApplicationPlugin( score::GUIApplicationPlugin* score_addon_hardware::make_guiApplicationPlugin(
const score::GUIApplicationContext& app) const const score::GUIApplicationContext& app)
{ {
return new Hardware::ApplicationPlugin{app}; return new Hardware::ApplicationPlugin{app};
} }
@ -14,6 +20,21 @@ score::GUIApplicationPlugin *score_addon_hardware::make_guiApplicationPlugin(
std::vector<std::unique_ptr<score::InterfaceListBase>> std::vector<std::unique_ptr<score::InterfaceListBase>>
score_addon_hardware::factoryFamilies() score_addon_hardware::factoryFamilies()
{ {
return make_ptr_vector< return make_ptr_vector<score::InterfaceListBase>();
score::InterfaceListBase>();
} }
std::vector<score::InterfaceBase*> score_addon_hardware::factories(
const score::ApplicationContext& ctx, const score::InterfaceKey& key) const
{
return instantiate_factories<
score::ApplicationContext,
FW<score::SettingsDelegateFactory, Hardware::Settings::Factory>>(ctx, key);
}
auto score_addon_hardware::required() const -> std::vector<score::PluginKey>
{
return {score_plugin_scenario::static_key()};
}
#include <score/plugins/PluginInstances.hpp>
SCORE_EXPORT_PLUGIN(score_addon_hardware)

View file

@ -1,14 +1,16 @@
#pragma once #pragma once
#include <score/application/ApplicationContext.hpp> #include <score/application/ApplicationContext.hpp>
#include <score/plugins//Interface.hpp> #include <score/plugins/Interface.hpp>
#include <score/plugins/qt_interfaces/PluginRequirements_QtInterface.hpp>
#include <score/plugins/qt_interfaces/FactoryFamily_QtInterface.hpp> #include <score/plugins/qt_interfaces/FactoryFamily_QtInterface.hpp>
#include <score/plugins/qt_interfaces/FactoryInterface_QtInterface.hpp> #include <score/plugins/qt_interfaces/FactoryInterface_QtInterface.hpp>
#include <score/plugins/qt_interfaces/GUIApplicationPlugin_QtInterface.hpp> #include <score/plugins/qt_interfaces/GUIApplicationPlugin_QtInterface.hpp>
#include <score/plugins/qt_interfaces/PluginRequirements_QtInterface.hpp>
#include <QObject> #include <QObject>
#include <utility>
#include <vector>
class score_addon_hardware final class score_addon_hardware final
: public score::Plugin_QtInterface : public score::Plugin_QtInterface
, public score::FactoryList_QtInterface , public score::FactoryList_QtInterface
@ -22,9 +24,9 @@ public:
private: private:
score::GUIApplicationPlugin* score::GUIApplicationPlugin*
make_guiApplicationPlugin(const score::GUIApplicationContext& app) const; make_guiApplicationPlugin(const score::GUIApplicationContext& app) override;
std::vector<std::unique_ptr<score::InterfaceBase>> factoryFamilies() override; std::vector<std::unique_ptr<score::InterfaceListBase>> factoryFamilies() override;
std::vector<score::InterfaceBase*> factories( std::vector<score::InterfaceBase*> factories(
const score::ApplicationContext& ctx, const score::ApplicationContext& ctx,
@ -32,4 +34,3 @@ private:
std::vector<score::PluginKey> required() const override; std::vector<score::PluginKey> required() const override;
}; };