Skip to content

Commit

Permalink
Merge pull request #776 from jpcima/lv2-parameters
Browse files Browse the repository at this point in the history
Present the controllers as LV2 parameters
  • Loading branch information
jpcima authored Apr 5, 2021
2 parents da9135b + 4731bef commit 539fbf6
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 83 deletions.
56 changes: 56 additions & 0 deletions cmake/LV2Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,59 @@ else()
set(LV2PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/lv2" CACHE STRING
"Install destination for LV2 bundle [default: ${CMAKE_INSTALL_PREFIX}/lib/lv2]")
endif()

include(StringUtility)

function(sfizz_lv2_generate_controllers_ttl FILE)
file(WRITE "${FILE}" "# LV2 parameters for SFZ controllers
@prefix atom: <http://lv2plug.in/ns/ext/atom#> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
@prefix midi: <http://lv2plug.in/ns/ext/midi#> .
@prefix patch: <http://lv2plug.in/ns/ext/patch#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sfizz: <${LV2PLUGIN_URI}#> .
")
math(EXPR _j "${SFIZZ_NUM_CCS}-1")
foreach(_i RANGE "${_j}")
string_left_pad(_i "${_i}" 3 0)
file(APPEND "${FILE}" "
sfizz:cc${_i}
a lv2:Parameter ;
rdfs:label \"Controller ${_i}\" ;
rdfs:range atom:Float")

if(_i LESS 128)
math(EXPR _digit1 "${_i}>>4")
math(EXPR _digit2 "${_i}&15")
string(SUBSTRING "0123456789ABCDEF" "${_digit1}" 1 _digit1)
string(SUBSTRING "0123456789ABCDEF" "${_digit2}" 1 _digit2)
file(APPEND "${FILE}" " ;
midi:binding \"B0${_digit1}${_digit2}00\"^^midi:MidiEvent .
")
else()
file(APPEND "${FILE}" " .
")
endif()
endforeach()

file(APPEND "${FILE}" "
<${LV2PLUGIN_URI}>
a lv2:Plugin ;
")

file(APPEND "${FILE}" " patch:readable sfizz:cc000")
foreach(_i RANGE 1 "${_j}")
string_left_pad(_i "${_i}" 3 0)
file(APPEND "${FILE}" ", sfizz:cc${_i}")
endforeach()
file(APPEND "${FILE}" " ;
")

file(APPEND "${FILE}" " patch:writable sfizz:cc000")
foreach(_i RANGE 1 "${_j}")
string_left_pad(_i "${_i}" 3 0)
file(APPEND "${FILE}" ", sfizz:cc${_i}")
endforeach()
file(APPEND "${FILE}" " .
")
endfunction()
11 changes: 11 additions & 0 deletions cmake/StringUtility.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: BSD-2-Clause

function(string_left_pad VAR INPUT LENGTH FILLCHAR)
set(_output "${INPUT}")
string(LENGTH "${_output}" _length)
while(_length LESS "${LENGTH}")
set(_output "${FILLCHAR}${_output}")
string(LENGTH "${_output}" _length)
endwhile()
set("${VAR}" "${_output}" PARENT_SCOPE)
endfunction()
29 changes: 18 additions & 11 deletions plugins/editor/src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -476,12 +482,18 @@ void Editor::Impl::uiReceiveValue(EditId id, const EditValue& v)
else if (editIdIsKeyswitchLabel(id)) {
updateSWLastLabel(keyswitchLabelForEditId(id), v.to_string().c_str());
}
else if (editIdIsCC(id)) {
updateCCValue(unsigned(ccForEditId(id)), v.to_float());
}
else if (editIdIsCCUsed(id)) {
updateCCUsed(ccUsedForEditId(id), v.to_float() != 0);
bool used = v.to_float() != 0;
updateCCUsed(ccUsedForEditId(id), used);
// TODO(jpc) remove value requests, when implementing CC automation
char pathBuf[256];
sprintf(pathBuf, "/cc%u/value", ccUsedForEditId(id));
sendQueuedOSC(pathBuf, "", nullptr);
if (used) {
char pathBuf[256];
sprintf(pathBuf, "/cc%u/value", ccUsedForEditId(id));
sendQueuedOSC(pathBuf, "", nullptr);
}
}
else if (editIdIsCCDefault(id)) {
updateCCDefaultValue(ccDefaultForEditId(id), v.to_float());
Expand Down Expand Up @@ -1610,13 +1622,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)
Expand Down
4 changes: 4 additions & 0 deletions plugins/editor/src/editor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,6 +25,9 @@ class Editor {
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_;
Expand Down
3 changes: 3 additions & 0 deletions plugins/lv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ if(SFIZZ_USE_VCPKG OR SFIZZ_STATIC_DEPENDENCIES OR CMAKE_CXX_COMPILER_ID MATCHES
file(COPY "lgpl-3.0.txt" DESTINATION ${PROJECT_BINARY_DIR})
endif()

# Generate controllers.ttl
sfizz_lv2_generate_controllers_ttl("${PROJECT_BINARY_DIR}/controllers.ttl")

# Copy resource files into the bundle
set(LV2_RESOURCES
DefaultInstrument.sfz
Expand Down
2 changes: 1 addition & 1 deletion plugins/lv2/manifest.ttl.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<@LV2PLUGIN_URI@>
a lv2:Plugin ;
lv2:binary <Contents/Binary/@PROJECT_NAME@@CMAKE_SHARED_MODULE_SUFFIX@> ;
rdfs:seeAlso <@PROJECT_NAME@.ttl> .
rdfs:seeAlso <@PROJECT_NAME@.ttl>, <controllers.ttl> .

@LV2PLUGIN_IF_ENABLE_UI@<@LV2PLUGIN_URI@#ui>
@LV2PLUGIN_IF_ENABLE_UI@ a ui:@LV2_UI_TYPE@ ;
Expand Down
Loading

0 comments on commit 539fbf6

Please sign in to comment.