From cef7f883d2f967143e20f1b5fadaf630af264c9d Mon Sep 17 00:00:00 2001 From: Alexandros Theodotou Date: Sun, 9 Feb 2020 16:33:01 +0000 Subject: [PATCH] implement CV and control trigger --- src/zlfo.c | 12 ++++++++++++ src/zlfo_math.h | 35 +++++++++++++++++++++++++---------- src/zlfo_ttl_gen.c | 2 +- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/zlfo.c b/src/zlfo.c index 7701885..699edc3 100644 --- a/src/zlfo.c +++ b/src/zlfo.c @@ -34,6 +34,7 @@ #define IS_FREERUN(x) (*x->freerun > 0.001f) #define IS_STEP_MODE(x) (*x->step_mode > 0.001f) +#define IS_TRIGGERED(x) (*x->trigger > 0.001f) typedef struct ZLFO { @@ -489,6 +490,17 @@ run ( ((float) self->common.period_size / grid_step_divisor); + /* handle triggers + * + * FIXME CV trigger requires splitting the cycle, + * but for now it applies to the whole cycle */ + if (IS_TRIGGERED (self) || + float_array_contains_nonzero ( + self->cv_trigger, n_samples)) + { + self->common.current_sample = 0; + } + for (uint32_t i = 0; i < n_samples; i++) { /* invert horizontally */ diff --git a/src/zlfo_math.h b/src/zlfo_math.h index d63942c..62b756b 100644 --- a/src/zlfo_math.h +++ b/src/zlfo_math.h @@ -254,17 +254,18 @@ get_current_sample ( HostPosition * host_pos, uint32_t period_size) { - /* if beat_unit is 0 that means we don't know the - * time info yet */ - if (freerunning || host_pos->beat_unit == 0) + if (freerunning) { - if (!freerunning && host_pos->beat_unit == 0) - { - fprintf ( - stderr, - "Host did not send time info. Beat " - "unit is unknown.\n"); - } + return 0; + } + else if (host_pos->beat_unit == 0) + { + /* if beat_unit is 0 that means we don't + * know the time info yet */ + fprintf ( + stderr, + "Host did not send time info. Beat " + "unit is unknown.\n"); return 0; } else /* synced */ @@ -273,6 +274,20 @@ get_current_sample ( } } +static inline int +float_array_contains_nonzero ( + const float * arr, + size_t size) +{ + for (size_t i = 0; i < size; i++) + { + if (arr[i] > 0.0001f || + arr[i] < - 0.0001f) + return 1; + } + return 0; +} + /** * @param sine_multipler Position to save the sine * multiplier in. diff --git a/src/zlfo_ttl_gen.c b/src/zlfo_ttl_gen.c index fe6c969..4174211 100644 --- a/src/zlfo_ttl_gen.c +++ b/src/zlfo_ttl_gen.c @@ -122,7 +122,7 @@ int main ( lv2:default %f ;\n\ lv2:minimum %f ;\n\ lv2:maximum %f ;\n\ - ] , [\n", 0.0, -1.0, 1.0, 0.0, -1.0, 1.0); + ] , [\n", 0.0, 0.0, 1.0, 0.0, 0.0, 1.0); /* write input controls */ int index = ZLFO_GATE;