Skip to content

Commit

Permalink
Refactored expander roles to be more generic.
Browse files Browse the repository at this point in the history
I realized I can use a single "roles" concept to cover multiple
distinct sender/receiver pairs for expander functionality.
Renamed VectorRole to ExpanderRole.
Reworked determination of roles to be more generic for
a new pair of ChaosOperator roles.
  • Loading branch information
cosinekitty committed Nov 25, 2024
1 parent ef2496d commit 390012b
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/chaops_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ namespace Sapphire

Model* modelSapphireChaops = createSapphireModel<Sapphire::ChaosOperators::ChaopsModule, Sapphire::ChaosOperators::ChaopsWidget>(
"Chaops",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/elastika_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,5 @@ namespace Sapphire

Model* modelSapphireElastika = createSapphireModel<Sapphire::Elastika::ElastikaModule, Sapphire::Elastika::ElastikaWidget>(
"Elastika",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/frolic_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ namespace Sapphire

Model* modelSapphireFrolic = createSapphireModel<Sapphire::FrolicModule, Sapphire::FrolicWidget>(
"Frolic",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/galaxy_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ namespace Sapphire

Model *modelSapphireGalaxy = createSapphireModel<Sapphire::Galaxy::GalaxyModule, Sapphire::Galaxy::GalaxyWidget>(
"Galaxy",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/glee_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ namespace Sapphire

Model* modelSapphireGlee = createSapphireModel<Sapphire::GleeModule, Sapphire::GleeWidget>(
"Glee",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/gravy_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,5 @@ namespace Sapphire

Model *modelSapphireGravy = createSapphireModel<Sapphire::Gravy::GravyModule, Sapphire::Gravy::GravyWidget>(
"Gravy",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/hiss_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ namespace Sapphire

Model* modelSapphireHiss = createSapphireModel<Sapphire::Hiss::HissModule, Sapphire::Hiss::HissWidget>(
"Hiss",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/lark_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ namespace Sapphire

Model* modelSapphireLark = createSapphireModel<Sapphire::LarkModule, Sapphire::LarkWidget>(
"Lark",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/moots_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,5 @@ namespace Sapphire

Model* modelSapphireMoots = createSapphireModel<Sapphire::Moots::MootsModule, Sapphire::Moots::MootsWidget>(
"Moots",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/nucleus_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,5 @@ namespace Sapphire

Model* modelSapphireNucleus = createSapphireModel<Sapphire::Nucleus::NucleusModule, Sapphire::Nucleus::NucleusWidget>(
"Nucleus",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/pivot_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ namespace Sapphire

Model* modelSapphirePivot = createSapphireModel<Sapphire::Pivot::PivotModule, Sapphire::Pivot::PivotWidget>(
"Pivot",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/polynucleus_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,5 +696,5 @@ namespace Sapphire

Model* modelSapphirePolynucleus = createSapphireModel<Sapphire::Polynucleus::PolynucleusModule, Sapphire::Polynucleus::PolynucleusWidget>(
"Polynucleus",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/pop_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,5 @@ namespace Sapphire

Model* modelSapphirePop = createSapphireModel<Sapphire::Pop::PopModule, Sapphire::Pop::PopWidget>(
"Pop",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/rotini_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ namespace Sapphire

Model* modelSapphireRotini = createSapphireModel<Sapphire::Rotini::RotiniModule, Sapphire::Rotini::RotiniWidget>(
"Rotini",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/sam_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ namespace Sapphire

Model* modelSapphireSam = createSapphireModel<Sapphire::SplitAddMerge::SplitAddMergeModule, Sapphire::SplitAddMerge::SplitAddMergeWidget>(
"SplitAddMerge",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
53 changes: 29 additions & 24 deletions src/sapphire_vcvrack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,41 @@
#include "plugin.hpp"
namespace Sapphire
{
enum class VectorRole
enum class ExpanderRole
{
None,
Sender,
Receiver,
SenderAndReceiver,
None = 0,
VectorSender = 0x01,
VectorReceiver = 0x02,
ChaosOpSender = 0x04, // Chaops
ChaosOpReceiver = 0x08, // Frolic, Glee, Lark
};

inline constexpr ExpanderRole Both(ExpanderRole a, ExpanderRole b)
{
return static_cast<ExpanderRole>(static_cast<int>(a) | static_cast<int>(b));
}

const ExpanderRole VectorSenderAndReceiver = Both(
Sapphire::ExpanderRole::VectorSender,
Sapphire::ExpanderRole::VectorReceiver
);

struct ModelInfo
{
static ModelInfo *front;
ModelInfo *next = nullptr;
rack::plugin::Model* model;
VectorRole vectorRole;
ExpanderRole roles;

ModelInfo(rack::plugin::Model* _model, VectorRole _vectorRole)
ModelInfo(rack::plugin::Model* _model, ExpanderRole _roles)
: model(_model)
, vectorRole(_vectorRole)
, roles(_roles)
{
}

static void insert(Model *_model, VectorRole _vectorRole)
static void insert(Model *_model, ExpanderRole _roles)
{
ModelInfo *info = new ModelInfo(_model, _vectorRole);
ModelInfo *info = new ModelInfo(_model, _roles);
info->next = front;
front = info;
}
Expand All @@ -42,22 +53,16 @@ namespace Sapphire
return nullptr;
}

static bool canReceiveVectors(const Model* model)
static bool hasRole(const Module* module, ExpanderRole role)
{
ModelInfo* info = search(model);
if (info == nullptr)
if (module == nullptr)
return false;

return (info->vectorRole == VectorRole::Receiver) || (info->vectorRole == VectorRole::SenderAndReceiver);
}

static bool canSendVectors(const Model* model)
{
ModelInfo* info = search(model);
ModelInfo* info = search(module->model);
if (info == nullptr)
return false;

return (info->vectorRole == VectorRole::Sender) || (info->vectorRole == VectorRole::SenderAndReceiver);
return 0 != (static_cast<int>(info->roles) & static_cast<int>(role));
}
};

Expand Down Expand Up @@ -127,7 +132,7 @@ namespace Sapphire

static bool isVectorReceiver(const Module* module)
{
return (module != nullptr) && ModelInfo::canReceiveVectors(module->model);
return ModelInfo::hasRole(module, ExpanderRole::VectorReceiver);
}

explicit VectorSender(Module& module)
Expand Down Expand Up @@ -158,7 +163,7 @@ namespace Sapphire

static bool isVectorSender(const Module* module)
{
return (module != nullptr) && ModelInfo::canSendVectors(module->model);
return ModelInfo::hasRole(module, ExpanderRole::VectorSender);
}

explicit VectorReceiver(Module& module)
Expand Down Expand Up @@ -1057,9 +1062,9 @@ namespace Sapphire
template <class TModule, class TModuleWidget>
rack::plugin::Model* createSapphireModel(
std::string slug,
Sapphire::VectorRole vectorRole)
Sapphire::ExpanderRole roles)
{
Model *model = rack::createModel<TModule, TModuleWidget>(slug);
Sapphire::ModelInfo::insert(model, vectorRole);
Sapphire::ModelInfo::insert(model, roles);
return model;
}
2 changes: 1 addition & 1 deletion src/sauce_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,5 @@ namespace Sapphire

Model *modelSapphireSauce = createSapphireModel<Sapphire::Sauce::SauceModule, Sapphire::Sauce::SauceWidget>(
"Sauce",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);
2 changes: 1 addition & 1 deletion src/tin_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ namespace Sapphire

Model* modelSapphireTin = createSapphireModel<Sapphire::TricorderInput::TinModule, Sapphire::TricorderInput::TinWidget>(
"Tin",
Sapphire::VectorRole::Sender
Sapphire::ExpanderRole::VectorSender
);
2 changes: 1 addition & 1 deletion src/tout_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ namespace Sapphire

Model* modelSapphireTout = createSapphireModel<Sapphire::TricorderOutput::ToutModule, Sapphire::TricorderOutput::ToutWidget>(
"Tout",
Sapphire::VectorRole::SenderAndReceiver
Sapphire::VectorSenderAndReceiver
);
2 changes: 1 addition & 1 deletion src/tricorder_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,5 +1739,5 @@ namespace Sapphire

Model *modelSapphireTricorder = createSapphireModel<Sapphire::Tricorder::TricorderModule, Sapphire::Tricorder::TricorderWidget>(
"Tricorder",
Sapphire::VectorRole::SenderAndReceiver
Sapphire::VectorSenderAndReceiver
);
2 changes: 1 addition & 1 deletion src/tubeunit_vcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,5 +519,5 @@ namespace Sapphire

Model* modelSapphireTubeUnit = createSapphireModel<Sapphire::TubeUnit::TubeUnitModule, Sapphire::TubeUnit::TubeUnitWidget>(
"TubeUnit",
Sapphire::VectorRole::None
Sapphire::ExpanderRole::None
);

0 comments on commit 390012b

Please sign in to comment.