diff --git a/plugins/Cardinal/plugin.json b/plugins/Cardinal/plugin.json index d54bc1b..1ef3af9 100644 --- a/plugins/Cardinal/plugin.json +++ b/plugins/Cardinal/plugin.json @@ -77,10 +77,10 @@ ] }, { - "slug": "IldaeilExpIn8", + "slug": "CardinalExpIn8", "disabled": false, - "name": "Ildaeil Expander Inputs 8", - "description": "Expander to add 8 parameters CV inputs to Ildaeil", + "name": "Cardinal Expander Inputs 8", + "description": "Expander to add 8 parameters CV inputs to Cardinal's plugin hosts", "tags": [ "Expander" ] diff --git a/plugins/Cardinal/res/IldaeilExpIn8.svg b/plugins/Cardinal/res/CardinalExpIn8.svg similarity index 100% rename from plugins/Cardinal/res/IldaeilExpIn8.svg rename to plugins/Cardinal/res/CardinalExpIn8.svg diff --git a/plugins/Cardinal/src/IldaeilExpIn8.cpp b/plugins/Cardinal/src/CardinalExpIn8.cpp similarity index 57% rename from plugins/Cardinal/src/IldaeilExpIn8.cpp rename to plugins/Cardinal/src/CardinalExpIn8.cpp index 9b8f1f0..3b855ff 100644 --- a/plugins/Cardinal/src/IldaeilExpIn8.cpp +++ b/plugins/Cardinal/src/CardinalExpIn8.cpp @@ -1,13 +1,25 @@ -//Expander module for Ildaeil +//Expander module for Cardinal's plugin hosts // //Based on code from GateSeq64 and GateSeq64Expander by Marc Boulé //Adapted for Ildaeil by Simon-L #include "plugin.hpp" +#include "expanders.hpp" static const unsigned int ildaeil_expanderRefreshStepSkips = 4; -struct IldaeilExpIn8 : Module { +struct CardinalExpIn8 : CardinalExpander, Module { + + void sendExpMessage() { + for (int i = 0; i < NUM_INPUTS; i++) { + float *messageToBase = (float*)rightExpander.module->leftExpander.producerMessage; + messageToBase[i] = (inputs[i].isConnected() ? inputs[i].getVoltage() : 0.0); + } + rightExpander.module->leftExpander.messageFlipRequested = true; + } + + void processExpMessage() {} + enum InputIds { PARAM1_INPUT, PARAM2_INPUT, @@ -20,12 +32,8 @@ struct IldaeilExpIn8 : Module { NUM_INPUTS }; - // Expander - float rightMessages[2][2] = {};// messages from Ildaeil - - unsigned int expanderRefreshCounter = 0; - IldaeilExpIn8() { + CardinalExpIn8() { config(0, NUM_INPUTS, 0, 0); rightExpander.producerMessage = rightMessages[0]; @@ -42,25 +50,20 @@ struct IldaeilExpIn8 : Module { } - void process(const ProcessArgs &args) override { - bool ildaeilPresent = (rightExpander.module && rightExpander.module->model == modelIldaeil); - if (ildaeilPresent) { - float *messagesToIldaeil = (float*)rightExpander.module->leftExpander.producerMessage; - for (int i = 0; i < NUM_INPUTS; i++) { - messagesToIldaeil[i] = (inputs[i].isConnected() ? inputs[i].getVoltage() : 0.0); - } - rightExpander.module->leftExpander.messageFlipRequested = true; + bool basePresent = (rightExpander.module && isCardinalExpandable(rightExpander.module)); + if (basePresent) { + sendExpMessage(); } }// process() }; -struct IldaeilExpIn8Widget : ModuleWidget { - IldaeilExpIn8Widget(IldaeilExpIn8 *module) { +struct CardinalExpIn8Widget : ModuleWidget { + CardinalExpIn8Widget(CardinalExpIn8 *module) { setModule(module); - setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/IldaeilExpIn8.svg"))); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/CardinalExpIn8.svg"))); box.size = Vec(RACK_GRID_WIDTH * 2, RACK_GRID_HEIGHT); // Screws @@ -70,16 +73,16 @@ struct IldaeilExpIn8Widget : ModuleWidget { addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); // Inputs - addInput(createInput(Vec(3, 54 + 75), module, IldaeilExpIn8::PARAM1_INPUT)); - addInput(createInput(Vec(3, 54 + 105), module, IldaeilExpIn8::PARAM2_INPUT)); - addInput(createInput(Vec(3, 54 + 135), module, IldaeilExpIn8::PARAM3_INPUT)); - addInput(createInput(Vec(3, 54 + 165), module, IldaeilExpIn8::PARAM4_INPUT)); - addInput(createInput(Vec(3, 54 + 195), module, IldaeilExpIn8::PARAM5_INPUT)); - addInput(createInput(Vec(3, 54 + 225), module, IldaeilExpIn8::PARAM6_INPUT)); - addInput(createInput(Vec(3, 54 + 255), module, IldaeilExpIn8::PARAM7_INPUT)); - addInput(createInput(Vec(3, 54 + 285), module, IldaeilExpIn8::PARAM8_INPUT)); + addInput(createInput(Vec(3, 54 + 75), module, CardinalExpIn8::PARAM1_INPUT)); + addInput(createInput(Vec(3, 54 + 105), module, CardinalExpIn8::PARAM2_INPUT)); + addInput(createInput(Vec(3, 54 + 135), module, CardinalExpIn8::PARAM3_INPUT)); + addInput(createInput(Vec(3, 54 + 165), module, CardinalExpIn8::PARAM4_INPUT)); + addInput(createInput(Vec(3, 54 + 195), module, CardinalExpIn8::PARAM5_INPUT)); + addInput(createInput(Vec(3, 54 + 225), module, CardinalExpIn8::PARAM6_INPUT)); + addInput(createInput(Vec(3, 54 + 255), module, CardinalExpIn8::PARAM7_INPUT)); + addInput(createInput(Vec(3, 54 + 285), module, CardinalExpIn8::PARAM8_INPUT)); } }; -Model *modelIldaeilExpIn8 = createModel("IldaeilExpIn8"); +Model *modelCardinalExpIn8 = createModel("CardinalExpIn8"); diff --git a/plugins/Cardinal/src/Carla.cpp b/plugins/Cardinal/src/Carla.cpp index 33b034b..abd0c20 100644 --- a/plugins/Cardinal/src/Carla.cpp +++ b/plugins/Cardinal/src/Carla.cpp @@ -16,6 +16,7 @@ */ #include "plugincontext.hpp" +#include "expanders.hpp" #include "CarlaNativePlugin.h" #include "CarlaBackendUtils.hpp" @@ -54,7 +55,7 @@ static intptr_t host_dispatcher(NativeHostHandle handle, NativeHostDispatcherOpc // -------------------------------------------------------------------------------------------------------------------- -struct CarlaModule : Module { +struct CarlaModule : Module, CardinalExpander { enum ParamIds { BIPOLAR_INPUTS, BIPOLAR_OUTPUTS, @@ -123,6 +124,8 @@ struct CarlaModule : Module { std::memset(dataOut, 0, sizeof(dataOut)); + setupExpanding(this); + fCarlaPluginDescriptor = carla_get_native_patchbay_cv8_plugin(); DISTRHO_SAFE_ASSERT_RETURN(fCarlaPluginDescriptor != nullptr,); @@ -259,11 +262,34 @@ struct CarlaModule : Module { patchStorage = getPatchStorageDirectory(); } + void sendExpMessage() {} + + void processExpMessage() { + // Unimplemented + float *messagesFromExpander = (float*)leftExpander.consumerMessage; + if (carla_get_current_plugin_count(fCarlaHostHandle)) { + const uint32_t pcount = carla_get_parameter_count(fCarlaHostHandle, 0); + for (uint i = 0; i < 8; i++) { + if (i < pcount && leftExpander.module->inputs[i].isConnected()) { + const ::ParameterRanges* const pranges = carla_get_parameter_ranges(fCarlaHostHandle, 0, i); + float scaled_param = (messagesFromExpander[i] + 10.0) * (pranges->max - pranges->min) / (20.0 + pranges->min); + carla_set_parameter_value(fCarlaHostHandle, 0, i, scaled_param); + fCarlaHostDescriptor.ui_parameter_changed(this, i, scaled_param); + } + } + } + } + void process(const ProcessArgs& args) override { if (fCarlaPluginHandle == nullptr) return; + bool expanderPresent = (leftExpander.module && isCardinalExpander(leftExpander.module)); + if (expanderPresent) { + processExpMessage(); + } + const float inputOffset = params[BIPOLAR_INPUTS].getValue() > 0.1f ? -5.0f : 0.0f; const float outputOffset = params[BIPOLAR_OUTPUTS].getValue() > 0.1f ? -5.0f : 0.0f; diff --git a/plugins/Cardinal/src/Ildaeil.cpp b/plugins/Cardinal/src/Ildaeil.cpp index a6cf4c4..e75c205 100644 --- a/plugins/Cardinal/src/Ildaeil.cpp +++ b/plugins/Cardinal/src/Ildaeil.cpp @@ -26,6 +26,7 @@ */ #include "plugincontext.hpp" +#include "expanders.hpp" #ifndef HEADLESS # include "ImGuiWidget.hpp" @@ -220,7 +221,7 @@ struct JuceInitializer { }; #endif -struct IldaeilModule : Module { +struct IldaeilModule : CardinalExpander, Module { enum ParamIds { NUM_PARAMS }; @@ -244,8 +245,22 @@ struct IldaeilModule : Module { NUM_LIGHTS }; - // Expander - float leftMessages[2][8] = {};// messages from expander + void sendExpMessage() {} + + void processExpMessage() { + float *messagesFromExpander = (float*)leftExpander.consumerMessage; + if (carla_get_current_plugin_count(fCarlaHostHandle)) { + const uint32_t pcount = carla_get_parameter_count(fCarlaHostHandle, 0); + for (uint i = 0; i < 8; i++) { + if (i < pcount && leftExpander.module->inputs[i].isConnected()) { + const ::ParameterRanges* const pranges = carla_get_parameter_ranges(fCarlaHostHandle, 0, i); + float scaled_param = (messagesFromExpander[i] + 10.0) * (pranges->max - pranges->min) / (20.0 + pranges->min); + carla_set_parameter_value(fCarlaHostHandle, 0, i, scaled_param); + fCarlaHostDescriptor.ui_parameter_changed(this, i, scaled_param); + } + } + } + } #ifndef HEADLESS SharedResourcePointer juceInitializer; @@ -277,14 +292,6 @@ struct IldaeilModule : Module { { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); - leftExpander.producerMessage = leftMessages[0]; - leftExpander.consumerMessage = leftMessages[1]; - - for (uint i = 0; i < 8; ++i) - { - leftMessages[1][i] = 0.0; - } - for (uint i=0; i<2; ++i) { const char name[] = { 'A','u','d','i','o',' ','#',static_cast('0'+i+1),'\0' }; @@ -301,6 +308,8 @@ struct IldaeilModule : Module { std::memset(audioDataOut1, 0, sizeof(audioDataOut1)); std::memset(audioDataOut2, 0, sizeof(audioDataOut2)); + setupExpanding(this); + fCarlaPluginDescriptor = carla_get_native_rack_plugin(); DISTRHO_SAFE_ASSERT_RETURN(fCarlaPluginDescriptor != nullptr,); @@ -444,18 +453,10 @@ struct IldaeilModule : Module { if (fCarlaPluginHandle == nullptr) return; - bool expanderPresent = (leftExpander.module && leftExpander.module->model == modelIldaeilExpIn8); - float *messagesFromExpander = (float*)leftExpander.consumerMessage;// could be invalid pointer when !expanderPresent, so read it only when expanderPresent + bool expanderPresent = (leftExpander.module && isCardinalExpander(leftExpander.module)); if (expanderPresent) { - const uint32_t pcount = carla_get_parameter_count(fCarlaHostHandle, 0); - for (uint i = 0; i < 8; i++) { - if (i < pcount && leftExpander.module->inputs[i].isConnected()) { - const ::ParameterRanges* const pranges = carla_get_parameter_ranges(fCarlaHostHandle, 0, i); - float scaled_param = (messagesFromExpander[i] + 10.0) * (pranges->max - pranges->min) / (20.0 + pranges->min); - carla_set_parameter_value(fCarlaHostHandle, 0, i, scaled_param); - fCarlaHostDescriptor.ui_parameter_changed(this, i, scaled_param); - } - } + // d_stdout("hm?"); + processExpMessage(); } const unsigned i = audioDataFill++; @@ -1395,7 +1396,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { } else { - bool expanderPresent = (module->leftExpander.module && module->leftExpander.module->model == modelIldaeilExpIn8); + bool expanderPresent = (module->leftExpander.module && module->isCardinalExpander(module->leftExpander.module)); const bool disabled = expanderPresent && (i < 8) && (module->leftExpander.module->inputs[i].isConnected()); if (disabled) ImGui::BeginDisabled(); diff --git a/plugins/Cardinal/src/expanders.hpp b/plugins/Cardinal/src/expanders.hpp new file mode 100644 index 0000000..f203aad --- /dev/null +++ b/plugins/Cardinal/src/expanders.hpp @@ -0,0 +1,21 @@ + +struct CardinalExpander +{ + CardinalExpander(){ + }; + ~CardinalExpander(){}; + + bool isCardinalExpandable(Module *x) { return x->model == modelIldaeil || x->model == modelCarla; }; + bool isCardinalExpander(Module *x) { return x->model == modelCardinalExpIn8; }; + + virtual void sendExpMessage() = 0; + virtual void processExpMessage() = 0; + + float rightMessages[2][8] = {}; // messages from right-side + float leftMessages[2][8] = {};// messages from left-side + + void setupExpanding(Module *module) { + module->leftExpander.producerMessage = leftMessages[0]; + module->leftExpander.consumerMessage = leftMessages[1]; + } +}; \ No newline at end of file diff --git a/plugins/Cardinal/src/plugin.hpp b/plugins/Cardinal/src/plugin.hpp index f75db6b..de7e886 100644 --- a/plugins/Cardinal/src/plugin.hpp +++ b/plugins/Cardinal/src/plugin.hpp @@ -34,4 +34,4 @@ extern Model* modelHostCV; extern Model* modelHostParameters; extern Model* modelHostTime; extern Model* modelIldaeil; -extern Model* modelIldaeilExpIn8; +extern Model* modelCardinalExpIn8; diff --git a/plugins/Makefile b/plugins/Makefile index 8a6b3cd..97dcefd 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -186,7 +186,7 @@ PLUGIN_FILES += Cardinal/src/HostCV.cpp PLUGIN_FILES += Cardinal/src/HostParameters.cpp PLUGIN_FILES += Cardinal/src/HostTime.cpp PLUGIN_FILES += Cardinal/src/Ildaeil.cpp -PLUGIN_FILES += Cardinal/src/IldaeilExpIn8.cpp +PLUGIN_FILES += Cardinal/src/CardinalExpIn8.cpp ifneq ($(HEADLESS),true) PLUGIN_FILES += Cardinal/src/ImGuiWidget.cpp diff --git a/plugins/plugins.cpp b/plugins/plugins.cpp index 1531dc6..0e43812 100644 --- a/plugins/plugins.cpp +++ b/plugins/plugins.cpp @@ -647,7 +647,7 @@ static void initStatic__Cardinal() p->addModel(modelHostParameters); p->addModel(modelHostTime); p->addModel(modelIldaeil); - p->addModel(modelIldaeilExpIn8); + p->addModel(modelCardinalExpIn8); } }