Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Aug 11, 2019
0 parents commit ca71453
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
*.a
*.d
*.o

*.exe
*.dll
*.dylib
*.so
*.zip

.kdev_include_paths
.kdev4/

bin/
build/
6 changes: 6 additions & 0 deletions .gitmodules
@@ -0,0 +1,6 @@
[submodule "stk"]
path = stk
url = git@github.com:DISTRHO/stk.git
[submodule "dpf"]
path = dpf
url = git@github.com:DISTRHO/DPF.git
13 changes: 13 additions & 0 deletions LICENSE
@@ -0,0 +1,13 @@
DISTRHO Plugin Framework (DPF)
Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>

Permission to use, copy, modify, and/or distribute this software for any purpose with
or without fee is hereby granted, provided that the above copyright notice and this
permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 changes: 38 additions & 0 deletions Makefile
@@ -0,0 +1,38 @@
#!/usr/bin/make -f
# Makefile for DPF STK Plugins #
# ---------------------------- #
# Created by falkTX
#

include dpf/Makefile.base.mk

all: plugins gen

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

plugins:
$(MAKE) all -C plugins/Flute

ifneq ($(CROSS_COMPILING),true)
gen: plugins dpf/utils/lv2_ttl_generator
@$(CURDIR)/dpf/utils/generate-ttl.sh
ifeq ($(MACOS),true)
@$(CURDIR)/dpf/utils/generate-vst-bundles.sh
endif

dpf/utils/lv2_ttl_generator:
$(MAKE) -C dpf/utils/lv2-ttl-generator
else
gen:
endif

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

clean:
$(MAKE) clean -C dpf/utils/lv2-ttl-generator
$(MAKE) clean -C plugins/Flute
rm -rf bin build

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

.PHONY: plugins
5 changes: 5 additions & 0 deletions README.md
@@ -0,0 +1,5 @@
# DPF STK Plugins

This is an attempt of building synth plugins with DPF and STK.
Work in progress.

1 change: 1 addition & 0 deletions dpf
Submodule dpf added at bbc188
30 changes: 30 additions & 0 deletions plugins/Flute/DistrhoPluginInfo.h
@@ -0,0 +1,30 @@
/*
* DPF STK Plugins
* Copyright (C) 2019 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "STK Flute"
#define DISTRHO_PLUGIN_URI "https://dpf.kx.studio/plugins/stk/Flute"

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

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

#ifndef DPF_STK_FLUTE_HPP_INCLUDED
#define DPF_STK_FLUTE_HPP_INCLUDED

#include "DistrhoPluginUtils.hpp"
#include "../../stk/include/Flute.h"
#include "../../stk/include/Voicer.h"
#include "../../stk/include/SKINImsg.h"

using stk::StkFloat;

START_NAMESPACE_DISTRHO

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

class StkFlute : public Plugin
{
public:
static const size_t kNumVoices = 6;

/*
Control Change Numbers:
- Jet Delay = 2
- Noise Gain = 4
- Vibrato Frequency = 11
- Vibrato Gain = 1
- Breath Pressure = 128
*/
enum Parameters
{
kParamJetDelay = 0,
kParamNoiseGain,
kParamVibratoFrequency,
kParamVibratoGain,
kParamBreathPressure,
kParamCount
};

StkFlute()
: Plugin(kParamCount, 0, 0), // 0 programs, 0 states
voicer(0.0)
{
for (size_t i=0; i<kParamCount; ++i)
params[i] = 0.0f;

for (size_t i=0; i<kNumVoices; ++i)
{
flute[i].setSampleRate(getSampleRate());
voicer.addInstrument(&flute[i]);
}
}

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

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

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

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

const char* getHomePage() const override
{
return DISTRHO_PLUGIN_URI;
}

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

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

int64_t getUniqueId() const noexcept override
{
return d_cconst('D', 'F', 'l', 't');
}

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

void initParameter(uint32_t index, Parameter& parameter) override
{
switch (index)
{
case kParamJetDelay:
parameter.hints = kParameterIsAutomable;
parameter.name = "Jet Delay";
parameter.symbol = "JetDelay";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
break;
case kParamNoiseGain:
parameter.hints = kParameterIsAutomable;
parameter.name = "Noise Gain";
parameter.symbol = "NoiseGain";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
break;
case kParamVibratoFrequency:
parameter.hints = kParameterIsAutomable;
parameter.name = "Vibrato Frequency";
parameter.symbol = "VibratoFrequency";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
break;
case kParamVibratoGain:
parameter.hints = kParameterIsAutomable;
parameter.name = "Vibrato Gain";
parameter.symbol = "VibratoGain";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
break;
case kParamBreathPressure:
parameter.hints = kParameterIsAutomable;
parameter.name = "Breath Pressure";
parameter.symbol = "BreathPressure";
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f;
break;
}
}

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

float getParameterValue(uint32_t index) const override
{
return params[index];
}

void setParameterValue(uint32_t index, float value) override
{
switch (index)
{
case kParamJetDelay:
instrumentControlChange(__SK_JetDelay_, value*128.0);
break;
case kParamNoiseGain:
instrumentControlChange(__SK_NoiseLevel_, value*128.0);
break;
case kParamVibratoFrequency:
instrumentControlChange(__SK_ModFrequency_, value*128.0);
break;
case kParamVibratoGain:
instrumentControlChange(__SK_ModWheel_, value*128.0);
break;
case kParamBreathPressure:
instrumentControlChange(__SK_AfterTouch_Cont_, value*128.0);
break;
}

params[index] = value;
}

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

void deactivate() override
{
for (size_t i=0; i<kNumVoices; ++i)
flute[i].clear();
}

void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override
{
StkFloat note, velo;
std::memset(outputs[0], 0, sizeof(float)*frames);

for (AudioMidiSyncHelper amsh(outputs, frames, midiEvents, midiEventCount); amsh.nextEvent();)
{
for (uint32_t i=0; i<amsh.midiEventCount; ++i)
{
if (amsh.midiEvents[i].size > MidiEvent::kDataSize)
continue;

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

switch (status)
{
case 0x90:
note = static_cast<StkFloat>(data[1]);
velo = static_cast<StkFloat>(data[2]);
if (velo > 0)
{
voicer.noteOn(note, velo);
break;
}
// fall through
case 0x80:
note = static_cast<StkFloat>(data[1]);
velo = static_cast<StkFloat>(data[2]);
voicer.noteOff(note, velo);
break;
}

// TODO pitchbend
// TODO all notes off
}

float* const out = amsh.outputs[0];

for (uint32_t i=0; i<amsh.frames; ++i)
out[i] = voicer.tick();
}
}

// -------------------------------------------------------------------
// ...

void sampleRateChanged(const double newSampleRate) override
{
for (size_t i=0; i<kNumVoices; ++i)
flute[i].setSampleRate(newSampleRate);
}

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

private:
float params[kParamCount];
stk::Flute flute[kNumVoices];
stk::Voicer voicer;

void instrumentControlChange(int number, StkFloat value)
{
for (size_t i=0; i<kNumVoices; ++i)
flute[i].controlChange(number, value);
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StkFlute)
};

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

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

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

END_NAMESPACE_DISTRHO

#endif // DPF_STK_FLUTE_HPP_INCLUDED

0 comments on commit ca71453

Please sign in to comment.