Allow UI to send value by controller

This commit is contained in:
Jean Pierre Cimalando 2021-04-05 17:06:17 +02:00
parent 308eb788e6
commit 2436414ad8
4 changed files with 45 additions and 8 deletions

View file

@ -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)

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include <sfizz_message.h>
#include <memory>
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> impl_;

View file

@ -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<const LV2_Atom *>(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;
}
}

View file

@ -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());