Regen patches

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-12-30 16:06:52 +00:00
parent 476bae222f
commit 4ab933a073
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
12 changed files with 603 additions and 517 deletions

View file

@ -1,5 +1,5 @@
--- ../Rack/src/engine/Engine.cpp 2022-09-21 20:25:53.592040301 +0100
+++ Engine.cpp 2022-11-29 19:49:19.196926572 +0000
--- ../Rack/src/engine/Engine.cpp 2022-09-21 19:49:12.200540736 +0100
+++ Engine.cpp 2022-12-29 16:15:36.061769776 +0000
@@ -1,3 +1,30 @@
+/*
+ * DISTRHO Cardinal Plugin
@ -31,7 +31,7 @@
#include <algorithm>
#include <set>
#include <thread>
@@ -6,183 +33,38 @@
@@ -6,183 +33,39 @@
#include <atomic>
#include <tuple>
#include <pmmintrin.h>
@ -98,6 +98,7 @@
- });
- }
-};
+#include "../CardinalRemote.hpp"
+#include "DistrhoUtils.hpp"
@ -227,7 +228,7 @@
// moduleId
std::map<int64_t, Module*> modulesCache;
@@ -198,7 +80,9 @@
@@ -198,7 +81,9 @@
int64_t blockFrame = 0;
double blockTime = 0.0;
int blockFrames = 0;
@ -237,7 +238,7 @@
// Meter
int meterCount = 0;
double meterTotal = 0.0;
@@ -206,6 +90,7 @@
@@ -206,33 +91,21 @@
double meterLastTime = -INFINITY;
double meterLastAverage = 0.0;
double meterLastMax = 0.0;
@ -245,7 +246,14 @@
// Parameter smoothing
Module* smoothModule = NULL;
@@ -217,22 +102,6 @@
int smoothParamId = 0;
float smoothValue = 0.f;
+ // Remote control
+ remoteUtils::RemoteDetails* remoteDetails = nullptr;
+
/** Mutex that guards the Engine state, such as settings, Modules, and Cables.
Writers lock when mutating the engine's state or stepping the block.
Readers lock when using the engine's state.
*/
SharedMutex mutex;
@ -268,7 +276,7 @@
};
@@ -260,76 +129,11 @@
@@ -260,76 +133,11 @@
}
@ -346,7 +354,7 @@
// Copy all voltages from output to input
for (int c = 0; c < channels; c++) {
float v = output->voltages[c];
@@ -346,6 +150,53 @@
@@ -346,6 +154,53 @@
}
@ -400,7 +408,28 @@
/** Steps a single frame
*/
static void Engine_stepFrame(Engine* that) {
@@ -372,13 +223,8 @@
@@ -358,10 +213,16 @@
float smoothValue = internal->smoothValue;
Param* smoothParam = &smoothModule->params[smoothParamId];
float value = smoothParam->value;
- // Use decay rate of roughly 1 graphics frame
- const float smoothLambda = 60.f;
- float newValue = value + (smoothValue - value) * smoothLambda * internal->sampleTime;
- if (value == newValue) {
+ float newValue;
+ if (internal->remoteDetails != nullptr) {
+ newValue = value;
+ sendParamChangeToRemote(internal->remoteDetails, smoothModule->id, smoothParamId, value);
+ } else {
+ // Use decay rate of roughly 1 graphics frame
+ const float smoothLambda = 60.f;
+ newValue = value + (smoothValue - value) * smoothLambda * internal->sampleTime;
+ }
+ if (d_isEqual(value, newValue)) {
// Snap to actual smooth value if the value doesn't change enough (due to the granularity of floats)
smoothParam->setValue(smoothValue);
internal->smoothModule = NULL;
@@ -372,13 +233,8 @@
}
}
@ -415,7 +444,7 @@
if (module->leftExpander.messageFlipRequested) {
std::swap(module->leftExpander.producerMessage, module->leftExpander.consumerMessage);
module->leftExpander.messageFlipRequested = false;
@@ -389,13 +235,32 @@
@@ -389,13 +245,32 @@
}
}
@ -454,7 +483,7 @@
}
@@ -414,35 +279,119 @@
@@ -414,35 +289,119 @@
}
@ -585,7 +614,7 @@
}
@@ -460,37 +409,23 @@
@@ -460,37 +419,23 @@
Engine::Engine() {
internal = new Internal;
@ -631,7 +660,7 @@
delete internal;
}
@@ -519,18 +454,22 @@
@@ -519,18 +464,22 @@
removeModule_NoLock(module);
delete module;
}
@ -657,7 +686,7 @@
random::init();
internal->blockFrame = internal->frame;
@@ -543,18 +482,14 @@
@@ -543,18 +492,14 @@
Engine_updateExpander_NoLock(this, module, true);
}
@ -677,7 +706,7 @@
// Stop timer
double endTime = system::getTime();
double meter = (endTime - startTime) / (frames * internal->sampleTime);
@@ -572,47 +507,20 @@
@@ -572,47 +517,20 @@
internal->meterTotal = 0.0;
internal->meterMax = 0.0;
}
@ -727,7 +756,7 @@
}
@@ -635,20 +543,13 @@
@@ -635,20 +553,13 @@
for (Module* module : internal->modules) {
module->onSampleRateChange(e);
}
@ -751,7 +780,7 @@
}
@@ -658,7 +559,6 @@
@@ -658,7 +569,6 @@
void Engine::yieldWorkers() {
@ -759,7 +788,7 @@
}
@@ -698,17 +598,25 @@
@@ -698,17 +608,25 @@
double Engine::getMeterAverage() {
@ -786,7 +815,7 @@
}
@@ -718,8 +626,12 @@
@@ -718,8 +636,12 @@
for (Module* m : internal->modules) {
if (i >= len)
break;
@ -801,7 +830,7 @@
}
return i;
}
@@ -728,27 +640,43 @@
@@ -728,27 +650,43 @@
std::vector<int64_t> Engine::getModuleIds() {
SharedLock<SharedMutex> lock(internal->mutex);
std::vector<int64_t> moduleIds;
@ -849,7 +878,7 @@
internal->modulesCache[module->id] = module;
// Dispatch AddEvent
Module::AddEvent eAdd;
@@ -763,6 +691,9 @@
@@ -763,6 +701,9 @@
if (paramHandle->moduleId == module->id)
paramHandle->module = module;
}
@ -859,7 +888,7 @@
}
@@ -772,11 +703,11 @@
@@ -772,11 +713,11 @@
}
@ -876,7 +905,7 @@
// Dispatch RemoveEvent
Module::RemoveEvent eRemove;
module->onRemove(eRemove);
@@ -785,18 +716,14 @@
@@ -785,18 +726,14 @@
if (paramHandle->moduleId == module->id)
paramHandle->module = NULL;
}
@ -897,7 +926,7 @@
}
// Update expanders of other modules
for (Module* m : internal->modules) {
@@ -809,14 +736,31 @@
@@ -809,14 +746,31 @@
m->rightExpander.module = NULL;
}
}
@ -932,7 +961,7 @@
}
@@ -824,7 +768,8 @@
@@ -824,7 +778,8 @@
SharedLock<SharedMutex> lock(internal->mutex);
// TODO Performance could be improved by searching modulesCache, but more testing would be needed to make sure it's always valid.
auto it = std::find(internal->modules.begin(), internal->modules.end(), module);
@ -942,7 +971,7 @@
}
@@ -844,7 +789,7 @@
@@ -844,7 +799,7 @@
void Engine::resetModule(Module* module) {
std::lock_guard<SharedMutex> lock(internal->mutex);
@ -951,7 +980,7 @@
Module::ResetEvent eReset;
module->onReset(eReset);
@@ -853,7 +798,7 @@
@@ -853,7 +808,7 @@
void Engine::randomizeModule(Module* module) {
std::lock_guard<SharedMutex> lock(internal->mutex);
@ -960,7 +989,7 @@
Module::RandomizeEvent eRandomize;
module->onRandomize(eRandomize);
@@ -861,7 +806,7 @@
@@ -861,7 +816,7 @@
void Engine::bypassModule(Module* module, bool bypassed) {
@ -969,7 +998,7 @@
if (module->isBypassed() == bypassed)
return;
@@ -907,11 +852,17 @@
@@ -907,11 +862,17 @@
void Engine::prepareSave() {
@ -987,7 +1016,7 @@
}
@@ -946,16 +897,16 @@
@@ -946,16 +907,16 @@
void Engine::addCable(Cable* cable) {
std::lock_guard<SharedMutex> lock(internal->mutex);
@ -1009,7 +1038,7 @@
// Get connected status of output, to decide whether we need to call a PortChangeEvent.
// It's best to not trust `cable->outputModule->outputs[cable->outputId]->isConnected()`
if (cable2->outputModule == cable->outputModule && cable2->outputId == cable->outputId)
@@ -969,6 +920,8 @@
@@ -969,6 +930,8 @@
// Add the cable
internal->cables.push_back(cable);
internal->cablesCache[cable->id] = cable;
@ -1018,7 +1047,7 @@
Engine_updateConnected(this);
// Dispatch input port event
{
@@ -996,10 +949,12 @@
@@ -996,10 +959,12 @@
void Engine::removeCable_NoLock(Cable* cable) {
@ -1033,7 +1062,17 @@
// Remove the cable
internal->cablesCache.erase(cable->id);
internal->cables.erase(it);
@@ -1085,11 +1040,11 @@
@@ -1053,6 +1018,9 @@
internal->smoothModule = NULL;
internal->smoothParamId = 0;
}
+ if (internal->remoteDetails != nullptr) {
+ sendParamChangeToRemote(internal->remoteDetails, module->id, paramId, value);
+ }
module->params[paramId].value = value;
}
@@ -1085,11 +1053,11 @@
std::lock_guard<SharedMutex> lock(internal->mutex);
// New ParamHandles must be blank.
// This means we don't have to refresh the cache.
@ -1047,7 +1086,7 @@
// Add it
internal->paramHandles.insert(paramHandle);
@@ -1106,7 +1061,7 @@
@@ -1106,7 +1074,7 @@
void Engine::removeParamHandle_NoLock(ParamHandle* paramHandle) {
// Check that the ParamHandle is already added
auto it = internal->paramHandles.find(paramHandle);
@ -1056,7 +1095,7 @@
// Remove it
paramHandle->module = NULL;
@@ -1143,7 +1098,7 @@
@@ -1143,7 +1111,7 @@
void Engine::updateParamHandle_NoLock(ParamHandle* paramHandle, int64_t moduleId, int paramId, bool overwrite) {
// Check that it exists
auto it = internal->paramHandles.find(paramHandle);
@ -1065,7 +1104,7 @@
// Set IDs
paramHandle->moduleId = moduleId;
@@ -1187,6 +1142,10 @@
@@ -1187,6 +1155,10 @@
json_t* moduleJ = module->toJson();
json_array_append_new(modulesJ, moduleJ);
}
@ -1076,7 +1115,7 @@
json_object_set_new(rootJ, "modules", modulesJ);
// cables
@@ -1197,11 +1156,6 @@
@@ -1197,11 +1169,6 @@
}
json_object_set_new(rootJ, "cables", cablesJ);
@ -1088,7 +1127,7 @@
return rootJ;
}
@@ -1225,14 +1179,20 @@
@@ -1225,14 +1192,20 @@
}
catch (Exception& e) {
WARN("Cannot load model: %s", e.what());
@ -1113,7 +1152,7 @@
try {
// This doesn't need a lock because the Module is not added to the Engine yet.
@@ -1248,7 +1208,8 @@
@@ -1248,7 +1221,8 @@
}
catch (Exception& e) {
WARN("Cannot load module: %s", e.what());
@ -1123,7 +1162,7 @@
delete module;
continue;
}
@@ -1285,67 +1246,15 @@
@@ -1285,67 +1259,20 @@
continue;
}
}
@ -1134,9 +1173,9 @@
- Module* masterModule = getModule(json_integer_value(masterModuleIdJ));
- setMasterModule(masterModule);
- }
-}
-
-
}
-void EngineWorker::run() {
- // Configure thread
- contextSet(engine->internal->context);
@ -1151,6 +1190,7 @@
- Engine_stepWorker(engine, id);
- engine->internal->workerBarrier.wait();
- }
+void Engine::startFallbackThread() {
}
@ -1179,7 +1219,8 @@
- });
- }
- }
+void Engine::startFallbackThread() {
+void Engine_setAboutToClose(Engine* const engine) {
+ engine->internal->aboutToClose = true;
}
@ -1189,8 +1230,8 @@
-
- internal->fallbackRunning = true;
- internal->fallbackThread = std::thread(Engine_fallbackRun, this);
+void Engine_setAboutToClose(Engine* const engine) {
+ engine->internal->aboutToClose = true;
+void Engine_setRemoteDetails(Engine* const engine, remoteUtils::RemoteDetails* const remoteDetails) {
+ engine->internal->remoteDetails = remoteDetails;
}