Browse Source

avoid sending atoms on every cycle

master
Alexandros Theodotou 3 years ago
parent
commit
5f7a125104
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 51
      src/zlfo.c
  2. 3
      src/zlfo_common.h
  3. 10
      src/zlfo_math.h
  4. 19
      src/zlfo_ttl_gen.c
  5. 101
      src/zlfo_ui.c

51
src/zlfo.c

@ -69,6 +69,7 @@ typedef struct ZLFO @@ -69,6 +69,7 @@ typedef struct ZLFO
float * square_out;
float * rnd_out;
float * custom_out;
float * sample_to_ui;
/** This is how far we are inside a beat, from 0.0
* to 1.0. */
@ -87,12 +88,21 @@ typedef struct ZLFO @@ -87,12 +88,21 @@ typedef struct ZLFO
/* whether the plugin was freerunning in the
* last cycle. this is used to detect changes
* in freerunning/sync. */
int was_freerunning;
int was_freerunning;
/** Frequency during the last run. */
float last_freq;
float last_sync_rate;
float last_sync_rate_type;
float last_freq;
float last_sync_rate;
float last_sync_rate_type;
/* These are used to detect changes so we
* can notify the UI. */
long last_period_size;
double last_samplerate;
/** Flag to be used to send messages to the
* UI. */
int first_run_with_ui;
} ZLFO;
@ -261,6 +271,9 @@ connect_port ( @@ -261,6 +271,9 @@ connect_port (
case ZLFO_CUSTOM_OUT:
self->custom_out = (float *) data;
break;
case ZLFO_SAMPLE_TO_UI:
self->sample_to_ui = (float *) data;
break;
default:
break;
}
@ -400,6 +413,8 @@ activate ( @@ -400,6 +413,8 @@ activate (
{
ZLFO * self = (ZLFO*) instance;
self->first_run_with_ui = 1;
recalc_multipliers (self);
}
@ -433,6 +448,7 @@ run ( @@ -433,6 +448,7 @@ run (
self->common.uris.ui_on)
{
self->ui_active = 1;
self->first_run_with_ui = 1;
}
else if (obj->body.otype ==
self->common.uris.ui_off)
@ -675,16 +691,33 @@ run ( @@ -675,16 +691,33 @@ run (
self->current_sample, self->period_size);
#endif
if (self->ui_active &&
(self->common.period_size !=
self->last_period_size ||
!math_doubles_equal (
self->common.samplerate,
self->last_samplerate) ||
xport_changed ||
self->first_run_with_ui))
{
/*fprintf (stderr, "sending messages\n");*/
send_messages_to_ui (self, xport_changed);
self->first_run_with_ui = 0;
}
/* set current sample for UI to pick up */
*self->sample_to_ui =
(float) self->common.current_sample;
/* remember values */
self->last_freq = *self->freq;
self->last_sync_rate = *self->sync_rate;
self->last_sync_rate_type = *self->sync_rate_type;
self->was_freerunning = is_freerunning;
if (self->ui_active)
{
send_messages_to_ui (self, xport_changed);
}
self->last_period_size =
self->common.period_size;
self->last_samplerate =
self->common.samplerate;
}
static void

3
src/zlfo_common.h

@ -87,6 +87,9 @@ typedef enum PortIndex @@ -87,6 +87,9 @@ typedef enum PortIndex
ZLFO_CONTROL,
/** Plugin to UI communication. */
ZLFO_NOTIFY,
/** Plugin to UI communication of the current
* sample. */
ZLFO_SAMPLE_TO_UI,
ZLFO_CV_GATE,
ZLFO_CV_TRIGGER,

10
src/zlfo_math.h

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include "config.h"
#include <float.h>
#include <math.h>
#include "zlfo_common.h"
@ -360,9 +361,12 @@ recalc_vars ( @@ -360,9 +361,12 @@ recalc_vars (
get_period_size (
freerunning, host_pos, effective_freq,
sync_rate_float, frames_per_beat, samplerate);
*current_sample =
get_current_sample (
freerunning, host_pos, *period_size);
if (current_sample)
{
*current_sample =
get_current_sample (
freerunning, host_pos, *period_size);
}
}
#endif

19
src/zlfo_ttl_gen.c

@ -102,10 +102,22 @@ int main ( @@ -102,10 +102,22 @@ int main (
lv2:symbol \"notify\" ;\n\
lv2:name \"Notify\" ;\n\
rdfs:comment \"Plugin to GUI communication\" ;\n\
] , [\n\
a lv2:OutputPort ,\n\
lv2:ControlPort ;\n\
lv2:index 2 ;\n\
lv2:symbol \"sample_to_ui\" ;\n\
lv2:name \"Sample to UI\" ;\n\
rdfs:comment \"Plugin to GUI communication\" ;\n\
lv2:default %d ;\n\
lv2:minimum %d ;\n\
lv2:maximum %d ;\n\
lv2:portProperty lv2:integer ;\n\
lv2:portProperty pprop:notOnGUI ;\n\
] , [\n\
a lv2:InputPort ,\n\
lv2:CVPort ;\n\
lv2:index 2 ;\n\
lv2:index 3 ;\n\
lv2:symbol \"cv_gate\" ;\n\
lv2:name \"Gate\" ;\n\
rdfs:comment \"CV gate\" ;\n\
@ -115,14 +127,15 @@ int main ( @@ -115,14 +127,15 @@ int main (
] , [\n\
a lv2:InputPort ,\n\
lv2:CVPort ;\n\
lv2:index 3 ;\n\
lv2:index 4 ;\n\
lv2:symbol \"cv_trigger\" ;\n\
lv2:name \"Trigger\" ;\n\
rdfs:comment \"CV trigger\" ;\n\
lv2:default %f ;\n\
lv2:minimum %f ;\n\
lv2:maximum %f ;\n\
] , [\n", 0.0, 0.0, 1.0, 0.0, 0.0, 1.0);
] , [\n",
0, 0, 30720000, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0);
/* write input controls */
int index = ZLFO_GATE;

101
src/zlfo_ui.c

@ -220,6 +220,13 @@ typedef struct ZLfoUi @@ -220,6 +220,13 @@ typedef struct ZLfoUi
* or -1. */
int dragging_node;
/** This is double here so we can be more
* precise with calculations. */
double current_sample;
/** Last time the current sample was set at. */
gint64 last_current_sample_set;
ZtkApp * app;
} ZLfoUi;
@ -1652,6 +1659,20 @@ draw_graph_steps ( @@ -1652,6 +1659,20 @@ draw_graph_steps (
}
}
static void
redraw_mid_region (
ZLfoUi * self)
{
PuglRect rect;
rect.x = self->mid_region->rect.x;
rect.y = self->mid_region->rect.y;
rect.width = self->mid_region->rect.width;
rect.height =
self->mid_region->rect.height;
puglPostRedisplayRect (
self->app->view, rect);
}
static void
mid_region_bg_draw_cb (
ZtkWidget * widget,
@ -1665,6 +1686,49 @@ mid_region_bg_draw_cb ( @@ -1665,6 +1686,49 @@ mid_region_bg_draw_cb (
widget->rect.width, widget->rect.height);
cairo_fill (cr);
float sync_rate_float =
sync_rate_to_float (
self->sync_rate,
self->sync_rate_type);
/**
* Effective frequency.
*
* This is either the free-running frequency,
* or the frequency corresponding to the current
* sync rate.
*/
float effective_freq =
get_effective_freq (
self->freerun, self->freq,
&self->common.host_pos, sync_rate_float);
/* calculate current sample */
gint64 cur_time = g_get_monotonic_time ();
if (self->last_current_sample_set == 0 ||
(!self->freerun &&
self->common.host_pos.speed < 0.001f))
{
self->last_current_sample_set = cur_time;
}
else
{
double samples_diff =
((double) self->common.samplerate *
((double)
(cur_time -
self->last_current_sample_set) /
1000000.0));
self->current_sample += samples_diff;
while (self->current_sample >=
(double) self->common.period_size)
{
self->current_sample -=
(double) self->common.period_size;
}
self->last_current_sample_set = cur_time;
}
/* draw grid */
for (int i = 0; i < 9; i++)
{
@ -1706,7 +1770,7 @@ mid_region_bg_draw_cb ( @@ -1706,7 +1770,7 @@ mid_region_bg_draw_cb (
/* draw current position */
double total_space = GRID_WIDTH;
double current_offset =
(double) self->common.current_sample /
self->current_sample /
(double) self->common.period_size;
#if 0
ztk_message (
@ -1726,29 +1790,12 @@ mid_region_bg_draw_cb ( @@ -1726,29 +1790,12 @@ mid_region_bg_draw_cb (
cairo_stroke (cr);
/*#endif*/
float sync_rate_float =
sync_rate_to_float (
self->sync_rate,
self->sync_rate_type);
/**
* Effective frequency.
*
* This is either the free-running frequency,
* or the frequency corresponding to the current
* sync rate.
*/
float effective_freq =
get_effective_freq (
self->freerun, self->freq,
&self->common.host_pos, sync_rate_float);
recalc_vars (
self->freerun,
&self->common.sine_multiplier,
&self->common.saw_multiplier,
&self->common.period_size,
&self->common.current_sample,
NULL,
&self->common.host_pos, effective_freq,
sync_rate_float,
(float) self->common.samplerate);
@ -2754,6 +2801,10 @@ port_event ( @@ -2754,6 +2801,10 @@ port_event (
self->num_nodes =
(int) * (const float *) buffer;
break;
case ZLFO_SAMPLE_TO_UI:
self->current_sample =
(double) * (const float *) buffer;
break;
default:
break;
}
@ -2826,6 +2877,9 @@ port_event ( @@ -2826,6 +2877,9 @@ port_event (
self->common.current_sample =
((LV2_Atom_Long*)
current_sample)->body;
self->current_sample =
(double)
self->common.current_sample;
self->common.samplerate =
((LV2_Atom_Double*)
samplerate)->body;
@ -2855,14 +2909,7 @@ port_event ( @@ -2855,14 +2909,7 @@ port_event (
}
/*#if 0*/
PuglRect rect;
rect.x = self->mid_region->rect.x;
rect.y = self->mid_region->rect.y;
rect.width = self->mid_region->rect.width;
rect.height =
self->mid_region->rect.height;
puglPostRedisplayRect (
self->app->view, rect);
redraw_mid_region (self);
/*#endif*/
}
else

Loading…
Cancel
Save