Browse Source

Setup plugin resources to build, cleanup

tags/22.02
falkTX 3 years ago
parent
commit
739359430a
4 changed files with 179 additions and 30 deletions
  1. +34
    -1
      plugins/Makefile
  2. +94
    -29
      plugins/plugins.cpp
  3. +49
    -0
      plugins/res2c.py
  4. +2
    -0
      src/Makefile

+ 34
- 1
plugins/Makefile View File

@@ -5,6 +5,7 @@
#

DEP_PATH = $(abspath ../src/Rack/dep)
OBJCOPY ?= objcopy

# --------------------------------------------------------------
# Import base definitions
@@ -20,16 +21,25 @@ PLUGIN_FILES = plugins.cpp

# Befaco
PLUGIN_FILES += $(filter-out Befaco/src/plugin.cpp,$(wildcard Befaco/src/*.cpp))
PLUGIN_BINARIES += Befaco/src/SpringReverbIR.pcm

# Fundamental
PLUGIN_FILES += $(filter-out Fundamental/src/plugin.cpp,$(wildcard Fundamental/src/*.cpp))

# --------------------------------------------------------------
# Resources to symlink

# TODO
# PLUGIN_RESOURCES = res/Befaco/res
# PLUGIN_RESOURCES = res/Befaco/res

# --------------------------------------------------------------
# Build setup

BUILD_DIR = ../build/plugins

PLUGIN_OBJS = $(PLUGIN_FILES:%=$(BUILD_DIR)/%.o)
PLUGIN_OBJS = $(PLUGIN_FILES:%=$(BUILD_DIR)/%.o)
PLUGIN_OBJS += $(PLUGIN_BINARIES:%=$(BUILD_DIR)/%.bin.o)

ifeq ($(MACOS),true)
BASE_FLAGS += -DARCH_MAC
@@ -42,6 +52,7 @@ endif
BUILD_C_FLAGS += -std=gnu11

BASE_FLAGS += -I../dpf/dgl/src/nanovg
BASE_FLAGS += -I../dpf/distrho
BASE_FLAGS += -I../src
BASE_FLAGS += -I../src/neon-compat
BASE_FLAGS += -I../src/Rack/include
@@ -56,8 +67,10 @@ BASE_FLAGS += -I../src/Rack/dep/pffft
BASE_FLAGS += -pthread

ifeq ($(WINDOWS),true)
BASE_FLAGS += -D_USE_MATH_DEFINES
BASE_FLAGS += -Imingw-compat
BASE_FLAGS += -Imingw-std-threads
BASE_FLAGS += -municode
endif

# --------------------------------------------------------------
@@ -66,6 +79,20 @@ endif
BASE_FLAGS += -Wno-unused-parameter
BASE_FLAGS += -Wno-unused-variable

# also lots of plugins not updated to v2 yet
BASE_FLAGS += -Wno-deprecated-declarations

# --------------------------------------------------------------
# temporary macro just to get the ball rolling

ifeq ($(EXE_WRAPPER),wine)
PLUGINS_DIR = Z:$(subst /,\\,$(CURDIR))
else
PLUGINS_DIR = $(CURDIR)
endif

BUILD_CXX_FLAGS += -DCARDINAL_PLUGINS_DIR='"$(PLUGINS_DIR)"'

# --------------------------------------------------------------
# Build targets

@@ -100,6 +127,12 @@ $(BUILD_DIR)/Fundamental/%.cpp.o: Fundamental/%.cpp
@echo "Compiling $<"
$(SILENT)$(CXX) $< $(BUILD_CXX_FLAGS) -DpluginInstance=pluginInstance__Fundamental -c -o $@

# copied and adjusted from VCVRack's compile.mk
$(BUILD_DIR)/%.bin.o: % res2c.py
-@mkdir -p "$(shell dirname $(BUILD_DIR)/$<)"
@echo "Generating and Compiling $<"
$(shell ./res2c.py $< | $(CC) -x c - $(BUILD_C_FLAGS) -c -o $@)

# --------------------------------------------------------------

-include $(PLUGIN_OBJS:%.o=%.d)


+ 94
- 29
plugins/plugins.cpp View File

@@ -17,6 +17,9 @@

#include <plugin.hpp>

#include "DistrhoUtils.hpp"

#include "Befaco/src/plugin.hpp"
#include "Fundamental/src/plugin.hpp"

Plugin* pluginInstance__Befaco;
@@ -25,45 +28,107 @@ Plugin* pluginInstance__Fundamental;
namespace rack {
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)
{
p->path = system::join(CARDINAL_PLUGINS_DIR, name);

const std::string manifestFilename = system::join(p->path, "plugin.json");

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;
}
}

~StaticPluginLoader()
{
if (rootJ != nullptr)
{
plugin->fromJson(rootJ);
json_decref(rootJ);
plugins.push_back(plugin);
}

if (file != nullptr)
std::fclose(file);
}

bool ok() const noexcept
{
return rootJ != nullptr;
}
};

static void initStatic__Befaco()
{
Plugin* p = new Plugin;
pluginInstance__Befaco = p;
plugins.push_back(p);

const StaticPluginLoader spl(p, "Befaco");
if (spl.ok())
{
p->addModel(modelEvenVCO);
p->addModel(modelRampage);
p->addModel(modelABC);
p->addModel(modelSpringReverb);
p->addModel(modelMixer);
p->addModel(modelSlewLimiter);
p->addModel(modelDualAtenuverter);
}
}

static void initStatic__Fundamental()
{
Plugin* p = new Plugin;
pluginInstance__Fundamental = p;
p->addModel(modelVCO);
p->addModel(modelVCO2);
p->addModel(modelVCF);
p->addModel(modelVCA_1);
p->addModel(modelVCA);
p->addModel(modelLFO);
p->addModel(modelLFO2);
p->addModel(modelDelay);
p->addModel(modelADSR);
p->addModel(modelVCMixer);
p->addModel(model_8vert);
p->addModel(modelUnity);
p->addModel(modelMutes);
p->addModel(modelPulses);
p->addModel(modelScope);
p->addModel(modelSEQ3);
p->addModel(modelSequentialSwitch1);
p->addModel(modelSequentialSwitch2);
p->addModel(modelOctave);
p->addModel(modelQuantizer);
p->addModel(modelSplit);
p->addModel(modelMerge);
p->addModel(modelSum);
p->addModel(modelViz);
p->addModel(modelMidSide);
p->addModel(modelNoise);
p->addModel(modelRandom);
plugins.push_back(p);

const StaticPluginLoader spl(p, "Fundamental");
if (spl.ok())
{
p->addModel(modelVCO);
p->addModel(modelVCO2);
p->addModel(modelVCF);
p->addModel(modelVCA_1);
p->addModel(modelVCA);
p->addModel(modelLFO);
p->addModel(modelLFO2);
p->addModel(modelDelay);
p->addModel(modelADSR);
p->addModel(modelVCMixer);
p->addModel(model_8vert);
p->addModel(modelUnity);
p->addModel(modelMutes);
p->addModel(modelPulses);
p->addModel(modelScope);
p->addModel(modelSEQ3);
p->addModel(modelSequentialSwitch1);
p->addModel(modelSequentialSwitch2);
p->addModel(modelOctave);
p->addModel(modelQuantizer);
p->addModel(modelSplit);
p->addModel(modelMerge);
p->addModel(modelSum);
p->addModel(modelViz);
p->addModel(modelMidSide);
p->addModel(modelNoise);
p->addModel(modelRandom);
}
}

void initStaticPlugins()


+ 49
- 0
plugins/res2c.py View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# DISTRHO Plugin Framework (DPF)
# Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with
# or without fee is hereby granted, provided that the above copyright notice and this
# permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
# TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
# NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import os
import sys

# -----------------------------------------------------

def res2c(filename):
resname = "src_" + os.path.basename(filename.replace(".","_"))
fhandle = open(filename, 'rb')
resdata = fhandle.read()

print("const unsigned char %s[] = {\n" % resname)
for data in resdata:
print(" %3u," % data)
print("};\n")

print("const unsigned int %s_len = %d;\n" % (resname, fhandle.tell()))

# -----------------------------------------------------

if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: %s <filename>" % sys.argv[0])
quit()

filename = sys.argv[1]

if not os.path.exists(filename):
print("Folder '%s' does not exist" % filename)
quit()

# dump code now
res2c(filename)

+ 2
- 0
src/Makefile View File

@@ -97,8 +97,10 @@ BASE_FLAGS += -Ineon-compat
BASE_FLAGS += -pthread

ifeq ($(WINDOWS),true)
BASE_FLAGS += -D_USE_MATH_DEFINES
BASE_FLAGS += -Imingw-compat
BASE_FLAGS += -Imingw-std-threads
BASE_FLAGS += -municode
endif

BUILD_C_FLAGS += -std=gnu11


Loading…
Cancel
Save