aboutsummaryrefslogtreecommitdiff
path: root/vm_ui.c
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-21 21:20:30 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-21 21:20:30 +0100
commite5530df06577e3bc454cb62371cc587dd68074a7 (patch)
treef7fa74f58b0fda55e1ffd32405dc8714c18d1971 /vm_ui.c
parentd0f3a9ac228f5798a045f75376817b43666939bd (diff)
downloadvm.lv2-e5530df06577e3bc454cb62371cc587dd68074a7.tar.xz
add OP_RAND, read param:sampleRate from options.
Diffstat (limited to 'vm_ui.c')
-rw-r--r--vm_ui.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/vm_ui.c b/vm_ui.c
index 8e36479..e392b6e 100644
--- a/vm_ui.c
+++ b/vm_ui.c
@@ -85,6 +85,8 @@ struct _plughandle_t {
plot_t inp [CTRL_MAX];
plot_t outp [CTRL_MAX];
+ float sample_rate;
+
command_t cmds [ITEMS_MAX];
};
@@ -430,6 +432,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
void *parent = NULL;
LV2UI_Resize *host_resize = NULL;
+ LV2_Options_Option *opts = NULL;
for(int i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_UI__parent))
@@ -442,6 +445,8 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
handle->unmap = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_LOG__log))
handle->log = features[i]->data;
+ else if(!strcmp(features[i]->URI, LV2_OPTIONS__options))
+ opts = features[i]->data;
}
if(!parent)
@@ -464,6 +469,20 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
lv2_atom_forge_init(&handle->forge, handle->map);
+ const LV2_URID param_sampleRate = handle->map->map(handle->map->handle, LV2_PARAMETERS__sampleRate);
+ if(opts)
+ {
+ for(LV2_Options_Option *opt = opts;
+ (opt->key != 0) && (opt->value != NULL);
+ opt++)
+ {
+ if( (opt->key == param_sampleRate) && (opt->type == handle->forge.Float) )
+ handle->sample_rate = *(const float *)opt->value;
+ }
+ }
+ if(!handle->sample_rate)
+ handle->sample_rate = 48000.f; // fall-back
+
vm_api_init(handle->api, handle->map);
if(!props_init(&handle->props, MAX_NPROPS, plugin_uri, handle->map, handle))
@@ -552,9 +571,8 @@ port_event(LV2UI_Handle instance, uint32_t index, uint32_t size,
const int64_t dt = off->body - handle->off;
handle->off = off->body;
- const float rate = 48000.f / dt; //FIXME
const unsigned ntimes = 4; //FIXME
- const unsigned window = ceilf(PLOT_MAX / rate / ntimes);
+ const unsigned window = ceilf(PLOT_MAX / handle->sample_rate / ntimes);
const unsigned remainder = PLOT_MAX - window;
float mem [PLOT_MAX];