@@ -0,0 +1,72 @@ | |||
/* | |||
* Carla Native Plugins | |||
* 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 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 | |||
// Plugin Code | |||
#include "distrho-3bandeq/DistrhoArtwork3BandEQ.cpp" | |||
#include "distrho-3bandeq/DistrhoPlugin3BandEQ.cpp" | |||
#include "distrho-3bandeq/DistrhoUI3BandEQ.cpp" | |||
// DISTRHO Code | |||
#define DISTRHO_PLUGIN_TARGET_CARLA | |||
#include "DistrhoPluginMain.cpp" | |||
#include "DistrhoUIMain.cpp" | |||
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_USES_PARENT_ID), | |||
#else | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE), | |||
#endif | |||
/* supports */ static_cast<NativePluginSupports>(0x0), | |||
/* 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() | |||
{ | |||
USE_NAMESPACE_DISTRHO | |||
carla_register_native_plugin(&_3bandeqDesc); | |||
} | |||
// ----------------------------------------------------------------------- |
@@ -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 | |||
@@ -0,0 +1,258 @@ | |||
/* | |||
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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 | |||
d_setProgram(0); | |||
// reset | |||
d_deactivate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Init | |||
void DistrhoPlugin3BandEQ::d_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::d_initProgramName(uint32_t index, d_string& programName) | |||
{ | |||
if (index != 0) | |||
return; | |||
programName = "Default"; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Internal data | |||
float DistrhoPlugin3BandEQ::d_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::d_setParameterValue(uint32_t index, float value) | |||
{ | |||
if (d_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)d_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)d_getSampleRate()); | |||
a0HP = 1.0f - xHP; | |||
b1HP = -xHP; | |||
break; | |||
} | |||
} | |||
void DistrhoPlugin3BandEQ::d_setProgram(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 | |||
d_activate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Process | |||
void DistrhoPlugin3BandEQ::d_activate() | |||
{ | |||
const float sr = (float)d_getSampleRate(); | |||
xLP = std::exp(-2.0f * kPI * freqLP / sr); | |||
a0LP = 1.0f - xLP; | |||
b1LP = -xLP; | |||
xHP = std::exp(-2.0f * kPI * freqHP / sr); | |||
a0HP = 1.0f - xHP; | |||
b1HP = -xHP; | |||
} | |||
void DistrhoPlugin3BandEQ::d_deactivate() | |||
{ | |||
out1LP = out2LP = out1HP = out2HP = 0.0f; | |||
tmp1LP = tmp2LP = tmp1HP = tmp2HP = 0.0f; | |||
} | |||
void DistrhoPlugin3BandEQ::d_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 |
@@ -0,0 +1,113 @@ | |||
/* | |||
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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* d_getLabel() const noexcept override | |||
{ | |||
return "3BandEQ"; | |||
} | |||
const char* d_getMaker() const noexcept override | |||
{ | |||
return "DISTRHO"; | |||
} | |||
const char* d_getLicense() const noexcept override | |||
{ | |||
return "LGPL"; | |||
} | |||
uint32_t d_getVersion() const noexcept override | |||
{ | |||
return 0x1000; | |||
} | |||
int64_t d_getUniqueId() const noexcept override | |||
{ | |||
return d_cconst('D', '3', 'E', 'Q'); | |||
} | |||
// ------------------------------------------------------------------- | |||
// Init | |||
void d_initParameter(uint32_t index, Parameter& parameter) override; | |||
void d_initProgramName(uint32_t index, d_string& programName) override; | |||
// ------------------------------------------------------------------- | |||
// Internal data | |||
float d_getParameterValue(uint32_t index) const override; | |||
void d_setParameterValue(uint32_t index, float value) override; | |||
void d_setProgram(uint32_t index) override; | |||
// ------------------------------------------------------------------- | |||
// Process | |||
void d_activate() override; | |||
void d_deactivate() override; | |||
void d_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 |
@@ -0,0 +1,35 @@ | |||
/* | |||
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn | |||
* Copyright (C) 2012-2014 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_NAME "3 Band EQ" | |||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||
#define DISTRHO_PLUGIN_IS_SYNTH 0 | |||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | |||
#define DISTRHO_PLUGIN_WANT_LATENCY 0 | |||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | |||
#define DISTRHO_PLUGIN_WANT_STATE 0 | |||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 | |||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/3BandEQ" | |||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -0,0 +1,205 @@ | |||
/* | |||
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn | |||
* Copyright (C) 2012-2014 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" | |||
using DGL::Point; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoUI3BandEQ::DistrhoUI3BandEQ() | |||
: UI(), | |||
fAboutWindow(this) | |||
{ | |||
// set UI size | |||
setSize(DistrhoArtwork3BandEQ::backgroundWidth, DistrhoArtwork3BandEQ::backgroundHeight); | |||
// background | |||
fImgBackground = Image(DistrhoArtwork3BandEQ::backgroundData, DistrhoArtwork3BandEQ::backgroundWidth, DistrhoArtwork3BandEQ::backgroundHeight, GL_BGR); | |||
// about | |||
Image aboutImage(DistrhoArtwork3BandEQ::aboutData, DistrhoArtwork3BandEQ::aboutWidth, DistrhoArtwork3BandEQ::aboutHeight, GL_BGR); | |||
fAboutWindow.setImage(aboutImage); | |||
// sliders | |||
Image sliderImage(DistrhoArtwork3BandEQ::sliderData, DistrhoArtwork3BandEQ::sliderWidth, DistrhoArtwork3BandEQ::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(*fSliderLow); | |||
fSliderMid->setId(DistrhoPlugin3BandEQ::paramMid); | |||
fSliderMid->setStartPos(sliderPosStart); | |||
fSliderMid->setEndPos(sliderPosEnd); | |||
// slider High | |||
sliderPosStart.setX(183); | |||
sliderPosEnd.setX(183); | |||
fSliderHigh = new ImageSlider(*fSliderLow); | |||
fSliderHigh->setId(DistrhoPlugin3BandEQ::paramHigh); | |||
fSliderHigh->setStartPos(sliderPosStart); | |||
fSliderHigh->setEndPos(sliderPosEnd); | |||
// slider Master | |||
sliderPosStart.setX(287); | |||
sliderPosEnd.setX(287); | |||
fSliderMaster = new ImageSlider(*fSliderLow); | |||
fSliderMaster->setId(DistrhoPlugin3BandEQ::paramMaster); | |||
fSliderMaster->setStartPos(sliderPosStart); | |||
fSliderMaster->setEndPos(sliderPosEnd); | |||
// knobs | |||
Image knobImage(DistrhoArtwork3BandEQ::knobData, DistrhoArtwork3BandEQ::knobWidth, DistrhoArtwork3BandEQ::knobHeight); | |||
// knob Low-Mid | |||
fKnobLowMid = new ImageKnob(this, knobImage, ImageKnob::Vertical, 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, 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(DistrhoArtwork3BandEQ::aboutButtonNormalData, DistrhoArtwork3BandEQ::aboutButtonNormalWidth, DistrhoArtwork3BandEQ::aboutButtonNormalHeight); | |||
Image aboutImageHover(DistrhoArtwork3BandEQ::aboutButtonHoverData, DistrhoArtwork3BandEQ::aboutButtonHoverWidth, DistrhoArtwork3BandEQ::aboutButtonHoverHeight); | |||
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover); | |||
fButtonAbout->setAbsolutePos(264, 300); | |||
fButtonAbout->setCallback(this); | |||
// set default values | |||
d_programChanged(0); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void DistrhoUI3BandEQ::d_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::d_programChanged(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) | |||
{ | |||
d_editParameter(knob->getId(), true); | |||
} | |||
void DistrhoUI3BandEQ::imageKnobDragFinished(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), false); | |||
} | |||
void DistrhoUI3BandEQ::imageKnobValueChanged(ImageKnob* knob, float value) | |||
{ | |||
d_setParameterValue(knob->getId(), value); | |||
} | |||
void DistrhoUI3BandEQ::imageSliderDragStarted(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), true); | |||
} | |||
void DistrhoUI3BandEQ::imageSliderDragFinished(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), false); | |||
} | |||
void DistrhoUI3BandEQ::imageSliderValueChanged(ImageSlider* slider, float value) | |||
{ | |||
d_setParameterValue(slider->getId(), value); | |||
} | |||
void DistrhoUI3BandEQ::onDisplay() | |||
{ | |||
fImgBackground.draw(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
UI* createUI() | |||
{ | |||
return new DistrhoUI3BandEQ(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,82 @@ | |||
/* | |||
* DISTRHO 3BandEQ Plugin, based on 3BandEQ by Michael Gruhn | |||
* Copyright (C) 2012-2014 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 "ImageAboutWindow.hpp" | |||
#include "ImageButton.hpp" | |||
#include "ImageKnob.hpp" | |||
#include "ImageSlider.hpp" | |||
#include "DistrhoArtwork3BandEQ.hpp" | |||
using DGL::Image; | |||
using DGL::ImageAboutWindow; | |||
using DGL::ImageButton; | |||
using DGL::ImageKnob; | |||
using DGL::ImageSlider; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoUI3BandEQ : public UI, | |||
public ImageButton::Callback, | |||
public ImageKnob::Callback, | |||
public ImageSlider::Callback | |||
{ | |||
public: | |||
DistrhoUI3BandEQ(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void d_parameterChanged(uint32_t index, float value) override; | |||
void d_programChanged(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 |
@@ -0,0 +1,72 @@ | |||
/* | |||
* Carla Native Plugins | |||
* 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 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 | |||
// Plugin Code | |||
#include "distrho-3bandsplitter/DistrhoArtwork3BandSplitter.cpp" | |||
#include "distrho-3bandsplitter/DistrhoPlugin3BandSplitter.cpp" | |||
#include "distrho-3bandsplitter/DistrhoUI3BandSplitter.cpp" | |||
// DISTRHO Code | |||
#define DISTRHO_PLUGIN_TARGET_CARLA | |||
#include "DistrhoPluginMain.cpp" | |||
#include "DistrhoUIMain.cpp" | |||
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_USES_PARENT_ID), | |||
#else | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE), | |||
#endif | |||
/* supports */ static_cast<NativePluginSupports>(0x0), | |||
/* 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() | |||
{ | |||
USE_NAMESPACE_DISTRHO | |||
carla_register_native_plugin(&_3bandsplitterDesc); | |||
} | |||
// ----------------------------------------------------------------------- |
@@ -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 | |||
@@ -0,0 +1,266 @@ | |||
/* | |||
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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 | |||
d_setProgram(0); | |||
// reset | |||
d_deactivate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Init | |||
void DistrhoPlugin3BandSplitter::d_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::d_initProgramName(uint32_t index, d_string& programName) | |||
{ | |||
if (index != 0) | |||
return; | |||
programName = "Default"; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Internal data | |||
float DistrhoPlugin3BandSplitter::d_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::d_setParameterValue(uint32_t index, float value) | |||
{ | |||
if (d_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)d_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)d_getSampleRate()); | |||
a0HP = 1.0f - xHP; | |||
b1HP = -xHP; | |||
break; | |||
} | |||
} | |||
void DistrhoPlugin3BandSplitter::d_setProgram(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 | |||
d_activate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Process | |||
void DistrhoPlugin3BandSplitter::d_activate() | |||
{ | |||
const float sr = (float)d_getSampleRate(); | |||
xLP = std::exp(-2.0f * kPI * freqLP / sr); | |||
a0LP = 1.0f - xLP; | |||
b1LP = -xLP; | |||
xHP = std::exp(-2.0f * kPI * freqHP / sr); | |||
a0HP = 1.0f - xHP; | |||
b1HP = -xHP; | |||
} | |||
void DistrhoPlugin3BandSplitter::d_deactivate() | |||
{ | |||
out1LP = out2LP = out1HP = out2HP = 0.0f; | |||
tmp1LP = tmp2LP = tmp1HP = tmp2HP = 0.0f; | |||
} | |||
void DistrhoPlugin3BandSplitter::d_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; | |||
out1[i] = out1LP*lowVol * outVol; | |||
out2[i] = out2LP*lowVol * outVol; | |||
out3[i] = (in1[i] - out1LP - out1HP)*midVol * outVol; | |||
out4[i] = (in2[i] - out2LP - out2HP)*midVol * outVol; | |||
out5[i] = out1HP*highVol * outVol; | |||
out6[i] = out2HP*highVol * outVol; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
Plugin* createPlugin() | |||
{ | |||
return new DistrhoPlugin3BandSplitter(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,113 @@ | |||
/* | |||
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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* d_getLabel() const noexcept override | |||
{ | |||
return "3BandSplitter"; | |||
} | |||
const char* d_getMaker() const noexcept override | |||
{ | |||
return "DISTRHO"; | |||
} | |||
const char* d_getLicense() const noexcept override | |||
{ | |||
return "LGPL"; | |||
} | |||
uint32_t d_getVersion() const noexcept override | |||
{ | |||
return 0x1000; | |||
} | |||
int64_t d_getUniqueId() const noexcept override | |||
{ | |||
return d_cconst('D', '3', 'E', 'S'); | |||
} | |||
// ------------------------------------------------------------------- | |||
// Init | |||
void d_initParameter(uint32_t index, Parameter& parameter) override; | |||
void d_initProgramName(uint32_t index, d_string& programName) override; | |||
// ------------------------------------------------------------------- | |||
// Internal data | |||
float d_getParameterValue(uint32_t index) const override; | |||
void d_setParameterValue(uint32_t index, float value) override; | |||
void d_setProgram(uint32_t index) override; | |||
// ------------------------------------------------------------------- | |||
// Process | |||
void d_activate() override; | |||
void d_deactivate() override; | |||
void d_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 |
@@ -0,0 +1,35 @@ | |||
/* | |||
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn | |||
* Copyright (C) 2012-2014 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_NAME "3 Band Splitter" | |||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||
#define DISTRHO_PLUGIN_IS_SYNTH 0 | |||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 6 | |||
#define DISTRHO_PLUGIN_WANT_LATENCY 0 | |||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | |||
#define DISTRHO_PLUGIN_WANT_STATE 0 | |||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 | |||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/3BandSplitter" | |||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -0,0 +1,205 @@ | |||
/* | |||
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn | |||
* Copyright (C) 2012-2014 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" | |||
using DGL::Point; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoUI3BandSplitter::DistrhoUI3BandSplitter() | |||
: UI(), | |||
fAboutWindow(this) | |||
{ | |||
// set UI size | |||
setSize(DistrhoArtwork3BandSplitter::backgroundWidth, DistrhoArtwork3BandSplitter::backgroundHeight); | |||
// background | |||
fImgBackground = Image(DistrhoArtwork3BandSplitter::backgroundData, DistrhoArtwork3BandSplitter::backgroundWidth, DistrhoArtwork3BandSplitter::backgroundHeight, GL_BGR); | |||
// about | |||
Image aboutImage(DistrhoArtwork3BandSplitter::aboutData, DistrhoArtwork3BandSplitter::aboutWidth, DistrhoArtwork3BandSplitter::aboutHeight, GL_BGR); | |||
fAboutWindow.setImage(aboutImage); | |||
// sliders | |||
Image sliderImage(DistrhoArtwork3BandSplitter::sliderData, DistrhoArtwork3BandSplitter::sliderWidth, DistrhoArtwork3BandSplitter::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(*fSliderLow); | |||
fSliderMid->setId(DistrhoPlugin3BandSplitter::paramMid); | |||
fSliderMid->setStartPos(sliderPosStart); | |||
fSliderMid->setEndPos(sliderPosEnd); | |||
// slider High | |||
sliderPosStart.setX(183); | |||
sliderPosEnd.setX(183); | |||
fSliderHigh = new ImageSlider(*fSliderLow); | |||
fSliderHigh->setId(DistrhoPlugin3BandSplitter::paramHigh); | |||
fSliderHigh->setStartPos(sliderPosStart); | |||
fSliderHigh->setEndPos(sliderPosEnd); | |||
// slider Master | |||
sliderPosStart.setX(287); | |||
sliderPosEnd.setX(287); | |||
fSliderMaster = new ImageSlider(*fSliderLow); | |||
fSliderMaster->setId(DistrhoPlugin3BandSplitter::paramMaster); | |||
fSliderMaster->setStartPos(sliderPosStart); | |||
fSliderMaster->setEndPos(sliderPosEnd); | |||
// knobs | |||
Image knobImage(DistrhoArtwork3BandSplitter::knobData, DistrhoArtwork3BandSplitter::knobWidth, DistrhoArtwork3BandSplitter::knobHeight); | |||
// knob Low-Mid | |||
fKnobLowMid = new ImageKnob(this, knobImage, ImageKnob::Vertical, 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, 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(DistrhoArtwork3BandSplitter::aboutButtonNormalData, DistrhoArtwork3BandSplitter::aboutButtonNormalWidth, DistrhoArtwork3BandSplitter::aboutButtonNormalHeight); | |||
Image aboutImageHover(DistrhoArtwork3BandSplitter::aboutButtonHoverData, DistrhoArtwork3BandSplitter::aboutButtonHoverWidth, DistrhoArtwork3BandSplitter::aboutButtonHoverHeight); | |||
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover); | |||
fButtonAbout->setAbsolutePos(264, 300); | |||
fButtonAbout->setCallback(this); | |||
// set default values | |||
d_programChanged(0); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void DistrhoUI3BandSplitter::d_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::d_programChanged(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) | |||
{ | |||
d_editParameter(knob->getId(), true); | |||
} | |||
void DistrhoUI3BandSplitter::imageKnobDragFinished(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), false); | |||
} | |||
void DistrhoUI3BandSplitter::imageKnobValueChanged(ImageKnob* knob, float value) | |||
{ | |||
d_setParameterValue(knob->getId(), value); | |||
} | |||
void DistrhoUI3BandSplitter::imageSliderDragStarted(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), true); | |||
} | |||
void DistrhoUI3BandSplitter::imageSliderDragFinished(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), false); | |||
} | |||
void DistrhoUI3BandSplitter::imageSliderValueChanged(ImageSlider* slider, float value) | |||
{ | |||
d_setParameterValue(slider->getId(), value); | |||
} | |||
void DistrhoUI3BandSplitter::onDisplay() | |||
{ | |||
fImgBackground.draw(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
UI* createUI() | |||
{ | |||
return new DistrhoUI3BandSplitter(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,82 @@ | |||
/* | |||
* DISTRHO 3BandSplitter Plugin, based on 3BandSplitter by Michael Gruhn | |||
* Copyright (C) 2012-2014 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 "ImageAboutWindow.hpp" | |||
#include "ImageButton.hpp" | |||
#include "ImageKnob.hpp" | |||
#include "ImageSlider.hpp" | |||
#include "DistrhoArtwork3BandSplitter.hpp" | |||
using DGL::Image; | |||
using DGL::ImageAboutWindow; | |||
using DGL::ImageButton; | |||
using DGL::ImageKnob; | |||
using DGL::ImageSlider; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoUI3BandSplitter : public UI, | |||
public ImageButton::Callback, | |||
public ImageKnob::Callback, | |||
public ImageSlider::Callback | |||
{ | |||
public: | |||
DistrhoUI3BandSplitter(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void d_parameterChanged(uint32_t index, float value) override; | |||
void d_programChanged(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 |
@@ -0,0 +1,73 @@ | |||
/* | |||
* Carla Native Plugins | |||
* 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 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-mverb/DistrhoPluginInfo.h" | |||
#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) | |||
# undef DISTRHO_PLUGIN_HAS_UI | |||
# define DISTRHO_PLUGIN_HAS_UI 0 | |||
#endif | |||
// Plugin Code | |||
#include "distrho-mverb/DistrhoArtworkMVerb.cpp" | |||
#include "distrho-mverb/DistrhoPluginMVerb.cpp" | |||
#include "distrho-mverb/DistrhoUIMVerb.cpp" | |||
#include "distrho-mverb/font/Kh-Kangrey.cpp" | |||
// DISTRHO Code | |||
#define DISTRHO_PLUGIN_TARGET_CARLA | |||
#include "DistrhoPluginMain.cpp" | |||
#include "DistrhoUIMain.cpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
static const NativePluginDescriptor _mverbDesc = { | |||
/* category */ NATIVE_PLUGIN_CATEGORY_DELAY, | |||
#ifdef HAVE_DGL | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE|NATIVE_PLUGIN_HAS_UI|NATIVE_PLUGIN_USES_PARENT_ID), | |||
#else | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE), | |||
#endif | |||
/* supports */ static_cast<NativePluginSupports>(0x0), | |||
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, | |||
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS, | |||
/* midiIns */ 0, | |||
/* midiOuts */ 0, | |||
/* paramIns */ MVerb<float>::NUM_PARAMS, | |||
/* paramOuts */ 0, | |||
/* name */ DISTRHO_PLUGIN_NAME, | |||
/* label */ "mverb", | |||
/* maker */ "falkTX, Martin Eastwood", | |||
/* copyright */ "GPL v3+", | |||
PluginDescriptorFILL(PluginCarla) | |||
}; | |||
END_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
CARLA_EXPORT | |||
void carla_register_native_plugin_distrho_mverb() | |||
{ | |||
USE_NAMESPACE_DISTRHO | |||
carla_register_native_plugin(&_mverbDesc); | |||
} | |||
// ----------------------------------------------------------------------- |
@@ -0,0 +1,20 @@ | |||
/* (Auto-generated binary data file). */ | |||
#ifndef BINARY_DISTRHOARTWORKMVERB_HPP | |||
#define BINARY_DISTRHOARTWORKMVERB_HPP | |||
namespace DistrhoArtworkMVerb | |||
{ | |||
extern const char* backgroundData; | |||
const unsigned int backgroundDataSize = 147744; | |||
const unsigned int backgroundWidth = 456; | |||
const unsigned int backgroundHeight = 108; | |||
extern const char* knobData; | |||
const unsigned int knobDataSize = 528384; | |||
const unsigned int knobWidth = 32; | |||
const unsigned int knobHeight = 4128; | |||
} | |||
#endif // BINARY_DISTRHOARTWORKMVERB_HPP | |||
@@ -0,0 +1,37 @@ | |||
/* | |||
* DISTRHO MVerb, a DPF'ied MVerb. | |||
* Copyright (c) 2010 Martin Eastwood | |||
* Copyright (C) 2014 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. | |||
*/ | |||
#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED | |||
#define DISTRHO_PLUGIN_INFO_H_INCLUDED | |||
#define DISTRHO_PLUGIN_NAME "MVerb" | |||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||
#define DISTRHO_PLUGIN_IS_SYNTH 0 | |||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | |||
#define DISTRHO_PLUGIN_WANT_LATENCY 0 | |||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | |||
#define DISTRHO_PLUGIN_WANT_STATE 0 | |||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 | |||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/MVerb" | |||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -0,0 +1,235 @@ | |||
/* | |||
* DISTRHO MVerb, a DPF'ied MVerb. | |||
* Copyright (c) 2010 Martin Eastwood | |||
* Copyright (C) 2014 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 "DistrhoPluginMVerb.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoPluginMVerb::DistrhoPluginMVerb() | |||
: Plugin(MVerb<float>::NUM_PARAMS, 5, 0) // 5 program, 0 states | |||
{ | |||
fVerb.setSampleRate(d_getSampleRate()); | |||
// set initial values | |||
d_setProgram(0); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Init | |||
void DistrhoPluginMVerb::d_initParameter(uint32_t index, Parameter& parameter) | |||
{ | |||
parameter.unit = "%"; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
// default values taken from 1st preset | |||
switch (index) | |||
{ | |||
case MVerb<float>::DAMPINGFREQ: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Damping"; | |||
parameter.symbol = "damping"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::DENSITY: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Density"; | |||
parameter.symbol = "density"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::BANDWIDTHFREQ: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Bandwidth"; | |||
parameter.symbol = "bandwidth"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::DECAY: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Decay"; | |||
parameter.symbol = "decay"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::PREDELAY: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Predelay"; | |||
parameter.symbol = "predelay"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::SIZE: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Size"; | |||
parameter.symbol = "size"; | |||
parameter.ranges.def = 0.75f * 100.0f; | |||
parameter.ranges.min = 0.05f * 100.0f; | |||
break; | |||
case MVerb<float>::GAIN: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Gain"; | |||
parameter.symbol = "gain"; | |||
parameter.ranges.def = 1.0f * 100.0f; | |||
break; | |||
case MVerb<float>::MIX: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Mix"; | |||
parameter.symbol = "mix"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
case MVerb<float>::EARLYMIX: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Early/Late Mix"; | |||
parameter.symbol = "earlymix"; | |||
parameter.ranges.def = 0.5f * 100.0f; | |||
break; | |||
} | |||
} | |||
void DistrhoPluginMVerb::d_initProgramName(uint32_t index, d_string& programName) | |||
{ | |||
switch(index) | |||
{ | |||
case 0: | |||
programName = "Halves"; | |||
break; | |||
case 1: | |||
programName = "Dark"; | |||
break; | |||
case 2: | |||
programName = "Cupboard"; | |||
break; | |||
case 3: | |||
programName = "Stadium"; | |||
break; | |||
case 4: | |||
programName = "Subtle"; | |||
break; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Internal data | |||
float DistrhoPluginMVerb::d_getParameterValue(uint32_t index) const | |||
{ | |||
return fVerb.getParameter(index) * 100.0f; | |||
} | |||
void DistrhoPluginMVerb::d_setParameterValue(uint32_t index, float value) | |||
{ | |||
fVerb.setParameter(index, value / 100.0f); | |||
} | |||
void DistrhoPluginMVerb::d_setProgram(uint32_t index) | |||
{ | |||
// NOTE: DAMPINGFREQ is reversed | |||
switch(index) | |||
{ | |||
case 0: | |||
fVerb.setParameter(MVerb<float>::DAMPINGFREQ, 0.5f); | |||
fVerb.setParameter(MVerb<float>::DENSITY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::BANDWIDTHFREQ, 0.5f); | |||
fVerb.setParameter(MVerb<float>::DECAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::PREDELAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::SIZE, 0.75f); | |||
fVerb.setParameter(MVerb<float>::GAIN, 1.0f); | |||
fVerb.setParameter(MVerb<float>::MIX, 0.5f); | |||
fVerb.setParameter(MVerb<float>::EARLYMIX, 0.5f); | |||
break; | |||
case 1: | |||
fVerb.setParameter(MVerb<float>::DAMPINGFREQ, 0.1f); | |||
fVerb.setParameter(MVerb<float>::DENSITY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::BANDWIDTHFREQ, 0.1f); | |||
fVerb.setParameter(MVerb<float>::DECAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::PREDELAY, 0.0f); | |||
fVerb.setParameter(MVerb<float>::SIZE, 0.5f); | |||
fVerb.setParameter(MVerb<float>::GAIN, 1.0f); | |||
fVerb.setParameter(MVerb<float>::MIX, 0.5f); | |||
fVerb.setParameter(MVerb<float>::EARLYMIX, 0.75f); | |||
break; | |||
case 2: | |||
fVerb.setParameter(MVerb<float>::DAMPINGFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DENSITY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::BANDWIDTHFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DECAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::PREDELAY, 0.0f); | |||
fVerb.setParameter(MVerb<float>::SIZE, 0.25f); | |||
fVerb.setParameter(MVerb<float>::GAIN, 1.0f); | |||
fVerb.setParameter(MVerb<float>::MIX, 0.35f); | |||
fVerb.setParameter(MVerb<float>::EARLYMIX, 0.75f); | |||
break; | |||
case 3: | |||
fVerb.setParameter(MVerb<float>::DAMPINGFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DENSITY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::BANDWIDTHFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DECAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::PREDELAY, 0.0f); | |||
fVerb.setParameter(MVerb<float>::SIZE, 1.0f); | |||
fVerb.setParameter(MVerb<float>::GAIN, 1.0f); | |||
fVerb.setParameter(MVerb<float>::MIX, 0.35f); | |||
fVerb.setParameter(MVerb<float>::EARLYMIX, 0.75f); | |||
break; | |||
case 4: | |||
fVerb.setParameter(MVerb<float>::DAMPINGFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DENSITY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::BANDWIDTHFREQ, 1.0f); | |||
fVerb.setParameter(MVerb<float>::DECAY, 0.5f); | |||
fVerb.setParameter(MVerb<float>::PREDELAY, 0.0f); | |||
fVerb.setParameter(MVerb<float>::SIZE, 0.5f); | |||
fVerb.setParameter(MVerb<float>::GAIN, 1.0f); | |||
fVerb.setParameter(MVerb<float>::MIX, 0.15f); | |||
fVerb.setParameter(MVerb<float>::EARLYMIX, 0.75f); | |||
break; | |||
} | |||
fVerb.reset(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Process | |||
void DistrhoPluginMVerb::d_activate() | |||
{ | |||
fVerb.reset(); | |||
} | |||
void DistrhoPluginMVerb::d_run(const float** inputs, float** outputs, uint32_t frames) | |||
{ | |||
fVerb.process(inputs, outputs, frames); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Callbacks | |||
void DistrhoPluginMVerb::d_sampleRateChanged(double newSampleRate) | |||
{ | |||
fVerb.setSampleRate(newSampleRate); | |||
} | |||
// ----------------------------------------------------------------------- | |||
Plugin* createPlugin() | |||
{ | |||
return new DistrhoPluginMVerb(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,99 @@ | |||
/* | |||
* DISTRHO MVerb, a DPF'ied MVerb. | |||
* Copyright (c) 2010 Martin Eastwood | |||
* Copyright (C) 2014 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. | |||
*/ | |||
#ifndef DISTRHO_PLUGIN_MVERB_HPP_INCLUDED | |||
#define DISTRHO_PLUGIN_MVERB_HPP_INCLUDED | |||
#include "DistrhoPlugin.hpp" | |||
#include "MVerb.h" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoPluginMVerb : public Plugin | |||
{ | |||
public: | |||
DistrhoPluginMVerb(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// Information | |||
const char* d_getLabel() const noexcept override | |||
{ | |||
return "MVerb"; | |||
} | |||
const char* d_getMaker() const noexcept override | |||
{ | |||
return "Martin Eastwood, falkTX"; | |||
} | |||
const char* d_getLicense() const noexcept override | |||
{ | |||
return "GPL v3+"; | |||
} | |||
uint32_t d_getVersion() const noexcept override | |||
{ | |||
return 0x1000; | |||
} | |||
int64_t d_getUniqueId() const noexcept override | |||
{ | |||
return d_cconst('M', 'V', 'r', 'b'); | |||
} | |||
// ------------------------------------------------------------------- | |||
// Init | |||
void d_initParameter(uint32_t index, Parameter& parameter) override; | |||
void d_initProgramName(uint32_t index, d_string& programName) override; | |||
// ------------------------------------------------------------------- | |||
// Internal data | |||
float d_getParameterValue(uint32_t index) const override; | |||
void d_setParameterValue(uint32_t index, float value) override; | |||
void d_setProgram(uint32_t index) override; | |||
// ------------------------------------------------------------------- | |||
// Process | |||
void d_activate() override; | |||
void d_run(const float** inputs, float** outputs, uint32_t frames) override; | |||
// ------------------------------------------------------------------- | |||
// Callbacks | |||
void d_sampleRateChanged(double newSampleRate) override; | |||
// ------------------------------------------------------------------- | |||
private: | |||
MVerb<float> fVerb; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginMVerb) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_PLUGIN_MVERB_HPP_INCLUDED |
@@ -0,0 +1,257 @@ | |||
/* | |||
* DISTRHO MVerb, a DPF'ied MVerb. | |||
* Copyright (c) 2010 Martin Eastwood | |||
* Copyright (C) 2014 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 "DistrhoUIMVerb.hpp" | |||
#include "MVerb.h" | |||
#include "font/Kh-Kangrey.h" | |||
START_NAMESPACE_DISTRHO | |||
using DGL::Color; | |||
// ----------------------------------------------------------------------- | |||
DistrhoUIMVerb::DistrhoUIMVerb() | |||
: UI() | |||
{ | |||
// set UI size | |||
setSize(DistrhoArtworkMVerb::backgroundWidth, DistrhoArtworkMVerb::backgroundHeight); | |||
// background | |||
fImgBackground = Image(DistrhoArtworkMVerb::backgroundData, DistrhoArtworkMVerb::backgroundWidth, DistrhoArtworkMVerb::backgroundHeight, GL_BGR); | |||
// text | |||
fNanoText.createFontMem("kh", (uchar*)khkangrey_ttf, khkangrey_ttfSize, false); | |||
// knobs | |||
Image knobImage(DistrhoArtworkMVerb::knobData, DistrhoArtworkMVerb::knobWidth, DistrhoArtworkMVerb::knobHeight); | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::DAMPINGFREQ)); | |||
knob->setAbsolutePos(56 + 7*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::DENSITY)); | |||
knob->setAbsolutePos(56 + 4*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::BANDWIDTHFREQ)); | |||
knob->setAbsolutePos(56 + 5*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::DECAY)); | |||
knob->setAbsolutePos(56 + 6*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::PREDELAY)); | |||
knob->setAbsolutePos(56 + 1*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::SIZE)); | |||
knob->setAbsolutePos(56 + 3*40, 40); | |||
knob->setRange(5.0f, 100.0f); | |||
knob->setDefault(100.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::GAIN)); | |||
knob->setAbsolutePos(56 + 8*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(75.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::MIX)); | |||
knob->setAbsolutePos(56 + 0*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
{ | |||
ImageKnob* const knob(new ImageKnob(this, knobImage, ImageKnob::Vertical, MVerb<float>::EARLYMIX)); | |||
knob->setAbsolutePos(56 + 2*40, 40); | |||
knob->setRange(0.0f, 100.0f); | |||
knob->setDefault(50.0f); | |||
knob->setCallback(this); | |||
fKnobs.push_back(knob); | |||
} | |||
// set initial values | |||
d_programChanged(0); | |||
} | |||
DistrhoUIMVerb::~DistrhoUIMVerb() | |||
{ | |||
for (std::vector<ImageKnob*>::iterator it=fKnobs.begin(), end=fKnobs.end(); it != end; ++it) | |||
{ | |||
ImageKnob* const knob(*it); | |||
delete knob; | |||
} | |||
fKnobs.clear(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void DistrhoUIMVerb::d_parameterChanged(uint32_t index, float value) | |||
{ | |||
fKnobs[index]->setValue(value); | |||
} | |||
void DistrhoUIMVerb::d_programChanged(uint32_t index) | |||
{ | |||
switch(index) | |||
{ | |||
case 0: | |||
fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::PREDELAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::MIX]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::EARLYMIX]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::SIZE]->setValue(0.75f*100.0f); | |||
break; | |||
case 1: | |||
fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.9f*100.0f); | |||
fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(0.1f*100.0f); | |||
fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::SIZE]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::MIX]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f); | |||
break; | |||
case 2: | |||
fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::SIZE]->setValue(0.25f*100.0f); | |||
fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::MIX]->setValue(0.35f*100.0f); | |||
fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f); | |||
break; | |||
case 3: | |||
fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::SIZE]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::MIX]->setValue(0.35f*100.0f); | |||
fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f); | |||
break; | |||
case 4: | |||
fKnobs[MVerb<float>::DAMPINGFREQ]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::DENSITY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::BANDWIDTHFREQ]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::DECAY]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::PREDELAY]->setValue(0.0f*100.0f); | |||
fKnobs[MVerb<float>::SIZE]->setValue(0.5f*100.0f); | |||
fKnobs[MVerb<float>::GAIN]->setValue(1.0f*100.0f); | |||
fKnobs[MVerb<float>::MIX]->setValue(0.15f*100.0f); | |||
fKnobs[MVerb<float>::EARLYMIX]->setValue(0.75f*100.0f); | |||
break; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Widget Callbacks | |||
void DistrhoUIMVerb::imageKnobDragStarted(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), true); | |||
} | |||
void DistrhoUIMVerb::imageKnobDragFinished(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), false); | |||
} | |||
void DistrhoUIMVerb::imageKnobValueChanged(ImageKnob* knob, float value) | |||
{ | |||
d_setParameterValue(knob->getId(), value); | |||
} | |||
void DistrhoUIMVerb::onDisplay() | |||
{ | |||
fImgBackground.draw(); | |||
// text display | |||
fNanoText.beginFrame(getWidth(), getHeight()); | |||
fNanoText.fontFace("kh"); | |||
fNanoText.fontSize(20); | |||
fNanoText.textAlign(NanoVG::Align(NanoVG::ALIGN_CENTER|NanoVG::ALIGN_TOP)); | |||
fNanoText.fillColor(Color(1.0f, 1.0f, 1.0f)); | |||
char strBuf[32+1]; | |||
strBuf[32] = '\0'; | |||
for (int i=0; i<MVerb<float>::NUM_PARAMS; ++i) | |||
{ | |||
std::snprintf(strBuf, 32, "%i%%", int(fKnobs[i]->getValue())); | |||
fNanoText.textBox(58 + fKnobs[i]->getAbsoluteX()-56, 73, 30.0f, strBuf, nullptr); | |||
} | |||
fNanoText.endFrame(); | |||
// just in case | |||
glDisable(GL_CULL_FACE); | |||
} | |||
// ----------------------------------------------------------------------- | |||
UI* createUI() | |||
{ | |||
return new DistrhoUIMVerb(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,74 @@ | |||
/* | |||
* DISTRHO MVerb, a DPF'ied MVerb. | |||
* Copyright (c) 2010 Martin Eastwood | |||
* Copyright (C) 2014 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. | |||
*/ | |||
#ifndef DISTRHO_UI_MVERB_HPP_INCLUDED | |||
#define DISTRHO_UI_MVERB_HPP_INCLUDED | |||
#include "DistrhoUI.hpp" | |||
#include "ImageKnob.hpp" | |||
#include "NanoVG.hpp" | |||
#include "DistrhoArtworkMVerb.hpp" | |||
#include <vector> | |||
using DGL::Image; | |||
using DGL::ImageKnob; | |||
using DGL::NanoVG; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoUIMVerb : public UI, | |||
public ImageKnob::Callback | |||
{ | |||
public: | |||
DistrhoUIMVerb(); | |||
~DistrhoUIMVerb() override; | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void d_parameterChanged(uint32_t index, float value) override; | |||
void d_programChanged(uint32_t index) override; | |||
// ------------------------------------------------------------------- | |||
// Widget Callbacks | |||
void imageKnobDragStarted(ImageKnob* knob) override; | |||
void imageKnobDragFinished(ImageKnob* knob) override; | |||
void imageKnobValueChanged(ImageKnob* knob, float value) override; | |||
void onDisplay() override; | |||
private: | |||
Image fImgBackground; | |||
NanoVG fNanoText; | |||
std::vector<ImageKnob*> fKnobs; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUIMVerb) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_UI_MVERB_HPP_INCLUDED |
@@ -0,0 +1,842 @@ | |||
// Copyright (c) 2010 Martin Eastwood | |||
// This code is distributed under the terms of the GNU General Public License | |||
// MVerb 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 | |||
// at your option) any later version. | |||
// | |||
// MVerb 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. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this MVerb. If not, see <http://www.gnu.org/licenses/>. | |||
#ifndef EMVERB_H | |||
#define EMVERB_H | |||
#include <cmath> | |||
#include <cstring> | |||
//forward declaration | |||
template<typename T, int maxLength> class Allpass; | |||
template<typename T, int maxLength> class StaticAllpassFourTap; | |||
template<typename T, int maxLength> class StaticDelayLine; | |||
template<typename T, int maxLength> class StaticDelayLineFourTap; | |||
template<typename T, int maxLength> class StaticDelayLineEightTap; | |||
template<typename T, int OverSampleCount> class StateVariable; | |||
template<typename T> | |||
class MVerb | |||
{ | |||
private: | |||
Allpass<T, 96000> allpass[4]; | |||
StaticAllpassFourTap<T, 96000> allpassFourTap[4]; | |||
StateVariable<T,4> bandwidthFilter[2]; | |||
StateVariable<T,4> damping[2]; | |||
StaticDelayLine<T, 96000> predelay; | |||
StaticDelayLineFourTap<T, 96000> staticDelayLine[4]; | |||
StaticDelayLineEightTap<T, 96000> earlyReflectionsDelayLine[2]; | |||
T SampleRate, DampingFreq, Density1, Density2, BandwidthFreq, PreDelayTime, Decay, Gain, Mix, EarlyMix, Size; | |||
T MixSmooth, EarlyLateSmooth, BandwidthSmooth, DampingSmooth, PredelaySmooth, SizeSmooth, DensitySmooth, DecaySmooth; | |||
T PreviousLeftTank, PreviousRightTank; | |||
int ControlRate, ControlRateCounter; | |||
public: | |||
enum | |||
{ | |||
DAMPINGFREQ=0, | |||
DENSITY, | |||
BANDWIDTHFREQ, | |||
DECAY, | |||
PREDELAY, | |||
SIZE, | |||
GAIN, | |||
MIX, | |||
EARLYMIX, | |||
NUM_PARAMS | |||
}; | |||
MVerb(){ | |||
DampingFreq = 18000.; | |||
BandwidthFreq = 18000.; | |||
SampleRate = 44100.; | |||
Decay = 0.5; | |||
Gain = 1.; | |||
Mix = 1.; | |||
Size = 1.; | |||
EarlyMix = 1.; | |||
PreviousLeftTank = 0.; | |||
PreviousRightTank = 0.; | |||
PreDelayTime = 100 * (SampleRate / 1000); | |||
MixSmooth = EarlyLateSmooth = BandwidthSmooth = DampingSmooth = PredelaySmooth = SizeSmooth = DecaySmooth = DensitySmooth = 0.; | |||
ControlRate = SampleRate / 1000; | |||
ControlRateCounter = 0; | |||
reset(); | |||
} | |||
~MVerb(){ | |||
//nowt to do here | |||
} | |||
void process(const T **inputs, T **outputs, int sampleFrames){ | |||
T OneOverSampleFrames = 1. / sampleFrames; | |||
T MixDelta = (Mix - MixSmooth) * OneOverSampleFrames; | |||
T EarlyLateDelta = (EarlyMix - EarlyLateSmooth) * OneOverSampleFrames; | |||
T BandwidthDelta = (((BandwidthFreq * 18400.) + 100.) - BandwidthSmooth) * OneOverSampleFrames; | |||
T DampingDelta = (((DampingFreq * 18400.) + 100.) - DampingSmooth) * OneOverSampleFrames; | |||
T PredelayDelta = ((PreDelayTime * 200 * (SampleRate / 1000)) - PredelaySmooth) * OneOverSampleFrames; | |||
T SizeDelta = (Size - SizeSmooth) * OneOverSampleFrames; | |||
T DecayDelta = (((0.7995f * Decay) + 0.005) - DecaySmooth) * OneOverSampleFrames; | |||
T DensityDelta = (((0.7995f * Density1) + 0.005) - DensitySmooth) * OneOverSampleFrames; | |||
for(int i=0;i<sampleFrames;++i){ | |||
T left = inputs[0][i]; | |||
T right = inputs[1][i]; | |||
MixSmooth += MixDelta; | |||
EarlyLateSmooth += EarlyLateDelta; | |||
BandwidthSmooth += BandwidthDelta; | |||
DampingSmooth += DampingDelta; | |||
PredelaySmooth += PredelayDelta; | |||
SizeSmooth += SizeDelta; | |||
DecaySmooth += DecayDelta; | |||
DensitySmooth += DensityDelta; | |||
if (ControlRateCounter >= ControlRate){ | |||
ControlRateCounter = 0; | |||
bandwidthFilter[0].Frequency(BandwidthSmooth); | |||
bandwidthFilter[1].Frequency(BandwidthSmooth); | |||
damping[0].Frequency(DampingSmooth); | |||
damping[1].Frequency(DampingSmooth); | |||
} | |||
++ControlRateCounter; | |||
predelay.SetLength(PredelaySmooth); | |||
Density2 = DecaySmooth + 0.15; | |||
if (Density2 > 0.5) | |||
Density2 = 0.5; | |||
if (Density2 < 0.25) | |||
Density2 = 0.25; | |||
allpassFourTap[1].SetFeedback(Density2); | |||
allpassFourTap[3].SetFeedback(Density2); | |||
allpassFourTap[0].SetFeedback(Density1); | |||
allpassFourTap[2].SetFeedback(Density1); | |||
T bandwidthLeft = bandwidthFilter[0](left) ; | |||
T bandwidthRight = bandwidthFilter[1](right) ; | |||
T earlyReflectionsL = earlyReflectionsDelayLine[0] ( bandwidthLeft * 0.5 + bandwidthRight * 0.3 ) | |||
+ earlyReflectionsDelayLine[0].GetIndex(2) * 0.6 | |||
+ earlyReflectionsDelayLine[0].GetIndex(3) * 0.4 | |||
+ earlyReflectionsDelayLine[0].GetIndex(4) * 0.3 | |||
+ earlyReflectionsDelayLine[0].GetIndex(5) * 0.3 | |||
+ earlyReflectionsDelayLine[0].GetIndex(6) * 0.1 | |||
+ earlyReflectionsDelayLine[0].GetIndex(7) * 0.1 | |||
+ ( bandwidthLeft * 0.4 + bandwidthRight * 0.2 ) * 0.5 ; | |||
T earlyReflectionsR = earlyReflectionsDelayLine[1] ( bandwidthLeft * 0.3 + bandwidthRight * 0.5 ) | |||
+ earlyReflectionsDelayLine[1].GetIndex(2) * 0.6 | |||
+ earlyReflectionsDelayLine[1].GetIndex(3) * 0.4 | |||
+ earlyReflectionsDelayLine[1].GetIndex(4) * 0.3 | |||
+ earlyReflectionsDelayLine[1].GetIndex(5) * 0.3 | |||
+ earlyReflectionsDelayLine[1].GetIndex(6) * 0.1 | |||
+ earlyReflectionsDelayLine[1].GetIndex(7) * 0.1 | |||
+ ( bandwidthLeft * 0.2 + bandwidthRight * 0.4 ) * 0.5 ; | |||
T predelayMonoInput = predelay(( bandwidthRight + bandwidthLeft ) * 0.5f); | |||
T smearedInput = predelayMonoInput; | |||
for(int j=0;j<4;j++) | |||
smearedInput = allpass[j] ( smearedInput ); | |||
T leftTank = allpassFourTap[0] ( smearedInput + PreviousRightTank ) ; | |||
leftTank = staticDelayLine[0] (leftTank); | |||
leftTank = damping[0](leftTank); | |||
leftTank = allpassFourTap[1](leftTank); | |||
leftTank = staticDelayLine[1](leftTank); | |||
T rightTank = allpassFourTap[2] (smearedInput + PreviousLeftTank) ; | |||
rightTank = staticDelayLine[2](rightTank); | |||
rightTank = damping[1] (rightTank); | |||
rightTank = allpassFourTap[3](rightTank); | |||
rightTank = staticDelayLine[3](rightTank); | |||
PreviousLeftTank = leftTank * DecaySmooth; | |||
PreviousRightTank = rightTank * DecaySmooth; | |||
T accumulatorL = (0.6*staticDelayLine[2].GetIndex(1)) | |||
+(0.6*staticDelayLine[2].GetIndex(2)) | |||
-(0.6*allpassFourTap[3].GetIndex(1)) | |||
+(0.6*staticDelayLine[3].GetIndex(1)) | |||
-(0.6*staticDelayLine[0].GetIndex(1)) | |||
-(0.6*allpassFourTap[1].GetIndex(1)) | |||
-(0.6*staticDelayLine[1].GetIndex(1)); | |||
T accumulatorR = (0.6*staticDelayLine[0].GetIndex(2)) | |||
+(0.6*staticDelayLine[0].GetIndex(3)) | |||
-(0.6*allpassFourTap[1].GetIndex(2)) | |||
+(0.6*staticDelayLine[1].GetIndex(2)) | |||
-(0.6*staticDelayLine[2].GetIndex(3)) | |||
-(0.6*allpassFourTap[3].GetIndex(2)) | |||
-(0.6*staticDelayLine[3].GetIndex(2)); | |||
accumulatorL = ((accumulatorL * EarlyMix) + ((1 - EarlyMix) * earlyReflectionsL)); | |||
accumulatorR = ((accumulatorR * EarlyMix) + ((1 - EarlyMix) * earlyReflectionsR)); | |||
left = ( left + MixSmooth * ( accumulatorL - left ) ) * Gain; | |||
right = ( right + MixSmooth * ( accumulatorR - right ) ) * Gain; | |||
outputs[0][i] = left; | |||
outputs[1][i] = right; | |||
} | |||
} | |||
void reset(){ | |||
ControlRateCounter = 0; | |||
bandwidthFilter[0].SetSampleRate (SampleRate ); | |||
bandwidthFilter[1].SetSampleRate (SampleRate ); | |||
bandwidthFilter[0].Reset(); | |||
bandwidthFilter[1].Reset(); | |||
damping[0].SetSampleRate (SampleRate ); | |||
damping[1].SetSampleRate (SampleRate ); | |||
damping[0].Reset(); | |||
damping[1].Reset(); | |||
predelay.Clear(); | |||
predelay.SetLength(PreDelayTime); | |||
allpass[0].Clear(); | |||
allpass[1].Clear(); | |||
allpass[2].Clear(); | |||
allpass[3].Clear(); | |||
allpass[0].SetLength (0.0048 * SampleRate); | |||
allpass[1].SetLength (0.0036 * SampleRate); | |||
allpass[2].SetLength (0.0127 * SampleRate); | |||
allpass[3].SetLength (0.0093 * SampleRate); | |||
allpass[0].SetFeedback (0.75); | |||
allpass[1].SetFeedback (0.75); | |||
allpass[2].SetFeedback (0.625); | |||
allpass[3].SetFeedback (0.625); | |||
allpassFourTap[0].Clear(); | |||
allpassFourTap[1].Clear(); | |||
allpassFourTap[2].Clear(); | |||
allpassFourTap[3].Clear(); | |||
allpassFourTap[0].SetLength(0.020 * SampleRate * Size); | |||
allpassFourTap[1].SetLength(0.060 * SampleRate * Size); | |||
allpassFourTap[2].SetLength(0.030 * SampleRate * Size); | |||
allpassFourTap[3].SetLength(0.089 * SampleRate * Size); | |||
allpassFourTap[0].SetFeedback(Density1); | |||
allpassFourTap[1].SetFeedback(Density2); | |||
allpassFourTap[2].SetFeedback(Density1); | |||
allpassFourTap[3].SetFeedback(Density2); | |||
allpassFourTap[0].SetIndex(0,0,0,0); | |||
allpassFourTap[1].SetIndex(0,0.006 * SampleRate * Size, 0.041 * SampleRate * Size, 0); | |||
allpassFourTap[2].SetIndex(0,0,0,0); | |||
allpassFourTap[3].SetIndex(0,0.031 * SampleRate * Size, 0.011 * SampleRate * Size, 0); | |||
staticDelayLine[0].Clear(); | |||
staticDelayLine[1].Clear(); | |||
staticDelayLine[2].Clear(); | |||
staticDelayLine[3].Clear(); | |||
staticDelayLine[0].SetLength(0.15 * SampleRate * Size); | |||
staticDelayLine[1].SetLength(0.12 * SampleRate * Size); | |||
staticDelayLine[2].SetLength(0.14 * SampleRate * Size); | |||
staticDelayLine[3].SetLength(0.11 * SampleRate * Size); | |||
staticDelayLine[0].SetIndex(0, 0.067 * SampleRate * Size, 0.011 * SampleRate * Size , 0.121 * SampleRate * Size); | |||
staticDelayLine[1].SetIndex(0, 0.036 * SampleRate * Size, 0.089 * SampleRate * Size , 0); | |||
staticDelayLine[2].SetIndex(0, 0.0089 * SampleRate * Size, 0.099 * SampleRate * Size , 0); | |||
staticDelayLine[3].SetIndex(0, 0.067 * SampleRate * Size, 0.0041 * SampleRate * Size , 0); | |||
earlyReflectionsDelayLine[0].Clear(); | |||
earlyReflectionsDelayLine[1].Clear(); | |||
earlyReflectionsDelayLine[0].SetLength(0.089 * SampleRate); | |||
earlyReflectionsDelayLine[0].SetIndex (0, 0.0199*SampleRate, 0.0219*SampleRate, 0.0354*SampleRate,0.0389*SampleRate, 0.0414*SampleRate, 0.0692*SampleRate, 0); | |||
earlyReflectionsDelayLine[1].SetLength(0.069 * SampleRate); | |||
earlyReflectionsDelayLine[1].SetIndex (0, 0.0099*SampleRate, 0.011*SampleRate, 0.0182*SampleRate,0.0189*SampleRate, 0.0213*SampleRate, 0.0431*SampleRate, 0); | |||
} | |||
void setParameter(int index, T value){ | |||
switch(index){ | |||
case DAMPINGFREQ: | |||
DampingFreq = /* 1. - */ value; // FIXME? | |||
break; | |||
case DENSITY: | |||
Density1 = value; | |||
break; | |||
case BANDWIDTHFREQ: | |||
BandwidthFreq = value; | |||
break; | |||
case PREDELAY: | |||
PreDelayTime = value; | |||
break; | |||
case SIZE: | |||
Size = value; | |||
allpassFourTap[0].Clear(); | |||
allpassFourTap[1].Clear(); | |||
allpassFourTap[2].Clear(); | |||
allpassFourTap[3].Clear(); | |||
allpassFourTap[0].SetLength(0.020 * SampleRate * Size); | |||
allpassFourTap[1].SetLength(0.060 * SampleRate * Size); | |||
allpassFourTap[2].SetLength(0.030 * SampleRate * Size); | |||
allpassFourTap[3].SetLength(0.089 * SampleRate * Size); | |||
allpassFourTap[1].SetIndex(0,0.006 * SampleRate * Size, 0.041 * SampleRate * Size, 0); | |||
allpassFourTap[3].SetIndex(0,0.031 * SampleRate * Size, 0.011 * SampleRate * Size, 0); | |||
staticDelayLine[0].Clear(); | |||
staticDelayLine[1].Clear(); | |||
staticDelayLine[2].Clear(); | |||
staticDelayLine[3].Clear(); | |||
staticDelayLine[0].SetLength(0.15 * SampleRate * Size); | |||
staticDelayLine[1].SetLength(0.12 * SampleRate * Size); | |||
staticDelayLine[2].SetLength(0.14 * SampleRate * Size); | |||
staticDelayLine[3].SetLength(0.11 * SampleRate * Size); | |||
staticDelayLine[0].SetIndex(0, 0.067 * SampleRate * Size, 0.011 * SampleRate * Size , 0.121 * SampleRate * Size); | |||
staticDelayLine[1].SetIndex(0, 0.036 * SampleRate * Size, 0.089 * SampleRate * Size , 0); | |||
staticDelayLine[2].SetIndex(0, 0.0089 * SampleRate * Size, 0.099 * SampleRate * Size , 0); | |||
staticDelayLine[3].SetIndex(0, 0.067 * SampleRate * Size, 0.0041 * SampleRate * Size , 0); | |||
break; | |||
case DECAY: | |||
Decay = value; | |||
break; | |||
case GAIN: | |||
Gain = value; | |||
break; | |||
case MIX: | |||
Mix = value; | |||
break; | |||
case EARLYMIX: | |||
EarlyMix = value; | |||
break; | |||
} | |||
} | |||
float getParameter(int index) const{ | |||
switch(index){ | |||
case DAMPINGFREQ: | |||
return DampingFreq; | |||
break; | |||
case DENSITY: | |||
return Density1; | |||
break; | |||
case BANDWIDTHFREQ: | |||
return BandwidthFreq; | |||
break; | |||
case PREDELAY: | |||
return PreDelayTime; | |||
break; | |||
case SIZE: | |||
return Size; | |||
break; | |||
case DECAY: | |||
return Decay; | |||
break; | |||
case GAIN: | |||
return Gain; | |||
break; | |||
case MIX: | |||
return Mix; | |||
break; | |||
case EARLYMIX: | |||
return EarlyMix; | |||
break; | |||
default: return 0.f; | |||
break; | |||
} | |||
} | |||
void setSampleRate(T sr){ | |||
SampleRate = sr; | |||
ControlRate = SampleRate / 1000; | |||
reset(); | |||
} | |||
}; | |||
template<typename T, int maxLength> | |||
class Allpass | |||
{ | |||
private: | |||
T buffer[maxLength]; | |||
int index; | |||
int Length; | |||
T Feedback; | |||
public: | |||
Allpass() | |||
{ | |||
SetLength ( maxLength - 1 ); | |||
Clear(); | |||
Feedback = 0.5; | |||
} | |||
T operator()(T input) | |||
{ | |||
T output; | |||
T bufout; | |||
bufout = buffer[index]; | |||
T temp = input * -Feedback; | |||
output = bufout + temp; | |||
buffer[index] = input + ((bufout+temp)*Feedback); | |||
if(++index>=Length) index = 0; | |||
return output; | |||
} | |||
void SetLength (int Length) | |||
{ | |||
if( Length >= maxLength ) | |||
Length = maxLength; | |||
if( Length < 0 ) | |||
Length = 0; | |||
this->Length = Length; | |||
} | |||
void SetFeedback(T feedback) | |||
{ | |||
Feedback = feedback; | |||
} | |||
void Clear() | |||
{ | |||
std::memset(buffer, 0, sizeof(buffer)); | |||
index = 0; | |||
} | |||
int GetLength() const | |||
{ | |||
return Length; | |||
} | |||
}; | |||
template<typename T, int maxLength> | |||
class StaticAllpassFourTap | |||
{ | |||
private: | |||
T buffer[maxLength]; | |||
int index1, index2, index3, index4; | |||
int Length; | |||
T Feedback; | |||
public: | |||
StaticAllpassFourTap() | |||
{ | |||
SetLength ( maxLength - 1 ); | |||
Clear(); | |||
Feedback = 0.5; | |||
} | |||
T operator()(T input) | |||
{ | |||
T output; | |||
T bufout; | |||
bufout = buffer[index1]; | |||
T temp = input * -Feedback; | |||
output = bufout + temp; | |||
buffer[index1] = input + ((bufout+temp)*Feedback); | |||
if(++index1>=Length) | |||
index1 = 0; | |||
if(++index2 >= Length) | |||
index2 = 0; | |||
if(++index3 >= Length) | |||
index3 = 0; | |||
if(++index4 >= Length) | |||
index4 = 0; | |||
return output; | |||
} | |||
void SetIndex (int Index1, int Index2, int Index3, int Index4) | |||
{ | |||
index1 = Index1; | |||
index2 = Index2; | |||
index3 = Index3; | |||
index4 = Index4; | |||
} | |||
T GetIndex (int Index) | |||
{ | |||
switch (Index) | |||
{ | |||
case 0: | |||
return buffer[index1]; | |||
break; | |||
case 1: | |||
return buffer[index2]; | |||
break; | |||
case 2: | |||
return buffer[index3]; | |||
break; | |||
case 3: | |||
return buffer[index4]; | |||
break; | |||
default: | |||
return buffer[index1]; | |||
break; | |||
} | |||
} | |||
void SetLength (int Length) | |||
{ | |||
if( Length >= maxLength ) | |||
Length = maxLength; | |||
if( Length < 0 ) | |||
Length = 0; | |||
this->Length = Length; | |||
} | |||
void Clear() | |||
{ | |||
std::memset(buffer, 0, sizeof(buffer)); | |||
index1 = index2 = index3 = index4 = 0; | |||
} | |||
void SetFeedback(T feedback) | |||
{ | |||
Feedback = feedback; | |||
} | |||
int GetLength() const | |||
{ | |||
return Length; | |||
} | |||
}; | |||
template<typename T, int maxLength> | |||
class StaticDelayLine | |||
{ | |||
private: | |||
T buffer[maxLength]; | |||
int index; | |||
int Length; | |||
T Feedback; | |||
public: | |||
StaticDelayLine() | |||
{ | |||
SetLength ( maxLength - 1 ); | |||
Clear(); | |||
} | |||
T operator()(T input) | |||
{ | |||
T output = buffer[index]; | |||
buffer[index++] = input; | |||
if(index >= Length) | |||
index = 0; | |||
return output; | |||
} | |||
void SetLength (int Length) | |||
{ | |||
if( Length >= maxLength ) | |||
Length = maxLength; | |||
if( Length < 0 ) | |||
Length = 0; | |||
this->Length = Length; | |||
} | |||
void Clear() | |||
{ | |||
std::memset(buffer, 0, sizeof(buffer)); | |||
index = 0; | |||
} | |||
int GetLength() const | |||
{ | |||
return Length; | |||
} | |||
}; | |||
template<typename T, int maxLength> | |||
class StaticDelayLineFourTap | |||
{ | |||
private: | |||
T buffer[maxLength]; | |||
int index1, index2, index3, index4; | |||
int Length; | |||
T Feedback; | |||
public: | |||
StaticDelayLineFourTap() | |||
{ | |||
SetLength ( maxLength - 1 ); | |||
Clear(); | |||
} | |||
//get ouput and iterate | |||
T operator()(T input) | |||
{ | |||
T output = buffer[index1]; | |||
buffer[index1++] = input; | |||
if(index1 >= Length) | |||
index1 = 0; | |||
if(++index2 >= Length) | |||
index2 = 0; | |||
if(++index3 >= Length) | |||
index3 = 0; | |||
if(++index4 >= Length) | |||
index4 = 0; | |||
return output; | |||
} | |||
void SetIndex (int Index1, int Index2, int Index3, int Index4) | |||
{ | |||
index1 = Index1; | |||
index2 = Index2; | |||
index3 = Index3; | |||
index4 = Index4; | |||
} | |||
T GetIndex (int Index) | |||
{ | |||
switch (Index) | |||
{ | |||
case 0: | |||
return buffer[index1]; | |||
break; | |||
case 1: | |||
return buffer[index2]; | |||
break; | |||
case 2: | |||
return buffer[index3]; | |||
break; | |||
case 3: | |||
return buffer[index4]; | |||
break; | |||
default: | |||
return buffer[index1]; | |||
break; | |||
} | |||
} | |||
void SetLength (int Length) | |||
{ | |||
if( Length >= maxLength ) | |||
Length = maxLength; | |||
if( Length < 0 ) | |||
Length = 0; | |||
this->Length = Length; | |||
} | |||
void Clear() | |||
{ | |||
std::memset(buffer, 0, sizeof(buffer)); | |||
index1 = index2 = index3 = index4 = 0; | |||
} | |||
int GetLength() const | |||
{ | |||
return Length; | |||
} | |||
}; | |||
template<typename T, int maxLength> | |||
class StaticDelayLineEightTap | |||
{ | |||
private: | |||
T buffer[maxLength]; | |||
int index1, index2, index3, index4, index5, index6, index7, index8; | |||
int Length; | |||
T Feedback; | |||
public: | |||
StaticDelayLineEightTap() | |||
{ | |||
SetLength ( maxLength - 1 ); | |||
Clear(); | |||
} | |||
//get ouput and iterate | |||
T operator()(T input) | |||
{ | |||
T output = buffer[index1]; | |||
buffer[index1++] = input; | |||
if(index1 >= Length) | |||
index1 = 0; | |||
if(++index2 >= Length) | |||
index2 = 0; | |||
if(++index3 >= Length) | |||
index3 = 0; | |||
if(++index4 >= Length) | |||
index4 = 0; | |||
if(++index5 >= Length) | |||
index5 = 0; | |||
if(++index6 >= Length) | |||
index6 = 0; | |||
if(++index7 >= Length) | |||
index7 = 0; | |||
if(++index8 >= Length) | |||
index8 = 0; | |||
return output; | |||
} | |||
void SetIndex (int Index1, int Index2, int Index3, int Index4, int Index5, int Index6, int Index7, int Index8) | |||
{ | |||
index1 = Index1; | |||
index2 = Index2; | |||
index3 = Index3; | |||
index4 = Index4; | |||
index5 = Index5; | |||
index6 = Index6; | |||
index7 = Index7; | |||
index8 = Index8; | |||
} | |||
T GetIndex (int Index) | |||
{ | |||
switch (Index) | |||
{ | |||
case 0: | |||
return buffer[index1]; | |||
break; | |||
case 1: | |||
return buffer[index2]; | |||
break; | |||
case 2: | |||
return buffer[index3]; | |||
break; | |||
case 3: | |||
return buffer[index4]; | |||
break; | |||
case 4: | |||
return buffer[index5]; | |||
break; | |||
case 5: | |||
return buffer[index6]; | |||
break; | |||
case 6: | |||
return buffer[index7]; | |||
break; | |||
case 7: | |||
return buffer[index8]; | |||
break; | |||
default: | |||
return buffer[index1]; | |||
break; | |||
} | |||
} | |||
void SetLength (int Length) | |||
{ | |||
if( Length >= maxLength ) | |||
Length = maxLength; | |||
if( Length < 0 ) | |||
Length = 0; | |||
this->Length = Length; | |||
} | |||
void Clear() | |||
{ | |||
std::memset(buffer, 0, sizeof(buffer)); | |||
index1 = index2 = index3 = index4 = index5 = index6 = index7 = index8 = 0; | |||
} | |||
int GetLength() const | |||
{ | |||
return Length; | |||
} | |||
}; | |||
template<typename T, int OverSampleCount> | |||
class StateVariable | |||
{ | |||
public: | |||
enum FilterType | |||
{ | |||
LOWPASS, | |||
HIGHPASS, | |||
BANDPASS, | |||
NOTCH, | |||
FilterTypeCount | |||
}; | |||
private: | |||
T sampleRate; | |||
T frequency; | |||
T q; | |||
T f; | |||
T low; | |||
T high; | |||
T band; | |||
T notch; | |||
T *out; | |||
public: | |||
StateVariable() | |||
{ | |||
SetSampleRate(44100.); | |||
Frequency(1000.); | |||
Resonance(0); | |||
Type(LOWPASS); | |||
Reset(); | |||
} | |||
T operator()(T input) | |||
{ | |||
for(unsigned int i = 0; i < OverSampleCount; i++) | |||
{ | |||
low += f * band + 1e-25; | |||
high = input - low - q * band; | |||
band += f * high; | |||
notch = low + high; | |||
} | |||
return *out; | |||
} | |||
void Reset() | |||
{ | |||
low = high = band = notch = 0; | |||
} | |||
void SetSampleRate(T sampleRate) | |||
{ | |||
this->sampleRate = sampleRate * OverSampleCount; | |||
UpdateCoefficient(); | |||
} | |||
void Frequency(T frequency) | |||
{ | |||
this->frequency = frequency; | |||
UpdateCoefficient(); | |||
} | |||
void Resonance(T resonance) | |||
{ | |||
this->q = 2 - 2 * resonance; | |||
} | |||
void Type(int type) | |||
{ | |||
switch(type) | |||
{ | |||
case LOWPASS: | |||
out = &low; | |||
break; | |||
case HIGHPASS: | |||
out = &high; | |||
break; | |||
case BANDPASS: | |||
out = &band; | |||
break; | |||
case NOTCH: | |||
out = ¬ch; | |||
break; | |||
default: | |||
out = &low; | |||
break; | |||
} | |||
} | |||
private: | |||
void UpdateCoefficient() | |||
{ | |||
f = 2. * std::sin(M_PI * frequency / sampleRate); | |||
} | |||
}; | |||
#endif |
@@ -0,0 +1,9 @@ | |||
/* binary data of Kh-Kangrey.ttf */ | |||
#ifndef BINARY_KH_KANGREY_H | |||
#define BINARY_KH_KANGREY_H | |||
extern const char* khkangrey_ttf; | |||
const int khkangrey_ttfSize = 158316; | |||
#endif |
@@ -0,0 +1,72 @@ | |||
/* | |||
* Carla Native Plugins | |||
* 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 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 | |||
// Plugin Code | |||
#include "distrho-nekobi/DistrhoArtworkNekobi.cpp" | |||
#include "distrho-nekobi/DistrhoPluginNekobi.cpp" | |||
#include "distrho-nekobi/DistrhoUINekobi.cpp" | |||
// DISTRHO Code | |||
#define DISTRHO_PLUGIN_TARGET_CARLA | |||
#include "DistrhoPluginMain.cpp" | |||
#include "DistrhoUIMain.cpp" | |||
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_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() | |||
{ | |||
USE_NAMESPACE_DISTRHO | |||
carla_register_native_plugin(&nekobiDesc); | |||
} | |||
// ----------------------------------------------------------------------- |
@@ -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 | |||
@@ -0,0 +1,36 @@ | |||
/* | |||
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. | |||
* Copyright (C) 2013-2014 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_NAME "Nekobi" | |||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||
#define DISTRHO_PLUGIN_IS_SYNTH 1 | |||
#define DISTRHO_PLUGIN_NUM_INPUTS 0 | |||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1 | |||
#define DISTRHO_PLUGIN_WANT_LATENCY 0 | |||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 0 | |||
#define DISTRHO_PLUGIN_WANT_STATE 0 | |||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 | |||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Nekobi" | |||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -0,0 +1,404 @@ | |||
/* | |||
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. | |||
* Copyright (C) 2004 Sean Bolton and others | |||
* Copyright (C) 2013-2014 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. | |||
*/ | |||
#include "DistrhoPluginNekobi.hpp" | |||
extern "C" { | |||
#include "nekobee-src/nekobee_synth.c" | |||
#include "nekobee-src/nekobee_voice.c" | |||
#include "nekobee-src/nekobee_voice_render.c" | |||
#include "nekobee-src/minblep_tables.c" | |||
// ----------------------------------------------------------------------- | |||
// mutual exclusion | |||
bool dssp_voicelist_mutex_trylock(nekobee_synth_t* const synth) | |||
{ | |||
/* Attempt the mutex lock */ | |||
if (pthread_mutex_trylock(&synth->voicelist_mutex) != 0) | |||
{ | |||
synth->voicelist_mutex_grab_failed = 1; | |||
return false; | |||
} | |||
/* Clean up if a previous mutex grab failed */ | |||
if (synth->voicelist_mutex_grab_failed) | |||
{ | |||
nekobee_synth_all_voices_off(synth); | |||
synth->voicelist_mutex_grab_failed = 0; | |||
} | |||
return true; | |||
} | |||
bool dssp_voicelist_mutex_lock(nekobee_synth_t* const synth) | |||
{ | |||
return (pthread_mutex_lock(&synth->voicelist_mutex) == 0); | |||
} | |||
bool dssp_voicelist_mutex_unlock(nekobee_synth_t* const synth) | |||
{ | |||
return (pthread_mutex_unlock(&synth->voicelist_mutex) == 0); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// nekobee_handle_raw_event | |||
void nekobee_handle_raw_event(nekobee_synth_t* const synth, const uint8_t size, const uint8_t* const data) | |||
{ | |||
if (size != 3) | |||
return; | |||
switch (data[0] & 0xf0) | |||
{ | |||
case 0x80: | |||
nekobee_synth_note_off(synth, data[1], data[2]); | |||
break; | |||
case 0x90: | |||
if (data[2] > 0) | |||
nekobee_synth_note_on(synth, data[1], data[2]); | |||
else | |||
nekobee_synth_note_off(synth, data[1], 64); /* shouldn't happen, but... */ | |||
break; | |||
case 0xB0: | |||
nekobee_synth_control_change(synth, data[1], data[2]); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
} /* extern "C" */ | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoPluginNekobi::DistrhoPluginNekobi() | |||
: Plugin(paramCount, 0, 0) // 0 programs, 0 states | |||
{ | |||
nekobee_init_tables(); | |||
// init synth | |||
fSynth.sample_rate = d_getSampleRate(); | |||
fSynth.deltat = 1.0f / (float)d_getSampleRate(); | |||
fSynth.nugget_remains = 0; | |||
fSynth.note_id = 0; | |||
fSynth.polyphony = XSYNTH_DEFAULT_POLYPHONY; | |||
fSynth.voices = XSYNTH_DEFAULT_POLYPHONY; | |||
fSynth.monophonic = XSYNTH_MONO_MODE_ONCE; | |||
fSynth.glide = 0; | |||
fSynth.last_noteon_pitch = 0.0f; | |||
fSynth.vcf_accent = 0.0f; | |||
fSynth.vca_accent = 0.0f; | |||
for (int i=0; i<8; ++i) | |||
fSynth.held_keys[i] = -1; | |||
fSynth.voice = nekobee_voice_new(); | |||
fSynth.voicelist_mutex_grab_failed = 0; | |||
pthread_mutex_init(&fSynth.voicelist_mutex, nullptr); | |||
fSynth.channel_pressure = 0; | |||
fSynth.pitch_wheel_sensitivity = 0; | |||
fSynth.pitch_wheel = 0; | |||
for (int i=0; i<128; ++i) | |||
{ | |||
fSynth.key_pressure[i] = 0; | |||
fSynth.cc[i] = 0; | |||
} | |||
fSynth.cc[7] = 127; // full volume | |||
fSynth.mod_wheel = 1.0f; | |||
fSynth.pitch_bend = 1.0f; | |||
fSynth.cc_volume = 1.0f; | |||
// Default values | |||
fParams.waveform = 0.0f; | |||
fParams.tuning = 0.0f; | |||
fParams.cutoff = 25.0f; | |||
fParams.resonance = 25.0f; | |||
fParams.envMod = 50.0f; | |||
fParams.decay = 75.0f; | |||
fParams.accent = 25.0f; | |||
fParams.volume = 75.0f; | |||
// Internal stuff | |||
fSynth.waveform = 0.0f; | |||
fSynth.tuning = 1.0f; | |||
fSynth.cutoff = 5.0f; | |||
fSynth.resonance = 0.8f; | |||
fSynth.envmod = 0.3f; | |||
fSynth.decay = 0.0002f; | |||
fSynth.accent = 0.3f; | |||
fSynth.volume = 0.75f; | |||
// reset | |||
d_deactivate(); | |||
} | |||
DistrhoPluginNekobi::~DistrhoPluginNekobi() | |||
{ | |||
std::free(fSynth.voice); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Init | |||
void DistrhoPluginNekobi::d_initParameter(uint32_t index, Parameter& parameter) | |||
{ | |||
switch (index) | |||
{ | |||
case paramWaveform: | |||
parameter.hints = kParameterIsAutomable|kParameterIsBoolean; | |||
parameter.name = "Waveform"; | |||
parameter.symbol = "waveform"; | |||
parameter.ranges.def = 0.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 1.0f; | |||
break; | |||
case paramTuning: | |||
parameter.hints = kParameterIsAutomable; // was 0.5 <-> 2.0, log | |||
parameter.name = "Tuning"; | |||
parameter.symbol = "tuning"; | |||
parameter.ranges.def = 0.0f; | |||
parameter.ranges.min = -12.0f; | |||
parameter.ranges.max = 12.0f; | |||
break; | |||
case paramCutoff: | |||
parameter.hints = kParameterIsAutomable; // modified x2.5 | |||
parameter.name = "Cutoff"; | |||
parameter.symbol = "cutoff"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 25.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
case paramResonance: | |||
parameter.hints = kParameterIsAutomable; // modified x100 | |||
parameter.name = "VCF Resonance"; | |||
parameter.symbol = "resonance"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 25.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 95.0f; | |||
break; | |||
case paramEnvMod: | |||
parameter.hints = kParameterIsAutomable; // modified x100 | |||
parameter.name = "Env Mod"; | |||
parameter.symbol = "env_mod"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 50.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
case paramDecay: | |||
parameter.hints = kParameterIsAutomable; // was 0.000009 <-> 0.0005, log | |||
parameter.name = "Decay"; | |||
parameter.symbol = "decay"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 75.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
case paramAccent: | |||
parameter.hints = kParameterIsAutomable; // modified x100 | |||
parameter.name = "Accent"; | |||
parameter.symbol = "accent"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 25.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
case paramVolume: | |||
parameter.hints = kParameterIsAutomable; // modified x100 | |||
parameter.name = "Volume"; | |||
parameter.symbol = "volume"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 75.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Internal data | |||
float DistrhoPluginNekobi::d_getParameterValue(uint32_t index) const | |||
{ | |||
switch (index) | |||
{ | |||
case paramWaveform: | |||
return fParams.waveform; | |||
case paramTuning: | |||
return fParams.tuning; | |||
case paramCutoff: | |||
return fParams.cutoff; | |||
case paramResonance: | |||
return fParams.resonance; | |||
case paramEnvMod: | |||
return fParams.envMod; | |||
case paramDecay: | |||
return fParams.decay; | |||
case paramAccent: | |||
return fParams.accent; | |||
case paramVolume: | |||
return fParams.volume; | |||
} | |||
return 0.0f; | |||
} | |||
void DistrhoPluginNekobi::d_setParameterValue(uint32_t index, float value) | |||
{ | |||
switch (index) | |||
{ | |||
case paramWaveform: | |||
fParams.waveform = value; | |||
fSynth.waveform = value; | |||
DISTRHO_SAFE_ASSERT(fSynth.waveform == 0.0f || fSynth.waveform == 1.0f); | |||
break; | |||
case paramTuning: | |||
fParams.tuning = value; | |||
fSynth.tuning = (value+12.0f)/24.0f * 1.5 + 0.5f; // FIXME: log? | |||
DISTRHO_SAFE_ASSERT(fSynth.tuning >= 0.5f && fSynth.tuning <= 2.0f); | |||
break; | |||
case paramCutoff: | |||
fParams.cutoff = value; | |||
fSynth.cutoff = value/2.5f; | |||
DISTRHO_SAFE_ASSERT(fSynth.cutoff >= 0.0f && fSynth.cutoff <= 40.0f); | |||
break; | |||
case paramResonance: | |||
fParams.resonance = value; | |||
fSynth.resonance = value/100.0f; | |||
DISTRHO_SAFE_ASSERT(fSynth.resonance >= 0.0f && fSynth.resonance <= 0.95f); | |||
break; | |||
case paramEnvMod: | |||
fParams.envMod = value; | |||
fSynth.envmod = value/100.0f; | |||
DISTRHO_SAFE_ASSERT(fSynth.envmod >= 0.0f && fSynth.envmod <= 1.0f); | |||
break; | |||
case paramDecay: | |||
fParams.decay = value; | |||
fSynth.decay = value/100.0f * 0.000491f + 0.000009f; // FIXME: log? | |||
DISTRHO_SAFE_ASSERT(fSynth.decay >= 0.000009f && fSynth.decay <= 0.0005f); | |||
break; | |||
case paramAccent: | |||
fParams.accent = value; | |||
fSynth.accent = value/100.0f; | |||
DISTRHO_SAFE_ASSERT(fSynth.accent >= 0.0f && fSynth.accent <= 1.0f); | |||
break; | |||
case paramVolume: | |||
fParams.volume = value; | |||
fSynth.volume = value/100.0f; | |||
DISTRHO_SAFE_ASSERT(fSynth.volume >= 0.0f && fSynth.volume <= 1.0f); | |||
break; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Process | |||
void DistrhoPluginNekobi::d_activate() | |||
{ | |||
fSynth.nugget_remains = 0; | |||
fSynth.note_id = 0; | |||
if (fSynth.voice != nullptr) | |||
nekobee_synth_all_voices_off(&fSynth); | |||
} | |||
void DistrhoPluginNekobi::d_deactivate() | |||
{ | |||
if (fSynth.voice != nullptr) | |||
nekobee_synth_all_voices_off(&fSynth); | |||
} | |||
void DistrhoPluginNekobi::d_run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) | |||
{ | |||
uint32_t framesDone = 0; | |||
uint32_t curEventIndex = 0; | |||
uint32_t burstSize; | |||
float* out = outputs[0]; | |||
if (fSynth.voice == nullptr || ! dssp_voicelist_mutex_trylock(&fSynth)) | |||
{ | |||
std::memset(out, 0, sizeof(float)*frames); | |||
return; | |||
} | |||
while (framesDone < frames) | |||
{ | |||
if (fSynth.nugget_remains == 0) | |||
fSynth.nugget_remains = XSYNTH_NUGGET_SIZE; | |||
/* process any ready events */ | |||
while (curEventIndex < midiEventCount && framesDone == midiEvents[curEventIndex].frame) | |||
{ | |||
if (midiEvents[curEventIndex].size > MidiEvent::kDataSize) | |||
continue; | |||
nekobee_handle_raw_event(&fSynth, midiEvents[curEventIndex].size, midiEvents[curEventIndex].data); | |||
curEventIndex++; | |||
} | |||
/* calculate the sample count (burstSize) for the next nekobee_voice_render() call to be the smallest of: | |||
* - control calculation quantization size (XSYNTH_NUGGET_SIZE, in samples) | |||
* - the number of samples remaining in an already-begun nugget (synth->nugget_remains) | |||
* - the number of samples until the next event is ready | |||
* - the number of samples left in this run | |||
*/ | |||
burstSize = XSYNTH_NUGGET_SIZE; | |||
/* we're still in the middle of a nugget, so reduce the burst size | |||
* to end when the nugget ends */ | |||
if (fSynth.nugget_remains < burstSize) | |||
burstSize = fSynth.nugget_remains; | |||
/* reduce burst size to end when next event is ready */ | |||
if (curEventIndex < midiEventCount && midiEvents[curEventIndex].frame - framesDone < burstSize) | |||
burstSize = midiEvents[curEventIndex].frame - framesDone; | |||
/* reduce burst size to end at end of this run */ | |||
if (frames - framesDone < burstSize) | |||
burstSize = frames - framesDone; | |||
/* render the burst */ | |||
nekobee_synth_render_voices(&fSynth, out + framesDone, burstSize, (burstSize == fSynth.nugget_remains)); | |||
framesDone += burstSize; | |||
fSynth.nugget_remains -= burstSize; | |||
} | |||
dssp_voicelist_mutex_unlock(&fSynth); | |||
} | |||
// ----------------------------------------------------------------------- | |||
Plugin* createPlugin() | |||
{ | |||
return new DistrhoPluginNekobi(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,121 @@ | |||
/* | |||
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. | |||
* Copyright (C) 2004 Sean Bolton and others | |||
* Copyright (C) 2013-2014 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_NEKOBI_HPP_INCLUDED | |||
#define DISTRHO_PLUGIN_NEKOBI_HPP_INCLUDED | |||
#include "DistrhoPlugin.hpp" | |||
extern "C" { | |||
#include "nekobee-src/nekobee_synth.h" | |||
} | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoPluginNekobi : public Plugin | |||
{ | |||
public: | |||
enum Parameters | |||
{ | |||
paramWaveform = 0, | |||
paramTuning, | |||
paramCutoff, | |||
paramResonance, | |||
paramEnvMod, | |||
paramDecay, | |||
paramAccent, | |||
paramVolume, | |||
paramCount | |||
}; | |||
DistrhoPluginNekobi(); | |||
~DistrhoPluginNekobi() override; | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// Information | |||
const char* d_getLabel() const noexcept override | |||
{ | |||
return "Nekobi"; | |||
} | |||
const char* d_getMaker() const noexcept override | |||
{ | |||
return "Sean Bolton, falkTX"; | |||
} | |||
const char* d_getLicense() const noexcept override | |||
{ | |||
return "GPL v2+"; | |||
} | |||
uint32_t d_getVersion() const noexcept override | |||
{ | |||
return 0x1000; | |||
} | |||
int64_t d_getUniqueId() const noexcept override | |||
{ | |||
return d_cconst('D', 'N', 'e', 'k'); | |||
} | |||
// ------------------------------------------------------------------- | |||
// Init | |||
void d_initParameter(uint32_t index, Parameter& parameter) override; | |||
// ------------------------------------------------------------------- | |||
// Internal data | |||
float d_getParameterValue(uint32_t index) const override; | |||
void d_setParameterValue(uint32_t index, float value) override; | |||
// ------------------------------------------------------------------- | |||
// Process | |||
void d_activate() override; | |||
void d_deactivate() override; | |||
void d_run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override; | |||
// ------------------------------------------------------------------- | |||
private: | |||
struct ParamValues { | |||
float waveform; | |||
float tuning; | |||
float cutoff; | |||
float resonance; | |||
float envMod; | |||
float decay; | |||
float accent; | |||
float volume; | |||
} fParams; | |||
nekobee_synth_t fSynth; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginNekobi) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_PLUGIN_NEKOBI_HPP_INCLUDED |
@@ -0,0 +1,225 @@ | |||
/* | |||
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. | |||
* Copyright (C) 2013-2014 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. | |||
*/ | |||
#include "DistrhoPluginNekobi.hpp" | |||
#include "DistrhoUINekobi.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoUINekobi::DistrhoUINekobi() | |||
: UI(), | |||
fAboutWindow(this) | |||
{ | |||
// FIXME | |||
fNeko.setTimerSpeed(5); | |||
// set UI size | |||
setSize(DistrhoArtworkNekobi::backgroundWidth, DistrhoArtworkNekobi::backgroundHeight); | |||
// background | |||
fImgBackground = Image(DistrhoArtworkNekobi::backgroundData, DistrhoArtworkNekobi::backgroundWidth, DistrhoArtworkNekobi::backgroundHeight, GL_BGR); | |||
Image aboutImage(DistrhoArtworkNekobi::aboutData, DistrhoArtworkNekobi::aboutWidth, DistrhoArtworkNekobi::aboutHeight, GL_BGR); | |||
fAboutWindow.setImage(aboutImage); | |||
// slider | |||
Image sliderImage(DistrhoArtworkNekobi::sliderData, DistrhoArtworkNekobi::sliderWidth, DistrhoArtworkNekobi::sliderHeight); | |||
fSliderWaveform = new ImageSlider(this, sliderImage, DistrhoPluginNekobi::paramWaveform); | |||
fSliderWaveform->setStartPos(133, 40); | |||
fSliderWaveform->setEndPos(133, 60); | |||
fSliderWaveform->setRange(0.0f, 1.0f); | |||
fSliderWaveform->setStep(1.0f); | |||
fSliderWaveform->setValue(0.0f); | |||
fSliderWaveform->setCallback(this); | |||
// knobs | |||
Image knobImage(DistrhoArtworkNekobi::knobData, DistrhoArtworkNekobi::knobWidth, DistrhoArtworkNekobi::knobHeight); | |||
// knob Tuning | |||
fKnobTuning = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramTuning); | |||
fKnobTuning->setAbsolutePos(41, 43); | |||
fKnobTuning->setRange(-12.0f, 12.0f); | |||
fKnobTuning->setDefault(0.0f); | |||
fKnobTuning->setValue(0.0f); | |||
fKnobTuning->setRotationAngle(305); | |||
fKnobTuning->setCallback(this); | |||
// knob Cutoff | |||
fKnobCutoff = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramCutoff); | |||
fKnobCutoff->setAbsolutePos(185, 43); | |||
fKnobCutoff->setRange(0.0f, 100.0f); | |||
fKnobCutoff->setDefault(25.0f); | |||
fKnobCutoff->setValue(25.0f); | |||
fKnobCutoff->setRotationAngle(305); | |||
fKnobCutoff->setCallback(this); | |||
// knob Resonance | |||
fKnobResonance = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramResonance); | |||
fKnobResonance->setAbsolutePos(257, 43); | |||
fKnobResonance->setRange(0.0f, 95.0f); | |||
fKnobResonance->setDefault(25.0f); | |||
fKnobResonance->setValue(25.0f); | |||
fKnobResonance->setRotationAngle(305); | |||
fKnobResonance->setCallback(this); | |||
// knob Env Mod | |||
fKnobEnvMod = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramEnvMod); | |||
fKnobEnvMod->setAbsolutePos(329, 43); | |||
fKnobEnvMod->setRange(0.0f, 100.0f); | |||
fKnobEnvMod->setDefault(50.0f); | |||
fKnobEnvMod->setValue(50.0f); | |||
fKnobEnvMod->setRotationAngle(305); | |||
fKnobEnvMod->setCallback(this); | |||
// knob Decay | |||
fKnobDecay = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramDecay); | |||
fKnobDecay->setAbsolutePos(400, 43); | |||
fKnobDecay->setRange(0.0f, 100.0f); | |||
fKnobDecay->setDefault(75.0f); | |||
fKnobDecay->setValue(75.0f); | |||
fKnobDecay->setRotationAngle(305); | |||
fKnobDecay->setCallback(this); | |||
// knob Accent | |||
fKnobAccent = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramAccent); | |||
fKnobAccent->setAbsolutePos(473, 43); | |||
fKnobAccent->setRange(0.0f, 100.0f); | |||
fKnobAccent->setDefault(25.0f); | |||
fKnobAccent->setValue(25.0f); | |||
fKnobAccent->setRotationAngle(305); | |||
fKnobAccent->setCallback(this); | |||
// knob Volume | |||
fKnobVolume = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginNekobi::paramVolume); | |||
fKnobVolume->setAbsolutePos(545, 43); | |||
fKnobVolume->setRange(0.0f, 100.0f); | |||
fKnobVolume->setDefault(75.0f); | |||
fKnobVolume->setValue(75.0f); | |||
fKnobVolume->setRotationAngle(305); | |||
fKnobVolume->setCallback(this); | |||
// about button | |||
Image aboutImageNormal(DistrhoArtworkNekobi::aboutButtonNormalData, DistrhoArtworkNekobi::aboutButtonNormalWidth, DistrhoArtworkNekobi::aboutButtonNormalHeight); | |||
Image aboutImageHover(DistrhoArtworkNekobi::aboutButtonHoverData, DistrhoArtworkNekobi::aboutButtonHoverWidth, DistrhoArtworkNekobi::aboutButtonHoverHeight); | |||
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover); | |||
fButtonAbout->setAbsolutePos(505, 5); | |||
fButtonAbout->setCallback(this); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void DistrhoUINekobi::d_parameterChanged(uint32_t index, float value) | |||
{ | |||
switch (index) | |||
{ | |||
case DistrhoPluginNekobi::paramTuning: | |||
fKnobTuning->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramWaveform: | |||
fSliderWaveform->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramCutoff: | |||
fKnobCutoff->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramResonance: | |||
fKnobResonance->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramEnvMod: | |||
fKnobEnvMod->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramDecay: | |||
fKnobDecay->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramAccent: | |||
fKnobAccent->setValue(value); | |||
break; | |||
case DistrhoPluginNekobi::paramVolume: | |||
fKnobVolume->setValue(value); | |||
break; | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
// UI Callbacks | |||
void DistrhoUINekobi::d_uiIdle() | |||
{ | |||
if (fNeko.idle()) | |||
repaint(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Widget Callbacks | |||
void DistrhoUINekobi::imageButtonClicked(ImageButton* button, int) | |||
{ | |||
if (button != fButtonAbout) | |||
return; | |||
fAboutWindow.exec(); | |||
} | |||
void DistrhoUINekobi::imageKnobDragStarted(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), true); | |||
} | |||
void DistrhoUINekobi::imageKnobDragFinished(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), false); | |||
} | |||
void DistrhoUINekobi::imageKnobValueChanged(ImageKnob* knob, float value) | |||
{ | |||
d_setParameterValue(knob->getId(), value); | |||
} | |||
void DistrhoUINekobi::imageSliderDragStarted(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), true); | |||
} | |||
void DistrhoUINekobi::imageSliderDragFinished(ImageSlider* slider) | |||
{ | |||
d_editParameter(slider->getId(), false); | |||
} | |||
void DistrhoUINekobi::imageSliderValueChanged(ImageSlider* slider, float value) | |||
{ | |||
d_setParameterValue(slider->getId(), value); | |||
} | |||
void DistrhoUINekobi::onDisplay() | |||
{ | |||
fImgBackground.draw(); | |||
fNeko.draw(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
UI* createUI() | |||
{ | |||
return new DistrhoUINekobi(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,89 @@ | |||
/* | |||
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others. | |||
* Copyright (C) 2013-2014 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_UI_NEKOBI_HPP_INCLUDED | |||
#define DISTRHO_UI_NEKOBI_HPP_INCLUDED | |||
#include "DistrhoUI.hpp" | |||
#include "ImageAboutWindow.hpp" | |||
#include "ImageButton.hpp" | |||
#include "ImageKnob.hpp" | |||
#include "ImageSlider.hpp" | |||
#include "DistrhoArtworkNekobi.hpp" | |||
#include "NekoWidget.hpp" | |||
using DGL::ImageAboutWindow; | |||
using DGL::ImageButton; | |||
using DGL::ImageKnob; | |||
using DGL::ImageSlider; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoUINekobi : public UI, | |||
public ImageButton::Callback, | |||
public ImageKnob::Callback, | |||
public ImageSlider::Callback | |||
{ | |||
public: | |||
DistrhoUINekobi(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void d_parameterChanged(uint32_t index, float value) override; | |||
// ------------------------------------------------------------------- | |||
// UI Callbacks | |||
void d_uiIdle() 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; | |||
NekoWidget fNeko; | |||
ScopedPointer<ImageButton> fButtonAbout; | |||
ScopedPointer<ImageSlider> fSliderWaveform; | |||
ScopedPointer<ImageKnob> fKnobTuning, fKnobCutoff, fKnobResonance; | |||
ScopedPointer<ImageKnob> fKnobEnvMod, fKnobDecay, fKnobAccent, fKnobVolume; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUINekobi) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_UI_NEKOBI_HPP_INCLUDED |
@@ -0,0 +1,202 @@ | |||
/* | |||
* Neko widget animation | |||
* Copyright (C) 2013-2014 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 NEKO_WIDGET_HPP_INCLUDED | |||
#define NEKO_WIDGET_HPP_INCLUDED | |||
#include "DistrhoArtworkNekobi.hpp" | |||
#include "Image.hpp" | |||
#include "Widget.hpp" | |||
#include <cstdlib> // rand | |||
using DGL::Image; | |||
// ----------------------------------------------------------------------- | |||
class NekoWidget | |||
{ | |||
public: | |||
NekoWidget() | |||
: fPos(0), | |||
fTimer(0), | |||
fTimerSpeed(20), | |||
fCurAction(kActionNone), | |||
fCurImage(&fImages.sit) | |||
{ | |||
// load images | |||
{ | |||
using namespace DistrhoArtworkNekobi; | |||
#define JOIN(a, b) a ## b | |||
#define LOAD_IMAGE(NAME) fImages.NAME.loadFromMemory(JOIN(NAME, Data), JOIN(NAME, Width), JOIN(NAME, Height)); | |||
LOAD_IMAGE(sit) | |||
LOAD_IMAGE(tail) | |||
LOAD_IMAGE(claw1) | |||
LOAD_IMAGE(claw2) | |||
LOAD_IMAGE(scratch1) | |||
LOAD_IMAGE(scratch2) | |||
LOAD_IMAGE(run1) | |||
LOAD_IMAGE(run2) | |||
LOAD_IMAGE(run3) | |||
LOAD_IMAGE(run4) | |||
#undef JOIN | |||
#undef LOAD_IMAGE | |||
} | |||
} | |||
void draw() | |||
{ | |||
int x = fPos+108; | |||
int y = -2; | |||
if (fCurImage == &fImages.claw1 || fCurImage == &fImages.claw2) | |||
{ | |||
x += 2; | |||
y += 12; | |||
} | |||
fCurImage->drawAt(x, y); | |||
} | |||
// returns true if needs repaint | |||
bool idle() | |||
{ | |||
if (++fTimer % fTimerSpeed != 0) // target is 20ms | |||
return false; | |||
if (fTimer == fTimerSpeed*9) | |||
{ | |||
if (fCurAction == kActionNone) | |||
fCurAction = static_cast<Action>(std::rand() % kActionCount); | |||
else | |||
fCurAction = kActionNone; | |||
fTimer = 0; | |||
} | |||
switch (fCurAction) | |||
{ | |||
case kActionNone: | |||
if (fCurImage == &fImages.sit) | |||
fCurImage = &fImages.tail; | |||
else | |||
fCurImage = &fImages.sit; | |||
break; | |||
case kActionClaw: | |||
if (fCurImage == &fImages.claw1) | |||
fCurImage = &fImages.claw2; | |||
else | |||
fCurImage = &fImages.claw1; | |||
break; | |||
case kActionScratch: | |||
if (fCurImage == &fImages.scratch1) | |||
fCurImage = &fImages.scratch2; | |||
else | |||
fCurImage = &fImages.scratch1; | |||
break; | |||
case kActionRunRight: | |||
if (fTimer == 0 && fPos > 20*9) | |||
{ | |||
// run the other way | |||
--fTimer; | |||
fCurAction = kActionRunLeft; | |||
idle(); | |||
break; | |||
} | |||
fPos += 20; | |||
if (fCurImage == &fImages.run1) | |||
fCurImage = &fImages.run2; | |||
else | |||
fCurImage = &fImages.run1; | |||
break; | |||
case kActionRunLeft: | |||
if (fTimer == 0 && fPos < 20*9) | |||
{ | |||
// run the other way | |||
--fTimer; | |||
fCurAction = kActionRunRight; | |||
idle(); | |||
break; | |||
} | |||
fPos -= 20; | |||
if (fCurImage == &fImages.run3) | |||
fCurImage = &fImages.run4; | |||
else | |||
fCurImage = &fImages.run3; | |||
break; | |||
case kActionCount: | |||
break; | |||
} | |||
return true; | |||
} | |||
void setTimerSpeed(int speed) | |||
{ | |||
fTimer = 0; | |||
fTimerSpeed = speed; | |||
} | |||
// ------------------------------------------------------------------- | |||
private: | |||
enum Action { | |||
kActionNone, // bounce tail | |||
kActionClaw, | |||
kActionScratch, | |||
kActionRunRight, | |||
kActionRunLeft, | |||
kActionCount | |||
}; | |||
struct Images { | |||
Image sit; | |||
Image tail; | |||
Image claw1; | |||
Image claw2; | |||
Image scratch1; | |||
Image scratch2; | |||
Image run1; | |||
Image run2; | |||
Image run3; | |||
Image run4; | |||
} fImages; | |||
int fPos; | |||
int fTimer; | |||
int fTimerSpeed; | |||
Action fCurAction; | |||
Image* fCurImage; | |||
}; | |||
// ----------------------------------------------------------------------- | |||
#endif // NEKO_WIDGET_HPP_INCLUDED |
@@ -0,0 +1,77 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* Portions of this file may have come from Chris Cannam and Steve | |||
* Harris's public domain DSSI example code. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this program; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#ifndef _XSYNTH_H | |||
#define _XSYNTH_H | |||
/* ==== debugging ==== */ | |||
/* XSYNTH_DEBUG bits */ | |||
#define XDB_DSSI 1 /* DSSI interface */ | |||
#define XDB_AUDIO 2 /* audio output */ | |||
#define XDB_NOTE 4 /* note on/off, voice allocation */ | |||
#define XDB_DATA 8 /* plugin patchbank handling */ | |||
#define GDB_MAIN 16 /* GUI main program flow */ | |||
#define GDB_OSC 32 /* GUI OSC handling */ | |||
#define GDB_IO 64 /* GUI patch file input/output */ | |||
#define GDB_GUI 128 /* GUI GUI callbacks, updating, etc. */ | |||
/* If you want debug information, define XSYNTH_DEBUG to the XDB_* bits you're | |||
* interested in getting debug information about, bitwise-ORed together. | |||
* Otherwise, leave it undefined. */ | |||
// #define XSYNTH_DEBUG (1+8+16+32+64) | |||
//#define XSYNTH_DEBUG GDB_GUI + GDB_OSC | |||
// #define XSYNTH_DEBUG XDB_DSSI | |||
#ifdef XSYNTH_DEBUG | |||
#include <stdio.h> | |||
#define XSYNTH_DEBUG_INIT(x) | |||
#define XDB_MESSAGE(type, fmt...) { if (XSYNTH_DEBUG & type) fprintf(stderr, "nekobee-dssi.so" fmt); } | |||
#define GDB_MESSAGE(type, fmt...) { if (XSYNTH_DEBUG & type) fprintf(stderr, "nekobee_gtk" fmt); } | |||
// -FIX-: | |||
// #include "message_buffer.h" | |||
// #define XSYNTH_DEBUG_INIT(x) mb_init(x) | |||
// #define XDB_MESSAGE(type, fmt...) { \- | |||
// if (XSYNTH_DEBUG & type) { \- | |||
// char _m[256]; \- | |||
// snprintf(_m, 255, fmt); \- | |||
// add_message(_m); \- | |||
// } \- | |||
// } | |||
#else /* !XSYNTH_DEBUG */ | |||
#define XDB_MESSAGE(type, fmt...) | |||
#define GDB_MESSAGE(type, fmt...) | |||
#define XSYNTH_DEBUG_INIT(x) | |||
#endif /* XSYNTH_DEBUG */ | |||
/* ==== end of debugging ==== */ | |||
#define XSYNTH_MAX_POLYPHONY 1 | |||
#define XSYNTH_DEFAULT_POLYPHONY 1 | |||
#endif /* _XSYNTH_H */ |
@@ -0,0 +1,237 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* Portions of this file may have come from Steve Brookes' | |||
* nekobee, copyright (C) 1999 S. J. Brookes. | |||
* Portions of this file may have come from Peter Hanappe's | |||
* Fluidsynth, copyright (C) 2003 Peter Hanappe and others. | |||
* Portions of this file may have come from Chris Cannam and Steve | |||
* Harris's public domain DSSI example code. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this program; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#include <stdlib.h> | |||
#include <stdio.h> | |||
#include <string.h> | |||
#include <math.h> | |||
#include <pthread.h> | |||
#include "nekobee.h" | |||
#include "nekobee_synth.h" | |||
#include "nekobee_voice.h" | |||
/* | |||
* nekobee_synth_all_voices_off | |||
* | |||
* stop processing all notes immediately | |||
*/ | |||
void | |||
nekobee_synth_all_voices_off(nekobee_synth_t *synth) | |||
{ | |||
int i; | |||
nekobee_voice_t *voice; | |||
for (i = 0; i < synth->voices; i++) { | |||
//voice = synth->voice[i]; | |||
voice = synth->voice; | |||
if (_PLAYING(voice)) { | |||
nekobee_voice_off(voice); | |||
} | |||
} | |||
for (i = 0; i < 8; i++) synth->held_keys[i] = -1; | |||
} | |||
/* | |||
* nekobee_synth_note_off | |||
* | |||
* handle a note off message | |||
*/ | |||
void | |||
nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key, unsigned char rvelocity) | |||
{ | |||
int i, count = 0; | |||
nekobee_voice_t *voice; | |||
for (i = 0; i < synth->voices; i++) { | |||
voice = synth->voice; | |||
if (_PLAYING(voice)) { | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_synth_note_off: key %d rvel %d voice %d note id %d\n", key, rvelocity, i, voice->note_id); | |||
nekobee_voice_note_off(synth, voice, key, 64); | |||
count++; | |||
} | |||
} | |||
if (!count) | |||
nekobee_voice_remove_held_key(synth, key); | |||
return; | |||
(void)rvelocity; | |||
} | |||
/* | |||
* nekobee_synth_all_notes_off | |||
* | |||
* put all notes into the released state | |||
*/ | |||
void | |||
nekobee_synth_all_notes_off(nekobee_synth_t* synth) | |||
{ | |||
int i; | |||
nekobee_voice_t *voice; | |||
/* reset the sustain controller */ | |||
synth->cc[MIDI_CTL_SUSTAIN] = 0; | |||
for (i = 0; i < synth->voices; i++) { | |||
//voice = synth->voice[i]; | |||
voice = synth->voice; | |||
if (_ON(voice) || _SUSTAINED(voice)) { | |||
nekobee_voice_release_note(synth, voice); | |||
} | |||
} | |||
} | |||
/* | |||
* nekobee_synth_note_on | |||
*/ | |||
void | |||
nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key, unsigned char velocity) | |||
{ | |||
nekobee_voice_t* voice; | |||
voice = synth->voice; | |||
if (_PLAYING(synth->voice)) { | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_synth_note_on: retriggering mono voice on new key %d\n", key); | |||
} | |||
voice->note_id = synth->note_id++; | |||
nekobee_voice_note_on(synth, voice, key, velocity); | |||
} | |||
/* | |||
* nekobee_synth_update_volume | |||
*/ | |||
void | |||
nekobee_synth_update_volume(nekobee_synth_t* synth) | |||
{ | |||
synth->cc_volume = (float)(synth->cc[MIDI_CTL_MSB_MAIN_VOLUME] * 128 + | |||
synth->cc[MIDI_CTL_LSB_MAIN_VOLUME]) / 16256.0f; | |||
if (synth->cc_volume > 1.0f) | |||
synth->cc_volume = 1.0f; | |||
/* don't need to check if any playing voices need updating, because it's global */ | |||
} | |||
/* | |||
* nekobee_synth_control_change | |||
*/ | |||
void | |||
nekobee_synth_control_change(nekobee_synth_t *synth, unsigned int param, signed int value) | |||
{ | |||
synth->cc[param] = value; | |||
switch (param) { | |||
case MIDI_CTL_MSB_MAIN_VOLUME: | |||
case MIDI_CTL_LSB_MAIN_VOLUME: | |||
nekobee_synth_update_volume(synth); | |||
break; | |||
case MIDI_CTL_ALL_SOUNDS_OFF: | |||
nekobee_synth_all_voices_off(synth); | |||
break; | |||
case MIDI_CTL_RESET_CONTROLLERS: | |||
nekobee_synth_init_controls(synth); | |||
break; | |||
case MIDI_CTL_ALL_NOTES_OFF: | |||
nekobee_synth_all_notes_off(synth); | |||
break; | |||
/* what others should we respond to? */ | |||
/* these we ignore (let the host handle): | |||
* BANK_SELECT_MSB | |||
* BANK_SELECT_LSB | |||
* DATA_ENTRY_MSB | |||
* NRPN_MSB | |||
* NRPN_LSB | |||
* RPN_MSB | |||
* RPN_LSB | |||
* -FIX- no! we need RPN (0, 0) Pitch Bend Sensitivity! | |||
*/ | |||
} | |||
} | |||
/* | |||
* nekobee_synth_init_controls | |||
*/ | |||
void | |||
nekobee_synth_init_controls(nekobee_synth_t *synth) | |||
{ | |||
int i; | |||
for (i = 0; i < 128; i++) { | |||
synth->cc[i] = 0; | |||
} | |||
synth->cc[7] = 127; /* full volume */ | |||
nekobee_synth_update_volume(synth); | |||
} | |||
/* | |||
* nekobee_synth_render_voices | |||
*/ | |||
void | |||
nekobee_synth_render_voices(nekobee_synth_t *synth, float *out, unsigned long sample_count, | |||
int do_control_update) | |||
{ | |||
unsigned long i; | |||
float res, wow; | |||
/* clear the buffer */ | |||
for (i = 0; i < sample_count; i++) | |||
out[i] = 0.0f; | |||
// we can do anything that must be updated all the time here | |||
// this is called even when a voice isn't playing | |||
// approximate a log scale | |||
res = 1-synth->resonance; | |||
wow = res*res; | |||
wow = wow/10.0f; | |||
// as the resonance is increased, "wow" slows down the accent attack | |||
if ((synth->voice->velocity>90) && (synth->vcf_accent < synth->voice->vcf_eg)) { | |||
synth->vcf_accent=(0.985-wow)*synth->vcf_accent+(0.015+wow)*synth->voice->vcf_eg; | |||
} else { | |||
synth->vcf_accent=(0.985-wow)*synth->vcf_accent; // or just decay | |||
} | |||
if (synth->voice->velocity>90) { | |||
synth->vca_accent=0.95*synth->vca_accent+0.05; // ramp up accent on with a time constant | |||
} else { | |||
synth->vca_accent=0.95*synth->vca_accent; // accent off with time constant | |||
} | |||
#if defined(XSYNTH_DEBUG) && (XSYNTH_DEBUG & XDB_AUDIO) | |||
out[0] += 0.10f; /* add a 'buzz' to output so there's something audible even when quiescent */ | |||
#endif /* defined(XSYNTH_DEBUG) && (XSYNTH_DEBUG & XDB_AUDIO) */ | |||
if (_PLAYING(synth->voice)) { | |||
nekobee_voice_render(synth, synth->voice, out, sample_count, do_control_update); | |||
} | |||
} |
@@ -0,0 +1,132 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* Portions of this file may have come from Peter Hanappe's | |||
* Fluidsynth, copyright (C) 2003 Peter Hanappe and others. | |||
* Portions of this file may have come from alsa-lib, copyright | |||
* and licensed under the LGPL v2.1. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this program; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#ifndef _XSYNTH_SYNTH_H | |||
#define _XSYNTH_SYNTH_H | |||
#include <pthread.h> | |||
#include "nekobee.h" | |||
#include "nekobee_types.h" | |||
#define XSYNTH_MONO_MODE_OFF 0 | |||
#define XSYNTH_MONO_MODE_ON 1 | |||
#define XSYNTH_MONO_MODE_ONCE 2 | |||
#define XSYNTH_MONO_MODE_BOTH 3 | |||
#define XSYNTH_GLIDE_MODE_LEGATO 0 | |||
#define XSYNTH_GLIDE_MODE_INITIAL 1 | |||
#define XSYNTH_GLIDE_MODE_ALWAYS 2 | |||
#define XSYNTH_GLIDE_MODE_LEFTOVER 3 | |||
#define XSYNTH_GLIDE_MODE_OFF 4 | |||
/* | |||
* nekobee_synth_t | |||
*/ | |||
struct _nekobee_synth_t { | |||
/* output */ | |||
unsigned long sample_rate; | |||
float deltat; /* 1 / sample_rate */ | |||
unsigned long nugget_remains; | |||
/* voice tracking and data */ | |||
unsigned int note_id; /* incremented for every new note, used for voice-stealing prioritization */ | |||
int polyphony; /* requested polyphony, must be <= XSYNTH_MAX_POLYPHONY */ | |||
int voices; /* current polyphony, either requested polyphony above or 1 while in monophonic mode */ | |||
int monophonic; /* true if operating in monophonic mode */ | |||
int glide; /* current glide mode */ | |||
float last_noteon_pitch; /* glide start pitch for non-legato modes */ | |||
signed char held_keys[8]; /* for monophonic key tracking, an array of note-ons, most recently received first */ | |||
float vcf_accent; /* used to emulate the circuit that sweeps the vcf at full resonance */ | |||
float vca_accent; /* used to smooth the accent pulse, removing the click */ | |||
//nekobee_voice_t *voice[XSYNTH_MAX_POLYPHONY]; | |||
nekobee_voice_t *voice; | |||
pthread_mutex_t voicelist_mutex; | |||
int voicelist_mutex_grab_failed; | |||
/* current non-paramter-mapped controller values */ | |||
unsigned char key_pressure[128]; | |||
unsigned char cc[128]; /* controller values */ | |||
unsigned char channel_pressure; | |||
unsigned char pitch_wheel_sensitivity; /* in semitones */ | |||
int pitch_wheel; /* range is -8192 - 8191 */ | |||
/* translated controller values */ | |||
float mod_wheel; /* filter cutoff multiplier, off = 1.0, full on = 0.0 */ | |||
float pitch_bend; /* frequency multiplier, product of wheel setting and sensitivity, center = 1.0 */ | |||
float cc_volume; /* volume multiplier, 0.0 to 1.0 */ | |||
/* patch parameters */ | |||
float tuning; | |||
float waveform; | |||
float cutoff; | |||
float resonance; | |||
float envmod; | |||
float decay; | |||
float accent; | |||
float volume; | |||
}; | |||
void nekobee_synth_all_voices_off(nekobee_synth_t *synth); | |||
void nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key, | |||
unsigned char rvelocity); | |||
void nekobee_synth_all_notes_off(nekobee_synth_t *synth); | |||
void nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key, | |||
unsigned char velocity); | |||
void nekobee_synth_control_change(nekobee_synth_t *synth, unsigned int param, | |||
signed int value); | |||
void nekobee_synth_init_controls(nekobee_synth_t *synth); | |||
void nekobee_synth_render_voices(nekobee_synth_t *synth, float *out, | |||
unsigned long sample_count, | |||
int do_control_update); | |||
/* these come right out of alsa/asoundef.h */ | |||
#define MIDI_CTL_MSB_MODWHEEL 0x01 /**< Modulation */ | |||
#define MIDI_CTL_MSB_PORTAMENTO_TIME 0x05 /**< Portamento time */ | |||
#define MIDI_CTL_MSB_MAIN_VOLUME 0x07 /**< Main volume */ | |||
#define MIDI_CTL_MSB_BALANCE 0x08 /**< Balance */ | |||
#define MIDI_CTL_LSB_MODWHEEL 0x21 /**< Modulation */ | |||
#define MIDI_CTL_LSB_PORTAMENTO_TIME 0x25 /**< Portamento time */ | |||
#define MIDI_CTL_LSB_MAIN_VOLUME 0x27 /**< Main volume */ | |||
#define MIDI_CTL_LSB_BALANCE 0x28 /**< Balance */ | |||
#define MIDI_CTL_SUSTAIN 0x40 /**< Sustain pedal */ | |||
// nekobee defines | |||
#define MIDI_CTL_TUNING 0x4b // impossible | |||
#define MIDI_CTL_WAVEFORM 0x46 // select waveform | |||
#define MIDI_CTL_CUTOFF 0x4a // VCF Cutoff | |||
#define MIDI_CTL_RESONANCE 0x47 // VCF Resonance | |||
#define MIDI_CTL_ENVMOD 0x01 // cheat and use modwheel | |||
#define MIDI_CTL_DECAY 0x48 // Decay time (well release really) | |||
#define MIDI_CTL_ACCENT 0x4c // impossible | |||
#define MIDI_CTL_ALL_SOUNDS_OFF 0x78 /**< All sounds off */ | |||
#define MIDI_CTL_RESET_CONTROLLERS 0x79 /**< Reset Controllers */ | |||
#define MIDI_CTL_ALL_NOTES_OFF 0x7b /**< All notes off */ | |||
#define XSYNTH_SYNTH_SUSTAINED(_s) ((_s)->cc[MIDI_CTL_SUSTAIN] >= 64) | |||
#endif /* _XSYNTH_SYNTH_H */ |
@@ -0,0 +1,30 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this library; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#ifndef _XSYNTH_TYPES_H | |||
#define _XSYNTH_TYPES_H | |||
#include <stddef.h> | |||
typedef struct _nekobee_synth_t nekobee_synth_t; | |||
typedef struct _nekobee_voice_t nekobee_voice_t; | |||
typedef struct _nekobee_patch_t nekobee_patch_t; | |||
#endif /* _XSYNTH_TYPES_H */ |
@@ -0,0 +1,256 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* Portions of this file may have come from Steve Brookes' | |||
* nekobee, copyright (C) 1999 S. J. Brookes. | |||
* Portions of this file may have come from Peter Hanappe's | |||
* Fluidsynth, copyright (C) 2003 Peter Hanappe and others. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this program; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#define _BSD_SOURCE 1 | |||
#define _SVID_SOURCE 1 | |||
#define _ISOC99_SOURCE 1 | |||
#include <stdlib.h> | |||
#include "nekobee_types.h" | |||
#include "nekobee.h" | |||
#include "nekobee_synth.h" | |||
#include "nekobee_voice.h" | |||
/* | |||
* nekobee_voice_new | |||
*/ | |||
nekobee_voice_t * | |||
nekobee_voice_new() | |||
{ | |||
nekobee_voice_t *voice; | |||
voice = (nekobee_voice_t *)calloc(sizeof(nekobee_voice_t), 1); | |||
if (voice) { | |||
voice->status = XSYNTH_VOICE_OFF; | |||
} | |||
return voice; | |||
} | |||
/* | |||
* nekobee_voice_note_on | |||
*/ | |||
void | |||
nekobee_voice_note_on(nekobee_synth_t *synth, nekobee_voice_t *voice, | |||
unsigned char key, unsigned char velocity) | |||
{ | |||
int i; | |||
voice->key = key; | |||
voice->velocity = velocity; | |||
if (!synth->monophonic || !(_ON(voice) || _SUSTAINED(voice))) { | |||
// brand-new voice, or monophonic voice in release phase; set everything up | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_voice_note_on in polyphonic/new section: key %d, mono %d, old status %d\n", key, synth->monophonic, voice->status); | |||
voice->target_pitch = nekobee_pitch[key]; | |||
if (synth->held_keys[0] >= 0) { | |||
voice->prev_pitch = nekobee_pitch[synth->held_keys[0]]; | |||
} else { | |||
voice->prev_pitch = voice->target_pitch; | |||
} | |||
if (!_PLAYING(voice)) { | |||
voice->lfo_pos = 0.0f; | |||
voice->vca_eg = 0.0f; | |||
voice->vcf_eg = 0.0f; | |||
voice->delay1 = 0.0f; | |||
voice->delay2 = 0.0f; | |||
voice->delay3 = 0.0f; | |||
voice->delay4 = 0.0f; | |||
voice->c5 = 0.0f; | |||
voice->osc_index = 0; | |||
voice->osc1.last_waveform = -1; | |||
voice->osc1.pos = 0.0f; | |||
} | |||
voice->vca_eg_phase = 0; | |||
voice->vcf_eg_phase = 0; | |||
// nekobee_voice_update_pressure_mod(synth, voice); | |||
} else { | |||
/* synth is monophonic, and we're modifying a playing voice */ | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_voice_note_on in monophonic section: old key %d => new key %d\n", synth->held_keys[0], key); | |||
/* set new pitch */ | |||
voice->target_pitch = nekobee_pitch[key]; | |||
if (synth->glide == XSYNTH_GLIDE_MODE_INITIAL || | |||
synth->glide == XSYNTH_GLIDE_MODE_OFF) | |||
voice->prev_pitch = voice->target_pitch; | |||
/* if in 'on' or 'both' modes, and key has changed, then re-trigger EGs */ | |||
if ((synth->monophonic == XSYNTH_MONO_MODE_ON || | |||
synth->monophonic == XSYNTH_MONO_MODE_BOTH) && | |||
(synth->held_keys[0] < 0 || synth->held_keys[0] != key)) { | |||
voice->vca_eg_phase = 0; | |||
voice->vcf_eg_phase = 0; | |||
} | |||
/* all other variables stay what they are */ | |||
} | |||
synth->last_noteon_pitch = voice->target_pitch; | |||
/* add new key to the list of held keys */ | |||
/* check if new key is already in the list; if so, move it to the | |||
* top of the list, otherwise shift the other keys down and add it | |||
* to the top of the list. */ | |||
for (i = 0; i < 7; i++) { | |||
if (synth->held_keys[i] == key) | |||
break; | |||
} | |||
for (; i > 0; i--) { | |||
synth->held_keys[i] = synth->held_keys[i - 1]; | |||
} | |||
synth->held_keys[0] = key; | |||
if (!_PLAYING(voice)) { | |||
nekobee_voice_start_voice(voice); | |||
} else if (!_ON(voice)) { /* must be XSYNTH_VOICE_SUSTAINED or XSYNTH_VOICE_RELEASED */ | |||
voice->status = XSYNTH_VOICE_ON; | |||
} | |||
} | |||
/* | |||
* nekobee_voice_set_release_phase | |||
*/ | |||
static inline void | |||
nekobee_voice_set_release_phase(nekobee_voice_t *voice) | |||
{ | |||
voice->vca_eg_phase = 2; | |||
voice->vcf_eg_phase = 2; | |||
} | |||
/* | |||
* nekobee_voice_remove_held_key | |||
*/ | |||
inline void | |||
nekobee_voice_remove_held_key(nekobee_synth_t *synth, unsigned char key) | |||
{ | |||
int i; | |||
/* check if this key is in list of held keys; if so, remove it and | |||
* shift the other keys up */ | |||
for (i = 7; i >= 0; i--) { | |||
if (synth->held_keys[i] == key) | |||
break; | |||
} | |||
if (i >= 0) { | |||
for (; i < 7; i++) { | |||
synth->held_keys[i] = synth->held_keys[i + 1]; | |||
} | |||
synth->held_keys[7] = -1; | |||
} | |||
} | |||
/* | |||
* nekobee_voice_note_off | |||
*/ | |||
void | |||
nekobee_voice_note_off(nekobee_synth_t *synth, nekobee_voice_t *voice, | |||
unsigned char key, unsigned char rvelocity) | |||
{ | |||
unsigned char previous_top_key; | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_set_note_off: called for voice %p, key %d\n", voice, key); | |||
/* save release velocity */ | |||
voice->velocity = rvelocity; | |||
previous_top_key = synth->held_keys[0]; | |||
/* remove this key from list of held keys */ | |||
nekobee_voice_remove_held_key(synth, key); | |||
if (synth->held_keys[0] >= 0) { | |||
/* still some keys held */ | |||
if (synth->held_keys[0] != previous_top_key) { | |||
/* most-recently-played key has changed */ | |||
voice->key = synth->held_keys[0]; | |||
XDB_MESSAGE(XDB_NOTE, " note-off in monophonic section: changing pitch to %d\n", voice->key); | |||
voice->target_pitch = nekobee_pitch[voice->key]; | |||
if (synth->glide == XSYNTH_GLIDE_MODE_INITIAL || | |||
synth->glide == XSYNTH_GLIDE_MODE_OFF) | |||
voice->prev_pitch = voice->target_pitch; | |||
/* if mono mode is 'both', re-trigger EGs */ | |||
if (synth->monophonic == XSYNTH_MONO_MODE_BOTH && !_RELEASED(voice)) { | |||
voice->vca_eg_phase = 0; | |||
voice->vcf_eg_phase = 0; | |||
} | |||
} | |||
} else { /* no keys still held */ | |||
if (XSYNTH_SYNTH_SUSTAINED(synth)) { | |||
/* no more keys in list, but we're sustained */ | |||
XDB_MESSAGE(XDB_NOTE, " note-off in monophonic section: sustained with no held keys\n"); | |||
if (!_RELEASED(voice)) | |||
voice->status = XSYNTH_VOICE_SUSTAINED; | |||
} else { /* not sustained */ | |||
/* no more keys in list, so turn off note */ | |||
XDB_MESSAGE(XDB_NOTE, " note-off in monophonic section: turning off voice %p\n", voice); | |||
nekobee_voice_set_release_phase(voice); | |||
voice->status = XSYNTH_VOICE_RELEASED; | |||
} | |||
} | |||
} | |||
/* | |||
* nekobee_voice_release_note | |||
*/ | |||
void | |||
nekobee_voice_release_note(nekobee_synth_t *synth, nekobee_voice_t *voice) | |||
{ | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_voice_release_note: turning off voice %p\n", voice); | |||
if (_ON(voice)) { | |||
/* dummy up a release velocity */ | |||
voice->rvelocity = 64; | |||
} | |||
nekobee_voice_set_release_phase(voice); | |||
voice->status = XSYNTH_VOICE_RELEASED; | |||
return; | |||
(void)synth; | |||
} |
@@ -0,0 +1,183 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
* | |||
* Copyright (C) 2004 Sean Bolton and others. | |||
* | |||
* Portions of this file may have come from Steve Brookes' | |||
* nekobee, copyright (C) 1999 S. J. Brookes. | |||
* Portions of this file may have come from Peter Hanappe's | |||
* Fluidsynth, copyright (C) 2003 Peter Hanappe and others. | |||
* | |||
* 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 (at your option) 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. | |||
* | |||
* You should have received a copy of the GNU General Public | |||
* License along with this program; if not, write to the Free | |||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
* MA 02111-1307, USA. | |||
*/ | |||
#ifndef _XSYNTH_VOICE_H | |||
#define _XSYNTH_VOICE_H | |||
#include <string.h> | |||
#include "nekobee_types.h" | |||
/* maximum size of a rendering burst */ | |||
#define XSYNTH_NUGGET_SIZE 64 | |||
/* minBLEP constants */ | |||
/* minBLEP table oversampling factor (must be a power of two): */ | |||
#define MINBLEP_PHASES 64 | |||
/* MINBLEP_PHASES minus one: */ | |||
#define MINBLEP_PHASE_MASK 63 | |||
/* length in samples of (truncated) step discontinuity delta: */ | |||
#define STEP_DD_PULSE_LENGTH 72 | |||
/* length in samples of (truncated) slope discontinuity delta: */ | |||
#define SLOPE_DD_PULSE_LENGTH 71 | |||
/* the longer of the two above: */ | |||
#define LONGEST_DD_PULSE_LENGTH STEP_DD_PULSE_LENGTH | |||
/* MINBLEP_BUFFER_LENGTH must be at least XSYNTH_NUGGET_SIZE plus | |||
* LONGEST_DD_PULSE_LENGTH, and not less than twice LONGEST_DD_PULSE_LENGTH: */ | |||
#define MINBLEP_BUFFER_LENGTH 512 | |||
/* delay between start of DD pulse and the discontinuity, in samples: */ | |||
#define DD_SAMPLE_DELAY 4 | |||
struct _nekobee_patch_t | |||
{ | |||
float tuning; | |||
unsigned char waveform; | |||
float cutoff; | |||
float resonance; | |||
float envmod; | |||
float decay; | |||
float accent; | |||
float volume; | |||
}; | |||
enum nekobee_voice_status | |||
{ | |||
XSYNTH_VOICE_OFF, /* silent: is not processed by render loop */ | |||
XSYNTH_VOICE_ON, /* has not received a note off event */ | |||
XSYNTH_VOICE_SUSTAINED, /* has received note off, but sustain controller is on */ | |||
XSYNTH_VOICE_RELEASED /* had note off, not sustained, in final decay phase of envelopes */ | |||
}; | |||
struct blosc | |||
{ | |||
int last_waveform, /* persistent */ | |||
waveform, /* comes from LADSPA port each cycle */ | |||
bp_high; /* persistent */ | |||
float pos, /* persistent */ | |||
pw; /* comes from LADSPA port each cycle */ | |||
}; | |||
/* | |||
* nekobee_voice_t | |||
*/ | |||
struct _nekobee_voice_t | |||
{ | |||
unsigned int note_id; | |||
unsigned char status; | |||
unsigned char key; | |||
unsigned char velocity; | |||
unsigned char rvelocity; /* the note-off velocity */ | |||
/* translated controller values */ | |||
float pressure; /* filter resonance multiplier, off = 1.0, full on = 0.0 */ | |||
/* persistent voice state */ | |||
float prev_pitch, | |||
target_pitch, | |||
lfo_pos; | |||
struct blosc osc1; | |||
float vca_eg, | |||
vcf_eg, | |||
accent_slug, | |||
delay1, | |||
delay2, | |||
delay3, | |||
delay4, | |||
c5; | |||
unsigned char vca_eg_phase, | |||
vcf_eg_phase; | |||
int osc_index; /* shared index into osc_audio */ | |||
float osc_audio[MINBLEP_BUFFER_LENGTH]; | |||
float freqcut_buf[XSYNTH_NUGGET_SIZE]; | |||
float vca_buf[XSYNTH_NUGGET_SIZE]; | |||
}; | |||
#define _PLAYING(voice) ((voice)->status != XSYNTH_VOICE_OFF) | |||
#define _ON(voice) ((voice)->status == XSYNTH_VOICE_ON) | |||
#define _SUSTAINED(voice) ((voice)->status == XSYNTH_VOICE_SUSTAINED) | |||
#define _RELEASED(voice) ((voice)->status == XSYNTH_VOICE_RELEASED) | |||
#define _AVAILABLE(voice) ((voice)->status == XSYNTH_VOICE_OFF) | |||
extern float nekobee_pitch[128]; | |||
typedef struct { float value, delta; } float_value_delta; | |||
extern float_value_delta step_dd_table[]; | |||
extern float slope_dd_table[]; | |||
/* nekobee_voice.c */ | |||
nekobee_voice_t *nekobee_voice_new(); | |||
void nekobee_voice_note_on(nekobee_synth_t *synth, | |||
nekobee_voice_t *voice, | |||
unsigned char key, | |||
unsigned char velocity); | |||
void nekobee_voice_remove_held_key(nekobee_synth_t *synth, | |||
unsigned char key); | |||
void nekobee_voice_note_off(nekobee_synth_t *synth, | |||
nekobee_voice_t *voice, | |||
unsigned char key, | |||
unsigned char rvelocity); | |||
void nekobee_voice_release_note(nekobee_synth_t *synth, | |||
nekobee_voice_t *voice); | |||
void nekobee_voice_set_ports(nekobee_synth_t *synth, | |||
nekobee_patch_t *patch); | |||
void nekobee_voice_update_pressure_mod(nekobee_synth_t *synth, | |||
nekobee_voice_t *voice); | |||
/* nekobee_voice_render.c */ | |||
void nekobee_init_tables(void); | |||
void nekobee_voice_render(nekobee_synth_t *synth, nekobee_voice_t *voice, | |||
float *out, unsigned long sample_count, | |||
int do_control_update); | |||
/* inline functions */ | |||
/* | |||
* nekobee_voice_off | |||
* | |||
* Purpose: Turns off a voice immediately, meaning that it is not processed | |||
* anymore by the render loop. | |||
*/ | |||
static inline void | |||
nekobee_voice_off(nekobee_voice_t* voice) | |||
{ | |||
voice->status = XSYNTH_VOICE_OFF; | |||
/* silence the oscillator buffer for the next use */ | |||
memset(voice->osc_audio, 0, MINBLEP_BUFFER_LENGTH * sizeof(float)); | |||
/* -FIX- decrement active voice count? */ | |||
} | |||
/* | |||
* nekobee_voice_start_voice | |||
*/ | |||
static inline void | |||
nekobee_voice_start_voice(nekobee_voice_t *voice) | |||
{ | |||
voice->status = XSYNTH_VOICE_ON; | |||
/* -FIX- increment active voice count? */ | |||
} | |||
#endif /* _XSYNTH_VOICE_H */ |
@@ -0,0 +1,414 @@ | |||
/* nekobee DSSI software synthesizer plugin | |||
*/ | |||
#define _BSD_SOURCE 1 | |||
#define _SVID_SOURCE 1 | |||
#define _ISOC99_SOURCE 1 | |||
#include <math.h> | |||
#include "nekobee.h" | |||
#include "nekobee_synth.h" | |||
#include "nekobee_voice.h" | |||
#ifndef M_PI | |||
#define M_PI 3.14159265358979323846 | |||
#endif | |||
#define M_2PI_F (2.0f * (float)M_PI) | |||
#define M_PI_F (float)M_PI | |||
#define VCF_FREQ_MAX (0.825f) /* original filters only stable to this frequency */ | |||
static int tables_initialized = 0; | |||
float nekobee_pitch[128]; | |||
#define pitch_ref_note 69 | |||
#define volume_to_amplitude_scale 128 | |||
static float volume_to_amplitude_table[4 + volume_to_amplitude_scale + 2]; | |||
static float velocity_to_attenuation[128]; | |||
static float qdB_to_amplitude_table[4 + 256 + 0]; | |||
void | |||
nekobee_init_tables(void) | |||
{ | |||
int i; | |||
float pexp; | |||
float volume, volume_exponent; | |||
float ol, amp; | |||
if (tables_initialized) | |||
return; | |||
/* MIDI note to pitch */ | |||
for (i = 0; i < 128; ++i) { | |||
pexp = (float)(i - pitch_ref_note) / 12.0f; | |||
nekobee_pitch[i] = powf(2.0f, pexp); | |||
} | |||
/* volume to amplitude | |||
* | |||
* This generates a curve which is: | |||
* volume_to_amplitude_table[128 + 4] = 0.25 * 3.16... ~= -2dB | |||
* volume_to_amplitude_table[64 + 4] = 0.25 * 1.0 ~= -12dB | |||
* volume_to_amplitude_table[32 + 4] = 0.25 * 0.316... ~= -22dB | |||
* volume_to_amplitude_table[16 + 4] = 0.25 * 0.1 ~= -32dB | |||
* etc. | |||
*/ | |||
volume_exponent = 1.0f / (2.0f * log10f(2.0f)); | |||
for (i = 0; i <= volume_to_amplitude_scale; i++) { | |||
volume = (float)i / (float)volume_to_amplitude_scale; | |||
volume_to_amplitude_table[i + 4] = powf(2.0f * volume, volume_exponent) / 4.0f; | |||
} | |||
volume_to_amplitude_table[ -1 + 4] = 0.0f; | |||
volume_to_amplitude_table[129 + 4] = volume_to_amplitude_table[128 + 4]; | |||
/* velocity to attenuation | |||
* | |||
* Creates the velocity to attenuation lookup table, for converting | |||
* velocities [1, 127] to full-velocity-sensitivity attenuation in | |||
* quarter decibels. Modeled after my TX-7's velocity response.*/ | |||
velocity_to_attenuation[0] = 253.9999f; | |||
for (i = 1; i < 127; i++) { | |||
if (i >= 10) { | |||
ol = (powf(((float)i / 127.0f), 0.32f) - 1.0f) * 100.0f; | |||
amp = powf(2.0f, ol / 8.0f); | |||
} else { | |||
ol = (powf(((float)10 / 127.0f), 0.32f) - 1.0f) * 100.0f; | |||
amp = powf(2.0f, ol / 8.0f) * (float)i / 10.0f; | |||
} | |||
velocity_to_attenuation[i] = log10f(amp) * -80.0f; | |||
} | |||
velocity_to_attenuation[127] = 0.0f; | |||
/* quarter-decibel attenuation to amplitude */ | |||
qdB_to_amplitude_table[-1 + 4] = 1.0f; | |||
for (i = 0; i <= 255; i++) { | |||
qdB_to_amplitude_table[i + 4] = powf(10.0f, (float)i / -80.0f); | |||
} | |||
tables_initialized = 1; | |||
} | |||
static inline float | |||
volume(float level) | |||
{ | |||
unsigned char segment; | |||
float fract; | |||
level *= (float)volume_to_amplitude_scale; | |||
segment = lrintf(level - 0.5f); | |||
fract = level - (float)segment; | |||
return volume_to_amplitude_table[segment + 4] + fract * | |||
(volume_to_amplitude_table[segment + 5] - | |||
volume_to_amplitude_table[segment + 4]); | |||
} | |||
static inline float | |||
qdB_to_amplitude(float qdB) | |||
{ | |||
int i = lrintf(qdB - 0.5f); | |||
float f = qdB - (float)i; | |||
return qdB_to_amplitude_table[i + 4] + f * | |||
(qdB_to_amplitude_table[i + 5] - | |||
qdB_to_amplitude_table[i + 4]); | |||
} | |||
void blosc_place_step_dd(float *buffer, int index, float phase, float w, float scale){ | |||
float r; | |||
int i; | |||
r = MINBLEP_PHASES * phase / w; | |||
i = lrintf(r - 0.5f); | |||
r -= (float)i; | |||
i &= MINBLEP_PHASE_MASK; /* port changes can cause i to be out-of-range */ | |||
/* This would be better than the above, but more expensive: | |||
* while (i < 0) { | |||
* i += MINBLEP_PHASES; | |||
* index++; | |||
* } | |||
*/ | |||
while (i < MINBLEP_PHASES * STEP_DD_PULSE_LENGTH) { | |||
buffer[index] += scale * (step_dd_table[i].value + r * step_dd_table[i].delta); | |||
i += MINBLEP_PHASES; | |||
index++; | |||
} | |||
} | |||
void vco(unsigned long sample_count, nekobee_voice_t *voice, struct blosc *osc, | |||
int index, float w) | |||
{ | |||
unsigned long sample; | |||
float pos = osc->pos; | |||
float pw, gain, halfgain, out; | |||
pw=0.46f; | |||
gain=1.0f; | |||
halfgain=gain*0.5f; | |||
int bp_high = osc->bp_high; | |||
out=(bp_high ? halfgain : -halfgain); | |||
switch (osc->waveform) | |||
{ | |||
default: | |||
case 0: { | |||
for (sample = 0; sample < sample_count; sample++) { | |||
pos += w; | |||
if (bp_high) { | |||
if (pos >= pw) { | |||
blosc_place_step_dd(voice->osc_audio, index, pos - pw, w, -gain); | |||
bp_high = 0; | |||
out = -halfgain; | |||
} | |||
if (pos >= 1.0f) { | |||
pos -= 1.0f; | |||
blosc_place_step_dd(voice->osc_audio, index, pos, w, gain); | |||
bp_high = 1; | |||
out = halfgain; | |||
} | |||
} else { | |||
if (pos >= 1.0f) { | |||
pos -= 1.0f; | |||
blosc_place_step_dd(voice->osc_audio, index, pos, w, gain); | |||
bp_high = 1; | |||
out = halfgain; | |||
} | |||
if (bp_high && pos >= pw) { | |||
blosc_place_step_dd(voice->osc_audio, index, pos - pw, w, -gain); | |||
bp_high = 0; | |||
out = -halfgain; | |||
} | |||
} | |||
voice->osc_audio[index + DD_SAMPLE_DELAY] += out; | |||
index++; | |||
} | |||
osc->pos = pos; | |||
osc->bp_high = bp_high; | |||
break; | |||
} | |||
case 1: // sawtooth wave | |||
{ | |||
for (sample=0; sample < sample_count; sample++) { | |||
pos += w; | |||
if (pos >= 1.0f) { | |||
pos -= 1.0f; | |||
blosc_place_step_dd(voice->osc_audio, index, pos, w, gain); | |||
} | |||
voice->osc_audio[index + DD_SAMPLE_DELAY] += gain * (0.5f - pos); | |||
index++; | |||
} | |||
break; | |||
} | |||
} | |||
osc->pos=pos; | |||
} | |||
static inline void | |||
vcf_4pole(nekobee_voice_t *voice, unsigned long sample_count, | |||
float *in, float *out, float *cutoff, float qres, float *amp) | |||
{ | |||
unsigned long sample; | |||
float freqcut, freqcut2, highpass, | |||
delay1 = voice->delay1, | |||
delay2 = voice->delay2, | |||
delay3 = voice->delay3, | |||
delay4 = voice->delay4; | |||
qres = 2.0f - qres * 1.995f; | |||
for (sample = 0; sample < sample_count; sample++) { | |||
/* Hal Chamberlin's state variable filter */ | |||
freqcut = cutoff[sample] * 2.0f; | |||
freqcut2 = cutoff[sample] * 4.0f; | |||
if (freqcut > VCF_FREQ_MAX) freqcut = VCF_FREQ_MAX; | |||
if (freqcut2 > VCF_FREQ_MAX) freqcut2 = VCF_FREQ_MAX; | |||
delay2 = delay2 + freqcut * delay1; /* delay2/4 = lowpass output */ | |||
highpass = in[sample] - delay2 - qres * delay1; | |||
delay1 = freqcut * highpass + delay1; /* delay1/3 = bandpass output */ | |||
delay4 = delay4 + freqcut2 * delay3; | |||
highpass = delay2 - delay4 - qres * delay3; | |||
delay3 = freqcut2 * highpass + delay3; | |||
/* mix filter output into output buffer */ | |||
out[sample] += 0.1*atan(3*delay4 * amp[sample]); | |||
} | |||
voice->delay1 = delay1; | |||
voice->delay2 = delay2; | |||
voice->delay3 = delay3; | |||
voice->delay4 = delay4; | |||
voice->c5 = 0.0f; | |||
} | |||
/* | |||
* nekobee_voice_render | |||
* | |||
* generate the actual sound data for this voice | |||
*/ | |||
void | |||
nekobee_voice_render(nekobee_synth_t *synth, nekobee_voice_t *voice, | |||
float *out, unsigned long sample_count, | |||
int do_control_update) | |||
{ | |||
unsigned long sample; | |||
/* state variables saved in voice */ | |||
float lfo_pos = voice->lfo_pos, | |||
vca_eg = voice->vca_eg, | |||
vcf_eg = voice->vcf_eg; | |||
unsigned char vca_eg_phase = voice->vca_eg_phase, | |||
vcf_eg_phase = voice->vcf_eg_phase; | |||
int osc_index = voice->osc_index; | |||
/* temporary variables used in calculating voice */ | |||
float fund_pitch; | |||
float deltat = synth->deltat; | |||
float freq, cutoff, vcf_amt; | |||
float vcf_acc_amt; | |||
/* set up synthesis variables from patch */ | |||
float omega; | |||
float vca_eg_amp = qdB_to_amplitude(velocity_to_attenuation[voice->velocity] * 0); | |||
float vca_eg_rate_level[3], vca_eg_one_rate[3]; | |||
float vcf_eg_amp = qdB_to_amplitude(velocity_to_attenuation[voice->velocity] * 0); | |||
float vcf_eg_rate_level[3], vcf_eg_one_rate[3]; | |||
float qres = synth->resonance; | |||
float vol_out = volume(synth->volume); | |||
float velocity = (voice->velocity); | |||
float vcf_egdecay = synth->decay; | |||
fund_pitch = 0.1f*voice->target_pitch +0.9 * voice->prev_pitch; /* glide */ | |||
if (do_control_update) { | |||
voice->prev_pitch = fund_pitch; /* save pitch for next time */ | |||
} | |||
fund_pitch *= 440.0f; | |||
omega = synth->tuning * fund_pitch; | |||
// if we have triggered ACCENT | |||
// we need a shorter decay | |||
// we should probably have something like this in the note on code | |||
// that could trigger an ACCENT light | |||
if (velocity>90) { | |||
vcf_egdecay=.0005; | |||
} | |||
// VCA - In a real 303, it is set for around 2 seconds | |||
vca_eg_rate_level[0] = 0.1f * vca_eg_amp; // instant on attack | |||
vca_eg_one_rate[0] = 0.9f; // very fast | |||
vca_eg_rate_level[1] = 0.0f; // sustain is zero | |||
vca_eg_one_rate[1] = 1.0f - 0.00001f; // decay time is very slow | |||
vca_eg_rate_level[2] = 0.0f; // decays to zero | |||
vca_eg_one_rate[2] = 0.975f; // very fast release | |||
// VCF - funny things go on with the accent | |||
vcf_eg_rate_level[0] = 0.1f * vcf_eg_amp; | |||
vcf_eg_one_rate[0] = 1-0.1f; //0.9f; | |||
vcf_eg_rate_level[1] = 0.0f; // vcf_egdecay * *(synth->vcf_eg_sustain_level) * vcf_eg_amp; | |||
vcf_eg_one_rate[1] = 1.0f - vcf_egdecay; | |||
vcf_eg_rate_level[2] = 0.0f; | |||
vcf_eg_one_rate[2] = 0.9995f; // 1.0f - *(synth->vcf_eg_release_time); | |||
vca_eg_amp *= 0.99f; | |||
vcf_eg_amp *= 0.99f; | |||
freq = M_PI_F * deltat * fund_pitch * synth->mod_wheel; /* now (0 to 1) * pi */ | |||
cutoff = 0.008f * synth->cutoff; | |||
// 303 always has slight VCF mod | |||
vcf_amt = 0.05f+(synth->envmod*0.75); | |||
/* copy some things so oscillator functions can see them */ | |||
voice->osc1.waveform = lrintf(synth->waveform); | |||
// work out how much the accent will affect the filter | |||
vcf_acc_amt=.333f+ (synth->resonance/1.5f); | |||
for (sample = 0; sample < sample_count; sample++) { | |||
vca_eg = vca_eg_rate_level[vca_eg_phase] + vca_eg_one_rate[vca_eg_phase] * vca_eg; | |||
vcf_eg = vcf_eg_rate_level[vcf_eg_phase] + vcf_eg_one_rate[vcf_eg_phase] * vcf_eg; | |||
voice->freqcut_buf[sample] = (cutoff + (vcf_amt * vcf_eg/2.0f) + (synth->vcf_accent * synth->accent*0.5f)); | |||
voice->vca_buf[sample] = vca_eg * vol_out*(1.0f + synth->accent*synth->vca_accent); | |||
if (!vca_eg_phase && vca_eg > vca_eg_amp) vca_eg_phase = 1; /* flip from attack to decay */ | |||
if (!vcf_eg_phase && vcf_eg > vcf_eg_amp) vcf_eg_phase = 1; /* flip from attack to decay */ | |||
} | |||
// oscillator | |||
vco(sample_count, voice, &voice->osc1, osc_index, deltat * omega); | |||
// VCF and VCA | |||
vcf_4pole(voice, sample_count, voice->osc_audio + osc_index, out, voice->freqcut_buf, qres, voice->vca_buf); | |||
osc_index += sample_count; | |||
if (do_control_update) { | |||
/* do those things should be done only once per control-calculation | |||
* interval ("nugget"), such as voice check-for-dead, pitch envelope | |||
* calculations, volume envelope phase transition checks, etc. */ | |||
/* check if we've decayed to nothing, turn off voice if so */ | |||
if (vca_eg_phase == 2 && voice->vca_buf[sample_count - 1] < 6.26e-6f) { | |||
// sound has completed its release phase (>96dB below volume '5' max) | |||
XDB_MESSAGE(XDB_NOTE, " nekobee_voice_render check for dead: killing note id %d\n", voice->note_id); | |||
nekobee_voice_off(voice); | |||
return; // we're dead now, so return | |||
} | |||
/* already saved prev_pitch above */ | |||
/* check oscillator audio buffer index, shift buffer if necessary */ | |||
if (osc_index > MINBLEP_BUFFER_LENGTH - (XSYNTH_NUGGET_SIZE + LONGEST_DD_PULSE_LENGTH)) { | |||
memcpy(voice->osc_audio, voice->osc_audio + osc_index, | |||
LONGEST_DD_PULSE_LENGTH * sizeof (float)); | |||
memset(voice->osc_audio + LONGEST_DD_PULSE_LENGTH, 0, | |||
(MINBLEP_BUFFER_LENGTH - LONGEST_DD_PULSE_LENGTH) * sizeof (float)); | |||
osc_index = 0; | |||
} | |||
} | |||
/* save things for next time around */ | |||
voice->lfo_pos = lfo_pos; | |||
voice->vca_eg = vca_eg; | |||
voice->vca_eg_phase = vca_eg_phase; | |||
voice->vcf_eg = vcf_eg; | |||
voice->vcf_eg_phase = vcf_eg_phase; | |||
voice->osc_index = osc_index; | |||
return; | |||
(void)freq; | |||
(void)vcf_acc_amt; | |||
} |
@@ -0,0 +1,72 @@ | |||
/* | |||
* Carla Native Plugins | |||
* 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 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-pingpongpan/DistrhoPluginInfo.h" | |||
#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) | |||
# undef DISTRHO_PLUGIN_HAS_UI | |||
# define DISTRHO_PLUGIN_HAS_UI 0 | |||
#endif | |||
// Plugin Code | |||
#include "distrho-pingpongpan/DistrhoArtworkPingPongPan.cpp" | |||
#include "distrho-pingpongpan/DistrhoPluginPingPongPan.cpp" | |||
#include "distrho-pingpongpan/DistrhoUIPingPongPan.cpp" | |||
// DISTRHO Code | |||
#define DISTRHO_PLUGIN_TARGET_CARLA | |||
#include "DistrhoPluginMain.cpp" | |||
#include "DistrhoUIMain.cpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
static const NativePluginDescriptor pingpongpanDesc = { | |||
/* category */ NATIVE_PLUGIN_CATEGORY_UTILITY, | |||
#ifdef HAVE_DGL | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE|NATIVE_PLUGIN_HAS_UI|NATIVE_PLUGIN_USES_PARENT_ID), | |||
#else | |||
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE), | |||
#endif | |||
/* supports */ static_cast<NativePluginSupports>(0x0), | |||
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS, | |||
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS, | |||
/* midiIns */ 0, | |||
/* midiOuts */ 0, | |||
/* paramIns */ DistrhoPluginPingPongPan::paramCount, | |||
/* paramOuts */ 0, | |||
/* name */ DISTRHO_PLUGIN_NAME, | |||
/* label */ "pingpongpan", | |||
/* maker */ "falkTX, Michael Gruhn", | |||
/* copyright */ "LGPL", | |||
PluginDescriptorFILL(PluginCarla) | |||
}; | |||
END_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
CARLA_EXPORT | |||
void carla_register_native_plugin_distrho_pingpongpan() | |||
{ | |||
USE_NAMESPACE_DISTRHO | |||
carla_register_native_plugin(&pingpongpanDesc); | |||
} | |||
// ----------------------------------------------------------------------- |
@@ -0,0 +1,35 @@ | |||
/* (Auto-generated binary data file). */ | |||
#ifndef BINARY_DISTRHOARTWORKPINGPONGPAN_HPP | |||
#define BINARY_DISTRHOARTWORKPINGPONGPAN_HPP | |||
namespace DistrhoArtworkPingPongPan | |||
{ | |||
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 = 7600; | |||
const unsigned int aboutButtonHoverWidth = 95; | |||
const unsigned int aboutButtonHoverHeight = 20; | |||
extern const char* aboutButtonNormalData; | |||
const unsigned int aboutButtonNormalDataSize = 7600; | |||
const unsigned int aboutButtonNormalWidth = 95; | |||
const unsigned int aboutButtonNormalHeight = 20; | |||
extern const char* backgroundData; | |||
const unsigned int backgroundDataSize = 157080; | |||
const unsigned int backgroundWidth = 308; | |||
const unsigned int backgroundHeight = 170; | |||
extern const char* knobData; | |||
const unsigned int knobDataSize = 17956; | |||
const unsigned int knobWidth = 67; | |||
const unsigned int knobHeight = 67; | |||
} | |||
#endif // BINARY_DISTRHOARTWORKPINGPONGPAN_HPP | |||
@@ -0,0 +1,35 @@ | |||
/* | |||
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn | |||
* Copyright (C) 2012-2014 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_NAME "Ping Pong Pan" | |||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||
#define DISTRHO_PLUGIN_IS_SYNTH 0 | |||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | |||
#define DISTRHO_PLUGIN_WANT_LATENCY 0 | |||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | |||
#define DISTRHO_PLUGIN_WANT_STATE 0 | |||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0 | |||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/PingPongPan" | |||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -0,0 +1,161 @@ | |||
/* | |||
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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 "DistrhoPluginPingPongPan.hpp" | |||
#include <cmath> | |||
static const float k2PI = 6.283185307f; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoPluginPingPongPan::DistrhoPluginPingPongPan() | |||
: Plugin(paramCount, 1, 0) // 1 program, 0 states | |||
{ | |||
// set default values | |||
d_setProgram(0); | |||
// reset | |||
d_deactivate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Init | |||
void DistrhoPluginPingPongPan::d_initParameter(uint32_t index, Parameter& parameter) | |||
{ | |||
switch (index) | |||
{ | |||
case paramFreq: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Frequency"; | |||
parameter.symbol = "freq"; | |||
parameter.ranges.def = 50.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
case paramWidth: | |||
parameter.hints = kParameterIsAutomable; | |||
parameter.name = "Width"; | |||
parameter.symbol = "with"; | |||
parameter.unit = "%"; | |||
parameter.ranges.def = 75.0f; | |||
parameter.ranges.min = 0.0f; | |||
parameter.ranges.max = 100.0f; | |||
break; | |||
} | |||
} | |||
void DistrhoPluginPingPongPan::d_initProgramName(uint32_t index, d_string& programName) | |||
{ | |||
if (index != 0) | |||
return; | |||
programName = "Default"; | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Internal data | |||
float DistrhoPluginPingPongPan::d_getParameterValue(uint32_t index) const | |||
{ | |||
switch (index) | |||
{ | |||
case paramFreq: | |||
return fFreq; | |||
case paramWidth: | |||
return fWidth; | |||
default: | |||
return 0.0f; | |||
} | |||
} | |||
void DistrhoPluginPingPongPan::d_setParameterValue(uint32_t index, float value) | |||
{ | |||
if (d_getSampleRate() <= 0.0) | |||
return; | |||
switch (index) | |||
{ | |||
case paramFreq: | |||
fFreq = value; | |||
waveSpeed = (k2PI * fFreq / 100.0f)/(float)d_getSampleRate(); | |||
break; | |||
case paramWidth: | |||
fWidth = value; | |||
break; | |||
} | |||
} | |||
void DistrhoPluginPingPongPan::d_setProgram(uint32_t index) | |||
{ | |||
if (index != 0) | |||
return; | |||
// Default values | |||
fFreq = 50.0f; | |||
fWidth = 75.0f; | |||
// reset filter values | |||
d_activate(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Process | |||
void DistrhoPluginPingPongPan::d_activate() | |||
{ | |||
waveSpeed = (k2PI * fFreq / 100.0f)/(float)d_getSampleRate(); | |||
} | |||
void DistrhoPluginPingPongPan::d_deactivate() | |||
{ | |||
wavePos = 0.0f; | |||
} | |||
void DistrhoPluginPingPongPan::d_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) | |||
{ | |||
pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f); | |||
if ((wavePos += waveSpeed) >= k2PI) | |||
wavePos -= k2PI; | |||
out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f); | |||
out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f); | |||
} | |||
} | |||
// ----------------------------------------------------------------------- | |||
Plugin* createPlugin() | |||
{ | |||
return new DistrhoPluginPingPongPan(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,104 @@ | |||
/* | |||
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn | |||
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de> | |||
* Copyright (C) 2012-2014 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_PINGPONGPAN_HPP_INCLUDED | |||
#define DISTRHO_PLUGIN_PINGPONGPAN_HPP_INCLUDED | |||
#include "DistrhoPlugin.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoPluginPingPongPan : public Plugin | |||
{ | |||
public: | |||
enum Parameters | |||
{ | |||
paramFreq = 0, | |||
paramWidth, | |||
paramCount | |||
}; | |||
DistrhoPluginPingPongPan(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// Information | |||
const char* d_getLabel() const noexcept override | |||
{ | |||
return "PingPongPan"; | |||
} | |||
const char* d_getMaker() const noexcept override | |||
{ | |||
return "DISTRHO"; | |||
} | |||
const char* d_getLicense() const noexcept override | |||
{ | |||
return "LGPL"; | |||
} | |||
uint32_t d_getVersion() const noexcept override | |||
{ | |||
return 0x1000; | |||
} | |||
int64_t d_getUniqueId() const noexcept override | |||
{ | |||
return d_cconst('D', 'P', 'P', 'P'); | |||
} | |||
// ------------------------------------------------------------------- | |||
// Init | |||
void d_initParameter(uint32_t index, Parameter& parameter) override; | |||
void d_initProgramName(uint32_t index, d_string& programName) override; | |||
// ------------------------------------------------------------------- | |||
// Internal data | |||
float d_getParameterValue(uint32_t index) const override; | |||
void d_setParameterValue(uint32_t index, float value) override; | |||
void d_setProgram(uint32_t index) override; | |||
// ------------------------------------------------------------------- | |||
// Process | |||
void d_activate() override; | |||
void d_deactivate() override; | |||
void d_run(const float** inputs, float** outputs, uint32_t frames) override; | |||
// ------------------------------------------------------------------- | |||
private: | |||
float fFreq; | |||
float fWidth; | |||
float waveSpeed; | |||
float pan, wavePos; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginPingPongPan) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_PLUGIN_PINGPONGPAN_HPP_INCLUDED |
@@ -0,0 +1,133 @@ | |||
/* | |||
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn | |||
* Copyright (C) 2012-2014 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 "DistrhoPluginPingPongPan.hpp" | |||
#include "DistrhoUIPingPongPan.hpp" | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
DistrhoUIPingPongPan::DistrhoUIPingPongPan() | |||
: UI(), | |||
fAboutWindow(this) | |||
{ | |||
// set UI size | |||
setSize(DistrhoArtworkPingPongPan::backgroundWidth, DistrhoArtworkPingPongPan::backgroundHeight); | |||
// background | |||
fImgBackground = Image(DistrhoArtworkPingPongPan::backgroundData, DistrhoArtworkPingPongPan::backgroundWidth, DistrhoArtworkPingPongPan::backgroundHeight, GL_BGR); | |||
Image imageAbout(DistrhoArtworkPingPongPan::aboutData, DistrhoArtworkPingPongPan::aboutWidth, DistrhoArtworkPingPongPan::aboutHeight, GL_BGR); | |||
fAboutWindow.setImage(imageAbout); | |||
// knobs | |||
Image knobImage(DistrhoArtworkPingPongPan::knobData, DistrhoArtworkPingPongPan::knobWidth, DistrhoArtworkPingPongPan::knobHeight); | |||
// knob Low-Mid | |||
fKnobFreq = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginPingPongPan::paramFreq); | |||
fKnobFreq->setAbsolutePos(60, 58); | |||
fKnobFreq->setRange(0.0f, 100.0f); | |||
fKnobFreq->setDefault(50.0f); | |||
fKnobFreq->setRotationAngle(270); | |||
fKnobFreq->setCallback(this); | |||
// knob Mid-High | |||
fKnobWidth = new ImageKnob(this, knobImage, ImageKnob::Vertical, DistrhoPluginPingPongPan::paramWidth); | |||
fKnobWidth->setAbsolutePos(182, 58); | |||
fKnobWidth->setRange(0.0f, 100.0f); | |||
fKnobWidth->setDefault(75.0f); | |||
fKnobWidth->setRotationAngle(270); | |||
fKnobWidth->setCallback(this); | |||
// about button | |||
Image aboutImageNormal(DistrhoArtworkPingPongPan::aboutButtonNormalData, DistrhoArtworkPingPongPan::aboutButtonNormalWidth, DistrhoArtworkPingPongPan::aboutButtonNormalHeight); | |||
Image aboutImageHover(DistrhoArtworkPingPongPan::aboutButtonHoverData, DistrhoArtworkPingPongPan::aboutButtonHoverWidth, DistrhoArtworkPingPongPan::aboutButtonHoverHeight); | |||
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover); | |||
fButtonAbout->setAbsolutePos(183, 8); | |||
fButtonAbout->setCallback(this); | |||
// set default values | |||
d_programChanged(0); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void DistrhoUIPingPongPan::d_parameterChanged(uint32_t index, float value) | |||
{ | |||
switch (index) | |||
{ | |||
case DistrhoPluginPingPongPan::paramFreq: | |||
fKnobFreq->setValue(value); | |||
break; | |||
case DistrhoPluginPingPongPan::paramWidth: | |||
fKnobWidth->setValue(value); | |||
break; | |||
} | |||
} | |||
void DistrhoUIPingPongPan::d_programChanged(uint32_t index) | |||
{ | |||
if (index != 0) | |||
return; | |||
// Default values | |||
fKnobFreq->setValue(50.0f); | |||
fKnobWidth->setValue(75.0f); | |||
} | |||
// ----------------------------------------------------------------------- | |||
// Widget Callbacks | |||
void DistrhoUIPingPongPan::imageButtonClicked(ImageButton* button, int) | |||
{ | |||
if (button != fButtonAbout) | |||
return; | |||
fAboutWindow.exec(); | |||
} | |||
void DistrhoUIPingPongPan::imageKnobDragStarted(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), true); | |||
} | |||
void DistrhoUIPingPongPan::imageKnobDragFinished(ImageKnob* knob) | |||
{ | |||
d_editParameter(knob->getId(), false); | |||
} | |||
void DistrhoUIPingPongPan::imageKnobValueChanged(ImageKnob* knob, float value) | |||
{ | |||
d_setParameterValue(knob->getId(), value); | |||
} | |||
void DistrhoUIPingPongPan::onDisplay() | |||
{ | |||
fImgBackground.draw(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
UI* createUI() | |||
{ | |||
return new DistrhoUIPingPongPan(); | |||
} | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO |
@@ -0,0 +1,75 @@ | |||
/* | |||
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn | |||
* Copyright (C) 2012-2014 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_PINGPONGPAN_HPP_INCLUDED | |||
#define DISTRHO_UI_PINGPONGPAN_HPP_INCLUDED | |||
#include "DistrhoUI.hpp" | |||
#include "ImageAboutWindow.hpp" | |||
#include "ImageButton.hpp" | |||
#include "ImageKnob.hpp" | |||
#include "DistrhoArtworkPingPongPan.hpp" | |||
using DGL::Image; | |||
using DGL::ImageAboutWindow; | |||
using DGL::ImageButton; | |||
using DGL::ImageKnob; | |||
START_NAMESPACE_DISTRHO | |||
// ----------------------------------------------------------------------- | |||
class DistrhoUIPingPongPan : public UI, | |||
public ImageButton::Callback, | |||
public ImageKnob::Callback | |||
{ | |||
public: | |||
DistrhoUIPingPongPan(); | |||
protected: | |||
// ------------------------------------------------------------------- | |||
// DSP Callbacks | |||
void d_parameterChanged(uint32_t index, float value) override; | |||
void d_programChanged(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 onDisplay() override; | |||
private: | |||
Image fImgBackground; | |||
ImageAboutWindow fAboutWindow; | |||
ScopedPointer<ImageButton> fButtonAbout; | |||
ScopedPointer<ImageKnob> fKnobFreq, fKnobWidth; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoUIPingPongPan) | |||
}; | |||
// ----------------------------------------------------------------------- | |||
END_NAMESPACE_DISTRHO | |||
#endif // DISTRHO_UI_PINGPONGPAN_HPP_INCLUDED |