From 383f02ee2b01b6cd6fdc7812bff6d9e5f036081f Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 4 Nov 2021 23:58:43 +0000 Subject: [PATCH] Filter out VCV logo from Core files at runtime --- src/Makefile | 3 ++ src/Makefile.cardinal.mk | 2 +- src/override/dep.cpp | 104 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 1dd43ff..3fce996 100644 --- a/src/Makefile +++ b/src/Makefile @@ -68,6 +68,9 @@ BUILD_C_FLAGS += -std=gnu11 BUILD_C_FLAGS += -fno-finite-math-only BUILD_CXX_FLAGS += -fno-finite-math-only +# use our custom function to filter out VCV trademarks +BUILD_CXX_FLAGS += -DnsvgParseFromFile=nsvgParseFromFileCardinal + # -------------------------------------------------------------- # Rack files to build diff --git a/src/Makefile.cardinal.mk b/src/Makefile.cardinal.mk index a42e0dd..1302ec9 100644 --- a/src/Makefile.cardinal.mk +++ b/src/Makefile.cardinal.mk @@ -170,7 +170,7 @@ all: jack lv2 vst2 vst3 resources ifeq ($(NAME),Cardinal) -CORE_RESOURCES = $(subst ../Rack/res/,,$(wildcard ../Rack/res/*)) template.vcv +CORE_RESOURCES = $(filter-out icon.png,$(subst ../Rack/res/,,$(wildcard ../Rack/res/*))) template.vcv PLUGIN_RESOURCES += $(CORE_RESOURCES:%=$(TARGET_DIR)/Cardinal.lv2/resources/%) ifeq ($(MACOS),true) diff --git a/src/override/dep.cpp b/src/override/dep.cpp index 8fd9e03..3dac141 100644 --- a/src/override/dep.cpp +++ b/src/override/dep.cpp @@ -16,6 +16,7 @@ */ #include +#include // fix blendish build, missing symbol in debug mode #ifdef DEBUG @@ -39,4 +40,107 @@ float FollowerBase::efGainMaxDecibelsDebug = 12.0f; // Compile those nice implementation-in-header little libraries #define NANOSVG_IMPLEMENTATION #define NANOSVG_ALL_COLOR_KEYWORDS +#undef nsvgParseFromFile #include + +// Custom Cardinal filtering +static const struct { + const char* filename; + const char* shapes[4]; +} pathsToFilterOut[] = { + { + "Core/AudioInterface.svg", + {"path39377","path39381","path39383","path39379"} + }, + { + "Core/AudioInterface2.svg", + {"path18733","path18737","path18731","path18735"} + }, + { + "Core/AudioInterface16.svg", + {"path40283","path40287","path40289","path40285"} + }, + { + "Core/CV-CC.svg", + {"path12881","path12885","path12887","path12883"} + }, + { + "Core/CV-Gate.svg", + {"path13127","path13131","path13133","path13129"} + }, + { + "Core/CV-MIDI.svg", + {"path12747","path12751","path12753","path12749"} + }, + { + "Core/MIDI-CC.svg", + {"path9740","path9744","path9746","path9742"} + }, + { + "Core/MIDI-CV.svg", + {"path11803","path11807","path11809","path11805"} + }, + { + "Core/MIDI-Gate.svg", + {"path11634","path11638","path11640","path11636"} + }, + { + "Core/MIDI-Map.svg", + {"path21209","path21213","path21215","path21211"} + }, + { + "Core/Notes.svg", + {"path6935","path6939","path6941","path6937"} + }, +}; + +static void removeShape(NSVGimage* const handle, const char* const id) +{ + for (NSVGshape *shape = handle->shapes, *old = nullptr; shape; old = shape, shape = shape->next) + { + if (strcmp(shape->id, id) != 0) + continue; + + if (old != nullptr) + old->next = shape->next; + else + handle->shapes = shape->next; + + nsvg__deletePaths(shape->paths); + free(shape); + break; + } +} + +extern "C" { +NSVGimage* nsvgParseFromFileCardinal(const char* filename, const char* units, float dpi); +} + +NSVGimage* nsvgParseFromFileCardinal(const char* const filename, const char* const units, const float dpi) +{ + if (NSVGimage* const handle = nsvgParseFromFile(filename, units, dpi)) + { + for (size_t i = 0; i < sizeof(pathsToFilterOut)/sizeof(pathsToFilterOut[0]); ++i) + { + const char* const pathToFilterOut = pathsToFilterOut[i].filename; + const size_t filenamelen = std::strlen(filename); + const size_t filterlen = std::strlen(pathToFilterOut); + + if (filenamelen < filterlen) + continue; + + if (std::strncmp(filename + (filenamelen-filterlen), pathToFilterOut, filterlen) == 0) + { + printf("Removing CC-ND deadlock from file...\n"); + removeShape(handle, pathsToFilterOut[i].shapes[0]); + removeShape(handle, pathsToFilterOut[i].shapes[1]); + removeShape(handle, pathsToFilterOut[i].shapes[2]); + removeShape(handle, pathsToFilterOut[i].shapes[3]); + } + } + + return handle; + } + + return nullptr; +}