From cf743245685d40bf56c7c1ca3a2ed84f2ed87e1c Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 25 Dec 2022 22:28:36 +0000 Subject: [PATCH] Initial work towards a mini variant, WIP Signed-off-by: falkTX --- dpf | 2 +- plugins/Cardinal/src/plugincontext.hpp | 1 + plugins/Makefile | 73 ++++++++- plugins/plugins-mini.cpp | 195 +++++++++++++++++++++++++ src/Cardinal/DistrhoPluginInfo.h | 1 + src/CardinalCommon.cpp | 8 + src/CardinalFX/DistrhoPluginInfo.h | 1 + src/CardinalMini/CardinalCommon.cpp | 1 + src/CardinalMini/CardinalPlugin.cpp | 1 + src/CardinalMini/CardinalUI.cpp | 1 + src/CardinalMini/DistrhoPluginInfo.h | 55 +++++++ src/CardinalMini/Makefile | 8 + src/CardinalMini/RemoteNanoVG.cpp | 1 + src/CardinalMini/RemoteWindow.cpp | 1 + src/CardinalMini/Window.cpp | 1 + src/CardinalMini/common.cpp | 1 + src/CardinalMini/glfw.cpp | 1 + src/CardinalNative/DistrhoPluginInfo.h | 1 + src/CardinalPlugin.cpp | 4 +- src/Makefile | 34 +++-- src/Makefile.cardinal.mk | 75 +++++++--- src/PluginContext.hpp | 10 ++ src/custom/RemoteNanoVG.cpp | 14 +- 23 files changed, 449 insertions(+), 41 deletions(-) create mode 100644 plugins/plugins-mini.cpp create mode 120000 src/CardinalMini/CardinalCommon.cpp create mode 120000 src/CardinalMini/CardinalPlugin.cpp create mode 120000 src/CardinalMini/CardinalUI.cpp create mode 100644 src/CardinalMini/DistrhoPluginInfo.h create mode 100644 src/CardinalMini/Makefile create mode 120000 src/CardinalMini/RemoteNanoVG.cpp create mode 120000 src/CardinalMini/RemoteWindow.cpp create mode 120000 src/CardinalMini/Window.cpp create mode 120000 src/CardinalMini/common.cpp create mode 120000 src/CardinalMini/glfw.cpp diff --git a/dpf b/dpf index 924576a..564f651 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 924576a58c3f3a98d7df56f189f3f53fc4da0abb +Subproject commit 564f6519b4bbf1c6cc8791a9adbb377f6cfd4984 diff --git a/plugins/Cardinal/src/plugincontext.hpp b/plugins/Cardinal/src/plugincontext.hpp index e087784..935a007 100644 --- a/plugins/Cardinal/src/plugincontext.hpp +++ b/plugins/Cardinal/src/plugincontext.hpp @@ -41,6 +41,7 @@ static constexpr const uint32_t kModuleParameters = 24; enum CardinalVariant { kCardinalVariantMain, + kCardinalVariantMini, kCardinalVariantFX, kCardinalVariantNative, kCardinalVariantSynth, diff --git a/plugins/Makefile b/plugins/Makefile index 515378b..e9bfc20 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -231,7 +231,13 @@ DRWAV += drwav_write_raw # -------------------------------------------------------------- # Files to build +ifeq ($(NOPLUGINS),true) +PLUGIN_FILES = noplugins.cpp +else PLUGIN_FILES = plugins.cpp +endif + +MINIPLUGIN_FILES = plugins-mini.cpp # -------------------------------------------------------------- # Cardinal (built-in) @@ -250,6 +256,17 @@ PLUGIN_FILES += Cardinal/src/HostParameters-Map.cpp PLUGIN_FILES += Cardinal/src/HostTime.cpp PLUGIN_FILES += Cardinal/src/TextEditor.cpp +MINIPLUGIN_FILES += Cardinal/src/HostAudio.cpp +MINIPLUGIN_FILES += Cardinal/src/HostCV.cpp +MINIPLUGIN_FILES += Cardinal/src/HostMIDI.cpp +MINIPLUGIN_FILES += Cardinal/src/HostMIDI-CC.cpp +MINIPLUGIN_FILES += Cardinal/src/HostMIDI-Gate.cpp +MINIPLUGIN_FILES += Cardinal/src/HostMIDI-Map.cpp +MINIPLUGIN_FILES += Cardinal/src/HostParameters.cpp +MINIPLUGIN_FILES += Cardinal/src/HostParameters-Map.cpp +MINIPLUGIN_FILES += Cardinal/src/HostTime.cpp +MINIPLUGIN_FILES += Cardinal/src/TextEditor.cpp + ifneq ($(USE_GLES2),true) ifneq ($(USE_GLES3),true) PLUGIN_FILES += Cardinal/src/glBars.cpp @@ -280,6 +297,7 @@ endif ifeq ($(shell $(PKG_CONFIG) --exists fftw3f && echo true),true) PLUGIN_FILES += Cardinal/src/AudioToCVPitch.cpp +MINIPLUGIN_FILES += Cardinal/src/AudioToCVPitch.cpp BASE_FLAGS += -DHAVE_FFTW3F endif @@ -1106,7 +1124,11 @@ endif # !NOPLUGINS # -------------------------------------------------------------- # Build setup +ifeq ($(HEADLESS),true) +BUILD_DIR = ../build-headless/plugins +else BUILD_DIR = ../build/plugins +endif ifeq ($(MACOS),true) BASE_FLAGS += -DARCH_MAC @@ -1261,16 +1283,23 @@ endif # -------------------------------------------------------------- # Build targets +ifeq ($(HEADLESS),true) +TARGET_SUFFIX = -headless +endif + ifeq ($(NOPLUGINS),true) -TARGET = noplugins.a +TARGETS = noplugins$(TARGET_SUFFIX).a else -TARGET = plugins.a +TARGETS = plugins$(TARGET_SUFFIX).a plugins-mini-headless.a endif -all: $(TARGET) +all: $(TARGETS) +ifneq ($(HEADLESS),true) + $(MAKE) HEADLESS=true plugins-mini-headless.a +endif clean: - rm -f $(TARGET) + rm -f $(TARGETS) rm -rf $(BUILD_DIR) rm -rf surgext/build @@ -1342,6 +1371,9 @@ JACK_RESOURCES += $(CURDIR)/surgext/build/surge-data/wavetables JACK_RESOURCES += $(CURDIR)/surgext/build/surge-data/windows.wt endif +MINIPLUGIN_LIST = Cardinal +MINIRESOURCE_FILES = $(wildcard Cardinal/res/*.svg) + RESOURCE_FILES += Cardinal/res/Miku/Miku.png # MOD builds only have LV2 main and FX variant @@ -1349,8 +1381,10 @@ ifeq ($(MOD_BUILD),true) LV2_RESOURCES = $(PLUGIN_LIST:%=../bin/Cardinal.lv2/resources/PluginManifests/%.json) LV2_RESOURCES += $(PLUGIN_LIST:%=../bin/CardinalFX.lv2/resources/PluginManifests/%.json) +LV2_RESOURCES += $(MINIPLUGIN_LIST:%=../bin/CardinalMini.lv2/resources/PluginManifests/%.json) LV2_RESOURCES += $(RESOURCE_FILES:%=../bin/Cardinal.lv2/resources/%) LV2_RESOURCES += $(RESOURCE_FILES:%=../bin/CardinalFX.lv2/resources/%) +LV2_RESOURCES += $(MINIRESOURCE_FILES:%=../bin/CardinalMini.lv2/resources/%) # MOD builds only have LV2 FX variant for now else ifeq ($(WASM),true) @@ -1362,10 +1396,12 @@ else LV2_RESOURCES = $(PLUGIN_LIST:%=../bin/Cardinal.lv2/resources/PluginManifests/%.json) LV2_RESOURCES += $(PLUGIN_LIST:%=../bin/CardinalFX.lv2/resources/PluginManifests/%.json) +LV2_RESOURCES += $(MINIPLUGIN_LIST:%=../bin/CardinalMini.lv2/resources/PluginManifests/%.json) LV2_RESOURCES += $(PLUGIN_LIST:%=../bin/CardinalSynth.lv2/resources/PluginManifests/%.json) LV2_RESOURCES += $(RESOURCE_FILES:%=../bin/Cardinal.lv2/resources/%) LV2_RESOURCES += $(RESOURCE_FILES:%=../bin/CardinalFX.lv2/resources/%) LV2_RESOURCES += $(RESOURCE_FILES:%=../bin/CardinalSynth.lv2/resources/%) +LV2_RESOURCES += $(MINIRESOURCE_FILES:%=../bin/CardinalMini.lv2/resources/%) ifeq ($(MACOS),true) VST2_RESOURCES = $(PLUGIN_LIST:%=../bin/CardinalFX.vst/Contents/Resources/PluginManifests/%.json) @@ -1404,6 +1440,10 @@ resources: $(JACK_RESOURCES) $(LV2_RESOURCES) $(VST2_RESOURCES) $(VST3_RESOURCES -@mkdir -p "$(shell dirname $@)" $(SILENT)ln -sf $(abspath $<) $@ +../bin/CardinalMini.lv2/resources/%: % + -@mkdir -p "$(shell dirname $@)" + $(SILENT)ln -sf $(abspath $<) $@ + ../bin/CardinalNative.lv2/resources/%: % -@mkdir -p "$(shell dirname $@)" $(SILENT)ln -sf $(abspath $<) $@ @@ -1426,6 +1466,10 @@ endif -@mkdir -p "$(shell dirname $@)" $(SILENT)ln -sf $(abspath $<) $@ +../bin/CardinalMini.lv2/resources/PluginManifests/%.json: %/plugin.json + -@mkdir -p "$(shell dirname $@)" + $(SILENT)ln -sf $(abspath $<) $@ + ../bin/CardinalNative.lv2/resources/PluginManifests/%.json: %/plugin.json -@mkdir -p "$(shell dirname $@)" $(SILENT)ln -sf $(abspath $<) $@ @@ -1539,6 +1583,8 @@ endif PLUGIN_OBJS = $(PLUGIN_FILES:%=$(BUILD_DIR)/%.o) PLUGIN_OBJS += $(PLUGIN_BINARIES:%=$(BUILD_DIR)/%.bin.o) +MINIPLUGIN_OBJS = $(MINIPLUGIN_FILES:%=$(BUILD_DIR)/%.o) + NOPLUGIN_OBJS = $(NOPLUGIN_FILES:%=$(BUILD_DIR)/%.o) .PRECIOUS: $(PLUGIN_BINARIES:%=$(BUILD_DIR)/%.bin.c) @@ -1547,12 +1593,17 @@ NOPLUGIN_OBJS = $(NOPLUGIN_FILES:%=$(BUILD_DIR)/%.o) custom_module_names = -D${1}=${2}${1} -Dmodel${1}=model${2}${1} -D${1}Widget=${2}${1}Widget custom_per_file_names = -D${1}=${2}_${1} -plugins.a: $(PLUGIN_OBJS) +plugins$(TARGET_SUFFIX).a: $(PLUGIN_OBJS) + @echo "Creating $@" + $(SILENT)rm -f $@ + $(SILENT)$(AR) crs $@ $^ + +plugins-mini$(TARGET_SUFFIX).a: $(MINIPLUGIN_OBJS) @echo "Creating $@" $(SILENT)rm -f $@ $(SILENT)$(AR) crs $@ $^ -noplugins.a: $(NOPLUGIN_OBJS) +noplugins$(TARGET_SUFFIX).a: $(NOPLUGIN_OBJS) @echo "Creating $@" $(NOPLUGIN_OBJS) $(SILENT)rm -f $@ $(SILENT)$(AR) crs $@ $^ @@ -1572,6 +1623,16 @@ $(BUILD_DIR)/plugins.cpp.o: plugins.cpp @echo "Compiling $<" $(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ +$(BUILD_DIR)/plugins-mini.cpp.o: plugins-mini.cpp + -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" + @echo "Compiling $<" + $(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ + +$(BUILD_DIR)/noplugins.cpp.o: plugins.cpp + -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" + @echo "Compiling $<" + $(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ + $(BUILD_DIR)/Cardinal/%.cpp.o: Cardinal/%.cpp -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" @echo "Compiling $<" diff --git a/plugins/plugins-mini.cpp b/plugins/plugins-mini.cpp new file mode 100644 index 0000000..3c50e38 --- /dev/null +++ b/plugins/plugins-mini.cpp @@ -0,0 +1,195 @@ +/* + * DISTRHO Cardinal Plugin + * Copyright (C) 2021-2022 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the LICENSE file. + */ + +#include "rack.hpp" +#include "plugin.hpp" + +#include "DistrhoUtils.hpp" + +// Cardinal (built-in) +#include "Cardinal/src/plugin.hpp" + +// known terminal modules +std::vector hostTerminalModels; + +// plugin instances +Plugin* pluginInstance__Cardinal; + +namespace rack { + +namespace asset { +std::string pluginManifest(const std::string& dirname); +std::string pluginPath(const std::string& dirname); +} + +namespace plugin { + +struct StaticPluginLoader { + Plugin* const plugin; + FILE* file; + json_t* rootJ; + + StaticPluginLoader(Plugin* const p, const char* const name) + : plugin(p), + file(nullptr), + rootJ(nullptr) + { +#ifdef DEBUG + DEBUG("Loading plugin module %s", name); +#endif + + p->path = asset::pluginPath(name); + + const std::string manifestFilename = asset::pluginManifest(name); + + if ((file = std::fopen(manifestFilename.c_str(), "r")) == nullptr) + { + d_stderr2("Manifest file %s does not exist", manifestFilename.c_str()); + return; + } + + json_error_t error; + if ((rootJ = json_loadf(file, 0, &error)) == nullptr) + { + d_stderr2("JSON parsing error at %s %d:%d %s", manifestFilename.c_str(), error.line, error.column, error.text); + return; + } + + // force ABI, we use static plugins so this doesnt matter as long as it builds + json_t* const version = json_string((APP_VERSION_MAJOR + ".0").c_str()); + json_object_set(rootJ, "version", version); + json_decref(version); + + // Load manifest + p->fromJson(rootJ); + + // Reject plugin if slug already exists + if (Plugin* const existingPlugin = getPlugin(p->slug)) + throw Exception("Plugin %s is already loaded, not attempting to load it again", p->slug.c_str()); + } + + ~StaticPluginLoader() + { + if (rootJ != nullptr) + { + // Load modules manifest + json_t* const modulesJ = json_object_get(rootJ, "modules"); + plugin->modulesFromJson(modulesJ); + + json_decref(rootJ); + plugins.push_back(plugin); + } + + if (file != nullptr) + std::fclose(file); + } + + bool ok() const noexcept + { + return rootJ != nullptr; + } + + void removeModule(const char* const slugToRemove) const noexcept + { + json_t* const modules = json_object_get(rootJ, "modules"); + DISTRHO_SAFE_ASSERT_RETURN(modules != nullptr,); + + size_t i; + json_t* v; + json_array_foreach(modules, i, v) + { + if (json_t* const slug = json_object_get(v, "slug")) + { + if (const char* const value = json_string_value(slug)) + { + if (std::strcmp(value, slugToRemove) == 0) + { + json_array_remove(modules, i); + break; + } + } + } + } + } +}; + +static void initStatic__Cardinal() +{ + Plugin* const p = new Plugin; + pluginInstance__Cardinal = p; + + const StaticPluginLoader spl(p, "Cardinal"); + if (spl.ok()) + { + p->addModel(modelHostAudio2); + p->addModel(modelHostCV); + p->addModel(modelHostMIDI); + p->addModel(modelHostMIDICC); + p->addModel(modelHostMIDIGate); + p->addModel(modelHostMIDIMap); + p->addModel(modelHostParameters); + p->addModel(modelHostParametersMap); + p->addModel(modelHostTime); + p->addModel(modelTextEditor); + #ifdef HAVE_FFTW3F + p->addModel(modelAudioToCVPitch); + #else + spl.removeModule("AudioToCVPitch"); + #endif + spl.removeModule("AudioFile"); + spl.removeModule("Blank"); + spl.removeModule("Carla"); + spl.removeModule("ExpanderInputMIDI"); + spl.removeModule("ExpanderOutputMIDI"); + spl.removeModule("HostAudio8"); + spl.removeModule("Ildaeil"); + spl.removeModule("MPV"); + spl.removeModule("SassyScope"); + spl.removeModule("glBars"); + + hostTerminalModels = { + modelHostAudio2, + modelHostCV, + modelHostMIDI, + modelHostMIDICC, + modelHostMIDIGate, + modelHostMIDIMap, + modelHostParameters, + modelHostParametersMap, + modelHostTime, + }; + } +} + +void initStaticPlugins() +{ + initStatic__Cardinal(); +} + +void destroyStaticPlugins() +{ + for (Plugin* p : plugins) + delete p; + plugins.clear(); +} + +void updateStaticPluginsDarkMode() +{ +} + +} +} diff --git a/src/Cardinal/DistrhoPluginInfo.h b/src/Cardinal/DistrhoPluginInfo.h index df7f955..408f43b 100644 --- a/src/Cardinal/DistrhoPluginInfo.h +++ b/src/Cardinal/DistrhoPluginInfo.h @@ -19,6 +19,7 @@ #define DISTRHO_PLUGIN_INFO_H_INCLUDED #define CARDINAL_VARIANT_MAIN 1 +#define CARDINAL_VARIANT_MINI 0 #define CARDINAL_VARIANT_FX 0 #define CARDINAL_VARIANT_NATIVE 0 #define CARDINAL_VARIANT_SYNTH 0 diff --git a/src/CardinalCommon.cpp b/src/CardinalCommon.cpp index 4de8100..9a71895 100644 --- a/src/CardinalCommon.cpp +++ b/src/CardinalCommon.cpp @@ -57,6 +57,14 @@ # include #endif +#ifndef DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +# error wrong build +#endif + +#if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +# define HEADLESS +#endif + const std::string CARDINAL_VERSION = "22.12"; START_NAMESPACE_DISTRHO diff --git a/src/CardinalFX/DistrhoPluginInfo.h b/src/CardinalFX/DistrhoPluginInfo.h index 9c70212..fef86fc 100644 --- a/src/CardinalFX/DistrhoPluginInfo.h +++ b/src/CardinalFX/DistrhoPluginInfo.h @@ -19,6 +19,7 @@ #define DISTRHO_PLUGIN_INFO_H_INCLUDED #define CARDINAL_VARIANT_MAIN 0 +#define CARDINAL_VARIANT_MINI 0 #define CARDINAL_VARIANT_FX 1 #define CARDINAL_VARIANT_NATIVE 0 #define CARDINAL_VARIANT_SYNTH 0 diff --git a/src/CardinalMini/CardinalCommon.cpp b/src/CardinalMini/CardinalCommon.cpp new file mode 120000 index 0000000..76b4b5f --- /dev/null +++ b/src/CardinalMini/CardinalCommon.cpp @@ -0,0 +1 @@ +../CardinalCommon.cpp \ No newline at end of file diff --git a/src/CardinalMini/CardinalPlugin.cpp b/src/CardinalMini/CardinalPlugin.cpp new file mode 120000 index 0000000..c0c7e71 --- /dev/null +++ b/src/CardinalMini/CardinalPlugin.cpp @@ -0,0 +1 @@ +../CardinalPlugin.cpp \ No newline at end of file diff --git a/src/CardinalMini/CardinalUI.cpp b/src/CardinalMini/CardinalUI.cpp new file mode 120000 index 0000000..5558256 --- /dev/null +++ b/src/CardinalMini/CardinalUI.cpp @@ -0,0 +1 @@ +../CardinalUI.cpp \ No newline at end of file diff --git a/src/CardinalMini/DistrhoPluginInfo.h b/src/CardinalMini/DistrhoPluginInfo.h new file mode 100644 index 0000000..a27e82e --- /dev/null +++ b/src/CardinalMini/DistrhoPluginInfo.h @@ -0,0 +1,55 @@ +/* + * DISTRHO Cardinal Plugin + * Copyright (C) 2021-2022 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the LICENSE file. + */ + +#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED +#define DISTRHO_PLUGIN_INFO_H_INCLUDED + +#define CARDINAL_VARIANT_MAIN 0 +#define CARDINAL_VARIANT_MINI 1 +#define CARDINAL_VARIANT_FX 0 +#define CARDINAL_VARIANT_NATIVE 0 +#define CARDINAL_VARIANT_SYNTH 0 + +#define CARDINAL_NUM_AUDIO_INPUTS 2 +#define CARDINAL_NUM_AUDIO_OUTPUTS 2 + +#define DISTRHO_PLUGIN_BRAND "DISTRHO" +#define DISTRHO_PLUGIN_URI "https://distrho.kx.studio/plugins/cardinal#mini" +#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.cardinal#mini" + +#define DISTRHO_PLUGIN_NAME "Cardinal FX" +#define DISTRHO_PLUGIN_LABEL "CardinalFX" + +#define DISTRHO_PLUGIN_HAS_UI 1 +#define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0 +#define DISTRHO_UI_FILE_BROWSER 1 +#define DISTRHO_UI_USE_NANOVG 1 +#define DISTRHO_UI_USER_RESIZABLE 1 +#define DISTRHO_UI_DEFAULT_WIDTH 1228 +#define DISTRHO_UI_DEFAULT_HEIGHT 666 +#define DISTRHO_PLUGIN_IS_SYNTH 0 +#define DISTRHO_PLUGIN_NUM_INPUTS CARDINAL_NUM_AUDIO_INPUTS +#define DISTRHO_PLUGIN_NUM_OUTPUTS CARDINAL_NUM_AUDIO_OUTPUTS +#define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1 +#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1 +#define DISTRHO_PLUGIN_WANT_FULL_STATE 1 +#define DISTRHO_PLUGIN_WANT_STATE 1 +#define DISTRHO_PLUGIN_WANT_TIMEPOS 1 +#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:UtilityPlugin" +#define DISTRHO_PLUGIN_VST3_CATEGORIES "Fx|Generator" + +#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED diff --git a/src/CardinalMini/Makefile b/src/CardinalMini/Makefile new file mode 100644 index 0000000..24e5043 --- /dev/null +++ b/src/CardinalMini/Makefile @@ -0,0 +1,8 @@ +#!/usr/bin/make -f +# Makefile for DISTRHO Plugins # +# ---------------------------- # +# Created by falkTX +# + +NAME = CardinalMini +include ../Makefile.cardinal.mk diff --git a/src/CardinalMini/RemoteNanoVG.cpp b/src/CardinalMini/RemoteNanoVG.cpp new file mode 120000 index 0000000..a6394af --- /dev/null +++ b/src/CardinalMini/RemoteNanoVG.cpp @@ -0,0 +1 @@ +../custom/RemoteNanoVG.cpp \ No newline at end of file diff --git a/src/CardinalMini/RemoteWindow.cpp b/src/CardinalMini/RemoteWindow.cpp new file mode 120000 index 0000000..7e00fed --- /dev/null +++ b/src/CardinalMini/RemoteWindow.cpp @@ -0,0 +1 @@ +../custom/RemoteWindow.cpp \ No newline at end of file diff --git a/src/CardinalMini/Window.cpp b/src/CardinalMini/Window.cpp new file mode 120000 index 0000000..759f272 --- /dev/null +++ b/src/CardinalMini/Window.cpp @@ -0,0 +1 @@ +../override/Window.cpp \ No newline at end of file diff --git a/src/CardinalMini/common.cpp b/src/CardinalMini/common.cpp new file mode 120000 index 0000000..915948e --- /dev/null +++ b/src/CardinalMini/common.cpp @@ -0,0 +1 @@ +../override/common.cpp \ No newline at end of file diff --git a/src/CardinalMini/glfw.cpp b/src/CardinalMini/glfw.cpp new file mode 120000 index 0000000..8c6a6e4 --- /dev/null +++ b/src/CardinalMini/glfw.cpp @@ -0,0 +1 @@ +../custom/glfw.cpp \ No newline at end of file diff --git a/src/CardinalNative/DistrhoPluginInfo.h b/src/CardinalNative/DistrhoPluginInfo.h index b820481..5cdfbd6 100644 --- a/src/CardinalNative/DistrhoPluginInfo.h +++ b/src/CardinalNative/DistrhoPluginInfo.h @@ -19,6 +19,7 @@ #define DISTRHO_PLUGIN_INFO_H_INCLUDED #define CARDINAL_VARIANT_MAIN 0 +#define CARDINAL_VARIANT_MINI 0 #define CARDINAL_VARIANT_FX 0 #define CARDINAL_VARIANT_NATIVE 1 #define CARDINAL_VARIANT_SYNTH 0 diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index fd26266..f883949 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -647,6 +647,8 @@ protected: { #if CARDINAL_VARIANT_MAIN || CARDINAL_VARIANT_NATIVE return d_cconst('d', 'C', 'd', 'n'); + #elif CARDINAL_VARIANT_MINI + return d_cconst('d', 'C', 'd', 'M'); #elif CARDINAL_VARIANT_FX return d_cconst('d', 'C', 'n', 'F'); #elif CARDINAL_VARIANT_SYNTH @@ -671,7 +673,7 @@ protected: port.hints = kAudioPortIsCV | kCVPortHasPositiveUnipolarRange | kCVPortHasScaledRange | kCVPortIsOptional; index -= 8; } - #elif CARDINAL_VARIANT_FX || CARDINAL_VARIANT_NATIVE || CARDINAL_VARIANT_SYNTH + #elif CARDINAL_VARIANT_MINI || CARDINAL_VARIANT_NATIVE || CARDINAL_VARIANT_FX || CARDINAL_VARIANT_SYNTH if (index < 2) port.groupId = kPortGroupStereo; #endif diff --git a/src/Makefile b/src/Makefile index a3a1f20..ecdbd96 100644 --- a/src/Makefile +++ b/src/Makefile @@ -25,7 +25,11 @@ endif # -------------------------------------------------------------- # Build setup +ifeq ($(HEADLESS),true) +BUILD_DIR = ../build-headless/rack +else BUILD_DIR = ../build/rack +endif ifeq ($(MACOS),true) BASE_FLAGS += -DARCH_MAC @@ -213,14 +217,18 @@ endif # -------------------------------------------------------------- # Build targets -TARGET = rack.a +ifeq ($(HEADLESS),true) +TARGET_SUFFIX = -headless +endif + +TARGETS = rack$(TARGET_SUFFIX).a rack-headless.a ifneq ($(MACOS),true) CARDINAL_FX_ARGS = VST2_FILENAME=Cardinal.vst/CardinalFX$(LIB_EXT) CLAP_FILENAME=Cardinal.clap/CardinalFX.clap CARDINAL_SYNTH_ARGS = VST2_FILENAME=Cardinal.vst/CardinalSynth$(LIB_EXT) CLAP_FILENAME=Cardinal.clap/CardinalSynth.clap endif -all: $(TARGET) +all: $(TARGETS) ifeq ($(MOD_BUILD),true) $(MAKE) -C Cardinal lv2 $(MAKE) -C CardinalFX lv2 @@ -228,37 +236,38 @@ else ifeq ($(WASM),true) $(MAKE) -C CardinalNative else $(MAKE) -C Cardinal + $(MAKE) -C CardinalMini $(MAKE) -C CardinalNative $(MAKE) -C CardinalFX $(CARDINAL_FX_ARGS) $(MAKE) -C CardinalSynth $(CARDINAL_SYNTH_ARGS) endif -jack: $(TARGET) +jack: $(TARGETS) $(MAKE) jack -C Cardinal -native: $(TARGET) +native: $(TARGETS) $(MAKE) jack -C CardinalNative -lv2: $(TARGET) +lv2: $(TARGETS) $(MAKE) lv2 -C Cardinal $(MAKE) lv2 -C CardinalFX $(CARDINAL_FX_ARGS) $(MAKE) lv2 -C CardinalSynth $(CARDINAL_SYNTH_ARGS) -vst2: $(TARGET) +vst2: $(TARGETS) $(MAKE) vst2 -C CardinalFX $(CARDINAL_FX_ARGS) $(MAKE) vst2 -C CardinalSynth $(CARDINAL_SYNTH_ARGS) -vst3: $(TARGET) +vst3: $(TARGETS) $(MAKE) vst3 -C Cardinal $(MAKE) vst3 -C CardinalFX $(CARDINAL_FX_ARGS) $(MAKE) vst3 -C CardinalSynth $(CARDINAL_SYNTH_ARGS) -clap: $(TARGET) +clap: $(TARGETS) $(MAKE) clap -C CardinalFX $(CARDINAL_FX_ARGS) $(MAKE) clap -C CardinalSynth $(CARDINAL_SYNTH_ARGS) clean: - rm -f $(TARGET) + rm -f $(TARGETS) rm -rf $(BUILD_DIR) $(MAKE) clean -C Cardinal $(MAKE) clean -C CardinalFX $(CARDINAL_FX_ARGS) @@ -269,11 +278,16 @@ clean: RACK_OBJS = $(RACK_FILES:%=$(BUILD_DIR)/%.o) -$(TARGET): $(RACK_OBJS) +rack$(TARGET_SUFFIX).a: $(RACK_OBJS) @echo "Creating $@" $(SILENT)rm -f $@ $(SILENT)$(AR) crs $@ $^ +ifneq ($(HEADLESS),true) +rack-headless.a: + $(MAKE) HEADLESS=true $@ +endif + $(BUILD_DIR)/%.c.o: %.c -@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)" @echo "Compiling $<" diff --git a/src/Makefile.cardinal.mk b/src/Makefile.cardinal.mk index 05e9f22..af12cb2 100644 --- a/src/Makefile.cardinal.mk +++ b/src/Makefile.cardinal.mk @@ -8,6 +8,8 @@ ifeq ($(NAME),Cardinal) CARDINAL_VARIANT = main +else ifeq ($(NAME),CardinalMini) +CARDINAL_VARIANT = mini else ifeq ($(NAME),CardinalFX) CARDINAL_VARIANT = fx else ifeq ($(NAME),CardinalNative) @@ -19,6 +21,7 @@ endif # -------------------------------------------------------------- # Carla stuff +ifneq ($(CARDINAL_VARIANT),mini) ifneq ($(STATIC_BUILD),true) STATIC_PLUGIN_TARGET = true @@ -49,6 +52,7 @@ CARLA_EXTRA_LIBS += $(CARLA_BUILD_DIR)/modules/$(CARLA_BUILD_TYPE)/ysfx.a CARLA_EXTRA_LIBS += $(CARLA_BUILD_DIR)/modules/$(CARLA_BUILD_TYPE)/zita-resampler.a endif # STATIC_BUILD +endif # CARDINAL_VARIANT mini # -------------------------------------------------------------- # Import base definitions @@ -64,7 +68,7 @@ ifeq ($(CARDINAL_VARIANT),main) # main variant should not use rtaudio/sdl2 fallback (it has CV ports) SKIP_NATIVE_AUDIO_FALLBACK = true else -# fx and synth variants should only use rtaudio/sdl2 fallbacks +# other variants should only use rtaudio/sdl2 fallbacks FORCE_NATIVE_AUDIO_FALLBACK = true endif @@ -94,7 +98,10 @@ FILES_DSP = CardinalPlugin.cpp FILES_DSP += CardinalCommon.cpp FILES_DSP += common.cpp -ifeq ($(HEADLESS),true) +ifeq ($(CARDINAL_VARIANT),mini) +FILES_DSP += RemoteNanoVG.cpp +FILES_DSP += RemoteWindow.cpp +else ifeq ($(HEADLESS),true) FILES_DSP += RemoteNanoVG.cpp FILES_DSP += RemoteWindow.cpp else @@ -110,12 +117,24 @@ endif # -------------------------------------------------------------- # Extra libraries to link against -ifeq ($(NOPLUGINS),true) -RACK_EXTRA_LIBS = ../../plugins/noplugins.a +ifeq ($(HEADLESS),true) +TARGET_SUFFIX = -headless +endif + +ifeq ($(CARDINAL_VARIANT),mini) +RACK_EXTRA_LIBS = ../../plugins/plugins-mini-headless.a +else ifeq ($(NOPLUGINS),true) +RACK_EXTRA_LIBS = ../../plugins/noplugins$(TARGET_SUFFIX).a +else +RACK_EXTRA_LIBS = ../../plugins/plugins$(TARGET_SUFFIX).a +endif + +ifeq ($(CARDINAL_VARIANT),mini) +RACK_EXTRA_LIBS += ../rack-headless.a else -RACK_EXTRA_LIBS = ../../plugins/plugins.a +RACK_EXTRA_LIBS += ../rack$(TARGET_SUFFIX).a endif -RACK_EXTRA_LIBS += ../rack.a + RACK_EXTRA_LIBS += $(DEP_LIB_PATH)/libquickjs.a ifneq ($(SYSDEPS),true) @@ -133,6 +152,7 @@ endif # -------------------------------------------------------------- # surgext libraries +ifneq ($(CARDINAL_VARIANT),mini) ifneq ($(NOPLUGINS),true) SURGE_DEP_PATH = $(abspath ../../deps/surge-build) RACK_EXTRA_LIBS += $(SURGE_DEP_PATH)/src/common/libsurge-common.a @@ -152,6 +172,7 @@ endif RACK_EXTRA_LIBS += $(SURGE_DEP_PATH)/libs/sst/sst-plugininfra/libs/strnatcmp/libstrnatcmp.a RACK_EXTRA_LIBS += $(SURGE_DEP_PATH)/libs/sst/sst-plugininfra/libs/tinyxml/libtinyxml.a endif +endif # -------------------------------------------------------------- @@ -162,18 +183,18 @@ STATIC_CARLA_PLUGIN_LIBS = -lsndfile -lopus -lFLAC -lvorbisenc -lvorbis -logg -l endif endif -EXTRA_DEPENDENCIES = $(RACK_EXTRA_LIBS) $(CARLA_EXTRA_LIBS) -EXTRA_LIBS = $(RACK_EXTRA_LIBS) $(CARLA_EXTRA_LIBS) $(STATIC_CARLA_PLUGIN_LIBS) +EXTRA_DSP_DEPENDENCIES = $(RACK_EXTRA_LIBS) $(CARLA_EXTRA_LIBS) +EXTRA_DSP_LIBS = $(RACK_EXTRA_LIBS) $(CARLA_EXTRA_LIBS) $(STATIC_CARLA_PLUGIN_LIBS) ifeq ($(shell $(PKG_CONFIG) --exists fftw3f && echo true),true) -EXTRA_DEPENDENCIES += ../../deps/aubio/libaubio.a -EXTRA_LIBS += ../../deps/aubio/libaubio.a -EXTRA_LIBS += $(shell $(PKG_CONFIG) --libs fftw3f) +EXTRA_DSP_DEPENDENCIES += ../../deps/aubio/libaubio.a +EXTRA_DSP_LIBS += ../../deps/aubio/libaubio.a +EXTRA_DSP_LIBS += $(shell $(PKG_CONFIG) --libs fftw3f) endif ifneq ($(NOPLUGINS),true) ifeq ($(MACOS),true) -EXTRA_LIBS += -framework Accelerate +EXTRA_DSP_LIBS += -framework Accelerate endif endif @@ -216,9 +237,22 @@ ifneq ($(STATIC_BUILD),true) WASM_RESOURCES += $(CURDIR)/lv2/fomp.lv2/manifest.ttl endif -EXTRA_DEPENDENCIES += $(WASM_RESOURCES) +EXTRA_DSP_DEPENDENCIES += $(WASM_RESOURCES) endif +# -------------------------------------------------------------- +# mini variant UI + +# ifeq ($(CARDINAL_VARIANT),mini) +# ifneq ($(HEADLESS)$(MOD_BUILD),true) +# FILES_UI = CardinalUI.cpp +# FILES_UI += glfw.cpp +# FILES_UI += Window.cpp +# EXTRA_UI_DEPENDENCIES = $(subst -headless,,$(EXTRA_DSP_DEPENDENCIES)) +# EXTRA_UI_LIBS = $(subst -headless,,$(EXTRA_DSP_LIBS)) +# endif +# endif + # -------------------------------------------------------------- # Do some magic @@ -370,13 +404,13 @@ ifeq ($(MACOS),true) LINK_FLAGS += -framework IOKit else ifeq ($(WINDOWS),true) # needed by VCVRack -EXTRA_LIBS += -ldbghelp -lshlwapi -Wl,--stack,0x100000 +EXTRA_DSP_LIBS += -ldbghelp -lshlwapi -Wl,--stack,0x100000 # needed by JW-Modules -EXTRA_LIBS += -lws2_32 -lwinmm +EXTRA_DSP_LIBS += -lws2_32 -lwinmm endif ifeq ($(SYSDEPS),true) -EXTRA_LIBS += $(shell $(PKG_CONFIG) --libs jansson libarchive samplerate speexdsp) +EXTRA_DSP_LIBS += $(shell $(PKG_CONFIG) --libs jansson libarchive samplerate speexdsp) endif ifeq ($(WITH_LTO),true) @@ -393,7 +427,7 @@ endif ifeq ($(HAVE_LIBLO),true) BASE_FLAGS += $(LIBLO_FLAGS) -LINK_FLAGS += $(LIBLO_LIBS) +EXTRA_DSP_LIBS += $(LIBLO_LIBS) endif # -------------------------------------------------------------- @@ -422,10 +456,9 @@ BUILD_CXX_FLAGS += -DCARDINAL_PLUGIN_PREFIX='"$(PREFIX)"' # Enable all possible plugin types and setup resources ifeq ($(CARDINAL_VARIANT),main) -TARGETS = lv2 vst3 clap -ifeq ($(HAVE_JACK),true) -TARGETS += jack -endif +TARGETS = jack lv2 vst3 clap +else ifeq ($(CARDINAL_VARIANT),mini) +TARGETS = lv2_sep else ifeq ($(CARDINAL_VARIANT),native) TARGETS = jack else diff --git a/src/PluginContext.hpp b/src/PluginContext.hpp index 933d416..1b51333 100644 --- a/src/PluginContext.hpp +++ b/src/PluginContext.hpp @@ -40,6 +40,7 @@ static constexpr const uint kModuleParameters = 24; enum CardinalVariant { kCardinalVariantMain, + kCardinalVariantMini, kCardinalVariantFX, kCardinalVariantNative, kCardinalVariantSynth, @@ -74,6 +75,8 @@ struct CardinalPluginContext : rack::Context { sampleRate(p != nullptr ? p->getSampleRate() : 0.0), #if CARDINAL_VARIANT_MAIN variant(kCardinalVariantMain), + #elif CARDINAL_VARIANT_MINI + variant(kCardinalVariantMini), #elif CARDINAL_VARIANT_FX variant(kCardinalVariantFX), #elif CARDINAL_VARIANT_NATIVE @@ -162,7 +165,11 @@ public: CardinalBaseUI(const uint width, const uint height) : UI(width, height), + #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS context(getRackContextFromPlugin(getPluginInstancePointer())), + #else + context(new CardinalPluginContext(nullptr)), + #endif saving(false), savingUncompressed(false), #ifdef DISTRHO_OS_WASM @@ -182,6 +189,9 @@ public: context->tlw = nullptr; context->ui = nullptr; + #if !DISTRHO_PLUGIN_WANT_DIRECT_ACCESS + delete context; + #endif } }; #endif diff --git a/src/custom/RemoteNanoVG.cpp b/src/custom/RemoteNanoVG.cpp index a299cf0..ef7c653 100644 --- a/src/custom/RemoteNanoVG.cpp +++ b/src/custom/RemoteNanoVG.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * Copyright (C) 2021-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -15,8 +15,18 @@ * For a full copy of the GNU General Public License see the LICENSE file. */ +#include "DistrhoPluginInfo.h" + +#ifndef DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +# error wrong build +#endif + +#if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +# define HEADLESS +#endif + #ifndef HEADLESS -#include "OpenGL.hpp" +# include "OpenGL.hpp" #endif #include "nanovg.h"