Make a common lib for plugins, move OSC there

This commit is contained in:
Jean Pierre Cimalando 2021-02-08 20:39:24 +01:00
parent 15b6f15093
commit f1d240b88b
8 changed files with 95 additions and 60 deletions

View file

@ -54,22 +54,7 @@ add_subdirectory (src)
# Optional targets
add_subdirectory (clients)
if ((SFIZZ_LV2 AND SFIZZ_LV2_UI) OR SFIZZ_VST)
add_subdirectory (plugins/editor)
endif()
if (SFIZZ_LV2)
add_subdirectory (plugins/lv2)
endif()
if (SFIZZ_VST)
add_subdirectory (plugins/vst)
else()
if (SFIZZ_AU)
message(WARNING "Audio Unit requires VST to be enabled")
endif()
endif()
add_subdirectory (plugins)
if (SFIZZ_BENCHMARKS)
add_subdirectory (benchmarks)

24
plugins/CMakeLists.txt Normal file
View file

@ -0,0 +1,24 @@
add_library(plugins-common STATIC EXCLUDE_FROM_ALL
"common/plugin/MessageUtils.h"
"common/plugin/MessageUtils.cpp")
target_include_directories(plugins-common PUBLIC "common")
target_link_libraries(plugins-common
PUBLIC sfizz::spin_mutex
PUBLIC absl::strings)
add_library(sfizz::plugins-common ALIAS plugins-common)
if((SFIZZ_LV2 AND SFIZZ_LV2_UI) OR SFIZZ_VST)
add_subdirectory(editor)
endif()
if(SFIZZ_LV2)
add_subdirectory(lv2)
endif()
if(SFIZZ_VST)
add_subdirectory(vst)
else()
if(SFIZZ_AU)
message(WARNING "Audio Unit requires VST to be enabled")
endif()
endif()

View file

@ -0,0 +1,39 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "MessageUtils.h"
#include <absl/strings/ascii.h>
#include <absl/strings/numbers.h>
#include <cstring>
namespace Messages {
bool matchOSC(const char* pattern, const char* path, unsigned* indices)
{
unsigned nthIndex = 0;
while (const char *endp = std::strchr(pattern, '&')) {
size_t length = endp - pattern;
if (std::strncmp(pattern, path, length))
return false;
pattern += length;
path += length;
length = 0;
while (absl::ascii_isdigit(path[length]))
++length;
if (!absl::SimpleAtoi(absl::string_view(path, length), &indices[nthIndex++]))
return false;
pattern += 1;
path += length;
}
return !std::strcmp(path, pattern);
}
} // namespace Messages

View file

@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
namespace Messages {
/**
* Simple matcher for message handling in O(N)
* @param[in] pattern Pattern to match, where '&' characters match positive integer numbers
* @param[in] path Path to match against the pattern
* @param[out] indices Table which received the indices, with size >= the number of '&' in the pattern
*/
bool matchOSC(const char* pattern, const char* path, unsigned* indices);
} // namespace Messages

View file

@ -43,9 +43,8 @@ add_library(sfizz_editor STATIC EXCLUDE_FROM_ALL
src/editor/utility/vstgui_before.h)
add_library(sfizz::editor ALIAS sfizz_editor)
target_include_directories(sfizz_editor PUBLIC "src")
target_link_libraries(sfizz_editor PUBLIC sfizz::messaging)
target_link_libraries(sfizz_editor PUBLIC sfizz::messaging sfizz::plugins-common)
target_link_libraries(sfizz_editor PRIVATE sfizz::vstgui)
target_link_libraries(sfizz_editor PUBLIC absl::strings)
if(APPLE)
find_library(APPLE_APPKIT_LIBRARY "AppKit")
find_library(APPLE_CORESERVICES_LIBRARY "CoreServices")

View file

@ -10,6 +10,7 @@
#include "GUIComponents.h"
#include "GUIPiano.h"
#include "NativeHelpers.h"
#include "plugin/MessageUtils.h"
#include <absl/strings/string_view.h>
#include <absl/strings/match.h>
#include <absl/strings/ascii.h>
@ -372,43 +373,11 @@ void Editor::Impl::uiReceiveValue(EditId id, const EditValue& v)
}
}
///
static constexpr unsigned kMessageMaxIndices = 8;
static bool matchMessage(const char* pattern, const char* path, unsigned* indices)
{
unsigned nthIndex = 0;
while (const char *endp = strchr(pattern, '&')) {
if (nthIndex == kMessageMaxIndices)
return false;
size_t length = endp - pattern;
if (strncmp(pattern, path, length))
return false;
pattern += length;
path += length;
length = 0;
while (absl::ascii_isdigit(path[length]))
++length;
if (!absl::SimpleAtoi(absl::string_view(path, length), &indices[nthIndex++]))
return false;
pattern += 1;
path += length;
}
return !strcmp(path, pattern);
}
///
void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfizz_arg_t* args)
{
unsigned indices[kMessageMaxIndices];
unsigned indices[8];
if (!strcmp(path, "/cc/slots") && !strcmp(sig, "b")) {
if (Messages::matchOSC("/cc/slots", path, indices) && !strcmp(sig, "b")) {
const uint8_t* bitChunks = args[0].b->data;
uint32_t byteSize = args[0].b->size;
@ -426,7 +395,7 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi
}
}
}
else if (!strcmp(path, "/cc/changed") && !strcmp(sig, "b")) {
else if (Messages::matchOSC("/cc/changed", path, indices) && !strcmp(sig, "b")) {
const uint8_t* bitChunks = args[0].b->data;
uint32_t byteSize = args[0].b->size;
for (unsigned cc = 0; cc < 8 * byteSize; ++cc) {
@ -438,13 +407,13 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi
}
}
}
else if (matchMessage("/cc&/value", path, indices) && !strcmp(sig, "f")) {
else if (Messages::matchOSC("/cc&/value", path, indices) && !strcmp(sig, "f")) {
updateCCValue(indices[0], args[0].f);
}
else if (matchMessage("/cc&/default", path, indices) && !strcmp(sig, "f")) {
else if (Messages::matchOSC("/cc&/default", path, indices) && !strcmp(sig, "f")) {
updateCCDefaultValue(indices[0], args[0].f);
}
else if (matchMessage("/cc&/label", path, indices) && !strcmp(sig, "s")) {
else if (Messages::matchOSC("/cc&/label", path, indices) && !strcmp(sig, "s")) {
updateCCLabel(indices[0], args[0].s);
}
else {

View file

@ -21,14 +21,14 @@ source_group("Turtle Files" FILES
add_library(${LV2PLUGIN_PRJ_NAME} MODULE
${PROJECT_NAME}.cpp
${LV2PLUGIN_TTL_SRC_FILES})
target_link_libraries(${LV2PLUGIN_PRJ_NAME} PRIVATE sfizz::sfizz sfizz::spin_mutex)
target_link_libraries(${LV2PLUGIN_PRJ_NAME} PRIVATE sfizz::sfizz sfizz::plugins-common)
if(SFIZZ_LV2_UI)
add_library(${LV2PLUGIN_PRJ_NAME}_ui MODULE
${PROJECT_NAME}_ui.cpp
vstgui_helpers.h
vstgui_helpers.cpp)
target_link_libraries(${LV2PLUGIN_PRJ_NAME}_ui PRIVATE sfizz::editor sfizz::vstgui)
target_link_libraries(${LV2PLUGIN_PRJ_NAME}_ui PRIVATE sfizz::editor sfizz::vstgui sfizz::plugins-common)
endif()
# Explicitely strip all symbols on Linux but lv2_descriptor()

View file

@ -63,7 +63,7 @@ endif()
target_link_libraries(${VSTPLUGIN_PRJ_NAME}
PRIVATE sfizz::sfizz
PRIVATE sfizz::editor
PRIVATE sfizz::spin_mutex
PRIVATE sfizz::plugins-common
PRIVATE sfizz::pugixml sfizz::filesystem)
target_include_directories(${VSTPLUGIN_PRJ_NAME}
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
@ -202,7 +202,7 @@ elseif(SFIZZ_AU)
target_link_libraries(${AUPLUGIN_PRJ_NAME}
PRIVATE ${PROJECT_NAME}::${PROJECT_NAME}
PRIVATE sfizz::editor
PRIVATE sfizz::spin_mutex
PRIVATE sfizz::plugins-common
PRIVATE sfizz::pugixml sfizz::filesystem)
target_include_directories(${AUPLUGIN_PRJ_NAME}
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")