diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-21 13:25:21 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-21 13:25:21 +0100 |
commit | fb5967921e71ddd7ac122f752de3bfd07a1adb60 (patch) | |
tree | 0e2fae0a50bfbfbd4f94f4a480873f76428210ac | |
parent | c9fc6ad4456d8696ab57fae18e48e3e149612479 (diff) | |
download | vm.lv2-fb5967921e71ddd7ac122f752de3bfd07a1adb60.tar.xz |
clean up header.
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | vm.c | 75 | ||||
-rw-r--r-- | vm.h | 500 | ||||
-rw-r--r-- | vm.ttl | 138 | ||||
-rw-r--r-- | vm_ui.c | 83 |
5 files changed, 532 insertions, 266 deletions
@@ -1 +1 @@ -0.1.2811 +0.1.2813 @@ -62,7 +62,7 @@ struct _plughandle_t { plugstate_t stash; uint32_t graph_size; - opcode_t opcode; + vm_api_impl_t api [OP_MAX]; vm_stack_t stack; bool recalc; @@ -133,7 +133,7 @@ _intercept_graph(void *data, LV2_Atom_Forge *forge, int64_t frames, handle->graph_size = impl->value.size; handle->recalc = true; - handle->is_dynamic = vm_deserialize(&handle->opcode, &handle->forge, handle->cmds, + handle->is_dynamic = vm_deserialize(handle->api, &handle->forge, handle->cmds, impl->value.size, impl->value.body); handle->sync = true; @@ -180,7 +180,7 @@ instantiate(const LV2_Descriptor* descriptor, num_t rate, handle->vm_graph = handle->map->map(handle->map->handle, VM__graph); lv2_atom_forge_init(&handle->forge, handle->map); - vm_opcode_init(&handle->opcode, handle->map); + vm_api_init(handle->api, handle->map); if(!props_init(&handle->props, MAX_NPROPS, descriptor->URI, handle->map, handle)) { @@ -435,16 +435,6 @@ run(LV2_Handle instance, uint32_t nsamples) _stack_pop_num(&handle->stack, ab, 2); _stack_push_num(&handle->stack, ab, 2); } break; - case OP_FRAME: - { - num_t c = handle->frame; - _stack_push(&handle->stack, c); - } break; - case OP_SRATE: - { - num_t c = handle->srate; - _stack_push(&handle->stack, c); - } break; case OP_PI: { num_t c = M_PI; @@ -529,6 +519,24 @@ run(LV2_Handle instance, uint32_t nsamples) const unsigned c = ~a; _stack_push(&handle->stack, c); } break; + case OP_LSHIFT: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + const unsigned a = ab[1]; + const unsigned b = ab[0]; + const unsigned c = a << b; + _stack_push(&handle->stack, c); + } break; + case OP_RSHIFT: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + const unsigned a = ab[1]; + const unsigned b = ab[0]; + const unsigned c = a >> b; + _stack_push(&handle->stack, c); + } break; case OP_TER: { num_t ab [3]; @@ -550,6 +558,47 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = handle->stack.regs[idx & REG_MASK]; _stack_push(&handle->stack, c); } break; + + // time + case OP_BAR_BEAT: + { + //TODO + } break; + case OP_BAR: + { + //TODO + } break; + case OP_BEAT: + { + //TODO + } break; + case OP_BEAT_UNIT: + { + //TODO + } break; + case OP_BPB: + { + //TODO + } break; + case OP_BPM: + { + //TODO + } break; + case OP_FRAME: + { + num_t c = handle->frame; //FIXME use time:frame + _stack_push(&handle->stack, c); + } break; + case OP_FPS: + { + num_t c = handle->srate; //FIXME use time:framesPerSecond + _stack_push(&handle->stack, c); + } break; + case OP_SPEED: + { + //TODO + } break; + case OP_NOP: { terminate = true; @@ -26,54 +26,19 @@ #include "lv2/lv2plug.in/ns/ext/time/time.h" #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/extensions/ui/ui.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" -#define VM_URI "http://open-music-kontrollers.ch/lv2/vm" -#define VM_PREFIX VM_URI"#" - -#define VM__vm VM_PREFIX"vm" -#define VM__vm_ui VM_PREFIX"vm_ui" - -#define VM__graph VM_PREFIX"graph" - -#define VM__opNop VM_PREFIX"opNop" -#define VM__opControl VM_PREFIX"opControl" -#define VM__opPush VM_PREFIX"opPush" -#define VM__opAdd VM_PREFIX"opAdd" -#define VM__opSub VM_PREFIX"opSub" -#define VM__opMul VM_PREFIX"opMul" -#define VM__opDiv VM_PREFIX"opDiv" -#define VM__opNeg VM_PREFIX"opNeg" -#define VM__opAbs VM_PREFIX"opAbs" -#define VM__opPow VM_PREFIX"opPow" -#define VM__opSqrt VM_PREFIX"opSqrt" -#define VM__opMod VM_PREFIX"opMod" -#define VM__opExp VM_PREFIX"opExp" -#define VM__opExp2 VM_PREFIX"opExp2" -#define VM__opLog VM_PREFIX"opLog" -#define VM__opLog2 VM_PREFIX"opLog2" -#define VM__opLog10 VM_PREFIX"opLog10" -#define VM__opSin VM_PREFIX"opSin" -#define VM__opCos VM_PREFIX"opCos" -#define VM__opSwap VM_PREFIX"opSwap" -#define VM__opFrame VM_PREFIX"opFrame" -#define VM__opSampleRate VM_PREFIX"opSampleRate" -#define VM__opPi VM_PREFIX"opPi" -#define VM__opEq VM_PREFIX"opEq" -#define VM__opLt VM_PREFIX"opLt" -#define VM__opGt VM_PREFIX"opGt" -#define VM__opLe VM_PREFIX"opLe" -#define VM__opGe VM_PREFIX"opGe" -#define VM__opAnd VM_PREFIX"opAnd" -#define VM__opOr VM_PREFIX"opOr" -#define VM__opNot VM_PREFIX"opNot" -#define VM__opBAnd VM_PREFIX"opBAnd" -#define VM__opBOr VM_PREFIX"opBOr" -#define VM__opBNot VM_PREFIX"opBNot" -#define VM__opTernary VM_PREFIX"opTernary" -#define VM__opStore VM_PREFIX"opStore" -#define VM__opLoad VM_PREFIX"opLoad" +#include <timely.lv2/timely.h> + +#define VM_URI "http://open-music-kontrollers.ch/lv2/vm" +#define VM_PREFIX VM_URI"#" + +#define VM__vm VM_PREFIX"vm" +#define VM__vm_ui VM_PREFIX"vm_ui" + +#define VM__graph VM_PREFIX"graph" #define MAX_NPROPS 1 #define CTRL_MAX 0x8 @@ -85,9 +50,22 @@ typedef enum _opcode_enum_t opcode_enum_t; typedef enum _command_enum_t command_enum_t; -typedef struct _opcode_t opcode_t; typedef struct _command_t command_t; typedef struct _plugstate_t plugstate_t; +typedef struct _vm_api_def_t vm_api_def_t; +typedef struct _vm_api_impl_t vm_api_impl_t; + +struct _vm_api_def_t { + const char *uri; + const char *mnemo; + const char *label; + unsigned npops; + unsigned npushs; +}; + +struct _vm_api_impl_t { + LV2_URID urid; +}; enum _opcode_enum_t{ OP_NOP = 0, @@ -111,8 +89,6 @@ enum _opcode_enum_t{ OP_SIN, OP_COS, OP_SWAP, - OP_FRAME, - OP_SRATE, OP_PI, OP_EQ, OP_LT, @@ -125,9 +101,20 @@ enum _opcode_enum_t{ OP_BAND, OP_BOR, OP_BNOT, + OP_LSHIFT, + OP_RSHIFT, OP_TER, OP_STORE, OP_LOAD, + OP_BAR_BEAT, + OP_BAR, + OP_BEAT, + OP_BEAT_UNIT, + OP_BPB, + OP_BPM, + OP_FRAME, + OP_FPS, + OP_SPEED, OP_MAX, }; @@ -145,10 +132,6 @@ enum _command_enum_t { COMMAND_MAX, }; -struct _opcode_t { - LV2_URID op [OP_MAX]; -}; - struct _command_t { command_enum_t type; @@ -165,73 +148,370 @@ struct _plugstate_t { uint8_t graph [GRAPH_SIZE]; }; -static const char *opcode_uris [OP_MAX] = { - [OP_NOP] = VM__opNop, - [OP_CTRL] = VM__opControl, - [OP_PUSH] = VM__opPush, - [OP_ADD] = VM__opAdd, - [OP_SUB] = VM__opSub, - [OP_MUL] = VM__opMul, - [OP_DIV] = VM__opDiv, - [OP_NEG] = VM__opNeg, - [OP_ABS] = VM__opAbs, - [OP_POW] = VM__opPow, - [OP_SQRT] = VM__opSqrt, - [OP_MOD] = VM__opMod, - [OP_EXP] = VM__opExp, - [OP_EXP_2] = VM__opExp2, - [OP_LOG] = VM__opLog, - [OP_LOG_2] = VM__opLog2, - [OP_LOG_10] = VM__opLog10, - [OP_SIN] = VM__opSin, - [OP_COS] = VM__opCos, - [OP_SWAP] = VM__opSwap, - [OP_FRAME] = VM__opFrame, - [OP_SRATE] = VM__opSampleRate, - [OP_PI] = VM__opPi, - [OP_EQ] = VM__opEq, - [OP_LT] = VM__opLt, - [OP_GT] = VM__opGt, - [OP_LE] = VM__opLe, - [OP_GE] = VM__opGe, - [OP_AND] = VM__opAnd, - [OP_OR] = VM__opOr, - [OP_NOT] = VM__opNot, - [OP_BAND] = VM__opBAnd, - [OP_BOR] = VM__opBOr, - [OP_BNOT] = VM__opBNot, - [OP_TER] = VM__opTernary, - [OP_STORE] = VM__opStore, - [OP_LOAD] = VM__opLoad, +static const char *command_labels [COMMAND_MAX] = { + [COMMAND_NOP] = "", + [COMMAND_OPCODE] = "Op Code" , + [COMMAND_BOOL] = "Boolean" , + [COMMAND_INT] = "Integer" , + [COMMAND_LONG] = "Long" , + [COMMAND_FLOAT] = "Float" , + [COMMAND_DOUBLE] = "Double" +}; + +static const vm_api_def_t vm_api_def [OP_MAX] = { + [OP_NOP] = { + .uri = VM_PREFIX"opNop", + .label = "", + .mnemo = NULL, + .npops = 0, + .npushs = 0 + }, + [OP_CTRL] = { + .uri = VM_PREFIX"opInput", + .label = "input", + .mnemo = NULL, + .npops = 1, + .npushs = 1 + }, + [OP_PUSH] = { + .uri = VM_PREFIX"opPush", + .label = "Push top", + .mnemo = "push", + .npops = 1, + .npushs = 2 + }, + [OP_ADD] = { + .uri = VM_PREFIX"opAdd", + .label = "Add", + .mnemo = "+", + .npops = 2, + .npushs = 1 + }, + [OP_SUB] = { + .uri = VM_PREFIX"opSub", + .label = "Subtract", + .mnemo = "-", + .npops = 2, + .npushs = 1 + }, + [OP_MUL] = { + .uri = VM_PREFIX"opMul", + .label = "Multiply", + .mnemo = "*", + .npops = 2, + .npushs = 1 + }, + [OP_DIV] = { + .uri = VM_PREFIX"opDiv", + .label = "Divide", + .mnemo = "/", + .npops = 2, + .npushs = 1 + }, + [OP_NEG] = { + .uri = VM_PREFIX"opNeg", + .label = "Negate", + .mnemo = "neg", + .npops = 1, + .npushs = 1 + }, + [OP_ABS] = { + .uri = VM_PREFIX"opAbs", + .label = "Absolute", + .mnemo = "abs", + .npops = 1, + .npushs = 1 + }, + [OP_POW] = { + .uri = VM_PREFIX"opPow", + .label = "Power", + .mnemo = "^", + .npops = 2, + .npushs = 1 + }, + [OP_SQRT] = { + .uri = VM_PREFIX"opSqrt", + .label = "Square root", + .mnemo = "sqrt", + .npops = 1, + .npushs = 1 + }, + [OP_MOD] = { + .uri = VM_PREFIX"opMod", + .label = "Modulo", + .mnemo = "%", + .npops = 2, + .npushs = 1 + }, + [OP_EXP] = { + .uri = VM_PREFIX"opExp", + .label = "Exponential", + .mnemo = "exp", + .npops = 1, + .npushs = 1 + }, + [OP_EXP_2] = { + .uri = VM_PREFIX"opExp2", + .label = "Exponential base 2", + .mnemo = "exp2", + .npops = 1, + .npushs = 1 + }, + [OP_LOG] = { + .uri = VM_PREFIX"opLog", + .label = "Logarithm", + .mnemo = "log", + .npops = 1, + .npushs = 1 + }, + [OP_LOG_2] = { + .uri = VM_PREFIX"opLog2", + .label = "Logarithm base 2", + .mnemo = "log2", + .npops = 1, + .npushs = 1 + }, + [OP_LOG_10] = { + .uri = VM_PREFIX"opLog10", + .label = "Logarithm base 10", + .mnemo = "log10", + .npops = 1, + .npushs = 1 + }, + [OP_SIN] = { + .uri = VM_PREFIX"opSin", + .label = "Sinus", + .mnemo = "sin", + .npops = 1, + .npushs = 1 + }, + [OP_COS] = { + .uri = VM_PREFIX"opCos", + .label = "Cosinus", + .mnemo = "cos", + .npops = 1, + .npushs = 1 + }, + [OP_SWAP] = { + .uri = VM_PREFIX"opSwap", + .label = "Swap", + .mnemo = "swap", + .npops = 2, + .npushs = 2 + }, + [OP_PI] = { + .uri = VM_PREFIX"opPi", + .label = "Pi", + .mnemo = "pi", + .npops = 0, + .npushs = 1 + }, + [OP_EQ] = { + .uri = VM_PREFIX"opEq", + .label = "Equal", + .mnemo = "==", + .npops = 2, + .npushs = 1 + }, + [OP_LT] = { + .uri = VM_PREFIX"opLt", + .label = "Less than", + .mnemo = "<", + .npops = 2, + .npushs = 1 + }, + [OP_GT] = { + .uri = VM_PREFIX"opGt", + .label = "Greater than", + .mnemo = ">", + .npops = 2, + .npushs = 1 + }, + [OP_LE] = { + .uri = VM_PREFIX"opLe", + .label = "Less or equal", + .mnemo = "<=", + .npops = 2, + .npushs = 1 + }, + [OP_GE] = { + .uri = VM_PREFIX"opGe", + .label = "Greater or equal", + .mnemo = ">=", + .npops = 2, + .npushs = 1 + }, + [OP_AND] = { + .uri = VM_PREFIX"opAnd", + .label = "And", + .mnemo = "&&", + .npops = 2, + .npushs = 1 + }, + [OP_OR] = { + .uri = VM_PREFIX"opOr", + .label = "Or", + .mnemo = "||", + .npops = 2, + .npushs = 1 + }, + [OP_NOT] = { + .uri = VM_PREFIX"opNot", + .label = "Not", + .mnemo = "!", + .npops = 1, + .npushs = 1 + }, + [OP_BAND] = { + .uri = VM_PREFIX"opBAnd", + .label = "Bitwise and", + .mnemo = "&", + .npops = 2, + .npushs = 1 + }, + [OP_BOR] = { + .uri = VM_PREFIX"opBOr", + .label = "Bitwise or", + .mnemo = "|", + .npops = 2, + .npushs = 1 + }, + [OP_BNOT] = { + .uri = VM_PREFIX"opBNot", + .label = "Bitwise not", + .mnemo = "~", + .npops = 1, + .npushs = 1 + }, + [OP_LSHIFT] = { + .uri = VM_PREFIX"opLShift", + .label = "Left shift", + .mnemo = "<<", + .npops = 2, + .npushs = 1 + }, + [OP_RSHIFT] = { + .uri = VM_PREFIX"opRShift", + .label = "Right shift", + .mnemo = ">>", + .npops = 2, + .npushs = 1 + }, + [OP_TER] = { + .uri = VM_PREFIX"opTernary", + .label = "Ternary operator", + .mnemo = "?", + .npops = 3, + .npushs = 1 + }, + [OP_STORE] = { + .uri = VM_PREFIX"opStore", + .label = "Store in register", + .mnemo = "store", + .npops = 2, + .npushs = 0 + }, + [OP_LOAD] = { + .uri = VM_PREFIX"opLoad", + .label = "Load from register", + .mnemo = "load", + .npops = 1, + .npushs = 1 + }, + [OP_BAR_BEAT] = { + .uri = LV2_TIME__barBeat, + .label = "time:barBeat", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_BAR] = { + .uri = LV2_TIME__bar, + .label = "time:bar", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_BEAT] = { + .uri = LV2_TIME__beat, + .label = "time:beat", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_BEAT_UNIT] = { + .uri = LV2_TIME__beatUnit, + .label = "time:beatUnit", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_BPB] = { + .uri = LV2_TIME__beatsPerBar, + .label = "time:beatsPerBar", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_BPM] = { + .uri = LV2_TIME__beatsPerMinute, + .label = "time:beatsPerMinute", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_FRAME] = { + .uri = LV2_TIME__frame, + .label = "time:frame", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_FPS] = { + .uri = LV2_TIME__framesPerSecond, + .label = "time:framesPerSecond", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, + [OP_SPEED] = { + .uri = LV2_TIME__speed, + .label = "time:speed", + .mnemo = NULL, + .npops = 0, + .npushs = 1 + }, }; static inline void -vm_opcode_init(opcode_t *opcode, LV2_URID_Map *map) +vm_api_init(vm_api_impl_t *impl, LV2_URID_Map *map) { - for(unsigned i = 0; i < OP_MAX; i++) - opcode->op[i] = map->map(map->handle, opcode_uris[i]); + for(unsigned op = 0; op < OP_MAX; op++) + { + impl[op].urid = map->map(map->handle, vm_api_def[op].uri); + } } static inline opcode_enum_t -vm_opcode_unmap(opcode_t *opcode, LV2_URID otype) +vm_api_unmap(vm_api_impl_t *impl, LV2_URID urid) { - for(unsigned i = 0; i < OP_MAX; i++) + for(unsigned op = 0; op < OP_MAX; op++) { - if(otype == opcode->op[i]) - return i; + if(impl[op].urid == urid) + return op; } return OP_NOP; } static inline LV2_URID -vm_opcode_map(opcode_t *opcode, opcode_enum_t op) +vm_api_map(vm_api_impl_t *impl, opcode_enum_t op) { - return opcode->op[op]; + return impl[op].urid; } static inline LV2_Atom_Forge_Ref -vm_serialize(opcode_t *opcode, LV2_Atom_Forge *forge, const command_t *cmds) +vm_serialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, const command_t *cmds) { LV2_Atom_Forge_Frame frame; LV2_Atom_Forge_Ref ref = lv2_atom_forge_tuple(forge, &frame); @@ -270,7 +550,7 @@ vm_serialize(opcode_t *opcode, LV2_Atom_Forge *forge, const command_t *cmds) } break; case COMMAND_OPCODE: { - const LV2_URID otype = vm_opcode_map(opcode, cmd->op); + const LV2_URID otype = vm_api_map(impl, cmd->op); if(ref && otype) ref = lv2_atom_forge_urid(forge, otype); } break; @@ -293,7 +573,7 @@ vm_serialize(opcode_t *opcode, LV2_Atom_Forge *forge, const command_t *cmds) } static inline bool -vm_deserialize(opcode_t *opcode, LV2_Atom_Forge *forge, +vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, command_t *cmds, uint32_t size, const LV2_Atom *body) { command_t *cmd = cmds; @@ -333,10 +613,20 @@ vm_deserialize(opcode_t *opcode, LV2_Atom_Forge *forge, else if(item->type == forge->URID) { cmd->type = COMMAND_OPCODE; - cmd->op = vm_opcode_unmap(opcode, ((const LV2_Atom_URID *)item)->body); - - if(cmd->op == OP_FRAME) + cmd->op = vm_api_unmap(impl, ((const LV2_Atom_URID *)item)->body); + + if( (cmd->op == OP_BAR_BEAT) + || (cmd->op == OP_BAR) + || (cmd->op == OP_BEAT) + || (cmd->op == OP_BEAT_UNIT) + || (cmd->op == OP_BPB) + || (cmd->op == OP_BPM) + || (cmd->op == OP_FRAME) + || (cmd->op == OP_FPS) + || (cmd->op == OP_SPEED) ) + { is_dynamic = true; + } } else { @@ -56,114 +56,78 @@ vm:graph rdfs:label "Graph" ; rdfs:comment "vm graph tuple" . -vm:opControl - a rdfs:Class, owl:Class ; - rdfs:label "Push Control" . +vm:opInput + a rdfs:Datatype ; rdfs:label "Input port value" . vm:opPush - a rdfs:Class, owl:Class ; - rdfs:label "Push Top of stack" . + a rdfs:Datatype ; rdfs:label "Push Top of stack" . vm:opAdd - a rdfs:Class, owl:Class ; - rdfs:label "Addition" . + a rdfs:Datatype ; rdfs:label "Addition" . vm:opSub - a rdfs:Class, owl:Class ; - rdfs:label "Subtraction" . + a rdfs:Datatype ; rdfs:label "Subtraction" . vm:opMul - a rdfs:Class, owl:Class ; - rdfs:label "Multiplication" . + a rdfs:Datatype ; rdfs:label "Multiplication" . vm:opDiv - a rdfs:Class, owl:Class ; - rdfs:label "Division" . + a rdfs:Datatype ; rdfs:label "Division" . vm:opNeg - a rdfs:Class, owl:Class ; - rdfs:label "Negate" . + a rdfs:Datatype ; rdfs:label "Negate" . vm:opAbs - a rdfs:Class, owl:Class ; - rdfs:label "Absolute" . + a rdfs:Datatype ; rdfs:label "Absolute value" . vm:opPow - a rdfs:Class, owl:Class ; - rdfs:label "Power" . + a rdfs:Datatype ; rdfs:label "Power" . vm:opSqrt - a rdfs:Class, owl:Class ; - rdfs:label "Square root" . + a rdfs:Datatype ; rdfs:label "Square root" . vm:opMod - a rdfs:Class, owl:Class ; - rdfs:label "Modulo" . + a rdfs:Datatype ; rdfs:label "Modulo" . vm:opExp - a rdfs:Class, owl:Class ; - rdfs:label "Exponentiation" . + a rdfs:Datatype ; rdfs:label "Exponentiation" . vm:opExp2 - a rdfs:Class, owl:Class ; - rdfs:label "Exponentiation base 2" . + a rdfs:Datatype ; rdfs:label "Exponentiation base 2" . vm:opLog - a rdfs:Class, owl:Class ; - rdfs:label "Logarithm" . + a rdfs:Datatype ; rdfs:label "Logarithm" . vm:opLog2 - a rdfs:Class, owl:Class ; - rdfs:label "Logarithm base 2" . + a rdfs:Datatype ; rdfs:label "Logarithm base 2" . vm:opLog10 - a rdfs:Class, owl:Class ; - rdfs:label "Logarithm base 10" . + a rdfs:Datatype ; rdfs:label "Logarithm base 10" . vm:opSin - a rdfs:Class, owl:Class ; - rdfs:label "Sinus" . + a rdfs:Datatype ; rdfs:label "Sinus" . vm:opCos - a rdfs:Class, owl:Class ; - rdfs:label "Cosinus" . + a rdfs:Datatype ; rdfs:label "Cosinus" . vm:opSwap - a rdfs:Class, owl:Class ; - rdfs:label "Swap" . -vm:opFrame - a rdfs:Class, owl:Class ; - rdfs:label "Frame" . -vm:opSampleRate - a rdfs:Class, owl:Class ; - rdfs:label "SampleRate" . + a rdfs:Datatype ; rdfs:label "Swap" . vm:opPi - a rdfs:Class, owl:Class ; - rdfs:label "Pi" . + a rdfs:Datatype ; rdfs:label "Pi" . vm:opEq - a rdfs:Class, owl:Class ; - rdfs:label "Equal" . + a rdfs:Datatype ; rdfs:label "Equal" . vm:opLt - a rdfs:Class, owl:Class ; - rdfs:label "Less than" . + a rdfs:Datatype ; rdfs:label "Less than" . vm:opGt - a rdfs:Class, owl:Class ; - rdfs:label "Greater than" . + a rdfs:Datatype ; rdfs:label "Greater than" . vm:opLe - a rdfs:Class, owl:Class ; - rdfs:label "Less or equal" . + a rdfs:Datatype ; rdfs:label "Less or equal" . vm:opGe - a rdfs:Class, owl:Class ; - rdfs:label "Greater or equal" . + a rdfs:Datatype ; rdfs:label "Greater or equal" . vm:opAnd - a rdfs:Class, owl:Class ; - rdfs:label "Boolean And" . + a rdfs:Datatype ; rdfs:label "And" . vm:opOr - a rdfs:Class, owl:Class ; - rdfs:label "Boolean Or" . + a rdfs:Datatype ; rdfs:label "Or" . vm:opNot - a rdfs:Class, owl:Class ; - rdfs:label "Boolean Not" . + a rdfs:Datatype ; rdfs:label "Not" . vm:opBAnd - a rdfs:Class, owl:Class ; - rdfs:label "Bitwise And" . + a rdfs:Datatype ; rdfs:label "Bitwise And" . vm:opBOr - a rdfs:Class, owl:Class ; - rdfs:label "Bitwise Or" . + a rdfs:Datatype ; rdfs:label "Bitwise Or" . vm:opBNot - a rdfs:Class, owl:Class ; - rdfs:label "Bitwise Not" . + a rdfs:Datatype ; rdfs:label "Bitwise Not" . +vm:opLShift + a rdfs:Datatype ; rdfs:label "Left shift" . +vm:opRShift + a rdfs:Datatype ; rdfs:label "Right shift" . vm:opTernary - a rdfs:Class, owl:Class ; - rdfs:label "Ternary" . + a rdfs:Datatype ; rdfs:label "Ternary" . vm:opStore - a rdfs:Class, owl:Class ; - rdfs:label "Store in registry" . + a rdfs:Datatype ; rdfs:label "Store in register" . vm:opLoad - a rdfs:Class, owl:Class ; - rdfs:label "Load from registry" . + a rdfs:Datatype ; rdfs:label "Load from register" . # Plugin vm:vm @@ -344,14 +308,14 @@ vm:vm vm:graph [ a atom:Tuple ; rdf:value ( - 7 vm:opControl - 6 vm:opControl - 5 vm:opControl - 4 vm:opControl - 3 vm:opControl - 2 vm:opControl - 1 vm:opControl - 0 vm:opControl + 7 vm:opInput + 6 vm:opInput + 5 vm:opInput + 4 vm:opInput + 3 vm:opInput + 2 vm:opInput + 1 vm:opInput + 0 vm:opInput ) ] ] . @@ -369,7 +333,7 @@ vm:dBFS a atom:Tuple ; rdf:value ( # dBFS := Log10( |Control0| ) * 20.0 - 0 vm:opControl + 0 vm:opInput vm:opAbs vm:opLog10 20.0 vm:opMul @@ -390,11 +354,11 @@ vm:lfo a atom:Tuple ; rdf:value ( # Phase := (Frame % (SampleRate * Control0) ) / (SampleRate * Control0) - vm:opSampleRate - 0 vm:opControl + time:framesPerSecond + 0 vm:opInput vm:opMul vm:opPush - vm:opFrame + time:frame vm:opSwap vm:opMod vm:opSwap @@ -69,7 +69,7 @@ struct _plughandle_t { float dy; atom_ser_t ser; - opcode_t opcode; + vm_api_impl_t api [OP_MAX]; float in0 [CTRL_MAX]; float out0 [CTRL_MAX]; @@ -85,56 +85,6 @@ struct _desc_t { unsigned npop; }; -static const char *op_labels [OP_MAX] = { - [OP_NOP] = "-", - [OP_CTRL] = "Control (1:1)", - [OP_PUSH] = "Push (1:2)", - [OP_ADD] = "Add (2:1)", - [OP_SUB] = "Sub (2:1)", - [OP_MUL] = "Mul (2:1)", - [OP_DIV] = "Div (2:1)", - [OP_NEG] = "Neg (1:1)", - [OP_ABS] = "Abs (1:1)", - [OP_POW] = "Pow (2:1)", - [OP_SQRT] = "Sqrt (1:1)", - [OP_MOD] = "Mod (2:1)", - [OP_EXP] = "Exp (1:1)", - [OP_EXP_2] = "Exp2 (1:1)", - [OP_LOG] = "Log (1:1)", - [OP_LOG_2] = "Log2 (1:1)", - [OP_LOG_10] = "Log10 (1:1)", - [OP_SIN] = "Sin (1:1)", - [OP_COS] = "Cos (1:1)", - [OP_SWAP] = "Swap (2:2)", - [OP_FRAME] = "Frame (-:1)", - [OP_SRATE] = "Sample Rate (-:1)", - [OP_PI] = "Pi (-:1)", - [OP_EQ] = "Equal (2:1)", - [OP_LT] = "LessThan (2:1)", - [OP_GT] = "GreaterThan (2:1)", - [OP_LE] = "LessOrEqual (2:1)", - [OP_GE] = "GreaterOrEqual (2:1)", - [OP_AND] = "Boolean And (2:1)", - [OP_OR] = "Boolean Or (2:1)", - [OP_NOT] = "Boolean Not (1:1)", - [OP_BAND] = "Bitwise And (2:1)", - [OP_BOR] = "Bitwise Or (2:1)", - [OP_BNOT] = "Bitwise Not (1:1)", - [OP_TER] = "Ternary (3:1)", - [OP_STORE] = "Store (2:0)", - [OP_LOAD] = "Load (1:1)", -}; - -static const char *cmd_labels [COMMAND_MAX] = { - [COMMAND_NOP] = "-", - [COMMAND_OPCODE] = "Op Code" , - [COMMAND_BOOL] = "Boolean" , - [COMMAND_INT] = "Integer" , - [COMMAND_LONG] = "Long" , - [COMMAND_FLOAT] = "Float" , - [COMMAND_DOUBLE] = "Double" -}; - static void _intercept_graph(void *data, LV2_Atom_Forge *forge, int64_t frames, props_event_t event, props_impl_t *impl) @@ -143,7 +93,7 @@ _intercept_graph(void *data, LV2_Atom_Forge *forge, int64_t frames, handle->graph_size = impl->value.size; - vm_deserialize(&handle->opcode, &handle->forge, handle->cmds, + vm_deserialize(handle->api, &handle->forge, handle->cmds, impl->value.size, impl->value.body); } @@ -312,7 +262,7 @@ _expose(struct nk_context *ctx, struct nk_rect wbounds, void *data) const command_enum_t old_cmd_type = cmd->type; int cmd_type = old_cmd_type; - nk_combobox(ctx, cmd_labels, COMMAND_MAX, &cmd_type, dy, nk_vec2(nk_widget_width(ctx), dy*COMMAND_MAX)); + nk_combobox(ctx, command_labels, COMMAND_MAX, &cmd_type, dy, nk_vec2(nk_widget_width(ctx), dy*COMMAND_MAX)); //FIXME if(old_cmd_type != cmd_type) { cmd->type = cmd_type; @@ -374,12 +324,25 @@ _expose(struct nk_context *ctx, struct nk_rect wbounds, void *data) } break; case COMMAND_OPCODE: { - int op = cmd->op; - nk_combobox(ctx, op_labels, OP_MAX, &op, dy, nk_vec2(nk_widget_width(ctx), dy*OP_MAX)); - if(op != cmd->op) + const bool show_mnemo = true; //FIXME + const char *desc = show_mnemo && vm_api_def[cmd->op].mnemo + ? vm_api_def[cmd->op].mnemo + : vm_api_def[cmd->op].label; + if(nk_combo_begin_label(ctx, desc, nk_vec2(nk_widget_width(ctx), dy*OP_MAX))) //FIXME { - cmd->op = op; - sync = true; + nk_layout_row_dynamic(ctx, dy, 1); + for(unsigned op = 0; op < OP_MAX; op++) + { + desc = show_mnemo && vm_api_def[op].mnemo + ? vm_api_def[op].mnemo + : vm_api_def[op].label; + if(nk_combo_item_label(ctx, desc, NK_TEXT_LEFT)) + { + cmd->op = op; + sync = true; + } + } + nk_combo_end(ctx); } } break; case COMMAND_NOP: @@ -404,7 +367,7 @@ _expose(struct nk_context *ctx, struct nk_rect wbounds, void *data) atom_ser_t *ser = &handle->ser; ser->offset = 0; lv2_atom_forge_set_sink(&handle->forge, _sink, _deref, ser); - vm_serialize(&handle->opcode, &handle->forge, handle->cmds); + vm_serialize(handle->api, &handle->forge, handle->cmds); props_impl_t *impl = _props_impl_search(&handle->props, handle->vm_graph); if(impl) _props_set(&handle->props, impl, ser->atom->type, ser->atom->size, LV2_ATOM_BODY_CONST(ser->atom)); @@ -465,7 +428,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri, lv2_atom_forge_init(&handle->forge, handle->map); - vm_opcode_init(&handle->opcode, handle->map); + vm_api_init(handle->api, handle->map); if(!props_init(&handle->props, MAX_NPROPS, plugin_uri, handle->map, handle)) { |