399 changes: 399 additions & 0 deletions distrho-nekobi/DistrhoPluginNekobi.cpp
@@ -0,0 +1,399 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2004 Sean Bolton and others
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#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_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 = getSampleRate();
fSynth.deltat = 1.0f / (float)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
deactivate();
}

DistrhoPluginNekobi::~DistrhoPluginNekobi()
{
std::free(fSynth.voice);
}

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

void DistrhoPluginNekobi::initParameter(uint32_t index, Parameter& parameter)
{
switch (index)
{
case paramWaveform:
parameter.hints = kParameterIsAutomable|kParameterIsInteger;
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::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::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::activate()
{
fSynth.nugget_remains = 0;
fSynth.note_id = 0;

if (fSynth.voice != nullptr)
nekobee_synth_all_voices_off(&fSynth);
}

void DistrhoPluginNekobi::deactivate()
{
if (fSynth.voice != nullptr)
nekobee_synth_all_voices_off(&fSynth);
}

void DistrhoPluginNekobi::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
131 changes: 131 additions & 0 deletions distrho-nekobi/DistrhoPluginNekobi.hpp
@@ -0,0 +1,131 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2004 Sean Bolton and others
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_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* getLabel() const noexcept override
{
return "Nekobi";
}

const char* getDescription() const override
{
return "Simple single-oscillator synth based on the Roland TB-303.";
}

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

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

const char* getLicense() const noexcept override
{
return "GPL v2+";
}

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

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', 'N', 'e', 'k');
}

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

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

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

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

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

void activate() override;
void deactivate() override;
void 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
231 changes: 231 additions & 0 deletions distrho-nekobi/DistrhoUINekobi.cpp
@@ -0,0 +1,231 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#include "DistrhoPluginNekobi.hpp"
#include "DistrhoUINekobi.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtworkNekobi;

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

DistrhoUINekobi::DistrhoUINekobi()
: UI(Art::backgroundWidth, Art::backgroundHeight),
fImgBackground(Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, GL_BGR),
fAboutWindow(this)
{
// FIXME
fNeko.setTimerSpeed(5);

// about
Image aboutImage(Art::aboutData, Art::aboutWidth, Art::aboutHeight, GL_BGR);
fAboutWindow.setImage(aboutImage);

// slider
Image sliderImage(Art::sliderData, Art::sliderWidth, Art::sliderHeight);

fSliderWaveform = new ImageSlider(this, sliderImage);
fSliderWaveform->setId(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(Art::knobData, Art::knobWidth, Art::knobHeight);

// knob Tuning
fKnobTuning = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobTuning->setId(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);
fKnobCutoff->setId(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);
fKnobResonance->setId(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);
fKnobEnvMod->setId(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);
fKnobDecay->setId(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);
fKnobAccent->setId(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);
fKnobVolume->setId(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(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight);
Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight);
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
fButtonAbout->setAbsolutePos(505, 5);
fButtonAbout->setCallback(this);
}

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

void DistrhoUINekobi::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::uiIdle()
{
if (fNeko.idle())
repaint();
}

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

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

fAboutWindow.exec();
}

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

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

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

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

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

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

void DistrhoUINekobi::onDisplay()
{
fImgBackground.draw();
fNeko.draw();
}

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

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

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

END_NAMESPACE_DISTRHO
86 changes: 86 additions & 0 deletions distrho-nekobi/DistrhoUINekobi.hpp
@@ -0,0 +1,86 @@
/*
* DISTRHO Nekobi Plugin, based on Nekobee by Sean Bolton and others.
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#ifndef DISTRHO_UI_NEKOBI_HPP_INCLUDED
#define DISTRHO_UI_NEKOBI_HPP_INCLUDED

#include "DistrhoUI.hpp"

#include "ImageWidgets.hpp"

#include "DistrhoArtworkNekobi.hpp"
#include "NekoWidget.hpp"

using DGL_NAMESPACE::ImageAboutWindow;
using DGL_NAMESPACE::ImageButton;
using DGL_NAMESPACE::ImageKnob;
using DGL_NAMESPACE::ImageSlider;

START_NAMESPACE_DISTRHO

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

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

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

void parameterChanged(uint32_t index, float value) override;

// -------------------------------------------------------------------
// UI Callbacks

void 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
202 changes: 202 additions & 0 deletions distrho-nekobi/NekoWidget.hpp
@@ -0,0 +1,202 @@
/*
* Neko widget animation
* Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#ifndef NEKO_WIDGET_HPP_INCLUDED
#define NEKO_WIDGET_HPP_INCLUDED

#include "DistrhoArtworkNekobi.hpp"

#include "Image.hpp"
#include "Widget.hpp"

#include <cstdlib> // rand

using DGL_NAMESPACE::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
1,779 changes: 1,779 additions & 0 deletions distrho-nekobi/nekobee-src/minblep_tables.c

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee.h
@@ -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 */
237 changes: 237 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_synth.c
@@ -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);
}
}
132 changes: 132 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_synth.h
@@ -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 */
30 changes: 30 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_types.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 */
256 changes: 256 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_voice.c
@@ -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;
}
183 changes: 183 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_voice.h
@@ -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 */
414 changes: 414 additions & 0 deletions distrho-nekobi/nekobee-src/nekobee_voice_render.c

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions distrho-pingpongpan.cpp
@@ -0,0 +1,85 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

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

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

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

// Plugin Code
#include "distrho-pingpongpan/DistrhoArtworkPingPongPan.cpp"
#include "distrho-pingpongpan/DistrhoPluginPingPongPan.cpp"
#ifdef HAVE_DGL
#include "distrho-pingpongpan/DistrhoUIPingPongPan.cpp"
#endif

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

START_NAMESPACE_DISTRHO

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

static const NativePluginDescriptor pingpongpanDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
#ifdef HAVE_DGL
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
#else
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE),
#endif
/* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 0,
/* midiOuts */ 0,
/* paramIns */ 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();

CARLA_EXPORT
void carla_register_native_plugin_distrho_pingpongpan()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&pingpongpanDesc);
}

// -----------------------------------------------------------------------
5,651 changes: 5,651 additions & 0 deletions distrho-pingpongpan/DistrhoArtworkPingPongPan.cpp

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions distrho-pingpongpan/DistrhoArtworkPingPongPan.hpp
@@ -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

33 changes: 33 additions & 0 deletions distrho-pingpongpan/DistrhoPluginInfo.h
@@ -0,0 +1,33 @@
/*
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "Ping Pong Pan"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/PingPongPan"

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

#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:SpatialPlugin"

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
161 changes: 161 additions & 0 deletions distrho-pingpongpan/DistrhoPluginPingPongPan.cpp
@@ -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-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "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
loadProgram(0);

// reset
deactivate();
}

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

void DistrhoPluginPingPongPan::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 = "width";
parameter.unit = "%";
parameter.ranges.def = 75.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 100.0f;
break;
}
}

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

programName = "Default";
}

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

float DistrhoPluginPingPongPan::getParameterValue(uint32_t index) const
{
switch (index)
{
case paramFreq:
return fFreq;
case paramWidth:
return fWidth;
default:
return 0.0f;
}
}

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

switch (index)
{
case paramFreq:
fFreq = value;
waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
break;
case paramWidth:
fWidth = value;
break;
}
}

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

// Default values
fFreq = 50.0f;
fWidth = 75.0f;

// reset filter values
activate();
}

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

void DistrhoPluginPingPongPan::activate()
{
waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
}

void DistrhoPluginPingPongPan::deactivate()
{
wavePos = 0.0f;
}

void DistrhoPluginPingPongPan::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
114 changes: 114 additions & 0 deletions distrho-pingpongpan/DistrhoPluginPingPongPan.hpp
@@ -0,0 +1,114 @@
/*
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_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* getLabel() const noexcept override
{
return "PingPongPan";
}

const char* getDescription() const override
{
return "Ping Pong Panning.";
}

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

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

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

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

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', 'P', 'P', 'P');
}

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

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

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

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

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

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

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

private:
float 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
133 changes: 133 additions & 0 deletions distrho-pingpongpan/DistrhoUIPingPongPan.cpp
@@ -0,0 +1,133 @@
/*
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPluginPingPongPan.hpp"
#include "DistrhoUIPingPongPan.hpp"

START_NAMESPACE_DISTRHO

namespace Art = DistrhoArtworkPingPongPan;

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

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

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

// knob Low-Mid
fKnobFreq = new ImageKnob(this, knobImage, ImageKnob::Vertical);
fKnobFreq->setId(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);
fKnobWidth->setId(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(Art::aboutButtonNormalData, Art::aboutButtonNormalWidth, Art::aboutButtonNormalHeight);
Image aboutImageHover(Art::aboutButtonHoverData, Art::aboutButtonHoverWidth, Art::aboutButtonHoverHeight);
fButtonAbout = new ImageButton(this, aboutImageNormal, aboutImageHover, aboutImageHover);
fButtonAbout->setAbsolutePos(183, 8);
fButtonAbout->setCallback(this);

// set default values
programLoaded(0);
}

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

void DistrhoUIPingPongPan::parameterChanged(uint32_t index, float value)
{
switch (index)
{
case DistrhoPluginPingPongPan::paramFreq:
fKnobFreq->setValue(value);
break;
case DistrhoPluginPingPongPan::paramWidth:
fKnobWidth->setValue(value);
break;
}
}

void DistrhoUIPingPongPan::programLoaded(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)
{
editParameter(knob->getId(), true);
}

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

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

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

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

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

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

END_NAMESPACE_DISTRHO
67 changes: 67 additions & 0 deletions distrho-pingpongpan/DistrhoUIPingPongPan.hpp
@@ -0,0 +1,67 @@
/*
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_UI_PINGPONGPAN_HPP_INCLUDED
#define DISTRHO_UI_PINGPONGPAN_HPP_INCLUDED

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

#include "DistrhoArtworkPingPongPan.hpp"

START_NAMESPACE_DISTRHO

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

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

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

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

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

void imageButtonClicked(ImageButton* button, int) override;
void imageKnobDragStarted(ImageKnob* knob) override;
void imageKnobDragFinished(ImageKnob* knob) override;
void imageKnobValueChanged(ImageKnob* knob, float value) override;

void 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
67 changes: 67 additions & 0 deletions distrho-prom.cpp
@@ -0,0 +1,67 @@
/*
* Carla Native Plugins
* Copyright (C) 2012-2017 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#include "CarlaJuceUtils.hpp"

// Plugin Code
#include "distrho-prom/DistrhoPluginProM.cpp"
#include "distrho-prom/DistrhoUIProM.cpp"

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

START_NAMESPACE_DISTRHO

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

static const NativePluginDescriptor promDesc = {
/* category */ NATIVE_PLUGIN_CATEGORY_UTILITY,
/* hints */ static_cast<NativePluginHints>(NATIVE_PLUGIN_IS_RTSAFE
|NATIVE_PLUGIN_HAS_UI
|NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD
|NATIVE_PLUGIN_USES_PARENT_ID),
/* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING,
/* audioIns */ DISTRHO_PLUGIN_NUM_INPUTS,
/* audioOuts */ DISTRHO_PLUGIN_NUM_OUTPUTS,
/* midiIns */ 0,
/* midiOuts */ 0,
/* paramIns */ 0,
/* paramOuts */ 0,
/* name */ DISTRHO_PLUGIN_NAME,
/* label */ "prom",
/* maker */ "falkTX",
/* copyright */ "LGPL",
PluginDescriptorFILL(PluginCarla)
};

END_NAMESPACE_DISTRHO

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

CARLA_EXPORT
void carla_register_native_plugin_distrho_prom();

CARLA_EXPORT
void carla_register_native_plugin_distrho_prom()
{
USE_NAMESPACE_DISTRHO
carla_register_native_plugin(&promDesc);
}

// -----------------------------------------------------------------------
33 changes: 33 additions & 0 deletions distrho-prom/DistrhoPluginInfo.h
@@ -0,0 +1,33 @@
/*
* DISTRHO ProM Plugin
* Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

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

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_NUM_INPUTS 1
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1

// required by projectM
#define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 1

#define DISTRHO_PLUGIN_LV2_CATEGORY "lv2:AnalyserPlugin"

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
84 changes: 84 additions & 0 deletions distrho-prom/DistrhoPluginProM.cpp
@@ -0,0 +1,84 @@
/*
* DISTRHO ProM Plugin
* Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#include "DistrhoPluginProM.hpp"

#include "libprojectM/projectM.hpp"

START_NAMESPACE_DISTRHO

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

DistrhoPluginProM::DistrhoPluginProM()
: Plugin(0, 0, 0),
fPM(nullptr)
{
}

DistrhoPluginProM::~DistrhoPluginProM()
{
DISTRHO_SAFE_ASSERT(fPM == nullptr);
}

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

void DistrhoPluginProM::initParameter(uint32_t, Parameter&)
{
}

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

float DistrhoPluginProM::getParameterValue(uint32_t) const
{
return 0.0f;
}

void DistrhoPluginProM::setParameterValue(uint32_t, float)
{
}

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

void DistrhoPluginProM::run(const float** inputs, float** outputs, uint32_t frames)
{
const float* in = inputs[0];
float* out = outputs[0];

if (out != in)
std::memcpy(out, in, sizeof(float)*frames);

const MutexLocker csm(fMutex);

if (fPM == nullptr)
return;

if (PCM* const pcm = const_cast<PCM*>(fPM->pcm()))
pcm->addPCMfloat(in, frames);
}

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

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

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

END_NAMESPACE_DISTRHO
106 changes: 106 additions & 0 deletions distrho-prom/DistrhoPluginProM.hpp
@@ -0,0 +1,106 @@
/*
* DISTRHO ProM Plugin
* Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/

#ifndef DISTRHO_PLUGIN_PROM_HPP_INCLUDED
#define DISTRHO_PLUGIN_PROM_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

#include "extra/Mutex.hpp"

class projectM;
class DistrhoUIProM;

START_NAMESPACE_DISTRHO

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

class DistrhoPluginProM : public Plugin
{
public:
DistrhoPluginProM();
~DistrhoPluginProM() override;

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

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

const char* getDescription() const override
{
return "ProjectM visualizer.";
}

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

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

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

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

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

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

void initParameter(uint32_t, Parameter&) override;

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

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

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

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

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

private:
Mutex fMutex;
projectM* fPM;
friend class DistrhoUIProM;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginProM)
};

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

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_PROM_HPP_INCLUDED