233 changes: 233 additions & 0 deletions Makefile.mk
@@ -0,0 +1,233 @@
#!/usr/bin/make -f
# Makefile for native-plugins #
# --------------------------- #
# Created by falkTX
#

ifeq ($(TESTBUILD),true)
ifeq ($(LINUX),true)
CXXFLAGS += -isystem /opt/kxstudio/include/ntk
endif
endif

ifeq ($(MACOS_OR_WIN32),true)
HAVE_DGL = true
SKIP_ZYN_SYNTH = true
else
HAVE_DGL = $(shell pkg-config --exists gl x11 && echo true)
endif

HAVE_NTK = $(shell pkg-config --exists ntk ntk_images && echo true)
HAVE_PROJECTM = $(shell pkg-config --exists libprojectM && echo true)
ifneq ($(MACOS_OLD),true)
HAVE_ZYN_DEPS = $(shell pkg-config --exists liblo fftw3 mxml zlib && echo true)
endif

# ---------------------------------------------------------------------------------------------------------------------
# Check for optional libs (special non-pkgconfig unix tests)

ifeq ($(UNIX),true)

# fltk doesn't have a pkg-config file but has fltk-config instead.
# Also, don't try looking for it if we already have NTK.
ifneq ($(HAVE_NTK),true)
ifeq ($(shell which fltk-config 1>/dev/null 2>/dev/null && echo true),true)
ifeq ($(shell which fluid 1>/dev/null 2>/dev/null && echo true),true)
HAVE_FLTK = true
endif
endif
endif

endif

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

ifeq ($(HAVE_FLTK),true)
HAVE_ZYN_UI_DEPS = true
endif
ifeq ($(HAVE_NTK),true)
HAVE_ZYN_UI_DEPS = true
endif

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

ifeq ($(HAVE_DGL),true)
BASE_FLAGS += -DHAVE_DGL
endif

ifeq ($(HAVE_PROJECTM),true)
BASE_FLAGS += -DHAVE_PROJECTM
endif

ifeq ($(HAVE_ZYN_DEPS),true)
BASE_FLAGS += -DHAVE_ZYN_DEPS
ifeq ($(HAVE_ZYN_UI_DEPS),true)
BASE_FLAGS += -DHAVE_ZYN_UI_DEPS
endif
endif

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

ifeq ($(HAVE_DGL),true)

ifeq ($(MACOS_OR_WIN32),true)
ifeq ($(MACOS),true)
DGL_LIBS = -framework OpenGL -framework Cocoa
endif
ifeq ($(WIN32),true)
DGL_LIBS = -lopengl32 -lgdi32
endif
else

DGL_FLAGS = $(shell pkg-config --cflags gl x11)
DGL_LIBS = $(shell pkg-config --libs gl x11)
endif

DGL_FLAGS += -DDGL_NAMESPACE=CarlaDGL -DDGL_FILE_BROWSER_DISABLED -DDGL_NO_SHARED_RESOURCES
endif

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

ifeq ($(HAVE_PROJECTM),true)
PROJECTM_FLAGS = $(shell pkg-config --cflags libprojectM)
PROJECTM_LIBS = $(shell pkg-config --libs libprojectM)
endif

# ---------------------------------------------------------------------------------------------------------------------
# Flags for DPF Plugins

DPF_FLAGS = -I$(CWDE)/modules/distrho

ifeq ($(HAVE_DGL),true)
ifneq ($(MACOS_OR_WIN32),true)
DPF_FLAGS += $(shell pkg-config --cflags gl)
endif
DPF_FLAGS += -I$(CWDE)/modules/dgl -DDGL_NAMESPACE=CarlaDGL -DDGL_FILE_BROWSER_DISABLED -DDGL_NO_SHARED_RESOURCES
endif

# ---------------------------------------------------------------------------------------------------------------------
# Flags for ZynAddSubFX (DSP and UI separated)

ifeq ($(HAVE_ZYN_DEPS),true)

# Common flags
ZYN_BASE_FLAGS = $(shell pkg-config --cflags liblo mxml)
ZYN_BASE_FLAGS += -Iexternal/zynaddsubfx -Iexternal/zynaddsubfx/rtosc
ifneq ($(WIN32),true)
ZYN_BASE_FLAGS += -DHAVE_ASYNC
endif

ZYN_BASE_LIBS = $(shell pkg-config --libs liblo mxml) -lpthread
ZYN_BASE_LIBS += $(LIBDL_LIBS)

# DSP flags
ZYN_DSP_FLAGS = $(ZYN_BASE_FLAGS)
ZYN_DSP_FLAGS += $(shell pkg-config --cflags fftw3 zlib)
ZYN_DSP_LIBS = $(ZYN_BASE_LIBS)
ZYN_DSP_LIBS += $(shell pkg-config --libs fftw3 zlib)

ifeq ($(SKIP_ZYN_SYNTH),true)
BASE_FLAGS += -DSKIP_ZYN_SYNTH
else
# UI flags
ifeq ($(HAVE_ZYN_UI_DEPS),true)

# Common UI flags
ZYN_UI_FLAGS = $(ZYN_BASE_FLAGS)
ZYN_UI_LIBS = $(ZYN_BASE_LIBS)

# NTK or FLTK UI flags
ifeq ($(HAVE_NTK),true)
FLUID = ntk-fluid
ZYN_UI_FLAGS += $(shell pkg-config --cflags ntk_images ntk) -DNTK_GUI
ZYN_UI_LIBS += $(shell pkg-config --libs ntk_images ntk)
else # HAVE_NTK
FLUID = fluid
ZYN_UI_FLAGS += $(shell fltk-config --use-images --cxxflags) -DFLTK_GUI
ZYN_UI_LIBS += $(shell fltk-config --use-images --ldflags)
endif # HAVE_NTK

# UI extra flags
ifeq ($(HAVE_X11),true)
ZYN_UI_FLAGS += $(shell pkg-config --cflags x11)
ZYN_UI_LIBS += $(shell pkg-config --libs x11)
endif
ifeq ($(LINUX),true)
ZYN_UI_LIBS += -lrt
endif

else # HAVE_ZYN_UI_DEPS

ZYN_DSP_FLAGS += -DNO_UI

endif # SKIP_ZYN_SYNTH
endif # HAVE_ZYN_UI_DEPS
endif # HAVE_ZYN_DEPS

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

NATIVE_PLUGINS_LIBS += $(DGL_LIBS)
NATIVE_PLUGINS_LIBS += $(PROJECTM_LIBS)
NATIVE_PLUGINS_LIBS += $(ZYN_DSP_LIBS)
NATIVE_PLUGINS_LIBS += $(ZITA_DSP_LIBS)

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

ifeq ($(HAVE_DGL),true)
ALL_LIBS += $(MODULEDIR)/dgl.a
endif

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

all:

install_external_plugins:
ifeq ($(HAVE_ZYN_DEPS),true)
ifeq ($(HAVE_ZYN_UI_DEPS),true)
# Create directories (zynaddsubfx)
install -d $(DESTDIR)$(DATADIR)/carla/resources/zynaddsubfx

# Install resources (zynaddsubfx)
install -m 644 \
bin/resources/zynaddsubfx/*.png \
$(DESTDIR)$(DATADIR)/carla/resources/zynaddsubfx

install -m 755 \
bin/resources/zynaddsubfx-ui \
$(DESTDIR)$(DATADIR)/carla/resources
endif
endif

features_print_external_plugins:
@printf -- "\n"
@printf -- "$(tS)---> External plugins: $(tE)\n"
ifeq ($(HAVE_DGL),true)
@printf -- "DPF Plugins: $(ANS_YES) (with UI)\n"
ifeq ($(HAVE_PROJECTM),true)
@printf -- "DPF ProM: $(ANS_YES)\n"
else
@printf -- "DPF ProM: $(ANS_NO) $(mS)missing libprojectM$(mE)\n"
endif
else
@printf -- "DPF Plugins: $(ANS_YES) (without UI)\n"
ifeq ($(HAVE_PROJECTM),true)
@printf -- "DPF ProM: $(ANS_NO) $(mS)missing OpenGL$(mE)\n"
else
@printf -- "DPF ProM: $(ANS_NO) $(mS)missing OpenGL and libprojectM$(mE)\n"
endif
endif
ifeq ($(HAVE_ZYN_DEPS),true)
ifeq ($(HAVE_ZYN_UI_DEPS),true)
ifeq ($(HAVE_NTK),true)
@printf -- "ZynAddSubFX: $(ANS_YES) (with NTK UI)\n"
else
@printf -- "ZynAddSubFX: $(ANS_YES) (with FLTK UI)\n"
endif
else
@printf -- "ZynAddSubFX: $(ANS_YES) (without UI) $(mS)FLTK or NTK missing$(mE)\n"
endif
else
@printf -- "ZynAddSubFX: $(ANS_NO) $(mS)liblo, fftw3, mxml or zlib missing$(mE)\n"
endif

# ---------------------------------------------------------------------------------------------------------------------
66 changes: 66 additions & 0 deletions _all.c
@@ -0,0 +1,66 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2018 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 2 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 doc/GPL.txt file.
*/

#include "CarlaDefines.h"
#include "CarlaNative.h"

// --------------------------------------------------------------------------------------------------------------------

// DISTRHO plugins
extern void carla_register_native_plugin_distrho_3bandeq(void);
extern void carla_register_native_plugin_distrho_3bandsplitter(void);
extern void carla_register_native_plugin_distrho_kars(void);
extern void carla_register_native_plugin_distrho_nekobi(void);
extern void carla_register_native_plugin_distrho_pingpongpan(void);
extern void carla_register_native_plugin_distrho_prom(void);

// DISTRHO plugins (Juice)
extern void carla_register_native_plugin_distrho_vectorjuice(void);
extern void carla_register_native_plugin_distrho_wobblejuice(void);

// ZynAddSubFX
extern void carla_register_native_plugin_zynaddsubfx_fx(void);
extern void carla_register_native_plugin_zynaddsubfx_synth(void);

// --------------------------------------------------------------------------------------------------------------------

void carla_register_all_native_external_plugins(void)
{
// DISTRHO Plugins
carla_register_native_plugin_distrho_3bandeq();
carla_register_native_plugin_distrho_3bandsplitter();
carla_register_native_plugin_distrho_kars();
carla_register_native_plugin_distrho_nekobi();
carla_register_native_plugin_distrho_pingpongpan();
#if defined(HAVE_DGL) && defined(HAVE_PROJECTM)
carla_register_native_plugin_distrho_prom();
#endif

// DISTRHO plugins (Juice)
carla_register_native_plugin_distrho_vectorjuice();
carla_register_native_plugin_distrho_wobblejuice();

#ifdef HAVE_ZYN_DEPS
// ZynAddSubFX
carla_register_native_plugin_zynaddsubfx_fx();
# ifndef SKIP_ZYN_SYNTH
carla_register_native_plugin_zynaddsubfx_synth();
# endif
#endif
}

// --------------------------------------------------------------------------------------------------------------------
470 changes: 470 additions & 0 deletions _data.cpp

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions distrho-3bandeq.cpp
@@ -0,0 +1,85 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 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 2 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 doc/GPL.txt file.
*/

// config fix
#include "distrho-3bandeq/DistrhoPluginInfo.h"

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL)
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#include "CarlaMathUtils.hpp"
#include "CarlaJuceUtils.hpp"

// Plugin Code
#include "distrho-3bandeq/DistrhoArtwork3BandEQ.cpp"
#include "distrho-3bandeq/DistrhoPlugin3BandEQ.cpp"
#ifdef HAVE_DGL
#include "distrho-3bandeq/DistrhoUI3BandEQ.cpp"
#endif

// DISTRHO Code
#define DISTRHO_PLUGIN_TARGET_CARLA
#include "DistrhoPluginMain.cpp"
#ifdef HAVE_DGL
#include "DistrhoUIMain.cpp"
#endif

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

static const NativePluginDescriptor _3bandeqDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_EQ,
#ifdef HAVE_DGL
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
#else
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE),
#endif
/* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 0,
/* midiOuts */ 0,
/* paramIns */ DistrhoPlugin3BandEQ::paramCount,
/* paramOuts */ 0,
/* name */ DISTRHO_PLUGIN_NAME,
/* label */ "3bandeq",
/* maker */ "falkTX, Michael Gruhn",
/* copyright */ "LGPL",
PluginDescriptorFILL(PluginCarla)
};

END_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

CARLA_EXPORT
void carla_register_native_plugin_distrho_3bandeq();

CARLA_EXPORT
void carla_register_native_plugin_distrho_3bandeq()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&_3bandeqDesc);
}

// -----------------------------------------------------------------------
10,107 changes: 10,107 additions & 0 deletions distrho-3bandeq/DistrhoArtwork3BandEQ.cpp

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions distrho-3bandeq/DistrhoArtwork3BandEQ.hpp
@@ -0,0 +1,40 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_DISTRHOARTWORK3BANDEQ_HPP
#define BINARY_DISTRHOARTWORK3BANDEQ_HPP

namespace DistrhoArtwork3BandEQ
{
extern const char* aboutData;
const unsigned int aboutDataSize = 172710;
const unsigned int aboutWidth = 303;
const unsigned int aboutHeight = 190;

extern const char* aboutButtonHoverData;
const unsigned int aboutButtonHoverDataSize = 5888;
const unsigned int aboutButtonHoverWidth = 92;
const unsigned int aboutButtonHoverHeight = 16;

extern const char* aboutButtonNormalData;
const unsigned int aboutButtonNormalDataSize = 5888;
const unsigned int aboutButtonNormalWidth = 92;
const unsigned int aboutButtonNormalHeight = 16;

extern const char* backgroundData;
const unsigned int backgroundDataSize = 437472;
const unsigned int backgroundWidth = 392;
const unsigned int backgroundHeight = 372;

extern const char* knobData;
const unsigned int knobDataSize = 15376;
const unsigned int knobWidth = 62;
const unsigned int knobHeight = 62;

extern const char* sliderData;
const unsigned int sliderDataSize = 6000;
const unsigned int sliderWidth = 50;
const unsigned int sliderHeight = 30;
}

#endif // BINARY_DISTRHOARTWORK3BANDEQ_HPP

264 changes: 264 additions & 0 deletions distrho-3bandeq/DistrhoPlugin3BandEQ.cpp
@@ -0,0 +1,264 @@
/*
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPlugin3BandEQ.hpp"

#include <cmath>

static const float kAMP_DB = 8.656170245f;
static const float kDC_ADD = 1e-30f;
static const float kPI = 3.141592654f;

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

DistrhoPlugin3BandEQ::DistrhoPlugin3BandEQ()
: Plugin(paramCount, 1, 0) // 1 program, 0 states
{
// set default values
loadProgram(0);

// reset
deactivate();
}

// -----------------------------------------------------------------------
// Init

void DistrhoPlugin3BandEQ::initParameter(uint32_t index, Parameter& parameter)
{
switch (index)
{
case paramLow:
parameter.hints = kParameterIsAutomable;
parameter.name = "Low";
parameter.symbol = "low";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramMid:
parameter.hints = kParameterIsAutomable;
parameter.name = "Mid";
parameter.symbol = "mid";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramHigh:
parameter.hints = kParameterIsAutomable;
parameter.name = "High";
parameter.symbol = "high";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramMaster:
parameter.hints = kParameterIsAutomable;
parameter.name = "Master";
parameter.symbol = "master";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramLowMidFreq:
parameter.hints = kParameterIsAutomable;
parameter.name = "Low-Mid Freq";
parameter.symbol = "low_mid";
parameter.unit = "Hz";
parameter.ranges.def = 440.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1000.0f;
break;

case paramMidHighFreq:
parameter.hints = kParameterIsAutomable;
parameter.name = "Mid-High Freq";
parameter.symbol = "mid_high";
parameter.unit = "Hz";
parameter.ranges.def = 1000.0f;
parameter.ranges.min = 1000.0f;
parameter.ranges.max = 20000.0f;
break;
}
}

void DistrhoPlugin3BandEQ::initProgramName(uint32_t index, String& programName)
{
if (index != 0)
return;

programName = "Default";
}

// -----------------------------------------------------------------------
// Internal data

float DistrhoPlugin3BandEQ::getParameterValue(uint32_t index) const
{
switch (index)
{
case paramLow:
return fLow;
case paramMid:
return fMid;
case paramHigh:
return fHigh;
case paramMaster:
return fMaster;
case paramLowMidFreq:
return fLowMidFreq;
case paramMidHighFreq:
return fMidHighFreq;
default:
return 0.0f;
}
}

void DistrhoPlugin3BandEQ::setParameterValue(uint32_t index, float value)
{
if (getSampleRate() <= 0.0)
return;

switch (index)
{
case paramLow:
fLow = value;
lowVol = std::exp( (fLow/48.0f) * 48.0f / kAMP_DB);
break;
case paramMid:
fMid = value;
midVol = std::exp( (fMid/48.0f) * 48.0f / kAMP_DB);
break;
case paramHigh:
fHigh = value;
highVol = std::exp( (fHigh/48.0f) * 48.0f / kAMP_DB);
break;
case paramMaster:
fMaster = value;
outVol = std::exp( (fMaster/48.0f) * 48.0f / kAMP_DB);
break;
case paramLowMidFreq:
fLowMidFreq = std::fmin(value, fMidHighFreq);
freqLP = fLowMidFreq;
xLP = std::exp(-2.0f * kPI * freqLP / (float)getSampleRate());
a0LP = 1.0f - xLP;
b1LP = -xLP;
break;
case paramMidHighFreq:
fMidHighFreq = std::fmax(value, fLowMidFreq);
freqHP = fMidHighFreq;
xHP = std::exp(-2.0f * kPI * freqHP / (float)getSampleRate());
a0HP = 1.0f - xHP;
b1HP = -xHP;
break;
}
}

void DistrhoPlugin3BandEQ::loadProgram(uint32_t index)
{
if (index != 0)
return;

// Default values
fLow = 0.0f;
fMid = 0.0f;
fHigh = 0.0f;
fMaster = 0.0f;
fLowMidFreq = 220.0f;
fMidHighFreq = 2000.0f;

// Internal stuff
lowVol = midVol = highVol = outVol = 1.0f;
freqLP = 200.0f;
freqHP = 2000.0f;

// reset filter values
activate();
}

// -----------------------------------------------------------------------
// Process

void DistrhoPlugin3BandEQ::activate()
{
const float sr = (float)getSampleRate();

xLP = std::exp(-2.0f * kPI * freqLP / sr);

#ifdef DISTRHO_OS_WINDOWS
// don't ask me why, but this fixes a crash/exception below on windows...
printf("%f\n", -xLP);
#endif

a0LP = 1.0f - xLP;
b1LP = -xLP;

xHP = std::exp(-2.0f * kPI * freqHP / sr);
a0HP = 1.0f - xHP;
b1HP = -xHP;
}

void DistrhoPlugin3BandEQ::deactivate()
{
out1LP = out2LP = out1HP = out2HP = 0.0f;
tmp1LP = tmp2LP = tmp1HP = tmp2HP = 0.0f;
}

void DistrhoPlugin3BandEQ::run(const float** inputs, float** outputs, uint32_t frames)
{
const float* in1 = inputs[0];
const float* in2 = inputs[1];
float* out1 = outputs[0];
float* out2 = outputs[1];

for (uint32_t i=0; i < frames; ++i)
{
tmp1LP = a0LP * in1[i] - b1LP * tmp1LP + kDC_ADD;
tmp2LP = a0LP * in2[i] - b1LP * tmp2LP + kDC_ADD;
out1LP = tmp1LP - kDC_ADD;
out2LP = tmp2LP - kDC_ADD;

tmp1HP = a0HP * in1[i] - b1HP * tmp1HP + kDC_ADD;
tmp2HP = a0HP * in2[i] - b1HP * tmp2HP + kDC_ADD;
out1HP = in1[i] - tmp1HP - kDC_ADD;
out2HP = in2[i] - tmp2HP - kDC_ADD;

out1[i] = (out1LP*lowVol + (in1[i] - out1LP - out1HP)*midVol + out1HP*highVol) * outVol;
out2[i] = (out2LP*lowVol + (in2[i] - out2LP - out2HP)*midVol + out2HP*highVol) * outVol;
}
}

// -----------------------------------------------------------------------

Plugin* createPlugin()
{
return new DistrhoPlugin3BandEQ();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
123 changes: 123 additions & 0 deletions distrho-3bandeq/DistrhoPlugin3BandEQ.hpp
@@ -0,0 +1,123 @@
/*
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED
#define DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoPlugin3BandEQ : public Plugin
{
public:
enum Parameters
{
paramLow = 0,
paramMid,
paramHigh,
paramMaster,
paramLowMidFreq,
paramMidHighFreq,
paramCount
};

DistrhoPlugin3BandEQ();

protected:
// -------------------------------------------------------------------
// Information

const char* getLabel() const noexcept override
{
return "3BandEQ";
}

const char* getDescription() const override
{
return "3 Band Equalizer, stereo version.";
}

const char* getMaker() const noexcept override
{
return "DISTRHO";
}

const char* getHomePage() const override
{
return "https://github.com/DISTRHO/Mini-Series";
}

const char* getLicense() const noexcept override
{
return "LGPL";
}

uint32_t getVersion() const noexcept override
{
return d_version(1, 0, 0);
}

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', '3', 'E', 'Q');
}

// -------------------------------------------------------------------
// Init

void initParameter(uint32_t index, Parameter& parameter) override;
void initProgramName(uint32_t index, String& programName) override;

// -------------------------------------------------------------------
// Internal data

float getParameterValue(uint32_t index) const override;
void setParameterValue(uint32_t index, float value) override;
void loadProgram(uint32_t index) override;

// -------------------------------------------------------------------
// Process

void activate() override;
void deactivate() override;
void run(const float** inputs, float** outputs, uint32_t frames) override;

// -------------------------------------------------------------------

private:
float fLow, fMid, fHigh, fMaster, fLowMidFreq, fMidHighFreq;

float lowVol, midVol, highVol, outVol;
float freqLP, freqHP;

float xLP, a0LP, b1LP;
float xHP, a0HP, b1HP;

float out1LP, out2LP, out1HP, out2HP;
float tmp1LP, tmp2LP, tmp1HP, tmp2HP;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPlugin3BandEQ)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_3BANDEQ_HPP_INCLUDED
32 changes: 32 additions & 0 deletions distrho-3bandeq/DistrhoPluginInfo.h
@@ -0,0 +1,32 @@
/*
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "3 Band EQ"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/3BandEQ"

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1

#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:EQPlugin"

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
211 changes: 211 additions & 0 deletions distrho-3bandeq/DistrhoUI3BandEQ.cpp
@@ -0,0 +1,211 @@
/*
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPlugin3BandEQ.hpp"
#include "DistrhoUI3BandEQ.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtwork3BandEQ;

// -----------------------------------------------------------------------

DistrhoUI3BandEQ::DistrhoUI3BandEQ()
: UI(Art::backgroundWidth, Art::backgroundHeight),
fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, GL_BGR),
fAboutWindow(this)
{
// about
Image aboutImage(Art::aboutData, Art::aboutWidth, Art::aboutHeight, GL_BGR);
fAboutWindow.setImage(aboutImage);

// sliders
Image sliderImage(Art::sliderData, Art::sliderWidth, Art::sliderHeight);
Point<int> sliderPosStart(57, 43);
Point<int> sliderPosEnd(57, 43 + 160);

// slider Low
fSliderLow = new ImageSlider(this, sliderImage);
fSliderLow->setId(DistrhoPlugin3BandEQ::paramLow);
fSliderLow->setInverted(true);
fSliderLow->setStartPos(sliderPosStart);
fSliderLow->setEndPos(sliderPosEnd);
fSliderLow->setRange(-24.0f, 24.0f);
fSliderLow->setCallback(this);

// slider Mid
sliderPosStart.setX(120);
sliderPosEnd.setX(120);
fSliderMid = new ImageSlider(this, sliderImage);
fSliderMid->setId(DistrhoPlugin3BandEQ::paramMid);
fSliderMid->setInverted(true);
fSliderMid->setStartPos(sliderPosStart);
fSliderMid->setEndPos(sliderPosEnd);
fSliderMid->setRange(-24.0f, 24.0f);
fSliderMid->setCallback(this);

// slider High
sliderPosStart.setX(183);
sliderPosEnd.setX(183);
fSliderHigh = new ImageSlider(this, sliderImage);
fSliderHigh->setId(DistrhoPlugin3BandEQ::paramHigh);
fSliderHigh->setInverted(true);
fSliderHigh->setStartPos(sliderPosStart);
fSliderHigh->setEndPos(sliderPosEnd);
fSliderHigh->setRange(-24.0f, 24.0f);
fSliderHigh->setCallback(this);

// slider Master
sliderPosStart.setX(287);
sliderPosEnd.setX(287);
fSliderMaster = new ImageSlider(this, sliderImage);
fSliderMaster->setId(DistrhoPlugin3BandEQ::paramMaster);
fSliderMaster->setInverted(true);
fSliderMaster->setStartPos(sliderPosStart);
fSliderMaster->setEndPos(sliderPosEnd);
fSliderMaster->setRange(-24.0f, 24.0f);
fSliderMaster->setCallback(this);

// knobs
Image knobImage(Art::knobData, Art::knobWidth, Art::knobHeight);

// knob Low-Mid
fKnobLowMid = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobLowMid->setId(DistrhoPlugin3BandEQ::paramLowMidFreq);
fKnobLowMid->setAbsolutePos(65, 269);
fKnobLowMid->setRange(0.0f, 1000.0f);
fKnobLowMid->setDefault(440.0f);
fKnobLowMid->setRotationAngle(270);
fKnobLowMid->setCallback(this);

// knob Mid-High
fKnobMidHigh = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobMidHigh->setId(DistrhoPlugin3BandEQ::paramMidHighFreq);
fKnobMidHigh->setAbsolutePos(159, 269);
fKnobMidHigh->setRange(1000.0f, 20000.0f);
fKnobMidHigh->setDefault(1000.0f);
fKnobMidHigh->setRotationAngle(270);
fKnobMidHigh->setCallback(this);

// about button
Image aboutImageNormal(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight);
Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight);
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
fButtonAbout->setAbsolutePos(264, 300);
fButtonAbout->setCallback(this);

// set default values
programLoaded(0);
}

// -----------------------------------------------------------------------
// DSP Callbacks

void DistrhoUI3BandEQ::parameterChanged(uint32_t index, float value)
{
switch (index)
{
case DistrhoPlugin3BandEQ::paramLow:
fSliderLow->setValue(value);
break;
case DistrhoPlugin3BandEQ::paramMid:
fSliderMid->setValue(value);
break;
case DistrhoPlugin3BandEQ::paramHigh:
fSliderHigh->setValue(value);
break;
case DistrhoPlugin3BandEQ::paramMaster:
fSliderMaster->setValue(value);
break;
case DistrhoPlugin3BandEQ::paramLowMidFreq:
fKnobLowMid->setValue(value);
break;
case DistrhoPlugin3BandEQ::paramMidHighFreq:
fKnobMidHigh->setValue(value);
break;
}
}

void DistrhoUI3BandEQ::programLoaded(uint32_t index)
{
if (index != 0)
return;

// Default values
fSliderLow->setValue(0.0f);
fSliderMid->setValue(0.0f);
fSliderHigh->setValue(0.0f);
fSliderMaster->setValue(0.0f);
fKnobLowMid->setValue(220.0f);
fKnobMidHigh->setValue(2000.0f);
}

// -----------------------------------------------------------------------
// Widget Callbacks

void DistrhoUI3BandEQ::imageButtonClicked(ImageButton* button, int)
{
if (button != fButtonAbout)
return;

fAboutWindow.exec();
}

void DistrhoUI3BandEQ::imageKnobDragStarted(ImageKnob* knob)
{
editParameter(knob->getId(), true);
}

void DistrhoUI3BandEQ::imageKnobDragFinished(ImageKnob* knob)
{
editParameter(knob->getId(), false);
}

void DistrhoUI3BandEQ::imageKnobValueChanged(ImageKnob* knob, float value)
{
setParameterValue(knob->getId(), value);
}

void DistrhoUI3BandEQ::imageSliderDragStarted(ImageSlider* slider)
{
editParameter(slider->getId(), true);
}

void DistrhoUI3BandEQ::imageSliderDragFinished(ImageSlider* slider)
{
editParameter(slider->getId(), false);
}

void DistrhoUI3BandEQ::imageSliderValueChanged(ImageSlider* slider, float value)
{
setParameterValue(slider->getId(), value);
}

void DistrhoUI3BandEQ::onDisplay()
{
fImgBackground.draw();
}

// -----------------------------------------------------------------------

UI* createUI()
{
return new DistrhoUI3BandEQ();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
72 changes: 72 additions & 0 deletions distrho-3bandeq/DistrhoUI3BandEQ.hpp
@@ -0,0 +1,72 @@
/*
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_UI_3BANDEQ_HPP_INCLUDED
#define DISTRHO_UI_3BANDEQ_HPP_INCLUDED

#include "DistrhoUI.hpp"
#include "ImageWidgets.hpp"

#include "DistrhoArtwork3BandEQ.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoUI3BandEQ : public UI,
public ImageButton::Callback,
public ImageKnob::Callback,
public ImageSlider::Callback
{
public:
DistrhoUI3BandEQ();

protected:
// -------------------------------------------------------------------
// DSP Callbacks

void parameterChanged(uint32_t index, float value) override;
void programLoaded(uint32_t index) override;

// -------------------------------------------------------------------
// Widget Callbacks

void imageButtonClicked(ImageButton* button, int) override;
void imageKnobDragStarted(ImageKnob* knob) override;
void imageKnobDragFinished(ImageKnob* knob) override;
void imageKnobValueChanged(ImageKnob* knob, float value) override;
void imageSliderDragStarted(ImageSlider* slider) override;
void imageSliderDragFinished(ImageSlider* slider) override;
void imageSliderValueChanged(ImageSlider* slider, float value) override;

void onDisplay() override;

private:
Image fImgBackground;
ImageAboutWindow fAboutWindow;

ScopedPointer<ImageButton> fButtonAbout;
ScopedPointer<ImageKnob> fKnobLowMid, fKnobMidHigh;
ScopedPointer<ImageSlider> fSliderLow, fSliderMid, fSliderHigh, fSliderMaster;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUI3BandEQ)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_UI_3BANDEQ_HPP_INCLUDED
85 changes: 85 additions & 0 deletions distrho-3bandsplitter.cpp
@@ -0,0 +1,85 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 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 2 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 doc/GPL.txt file.
*/

// config fix
#include "distrho-3bandsplitter/DistrhoPluginInfo.h"

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL)
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#include "CarlaMathUtils.hpp"
#include "CarlaJuceUtils.hpp"

// Plugin Code
#include "distrho-3bandsplitter/DistrhoArtwork3BandSplitter.cpp"
#include "distrho-3bandsplitter/DistrhoPlugin3BandSplitter.cpp"
#ifdef HAVE_DGL
#include "distrho-3bandsplitter/DistrhoUI3BandSplitter.cpp"
#endif

// DISTRHO Code
#define DISTRHO_PLUGIN_TARGET_CARLA
#include "DistrhoPluginMain.cpp"
#ifdef HAVE_DGL
#include "DistrhoUIMain.cpp"
#endif

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

static const NativePluginDescriptor _3bandsplitterDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_EQ,
#ifdef HAVE_DGL
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
#else
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE),
#endif
/* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 0,
/* midiOuts */ 0,
/* paramIns */ DistrhoPlugin3BandSplitter::paramCount,
/* paramOuts */ 0,
/* name */ DISTRHO_PLUGIN_NAME,
/* label */ "3bandsplitter",
/* maker */ "falkTX, Michael Gruhn",
/* copyright */ "LGPL",
PluginDescriptorFILL(PluginCarla)
};

END_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

CARLA_EXPORT
void carla_register_native_plugin_distrho_3bandsplitter();

CARLA_EXPORT
void carla_register_native_plugin_distrho_3bandsplitter()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&_3bandsplitterDesc);
}

// -----------------------------------------------------------------------
10,107 changes: 10,107 additions & 0 deletions distrho-3bandsplitter/DistrhoArtwork3BandSplitter.cpp

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions distrho-3bandsplitter/DistrhoArtwork3BandSplitter.hpp
@@ -0,0 +1,40 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_DISTRHOARTWORK3BANDSPLITTER_HPP
#define BINARY_DISTRHOARTWORK3BANDSPLITTER_HPP

namespace DistrhoArtwork3BandSplitter
{
extern const char* aboutData;
const unsigned int aboutDataSize = 172710;
const unsigned int aboutWidth = 303;
const unsigned int aboutHeight = 190;

extern const char* aboutButtonHoverData;
const unsigned int aboutButtonHoverDataSize = 5888;
const unsigned int aboutButtonHoverWidth = 92;
const unsigned int aboutButtonHoverHeight = 16;

extern const char* aboutButtonNormalData;
const unsigned int aboutButtonNormalDataSize = 5888;
const unsigned int aboutButtonNormalWidth = 92;
const unsigned int aboutButtonNormalHeight = 16;

extern const char* backgroundData;
const unsigned int backgroundDataSize = 437472;
const unsigned int backgroundWidth = 392;
const unsigned int backgroundHeight = 372;

extern const char* knobData;
const unsigned int knobDataSize = 15376;
const unsigned int knobWidth = 62;
const unsigned int knobHeight = 62;

extern const char* sliderData;
const unsigned int sliderDataSize = 6000;
const unsigned int sliderWidth = 50;
const unsigned int sliderHeight = 30;
}

#endif // BINARY_DISTRHOARTWORK3BANDSPLITTER_HPP

272 changes: 272 additions & 0 deletions distrho-3bandsplitter/DistrhoPlugin3BandSplitter.cpp
@@ -0,0 +1,272 @@
/*
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPlugin3BandSplitter.hpp"

#include <cmath>

static const float kAMP_DB = 8.656170245f;
static const float kDC_ADD = 1e-30f;
static const float kPI = 3.141592654f;

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

DistrhoPlugin3BandSplitter::DistrhoPlugin3BandSplitter()
: Plugin(paramCount, 1, 0) // 1 program, 0 states
{
// set default values
loadProgram(0);

// reset
deactivate();
}

// -----------------------------------------------------------------------
// Init

void DistrhoPlugin3BandSplitter::initParameter(uint32_t index, Parameter& parameter)
{
switch (index)
{
case paramLow:
parameter.hints = kParameterIsAutomable;
parameter.name = "Low";
parameter.symbol = "low";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramMid:
parameter.hints = kParameterIsAutomable;
parameter.name = "Mid";
parameter.symbol = "mid";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramHigh:
parameter.hints = kParameterIsAutomable;
parameter.name = "High";
parameter.symbol = "high";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramMaster:
parameter.hints = kParameterIsAutomable;
parameter.name = "Master";
parameter.symbol = "master";
parameter.unit = "dB";
parameter.ranges.def = 0.0f;
parameter.ranges.min = -24.0f;
parameter.ranges.max = 24.0f;
break;

case paramLowMidFreq:
parameter.hints = kParameterIsAutomable;
parameter.name = "Low-Mid Freq";
parameter.symbol = "low_mid";
parameter.unit = "Hz";
parameter.ranges.def = 440.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1000.0f;
break;

case paramMidHighFreq:
parameter.hints = kParameterIsAutomable;
parameter.name = "Mid-High Freq";
parameter.symbol = "mid_high";
parameter.unit = "Hz";
parameter.ranges.def = 1000.0f;
parameter.ranges.min = 1000.0f;
parameter.ranges.max = 20000.0f;
break;
}
}

void DistrhoPlugin3BandSplitter::initProgramName(uint32_t index, String& programName)
{
if (index != 0)
return;

programName = "Default";
}

// -----------------------------------------------------------------------
// Internal data

float DistrhoPlugin3BandSplitter::getParameterValue(uint32_t index) const
{
switch (index)
{
case paramLow:
return fLow;
case paramMid:
return fMid;
case paramHigh:
return fHigh;
case paramMaster:
return fMaster;
case paramLowMidFreq:
return fLowMidFreq;
case paramMidHighFreq:
return fMidHighFreq;
default:
return 0.0f;
}
}

void DistrhoPlugin3BandSplitter::setParameterValue(uint32_t index, float value)
{
if (getSampleRate() <= 0.0)
return;

switch (index)
{
case paramLow:
fLow = value;
lowVol = std::exp( (fLow/48.0f) * 48.0f / kAMP_DB);
break;
case paramMid:
fMid = value;
midVol = std::exp( (fMid/48.0f) * 48.0f / kAMP_DB);
break;
case paramHigh:
fHigh = value;
highVol = std::exp( (fHigh/48.0f) * 48.0f / kAMP_DB);
break;
case paramMaster:
fMaster = value;
outVol = std::exp( (fMaster/48.0f) * 48.0f / kAMP_DB);
break;
case paramLowMidFreq:
fLowMidFreq = std::fmin(value, fMidHighFreq);
freqLP = fLowMidFreq;
xLP = std::exp(-2.0f * kPI * freqLP / (float)getSampleRate());
a0LP = 1.0f - xLP;
b1LP = -xLP;
break;
case paramMidHighFreq:
fMidHighFreq = std::fmax(value, fLowMidFreq);
freqHP = fMidHighFreq;
xHP = std::exp(-2.0f * kPI * freqHP / (float)getSampleRate());
a0HP = 1.0f - xHP;
b1HP = -xHP;
break;
}
}

void DistrhoPlugin3BandSplitter::loadProgram(uint32_t index)
{
if (index != 0)
return;

// Default values
fLow = 0.0f;
fMid = 0.0f;
fHigh = 0.0f;
fMaster = 0.0f;
fLowMidFreq = 220.0f;
fMidHighFreq = 2000.0f;

// Internal stuff
lowVol = midVol = highVol = outVol = 1.0f;
freqLP = 200.0f;
freqHP = 2000.0f;

// reset filter values
activate();
}

// -----------------------------------------------------------------------
// Process

void DistrhoPlugin3BandSplitter::activate()
{
const float sr = (float)getSampleRate();

xLP = std::exp(-2.0f * kPI * freqLP / sr);

#ifdef DISTRHO_OS_WINDOWS
// don't ask me why, but this fixes a crash/exception below on windows...
printf("%f\n", -xLP);
#endif

a0LP = 1.0f - xLP;
b1LP = -xLP;

xHP = std::exp(-2.0f * kPI * freqHP / sr);
a0HP = 1.0f - xHP;
b1HP = -xHP;
}

void DistrhoPlugin3BandSplitter::deactivate()
{
out1LP = out2LP = out1HP = out2HP = 0.0f;
tmp1LP = tmp2LP = tmp1HP = tmp2HP = 0.0f;
}

void DistrhoPlugin3BandSplitter::run(const float** inputs, float** outputs, uint32_t frames)
{
const float* in1 = inputs[0];
const float* in2 = inputs[1];
float* out1 = outputs[0];
float* out2 = outputs[1];
float* out3 = outputs[2];
float* out4 = outputs[3];
float* out5 = outputs[4];
float* out6 = outputs[5];

for (uint32_t i=0; i < frames; ++i)
{
tmp1LP = a0LP * in1[i] - b1LP * tmp1LP + kDC_ADD;
tmp2LP = a0LP * in2[i] - b1LP * tmp2LP + kDC_ADD;
out1LP = tmp1LP - kDC_ADD;
out2LP = tmp2LP - kDC_ADD;

tmp1HP = a0HP * in1[i] - b1HP * tmp1HP + kDC_ADD;
tmp2HP = a0HP * in2[i] - b1HP * tmp2HP + kDC_ADD;
out1HP = in1[i] - tmp1HP - kDC_ADD;
out2HP = in2[i] - tmp2HP - kDC_ADD;

out6[i] = out2HP*highVol * outVol;
out5[i] = out1HP*highVol * outVol;
out4[i] = (in2[i] - out2LP - out2HP)*midVol * outVol;
out3[i] = (in1[i] - out1LP - out1HP)*midVol * outVol;
out2[i] = out2LP*lowVol * outVol;
out1[i] = out1LP*lowVol * outVol;
}
}

// -----------------------------------------------------------------------

Plugin* createPlugin()
{
return new DistrhoPlugin3BandSplitter();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
123 changes: 123 additions & 0 deletions distrho-3bandsplitter/DistrhoPlugin3BandSplitter.hpp
@@ -0,0 +1,123 @@
/*
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_3BANDSPLITTER_HPP_INCLUDED
#define DISTRHO_PLUGIN_3BANDSPLITTER_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoPlugin3BandSplitter : public Plugin
{
public:
enum Parameters
{
paramLow = 0,
paramMid,
paramHigh,
paramMaster,
paramLowMidFreq,
paramMidHighFreq,
paramCount
};

DistrhoPlugin3BandSplitter();

protected:
// -------------------------------------------------------------------
// Information

const char* getLabel() const noexcept override
{
return "3BandSplitter";
}

const char* getDescription() const override
{
return "3 Band Equalizer, splitted output version.";
}

const char* getMaker() const noexcept override
{
return "DISTRHO";
}

const char* getHomePage() const override
{
return "https://github.com/DISTRHO/Mini-Series";
}

const char* getLicense() const noexcept override
{
return "LGPL";
}

uint32_t getVersion() const noexcept override
{
return d_version(1, 0, 0);
}

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', '3', 'E', 'S');
}

// -------------------------------------------------------------------
// Init

void initParameter(uint32_t index, Parameter& parameter) override;
void initProgramName(uint32_t index, String& programName) override;

// -------------------------------------------------------------------
// Internal data

float getParameterValue(uint32_t index) const override;
void setParameterValue(uint32_t index, float value) override;
void loadProgram(uint32_t index) override;

// -------------------------------------------------------------------
// Process

void activate() override;
void deactivate() override;
void run(const float** inputs, float** outputs, uint32_t frames) override;

// -------------------------------------------------------------------

private:
float fLow, fMid, fHigh, fMaster, fLowMidFreq, fMidHighFreq;

float lowVol, midVol, highVol, outVol;
float freqLP, freqHP;

float xLP, a0LP, b1LP;
float xHP, a0HP, b1HP;

float out1LP, out2LP, out1HP, out2HP;
float tmp1LP, tmp2LP, tmp1HP, tmp2HP;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPlugin3BandSplitter)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_3BANDSPLITTER_HPP_INCLUDED
32 changes: 32 additions & 0 deletions distrho-3bandsplitter/DistrhoPluginInfo.h
@@ -0,0 +1,32 @@
/*
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "3 Band Splitter"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/3BandSplitter"

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_OUTPUTS 6
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1

#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:EQPlugin"

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
211 changes: 211 additions & 0 deletions distrho-3bandsplitter/DistrhoUI3BandSplitter.cpp
@@ -0,0 +1,211 @@
/*
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPlugin3BandSplitter.hpp"
#include "DistrhoUI3BandSplitter.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtwork3BandSplitter;

// -----------------------------------------------------------------------

DistrhoUI3BandSplitter::DistrhoUI3BandSplitter()
: UI(Art::backgroundWidth, Art::backgroundHeight),
fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, GL_BGR),
fAboutWindow(this)
{
// about
Image aboutImage(Art::aboutData, Art::aboutWidth, Art::aboutHeight, GL_BGR);
fAboutWindow.setImage(aboutImage);

// sliders
Image sliderImage(Art::sliderData, Art::sliderWidth, Art::sliderHeight);
Point<int> sliderPosStart(57, 43);
Point<int> sliderPosEnd(57, 43 + 160);

// slider Low
fSliderLow = new ImageSlider(this, sliderImage);
fSliderLow->setId(DistrhoPlugin3BandSplitter::paramLow);
fSliderLow->setInverted(true);
fSliderLow->setStartPos(sliderPosStart);
fSliderLow->setEndPos(sliderPosEnd);
fSliderLow->setRange(-24.0f, 24.0f);
fSliderLow->setCallback(this);

// slider Mid
sliderPosStart.setX(120);
sliderPosEnd.setX(120);
fSliderMid = new ImageSlider(this, sliderImage);
fSliderMid->setId(DistrhoPlugin3BandSplitter::paramMid);
fSliderMid->setInverted(true);
fSliderMid->setStartPos(sliderPosStart);
fSliderMid->setEndPos(sliderPosEnd);
fSliderMid->setRange(-24.0f, 24.0f);
fSliderMid->setCallback(this);

// slider High
sliderPosStart.setX(183);
sliderPosEnd.setX(183);
fSliderHigh = new ImageSlider(this, sliderImage);
fSliderHigh->setId(DistrhoPlugin3BandSplitter::paramHigh);
fSliderHigh->setInverted(true);
fSliderHigh->setStartPos(sliderPosStart);
fSliderHigh->setEndPos(sliderPosEnd);
fSliderHigh->setRange(-24.0f, 24.0f);
fSliderHigh->setCallback(this);

// slider Master
sliderPosStart.setX(287);
sliderPosEnd.setX(287);
fSliderMaster = new ImageSlider(this, sliderImage);
fSliderMaster->setId(DistrhoPlugin3BandSplitter::paramMaster);
fSliderMaster->setInverted(true);
fSliderMaster->setStartPos(sliderPosStart);
fSliderMaster->setEndPos(sliderPosEnd);
fSliderMaster->setRange(-24.0f, 24.0f);
fSliderMaster->setCallback(this);

// knobs
Image knobImage(Art::knobData, Art::knobWidth, Art::knobHeight);

// knob Low-Mid
fKnobLowMid = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobLowMid->setId(DistrhoPlugin3BandSplitter::paramLowMidFreq);
fKnobLowMid->setAbsolutePos(65, 269);
fKnobLowMid->setRange(0.0f, 1000.0f);
fKnobLowMid->setDefault(440.0f);
fKnobLowMid->setRotationAngle(270);
fKnobLowMid->setCallback(this);

// knob Mid-High
fKnobMidHigh = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobMidHigh->setId(DistrhoPlugin3BandSplitter::paramMidHighFreq);
fKnobMidHigh->setAbsolutePos(159, 269);
fKnobMidHigh->setRange(1000.0f, 20000.0f);
fKnobMidHigh->setDefault(1000.0f);
fKnobMidHigh->setRotationAngle(270);
fKnobMidHigh->setCallback(this);

// about button
Image aboutImageNormal(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight);
Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight);
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
fButtonAbout->setAbsolutePos(264, 300);
fButtonAbout->setCallback(this);

// set default values
programLoaded(0);
}

// -----------------------------------------------------------------------
// DSP Callbacks

void DistrhoUI3BandSplitter::parameterChanged(uint32_t index, float value)
{
switch (index)
{
case DistrhoPlugin3BandSplitter::paramLow:
fSliderLow->setValue(value);
break;
case DistrhoPlugin3BandSplitter::paramMid:
fSliderMid->setValue(value);
break;
case DistrhoPlugin3BandSplitter::paramHigh:
fSliderHigh->setValue(value);
break;
case DistrhoPlugin3BandSplitter::paramMaster:
fSliderMaster->setValue(value);
break;
case DistrhoPlugin3BandSplitter::paramLowMidFreq:
fKnobLowMid->setValue(value);
break;
case DistrhoPlugin3BandSplitter::paramMidHighFreq:
fKnobMidHigh->setValue(value);
break;
}
}

void DistrhoUI3BandSplitter::programLoaded(uint32_t index)
{
if (index != 0)
return;

// Default values
fSliderLow->setValue(0.0f);
fSliderMid->setValue(0.0f);
fSliderHigh->setValue(0.0f);
fSliderMaster->setValue(0.0f);
fKnobLowMid->setValue(220.0f);
fKnobMidHigh->setValue(2000.0f);
}

// -----------------------------------------------------------------------
// Widget Callbacks

void DistrhoUI3BandSplitter::imageButtonClicked(ImageButton* button, int)
{
if (button != fButtonAbout)
return;

fAboutWindow.exec();
}

void DistrhoUI3BandSplitter::imageKnobDragStarted(ImageKnob* knob)
{
editParameter(knob->getId(), true);
}

void DistrhoUI3BandSplitter::imageKnobDragFinished(ImageKnob* knob)
{
editParameter(knob->getId(), false);
}

void DistrhoUI3BandSplitter::imageKnobValueChanged(ImageKnob* knob, float value)
{
setParameterValue(knob->getId(), value);
}

void DistrhoUI3BandSplitter::imageSliderDragStarted(ImageSlider* slider)
{
editParameter(slider->getId(), true);
}

void DistrhoUI3BandSplitter::imageSliderDragFinished(ImageSlider* slider)
{
editParameter(slider->getId(), false);
}

void DistrhoUI3BandSplitter::imageSliderValueChanged(ImageSlider* slider, float value)
{
setParameterValue(slider->getId(), value);
}

void DistrhoUI3BandSplitter::onDisplay()
{
fImgBackground.draw();
}

// -----------------------------------------------------------------------

UI* createUI()
{
return new DistrhoUI3BandSplitter();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
72 changes: 72 additions & 0 deletions distrho-3bandsplitter/DistrhoUI3BandSplitter.hpp
@@ -0,0 +1,72 @@
/*
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* 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 Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_UI_3BANDSPLITTER_HPP_INCLUDED
#define DISTRHO_UI_3BANDSPLITTER_HPP_INCLUDED

#include "DistrhoUI.hpp"
#include "ImageWidgets.hpp"

#include "DistrhoArtwork3BandSplitter.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoUI3BandSplitter : public UI,
public ImageButton::Callback,
public ImageKnob::Callback,
public ImageSlider::Callback
{
public:
DistrhoUI3BandSplitter();

protected:
// -------------------------------------------------------------------
// DSP Callbacks

void parameterChanged(uint32_t index, float value) override;
void programLoaded(uint32_t index) override;

// -------------------------------------------------------------------
// Widget Callbacks

void imageButtonClicked(ImageButton* button, int) override;
void imageKnobDragStarted(ImageKnob* knob) override;
void imageKnobDragFinished(ImageKnob* knob) override;
void imageKnobValueChanged(ImageKnob* knob, float value) override;
void imageSliderDragStarted(ImageSlider* slider) override;
void imageSliderDragFinished(ImageSlider* slider) override;
void imageSliderValueChanged(ImageSlider* slider, float value) override;

void onDisplay() override;

private:
Image fImgBackground;
ImageAboutWindow fAboutWindow;

ScopedPointer<ImageButton> fButtonAbout;
ScopedPointer<ImageKnob> fKnobLowMid, fKnobMidHigh;
ScopedPointer<ImageSlider> fSliderLow, fSliderMid, fSliderHigh, fSliderMaster;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUI3BandSplitter)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_UI_3BANDSPLITTER_HPP_INCLUDED
86 changes: 86 additions & 0 deletions distrho-kars.cpp
@@ -0,0 +1,86 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 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 2 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 doc/GPL.txt file.
*/

// config fix
#include "distrho-kars/DistrhoPluginInfo.h"

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL)
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#include "CarlaJuceUtils.hpp"

// Plugin Code
#include "distrho-kars/DistrhoArtworkKars.cpp"
#include "distrho-kars/DistrhoPluginKars.cpp"
#ifdef HAVE_DGL
#include "distrho-kars/DistrhoUIKars.cpp"
#endif

// DISTRHO Code
#define DISTRHO_PLUGIN_TARGET_CARLA
#include "DistrhoPluginMain.cpp"
#ifdef HAVE_DGL
#include "DistrhoUIMain.cpp"
#endif

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

static const NativePluginDescriptor karsDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_SYNTH,
#ifdef HAVE_DGL
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_IS_SYNTH
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
#else
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_IS_SYNTH),
#endif
/* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 1,
/* midiOuts */ 0,
/* paramIns */ DistrhoPluginKars::paramCount,
/* paramOuts */ 0,
/* name */ DISTRHO_PLUGIN_NAME,
/* label */ "kars",
/* maker */ "falkTX, Chris Cannam",
/* copyright */ "ISC",
PluginDescriptorFILL(PluginCarla)
};

END_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

CARLA_EXPORT
void carla_register_native_plugin_distrho_kars();

CARLA_EXPORT
void carla_register_native_plugin_distrho_kars()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&karsDesc);
}

// -----------------------------------------------------------------------
5,264 changes: 5,264 additions & 0 deletions distrho-kars/DistrhoArtworkKars.cpp

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions distrho-kars/DistrhoArtworkKars.hpp
@@ -0,0 +1,20 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_DISTRHOARTWORKKARS_HPP
#define BINARY_DISTRHOARTWORKKARS_HPP

namespace DistrhoArtworkKars
{
extern const char* backgroundData;
const unsigned int backgroundDataSize = 379260;
const unsigned int backgroundWidth = 301;
const unsigned int backgroundHeight = 315;

extern const char* switchData;
const unsigned int switchDataSize = 61952;
const unsigned int switchWidth = 88;
const unsigned int switchHeight = 176;
}

#endif // BINARY_DISTRHOARTWORKKARS_HPP

31 changes: 31 additions & 0 deletions distrho-kars/DistrhoPluginInfo.h
@@ -0,0 +1,31 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 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.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "Kars"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Kars"

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_IS_SYNTH 1
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1
#define DISTRHO_PLUGIN_USES_MODGUI 1

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
214 changes: 214 additions & 0 deletions distrho-kars/DistrhoPluginKars.cpp
@@ -0,0 +1,214 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 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.
*/

#include "DistrhoPluginKars.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

DistrhoPluginKars::DistrhoPluginKars()
: Plugin(paramCount, 0, 0), // 0 programs, 0 states
fSustain(false),
fSampleRate(getSampleRate()),
fBlockStart(0)
{
for (int i=kMaxNotes; --i >= 0;)
{
fNotes[i].index = i;
fNotes[i].setSampleRate(fSampleRate);
}
}

// -----------------------------------------------------------------------
// Init

void DistrhoPluginKars::initParameter(uint32_t index, Parameter& parameter)
{
if (index != 0)
return;

parameter.hints = kParameterIsAutomable|kParameterIsBoolean;
parameter.name = "Sustain";
parameter.symbol = "sustain";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
}

// -----------------------------------------------------------------------
// Internal data

float DistrhoPluginKars::getParameterValue(uint32_t index) const
{
if (index != 0)
return 0.0f;

return fSustain ? 1.0f : 0.0f;
}

void DistrhoPluginKars::setParameterValue(uint32_t index, float value)
{
if (index != 0)
return;

fSustain = value > 0.5f;
}

// -----------------------------------------------------------------------
// Process

void DistrhoPluginKars::activate()
{
fBlockStart = 0;

for (int i=kMaxNotes; --i >= 0;)
{
fNotes[i].on = kNoteNull;
fNotes[i].off = kNoteNull;
fNotes[i].velocity = 0;
}
}

void DistrhoPluginKars::run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount)
{
uint8_t note, velo;
float* out = outputs[0];

for (uint32_t count, pos=0, curEventIndex=0; pos<frames;)
{
for (;curEventIndex < midiEventCount && pos >= midiEvents[curEventIndex].frame; ++curEventIndex)
{
if (midiEvents[curEventIndex].size > MidiEvent::kDataSize)
continue;

const uint8_t* data = midiEvents[curEventIndex].data;
const uint8_t status = data[0] & 0xF0;

switch (status)
{
case 0x90:
note = data[1];
velo = data[2];
DISTRHO_SAFE_ASSERT_BREAK(note < 128); // kMaxNotes
if (velo > 0)
{
fNotes[note].on = fBlockStart + midiEvents[curEventIndex].frame;
fNotes[note].off = kNoteNull;
fNotes[note].velocity = velo;
break;
}
// fall through
case 0x80:
note = data[1];
DISTRHO_SAFE_ASSERT_BREAK(note < 128); // kMaxNotes
fNotes[note].off = fBlockStart + midiEvents[curEventIndex].frame;
break;
}
}

if (curEventIndex < midiEventCount && midiEvents[curEventIndex].frame < frames)
count = midiEvents[curEventIndex].frame - pos;
else
count = frames - pos;

std::memset(out+pos, 0, sizeof(float)*count);
//for (uint32_t i=0; i<count; ++i)
// out[pos + i] = 0.0f;

for (int i=kMaxNotes; --i >= 0;)
{
if (fNotes[i].on != kNoteNull)
addSamples(out, i, pos, count);
}

pos += count;
}

fBlockStart += frames;
}

void DistrhoPluginKars::addSamples(float* out, int voice, uint32_t offset, uint32_t count)
{
const uint32_t start = fBlockStart + offset;

Note& note(fNotes[voice]);

if (start < note.on)
return;

if (start == note.on)
{
for (int i=note.sizei; --i >= 0;)
note.wavetable[i] = (float(rand()) / float(RAND_MAX)) * 2.0f - 1.0f;
}

const float vgain = float(note.velocity) / 127.0f;

bool decay;
float gain, sample;
uint32_t index, size;

for (uint32_t i=0, s=start-note.on; i<count; ++i, ++s)
{
gain = vgain;

if ((! fSustain) && note.off != kNoteNull && note.off < i+start)
{
// reuse index and size to save some performance.
// actual values are release and dist
index = 1 + uint32_t(0.01 * fSampleRate); // release, not index
size = i + start - note.off; // dist, not size

if (size > index)
{
note.on = kNoteNull;
break;
}

gain = gain * float(index - size) / float(index);
}

size = uint32_t(note.sizei);
decay = s > size;
index = s % size;

sample = note.wavetable[index];

if (decay)
{
if (index == 0)
sample += note.wavetable[size-1];
else
sample += note.wavetable[index-1];

note.wavetable[index] = sample/2;
}

out[offset+i] += gain * sample;
}
}

// -----------------------------------------------------------------------

Plugin* createPlugin()
{
return new DistrhoPluginKars();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
152 changes: 152 additions & 0 deletions distrho-kars/DistrhoPluginKars.hpp
@@ -0,0 +1,152 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 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.
*/

#ifndef DISTRHO_PLUGIN_KARS_HPP_INCLUDED
#define DISTRHO_PLUGIN_KARS_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoPluginKars : public Plugin
{
public:
static const int kMaxNotes = 128;
static const uint32_t kNoteNull = (uint32_t)-1;

enum Parameters
{
paramSustain = 0,
paramCount
};

DistrhoPluginKars();

protected:
// -------------------------------------------------------------------
// Information

const char* getLabel() const noexcept override
{
return "Kars";
}

const char* getDescription() const override
{
return "Simple karplus-strong plucked string synth.";
}

const char* getMaker() const noexcept override
{
return "falkTX";
}

const char* getHomePage() const override
{
return "https://github.com/DISTRHO/Kars";
}

const char* getLicense() const noexcept override
{
return "ISC";
}

uint32_t getVersion() const noexcept override
{
return d_version(1, 0, 0);
}

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', 'K', 'r', 's');
}

// -------------------------------------------------------------------
// Init

void initParameter(uint32_t index, Parameter& parameter) override;

// -------------------------------------------------------------------
// Internal data

float getParameterValue(uint32_t index) const override;
void setParameterValue(uint32_t index, float value) override;

// -------------------------------------------------------------------
// Process

void activate() override;
void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override;

// -------------------------------------------------------------------

private:
bool fSustain;
double fSampleRate;
uint32_t fBlockStart;

struct Note {
uint32_t on;
uint32_t off;
uint8_t velocity;
float index;
float size;
int sizei;
float* wavetable;

Note() noexcept
: on(kNoteNull),
off(kNoteNull),
velocity(0),
index(0.0f),
size(0.0f),
wavetable(nullptr) {}

~Note() noexcept
{
if (wavetable != nullptr)
{
delete[] wavetable;
wavetable = nullptr;
}
}

void setSampleRate(const double sampleRate)
{
if (wavetable != nullptr)
delete[] wavetable;

const float frequency = 440.0f * std::pow(2.0f, (index - 69.0f) / 12.0f);
size = sampleRate / frequency;
sizei = int(size)+1;
wavetable = new float[sizei];
std::memset(wavetable, 0, sizeof(float)*static_cast<size_t>(sizei));
}

} fNotes[kMaxNotes];

void addSamples(float* out, int voice, uint32_t offset, uint32_t count);

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginKars)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_KARS_HPP_INCLUDED
77 changes: 77 additions & 0 deletions distrho-kars/DistrhoUIKars.cpp
@@ -0,0 +1,77 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 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.
*/

#include "DistrhoPluginKars.hpp"
#include "DistrhoUIKars.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtworkKars;

// -----------------------------------------------------------------------

DistrhoUIKars::DistrhoUIKars()
: UI(Art::backgroundWidth, Art::backgroundHeight),
fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight)
{
// sustain switch
Image switchImageNormal(Art::switchData, Art::switchWidth, Art::switchHeight/2);
Image switchImageDown(Art::switchData+(Art::switchWidth*Art::switchHeight/2*4), Art::switchWidth, Art::switchHeight/2);
fSwitchSustain = new ImageSwitch(this, switchImageNormal, switchImageDown);
fSwitchSustain->setAbsolutePos(Art::backgroundWidth/2-Art::switchWidth/2, Art::backgroundHeight/2-Art::switchHeight/4);
fSwitchSustain->setId(DistrhoPluginKars::paramSustain);
fSwitchSustain->setCallback(this);
}

// -----------------------------------------------------------------------
// DSP Callbacks

void DistrhoUIKars::parameterChanged(uint32_t index, float value)
{
if (index != 0)
return;

fSwitchSustain->setDown(value > 0.5f);
}

// -----------------------------------------------------------------------
// Widget Callbacks

void DistrhoUIKars::imageSwitchClicked(ImageSwitch* imageSwitch, bool down)
{
if (imageSwitch != fSwitchSustain)
return;

editParameter(DistrhoPluginKars::paramSustain, true);
setParameterValue(DistrhoPluginKars::paramSustain, down ? 1.0f : 0.0f);
editParameter(DistrhoPluginKars::paramSustain, false);
}

void DistrhoUIKars::onDisplay()
{
fImgBackground.draw();
}

// -----------------------------------------------------------------------

UI* createUI()
{
return new DistrhoUIKars();
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
60 changes: 60 additions & 0 deletions distrho-kars/DistrhoUIKars.hpp
@@ -0,0 +1,60 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 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.
*/

#ifndef DISTRHO_UI_KARS_HPP_INCLUDED
#define DISTRHO_UI_KARS_HPP_INCLUDED

#include "DistrhoUI.hpp"

#include "ImageWidgets.hpp"

#include "DistrhoArtworkKars.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

class DistrhoUIKars : public UI,
public ImageSwitch::Callback
{
public:
DistrhoUIKars();

protected:
// -------------------------------------------------------------------
// DSP Callbacks

void parameterChanged(uint32_t index, float value) override;

// -------------------------------------------------------------------
// Widget Callbacks

void imageSwitchClicked(ImageSwitch* imageSwitch, bool down) override;

void onDisplay() override;

private:
Image fImgBackground;
ScopedPointer<ImageSwitch> fSwitchSustain;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUIKars)
};

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_UI_KARS_HPP_INCLUDED
87 changes: 87 additions & 0 deletions distrho-nekobi.cpp
@@ -0,0 +1,87 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 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 2 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 doc/GPL.txt file.
*/

// config fix
#include "distrho-nekobi/DistrhoPluginInfo.h"

#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL)
# undef DISTRHO_PLUGIN_HAS_UI
# define DISTRHO_PLUGIN_HAS_UI 0
#endif

#include "CarlaJuceUtils.hpp"

// Plugin Code
#include "distrho-nekobi/DistrhoArtworkNekobi.cpp"
#include "distrho-nekobi/DistrhoPluginNekobi.cpp"
#ifdef HAVE_DGL
#include "distrho-nekobi/DistrhoUINekobi.cpp"
#endif

// DISTRHO Code
#define DISTRHO_PLUGIN_TARGET_CARLA
#include "DistrhoPluginMain.cpp"
#ifdef HAVE_DGL
#include "DistrhoUIMain.cpp"
#endif

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

static const NativePluginDescriptor nekobiDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_SYNTH,
#ifdef HAVE_DGL
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_IS_SYNTH
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
#else
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_IS_SYNTH),
#endif
/* supports */ static_cast<NativePluginSupports>(NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES
|NATIVE_PLUGIN_SUPPORTS_ALL_SOUND_OFF),
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 1,
/* midiOuts */ 0,
/* paramIns */ DistrhoPluginNekobi::paramCount,
/* paramOuts */ 0,
/* name */ DISTRHO_PLUGIN_NAME,
/* label */ "nekobi",
/* maker */ "falkTX, Sean Bolton and others",
/* copyright */ "GPL v2+",
PluginDescriptorFILL(PluginCarla)
};

END_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------

CARLA_EXPORT
void carla_register_native_plugin_distrho_nekobi();

CARLA_EXPORT
void carla_register_native_plugin_distrho_nekobi()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&nekobiDesc);
}

// -----------------------------------------------------------------------
6,890 changes: 6,890 additions & 0 deletions distrho-nekobi/DistrhoArtworkNekobi.cpp

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions distrho-nekobi/DistrhoArtworkNekobi.hpp
@@ -0,0 +1,90 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_DISTRHOARTWORKNEKOBI_HPP
#define BINARY_DISTRHOARTWORKNEKOBI_HPP

namespace DistrhoArtworkNekobi
{
extern const char* aboutData;
const unsigned int aboutDataSize = 172710;
const unsigned int aboutWidth = 303;
const unsigned int aboutHeight = 190;

extern const char* aboutButtonHoverData;
const unsigned int aboutButtonHoverDataSize = 5888;
const unsigned int aboutButtonHoverWidth = 92;
const unsigned int aboutButtonHoverHeight = 16;

extern const char* aboutButtonNormalData;
const unsigned int aboutButtonNormalDataSize = 5888;
const unsigned int aboutButtonNormalWidth = 92;
const unsigned int aboutButtonNormalHeight = 16;

extern const char* backgroundData;
const unsigned int backgroundDataSize = 206064;
const unsigned int backgroundWidth = 636;
const unsigned int backgroundHeight = 108;

extern const char* claw1Data;
const unsigned int claw1DataSize = 4096;
const unsigned int claw1Width = 32;
const unsigned int claw1Height = 32;

extern const char* claw2Data;
const unsigned int claw2DataSize = 4096;
const unsigned int claw2Width = 32;
const unsigned int claw2Height = 32;

extern const char* knobData;
const unsigned int knobDataSize = 10000;
const unsigned int knobWidth = 50;
const unsigned int knobHeight = 50;

extern const char* run1Data;
const unsigned int run1DataSize = 4096;
const unsigned int run1Width = 32;
const unsigned int run1Height = 32;

extern const char* run2Data;
const unsigned int run2DataSize = 4096;
const unsigned int run2Width = 32;
const unsigned int run2Height = 32;

extern const char* run3Data;
const unsigned int run3DataSize = 4096;
const unsigned int run3Width = 32;
const unsigned int run3Height = 32;

extern const char* run4Data;
const unsigned int run4DataSize = 4096;
const unsigned int run4Width = 32;
const unsigned int run4Height = 32;

extern const char* scratch1Data;
const unsigned int scratch1DataSize = 4096;
const unsigned int scratch1Width = 32;
const unsigned int scratch1Height = 32;

extern const char* scratch2Data;
const unsigned int scratch2DataSize = 4096;
const unsigned int scratch2Width = 32;
const unsigned int scratch2Height = 32;

extern const char* sitData;
const unsigned int sitDataSize = 4096;
const unsigned int sitWidth = 32;
const unsigned int sitHeight = 32;

extern const char* sliderData;
const unsigned int sliderDataSize = 6084;
const unsigned int sliderWidth = 39;
const unsigned int sliderHeight = 39;

extern const char* tailData;
const unsigned int tailDataSize = 4096;
const unsigned int tailWidth = 32;
const unsigned int tailHeight = 32;
}

#endif // BINARY_DISTRHOARTWORKNEKOBI_HPP

32 changes: 32 additions & 0 deletions distrho-nekobi/DistrhoPluginInfo.h
@@ -0,0 +1,32 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2015 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 2 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 DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "Nekobi"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Nekobi"

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_IS_SYNTH 1
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1
#define DISTRHO_PLUGIN_USES_MODGUI 1

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED