Add direct parameter changes to remote control, for LV2 and OSC

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-12-29 17:20:35 +00:00
parent 91cac905cc
commit d0eba9e1ae
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
11 changed files with 136 additions and 33 deletions

View file

@ -49,6 +49,7 @@
# undef DEBUG
#endif
#include "../CardinalRemote.hpp"
#include "DistrhoUtils.hpp"
@ -97,6 +98,9 @@ struct Engine::Internal {
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.
@ -210,12 +214,13 @@ static void Engine_stepFrame(Engine* that) {
Param* smoothParam = &smoothModule->params[smoothParamId];
float value = smoothParam->value;
float newValue;
if (internal->blockFrames != 1) {
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;
} else {
newValue = value;
}
if (d_isEqual(value, newValue)) {
// Snap to actual smooth value if the value doesn't change enough (due to the granularity of floats)
@ -1013,6 +1018,9 @@ void Engine::setParamValue(Module* module, int paramId, float value) {
internal->smoothModule = NULL;
internal->smoothParamId = 0;
}
if (internal->remoteDetails != nullptr) {
sendParamChangeToRemote(internal->remoteDetails, module->id, paramId, value);
}
module->params[paramId].value = value;
}
@ -1263,5 +1271,10 @@ void Engine_setAboutToClose(Engine* const engine) {
}
void Engine_setRemoteDetails(Engine* const engine, remoteUtils::RemoteDetails* const remoteDetails) {
engine->internal->remoteDetails = remoteDetails;
}
} // namespace engine
} // namespace rack

View file

@ -66,7 +66,9 @@ namespace rack {
namespace asset {
std::string patchesPath();
}
namespace engine {
void Engine_setRemoteDetails(Engine*, remoteUtils::RemoteDetails*);
}
namespace plugin {
void updateStaticPluginsDarkMode();
}
@ -168,26 +170,29 @@ struct FileButton : MenuButton {
patchUtils::revertDialog();
}, APP->patch->path.empty()));
// #if defined(HAVE_LIBLO) && ! CARDINAL_VARIANT_MINI
#if defined(HAVE_LIBLO) && ! CARDINAL_VARIANT_MINI
menu->addChild(new ui::MenuSeparator);
remoteUtils::RemoteDetails* const remoteDetails = remoteUtils::getRemote();
if (remoteDetails != nullptr && remoteDetails->connected) {
menu->addChild(createMenuItem("Deploy to MOD", "F7", [remoteDetails]() {
remoteUtils::deployToRemote(remoteDetails);
remoteUtils::sendFullPatchToRemote(remoteDetails);
}));
menu->addChild(createCheckMenuItem("Auto deploy to MOD", "",
[remoteDetails]() {return remoteDetails->autoDeploy;},
[remoteDetails]() {remoteDetails->autoDeploy = !remoteDetails->autoDeploy;}
[remoteDetails]() {
remoteDetails->autoDeploy = !remoteDetails->autoDeploy;
Engine_setRemoteDetails(APP->engine, remoteDetails->autoDeploy ? remoteDetails : nullptr);
}
));
} else {
menu->addChild(createMenuItem("Connect to MOD", "", []() {
remoteUtils::connectToRemote();
DISTRHO_SAFE_ASSERT(remoteUtils::connectToRemote());
}));
}
// #endif
#endif
#ifndef DISTRHO_OS_WASM
menu->addChild(new ui::MenuSeparator);

View file

@ -212,11 +212,15 @@ void Scene::step() {
if (remoteDetails->autoDeploy) {
const int actionIndex = APP->history->actionIndex;
const double time = system::getTime();
if (internal->historyActionIndex != actionIndex && time - internal->lastSceneChangeTime >= 1.0) {
if (internal->historyActionIndex != actionIndex && actionIndex > 0 && time - internal->lastSceneChangeTime >= 1.0) {
const std::string& name(APP->history->actions[actionIndex - 1]->name);
if (/*std::abs(internal->historyActionIndex = actionIndex) > 1 ||*/ name != "move knob") {
printf("action '%s'\n", APP->history->actions[actionIndex - 1]->name.c_str());
remoteUtils::sendFullPatchToRemote(remoteDetails);
window::generateScreenshot();
}
internal->historyActionIndex = actionIndex;
internal->lastSceneChangeTime = time;
remoteUtils::deployToRemote(remoteDetails);
window::generateScreenshot();
}
}
}
@ -319,7 +323,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) {
}
if (e.key == GLFW_KEY_F7 && (e.mods & RACK_MOD_MASK) == 0) {
if (remoteUtils::RemoteDetails* const remoteDetails = remoteUtils::getRemote())
remoteUtils::deployToRemote(remoteDetails);
remoteUtils::sendFullPatchToRemote(remoteDetails);
window::generateScreenshot();
e.consume(this);
}

View file

@ -585,9 +585,10 @@ static void Window__downscaleBitmap(uint8_t* pixels, int& width, int& height) {
static void Window__writeImagePNG(void* context, void* data, int size) {
USE_NAMESPACE_DISTRHO
CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context);
if (const char* const screenshot = String::asBase64(data, size).buffer()) {
if (char* const screenshot = String::asBase64(data, size).getAndReleaseBuffer()) {
ui->setState("screenshot", screenshot);
remoteUtils::sendScreenshotToRemote(ui->remoteDetails, screenshot);
std::free(screenshot);
}
}
#endif