Skip to content

Commit

Permalink
Use MetaModule:: namespace everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Sep 9, 2024
1 parent f3cc1b9 commit a39a758
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 39 deletions.
8 changes: 6 additions & 2 deletions src/hub/hub_knob.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "mapping/map_marks.hh"
#include "mapping/map_palette.hh"

namespace MetaModule
{

template<typename BaseKnobT>
class HubKnob : public BaseKnobT {
public:
Expand Down Expand Up @@ -46,8 +49,7 @@ public:
APP->scene->rack->setTouchedParam(this);
}
e.consume(this);
}
else if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) {
} else if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) {
mapBut.start_mapping();
}
}
Expand Down Expand Up @@ -89,3 +91,5 @@ private:
MetaModuleHubBase *hub;
HubKnobMapButton &mapBut;
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/hub/hub_knob_map_button.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "mapping/knob_alias_menu.hh"
#include "mapping/range_slider.hh"

namespace MetaModule
{

class HubKnobMapButton : public HubMapButton {
rack::ParamQuantity *paramQuantity = nullptr;
MetaModuleHubBase *hub;
Expand Down Expand Up @@ -140,3 +143,5 @@ public:
}
};
};

} // namespace MetaModule
4 changes: 4 additions & 0 deletions src/hub/hub_knob_mappings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// 5) which will notice the paramHandle is gone, and thus delete the map
// 6) Then, hub::encodeJson is called and writes out json without that map

namespace MetaModule
{

enum class ShouldLock { No, Yes };

Expand Down Expand Up @@ -422,3 +424,5 @@ public:

KnobMultiMap nullmap{};
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/hub/hub_map_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "mapping/map_palette.hh"
#include <cstdio>

namespace MetaModule
{

void HubMapButton::draw(const DrawArgs &args) {
hubParamObj.moduleID = parent.module ? parent.module->id : -1;

Expand Down Expand Up @@ -90,3 +93,5 @@ void HubMapButton::onEnter(const rack::event::Enter &e) {
}
e.consume(this);
}

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/hub/hub_map_button.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "hub/hub_module.hh"
#include <rack.hpp>

namespace MetaModule
{

class HubMapButton : public rack::Button {

public:
Expand All @@ -26,3 +29,5 @@ protected:
rack::app::ModuleWidget &parent;
MetaModuleHubBase *hub;
};

} // namespace MetaModule
29 changes: 17 additions & 12 deletions src/hub/hub_medium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

using namespace rack;

namespace MetaModule
{

struct HubMedium : MetaModuleHubBase {
using INFO = MetaModule::HubMediumInfo;
using INFO = HubMediumInfo;

static constexpr unsigned num_extra_params = 1; //Save Button

Expand All @@ -24,7 +27,7 @@ struct HubMedium : MetaModuleHubBase {
config(cnt.num_params + num_extra_params, cnt.num_inputs, cnt.num_outputs, cnt.num_lights);

// Configure elements with VCV
MetaModule::VCVModuleParamCreator<INFO> creator{this};
VCVModuleParamCreator<INFO> creator{this};
for (auto &element : INFO::Elements) {
std::visit([&creator](auto &el) { creator.config_element(el); }, element);
}
Expand All @@ -48,7 +51,7 @@ struct HubMedium : MetaModuleHubBase {

struct HubMediumWidget : MetaModuleHubWidget {

using INFO = MetaModule::HubMediumInfo;
using INFO = HubMediumInfo;

LedDisplayTextField *patchName;
LedDisplayTextField *patchDesc;
Expand All @@ -73,7 +76,7 @@ struct HubMediumWidget : MetaModuleHubWidget {
addChild(createWidget<ScrewBlack>(
rack::math::Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));

patchName = createWidget<MetaModule::TextField>(rack::mm2px(rack::math::Vec(36.1, 9.5)));
patchName = createWidget<TextField>(rack::mm2px(rack::math::Vec(36.1, 9.5)));
if (hubModule != nullptr && hubModule->patchNameText.length() > 0)
patchName->setText(this->hubModule->patchNameText);
else
Expand All @@ -92,7 +95,7 @@ struct HubMediumWidget : MetaModuleHubWidget {
addChild(statusText);
#endif

patchDesc = createWidget<MetaModule::TextField>(rack::mm2px(rack::math::Vec(36.4, 18.f)));
patchDesc = createWidget<TextField>(rack::mm2px(rack::math::Vec(36.4, 18.f)));
if (hubModule != nullptr && hubModule->patchDescText.length() > 0)
patchDesc->setText(this->hubModule->patchDescText);
else
Expand All @@ -109,11 +112,11 @@ struct HubMediumWidget : MetaModuleHubWidget {
knobSetTitle->fontSize = 10;
addChild(knobSetTitle);

knobSetNameField = new MetaModule::TextField{[this](std::string &text) {
auto idx = hubModule->mappings.getActiveKnobSetIdx();
hubModule->mappings.setKnobSetName(idx, text);
},
kMaxKnobSetNameChars};
knobSetNameField = new TextField{[this](std::string &text) {
auto idx = hubModule->mappings.getActiveKnobSetIdx();
hubModule->mappings.setKnobSetName(idx, text);
},
kMaxKnobSetNameChars};
knobSetNameField->box.pos = rack::mm2px(rack::math::Vec(52.0, 49.0));
knobSetNameField->box.size = {rack::mm2px(rack::math::Vec(40.f, 7.f))};
knobSetNameField->text = "";
Expand All @@ -131,7 +134,7 @@ struct HubMediumWidget : MetaModuleHubWidget {
updateKnobSetLabel();

// create widgets from all elements
MetaModule::HubWidgetCreator<INFO> creator(this, module);
HubWidgetCreator<INFO> creator(this, module);
for (auto &element : INFO::Elements) {
std::visit([&creator](auto &el) { creator.create(el); }, element);
}
Expand Down Expand Up @@ -210,4 +213,6 @@ struct HubMediumWidget : MetaModuleHubWidget {
};
};

rack::Model *modelHubMedium = rack::createModel<HubMedium, HubMediumWidget>("HubMedium");
} // namespace MetaModule

rack::Model *modelHubMedium = rack::createModel<MetaModule::HubMedium, MetaModule::HubMediumWidget>("HubMedium");
5 changes: 5 additions & 0 deletions src/hub/hub_midi.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once
#include "hub_knob.hh"

namespace MetaModule
{

class HubMidiMapButton : public HubKnobMapButton {
MetaModuleHubBase *hub;

Expand Down Expand Up @@ -114,3 +117,5 @@ private:
MetaModuleHubBase *hub;
HubKnobMapButton &mapBut;
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/hub/hub_module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <osdialog.h>
#include <span>

namespace MetaModule
{

struct MetaModuleHubBase : public rack::Module {

std::function<void()> updatePatchName;
Expand Down Expand Up @@ -157,3 +160,5 @@ struct MetaModuleHubBase : public rack::Module {
mappings.refreshParamHandles(ShouldLock::No);
}
};

} // namespace MetaModule
16 changes: 6 additions & 10 deletions src/hub/hub_module_widget.hh
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
#pragma once
#include "../comm/comm_module.hh"
#include "CoreModules/moduleFactory.hh"
#include "hub/knob_set_buttons.hh"
#include "hub/knob_set_menu.hh"
#include "hub/text_field.hh"
#include "hub_knob.hh"
#include "hub_midi.hh"
#include "hub_module.hh"
#include "mapping/ModuleID.h"
#include "mapping/map_palette.hh"
#include "mapping/module_directory.hh"
#include "mapping/patch_writer.hh"
#include "util/math.hh"
#include "util/string_util.hh"
#include <functional>
#include <string>

namespace MetaModule
{

struct MetaModuleHubWidget : rack::app::ModuleWidget {
MetaModuleHubWidget() = default;

MetaModuleHubBase *hubModule;

rack::Label *statusText;
KnobSetButtonGroup *knobSetButtons;
MetaModule::TextField *knobSetNameField;
TextField *knobSetNameField;

static constexpr float kKnobSpacingY = 17;
static constexpr float kKnobSpacingX = 18;
Expand Down Expand Up @@ -102,3 +96,5 @@ struct MetaModuleHubWidget : rack::app::ModuleWidget {
knobSetButtons->active_idx = activeKnobSetIdx;
}
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/hub/knob_set_menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "hub/hub_module.hh"
#include <rack.hpp>

namespace MetaModule
{

struct KnobSetNameTextBox : rack::ui::TextField {
using CallbackT = std::function<void(unsigned, std::string const &)>;
CallbackT onChangeCallback;
Expand Down Expand Up @@ -48,3 +51,5 @@ struct KnobSetNameMenuItem : rack::widget::Widget {
Widget::draw(args);
}
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/mapping/knob_alias_menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "hub/hub_module.hh"
#include <rack.hpp>

namespace MetaModule
{

struct KnobAliasTextBox : rack::ui::TextField {
MappableObj src;
MetaModuleHubBase *hub;
Expand Down Expand Up @@ -39,3 +42,5 @@ struct KnobAliasMenuItem : rack::widget::Widget {
Widget::draw(args);
}
};

} // namespace MetaModule
12 changes: 8 additions & 4 deletions src/mapping/patch_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "mapping/midi_modules.hh"
#include "mapping/module_directory.hh"
#include "patch-serial/patch_to_yaml.hh"
#include "patch-serial/ryml/ryml_serial.hh"
#include <algorithm>

namespace MetaModule
{

PatchFileWriter::PatchFileWriter(std::vector<BrandModule> modules, int64_t hubModuleId)
: hubModuleId{hubModuleId} {
setModuleList(modules);
Expand All @@ -24,7 +26,7 @@ void PatchFileWriter::setPatchDesc(std::string patchDesc) {
pd.description = patchDesc.c_str();
}

void PatchFileWriter::setMidiSettings(MetaModule::MIDI::ModuleIds &ids, MetaModule::MIDI::Settings const &settings) {
void PatchFileWriter::setMidiSettings(MIDI::ModuleIds &ids, MIDI::Settings const &settings) {
midiModuleIds = ids;
midiSettings = settings;

Expand Down Expand Up @@ -298,7 +300,7 @@ void PatchFileWriter::mapMidiCVPolySplitJack(CableMap &cable, unsigned monoJackI
}

void PatchFileWriter::mapMidiCVJack(CableMap &cable) {
using enum MetaModule::MIDI::CoreMidiJacks;
using enum MIDI::CoreMidiJacks;

if (cable.sendingJackId == VoctJack)
cable.sendingJackId = MidiMonoNoteJack;
Expand Down Expand Up @@ -373,6 +375,8 @@ std::map<int64_t, uint16_t> PatchFileWriter::squash_ids(std::vector<int64_t> ids
return s;
}

MetaModule::PatchData &PatchFileWriter::get_data() {
PatchData &PatchFileWriter::get_data() {
return pd;
}

} // namespace MetaModule
19 changes: 11 additions & 8 deletions src/mapping/patch_writer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
#include "JackMap.hh"
#include "ModuleID.h"
#include "ParamMap.hh"
#include "jansson.h"
#include "mapping/mapping.hh"
#include "mapping/midi_modules.hh"
#include "patch-serial/patch_to_yaml.hh"
#include "patch/patch.hh"
#include "patch/patch_data.hh"
#include <map>
#include <rack.hpp>
#include <span>
#include <vector>

namespace MetaModule
{

class PatchFileWriter {
public:
PatchFileWriter(std::vector<BrandModule> modules, int64_t hubModuleId);
Expand All @@ -21,15 +22,15 @@ public:
void setPatchDesc(std::string patchDesc);
void setCableList(std::vector<CableMap> &cables);
void setParamList(std::vector<ParamMap> &params);
void setMidiSettings(MetaModule::MIDI::ModuleIds &ids, MetaModule::MIDI::Settings const &settings);
void setMidiSettings(MIDI::ModuleIds &ids, MIDI::Settings const &settings);
void addModuleStateJson(rack::Module *module);

void addKnobMaps(unsigned panelKnobId, unsigned knobSetId, const std::span<const Mapping> maps);
void addKnobMapSet(unsigned knobSetId, std::string_view knobSetName);

std::string printPatchYAML();

MetaModule::PatchData &get_data();
PatchData &get_data();
static std::map<int64_t, uint16_t> squash_ids(std::vector<int64_t> ids);

private:
Expand All @@ -43,11 +44,13 @@ private:

void setModuleList(std::vector<BrandModule> &modules);

MetaModule::PatchData pd;
PatchData pd;
int64_t hubModuleId = -1;

MetaModule::MIDI::ModuleIds midiModuleIds;
MetaModule::MIDI::Settings midiSettings;
MIDI::ModuleIds midiModuleIds;
MIDI::Settings midiSettings;

std::map<int64_t, uint16_t> idMap; // idMap[64 bit VCV module id] -> 16 bit MM-patch module id
};

} // namespace MetaModule
5 changes: 5 additions & 0 deletions src/mapping/range_slider.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "hub/hub_module.hh"
#include <rack.hpp>

namespace MetaModule
{

enum class RangePart { Min, Max };

template<RangePart MINMAX>
Expand Down Expand Up @@ -57,3 +60,5 @@ public:
delete quantity;
}
};

} // namespace MetaModule
Loading

0 comments on commit a39a758

Please sign in to comment.