Skip to content

Commit

Permalink
Improve module partnering
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Dempsey committed Dec 4, 2023
1 parent 4380bc2 commit c274073
Show file tree
Hide file tree
Showing 28 changed files with 191 additions and 206 deletions.
27 changes: 1 addition & 26 deletions src/Compress/Compress-ui.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Compress.hpp"
#include "../colors.hpp"
#include "../knob_layout.hpp"
#include "../misc.hpp"
#include "../text.hpp"
#include "../widgets/cc_param.hpp"
Expand Down Expand Up @@ -74,8 +73,7 @@ CompressModuleWidget::CompressModuleWidget(CompressModule * module)
my_module->ui_event_sink = this;
}
setPanel(createPanel(asset::plugin(pluginInstance, "res/Compress.svg")));
addChild(partner_picker = createPartnerPicker(7.f, 14.f, 180.f, module ? &module->partner_binding : nullptr));

addChild(partner_picker = createPartnerPicker());
createCompressorUI();
}

Expand All @@ -95,29 +93,6 @@ Hc1Module* CompressModuleWidget::getPartner()
return my_module->getPartner();
}

// void CompressModuleWidget::draw(const DrawArgs& args)
// {
// ModuleWidget::draw(args);

// //auto partner = getPartner();
// //if (partner) {
// // system_data
// // auto font = GetPluginFontRegular();
// // SetTextStyle(args.vg, font, RampGray(G_90), 10.f);
// // std::string data;
// // if (partner->system_data.empty()) {
// // data = "(empty)";
// // } else {
// // for (auto b:partner->system_data) {
// // auto hex = format_string("%02x", b);
// // data.append(hex);
// // }
// // }
// // nvgText(args.vg, 7.5, box.size.y - 64, data.c_str(), nullptr);
// //}

// }

void CompressModuleWidget::appendContextMenu(Menu *menu)
{
if (!my_module) { return; }
Expand Down
20 changes: 8 additions & 12 deletions src/Compress/Compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ CompressModule::CompressModule()
configSwitch(P_COMP_MIX_REL, 0.f, 1.f, 0.f, "Mix relative CV", offon);

configLight(L_COMPRESSOR, "Compressor");
partner_binding.setClient(this);
}

CompressModule::~CompressModule()
{
if (!partner_subscribed) return;
auto partner = partner_binding.getPartner();
if (partner){
partner->unsubscribeHcEvents(this);
partner_subscribed = false;
}
partner_binding.unsubscribe();
}

json_t * CompressModule::dataToJson()
{
auto root = json_object();
Expand All @@ -56,12 +53,12 @@ void CompressModule::dataFromJson(json_t *root)
if (j) {
partner_binding.setClaim(json_string_value(j));
}
//getPartner();
getPartner();
}

Hc1Module* CompressModule::getPartner()
{
return getPartnerImpl<CompressModule>(this);
return partner_binding.getPartner();
}

void CompressModule::onCompressorChanged(const CompressorChangedEvent &e)
Expand Down Expand Up @@ -109,7 +106,6 @@ void CompressModule::onDeviceChanged(const DeviceChangedEvent& e)

void CompressModule::onDisconnect(const DisconnectEvent& e)
{
partner_subscribed = false;
partner_binding.onDisconnect(e);
if (ui_event_sink) {
ui_event_sink->onDisconnect(e);
Expand Down Expand Up @@ -226,10 +222,10 @@ void CompressModule::processControls()

void CompressModule::process(const ProcessArgs& args)
{
auto partner = getPartner();
if (!partner || !partner->readyToSend()) return;

if ((0 == ((args.frame + id) % CV_INTERVAL))) {
if (!partner_subscribed) {
getPartner();
}
processCV(Params::P_COMP_THRESHOLD);
processCV(Params::P_COMP_ATTACK);
processCV(Params::P_COMP_RATIO);
Expand Down
1 change: 0 additions & 1 deletion src/Compress/Compress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ struct CompressModule : Module, ISendMidi, IHandleHcEvents
IHandleHcEvents * ui_event_sink = nullptr;
PartnerBinding partner_binding;
Hc1Module* getPartner();
bool partner_subscribed = false;

// cv processing
const int CV_INTERVAL = 64;
Expand Down
7 changes: 6 additions & 1 deletion src/HC-1/HC-1-midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Hc1Module::onRenewClaim()
}
}

void Hc1Module::setMidiDevice(const std::string & claim)
void Hc1Module::setMidiDeviceClaim(const std::string & claim)
{
if (0 == device_claim.compare(claim)) return;
if (!device_claim.empty()) {
Expand All @@ -61,6 +61,11 @@ void Hc1Module::setMidiDevice(const std::string & claim)
reboot();
}

const std::string& Hc1Module::getMidiDeviceClaim()
{
return device_claim;
}

void Hc1Module::setMacroCCValue(int id, uint8_t value)
{
auto pq = dynamic_cast<CCParamQuantity*>(getParamQuantity(id));
Expand Down
4 changes: 2 additions & 2 deletions src/HC-1/HC-1-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ void Hc1ModuleWidget::onDeviceChanged(const DeviceChangedEvent& e)
{
bool have_device = e.device && (-1 != e.device->input_device_id);
em_picker->setConnection(e.device);
em_picker->describe(have_device ? e.device->info.friendly(true) : "Choose an Eagan Matrix device");
device_label->text(have_device ? e.device->info.friendly(false) : "<Eagan Matrix device>");
em_picker->describe(have_device ? e.device->info.friendly(TextFormatLength::Long) : "Choose an Eagan Matrix device");
device_label->text(have_device ? e.device->info.friendly(TextFormatLength::Short) : "<Eagan Matrix device>");
hardware_label->text(my_module ? HardwareName(my_module->em.hardware) : "");
firmware_label->text(format_string("v%03.2f", (my_module ? my_module->em.firmware_version : 0)/100.f));
}
Expand Down
9 changes: 5 additions & 4 deletions src/HC-1/HC-1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace pachde {
const NVGcolor& StatusColor(StatusItem led);
struct MidiInputWorker;

struct Hc1Module : IPresetHolder, ISendMidi, ISetDevice, IMidiDeviceChange, midi::Input, Module
struct Hc1Module : IPresetHolder, ISendMidi, IMidiDeviceHolder, IMidiDeviceChange, midi::Input, Module
{
enum Params
{
Expand Down Expand Up @@ -165,7 +165,7 @@ struct Hc1Module : IPresetHolder, ISendMidi, ISetDevice, IMidiDeviceChange, midi
// Phase State MIDI rate Post delay Budget
InitPhaseInfo{InitPhase::DeviceOutput, InitState::Uninitialized, EMMidiRate::Full, 4.0f, 0.f },
InitPhaseInfo{InitPhase::DeviceInput, InitState::Uninitialized, EMMidiRate::Full, 3.0f, 0.f },
InitPhaseInfo{InitPhase::DeviceHello, InitState::Uninitialized, EMMidiRate::Third, 1.0f, 4.f },
InitPhaseInfo{InitPhase::DeviceHello, InitState::Uninitialized, EMMidiRate::Third, 2.0f, 4.f },
InitPhaseInfo{InitPhase::DeviceConfig, InitState::Uninitialized, EMMidiRate::Third, 1.0f, 4.f },
InitPhaseInfo{InitPhase::CachedPresets, InitState::Uninitialized, EMMidiRate::Full, 0.f, 0.f },
InitPhaseInfo{InitPhase::UserPresets, InitState::Uninitialized, EMMidiRate::Third, 1.0f, 12.f },
Expand Down Expand Up @@ -233,8 +233,9 @@ struct Hc1Module : IPresetHolder, ISendMidi, ISetDevice, IMidiDeviceChange, midi
// IMidiDeviceChange
void onRenewClaim() override;

// ISetDevice
void setMidiDevice(const std::string & claim) override;
// IMidiDeviceHolder
void setMidiDeviceClaim(const std::string & claim) override;
const std::string& getMidiDeviceClaim() override;
bool in_reboot = false;

MidiInputWorker* midi_input_worker{nullptr};
Expand Down
2 changes: 0 additions & 2 deletions src/HC-2/HC-2-layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace pachde {
constexpr const float PAD = 1.f;
constexpr const float MORE_PAD = 4.f;
constexpr const float KNOB_BOX_HEIGHT = 62.5f;
constexpr const float KNOB_RADIUS = 12.f;
constexpr const float HALF_KNOB = KNOB_RADIUS *.5f;
constexpr const float KNOB_SPREAD = 54.25f;
constexpr const float KNOB_COL1 = 35.f;
constexpr const float KNOB_ROW = 44.f;
Expand Down
2 changes: 1 addition & 1 deletion src/HC-2/HC-2-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Hc2ModuleWidget::Hc2ModuleWidget(Hc2Module * module)
my_module->ui_event_sink = this;
}
setPanel(createPanel(asset::plugin(pluginInstance, "res/HC-2.svg")));
addChild(partner_picker = createPartnerPicker(7.f, 14.f, 180.f, module ? &module->partner_binding : nullptr));
addChild(partner_picker = createPartnerPicker());

createTiltEqUI(TEQ_BOX_LEFT, TEQ_BOX_TOP);

Expand Down
13 changes: 5 additions & 8 deletions src/HC-2/HC-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ Hc2Module::Hc2Module()
configSwitch(P_TEQ_MIX_REL, 0.f, 1.f, 0.f, "Mix relative CV", offon);

configLight(L_TEQ, "Tilt EQ");
partner_binding.setClient(this);
}

Hc2Module::~Hc2Module()
{
if (!partner_subscribed) return;
auto partner = partner_binding.getPartner();
if (partner){
partner->unsubscribeHcEvents(this);
partner_subscribed = false;
}
partner_binding.unsubscribe();
}

json_t * Hc2Module::dataToJson()
{
auto root = json_object();
Expand All @@ -57,7 +54,7 @@ void Hc2Module::dataFromJson(json_t *root)

Hc1Module* Hc2Module::getPartner()
{
return getPartnerImpl<Hc2Module>(this);
return partner_binding.getPartner();
}

void Hc2Module::onTiltEqChanged(const TiltEqChangedEvent& e)
Expand Down Expand Up @@ -96,7 +93,7 @@ void Hc2Module::onDeviceChanged(const DeviceChangedEvent& e)

void Hc2Module::onDisconnect(const DisconnectEvent& e)
{
partner_subscribed = false;
partner_binding.onDisconnect(e);
if (ui_event_sink) {
ui_event_sink->onDisconnect(e);
}
Expand Down
1 change: 0 additions & 1 deletion src/HC-2/HC-2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ struct Hc2Module : Module, ISendMidi, IHandleHcEvents
IHandleHcEvents * ui_event_sink = nullptr;
PartnerBinding partner_binding;
Hc1Module* getPartner();
bool partner_subscribed = false;

// cv processing
const int CV_INTERVAL = 64;
Expand Down
8 changes: 1 addition & 7 deletions src/HC-3/HC-3-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Hc3ModuleWidget::Hc3ModuleWidget(Hc3Module* module)
my_module->ui_event_sink = this;
}
setPanel(createPanel(asset::plugin(pluginInstance, "res/HC-3.svg")));
addChild(partner_picker = createPartnerPicker(7.f, 14.f, 180.f, module ? &module->partner_binding : nullptr));
addChild(partner_picker = createPartnerPicker());

float y = START_ROW;
float x = 15.f;
Expand Down Expand Up @@ -55,12 +55,6 @@ void Hc3ModuleWidget::onFavoritesFileChanged(const FavoritesFileChangedEvent& e)
void Hc3ModuleWidget::step()
{
ModuleWidget::step();
// if (module && device_label->getText().empty()) {
// auto partner = my_module->getPartner();
// if (partner && partner->connection) {
// device_label->text(partner->connection->info.friendly(false));
// }
// }
if (!module && !hacked_lights) {
// Rack turns every light to full brightness in the module browser
// we hack it here to show a more representative state.
Expand Down
21 changes: 8 additions & 13 deletions src/HC-3/HC-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ Hc3Module::Hc3Module()
"1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8",
"2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8",
});
partner_binding.setClient(this);
}

Hc3Module::~Hc3Module()
{
if (partner_subscribed) {
auto partner = partner_binding.getPartner();
if (partner) {
partner->unsubscribeHcEvents(this);
partner_subscribed = false;
}
}
partner_binding.unsubscribe();
}

Hc1Module* Hc3Module::getPartner() {
return getPartnerImpl<Hc3Module>(this);
Hc1Module* Hc3Module::getPartner()
{
return partner_binding.getPartner();
}

void Hc3Module::onDeviceChanged(const DeviceChangedEvent& e)
Expand All @@ -40,8 +36,7 @@ void Hc3Module::onDeviceChanged(const DeviceChangedEvent& e)

void Hc3Module::onDisconnect(const DisconnectEvent& e)
{
partner_subscribed = false;
// partner_binding.forgetModule();
partner_binding.onDisconnect(e);
if (ui_event_sink) {
ui_event_sink->onDisconnect(e);
}
Expand Down Expand Up @@ -137,6 +132,7 @@ void Hc3Module::dataFromJson(json_t *root)
files.push_back(json_string_value(jp));
}
}
getPartner();
}

void Hc3Module::openFile(int id) {
Expand Down Expand Up @@ -167,8 +163,7 @@ void Hc3Module::process(const ProcessArgs& args)
if (time > POLL_RATE) {
poll_timer.reset();
auto partner = getPartner();
if (partner)
{
if (partner) {
const std::string &partnerFile = partner->favoritesFile;
if (partnerFile.empty()) {
setSynchronizedLoadedId(-1);
Expand Down
1 change: 0 additions & 1 deletion src/HC-3/HC-3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct Hc3Module : Module, IHandleHcEvents
int loaded_id;
std::vector<std::string> files;
PartnerBinding partner_binding;
bool partner_subscribed = false;
IHandleHcEvents * ui_event_sink = nullptr;

const float POLL_RATE = 1.5f;
Expand Down
5 changes: 2 additions & 3 deletions src/HC-4/HC-4-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ Hc4ModuleWidget::Hc4ModuleWidget(Hc4Module * module)
my_module->ui_event_sink = this;
}
setPanel(createPanel(asset::plugin(pluginInstance, "res/HC-4.svg")));
addChild(partner_picker = createPartnerPicker(7.f, 14.f, 180.f, module ? &module->partner_binding : nullptr));
addChild(partner_picker = createPartnerPicker());
}

Hc1Module* Hc4ModuleWidget::getPartner()
{
if (!module) return nullptr;
return my_module->getPartner();
return module ? my_module->getPartner() : nullptr;
}

void Hc4ModuleWidget::onDeviceChanged(const DeviceChangedEvent& e)
Expand Down
12 changes: 4 additions & 8 deletions src/HC-4/HC-4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ namespace pachde {
Hc4Module::Hc4Module()
{
config(Params::NUM_PARAMS, Inputs::NUM_INPUTS, Outputs::NUM_OUTPUTS, Lights::NUM_LIGHTS);
partner_binding.setClient(this);
}

Hc4Module::~Hc4Module()
{
if (!partner_subscribed) return;
auto partner = partner_binding.getPartner();
if (partner){
partner->unsubscribeHcEvents(this);
partner_subscribed = false;
}
partner_binding.unsubscribe();
}

json_t * Hc4Module::dataToJson()
Expand All @@ -30,11 +26,12 @@ void Hc4Module::dataFromJson(json_t *root)
if (j) {
partner_binding.setClaim(json_string_value(j));
}
getPartner();
}

Hc1Module* Hc4Module::getPartner()
{
return getPartnerImpl<Hc4Module>(this);
return partner_binding.getPartner();
}

void Hc4Module::onPedalChanged(const PedalChangedEvent& e)
Expand All @@ -52,7 +49,6 @@ void Hc4Module::onDeviceChanged(const DeviceChangedEvent& e)

void Hc4Module::onDisconnect(const DisconnectEvent& e)
{
partner_subscribed = false;
partner_binding.onDisconnect(e);
if (ui_event_sink) {
ui_event_sink->onDisconnect(e);
Expand Down
1 change: 0 additions & 1 deletion src/HC-4/HC-4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct Hc4Module : Module, IHandleHcEvents
};

PartnerBinding partner_binding;
bool partner_subscribed = false;

IHandleHcEvents * ui_event_sink = nullptr;
const int CV_INTERVAL = 128;
Expand Down
2 changes: 1 addition & 1 deletion src/Pedals/Pedals-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ constexpr const float JUMP_SPREAD = 50.25f;

void PedalUICore::createUI()
{
addChild(partner_picker = createPartnerPicker(7.f, 14.f, 180.f, core_module ? &core_module->partner_binding : nullptr));
addChild(partner_picker = createPartnerPicker());

/// pedal function knob
float x_center = box.size.x * .5f;
Expand Down
Loading

0 comments on commit c274073

Please sign in to comment.