diff options
Diffstat (limited to 'src/lightctx.c')
-rw-r--r-- | src/lightctx.c | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/src/lightctx.c b/src/lightctx.c new file mode 100644 index 0000000..cbd5c24 --- /dev/null +++ b/src/lightctx.c @@ -0,0 +1,161 @@ +/* + * lightctx.c + * + * Copyright © 2019 Thomas White <taw@bitwiz.me.uk> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + + +#include "lightctx.h" + + +struct fixture *create_fixture(struct lightctx *nl, struct fixture_class *cls, + const char *label, int universe, int base_addr, + int flags) +{ + struct fixture *fix; + + if ( nl->n_fixtures == nl->max_fixtures ) { + struct fixture *fixtures_new; + fixtures_new = realloc(nl->fixtures, (64+nl->max_fixtures)*sizeof(struct fixture)); + if ( fixtures_new == NULL ) return NULL; + nl->fixtures = fixtures_new; + nl->max_fixtures += 64; + } + + fix = &nl->fixtures[nl->n_fixtures++]; + fix->label = strdup(label); + fix->universe = universe; + fix->base_addr = base_addr; + fix->cls = cls; + fix->flags = flags; + + fix->intensity = 0.0; + fix->cyan = 0.0; + fix->magenta = 0.0; + fix->yellow = 0.0; + fix->red = 0.0; + fix->green = 0.0; + fix->blue = 0.0; + fix->pan = 0.0; + fix->tilt = 0.0; + fix->gobo = 0; + fix->gobo_rotate = 0.0; + fix->gobo_spin = 0.0; + fix->prism = 0; + fix->prism_rotate = 0.0; + fix->prism_spin = 0.0; + fix->focus = 0.5; + fix->zoom = 0.5; + fix->frost = 0.0; + + return fix; +} + + +static void cap_value(float *val, float min, float max) +{ + if ( *val > max ) *val = max; + if ( *val < min ) *val = min; +} + + +void attr_movex(struct lightctx *nl, signed int d, int fine) +{ + int i; + float chg = fine ? d/60000.0 : d/10.0; + if ( nl->sel_attr != PANTILT ) return; + for ( i=0; i<nl->n_sel; i++ ) { + struct fixture *fix = &nl->fixtures[nl->selection[i]]; + if ( !(fix->cls->attributes & PANTILT) ) continue; + fix->pan += chg; + cap_value(&fix->pan, -1.0, 1.0); + } +} + + +void attr_movey(struct lightctx *nl, signed int d, int fine) +{ + int i; + float chg = fine ? d/60000.0 : d/10.0; + for ( i=0; i<nl->n_sel; i++ ) { + struct fixture *fix = &nl->fixtures[nl->selection[i]]; + + switch ( nl->sel_attr ) { + + case PANTILT : + fix->tilt += chg; + cap_value(&fix->tilt, -1.0, 1.0); + break; + + case FOCUS : + fix->focus += chg; + cap_value(&fix->focus, 0.0, 1.0); + break; + + case ZOOM : + fix->zoom += chg; + cap_value(&fix->zoom, 0.0, 1.0); + break; + + case FROST : + fix->frost += chg; + cap_value(&fix->frost, 0.0, 1.0); + break; + + case IRIS : + fix->iris += chg; + cap_value(&fix->iris, 0.0, 1.0); + break; + + case GOBO : + if ( (fix->gobo == 0) && (d<0) ) continue; + if ( (fix->gobo == fix->cls->n_gobos-1) && (d>0) ) continue; + fix->gobo += d; + break; + + case GOBO_ROTATE : + fix->gobo_rotate += chg; + cap_value(&fix->gobo_rotate, -1.0, 1.0); + break; + + case GOBO_SPIN : + fix->gobo_spin += chg; + cap_value(&fix->gobo_spin, -1.0, 1.0); + break; + + case PRISM : + if ( (fix->prism == 0) && (d<0) ) continue; + if ( (fix->prism == fix->cls->n_prisms-1) && (d>0) ) continue; + fix->prism += d; + break; + + case PRISM_ROTATE : + fix->prism_rotate += chg; + cap_value(&fix->prism_rotate, -1.0, 1.0); + break; + + case PRISM_SPIN : + fix->prism_spin += chg; + cap_value(&fix->prism_spin, -1.0, 1.0); + break; + + } + + } +} |