From 2436414ad8c56829354350cdc935329b023daa3d Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 5 Apr 2021 17:06:17 +0200 Subject: [PATCH] Allow UI to send value by controller --- plugins/editor/src/editor/Editor.cpp | 15 ++++++++------- plugins/editor/src/editor/Editor.h | 4 ++++ plugins/lv2/sfizz_ui.cpp | 21 +++++++++++++++++++++ plugins/vst/SfizzVstEditor.cpp | 13 ++++++++++++- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index 0dfb875b..d91e20cc 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -306,6 +306,12 @@ void Editor::close() } } +void Editor::sendQueuedOSC(const char* path, const char* sig, const sfizz_arg_t* args) +{ + Impl& impl = *impl_; + impl.sendQueuedOSC(path, sig, args); +} + void Editor::Impl::uiReceiveValue(EditId id, const EditValue& v) { switch (id) { @@ -1613,13 +1619,8 @@ void Editor::Impl::updateMemoryUsed(uint64_t mem) void Editor::Impl::performCCValueChange(unsigned cc, float value) { - // TODO(jpc) CC as parameters and automation - - char pathBuf[256]; - sprintf(pathBuf, "/cc%u/value", cc); - sfizz_arg_t args[1]; - args[0].f = value; - sendQueuedOSC(pathBuf, "f", args); + EditorController& ctrl = *ctrl_; + ctrl.uiSendValue(editIdForCC(int(cc)), value); } void Editor::Impl::performCCBeginEdit(unsigned cc) diff --git a/plugins/editor/src/editor/Editor.h b/plugins/editor/src/editor/Editor.h index 0c0ae1de..4345426c 100644 --- a/plugins/editor/src/editor/Editor.h +++ b/plugins/editor/src/editor/Editor.h @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #pragma once +#include #include class EditorController; @@ -24,6 +25,9 @@ public: void open(CFrame& frame); void close(); + // TODO(jpc) remove me after doing parameter automations + void sendQueuedOSC(const char* path, const char* sig, const sfizz_arg_t* args); + private: struct Impl; std::unique_ptr impl_; diff --git a/plugins/lv2/sfizz_ui.cpp b/plugins/lv2/sfizz_ui.cpp index db91b4e0..581f373f 100644 --- a/plugins/lv2/sfizz_ui.cpp +++ b/plugins/lv2/sfizz_ui.cpp @@ -537,6 +537,22 @@ void sfizz_ui_t::uiSendValue(EditId id, const EditValue& v) } }; + auto sendController = [this](LV2_URID property, float value) { + LV2_Atom_Forge *forge = &atom_forge; + LV2_Atom_Forge_Frame frame; + auto *atom = reinterpret_cast(atom_temp); + lv2_atom_forge_set_buffer(forge, atom_temp, sizeof(atom_temp)); + if (lv2_atom_forge_object(forge, &frame, 0, patch_set_uri) && + lv2_atom_forge_key(forge, patch_property_uri) && + lv2_atom_forge_urid(forge, property) && + lv2_atom_forge_key(forge, patch_value_uri) && + lv2_atom_forge_float(forge, value)) + { + lv2_atom_forge_pop(forge, &frame); + write(con, SFIZZ_CONTROL, lv2_atom_total_size(atom), atom_event_transfer_uri, atom); + } + }; + switch (id) { case EditId::Volume: sendFloat(SFIZZ_VOLUME, v.to_float()); @@ -566,6 +582,11 @@ void sfizz_ui_t::uiSendValue(EditId id, const EditValue& v) sendPath(sfizz_scala_file_uri, v.to_string()); break; default: + if (editIdIsCC(id)) { + int cc = ccForEditId(id); + LV2_URID urid = sfizz_lv2_ccmap_map(ccmap.get(), cc); + sendController(urid, v.to_float()); + } break; } } diff --git a/plugins/vst/SfizzVstEditor.cpp b/plugins/vst/SfizzVstEditor.cpp index decc6f43..eff7462f 100644 --- a/plugins/vst/SfizzVstEditor.cpp +++ b/plugins/vst/SfizzVstEditor.cpp @@ -329,7 +329,18 @@ void SfizzVstEditor::processNoteEventQueue() /// void SfizzVstEditor::uiSendValue(EditId id, const EditValue& v) { - if (id == EditId::SfzFile) + if (editIdIsCC(id)) { + int cc = ccForEditId(id); + // TODO(jpc) CC as parameters and automation + if (Editor* editor = editor_.get()) { + char pathBuf[256]; + sprintf(pathBuf, "/cc%u/value", cc); + sfizz_arg_t args[1]; + args[0].f = v.to_float(); + editor->sendQueuedOSC(pathBuf, "f", args); + } + } + else if (id == EditId::SfzFile) loadSfzFile(v.to_string()); else if (id == EditId::ScalaFile) loadScalaFile(v.to_string());