summaryrefslogtreecommitdiff
path: root/src/modules/flow
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-09-03 21:55:34 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-09-03 21:55:34 -0700
commit952e4ac7ea69bb42e266516d78ed72ed68499d3f (patch)
tree78425750e77eaf610cf69b17c22ddea5580aa06f /src/modules/flow
parent45548de598b226c18a21f1b0009995dd444836df (diff)
modules/flow: expose speed as a tap
Nothing too crazy here, the speed= setting still controls the speed in lieu of something driving the tap.
Diffstat (limited to 'src/modules/flow')
-rw-r--r--src/modules/flow/flow.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/modules/flow/flow.c b/src/modules/flow/flow.c
index 8b1386d..936bafe 100644
--- a/src/modules/flow/flow.c
+++ b/src/modules/flow/flow.c
@@ -8,6 +8,8 @@
#include "til_fb.h"
#include "til_module_context.h"
#include "til_settings.h"
+#include "til_stream.h"
+#include "til_tap.h"
#include "ff.h"
#include "v3f.h"
@@ -32,6 +34,18 @@ typedef struct flow_element_t {
typedef struct flow_context_t {
til_module_context_t til_module_context;
+
+ struct {
+ til_tap_t speed;
+ } taps;
+
+ struct {
+ float speed;
+ } vars;
+
+ float *speed;
+
+
ff_t *ff;
unsigned last_populate_idx;
unsigned n_iters;
@@ -86,6 +100,23 @@ static inline flow_element_t rand_element(unsigned *seed)
}
+static void flow_update_taps(flow_context_t *ctxt, til_stream_t *stream)
+{
+ if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.speed))
+ *ctxt->speed = ((flow_setup_t *)ctxt->til_module_context.setup)->speed;
+ else
+ ctxt->vars.speed = *ctxt->speed;
+
+ if (ctxt->vars.speed < 0.f)
+ ctxt->vars.speed = 0.f;
+
+ if (ctxt->vars.speed > 1.f)
+ ctxt->vars.speed = 1.f;
+
+ ctxt->n_iters = ceilf(ctxt->vars.speed * FLOW_MAX_SPEED);
+}
+
+
static til_module_context_t * flow_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
{
flow_setup_t *s = (flow_setup_t *)setup;
@@ -103,9 +134,11 @@ static til_module_context_t * flow_create_context(const til_module_t *module, ti
for (i = 0; i < s->count; i++)
ctxt->elements[i] = rand_element(&ctxt->til_module_context.seed);
- ctxt->n_iters = ceilf(s->speed * FLOW_MAX_SPEED);
ctxt->n_elements = s->count;
+ ctxt->taps.speed = til_tap_init_float(ctxt, &ctxt->speed, 1, &ctxt->vars.speed, "speed");
+ flow_update_taps(ctxt, stream);
+
return &ctxt->til_module_context;
}
@@ -142,6 +175,8 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st
til_fb_fragment_t *fragment = *fragment_ptr;
float w;
+ flow_update_taps(ctxt, stream);
+
til_fb_fragment_clear(fragment);
w = (M_2_PI * asinf(fabsf(sinf((ticks * .001f))))) * 2.f - 1.f;
© All Rights Reserved