From 92c70a380013da7e4c3f5a0ce1eaca6a96334250 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 11 Dec 2019 18:23:11 +0000 Subject: [PATCH] API cleanup with latest changes, test cv changes with LV2 Signed-off-by: falkTX --- source/backend/CarlaEngine.hpp | 4 +- source/backend/engine/CarlaEngineInternal.hpp | 28 +------- source/backend/engine/CarlaEnginePorts.cpp | 57 +++++++++++---- .../backend/plugin/CarlaPluginLADSPADSSI.cpp | 2 +- source/backend/plugin/CarlaPluginLV2.cpp | 70 +++++++++++++++++-- 5 files changed, 116 insertions(+), 45 deletions(-) diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index 68d93780c..29d9443a5 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -553,12 +553,12 @@ public: /*! * Add a CV port as a source of events. */ - void addCVSource(CarlaEngineCVPort* port) noexcept; + void addCVSource(CarlaEngineCVPort* port, uint32_t portIndexOffset) noexcept; /*! * Remove a CV port as a source of events. */ - void removeCVSource(CarlaEngineCVPort* port) noexcept; + void removeCVSource(uint32_t portIndexOffset) noexcept; /*! * Remove a CV port as a source of events. diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 90f7a4286..c5a14972e 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -214,8 +214,8 @@ struct EnginePluginData { struct CarlaEngineEventCV { CarlaEngineCVPort* cvPort; - float previousValue; uint32_t indexOffset; + float previousValue; }; struct CarlaEngineEventPort::ProtectedData { @@ -223,30 +223,8 @@ struct CarlaEngineEventPort::ProtectedData { const EngineProcessMode processMode; LinkedList cvs; - ProtectedData(const EngineProcessMode pm) noexcept - : buffer(nullptr), - processMode(pm), - cvs() - { - if (processMode == ENGINE_PROCESS_MODE_PATCHBAY) - { - buffer = new EngineEvent[kMaxEngineEventInternalCount]; - carla_zeroStructs(buffer, kMaxEngineEventInternalCount); - } - } - - ~ProtectedData() noexcept - { - cvs.clear(); - - if (processMode == ENGINE_PROCESS_MODE_PATCHBAY) - { - CARLA_SAFE_ASSERT_RETURN(buffer != nullptr,); - - delete[] buffer; - buffer = nullptr; - } - } + ProtectedData(const EngineProcessMode pm) noexcept; + ~ProtectedData() noexcept; CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData) }; diff --git a/source/backend/engine/CarlaEnginePorts.cpp b/source/backend/engine/CarlaEnginePorts.cpp index 210e8f5a6..4995c85ad 100644 --- a/source/backend/engine/CarlaEnginePorts.cpp +++ b/source/backend/engine/CarlaEnginePorts.cpp @@ -28,6 +28,7 @@ CARLA_BACKEND_START_NAMESPACE // Fallback data static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, {{ kEngineControlEventTypeNull, 0, 0.0f }} }; +static CarlaEngineEventCV kFallbackEngineEventCV = { nullptr, (uint32_t)-1, 0.0f }; // ----------------------------------------------------------------------- // Carla Engine port (Abstract) @@ -112,6 +113,34 @@ void CarlaEngineCVPort::setRange(const float min, const float max) noexcept // ----------------------------------------------------------------------- // Carla Engine Event port +CarlaEngineEventPort::ProtectedData::ProtectedData(const EngineProcessMode pm) noexcept + : buffer(nullptr), + processMode(pm), + cvs() +{ + if (processMode == ENGINE_PROCESS_MODE_PATCHBAY) + { + buffer = new EngineEvent[kMaxEngineEventInternalCount]; + carla_zeroStructs(buffer, kMaxEngineEventInternalCount); + } +} + +CarlaEngineEventPort::ProtectedData::~ProtectedData() noexcept +{ + for (LinkedList::Itenerator it = cvs.begin2(); it.valid(); it.next()) + delete it.getValue(kFallbackEngineEventCV).cvPort; + + cvs.clear(); + + if (processMode == ENGINE_PROCESS_MODE_PATCHBAY) + { + CARLA_SAFE_ASSERT_RETURN(buffer != nullptr,); + + delete[] buffer; + buffer = nullptr; + } +} + CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngineClient& client, const bool isInputPort, const uint32_t indexOffset) noexcept : CarlaEnginePort(client, isInputPort, indexOffset), pData(new ProtectedData(client.getEngine().getProccessMode())) @@ -125,27 +154,31 @@ CarlaEngineEventPort::~CarlaEngineEventPort() noexcept delete pData; } -void CarlaEngineEventPort::addCVSource(CarlaEngineCVPort* const port) noexcept +void CarlaEngineEventPort::addCVSource(CarlaEngineCVPort* const port, const uint32_t portIndexOffset) noexcept { CARLA_SAFE_ASSERT_RETURN(port != nullptr,); CARLA_SAFE_ASSERT_RETURN(port->isInput(),); carla_debug("CarlaEngineEventPort::addCVSource(%p)", port); - const CarlaEngineEventCV ecv { port, 0.0f, port->getIndexOffset() }; + const CarlaEngineEventCV ecv { port, portIndexOffset, 0.0f }; pData->cvs.append(ecv); } -void CarlaEngineEventPort::removeCVSource(CarlaEngineCVPort* const port) noexcept +void CarlaEngineEventPort::removeCVSource(const uint32_t portIndexOffset) noexcept { - carla_debug("CarlaEngineEventPort::removeCVSource(%p)", port); + carla_debug("CarlaEngineEventPort::removeCVSource(%u)", portIndexOffset); - // pData->cvPorts.removeOne(port); - // TODO - return; - (void)port; -} + for (LinkedList::Itenerator it = pData->cvs.begin2(); it.valid(); it.next()) + { + CarlaEngineEventCV& ecv(it.getValue(kFallbackEngineEventCV)); -static CarlaEngineEventCV kFallbackEngineEventCV = { nullptr, 0.0f, (uint32_t)-1 }; + if (ecv.indexOffset == portIndexOffset) + { + pData->cvs.remove(it); + break; + } + } +} void CarlaEngineEventPort::mixWithCvBuffer(const float* const buffer, const uint32_t frames, @@ -177,7 +210,7 @@ void CarlaEngineEventPort::mixWithCvBuffer(const float* const buffer, float previousValue = ecv.previousValue; ecv.cvPort->getRange(min, max); - for (uint32_t i=0; ibuffer[i++]); + EngineEvent& event(pData->buffer[eventIndex++]); event.type = kEngineEventTypeControl; event.time = i; diff --git a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp index cc3921bef..e8f0395b4 100644 --- a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp +++ b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp @@ -1239,7 +1239,7 @@ public: CarlaEngineCVPort* const cvPort = (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, portName, true, i); cvPort->setRange(pData->param.ranges[i].min, pData->param.ranges[i].max); - pData->event.portIn->addCVSource(cvPort); + pData->event.portIn->addCVSource(cvPort, i); } } diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index cd018f6f1..c64ef52ff 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -2798,6 +2798,30 @@ public: portName.truncate(portNameSize); pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, 0); + + for (uint32_t i=0; i < params; ++i) + { + const int32_t rindex = pData->param.data[i].rindex; + CARLA_SAFE_ASSERT_CONTINUE(rindex >= 0 && rindex < static_cast(fRdfDescriptor->PortCount)); + + if (pData->param.data[i].type != PARAMETER_INPUT) + continue; + if (fRdfDescriptor->Ports[rindex].Name == nullptr || fRdfDescriptor->Ports[rindex].Name[0] == '\0') + continue; + + portName = fRdfDescriptor->Ports[rindex].Name; + portName.truncate(portNameSize); + + // Parameter as CV + CarlaEngineCVPort* const cvPort = + (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, portName, true, i); + + if (true) + cvPort->setRange(0.0f, 3.0f + (float)i); + else + cvPort->setRange(pData->param.ranges[i].min, pData->param.ranges[i].max); + pData->event.portIn->addCVSource(cvPort, i); + } } if (needsCtrlOut) @@ -2844,7 +2868,7 @@ public: if (char* const midnam = fExt.midnam->midnam(fHandle)) { fEventsIn.ctrl->port->setMetaData("http://www.midi.org/dtds/MIDINameDocument10.dtd", - midnam, "text/xml"); + midnam, "text/xml"); if (fExt.midnam->free != nullptr) fExt.midnam->free(midnam); } @@ -3497,6 +3521,19 @@ public: } // End of MIDI Input (External) + // ---------------------------------------------------------------------------------------------------- + // CV Control Input + + for (uint32_t i=0, j=0; i < pData->param.count; ++i) + { + if (pData->param.data[i].type != PARAMETER_INPUT) + continue; + + const uint32_t cvIndex = j++; + + pData->event.portIn->mixWithCvBuffer(cvIn[pData->cvIn.count + cvIndex], frames, i); + } + // ---------------------------------------------------------------------------------------------------- // Event Input (System) @@ -3598,12 +3635,37 @@ public: break; case kEngineControlEventTypeParameter: { + float value; + #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH + // via CV + if (event.channel == 0xFF) + { + const uint32_t k = ctrlEvent.param; + CARLA_SAFE_ASSERT_CONTINUE(k < pData->param.count); + + if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN) + { + value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max; + } + else + { + if (pData->param.data[k].hints & PARAMETER_IS_LOGARITHMIC) + value = pData->param.ranges[k].getUnnormalizedLogValue(ctrlEvent.value); + else + value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); + + if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) + value = std::rint(value); + } + + setParameterValueRT(k, value, true); + continue; + } + // Control backend stuff if (event.channel == pData->ctrlChannel) { - float value; - if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0) { value = ctrlEvent.value; @@ -3655,8 +3717,6 @@ public: if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0) continue; - float value; - if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN) { value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;