aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-04-30 23:10:22 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-04-30 23:10:22 +0200
commit2ab0110193479f63ff8c72c899c0ccc2d81b6d21 (patch)
tree610289970373f000938a3338a0d9916a671278f0
parent7e57a15096e4d1ac67425dcd7a112ab1722d764f (diff)
downloadsynthpod-2ab0110193479f63ff8c72c899c0ccc2d81b6d21.tar.xz
app: prototype division of port_t into substruct.
* substruct for control/audio/cv/atom port types.
-rw-r--r--VERSION2
-rw-r--r--app/synthpod_app.c17
-rw-r--r--app/synthpod_app_mod.c29
-rw-r--r--app/synthpod_app_port.c27
-rw-r--r--app/synthpod_app_private.h52
-rw-r--r--app/synthpod_app_state.c27
-rw-r--r--app/synthpod_app_ui.c15
7 files changed, 87 insertions, 82 deletions
diff --git a/VERSION b/VERSION
index f85ed699..804ab969 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.4843
+0.1.4845
diff --git a/app/synthpod_app.c b/app/synthpod_app.c
index 0895a371..6d05ebab 100644
--- a/app/synthpod_app.c
+++ b/app/synthpod_app.c
@@ -151,7 +151,7 @@ _sp_app_process_single_run(mod_t *mod, uint32_t nsamples)
port_t *port = &mod->ports[i];
if( (port->type == PORT_TYPE_ATOM)
- && (port->buffer_type == PORT_BUFFER_TYPE_SEQUENCE)
+ && (port->atom.buffer_type == PORT_BUFFER_TYPE_SEQUENCE)
&& (port->direction == PORT_DIRECTION_OUTPUT)
&& (!mod->system_ports) ) // don't overwrite source buffer events
{
@@ -198,13 +198,10 @@ _sp_app_process_single_post(mod_t *mod, uint32_t nsamples, bool sparse_update_ti
// no notification/subscription and no support for patch:Message
const bool subscribed = port->subscriptions != 0;
- if(!(subscribed || port->patchable))
+ if(!subscribed)
+ continue; // skip this port
+ if( (port->type == PORT_TYPE_ATOM) && !port->atom.patchable)
continue; // skip this port
-
- /*
- if(port->patchable)
- printf("patchable %i %i %i\n", mod->uid, i, subscribed);
- */
if(port->driver->transfer && (port->driver->sparse_update ? sparse_update_timeout : true))
port->driver->transfer(app, port, nsamples);
@@ -520,9 +517,9 @@ sp_app_run_pre(sp_app_t *app, uint32_t nsamples)
port_t *port = &mod->ports[p];
// stash control port values
- if(port->stashing)
+ if( (port->type == PORT_TYPE_CONTROL) && port->control.stashing)
{
- port->stashing = false;
+ port->control.stashing = false;
_sp_app_port_control_stash(port);
}
@@ -531,7 +528,7 @@ sp_app_run_pre(sp_app_t *app, uint32_t nsamples)
// clear atom sequence input buffers
if( (port->type == PORT_TYPE_ATOM)
- && (port->buffer_type == PORT_BUFFER_TYPE_SEQUENCE) )
+ && (port->atom.buffer_type == PORT_BUFFER_TYPE_SEQUENCE) )
{
LV2_Atom_Sequence *seq = PORT_BUF_ALIGNED(port);
seq->atom.type = app->regs.port.sequence.urid;
diff --git a/app/synthpod_app_mod.c b/app/synthpod_app_mod.c
index 21b60e9c..988feed3 100644
--- a/app/synthpod_app_mod.c
+++ b/app/synthpod_app_mod.c
@@ -198,8 +198,10 @@ _sp_app_mod_slice_pool(mod_t *mod, port_type_t type)
// initialize control buffers to default value
if(tar->type == PORT_TYPE_CONTROL)
{
+ control_port_t *control = &tar->control;
+
float *buf_ptr = PORT_BASE_ALIGNED(tar);
- *buf_ptr = tar->dflt;
+ *buf_ptr = control->dflt;
}
ptr += lv2_atom_pad_size(tar->size);
@@ -699,12 +701,9 @@ _sp_app_mod_add(sp_app_t *app, const char *uri, u_id_t uid, LV2_URID urn)
tar->mod = mod;
tar->index = i;
tar->symbol = lilv_node_as_string(lilv_port_get_symbol(plug, port));
- tar->integer = lilv_port_has_property(plug, port, app->regs.port.integer.node);
- tar->toggled = lilv_port_has_property(plug, port, app->regs.port.toggled.node);
tar->direction = lilv_port_is_a(plug, port, app->regs.port.input.node)
? PORT_DIRECTION_INPUT
: PORT_DIRECTION_OUTPUT;
- atomic_flag_clear_explicit(&tar->lock, memory_order_relaxed);
// register system ports
if(mod->system_ports)
@@ -783,16 +782,21 @@ _sp_app_mod_add(sp_app_t *app, const char *uri, u_id_t uid, LV2_URID urn)
tar->monitored = 1;
tar->protocol = app->regs.port.float_protocol.urid;
tar->driver = &control_port_driver;
+
+ control_port_t *control = &tar->control;
+ control->is_integer = lilv_port_has_property(plug, port, app->regs.port.integer.node);
+ control->is_toggled = lilv_port_has_property(plug, port, app->regs.port.toggled.node);
+ atomic_flag_clear_explicit(&control->lock, memory_order_relaxed);
LilvNode *dflt_node;
LilvNode *min_node;
LilvNode *max_node;
lilv_port_get_range(mod->plug, port, &dflt_node, &min_node, &max_node);
- tar->dflt = dflt_node ? lilv_node_as_float(dflt_node) : 0.f;
- tar->min = min_node ? lilv_node_as_float(min_node) : 0.f;
- tar->max = max_node ? lilv_node_as_float(max_node) : 1.f;
- tar->range = tar->max - tar->min;
- tar->range_1 = 1.f / tar->range;
+ control->dflt = dflt_node ? lilv_node_as_float(dflt_node) : 0.f; //FIXME int, bool
+ control->min = min_node ? lilv_node_as_float(min_node) : 0.f; //FIXME int, bool
+ control->max = max_node ? lilv_node_as_float(max_node) : 1.f; //FIXME int, bool
+ control->range = control->max - control->min;
+ control->range_1 = 1.f / control->range;
lilv_node_free(dflt_node);
lilv_node_free(min_node);
lilv_node_free(max_node);
@@ -803,12 +807,13 @@ _sp_app_mod_add(sp_app_t *app, const char *uri, u_id_t uid, LV2_URID urn)
tar->type = PORT_TYPE_ATOM;
tar->selected = 0;
tar->monitored = 0;
- tar->buffer_type = PORT_BUFFER_TYPE_SEQUENCE; //FIXME properly discover this
tar->protocol = app->regs.port.event_transfer.urid; //FIXME handle atom_transfer
tar->driver = &seq_port_driver; // FIXME handle atom_port_driver
+ tar->atom.buffer_type = PORT_BUFFER_TYPE_SEQUENCE; //FIXME properly discover this
+
// does this port support patch:Message?
- tar->patchable = lilv_port_supports_event(plug, port, app->regs.patch.message.node);
+ tar->atom.patchable = lilv_port_supports_event(plug, port, app->regs.patch.message.node);
// check whether this is a control port
const LilvPort *control_port = lilv_plugin_get_port_by_designation(plug,
@@ -884,7 +889,7 @@ _sp_app_mod_add(sp_app_t *app, const char *uri, u_id_t uid, LV2_URID urn)
// initialize atom sequence ports
if( (tar->type == PORT_TYPE_ATOM)
- && (tar->buffer_type == PORT_BUFFER_TYPE_SEQUENCE) )
+ && (tar->atom.buffer_type == PORT_BUFFER_TYPE_SEQUENCE) )
{
LV2_Atom *atom = tar->base;
atom->size = sizeof(LV2_Atom_Sequence_Body);
diff --git a/app/synthpod_app_port.c b/app/synthpod_app_port.c
index 27d4bbb2..35600779 100644
--- a/app/synthpod_app_port.c
+++ b/app/synthpod_app_port.c
@@ -447,17 +447,18 @@ _update_ramp(sp_app_t *app, source_t *source, port_t *port, uint32_t nsamples)
__realtime void
_sp_app_port_control_stash(port_t *port)
{
+ control_port_t *control = &port->control;
void *buf = PORT_BASE_ALIGNED(port);
- if(_sp_app_port_try_lock(port))
+ if(_sp_app_port_try_lock(control))
{
- port->stash = *(float *)buf;
+ control->stash = *(float *)buf;
- _sp_app_port_unlock(port);
+ _sp_app_port_unlock(control);
}
else
{
- port->stashing = true;
+ control->stashing = true;
}
}
@@ -469,8 +470,8 @@ _port_control_simplex(sp_app_t *app, port_t *port, uint32_t nsamples)
port_t *src_port = port->sources[0].port;
// normalize
- const float norm = (*dst - src_port->min) * src_port->range_1;
- *dst = port->min + norm * port->range; //TODO handle exponential ranges
+ const float norm = (*dst - src_port->control.min) * src_port->control.range_1;
+ *dst = port->control.min + norm * port->control.range; //TODO handle exponential ranges
_sp_app_port_control_stash(port);
}
@@ -488,8 +489,8 @@ _port_control_multiplex(sp_app_t *app, port_t *port, uint32_t nsamples)
const float *src = PORT_BASE_ALIGNED(src_port);
// normalize
- const float norm = (*src - src_port->min) * src_port->range_1;
- *dst += port->min + norm * port->range; //TODO handle exponential ranges
+ const float norm = (*src - src_port->control.min) * src_port->control.range_1;
+ *dst += port->control.min + norm * port->control.range; //TODO handle exponential ranges
}
_sp_app_port_control_stash(port);
@@ -684,10 +685,10 @@ _port_float_protocol_update(sp_app_t *app, port_t *port, uint32_t nsamples)
const float *val = PORT_BASE_ALIGNED(port);
new_val = *val;
- needs_update = new_val != port->last;
+ needs_update = new_val != port->control.last;
if(needs_update) // update last value
- port->last = new_val;
+ port->control.last = new_val;
if(needs_update)
{
@@ -719,10 +720,10 @@ _port_peak_protocol_update(sp_app_t *app, port_t *port, uint32_t nsamples)
peak = val;
}
- if(fabs(peak - port->last) >= 1e-3) //TODO make this configurable
+ if(fabs(peak - port->audio.last) >= 1e-3) //TODO make this configurable
{
// update last value
- port->last = peak;
+ port->audio.last = peak;
const LV2UI_Peak_Data data = {
.period_start = app->fps.period_cnt,
@@ -789,7 +790,7 @@ _port_atom_transfer_update(sp_app_t *app, port_t *port, uint32_t nsamples)
if(atom->size == 0) // empty atom
return;
- else if( (port->buffer_type == PORT_BUFFER_TYPE_SEQUENCE)
+ else if( (port->atom.buffer_type == PORT_BUFFER_TYPE_SEQUENCE)
&& (atom->size == sizeof(LV2_Atom_Sequence_Body)) ) // empty atom sequence
return;
diff --git a/app/synthpod_app_private.h b/app/synthpod_app_private.h
index 8f369cee..cf7aeb3f 100644
--- a/app/synthpod_app_private.h
+++ b/app/synthpod_app_private.h
@@ -344,32 +344,46 @@ struct _connectable_t {
struct _control_port_t {
bool is_integer;
bool is_toggled;
- float val;
+
+ float dflt;
float min;
float max;
- float span;
+ float range;
+ float range_1;
+ float last;
+ int32_t i32;
+ float f32;
+
+ float stash;
+ bool stashing;
+ atomic_flag lock;
+
auto_t automation;
//FIXME
};
struct _audio_port_t {
connectable_t connectable;
+ float last;
//FIXME
};
struct _cv_port_t {
connectable_t connectable;
+ float last;
//FIXME
};
struct _atom_port_t {
connectable_t connectable;
port_buffer_type_t buffer_type; // none, sequence
+ bool patchable; // support patch:Message
//FIXME
};
struct _port_t {
mod_t *mod;
+
int selected;
int monitored;
@@ -384,27 +398,13 @@ struct _port_t {
size_t size;
void *buf;
void *base;
- int32_t i32;
- float f32;
- int integer;
- int toggled;
- port_direction_t direction; // input, output
port_type_t type; // audio, CV, control, atom
- port_buffer_type_t buffer_type; // none, sequence
- bool patchable; // support patch:Message
-
+ port_direction_t direction; // input, output
LV2_URID protocol; // floatProtocol, peakProtocol, atomTransfer, eventTransfer
- int subscriptions; // subsriptions reference counter
const port_driver_t *driver;
- float last;
-
- float dflt;
- float min;
- float max;
- float range;
- float range_1;
+ int subscriptions; // subsriptions reference counter
// system_port iface
struct {
@@ -412,10 +412,6 @@ struct _port_t {
void *data;
} sys;
- float stash;
- bool stashing;
- atomic_flag lock;
-
union {
control_port_t control;
audio_port_t audio;
@@ -649,24 +645,24 @@ int
_sp_app_port_desilence(sp_app_t *app, port_t *src_port, port_t *snk_port);
static inline void
-_sp_app_port_spin_lock(port_t *port)
+_sp_app_port_spin_lock(control_port_t *control)
{
- while(atomic_flag_test_and_set_explicit(&port->lock, memory_order_acquire))
+ while(atomic_flag_test_and_set_explicit(&control->lock, memory_order_acquire))
{
// spin
}
}
static inline bool
-_sp_app_port_try_lock(port_t *port)
+_sp_app_port_try_lock(control_port_t *control)
{
- return atomic_flag_test_and_set_explicit(&port->lock, memory_order_acquire) == false;
+ return atomic_flag_test_and_set_explicit(&control->lock, memory_order_acquire) == false;
}
static inline void
-_sp_app_port_unlock(port_t *port)
+_sp_app_port_unlock(control_port_t *control)
{
- atomic_flag_clear_explicit(&port->lock, memory_order_release);
+ atomic_flag_clear_explicit(&control->lock, memory_order_release);
}
/*
diff --git a/app/synthpod_app_state.c b/app/synthpod_app_state.c
index c35a3cca..5a5bb8cc 100644
--- a/app/synthpod_app_state.c
+++ b/app/synthpod_app_state.c
@@ -164,6 +164,7 @@ _state_set_value(const char *symbol, void *data,
if(tar->type == PORT_TYPE_CONTROL)
{
+ control_port_t *control = &tar->control;
float val = 0.f;
if( (type == app->forge.Int) && (size == sizeof(int32_t)) )
@@ -182,7 +183,7 @@ _state_set_value(const char *symbol, void *data,
//printf("%u %f\n", index, val);
float *buf_ptr = PORT_BASE_ALIGNED(tar);
*buf_ptr = val;
- tar->last = val - 0.1; // triggers notification
+ control->last = val - 0.1; // triggers notification
_sp_app_port_control_stash(tar);
}
@@ -209,33 +210,35 @@ _state_get_value(const char *symbol, void *data, uint32_t *size, uint32_t *type)
if( (tar->direction == PORT_DIRECTION_INPUT)
&& (tar->type == PORT_TYPE_CONTROL) )
{
- _sp_app_port_spin_lock(tar); // concurrent acess from worker and rt threads
+ control_port_t *control = &tar->control;
- const float stash = tar->stash;
+ _sp_app_port_spin_lock(control); // concurrent acess from worker and rt threads
- _sp_app_port_unlock(tar);
+ const float stash = control->stash;
+
+ _sp_app_port_unlock(control);
const void *ptr = NULL;
- if(tar->toggled)
+ if(control->is_toggled)
{
*size = sizeof(int32_t);
*type = app->forge.Bool;
- tar->i32 = floor(stash);
- ptr = &tar->i32;
+ control->i32 = floor(stash);
+ ptr = &control->i32;
}
- else if(tar->integer)
+ else if(control->is_integer)
{
*size = sizeof(int32_t);
*type = app->forge.Int;
- tar->i32 = floor(stash);
- ptr = &tar->i32;
+ control->i32 = floor(stash);
+ ptr = &control->i32;
}
else // float
{
*size = sizeof(float);
*type = app->forge.Float;
- tar->f32 = stash;
- ptr = &tar->f32;
+ control->f32 = stash;
+ ptr = &control->f32;
}
return ptr;
diff --git a/app/synthpod_app_ui.c b/app/synthpod_app_ui.c
index 9c5df6cd..52e59b39 100644
--- a/app/synthpod_app_ui.c
+++ b/app/synthpod_app_ui.c
@@ -66,14 +66,14 @@ _sp_app_from_ui_float_protocol(sp_app_t *app, const LV2_Atom *atom)
if(port->type == PORT_TYPE_CONTROL)
{
*buf = trans->value.body;
- port->last = trans->value.body;
+ port->control.last = trans->value.body;
_sp_app_port_control_stash(port);
}
else if(port->type == PORT_TYPE_CV)
{
for(unsigned i = 0; i < app->driver->max_block_size; i++)
buf[i] = trans->value.body;
- port->last = fabs(trans->value.body);
+ port->cv.last = fabs(trans->value.body);
}
return advance_ui[app->block_state];
@@ -689,8 +689,11 @@ _sp_app_from_ui_port_refresh(sp_app_t *app, const LV2_Atom *atom)
if(!port)
return advance_ui[app->block_state];
- float *buf_ptr = PORT_BASE_ALIGNED(port);
- port->last = *buf_ptr - 0.1; // will force notification
+ if(port->type == PORT_TYPE_CONTROL)
+ {
+ float *buf_ptr = PORT_BASE_ALIGNED(port);
+ port->control.last = *buf_ptr - 0.1; // will force notification
+ }
return advance_ui[app->block_state];
}
@@ -1520,7 +1523,7 @@ _subscription_list_add(sp_app_t *app, const LV2_Atom_Object *obj)
if(src_port->type == PORT_TYPE_CONTROL)
{
const float *buf_ptr = PORT_BASE_ALIGNED(src_port);
- src_port->last = *buf_ptr - 0.1; // will force notification
+ src_port->control.last = *buf_ptr - 0.1; // will force notification
}
}
}
@@ -1592,7 +1595,7 @@ _notification_list_add(sp_app_t *app, const LV2_Atom_Object *obj)
if(src_port->type == PORT_TYPE_CONTROL)
{
*buf_ptr = val;
- src_port->last = *buf_ptr; // we don't want any notification
+ src_port->control.last = *buf_ptr; // we don't want any notification
}
else if(src_port->type == PORT_TYPE_CV)
{