pass sample rate to state save/load
This commit is contained in:
parent
c81cc828aa
commit
f5c9ebab6a
@ -93,6 +93,7 @@ static float adjust_param(size_t index, float value) {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
plugin p;
|
plugin p;
|
||||||
|
float sample_rate;
|
||||||
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
|
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
|
||||||
const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
|
const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
|
||||||
#endif
|
#endif
|
||||||
@ -212,7 +213,8 @@ static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double s
|
|||||||
};
|
};
|
||||||
plugin_init(&instance->p, &cbs);
|
plugin_init(&instance->p, &cbs);
|
||||||
|
|
||||||
plugin_set_sample_rate(&instance->p, sample_rate);
|
instance->sample_rate = (float)sample_rate;
|
||||||
|
plugin_set_sample_rate(&instance->p, instance->sample_rate);
|
||||||
size_t req = plugin_mem_req(&instance->p);
|
size_t req = plugin_mem_req(&instance->p);
|
||||||
if (req != 0) {
|
if (req != 0) {
|
||||||
instance->mem = malloc(req);
|
instance->mem = malloc(req);
|
||||||
@ -451,7 +453,7 @@ static LV2_State_Status state_save(LV2_Handle instance, LV2_State_Store_Function
|
|||||||
/* .set_parameter = */ NULL
|
/* .set_parameter = */ NULL
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
return plugin_state_save(&i->p, &cbs) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
|
return plugin_state_save(&i->p, &cbs, i->sample_rate) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature * const * features) {
|
static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature * const * features) {
|
||||||
@ -479,7 +481,7 @@ static LV2_State_Status state_restore(LV2_Handle instance, LV2_State_Retrieve_Fu
|
|||||||
/* .set_parameter = */ state_set_parameter_cb
|
/* .set_parameter = */ state_set_parameter_cb
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
return plugin_state_load(&cbs, data, length) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
|
return plugin_state_load(&cbs, i->sample_rate, data, length) == 0 ? LV2_STATE_SUCCESS : LV2_STATE_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void * extension_data(const char * uri) {
|
static const void * extension_data(const char * uri) {
|
||||||
|
@ -271,7 +271,9 @@ typedef struct pluginInstance {
|
|||||||
Steinberg_uint32 refs;
|
Steinberg_uint32 refs;
|
||||||
Steinberg_FUnknown * context;
|
Steinberg_FUnknown * context;
|
||||||
plugin p;
|
plugin p;
|
||||||
float sampleRate;
|
float lastSampleRate;
|
||||||
|
float curSampleRate;
|
||||||
|
float nextSampleRate;
|
||||||
#if DATA_PRODUCT_PARAMETERS_IN_N > 0
|
#if DATA_PRODUCT_PARAMETERS_IN_N > 0
|
||||||
float parametersIn[DATA_PRODUCT_PARAMETERS_IN_N];
|
float parametersIn[DATA_PRODUCT_PARAMETERS_IN_N];
|
||||||
float parametersInSync[DATA_PRODUCT_PARAMETERS_IN_N];
|
float parametersInSync[DATA_PRODUCT_PARAMETERS_IN_N];
|
||||||
@ -412,6 +414,9 @@ static Steinberg_tresult pluginInitialize(void *thisInterface, struct Steinberg_
|
|||||||
if (p->context != NULL)
|
if (p->context != NULL)
|
||||||
return Steinberg_kResultFalse;
|
return Steinberg_kResultFalse;
|
||||||
p->context = context;
|
p->context = context;
|
||||||
|
p->lastSampleRate = 0.f;
|
||||||
|
p->curSampleRate = 0.f;
|
||||||
|
p->nextSampleRate = 0.f;
|
||||||
|
|
||||||
plugin_callbacks cbs = {
|
plugin_callbacks cbs = {
|
||||||
/* .handle = */ (void *)p,
|
/* .handle = */ (void *)p,
|
||||||
@ -628,7 +633,7 @@ static Steinberg_tresult pluginSetActive(void* thisInterface, Steinberg_TBool st
|
|||||||
p->neededBusesActive = 0;
|
p->neededBusesActive = 0;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
plugin_set_sample_rate(&p->p, p->sampleRate);
|
plugin_set_sample_rate(&p->p, p->nextSampleRate);
|
||||||
size_t req = plugin_mem_req(&p->p);
|
size_t req = plugin_mem_req(&p->p);
|
||||||
if (req != 0) {
|
if (req != 0) {
|
||||||
p->mem = malloc(req);
|
p->mem = malloc(req);
|
||||||
@ -636,8 +641,11 @@ static Steinberg_tresult pluginSetActive(void* thisInterface, Steinberg_TBool st
|
|||||||
return Steinberg_kOutOfMemory;
|
return Steinberg_kOutOfMemory;
|
||||||
plugin_mem_set(&p->p, p->mem);
|
plugin_mem_set(&p->p, p->mem);
|
||||||
}
|
}
|
||||||
|
p->curSampleRate = p->nextSampleRate;
|
||||||
|
p->lastSampleRate = p->nextSampleRate;
|
||||||
plugin_reset(&p->p);
|
plugin_reset(&p->p);
|
||||||
}
|
} else
|
||||||
|
p->curSampleRate = 0.f;
|
||||||
return Steinberg_kResultOk;
|
return Steinberg_kResultOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -667,7 +675,7 @@ static Steinberg_tresult pluginSetState(void* thisInterface, struct Steinberg_IB
|
|||||||
/* .set_parameter = */ pluginStateSetParameterCb
|
/* .set_parameter = */ pluginStateSetParameterCb
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
int err = plugin_state_load(&cbs, data, length);
|
int err = plugin_state_load(&cbs, p->curSampleRate, data, length);
|
||||||
#else
|
#else
|
||||||
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
|
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@ -723,7 +731,7 @@ static Steinberg_tresult pluginGetState(void* thisInterface, struct Steinberg_IB
|
|||||||
/* .set_parameter = */ NULL
|
/* .set_parameter = */ NULL
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
int err = plugin_state_save(&p->p, &cbs);
|
int err = plugin_state_save(&p->p, &cbs, p->lastSampleRate);
|
||||||
#else
|
#else
|
||||||
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
|
// we need to provide a default implementation because of certain hosts (e.g. Ardour)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
@ -855,7 +863,7 @@ static Steinberg_uint32 pluginGetLatencySamples(void* thisInterface) {
|
|||||||
static Steinberg_tresult pluginSetupProcessing(void* thisInterface, struct Steinberg_Vst_ProcessSetup* setup) {
|
static Steinberg_tresult pluginSetupProcessing(void* thisInterface, struct Steinberg_Vst_ProcessSetup* setup) {
|
||||||
TRACE("plugin IAudioProcessor setup processing\n");
|
TRACE("plugin IAudioProcessor setup processing\n");
|
||||||
pluginInstance *p = (pluginInstance *)((char *)thisInterface - offsetof(pluginInstance, vtblIAudioProcessor));
|
pluginInstance *p = (pluginInstance *)((char *)thisInterface - offsetof(pluginInstance, vtblIAudioProcessor));
|
||||||
p->sampleRate = (float)setup->sampleRate;
|
p->nextSampleRate = (float)setup->sampleRate;
|
||||||
return Steinberg_kResultOk;
|
return Steinberg_kResultOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1858,7 +1866,7 @@ static Steinberg_tresult controllerSetComponentState(void* thisInterface, struct
|
|||||||
/* .set_parameter = */ controllerStateSetParameterCb
|
/* .set_parameter = */ controllerStateSetParameterCb
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
int err = plugin_state_load(&cbs, data, length);
|
int err = plugin_state_load(&cbs, -1.f, data, length); // -1.f means "does not apply"
|
||||||
#else
|
#else
|
||||||
// we need to provide a default implementation because of certain hosts (e.g. Reaper)
|
// we need to provide a default implementation because of certain hosts (e.g. Reaper)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -138,7 +138,8 @@ static float parse_float(const uint8_t *data) {
|
|||||||
return v.f;
|
return v.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int plugin_state_save(plugin *instance, const plugin_state_callbacks *cbs) {
|
static int plugin_state_save(plugin *instance, const plugin_state_callbacks *cbs, float last_sample_rate) {
|
||||||
|
(void)last_sample_rate;
|
||||||
uint8_t data[13];
|
uint8_t data[13];
|
||||||
cbs->lock(cbs->handle);
|
cbs->lock(cbs->handle);
|
||||||
const float gain = instance->gain;
|
const float gain = instance->gain;
|
||||||
@ -159,7 +160,8 @@ static char x_isnan(float x) {
|
|||||||
return ((v.u & 0x7f800000) == 0x7f800000) && (v.u & 0x7fffff);
|
return ((v.u & 0x7f800000) == 0x7f800000) && (v.u & 0x7fffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int plugin_state_load(const plugin_state_callbacks *cbs, const char *data, size_t length) {
|
static int plugin_state_load(const plugin_state_callbacks *cbs, float cur_sample_rate, const char *data, size_t length) {
|
||||||
|
(void)cur_sample_rate;
|
||||||
if (length != 13)
|
if (length != 13)
|
||||||
return -1;
|
return -1;
|
||||||
const uint8_t *d = (const uint8_t *)data;
|
const uint8_t *d = (const uint8_t *)data;
|
||||||
|
Loading…
Reference in New Issue
Block a user