Skip to content

Commit ca71453

Browse files
author
falkTX
committed
Initial commit
0 parents  commit ca71453

File tree

11 files changed

+452
-0
lines changed

11 files changed

+452
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.a
2+
*.d
3+
*.o
4+
5+
*.exe
6+
*.dll
7+
*.dylib
8+
*.so
9+
*.zip
10+
11+
.kdev_include_paths
12+
.kdev4/
13+
14+
bin/
15+
build/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "stk"]
2+
path = stk
3+
url = git@github.com:DISTRHO/stk.git
4+
[submodule "dpf"]
5+
path = dpf
6+
url = git@github.com:DISTRHO/DPF.git

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DISTRHO Plugin Framework (DPF)
2+
Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
3+
4+
Permission to use, copy, modify, and/or distribute this software for any purpose with
5+
or without fee is hereby granted, provided that the above copyright notice and this
6+
permission notice appear in all copies.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
9+
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
10+
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
11+
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
12+
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/make -f
2+
# Makefile for DPF STK Plugins #
3+
# ---------------------------- #
4+
# Created by falkTX
5+
#
6+
7+
include dpf/Makefile.base.mk
8+
9+
all: plugins gen
10+
11+
# --------------------------------------------------------------
12+
13+
plugins:
14+
$(MAKE) all -C plugins/Flute
15+
16+
ifneq ($(CROSS_COMPILING),true)
17+
gen: plugins dpf/utils/lv2_ttl_generator
18+
@$(CURDIR)/dpf/utils/generate-ttl.sh
19+
ifeq ($(MACOS),true)
20+
@$(CURDIR)/dpf/utils/generate-vst-bundles.sh
21+
endif
22+
23+
dpf/utils/lv2_ttl_generator:
24+
$(MAKE) -C dpf/utils/lv2-ttl-generator
25+
else
26+
gen:
27+
endif
28+
29+
# --------------------------------------------------------------
30+
31+
clean:
32+
$(MAKE) clean -C dpf/utils/lv2-ttl-generator
33+
$(MAKE) clean -C plugins/Flute
34+
rm -rf bin build
35+
36+
# --------------------------------------------------------------
37+
38+
.PHONY: plugins

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# DPF STK Plugins
2+
3+
This is an attempt of building synth plugins with DPF and STK.
4+
Work in progress.
5+

dpf

Submodule dpf added at bbc188d

plugins/Flute/DistrhoPluginInfo.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* DPF STK Plugins
3+
* Copyright (C) 2019 Filipe Coelho <falktx@falktx.com>
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any purpose with
6+
* or without fee is hereby granted, provided that the above copyright notice and this
7+
* permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10+
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11+
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12+
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
18+
#define DISTRHO_PLUGIN_INFO_H_INCLUDED
19+
20+
#define DISTRHO_PLUGIN_BRAND "DISTRHO"
21+
#define DISTRHO_PLUGIN_NAME "STK Flute"
22+
#define DISTRHO_PLUGIN_URI "https://dpf.kx.studio/plugins/stk/Flute"
23+
24+
#define DISTRHO_PLUGIN_HAS_UI 0
25+
#define DISTRHO_PLUGIN_IS_RT_SAFE 0
26+
#define DISTRHO_PLUGIN_IS_SYNTH 1
27+
#define DISTRHO_PLUGIN_NUM_INPUTS 0
28+
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1
29+
30+
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED

plugins/Flute/Flute.cpp

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/*
2+
* DPF STK Plugins
3+
* Copyright (C) 2019 Filipe Coelho <falktx@falktx.com>
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any purpose with
6+
* or without fee is hereby granted, provided that the above copyright notice and this
7+
* permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10+
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11+
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12+
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef DPF_STK_FLUTE_HPP_INCLUDED
18+
#define DPF_STK_FLUTE_HPP_INCLUDED
19+
20+
#include "DistrhoPluginUtils.hpp"
21+
#include "../../stk/include/Flute.h"
22+
#include "../../stk/include/Voicer.h"
23+
#include "../../stk/include/SKINImsg.h"
24+
25+
using stk::StkFloat;
26+
27+
START_NAMESPACE_DISTRHO
28+
29+
// -----------------------------------------------------------------------
30+
31+
class StkFlute : public Plugin
32+
{
33+
public:
34+
static const size_t kNumVoices = 6;
35+
36+
/*
37+
Control Change Numbers:
38+
- Jet Delay = 2
39+
- Noise Gain = 4
40+
- Vibrato Frequency = 11
41+
- Vibrato Gain = 1
42+
- Breath Pressure = 128
43+
*/
44+
enum Parameters
45+
{
46+
kParamJetDelay = 0,
47+
kParamNoiseGain,
48+
kParamVibratoFrequency,
49+
kParamVibratoGain,
50+
kParamBreathPressure,
51+
kParamCount
52+
};
53+
54+
StkFlute()
55+
: Plugin(kParamCount, 0, 0), // 0 programs, 0 states
56+
voicer(0.0)
57+
{
58+
for (size_t i=0; i<kParamCount; ++i)
59+
params[i] = 0.0f;
60+
61+
for (size_t i=0; i<kNumVoices; ++i)
62+
{
63+
flute[i].setSampleRate(getSampleRate());
64+
voicer.addInstrument(&flute[i]);
65+
}
66+
}
67+
68+
protected:
69+
// -------------------------------------------------------------------
70+
// Information
71+
72+
const char* getLabel() const noexcept override
73+
{
74+
return "STK Flute";
75+
}
76+
77+
const char* getDescription() const override
78+
{
79+
return "...";
80+
}
81+
82+
const char* getMaker() const noexcept override
83+
{
84+
return "falkTX, STK";
85+
}
86+
87+
const char* getHomePage() const override
88+
{
89+
return DISTRHO_PLUGIN_URI;
90+
}
91+
92+
const char* getLicense() const noexcept override
93+
{
94+
return "ISC";
95+
}
96+
97+
uint32_t getVersion() const noexcept override
98+
{
99+
return d_version(1, 0, 0);
100+
}
101+
102+
int64_t getUniqueId() const noexcept override
103+
{
104+
return d_cconst('D', 'F', 'l', 't');
105+
}
106+
107+
// -------------------------------------------------------------------
108+
// Init
109+
110+
void initParameter(uint32_t index, Parameter& parameter) override
111+
{
112+
switch (index)
113+
{
114+
case kParamJetDelay:
115+
parameter.hints = kParameterIsAutomable;
116+
parameter.name = "Jet Delay";
117+
parameter.symbol = "JetDelay";
118+
parameter.ranges.def = 0.0f;
119+
parameter.ranges.min = 0.0f;
120+
parameter.ranges.max = 1.0f;
121+
break;
122+
case kParamNoiseGain:
123+
parameter.hints = kParameterIsAutomable;
124+
parameter.name = "Noise Gain";
125+
parameter.symbol = "NoiseGain";
126+
parameter.ranges.def = 0.0f;
127+
parameter.ranges.min = 0.0f;
128+
parameter.ranges.max = 1.0f;
129+
break;
130+
case kParamVibratoFrequency:
131+
parameter.hints = kParameterIsAutomable;
132+
parameter.name = "Vibrato Frequency";
133+
parameter.symbol = "VibratoFrequency";
134+
parameter.ranges.def = 0.0f;
135+
parameter.ranges.min = 0.0f;
136+
parameter.ranges.max = 1.0f;
137+
break;
138+
case kParamVibratoGain:
139+
parameter.hints = kParameterIsAutomable;
140+
parameter.name = "Vibrato Gain";
141+
parameter.symbol = "VibratoGain";
142+
parameter.ranges.def = 0.0f;
143+
parameter.ranges.min = 0.0f;
144+
parameter.ranges.max = 1.0f;
145+
break;
146+
case kParamBreathPressure:
147+
parameter.hints = kParameterIsAutomable;
148+
parameter.name = "Breath Pressure";
149+
parameter.symbol = "BreathPressure";
150+
parameter.ranges.def = 0.0f;
151+
parameter.ranges.min = 0.0f;
152+
parameter.ranges.max = 1.0f;
153+
break;
154+
}
155+
}
156+
157+
// -------------------------------------------------------------------
158+
// Internal data
159+
160+
float getParameterValue(uint32_t index) const override
161+
{
162+
return params[index];
163+
}
164+
165+
void setParameterValue(uint32_t index, float value) override
166+
{
167+
switch (index)
168+
{
169+
case kParamJetDelay:
170+
instrumentControlChange(__SK_JetDelay_, value*128.0);
171+
break;
172+
case kParamNoiseGain:
173+
instrumentControlChange(__SK_NoiseLevel_, value*128.0);
174+
break;
175+
case kParamVibratoFrequency:
176+
instrumentControlChange(__SK_ModFrequency_, value*128.0);
177+
break;
178+
case kParamVibratoGain:
179+
instrumentControlChange(__SK_ModWheel_, value*128.0);
180+
break;
181+
case kParamBreathPressure:
182+
instrumentControlChange(__SK_AfterTouch_Cont_, value*128.0);
183+
break;
184+
}
185+
186+
params[index] = value;
187+
}
188+
189+
// -------------------------------------------------------------------
190+
// Process
191+
192+
void deactivate() override
193+
{
194+
for (size_t i=0; i<kNumVoices; ++i)
195+
flute[i].clear();
196+
}
197+
198+
void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override
199+
{
200+
StkFloat note, velo;
201+
std::memset(outputs[0], 0, sizeof(float)*frames);
202+
203+
for (AudioMidiSyncHelper amsh(outputs, frames, midiEvents, midiEventCount); amsh.nextEvent();)
204+
{
205+
for (uint32_t i=0; i<amsh.midiEventCount; ++i)
206+
{
207+
if (amsh.midiEvents[i].size > MidiEvent::kDataSize)
208+
continue;
209+
210+
const uint8_t* data = amsh.midiEvents[i].data;
211+
const uint8_t status = data[0] & 0xF0;
212+
213+
switch (status)
214+
{
215+
case 0x90:
216+
note = static_cast<StkFloat>(data[1]);
217+
velo = static_cast<StkFloat>(data[2]);
218+
if (velo > 0)
219+
{
220+
voicer.noteOn(note, velo);
221+
break;
222+
}
223+
// fall through
224+
case 0x80:
225+
note = static_cast<StkFloat>(data[1]);
226+
velo = static_cast<StkFloat>(data[2]);
227+
voicer.noteOff(note, velo);
228+
break;
229+
}
230+
231+
// TODO pitchbend
232+
// TODO all notes off
233+
}
234+
235+
float* const out = amsh.outputs[0];
236+
237+
for (uint32_t i=0; i<amsh.frames; ++i)
238+
out[i] = voicer.tick();
239+
}
240+
}
241+
242+
// -------------------------------------------------------------------
243+
// ...
244+
245+
void sampleRateChanged(const double newSampleRate) override
246+
{
247+
for (size_t i=0; i<kNumVoices; ++i)
248+
flute[i].setSampleRate(newSampleRate);
249+
}
250+
251+
// -------------------------------------------------------------------
252+
253+
private:
254+
float params[kParamCount];
255+
stk::Flute flute[kNumVoices];
256+
stk::Voicer voicer;
257+
258+
void instrumentControlChange(int number, StkFloat value)
259+
{
260+
for (size_t i=0; i<kNumVoices; ++i)
261+
flute[i].controlChange(number, value);
262+
}
263+
264+
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StkFlute)
265+
};
266+
267+
// -----------------------------------------------------------------------
268+
269+
Plugin* createPlugin()
270+
{
271+
return new StkFlute();
272+
}
273+
274+
// -----------------------------------------------------------------------
275+
276+
END_NAMESPACE_DISTRHO
277+
278+
#endif // DPF_STK_FLUTE_HPP_INCLUDED

0 commit comments

Comments
 (0)