19#include "DistrhoPluginNekobi.hpp"
34 if (pthread_mutex_trylock(&
synth->voicelist_mutex) != 0)
36 synth->voicelist_mutex_grab_failed = 1;
41 if (
synth->voicelist_mutex_grab_failed)
44 synth->voicelist_mutex_grab_failed = 0;
52 return (pthread_mutex_unlock(&
synth->voicelist_mutex) == 0);
63 switch (
data[0] & 0xf0)
88DistrhoPluginNekobi::DistrhoPluginNekobi()
96 fSynth.nugget_remains = 0;
103 fSynth.last_noteon_pitch = 0.0f;
104 fSynth.vcf_accent = 0.0f;
105 fSynth.vca_accent = 0.0f;
107 for (
int i=0;
i<8; ++
i)
108 fSynth.held_keys[
i] = -1;
111 fSynth.voicelist_mutex_grab_failed = 0;
112 pthread_mutex_init(&fSynth.voicelist_mutex,
nullptr);
114 fSynth.channel_pressure = 0;
115 fSynth.pitch_wheel_sensitivity = 0;
116 fSynth.pitch_wheel = 0;
118 for (
int i=0;
i<128; ++
i)
120 fSynth.key_pressure[
i] = 0;
125 fSynth.mod_wheel = 1.0f;
126 fSynth.pitch_bend = 1.0f;
127 fSynth.cc_volume = 1.0f;
130 fParams.waveform = 0.0f;
131 fParams.tuning = 0.0f;
132 fParams.cutoff = 25.0f;
133 fParams.resonance = 25.0f;
134 fParams.envMod = 50.0f;
135 fParams.decay = 75.0f;
136 fParams.accent = 25.0f;
137 fParams.volume = 75.0f;
140 fSynth.waveform = 0.0f;
141 fSynth.tuning = 1.0f;
142 fSynth.cutoff = 5.0f;
143 fSynth.resonance = 0.8f;
144 fSynth.envmod = 0.3f;
145 fSynth.decay = 0.0002f;
146 fSynth.accent = 0.3f;
147 fSynth.volume = 0.75f;
153DistrhoPluginNekobi::~DistrhoPluginNekobi()
155 std::free(fSynth.voice);
161void DistrhoPluginNekobi::initParameter(
uint32_t index, Parameter& parameter)
166 parameter.hints = kParameterIsAutomatable|kParameterIsInteger;
167 parameter.name =
"Waveform";
168 parameter.symbol =
"waveform";
169 parameter.ranges.def = 0.0f;
170 parameter.ranges.min = 0.0f;
171 parameter.ranges.max = 1.0f;
172 parameter.enumValues.count = 2;
173 parameter.enumValues.restrictedMode =
true;
174 parameter.midiCC = 70;
176 ParameterEnumerationValue*
const enumValues =
new ParameterEnumerationValue[2];
177 enumValues[0].value = 0.0f;
178 enumValues[0].label =
"Square";
179 enumValues[1].value = 1.0f;
180 enumValues[1].label =
"Triangle";
181 parameter.enumValues.values = enumValues;
185 parameter.hints = kParameterIsAutomatable;
186 parameter.name =
"Tuning";
187 parameter.symbol =
"tuning";
188 parameter.ranges.def = 0.0f;
189 parameter.ranges.min = -12.0f;
190 parameter.ranges.max = 12.0f;
191 parameter.midiCC = 75;
194 parameter.hints = kParameterIsAutomatable;
195 parameter.name =
"Cutoff";
196 parameter.symbol =
"cutoff";
197 parameter.unit =
"%";
198 parameter.ranges.def = 25.0f;
199 parameter.ranges.min = 0.0f;
200 parameter.ranges.max = 100.0f;
201 parameter.midiCC = 74;
204 parameter.hints = kParameterIsAutomatable;
205 parameter.name =
"VCF Resonance";
206 parameter.symbol =
"resonance";
207 parameter.unit =
"%";
208 parameter.ranges.def = 25.0f;
209 parameter.ranges.min = 0.0f;
210 parameter.ranges.max = 95.0f;
211 parameter.midiCC = 71;
214 parameter.hints = kParameterIsAutomatable;
215 parameter.name =
"Env Mod";
216 parameter.symbol =
"env_mod";
217 parameter.unit =
"%";
218 parameter.ranges.def = 50.0f;
219 parameter.ranges.min = 0.0f;
220 parameter.ranges.max = 100.0f;
221 parameter.midiCC = 1;
224 parameter.hints = kParameterIsAutomatable;
225 parameter.name =
"Decay";
226 parameter.symbol =
"decay";
227 parameter.unit =
"%";
228 parameter.ranges.def = 75.0f;
229 parameter.ranges.min = 0.0f;
230 parameter.ranges.max = 100.0f;
231 parameter.midiCC = 72;
234 parameter.hints = kParameterIsAutomatable;
235 parameter.name =
"Accent";
236 parameter.symbol =
"accent";
237 parameter.unit =
"%";
238 parameter.ranges.def = 25.0f;
239 parameter.ranges.min = 0.0f;
240 parameter.ranges.max = 100.0f;
241 parameter.midiCC = 76;
244 parameter.hints = kParameterIsAutomatable;
245 parameter.name =
"Volume";
246 parameter.symbol =
"volume";
247 parameter.unit =
"%";
248 parameter.ranges.def = 75.0f;
249 parameter.ranges.min = 0.0f;
250 parameter.ranges.max = 100.0f;
251 parameter.midiCC = 7;
259float DistrhoPluginNekobi::getParameterValue(
uint32_t index)
const
264 return fParams.waveform;
266 return fParams.tuning;
268 return fParams.cutoff;
270 return fParams.resonance;
272 return fParams.envMod;
274 return fParams.decay;
276 return fParams.accent;
278 return fParams.volume;
284void DistrhoPluginNekobi::setParameterValue(
uint32_t index,
float value)
289 fParams.waveform =
value;
290 fSynth.waveform =
value;
294 fParams.tuning =
value;
295 fSynth.tuning = (
value+12.0f)/24.0f * 1.5 + 0.5f;
299 fParams.cutoff =
value;
300 fSynth.cutoff =
value/2.5f;
304 fParams.resonance =
value;
305 fSynth.resonance =
value/100.0f;
309 fParams.envMod =
value;
310 fSynth.envmod =
value/100.0f;
314 fParams.decay =
value;
315 fSynth.decay =
value/100.0f * 0.000491f + 0.000009f;
319 fParams.accent =
value;
320 fSynth.accent =
value/100.0f;
324 fParams.volume =
value;
325 fSynth.volume =
value/100.0f;
334void DistrhoPluginNekobi::activate()
336 fSynth.nugget_remains = 0;
339 if (fSynth.voice !=
nullptr)
343void DistrhoPluginNekobi::deactivate()
345 if (fSynth.voice !=
nullptr)
349void DistrhoPluginNekobi::run(
const float**,
float** outputs,
uint32_t frames,
const MidiEvent* midiEvents,
uint32_t midiEventCount)
355 float*
out = outputs[0];
359 std::memset(
out, 0,
sizeof(
float)*frames);
363 while (framesDone < frames)
365 if (fSynth.nugget_remains == 0)
369 while (curEventIndex < midiEventCount && framesDone == midiEvents[curEventIndex].frame)
371 if (midiEvents[curEventIndex].
size > MidiEvent::kDataSize)
388 if (fSynth.nugget_remains < burstSize)
389 burstSize = fSynth.nugget_remains;
392 if (curEventIndex < midiEventCount && midiEvents[curEventIndex].frame - framesDone < burstSize)
393 burstSize = midiEvents[curEventIndex].frame - framesDone;
396 if (frames - framesDone < burstSize)
397 burstSize = frames - framesDone;
401 framesDone += burstSize;
402 fSynth.nugget_remains -= burstSize;
412 return new DistrhoPluginNekobi();
#define END_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:191
#define DISTRHO_SAFE_ASSERT(cond)
Definition DistrhoDefines.h:104
#define START_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:190
Plugin * createPlugin()
Definition DistrhoPluginNekobi.cpp:410
bool dssp_voicelist_mutex_trylock(nekobee_synth_t *const synth)
Definition DistrhoPluginNekobi.cpp:31
void nekobee_handle_raw_event(nekobee_synth_t *const synth, const uint8_t size, const uint8_t *const data)
Definition DistrhoPluginNekobi.cpp:58
bool dssp_voicelist_mutex_unlock(nekobee_synth_t *const synth)
Definition DistrhoPluginNekobi.cpp:50
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
static void deactivate(LV2_Handle instance)
Definition bindings_test_plugin.c:128
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate)=0
JSAMPIMAGE data
Definition jpeglib.h:945
float out
Definition lilv_test.c:1461
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
#define XSYNTH_DEFAULT_POLYPHONY
Definition nekobee.h:75
void nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key, unsigned char rvelocity)
Definition nekobee_synth.c:65
void nekobee_synth_control_change(nekobee_synth_t *synth, unsigned int param, signed int value)
Definition nekobee_synth.c:143
void nekobee_synth_render_voices(nekobee_synth_t *synth, float *out, unsigned long sample_count, int do_control_update)
Definition nekobee_synth.c:201
void nekobee_synth_all_voices_off(nekobee_synth_t *synth)
Definition nekobee_synth.c:44
void nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key, unsigned char velocity)
Definition nekobee_synth.c:112
#define XSYNTH_MONO_MODE_ONCE
Definition nekobee_synth.h:36
struct _nekobee_synth_t nekobee_synth_t
Definition nekobee_types.h:26
nekobee_voice_t * nekobee_voice_new()
Definition nekobee_voice.c:41
#define XSYNTH_NUGGET_SIZE
Definition nekobee_voice.h:34
void nekobee_init_tables(void)
Definition nekobee_voice_render.c:38