aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFilipe Coelho <falktx@falktx.com>2020-11-28 00:07:57 +0000
committerDavid Robillard <d@drobilla.net>2020-12-18 10:13:44 +0100
commitd6301787b3bc3192788bc428a75f4895111dc8bd (patch)
tree1346f808230070fac62fa55ee5ad6a9453d08538 /plugins
parent5621caa6f182389c100855266abd3deca3369165 (diff)
downloadlv2-d6301787b3bc3192788bc428a75f4895111dc8bd.tar.xz
eg-sampler: Save and restore gain parameter value
Diffstat (limited to 'plugins')
-rw-r--r--plugins/eg-sampler.lv2/sampler.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c
index d4d2aa9..b85bb38 100644
--- a/plugins/eg-sampler.lv2/sampler.c
+++ b/plugins/eg-sampler.lv2/sampler.c
@@ -78,6 +78,7 @@ typedef struct {
Sample* sample;
uint32_t frame_offset;
float gain;
+ float gain_dB;
sf_count_t frame;
bool play;
bool activated;
@@ -281,7 +282,8 @@ instantiate(const LV2_Descriptor* descriptor,
lv2_atom_forge_init(&self->forge, self->map);
peaks_sender_init(&self->psend, self->map);
- self->gain = 1.0f;
+ self->gain = 1.0f;
+ self->gain_dB = 0.0f;
return (LV2_Handle)self;
}
@@ -359,7 +361,8 @@ handle_event(Sampler* self, LV2_Atom_Event* ev)
} else if (key == uris->param_gain) {
// Gain change
if (value->type == uris->atom_Float) {
- self->gain = DB_CO(((LV2_Atom_Float*)value)->body);
+ self->gain_dB = ((LV2_Atom_Float*)value)->body;
+ self->gain = DB_CO(self->gain_dB);
}
}
} else if (obj->body.otype == uris->patch_Get && self->sample) {
@@ -495,6 +498,15 @@ save(LV2_Handle instance,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
free(apath);
+
+ // Store the gain value
+ store(handle,
+ self->uris.param_gain,
+ &self->gain_dB,
+ sizeof(self->gain_dB),
+ self->uris.atom_Float,
+ LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
+
return LV2_STATE_SUCCESS;
}
@@ -564,6 +576,20 @@ restore(LV2_Handle instance,
free(path);
+ // Get param:gain from state
+ value = retrieve(handle, self->uris.param_gain, &size, &type, &valflags);
+ if (!value) {
+ // Not an error, since older versions did not save this property
+ lv2_log_note(&self->logger, "Missing param:gain\n");
+ return LV2_STATE_SUCCESS;
+ } else if (type != self->uris.atom_Float) {
+ lv2_log_error(&self->logger, "Non-float param:gain\n");
+ return LV2_STATE_ERR_BAD_TYPE;
+ }
+
+ self->gain_dB = *(const float*)value;
+ self->gain = DB_CO(self->gain_dB);
+
return LV2_STATE_SUCCESS;
}