clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 8d874c91ed02b21b5db90b24cf481fb2c9da534e
parent 1947fc46686e1f22b5eee98cb748a65256330865
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Wed,  7 Jan 2015 09:54:27 +0100

thyns: finished to add parameters

Diffstat:
Mexamples/thyns/filt.h | 7++-----
Mexamples/thyns/params.h | 1+
Mexamples/thyns/plugin.c | 11+++++++++--
Mexamples/thyns/thyns.h | 4++--
Mexamples/thyns/voice.h | 95++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
5 files changed, 103 insertions(+), 15 deletions(-)

diff --git a/examples/thyns/filt.h b/examples/thyns/filt.h @@ -20,9 +20,6 @@ struct thyns_filt uint32_t sr; // sample rate double pi_sr; // M_PI / sample_rate - double cutoff; // in hz - double resonance; - double g; double g_div; @@ -82,8 +79,8 @@ thyns_filt_param_info(uint32_t index, static inline void thyns_filt_params_init(union clap_param_value *values) { - values[THYNS_FILT_PARAM_CUTOFF].f = 10000; - values[THYNS_FILT_PARAM_RESONANCE].f = 0.7; + values[THYNS_FILT_PARAM_CUTOFF].f = 4000; + values[THYNS_FILT_PARAM_RESONANCE].f = 1.5; } static inline void diff --git a/examples/thyns/params.h b/examples/thyns/params.h @@ -9,6 +9,7 @@ struct thyns_params union clap_param_value filt[THYNS_FILT_PARAM_COUNT]; union clap_param_value amp_env[THYNS_ENV_PARAM_COUNT]; union clap_param_value filt_env[THYNS_ENV_PARAM_COUNT]; + union clap_param_value voice[THYNS_VOICE_PARAM_COUNT]; }; static void diff --git a/examples/thyns/plugin.c b/examples/thyns/plugin.c @@ -127,14 +127,21 @@ thyns_params_get(struct clap_plugin *plugin, if (index < i + THYNS_ENV_PARAM_COUNT) { thyns_env_param_info(index - i, p->thyns.params.amp_env[index - i], - "amp_env:", param); + "amp-env:", param); return true; } i += THYNS_ENV_PARAM_COUNT; if (index < i + THYNS_ENV_PARAM_COUNT) { thyns_env_param_info(index - i, p->thyns.params.filt_env[index - i], - "filt_env:", param); + "filt-env:", param); + return true; + } + i += THYNS_ENV_PARAM_COUNT; + + if (index < i + THYNS_VOICE_PARAM_COUNT) { + thyns_env_param_info(index - i, p->thyns.params.voice[index - i], + "", param); return true; } i += THYNS_ENV_PARAM_COUNT; diff --git a/examples/thyns/thyns.h b/examples/thyns/thyns.h @@ -94,7 +94,7 @@ thyns_note_on(struct thyns *thyns, voice->key = key; } - thyns_voice_params_init(voice, &thyns->params); + thyns_voice_values_init(voice, &thyns->params); thyns_voice_start_note(thyns->keys[key], key, pitch); } @@ -127,7 +127,7 @@ thyns_handle_event(struct thyns *thyns, else if (thyns->keys[ev->param.key]) { struct thyns_voice *voice = thyns->keys[ev->param.key]; voice->params.values[ev->param.index] = ev->param.value; - thyns_voice_use_param(voice, &voice->params, ev->param.index); + thyns_voice_use_value(voice, &voice->params, ev->param.index); } break; diff --git a/examples/thyns/voice.h b/examples/thyns/voice.h @@ -4,6 +4,15 @@ # include "env.h" # include "filt.h" # include "osc.h" + +enum thyns_voice_param_index +{ + THYNS_VOICE_PARAM_OSC_MIX = 0, + THYNS_VOICE_PARAM_FILT_ENV_DEPTH, + THYNS_VOICE_PARAM_AMP, + THYNS_VOICE_PARAM_COUNT, +}; + # include "params.h" struct thyns_voice @@ -31,11 +40,78 @@ struct thyns_voice struct thyns_env amp_env; double amp; + union clap_param_value *values[THYNS_VOICE_PARAM_COUNT]; + // voice parameters struct thyns_params params; }; static inline void +thyns_voice_param_info(uint32_t index, + union clap_param_value value, + const char *prefix, + struct clap_param *param) +{ +#define P(Dst, Args...) snprintf(Dst, sizeof (Dst), Args); + + switch (index) { + case THYNS_VOICE_PARAM_OSC_MIX: + P(param->id, "%s%s", prefix, "osc-mix"); + P(param->name, "%s", "osc mix"); + P(param->desc, "%s", "Oscillators mixer"); + P(param->display, "%f", value.f); + param->type = CLAP_PARAM_FLOAT; + param->is_per_note = true; + param->is_used = true; + param->is_periodic = false; + param->value = value; + param->min.f = 0; + param->max.f = 1; + param->scale = CLAP_PARAM_LINEAR; + break; + + case THYNS_VOICE_PARAM_FILT_ENV_DEPTH: + P(param->id, "%s%s", prefix, "filt-env-depth"); + P(param->name, "%s", "filter env depth"); + P(param->desc, "%s", "Filter's envelop"); + P(param->display, "%f", value.f); + param->type = CLAP_PARAM_FLOAT; + param->is_per_note = true; + param->is_used = true; + param->is_periodic = false; + param->value = value; + param->min.f = -4; + param->max.f = 4; + param->scale = CLAP_PARAM_LINEAR; + break; + + case THYNS_VOICE_PARAM_AMP: + P(param->id, "%s%s", prefix, "amp"); + P(param->name, "%s", "output volume"); + P(param->desc, "%s", "Output volume"); + P(param->display, "%f", value.f); + param->type = CLAP_PARAM_FLOAT; + param->is_per_note = true; + param->is_used = true; + param->is_periodic = false; + param->value = value; + param->min.f = -1; + param->max.f = 1; + param->scale = CLAP_PARAM_LINEAR; + break; + } +#undef P +} + +static inline void +thyns_voice_params_init(union clap_param_value *values) +{ + values[THYNS_VOICE_PARAM_OSC_MIX].f = 0.5; + values[THYNS_VOICE_PARAM_FILT_ENV_DEPTH].f = 0.2; + values[THYNS_VOICE_PARAM_AMP].f = 0.2; +} + +static inline void thyns_voice_init(struct thyns_voice *voice, uint32_t sr) { voice->prev = NULL; @@ -51,18 +127,14 @@ thyns_voice_init(struct thyns_voice *voice, uint32_t sr) // filter thyns_filt_init(&voice->filt, sr); - voice->filt.cutoff = 4000; - voice->filt.resonance = 1.5; thyns_env_init(&voice->filt_env, sr); - voice->filt_env_depth = 0.2; // amp thyns_env_init(&voice->amp_env, sr); - voice->amp = 0.2; } static inline void -thyns_voice_params_init(struct thyns_voice *voice, +thyns_voice_values_init(struct thyns_voice *voice, struct thyns_params *params) { uint32_t off = 0; @@ -91,10 +163,15 @@ thyns_voice_params_init(struct thyns_voice *voice, for (int i = 0; i < THYNS_ENV_PARAM_COUNT; ++i) voice->filt_env.values[i] = params->values + off + i; off += THYNS_ENV_PARAM_COUNT; + + // voice + for (int i = 0; i < THYNS_VOICE_PARAM_COUNT; ++i) + voice->values[i] = params->values + off + i; + off += THYNS_VOICE_PARAM_COUNT; } static inline void -thyns_voice_use_param(struct thyns_voice *voice, +thyns_voice_use_value(struct thyns_voice *voice, struct thyns_params *params, uint32_t index) { @@ -129,6 +206,12 @@ thyns_voice_use_param(struct thyns_voice *voice, return; } i += THYNS_ENV_PARAM_COUNT; + + if (index < i + THYNS_VOICE_PARAM_COUNT) { + voice->values[index - i] = params->values + index; + return; + } + i += THYNS_ENV_PARAM_COUNT; } static inline void