From 3aaa95e835e241190b9e79240c35e71c9591fc97 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Feb 2020 08:06:01 +0100 Subject: Do fixture patching from Scheme --- src/init.scm | 24 +++++++ src/nanolight.c | 93 ------------------------- src/scheme.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 221 insertions(+), 104 deletions(-) diff --git a/src/init.scm b/src/init.scm index b6069aa..f875ce3 100644 --- a/src/init.scm +++ b/src/init.scm @@ -14,3 +14,27 @@ [(null? fixtures) #f] [(eq? (fixture-name (car fixtures)) name) (car fixtures)] [else (find-fixture (cdr fixtures) name)]))) + +(define find-fixture-class + (lambda (fixture-classes name) + (cond + [(null? fixture-classes) #f] + [(string-ci=? (fixture-class-name (car fixture-classes)) name) (car fixture-classes)] + [else (find-fixture-class (cdr fixture-classes) name)]))) + +#! +(let ([robe-dl7s-mode1 (find-fixture-class fixture-class-library + "Robe Robin DL7S Profile Mode 1")]) + (if robe-dl7s-mode1 + (begin + (patch-fixture 'mh1 robe-dl7s-mode1 0 1) + (patch-fixture 'mh2 robe-dl7s-mode1 0 52) + (patch-fixture 'mh3 robe-dl7s-mode1 0 103) + (patch-fixture 'mh4 robe-dl7s-mode1 0 154)) + (display "DL7S not available\n"))) +!# + +(let ([dimmer (find-fixture-class fixture-class-library "Generic dimmer")]) + (if dimmer + (patch-fixture 'dim1 dimmer 0 1) + (display "Dimmer class not available\n"))) diff --git a/src/nanolight.c b/src/nanolight.c index 17411f1..de919bb 100644 --- a/src/nanolight.c +++ b/src/nanolight.c @@ -56,7 +56,6 @@ static gboolean scanout_cb(gpointer data) int main(int argc, char *argv[]) { struct lightctx nl; - struct fixture_class cls; int c; pthread_t repl_thread; @@ -91,93 +90,6 @@ int main(int argc, char *argv[]) bindtextdomain("nanolight", LOCALEDIR); textdomain("nanolight"); - /* Set up data structures */ - cls.name = "Robe Robin DL7S Profile Mode 1"; - cls.properties = COL_CMY; - cls.attributes = INTENSITY | COLOUR | PANTILT | FOCUS | ZOOM - | FROST | IRIS | GOBO | PRISM; - cls.attributes16 = INTENSITY | COLOUR | PANTILT | FOCUS | ZOOM - | IRIS; - - cls.intensity_offset = 49; - cls.pan_offset = 0; - cls.tilt_offset = 2; - cls.cyan_offset = 8; - cls.magenta_offset = 10; - cls.yellow_offset = 12; - cls.focus_offset = 34; - cls.zoom_offset = 32; - cls.frost_offset = 29; /* FIXME 0..179 only */ - cls.iris_offset = 30; /* FIXME: 0..179 only, but also fine @ offset 32 */ - cls.gobo_rotate_offset = 25; - cls.gobo_spin_offset = 25; - cls.prism_rotate_offset = 0; - cls.prism_spin_offset = 28; - - int magic_chans[] = {48}; - int magic_vals[] = {32}; - cls.magic_chans = magic_chans; - cls.magic_vals = magic_vals; - cls.n_magic = 1; - - int gobo_chans[] = {24, 22}; - int gobo_vals[] = { 0, 0, - 6, 0, - 10, 0, - 15, 0, - 19, 0, - 24, 0, - 28, 0, - 33, 0, - 38, 0, - 42, 0, - 47, 0, - 52, 0, - 57, 0, - 0, 67, - 0, 73, - 0, 78, - 0, 84, - 0, 89, - 0, 95, - 0, 100, - 0, 106 }; - int gobo_flags[] = { 0, - GOBO_ROTATE, - GOBO_ROTATE, - GOBO_ROTATE, - GOBO_ROTATE, - GOBO_ROTATE, - GOBO_ROTATE, - GOBO_SPIN, - GOBO_SPIN, - GOBO_SPIN, - GOBO_SPIN, - GOBO_SPIN, - GOBO_SPIN, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 }; - cls.n_gobos = 21; - cls.n_gobo_chans = 2; - cls.gobo_chans = gobo_chans; - cls.gobo_vals = gobo_vals; - cls.gobo_flags = gobo_flags; - - int prism_chans[] = {27}; - int prism_vals[] = {0, 50}; - int prism_flags [] = {0, PRISM_SPIN}; - cls.n_prisms = 2; - cls.n_prism_chans = 1; - cls.prism_chans = prism_chans; - cls.prism_vals = prism_vals; - cls.prism_flags = prism_flags; - nl.fixture_width = 80.0; nl.fixtures = NULL; nl.n_fixtures = 0; @@ -191,11 +103,6 @@ int main(int argc, char *argv[]) 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); - create_fixture(&nl, &cls, "mh3", 0, 103, REVERSE_PAN); - create_fixture(&nl, &cls, "mh4", 0, 154, REVERSE_PAN); - /* Set up output */ g_timeout_add(50, scanout_cb, &nl); diff --git a/src/scheme.c b/src/scheme.c index b81b1a3..e13d7d3 100644 --- a/src/scheme.c +++ b/src/scheme.c @@ -27,6 +27,11 @@ static SCM fixture_type; +static SCM fixture_class_type; + +SCM fixture_list = SCM_EOL; + +struct lightctx *nl = NULL; static SCM set_intensity(SCM fixture_scm, SCM intensity_scm) @@ -50,35 +55,217 @@ static SCM fixture_name(SCM fixture_scm) } +static SCM fixture_class_name(SCM fixture_class_scm) +{ + scm_assert_foreign_object_type(fixture_class_type, fixture_class_scm); + struct fixture_class *fixture_class = scm_foreign_object_ref(fixture_class_scm, 0); + return scm_from_utf8_string(fixture_class->name); +} + + +static struct fixture_class *make_generic_dimmer() +{ + struct fixture_class *cls; + + cls = malloc(sizeof(struct fixture_class)); + if ( cls == NULL ) return NULL; + + /* Set up data structures */ + cls->name = "Generic dimmer"; + cls->properties = 0; + cls->attributes = INTENSITY; + cls->attributes16 = 0; + cls->intensity_offset = 0; + cls->n_magic = 0; + cls->n_gobos = 0; + cls->n_gobo_chans = 0; + cls->n_prisms = 0; + cls->n_prism_chans = 0; + + return cls; +} + + +static struct fixture_class *make_dl7s() +{ + struct fixture_class *cls; + + cls = malloc(sizeof(struct fixture_class)); + if ( cls == NULL ) return NULL; + + /* Set up data structures */ + cls->name = "Robe Robin DL7S Profile Mode 1"; + cls->properties = COL_CMY; + cls->attributes = INTENSITY | COLOUR | PANTILT | FOCUS | ZOOM + | FROST | IRIS | GOBO | PRISM; + cls->attributes16 = INTENSITY | COLOUR | PANTILT | FOCUS | ZOOM + | IRIS; + + cls->intensity_offset = 49; + cls->pan_offset = 0; + cls->tilt_offset = 2; + cls->cyan_offset = 8; + cls->magenta_offset = 10; + cls->yellow_offset = 12; + cls->focus_offset = 34; + cls->zoom_offset = 32; + cls->frost_offset = 29; /* FIXME 0..179 only */ + cls->iris_offset = 30; /* FIXME: 0..179 only, but also fine @ offset 32 */ + cls->gobo_rotate_offset = 25; + cls->gobo_spin_offset = 25; + cls->prism_rotate_offset = 0; + cls->prism_spin_offset = 28; + + int magic_chans[] = {48}; + int magic_vals[] = {32}; + cls->magic_chans = magic_chans; + cls->magic_vals = magic_vals; + cls->n_magic = 1; + + int gobo_chans[] = {24, 22}; + int gobo_vals[] = { 0, 0, + 6, 0, + 10, 0, + 15, 0, + 19, 0, + 24, 0, + 28, 0, + 33, 0, + 38, 0, + 42, 0, + 47, 0, + 52, 0, + 57, 0, + 0, 67, + 0, 73, + 0, 78, + 0, 84, + 0, 89, + 0, 95, + 0, 100, + 0, 106 }; + int gobo_flags[] = { 0, + GOBO_ROTATE, + GOBO_ROTATE, + GOBO_ROTATE, + GOBO_ROTATE, + GOBO_ROTATE, + GOBO_ROTATE, + GOBO_SPIN, + GOBO_SPIN, + GOBO_SPIN, + GOBO_SPIN, + GOBO_SPIN, + GOBO_SPIN, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 }; + cls->n_gobos = 21; + cls->n_gobo_chans = 2; + cls->gobo_chans = gobo_chans; + cls->gobo_vals = gobo_vals; + cls->gobo_flags = gobo_flags; + + int prism_chans[] = {27}; + int prism_vals[] = {0, 50}; + int prism_flags [] = {0, PRISM_SPIN}; + cls->n_prisms = 2; + cls->n_prism_chans = 1; + cls->prism_chans = prism_chans; + cls->prism_vals = prism_vals; + cls->prism_flags = prism_flags; + + return cls; +} + + +static SCM patch_fixture(SCM fixture_name_scm, SCM fixture_class_scm, + SCM universe_scm, SCM addr_scm) +{ + const int universe = scm_to_int(universe_scm); + const int addr = scm_to_int(addr_scm); + struct fixture_class *fixture_class; + char *fixture_name; + SCM fixture_string; + struct fixture *fixture; + + scm_assert_foreign_object_type(fixture_class_type, fixture_class_scm); + fixture_class = scm_foreign_object_ref(fixture_class_scm, 0); + + if ( !scm_is_symbol(fixture_name_scm) ) return SCM_BOOL_F; + fixture_string = scm_symbol_to_string(fixture_name_scm); + fixture_name = scm_to_locale_string(fixture_string); + + fixture = create_fixture(nl, fixture_class, fixture_name, universe, addr, REVERSE_PAN); + free(fixture_name); + + SCM obj = scm_make_foreign_object_1(fixture_type, fixture); + SCM obj_list = scm_list_1(obj); + fixture_list = scm_append(scm_list_2(fixture_list, obj_list)); + scm_define(scm_from_utf8_symbol("fixtures"), fixture_list); + + return obj; +} + + static void finalize_fixture(SCM fixture) { printf("finalise fixture!\n"); } +static void finalize_fixture_class(SCM fixture) +{ + printf("finalise fixture class!\n"); +} + + void *register_scheme_funcs(void *data) { - struct lightctx *nl = data; SCM name, slots; - int i; - scm_t_struct_finalize finalizer; - SCM fixture_list; + SCM fixture_class_list; + struct fixture_class *cls; + + nl = data; + /* Define fixture type */ name = scm_from_utf8_symbol("fixture"); slots = scm_list_1(scm_from_utf8_symbol("data")); - finalizer = finalize_fixture; - fixture_type = scm_make_foreign_object_type(name, slots, finalizer); + fixture_type = scm_make_foreign_object_type(name, slots, finalize_fixture); - fixture_list = SCM_EOL; - for ( i=0; in_fixtures; i++ ) { - SCM obj = scm_make_foreign_object_1(fixture_type, &nl->fixtures[i]); + /* Define fixture class type */ + name = scm_from_utf8_symbol("fixture-class"); + slots = scm_list_1(scm_from_utf8_symbol("data")); + fixture_class_type = scm_make_foreign_object_type(name, slots, finalize_fixture_class); + + /* Expose the list of fixture classes */ + fixture_class_list = SCM_EOL; + cls = make_dl7s(); + if ( cls != NULL ) { + SCM obj = scm_make_foreign_object_1(fixture_class_type, cls); SCM obj_list = scm_list_1(obj); - fixture_list = scm_append(scm_list_2(fixture_list, obj_list)); + fixture_class_list = scm_append(scm_list_2(fixture_class_list, obj_list)); } + cls = make_generic_dimmer(); + if ( cls != NULL ) { + SCM obj = scm_make_foreign_object_1(fixture_class_type, cls); + SCM obj_list = scm_list_1(obj); + fixture_class_list = scm_append(scm_list_2(fixture_class_list, obj_list)); + } + scm_define(scm_from_utf8_symbol("fixture-class-library"), fixture_class_list); + + /* Expose the list of fixtures (starts empty) */ scm_define(scm_from_utf8_symbol("fixtures"), fixture_list); scm_c_define_gsubr("fixture-name", 1, 0, 0, &fixture_name); + scm_c_define_gsubr("fixture-class-name", 1, 0, 0, &fixture_class_name); scm_c_define_gsubr("set-intensity", 2, 0, 0, &set_intensity); + scm_c_define_gsubr("patch-fixture", 4, 0, 0, &patch_fixture); return NULL; } @@ -95,7 +282,6 @@ static void run_init() G_RESOURCE_LOOKUP_FLAGS_NONE, &error); initscm = g_bytes_get_data(bytes, &size); - printf("got %p\n", initscm); scm_c_eval_string(initscm); g_bytes_unref(bytes); } -- cgit v1.2.3