diff --git a/doc/README.lv2 b/doc/README.lv2 index bc8fc11..549e523 100644 --- a/doc/README.lv2 +++ b/doc/README.lv2 @@ -1,8 +1,7 @@ Beginning with version 0.05, an MFP patch can be saved as an LV2 plugin. Note that MFP can still not *host* LV2 plugins, only -LADSPA at this time (via the [plugin~ object)Note that as of this -release the scope is not included, so there may be a problem with -. But it can act as a plugin in other hosts. +LADSPA at this time (via the [plugin~ object). But it can act as +a plugin in other hosts. The support is pretty rudimentary, and is mainly intended to allow some exploration of "Max for Live" type interactions with diff --git a/mfp/gui/base_element.py b/mfp/gui/base_element.py index 81111e7..1e98de7 100644 --- a/mfp/gui/base_element.py +++ b/mfp/gui/base_element.py @@ -255,16 +255,16 @@ async def move(self, x, y, update_state=True, **kwargs): self.position_y = y @mutates('obj_state') - async def delete(self): + async def delete(self, delete_obj=True): # FIXME this is because self.app_window is the backend, not the app window MFPGUI().appwin.unregister(self) - if self.obj_id is not None and not self.is_export: + if delete_obj and self.obj_id is not None and not self.is_export: await MFPGUI().mfp.delete(self.obj_id) for conn in [c for c in self.connections_out]: - await conn.delete() + await conn.delete(delete_obj=delete_obj) for conn in [c for c in self.connections_in]: - await conn.delete() + await conn.delete(delete_obj=delete_obj) self.obj_id = None self.obj_state = self.OBJ_DELETED diff --git a/mfp/gui/clutter/base_element.py b/mfp/gui/clutter/base_element.py index d730e68..9d339c9 100644 --- a/mfp/gui/clutter/base_element.py +++ b/mfp/gui/clutter/base_element.py @@ -25,8 +25,8 @@ def __init__(self, window, x, y): super().__init__(window, x, y) - async def delete(self): - await super().delete() + async def delete(self, **kwargs): + await super().delete(**kwargs) if self.badge: if self.badge in self.app_window.event_sources: diff --git a/mfp/gui/clutter/button_element.py b/mfp/gui/clutter/button_element.py index cf122ad..d1a1358 100644 --- a/mfp/gui/clutter/button_element.py +++ b/mfp/gui/clutter/button_element.py @@ -159,4 +159,4 @@ def draw_cb(self, texture, ct, width, height): if self.indicator: ct.fill() else: - ct.stiroke() + ct.stroke() diff --git a/mfp/gui/clutter/connection_element.py b/mfp/gui/clutter/connection_element.py index 2ab931e..323becc 100644 --- a/mfp/gui/clutter/connection_element.py +++ b/mfp/gui/clutter/connection_element.py @@ -45,12 +45,12 @@ def __init__(self, window, obj_1, port_1, obj_2, port_2, dashed=False): async def update(self): await self.draw() - async def delete(self): + async def delete(self, **kwargs): if self.texture: self.group.set_content(None) self.texture = None - await super().delete() + await super().delete(**kwargs) def select(self): super().select() diff --git a/mfp/gui/clutter/message_element.py b/mfp/gui/clutter/message_element.py index c614cae..26d6c2b 100644 --- a/mfp/gui/clutter/message_element.py +++ b/mfp/gui/clutter/message_element.py @@ -40,7 +40,7 @@ def __init__(self, window, x, y): self.group.set_position(x, y) self.redraw() - async def delete(self): + async def delete(self, **kwargs): if self.texture: self.group.set_content(None) self.texture = None @@ -49,7 +49,7 @@ async def delete(self): await self.label.delete() self.label = None - await super().delete() + await super().delete(**kwargs) def redraw(self): if not self.texture: diff --git a/mfp/gui/clutter/processor_element.py b/mfp/gui/clutter/processor_element.py index 8575b1a..7abb85e 100644 --- a/mfp/gui/clutter/processor_element.py +++ b/mfp/gui/clutter/processor_element.py @@ -38,7 +38,7 @@ def __init__(self, window, x, y): self.redraw() - async def delete(self): + async def delete(self, **kwargs): if self.texture: self.group.set_content(None) self.texture = None @@ -47,7 +47,7 @@ async def delete(self): await self.label.delete() self.label = None - await super().delete() + await super().delete(**kwargs) def redraw(self): super().redraw() diff --git a/mfp/gui/connection_element.py b/mfp/gui/connection_element.py index 007eb25..30cf0ef 100644 --- a/mfp/gui/connection_element.py +++ b/mfp/gui/connection_element.py @@ -47,8 +47,8 @@ def __init__(self, window, obj_1, port_1, obj_2, port_2, dashed=False): def get_factory(cls): return ConnectionElementImpl.get_backend(MFPGUI().appwin.backend_name) - async def delete(self): - if (not self.dashed and self.obj_1 and self.obj_2 and + async def delete(self, delete_obj=True): + if (delete_obj and not self.dashed and self.obj_1 and self.obj_2 and self.obj_1.obj_id is not None and self.obj_2.obj_id is not None): await MFPGUI().mfp.disconnect( self.obj_1.obj_id, self.port_1, diff --git a/mfp/gui/patch_display.py b/mfp/gui/patch_display.py index 2070e8d..89598a9 100644 --- a/mfp/gui/patch_display.py +++ b/mfp/gui/patch_display.py @@ -98,7 +98,7 @@ async def configure(self, params): self.app_window.refresh(self) - async def delete(self): + async def delete(self, delete_obj=True): if self.obj_id is None: return @@ -106,7 +106,7 @@ async def delete(self): for layer in self.layers: to_delete = [o for o in layer.objects] for o in to_delete: - await o.delete() + await o.delete(delete_obj=delete_obj) layer.hide() layer.delete() @@ -115,7 +115,7 @@ async def delete(self): self.layer_view.remove(self) # last, delete the patch on the control side - if self.obj_id is not None: - to_delete = self.obj_id - self.obj_id = None + to_delete = self.obj_id + self.obj_id = None + if delete_obj and to_delete is not None: await MFPGUI().mfp.delete(to_delete) diff --git a/mfp/gui_command.py b/mfp/gui_command.py index 98ed906..f5f5879 100644 --- a/mfp/gui_command.py +++ b/mfp/gui_command.py @@ -163,15 +163,17 @@ async def connect(self, obj_1_id, obj_1_port, obj_2_id, obj_2_port): await c.update() async def delete(self, obj_id): + from mfp import log from .gui_main import MFPGUI from .gui.patch_display import PatchDisplay + obj = MFPGUI().recall(obj_id) if isinstance(obj, PatchDisplay): - await obj.delete() + await obj.delete(delete_obj=False) if obj in MFPGUI().appwin.patches: MFPGUI().appwin.patches.remove(obj) elif obj is not None: - await obj.delete() + await obj.delete(delete_obj=False) async def select(self, obj_id): from .gui_main import MFPGUI diff --git a/mfp/mfp_app.py b/mfp/mfp_app.py index bcba8a2..a2ad000 100644 --- a/mfp/mfp_app.py +++ b/mfp/mfp_app.py @@ -555,19 +555,13 @@ async def finish(self): log.debug("MFPApp.finish: all children reaped, good-bye!") - def finish_soon(self): - import threading + async def finish_soon(self): import asyncio - async def wait_and_finish(*args, **kwargs): - await asyncio.sleep(0.5) - await self.finish() - log.debug("MFPApp.finish_soon: done with app.finish", threading._active) - return True - - qt = threading.Thread(target=lambda *args, **kwargs: asyncio.run(wait_and_finish())) - qt.start() - self.leftover_threads.append(qt) + await asyncio.sleep(0.5) + await self.finish() + log.debug("MFPApp.finish_soon: done with app.finish") + return True def send(self, msg, port): if isinstance(msg, MethodCall): diff --git a/mfp/mfp_command.py b/mfp/mfp_command.py index 7c2fd4d..6f47398 100644 --- a/mfp/mfp_command.py +++ b/mfp/mfp_command.py @@ -106,7 +106,6 @@ def set_params(self, obj_id, params): if isinstance(obj, Processor): obj.gui_params = params - @noresp def set_gui_created(self, obj_id, value): from .mfp_app import MFPApp obj = MFPApp().recall(obj_id) @@ -211,12 +210,12 @@ async def show_editor(self, obj_id, show): await patch.delete_gui() @noresp - def save_lv2(self, patch_name, plugin_name): + async def save_lv2(self, patch_name, plugin_name): from .mfp_app import MFPApp patch = MFPApp().patches.get(patch_name) file_name = plugin_name + ".mfp" if patch: - patch.save_lv2(plugin_name, file_name) + await patch.save_lv2(plugin_name, file_name) def clipboard_copy(self, pointer_pos, objlist): from .mfp_app import MFPApp @@ -243,12 +242,14 @@ def open_context(self, node_id, context_id, owner_pid, samplerate): MFPApp().samplerate = samplerate if DSPContext.create(node_id, context_id, ctxt_name): + log.debug(f"open_context: created context, node={node_id} id={context_id} name={ctxt_name}") return True return False async def load_context(self, file_name, node_id, context_id): from .mfp_app import MFPApp from .dsp_object import DSPContext + log.debug(f"load_context: loading {file_name} in context node={node_id} ctxt_id={context_id}") ctxt = DSPContext.lookup(node_id, context_id) patch = await MFPApp().open_file(file_name, ctxt, False) patch.hot_inlets = list(range(len(patch.inlets))) @@ -272,7 +273,7 @@ async def close_context(self, node_id, context_id): del MFPApp().patches[pid] if not len(MFPApp().patches): - MFPApp().finish_soon() + await MFPApp().finish_soon() return None def open_patches(self): diff --git a/mfp/patch_lv2.py b/mfp/patch_lv2.py index 1c140f4..450459e 100644 --- a/mfp/patch_lv2.py +++ b/mfp/patch_lv2.py @@ -11,44 +11,44 @@ def find_mfplib(): from subprocess import Popen, PIPE - import re - sub = Popen(['/bin/bash', '-c', + import re + sub = Popen(['/bin/bash', '-c', "ldd `type -p mfpdsp` | grep libmfpdsp | cut -d '>' -f 2"], stdout=PIPE, stderr=PIPE) stdout, stderr = sub.communicate() #m = re.search(r"([^ ]\+) \(([0-9a-fx]\+)\)$", stdout.strip()) - m = re.search(r"^(.*) ([()0-9a-fx]+)$", stdout.strip()) - if m: - return m.group(1) - else: - return None + m = re.search(r"^(.*) ([()0-9a-fx]+)$", stdout.strip().decode('utf-8')) + if m: + return m.group(1) + else: + return None def create_path(fullpath): import os.path if os.path.isdir(fullpath): - return True + return True elif os.path.exists(fullpath): - return False + return False elif not fullpath: return True - else: + else: if fullpath[-1] == '/': fullpath = fullpath[:-1] head, tail = os.path.split(fullpath) - head_ok = create_path(head) - if head_ok: - try: + head_ok = create_path(head) + if head_ok: + try: os.mkdir(fullpath) - return True - except OSError: + return True + except OSError: pass - return False + return False @extends(Patch) def lv2_create_dir(self, plugname): from .mfp_app import MFPApp - import os - import os.path + import os + import os.path lv2_basedir = MFPApp().lv2_savepath lv2_dirname = plugname + ".lv2" @@ -64,7 +64,7 @@ def lv2_create_dir(self, plugname): ttl_template = """ -# manifest.ttl -- an LV2 plugin definition file for MFP +# manifest.ttl -- an LV2 plugin definition file for MFP # THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT @prefix doap: . @@ -72,7 +72,7 @@ def lv2_create_dir(self, plugname): @prefix rdf: . @prefix rdfs: . - + a lv2:Plugin; lv2:binary <%(ttl_libname)s>; lv2:project ; @@ -106,30 +106,30 @@ def lv2_create_dir(self, plugname): def lv2_write_ttl(self, ttlpath, plugname, filename): port_list = [] libname = "lib%s_lv2.so" % plugname - ttl_params = dict(ttl_plugname=plugname, ttl_filename=filename, + ttl_params = dict(ttl_plugname=plugname, ttl_filename=filename, ttl_libname=libname, ttl_description=(self.properties.get("description") or self.name)) portnum = 0 - for p in self.inlet_objects + self.outlet_objects: + for p in self.inlet_objects + self.outlet_objects: port_params = dict(port_number=portnum) port_types = "" if p.init_type in ("inlet~", "outlet~"): - needs_bounds = False + needs_bounds = False port_types = "lv2:AudioPort" else: - needs_bounds = True + needs_bounds = True port_types = "lv2:ControlPort" if p.init_type in ("inlet~", "inlet"): port_types += ", lv2:InputPort" else: port_types += ", lv2:OutputPort" - port_params['port_types'] = port_types - port_params['port_symbol'] = p.name + port_params['port_types'] = port_types + port_params['port_symbol'] = p.name port_params['port_name'] = p.properties.get("description") or p.name port_params['port_property'] = '' if needs_bounds: - bounds=dict(bounds_default=p.properties.get('bounds_default', 0.0), - bounds_minimum=p.properties.get('bounds_minimum', 0.0), + bounds=dict(bounds_default=p.properties.get('bounds_default', 0.0), + bounds_minimum=p.properties.get('bounds_minimum', 0.0), bounds_maximum=p.properties.get('bounds_maximum', 1.0)) port_params['port_bounds'] = bounds_template % bounds else: @@ -138,7 +138,7 @@ def lv2_write_ttl(self, ttlpath, plugname, filename): portnum += 1 port_list.append(port_template % port_params) - # Edit button + # Edit button port_params=dict(port_number=portnum) port_params['port_types'] = "lv2:InputPort, lv2:ControlPort" port_params['port_symbol'] = 'patch_edit' @@ -148,7 +148,7 @@ def lv2_write_ttl(self, ttlpath, plugname, filename): port_list.append(port_template % port_params) ttl_params['ports'] = ',\n'.join(port_list) - + with open(ttlpath, "w") as ttlfile: ttlfile.write(ttl_template % ttl_params) @@ -156,8 +156,8 @@ def lv2_write_ttl(self, ttlpath, plugname, filename): import os, os.path ttldir = os.path.dirname(ttlpath) mfplib_path = os.path.relpath(find_mfplib(), ttldir) - if not mfplib_path: - return None + if not mfplib_path: + return None else: linkpath = os.path.join(ttldir, libname) if not os.path.exists(linkpath): @@ -165,7 +165,7 @@ def lv2_write_ttl(self, ttlpath, plugname, filename): @extends(Patch) def lv2_bless(self, plugname): - pass + pass diff --git a/mfpdsp/builtin_noop.c b/mfpdsp/builtin_noop.c index 06b3f36..e931c00 100644 --- a/mfpdsp/builtin_noop.c +++ b/mfpdsp/builtin_noop.c @@ -11,20 +11,20 @@ typedef struct { int use_context_output; } builtin_noop_data; -static int -process(mfp_processor * proc) +static int +process(mfp_processor * proc) { builtin_noop_data * d = (builtin_noop_data *)(proc->data); - mfp_sample * inptr, * outptr; + mfp_sample * inptr, * outptr; int blocksize = proc->context->blocksize; - if (proc == NULL) { + if (proc == NULL) { return -1; } if(d->use_context_input) { - inptr = mfp_get_input_buffer(proc->context, d->io_channel); + inptr = mfp_get_input_buffer(proc->context, d->io_channel); } else { if (proc->inlet_buf == NULL) { @@ -41,7 +41,7 @@ process(mfp_processor * proc) } if(d->use_context_output) { - outptr = mfp_get_output_buffer(proc->context, d->io_channel); + outptr = mfp_get_output_buffer(proc->context, d->io_channel); } else { if (proc->outlet_buf == NULL) { @@ -58,12 +58,12 @@ process(mfp_processor * proc) } memcpy(outptr, inptr, blocksize*sizeof(mfp_sample)); - + return 0; } -static void -init(mfp_processor * proc) +static void +init(mfp_processor * proc) { builtin_noop_data * d = g_malloc0(sizeof(builtin_noop_data)); d->use_context_input = 0; @@ -74,19 +74,20 @@ init(mfp_processor * proc) } static void -destroy(mfp_processor * proc) +destroy(mfp_processor * proc) { return; } static int -config(mfp_processor * proc) +config(mfp_processor * proc) { builtin_noop_data * d = (builtin_noop_data *)(proc->data); gpointer ctxt_in = g_hash_table_lookup(proc->params, "use_context_input"); gpointer ctxt_out = g_hash_table_lookup(proc->params, "use_context_output"); gpointer chan = g_hash_table_lookup(proc->params, "io_channel"); + if (ctxt_in != NULL) { d->use_context_input = (int)(*(double *)ctxt_in); } @@ -99,11 +100,10 @@ config(mfp_processor * proc) d->io_channel = (int)(*(double *)chan); } - return 1; } -static mfp_procinfo * +static mfp_procinfo * init_builtin_noop_wrapper(void) { mfp_procinfo * p = g_malloc0(sizeof(mfp_procinfo)); p->is_generator = 1; @@ -118,21 +118,21 @@ init_builtin_noop_wrapper(void) { return p; } -mfp_procinfo * +mfp_procinfo * init_builtin_outlet(void) { mfp_procinfo * p = init_builtin_noop_wrapper(); p->name = strdup("outlet~"); return p; } -mfp_procinfo * +mfp_procinfo * init_builtin_inlet(void) { mfp_procinfo * p = init_builtin_noop_wrapper(); p->name = strdup("inlet~"); return p; } -mfp_procinfo * +mfp_procinfo * init_builtin_noop(void) { mfp_procinfo * p = init_builtin_noop_wrapper(); p->name = strdup("noop~"); diff --git a/mfpdsp/mfp_api.c b/mfpdsp/mfp_api.c index 0bbddb6..56d68a0 100644 --- a/mfpdsp/mfp_api.c +++ b/mfpdsp/mfp_api.c @@ -37,18 +37,15 @@ mfp_api_init(void) static void -api_load_callback(JsonNode * response, void * data) +api_load_callback(Carp__PythonValue * response, void * data) { int patch_objid; mfp_context * context = (mfp_context *)data; - if (JSON_NODE_TYPE(response) == JSON_NODE_ARRAY) { - JsonArray * arry = json_node_get_array(response); - JsonNode * val = json_array_get_element(arry, 1); - if (JSON_NODE_TYPE(val) == JSON_NODE_VALUE) { - patch_objid = (int)json_node_get_double(val); - mfp_context_default_io(context, patch_objid); - } + switch (response->value_types_case) { + case CARP__PYTHON_VALUE__VALUE_TYPES__INT: + mfp_context_default_io(context, response->_int); + break; } } @@ -132,8 +129,9 @@ mfp_api_open_context(mfp_context * context, char * msgbuf, int * msglen) } int -mfp_api_load_context(mfp_context * context, char * patchfile, - char * msgbuf, int * msglen) +mfp_api_load_context( + mfp_context * context, char * patchfile, char * msgbuf, int * msglen +) { const char service_name[] = "MFPCommand.load_context"; const int instance_id = api_rpcid; @@ -141,7 +139,7 @@ mfp_api_load_context(mfp_context * context, char * patchfile, mfp_rpc_args * arglist = mfp_rpc_args_init(&argblock); mfp_rpc_args_append_string(arglist, patchfile); - mfp_rpc_args_append_int(arglist, mfp_comm_nodeid); + mfp_rpc_args_append_string(arglist, rpc_node_id); mfp_rpc_args_append_int(arglist, context->id); int request_id = mfp_rpc_request( @@ -179,7 +177,7 @@ mfp_api_close_context(mfp_context * context) mfp_rpc_argblock argblock; mfp_rpc_args * arglist = mfp_rpc_args_init(&argblock); - mfp_rpc_args_append_int(arglist, mfp_comm_nodeid); + mfp_rpc_args_append_string(arglist, rpc_node_id); mfp_rpc_args_append_int(arglist, context->id); char * msgbuf = mfp_comm_get_buffer(); @@ -201,11 +199,13 @@ int mfp_api_exit_notify(void) { char announce[] = - "json:{ \"__type__\": \"HostExitNotify\" }"; + "json:{ \"__type__\": \"HostExitNotify\", \"host_id\": \"%s\" }"; char * msgbuf = mfp_comm_get_buffer(); + int msglen; strncpy(msgbuf, announce, strlen(announce)); - mfp_comm_submit_buffer(msgbuf, strlen(announce)); + msglen = snprintf(msgbuf, MFP_MAX_MSGSIZE-1, announce, rpc_node_id); + mfp_comm_submit_buffer(msgbuf, msglen); } diff --git a/mfpdsp/mfp_comm.c b/mfpdsp/mfp_comm.c index f7c115e..b440cc6 100644 --- a/mfpdsp/mfp_comm.c +++ b/mfpdsp/mfp_comm.c @@ -13,7 +13,6 @@ #include #include "mfp_dsp.h" -int mfp_comm_nodeid = -1; static char * comm_sockname = NULL; static int comm_socket = -1; static int comm_procpid = -1; diff --git a/mfpdsp/mfp_context.c b/mfpdsp/mfp_context.c index f1b50e7..637a632 100644 --- a/mfpdsp/mfp_context.c +++ b/mfpdsp/mfp_context.c @@ -81,22 +81,18 @@ mfp_context_default_io(mfp_context * context, int patch_id) inlet_t = (mfp_procinfo *)g_hash_table_lookup(mfp_proc_registry, "inlet~"); outlet_t = (mfp_procinfo *)g_hash_table_lookup(mfp_proc_registry, "outlet~"); - printf("connect_default_io: finding inlet~ and outlet~\n"); - for(p = (mfp_processor **)(mfp_proc_list->data); *p != NULL; p++) { if (((*p)->patch_id == patch_id) && ((*p)->typeinfo == inlet_t)) { - newval = g_malloc0(sizeof(float)); - *(float *)newval = 1.0; - mfp_proc_setparam((*p), "use_context_input", newval); - /* FIXME -- you were working here */ - printf(" found inlet~ %p (id %d)\n", (*p), (*p)->rpc_id); + newval = g_malloc0(sizeof(double)); + *(double *)newval = 1.0; + mfp_proc_setparam((*p), g_strdup("use_context_input"), newval); + (*p)->needs_config = 1; } if (((*p)->patch_id == patch_id) && ((*p)->typeinfo == outlet_t)) { - newval = g_malloc0(sizeof(float)); - *(float *)newval = 1.0; - mfp_proc_setparam((*p), "use_context_output", newval); - /* FIXME -- you were working here */ - printf(" found outlet~ %p (id %d)\n", (*p), (*p)->rpc_id); + newval = g_malloc0(sizeof(double)); + *(double *)newval = 1.0; + mfp_proc_setparam((*p), g_strdup("use_context_output"), newval); + (*p)->needs_config = 1; } } } diff --git a/mfpdsp/mfp_dsp.c b/mfpdsp/mfp_dsp.c index 72347f0..a8ae327 100644 --- a/mfpdsp/mfp_dsp.c +++ b/mfpdsp/mfp_dsp.c @@ -331,7 +331,7 @@ mfp_dsp_set_blocksize(mfp_context * ctxt, int nsamples) for(p = (mfp_processor **)(mfp_proc_list->data); *p != NULL; p++) { /* i/o buffers are pre-allocated to mfp_max_blocksize */ for (count = 0; count < (*p)->inlet_conn->len; count ++) { - mfp_block_resize((*p)->inlet_buf[count], nsamples); + mfp_block_resize((*p)->inlet_buf_alloc[count], nsamples); } for (count = 0; count < (*p)->outlet_conn->len; count ++) { @@ -340,16 +340,16 @@ mfp_dsp_set_blocksize(mfp_context * ctxt, int nsamples) (*p)->needs_config = 1; } - ctxt->blocksize = nsamples; if (ctxt->ctype == CTYPE_JACK) { return; } else if (ctxt->ctype == CTYPE_LV2) { for (count = 0; count < ctxt->info.lv2->output_buffers->len; count ++) { - mfp_block_resize(g_array_index(ctxt->info.lv2->output_buffers, mfp_block *, - count), - nsamples); + mfp_block_resize( + g_array_index(ctxt->info.lv2->output_buffers, mfp_block *, count), + nsamples + ); } } } diff --git a/mfpdsp/mfp_dsp.h b/mfpdsp/mfp_dsp.h index 9ed1303..e687aa0 100644 --- a/mfpdsp/mfp_dsp.h +++ b/mfpdsp/mfp_dsp.h @@ -200,7 +200,6 @@ extern int mfp_initialized; extern int mfp_max_blocksize; extern float mfp_in_latency; extern float mfp_out_latency; -extern int mfp_comm_nodeid; extern int mfp_log_quiet; extern GHashTable * mfp_proc_registry; diff --git a/mfpdsp/mfp_lv2_plug.c b/mfpdsp/mfp_lv2_plug.c index e0ad658..2f3f528 100644 --- a/mfpdsp/mfp_lv2_plug.c +++ b/mfpdsp/mfp_lv2_plug.c @@ -2,18 +2,18 @@ #include #include -#include "lv2/lv2plug.in/ns/ext/atom/atom.h" -#include "lv2/lv2plug.in/ns/ext/atom/util.h" -#include "lv2/lv2plug.in/ns/ext/midi/midi.h" -#include "lv2/lv2plug.in/ns/ext/urid/urid.h" -#include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/atom/atom.h" +#include "lv2/atom/util.h" +#include "lv2/midi/midi.h" +#include "lv2/urid/urid.h" +#include "lv2/core/lv2.h" -#include "mfp_dsp.h" +#include "mfp_dsp.h" #define MFP_LV2_URL "http://www.billgribble.com/mfp/mfp_lv2" -void * +void * mfp_lv2_get_port_data(mfp_lv2_info * self, int port) { return g_array_index(self->port_data, void *, port); @@ -21,18 +21,18 @@ mfp_lv2_get_port_data(mfp_lv2_info * self, int port) /* - * static functions for LV2 descriptor + * static functions for LV2 descriptor */ static LV2_Handle -mfp_lv2_instantiate(const LV2_Descriptor * descriptor, double rate, +mfp_lv2_instantiate(const LV2_Descriptor * descriptor, double rate, const char * bundle_path, const LV2_Feature * const * features) { mfp_context * context = NULL; mfp_lv2_info * self = NULL; - /* make sure that the MFP process is running */ + /* make sure that the MFP process is running */ if (!mfp_initialized) { mfp_init_all(NULL); } @@ -49,10 +49,10 @@ mfp_lv2_instantiate(const LV2_Descriptor * descriptor, double rate, self->output_ports = g_array_new(FALSE, TRUE, sizeof(int)); self->output_buffers = g_array_new(FALSE, TRUE, sizeof(mfp_block *)); - /* mfp_lv2_ttl_read populates self with info about this plugin */ + /* mfp_lv2_ttl_read populates self with info about this plugin */ mfp_lv2_ttl_read(self, bundle_path); - /* create output buffers */ + /* create output buffers */ for(int i = 0; i < self->output_ports->len; i++) { mfp_block * blk = mfp_block_new(mfp_max_blocksize); g_array_append_val(self->output_buffers, blk); @@ -66,15 +66,14 @@ mfp_lv2_instantiate(const LV2_Descriptor * descriptor, double rate, int request_id = mfp_api_load_context(context, self->object_path, msgbuf, &msglen); mfp_comm_submit_buffer(msgbuf, msglen); mfp_rpc_wait(request_id); - return (LV2_Handle)context; } static void -mfp_lv2_connect_port(LV2_Handle instance, uint32_t port, void * data) +mfp_lv2_connect_port(LV2_Handle instance, uint32_t port, void * data) { - mfp_context * context = (mfp_context *)instance; + mfp_context * context = (mfp_context *)instance; mfp_lv2_info * self = context->info.lv2; g_array_index(self->port_data, void *, port) = data; @@ -83,7 +82,7 @@ mfp_lv2_connect_port(LV2_Handle instance, uint32_t port, void * data) static void mfp_lv2_activate(LV2_Handle instance) { - mfp_context * context = (mfp_context *)instance; + mfp_context * context = (mfp_context *)instance; mfp_lv2_info * self = context->info.lv2; context->activated = 1; } @@ -122,7 +121,7 @@ mfp_lv2_send_control_output(mfp_context * context, int port, float val) mfp_comm_submit_buffer(msgbuf, msglen); } -static void +static void mfp_lv2_show_editor(mfp_context * context, int show) { int msglen = 0; @@ -133,9 +132,9 @@ mfp_lv2_show_editor(mfp_context * context, int show) static void -mfp_lv2_run(LV2_Handle instance, uint32_t nframes) +mfp_lv2_run(LV2_Handle instance, uint32_t nframes) { - mfp_context * context = (mfp_context *)instance; + mfp_context * context = (mfp_context *)instance; if (context == NULL) { mfp_log_error("mfp_lv2_run: context is NULL"); return; @@ -144,37 +143,39 @@ mfp_lv2_run(LV2_Handle instance, uint32_t nframes) return; } - mfp_lv2_info * self = context->info.lv2; + mfp_lv2_info * lv2_info = context->info.lv2; int first_run=1; mfp_dsp_set_blocksize(context, nframes); - if (self->port_control_values->len > 0) { + if (lv2_info->port_control_values->len > 0) { first_run = 0; } else { - g_array_set_size(self->port_control_values, self->port_data->len); + g_array_set_size(lv2_info->port_control_values, lv2_info->port_data->len); } - /* send an event to control [inlet]/[outlet] on startup and any change - * in value + /* send an event to control [inlet]/[outlet] on startup and any change + * in value */ - for(int i=0; i < (self->port_data->len ); i++) { - if((self->port_input_mask & (1 << i)) && - (self->port_control_mask & (1 << i))) { + for(int i=0; i < lv2_info->port_data->len; i++) { + if ( + lv2_info->port_input_mask & + lv2_info->port_control_mask & (1 << i) + ) { int val_changed = 1; - void * pdata = mfp_lv2_get_port_data(self, i); + void * pdata = mfp_lv2_get_port_data(lv2_info, i); if (pdata != NULL) { float val = *(float *)pdata; - if (!first_run && - (g_array_index(self->port_control_values, float, i) == val )) { + if (!first_run && + (g_array_index(lv2_info->port_control_values, float, i) == val )) { val_changed = 0; } - if (val_changed) { - g_array_index(self->port_control_values, float, i) = val; - if (i < self->port_data->len-1) { + if (val_changed) { + g_array_index(lv2_info->port_control_values, float, i) = val; + if (i < lv2_info->port_data->len-1) { mfp_lv2_send_control_input(context, i, val); } else { @@ -185,34 +186,37 @@ mfp_lv2_run(LV2_Handle instance, uint32_t nframes) } } - mfp_dsp_run(context); - /* copy the output buffers to the output ports */ - for (int port = 0; port < context->info.lv2->output_ports->len; port ++) { - int lv2port = g_array_index(context->info.lv2->output_ports, int, port); - if (context->info.lv2->port_audio_mask && - context->info.lv2->port_output_mask && (1 << lv2port)) { - mfp_sample * destptr = mfp_lv2_get_port_data(context->info.lv2, lv2port); + /* copy the output buffers to the output ports */ + for (int port = 0; port < lv2_info->output_ports->len; port ++) { + int lv2port = g_array_index(lv2_info->output_ports, int, port); + if ( + lv2_info->port_audio_mask & + lv2_info->port_output_mask & (1 << lv2port) + ) { + mfp_sample * destptr = mfp_lv2_get_port_data(lv2_info, lv2port); mfp_sample * srcptr = mfp_get_output_buffer(context, port); memcpy(destptr, srcptr, nframes*sizeof(mfp_sample)); } } - for(int i=0; i < self->port_data->len; i++) { - if((self->port_output_mask & (1 << i)) && - (self->port_control_mask & (1 << i))) { + for(int i=0; i < lv2_info->port_data->len; i++) { + if( + lv2_info->port_output_mask & (1 << i) & + lv2_info->port_control_mask + ) { int val_changed = 1; - void * pdata = mfp_lv2_get_port_data(self, i); + void * pdata = mfp_lv2_get_port_data(lv2_info, i); if (pdata != NULL) { float val = *(float *)pdata; - if (!first_run && - (g_array_index(self->port_control_values, float, i) == val )) { + if (!first_run && + (g_array_index(lv2_info->port_control_values, float, i) == val )) { val_changed = 0; } - if (val_changed) { - g_array_index(self->port_control_values, float, i) = val; + if (val_changed) { + g_array_index(lv2_info->port_control_values, float, i) = val; mfp_lv2_send_control_output(context, i, val); } } @@ -222,8 +226,8 @@ mfp_lv2_run(LV2_Handle instance, uint32_t nframes) static void mfp_lv2_deactivate(LV2_Handle instance) -{ - mfp_context * context = (mfp_context *)instance; +{ + mfp_context * context = (mfp_context *)instance; mfp_lv2_info * self = context->info.lv2; context->activated = 0; } @@ -231,7 +235,7 @@ mfp_lv2_deactivate(LV2_Handle instance) static void mfp_lv2_cleanup(LV2_Handle instance) { - mfp_context * context = (mfp_context *)instance; + mfp_context * context = (mfp_context *)instance; mfp_lv2_info * self = context->info.lv2; mfp_context_destroy(context); @@ -244,21 +248,21 @@ mfp_lv2_extension_data(const char * uri) return NULL; } -static char * +static char * find_plugname(const char * fullpath) { char * pdup = g_strdup(fullpath); char * pname; int plen = strlen(pdup); - - if (plen == 0) { + + if (plen == 0) { return NULL; } if (pdup[plen-1] == '/') { pdup[plen-1] = 0; plen --; } - + pname = rindex(pdup, (int)'/'); if (pname == NULL) { return NULL; @@ -280,12 +284,12 @@ static LV2_Descriptor descriptor = { mfp_lv2_extension_data }; -static const LV2_Descriptor * +static const LV2_Descriptor * mfp_lv2_lib_get_plugin(LV2_Lib_Handle handle, uint32_t index) { char * uri = g_malloc0(2048); - snprintf(uri, 2047, "http://www.billgribble.com/mfp/%s", + snprintf(uri, 2047, "http://www.billgribble.com/mfp/%s", find_plugname((const char *)handle)); descriptor.URI = uri; @@ -303,7 +307,7 @@ mfp_lv2_lib_cleanup(LV2_Lib_Handle handle) return; } -const LV2_Lib_Descriptor * +const LV2_Lib_Descriptor * lv2_lib_descriptor(const char * bundle_path, const LV2_Feature * const * features) { LV2_Lib_Descriptor * ld = g_malloc0(sizeof(LV2_Lib_Descriptor)); @@ -311,8 +315,5 @@ lv2_lib_descriptor(const char * bundle_path, const LV2_Feature * const * feature ld->size = sizeof(LV2_Lib_Descriptor); ld->cleanup = mfp_lv2_lib_cleanup; ld->get_plugin = mfp_lv2_lib_get_plugin; - return ld; + return ld; } - - - diff --git a/mfpdsp/mfp_lv2_ttl.c b/mfpdsp/mfp_lv2_ttl.c index 59cc8df..84e4be9 100644 --- a/mfpdsp/mfp_lv2_ttl.c +++ b/mfpdsp/mfp_lv2_ttl.c @@ -191,7 +191,7 @@ mfp_lv2_ttl_read(mfp_lv2_info * self, const char * bundle_path) ttl_parse_info * pinfo; sprintf(combined_path, "%s%s", bundle_path, mfest); - printf("ttl_read: looking for file at '%s'\n", combined_path); + mfp_log_debug("ttl_read: looking for file at '%s'\n", combined_path); fp = fopen(combined_path, "rb"); pinfo = g_malloc0(sizeof(ttl_parse_info)); diff --git a/mfpdsp/mfp_rpc.c b/mfpdsp/mfp_rpc.c index ae56950..d5bd17a 100644 --- a/mfpdsp/mfp_rpc.c +++ b/mfpdsp/mfp_rpc.c @@ -498,19 +498,6 @@ mfp_rpc_dispatch_request(const char * msgbuf, int msglen) } -static void -ready_callback(JsonNode * response, void * data) -{ - if (JSON_NODE_TYPE(response) == JSON_NODE_ARRAY) { - JsonArray * arry = json_node_get_array(response); - JsonNode * val = json_array_get_element(arry, 1); - if (JSON_NODE_TYPE(val) == JSON_NODE_VALUE) { - mfp_comm_nodeid = (int)json_node_get_double(val); - return; - } - } -} - static void create_uuid_32(char * buffer) { const char hexdigits[] = "0123456789abcdef";