diff options
-rw-r--r-- | lv2/core/meta.ttl | 9 | ||||
-rw-r--r-- | plugins/eg-sampler.lv2/sampler.c | 30 |
2 files changed, 37 insertions, 2 deletions
diff --git a/lv2/core/meta.ttl b/lv2/core/meta.ttl index 721fba8..20c72b4 100644 --- a/lv2/core/meta.ttl +++ b/lv2/core/meta.ttl @@ -38,6 +38,15 @@ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH R meta:kfoltman , meta:paniq ; doap:release [ + doap:revision "1.18.1" ; + doap:created "2020-12-18" ; + dcs:blame <http://drobilla.net/drobilla#me> ; + dcs:changeset [ + dcs:item [ + rdfs:label "eg-sample: Save and restore gain parameter value." + ] + ] + ] , [ doap:revision "1.18.0" ; doap:created "2020-04-26" ; doap:file-release <http://lv2plug.in/spec/lv2-1.18.0.tar.bz2> ; 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; } |