Skip to content

Commit

Permalink
HcOne->ModuleBroker
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Dempsey committed Sep 26, 2023
1 parent 689754c commit e59b4e2
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SOURCES += src/em_midi.cpp
SOURCES += src/em_pedal.cpp
SOURCES += src/em_types.cpp
SOURCES += src/misc.cpp
SOURCES += src/HcOne.cpp
SOURCES += src/module_broker.cpp
SOURCES += src/open_file.cpp
SOURCES += src/plugin.cpp
SOURCES += src/preset_meta.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/HC-1/HC-1-midi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "HC-1.hpp"
#include "../cc_param.hpp"
#include "../HcOne.hpp"
#include "../module_broker.hpp"

namespace pachde {

Expand Down Expand Up @@ -46,7 +46,7 @@ void Hc1Module::resetMidiIO()
void Hc1Module::checkDuplicate()
{
dupe = false;
auto one = HcOne::get();
auto one = ModuleBroker::get();
if (one->Hc1count() > 1) {
one->scan_while([=](Hc1Module* const& m) {
if (m != this
Expand Down
4 changes: 2 additions & 2 deletions src/HC-1/HC-1-process.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "HC-1.hpp"
#include "../cc_param.hpp"
#include "../HcOne.hpp"
#include "../module_broker.hpp"
namespace pachde {

void Hc1Module::processCV(int paramId)
Expand Down Expand Up @@ -177,7 +177,7 @@ void Hc1Module::initOutputDevice()
assert(InitState::Uninitialized == device_output_state);
assert(device_name.empty());

bool singleton = HcOne::get()->Hc1count() == 1;
bool singleton = ModuleBroker::get()->Hc1count() == 1;
auto claims = !singleton
? DeviceAssociation::getList()
: std::vector<DeviceAssociation>{};
Expand Down
8 changes: 4 additions & 4 deletions src/HC-1/HC-1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "HC-1.hpp"
#include "../cc_param.hpp"
#include "../HcOne.hpp"
#include "../module_broker.hpp"
#include "../misc.hpp"

namespace pachde {
Expand Down Expand Up @@ -61,13 +61,13 @@ Hc1Module::Hc1Module()
getLight(HEART_LIGHT).setBrightness(.8f);
clearCCValues();

HcOne::get()->registerHc1(this);
ModuleBroker::get()->registerHc1(this);
}

Hc1Module::~Hc1Module()
{
notifyDisconnect();
HcOne::get()->unregisterHc1(this);
ModuleBroker::get()->unregisterHc1(this);
if (restore_ui_data) {
delete restore_ui_data;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void Hc1Module::onSave(const SaveEvent& e)
void Hc1Module::onRemove(const RemoveEvent& e)
{
notifyDisconnect();
HcOne::get()->unregisterHc1(this);
ModuleBroker::get()->unregisterHc1(this);
savePresets();
Module::onRemove(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/HC-2/HC-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../cc_param.hpp"
#include "../colors.hpp"
#include "../components.hpp"
#include "../HcOne.hpp"
#include "../module_broker.hpp"
#include "../misc.hpp"
#include "../text.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/HC-2/HC-2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../em_types.hpp"
#include "../hc_events.hpp"
#include "../HC-1/HC-1.hpp"
#include "../HCOne.hpp"
#include "../module_broker.hpp"
#include "../plugin.hpp"
#include "../presets.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/HC-3/HC-3-ui.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "hc-3.hpp"
#include "../HcOne.hpp"
#include "../misc.hpp"
#include "../module_broker.hpp"
#include "../small_push.hpp"
#include "preset_file_widget.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/HC-3/HC-3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>
#include "../HC-1/HC-1.hpp"
#include "../hc_events.hpp"
#include "../HcOne.hpp"
#include "../module_broker.hpp"
#include "../plugin.hpp"
#include "../presets.hpp"
#include "../square_button.hpp"
Expand Down
26 changes: 13 additions & 13 deletions src/HcOne.cpp → src/module_broker.cpp
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
#include "HcOne.hpp"
#include "module_broker.hpp"

namespace pachde {
HcOne* hcOne = nullptr;
ModuleBroker* hcOne = nullptr;

struct HcOne::Internal
struct ModuleBroker::Internal
{
std::vector<Hc1Module*> hc1s;
};

HcOne* HcOne::get()
ModuleBroker* ModuleBroker::get()
{
if (!hcOne) {
hcOne = new HcOne;
hcOne = new ModuleBroker;
}
return hcOne;
}

HcOne::HcOne()
ModuleBroker::ModuleBroker()
: my(new Internal)
{
}

int HcOne::Hc1count() {
int ModuleBroker::Hc1count() {
return static_cast<int>(my->hc1s.size());
}

Hc1Module* HcOne::getSoleHc1() {
Hc1Module* ModuleBroker::getSoleHc1() {
if (my->hc1s.empty()) return nullptr;
if (1 == my->hc1s.size()) return *my->hc1s.cbegin();
return nullptr;
}

Hc1Module* HcOne::getHc1(std::function<bool (Hc1Module* const&)> pred)
Hc1Module* ModuleBroker::getHc1(std::function<bool (Hc1Module* const&)> pred)
{
auto item = std::find_if(my->hc1s.cbegin(), my->hc1s.cend(), pred);
return item == my->hc1s.cend() ? nullptr : *item;
}

void HcOne::scan_while(std::function<bool(Hc1Module* const&)> pred)
void ModuleBroker::scan_while(std::function<bool(Hc1Module* const&)> pred)
{
for (auto m: my->hc1s) {
if (!pred(m)) break;
}
}

Hc1Module* HcOne::getHc1(int64_t id)
Hc1Module* ModuleBroker::getHc1(int64_t id)
{
auto item = std::find_if(my->hc1s.cbegin(), my->hc1s.cend(), [=](Hc1Module* const& m){ return m->getId() == id; });
return item == my->hc1s.cend() ? nullptr : *item;
}

void HcOne::registerHc1(Hc1Module* module)
void ModuleBroker::registerHc1(Hc1Module* module)
{
if (my->hc1s.cend() == std::find(my->hc1s.cbegin(), my->hc1s.cend(), module)) {
my->hc1s.push_back(module);
}
}

void HcOne::unregisterHc1(Hc1Module* module)
void ModuleBroker::unregisterHc1(Hc1Module* module)
{
auto item = std::find(my->hc1s.cbegin(), my->hc1s.cend(), module);
if (item != my->hc1s.cend())
Expand Down
14 changes: 7 additions & 7 deletions src/HcOne.hpp → src/module_broker.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#pragma once
#ifndef HCONE_HPP_INCLUDED
#define HCONE_HPP_INCLUDED
#ifndef MODULE_BROKER_HPP_INCLUDED
#define MODULE_BROKER_HPP_INCLUDED
#include "./HC-1/HC-1.hpp"
// #include "./HC-2/HC-2.hpp"
// #include "./HC-3/HC-3.hpp"

namespace pachde {

struct HcOne
struct ModuleBroker
{
struct Internal;
Internal * my;

static HcOne* get();
static ModuleBroker* get();
void registerHc1(Hc1Module * module);
void unregisterHc1(Hc1Module * module);
int Hc1count();
Expand All @@ -24,7 +24,7 @@ struct HcOne
void scan_while(std::function<bool(Hc1Module* const&)> pred);

private:
HcOne();
ModuleBroker();
};

struct DeviceAssociation {
Expand All @@ -38,7 +38,7 @@ struct DeviceAssociation {
static std::vector<DeviceAssociation> getList()
{
std::vector<DeviceAssociation> list;
auto one = HcOne::get();
auto one = ModuleBroker::get();
one->scan_while([&](Hc1Module* const& mod){
list.push_back(DeviceAssociation{mod->deviceName(), mod->getId()});
return true;
Expand All @@ -60,7 +60,7 @@ struct PartnerBinding

Hc1Module* getPartner()
{
auto one = HcOne::get();
auto one = ModuleBroker::get();

// If no HC-1, forget any we remember and give up (but still remember
// the device name, if one comes along that matches)
Expand Down

0 comments on commit e59b4e2

Please sign in to comment.