Initial work towards a mini variant, WIP

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-12-25 22:28:36 +00:00
parent c0fc6cd78b
commit cf74324568
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
23 changed files with 452 additions and 44 deletions

View file

@ -41,6 +41,7 @@ static constexpr const uint32_t kModuleParameters = 24;
enum CardinalVariant {
kCardinalVariantMain,
kCardinalVariantMini,
kCardinalVariantFX,
kCardinalVariantNative,
kCardinalVariantSynth,

View file

@ -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 ($(NOPLUGINS),true)
TARGET = noplugins.a
else
TARGET = plugins.a
ifeq ($(HEADLESS),true)
TARGET_SUFFIX = -headless
endif
all: $(TARGET)
ifeq ($(NOPLUGINS),true)
TARGETS = noplugins$(TARGET_SUFFIX).a
else
TARGETS = plugins$(TARGET_SUFFIX).a plugins-mini-headless.a
endif
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 $@ $^
noplugins.a: $(NOPLUGIN_OBJS)
plugins-mini$(TARGET_SUFFIX).a: $(MINIPLUGIN_OBJS)
@echo "Creating $@"
$(SILENT)rm -f $@
$(SILENT)$(AR) crs $@ $^
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 $<"

195
plugins/plugins-mini.cpp Normal file
View file

@ -0,0 +1,195 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
*
* 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<Model*> 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()
{
}
}
}