diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-21 21:20:30 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-21 21:20:30 +0100 |
commit | e5530df06577e3bc454cb62371cc587dd68074a7 (patch) | |
tree | f7fa74f58b0fda55e1ffd32405dc8714c18d1971 | |
parent | d0f3a9ac228f5798a045f75376817b43666939bd (diff) | |
download | vm.lv2-e5530df06577e3bc454cb62371cc587dd68074a7.tar.xz |
add OP_RAND, read param:sampleRate from options.
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | vm.c | 11 | ||||
-rw-r--r-- | vm.h | 21 | ||||
-rw-r--r-- | vm.ttl | 2 | ||||
-rw-r--r-- | vm_ui.c | 22 |
5 files changed, 47 insertions, 11 deletions
@@ -1 +1 @@ -0.1.2847 +0.1.2849 @@ -67,7 +67,7 @@ struct _plughandle_t { vm_stack_t stack; bool needs_recalc; bool needs_sync; - bool uses_time; + bool is_dynamic; int64_t off; @@ -134,7 +134,7 @@ _intercept_graph(void *data, LV2_Atom_Forge *forge, int64_t frames, handle->graph_size = impl->value.size; handle->needs_recalc = true; - handle->uses_time = vm_deserialize(handle->api, &handle->forge, handle->cmds, + handle->is_dynamic = vm_deserialize(handle->api, &handle->forge, handle->cmds, impl->value.size, impl->value.body); handle->needs_sync = true; @@ -157,7 +157,7 @@ _cb(timely_t *timely, int64_t frames, LV2_URID type, void *data) { plughandle_t *handle = data; - if(handle->uses_time) + if(handle->is_dynamic) handle->needs_recalc = true; } @@ -583,6 +583,11 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = handle->stack.regs[idx & REG_MASK]; _stack_push(&handle->stack, c); } break; + case OP_RAND: + { + const num_t c = (num_t)rand() / RAND_MAX; + _stack_push(&handle->stack, c); + } break; // time case OP_BAR_BEAT: @@ -27,6 +27,8 @@ #include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "lv2/lv2plug.in/ns/ext/state/state.h" #include "lv2/lv2plug.in/ns/ext/time/time.h" +#include "lv2/lv2plug.in/ns/ext/options/options.h" +#include "lv2/lv2plug.in/ns/ext/parameters/parameters.h" #include "lv2/lv2plug.in/ns/extensions/ui/ui.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" @@ -106,6 +108,7 @@ enum _opcode_enum_t{ OP_TER, OP_STORE, OP_LOAD, + OP_RAND, OP_BAR_BEAT, OP_BAR, OP_BEAT, @@ -418,6 +421,13 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, + [OP_RAND] = { + .uri = VM_PREFIX"opRand", + .label = "Random number", + .mnemo = "rand", + .npops = 0, + .npushs = 1 + }, [OP_BAR_BEAT] = { .uri = LV2_TIME__barBeat, .label = "time:barBeat", @@ -579,7 +589,7 @@ vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, command_t *cmd = cmds; memset(cmds, 0x0, sizeof(command_t)*ITEMS_MAX); - bool uses_time = false; + bool is_dynamic = false; LV2_ATOM_TUPLE_BODY_FOREACH(body, size, item) { @@ -622,10 +632,11 @@ vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, || (cmd->op == OP_BPB) || (cmd->op == OP_BPM) || (cmd->op == OP_FRAME) - || (cmd->op == OP_FPS) - || (cmd->op == OP_SPEED) ) + //|| (cmd->op == OP_FPS) // is constant + || (cmd->op == OP_SPEED) + || (cmd->op == OP_RAND) ) { - uses_time = true; + is_dynamic = true; } } else @@ -639,7 +650,7 @@ vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, break; } - return uses_time; + return is_dynamic; } #endif // _VM_LV2_H @@ -128,6 +128,8 @@ vm:opStore a rdfs:Datatype ; rdfs:label "Store in register" . vm:opLoad a rdfs:Datatype ; rdfs:label "Load from register" . +vm:opRand + a rdfs:Datatype ; rdfs:label "Random" . # Plugin vm:vm @@ -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]; |