From 03f23ec9b611bf61f439ddde4a8759459be29832 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 16 Jul 2019 23:15:22 +0200 Subject: Initial crossfade stuff --- meson.build | 1 + src/crossfade.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/crossfade.h | 29 +++++++++++++++ src/display.c | 3 +- src/lightctx.h | 25 +++++++++++++ src/nanolight.c | 1 + src/scanout.c | 4 +++ 7 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/crossfade.c create mode 100644 src/crossfade.h diff --git a/meson.build b/meson.build index d647b04..edfcb6c 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,7 @@ executable('nanolight', 'src/command.c', 'src/scanout.c', 'src/display.c', + 'src/crossfade.c', ], dependencies : [gtk_dep, mdep, soup_dep], install : true) diff --git a/src/crossfade.c b/src/crossfade.c new file mode 100644 index 0000000..296bee2 --- /dev/null +++ b/src/crossfade.c @@ -0,0 +1,108 @@ +/* + * crossfade.c + * + * Copyright © 2019 Thomas White + * + * This file is part of NanoLight. + * + * NanoLight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#include +#include +#include +#include + +#include "lightctx.h" + + +static void fade(float start, float target, float frac, float *result) +{ + float val = start + (target - start)*frac; + + /* HTP merge */ + if ( val > *result ) *result = val; +} + + +void calculate_fades(struct lightctx *nl) +{ + int i; + float now = g_get_monotonic_time()/1e6; /* seconds */ + + for ( i=0; in_fades; i++ ) { + + int j; + struct fade *f = &nl->fades[i]; + float st = f->start_time/1e6; + float frac; + + if ( !f->active ) continue; + + frac = ((now-st)-f->delay)/f->fade; + if ( frac > 1.0 ) { + frac = 1.0; + f->active = 0; + } + if ( frac < 0.0 ) frac = 0.0; + + for ( j=0; in_fixtures; i++ ) { + struct fade_fix *fix = &f->fixtures[j]; + if ( fix->attrs & INTENSITY ) { + fade(fix->start.intensity, fix->target.intensity, frac, &fix->fix->v.intensity); + } + if ( fix->attrs & COLOUR ) { + fade(fix->start.cyan, fix->target.cyan, frac, &fix->fix->v.cyan); + fade(fix->start.magenta, fix->target.magenta, frac, &fix->fix->v.magenta); + fade(fix->start.yellow, fix->target.yellow, frac, &fix->fix->v.yellow); + fade(fix->start.red, fix->target.red, frac, &fix->fix->v.red); + fade(fix->start.green, fix->target.green, frac, &fix->fix->v.green); + fade(fix->start.blue, fix->target.blue, frac, &fix->fix->v.blue); + } + if ( fix->attrs & PANTILT ) { + fade(fix->start.pan, fix->target.pan, frac, &fix->fix->v.pan); + fade(fix->start.tilt, fix->target.tilt, frac, &fix->fix->v.tilt); + } + } + + } +} + + +void test_fade(struct lightctx *nl) +{ + struct fade *f; + + nl->fades = malloc(sizeof(struct fade)); + f = &nl->fades[0]; + + f->fixtures = malloc(64*sizeof(struct fade_fix)); + f->n_fixtures = 0; + + f->fixtures[0].fix = &nl->fixtures[0]; + f->fixtures[0].attrs = INTENSITY; + f->fixtures[0].target.intensity = 1.0; + f->n_fixtures = 1; + f->fade = 1.0; + f->delay = 1.0; + + /* Start the fade */ + f->fixtures[0].start = nl->fixtures[0].v; + f->start_time = g_get_monotonic_time(); + f->active = 1; + nl->n_fades = 1; +} + diff --git a/src/crossfade.h b/src/crossfade.h new file mode 100644 index 0000000..a698f17 --- /dev/null +++ b/src/crossfade.h @@ -0,0 +1,29 @@ +/* + * crossfade.h + * + * Copyright © 2019 Thomas White + * + * This file is part of NanoLight. + * + * NanoLight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef CROSSFADE_H +#define CROSSFADE_H + +extern void calculate_fades(struct lightctx *nl); +extern void test_fade(struct lightctx *nl); + +#endif /* CROSSFADE_H */ diff --git a/src/display.c b/src/display.c index 122d455..b5f7f24 100644 --- a/src/display.c +++ b/src/display.c @@ -34,6 +34,7 @@ #include "lightctx.h" #include "command.h" +#include "crossfade.h" #define OVERALL_BORDER (20.0) #define OVERALL_SPLIT (0.5) @@ -465,7 +466,7 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct lightctx case GDK_KEY_KP_Enter : if ( !nl->go_lock ) { - printf("Go!\n"); + test_fade(nl); nl->go_lock = 1; } break; diff --git a/src/lightctx.h b/src/lightctx.h index ec9170a..3017a5e 100644 --- a/src/lightctx.h +++ b/src/lightctx.h @@ -138,12 +138,37 @@ struct fixture }; +struct fade_fix +{ + struct fixture *fix; + int attrs; /* Bit mask of attributes to change */ + struct attr_vals start; + struct attr_vals target; +}; + + +struct fade +{ + struct fade_fix *fixtures; + int n_fixtures; + + gint64 start_time; + int active; + + float fade; + float delay; +}; + + struct lightctx { int n_fixtures; int max_fixtures; struct fixture *fixtures; + struct fade *fades; + int n_fades; + GtkIMContext *im_context; GtkWidget *da; diff --git a/src/nanolight.c b/src/nanolight.c index b78a6f8..1bcb2ea 100644 --- a/src/nanolight.c +++ b/src/nanolight.c @@ -186,6 +186,7 @@ int main(int argc, char *argv[]) nl.dragging = 0; nl.go_lock = 0; nl.sb_lock = 0; + nl.n_fades = 0; create_fixture(&nl, &cls, "mh1", 0, 1, REVERSE_PAN); create_fixture(&nl, &cls, "mh2", 0, 52, REVERSE_PAN); diff --git a/src/scanout.c b/src/scanout.c index 64e5574..6b04b7c 100644 --- a/src/scanout.c +++ b/src/scanout.c @@ -27,6 +27,8 @@ #include #include "lightctx.h" +#include "crossfade.h" + static void set_val(int *dmx, int base_addr, int attr_offset, float value, int sixteenbit) { @@ -107,6 +109,8 @@ int scanout_all(struct lightctx *nl) char str[8200]; signed int universe = -1; + calculate_fades(nl); + /* Start from zero */ for ( i=0; i<512; i++ ) dmx[i] = 0; -- cgit v1.2.3