From 944c905ee4187477a769624514545338b81fa4d0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 18 Feb 2020 22:42:06 +0100 Subject: Add basic Guile stuff --- meson.build | 5 +++- src/crossfade.c | 2 +- src/display.c | 5 ++-- src/lightctx.h | 4 ++- src/nanolight.c | 9 +++++-- src/scheme.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/scheme.h | 29 +++++++++++++++++++++ 7 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 src/scheme.c create mode 100644 src/scheme.h diff --git a/meson.build b/meson.build index edfcb6c..87e9882 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,8 @@ cairo_dep = dependency('cairo', required : true) pango_dep = dependency('pango', required : true) pangocairo_dep = dependency('pangocairo', required : true) soup_dep = dependency('libsoup-2.4', required : true) +guile_dep = dependency('guile-2.2', required : true) +thread_dep = dependency('threads') # Main program executable('nanolight', @@ -26,6 +28,7 @@ executable('nanolight', 'src/scanout.c', 'src/display.c', 'src/crossfade.c', + 'src/scheme.c', ], - dependencies : [gtk_dep, mdep, soup_dep], + dependencies : [gtk_dep, mdep, soup_dep, guile_dep, thread_dep], install : true) diff --git a/src/crossfade.c b/src/crossfade.c index 296bee2..cc34c1d 100644 --- a/src/crossfade.c +++ b/src/crossfade.c @@ -97,7 +97,7 @@ void test_fade(struct lightctx *nl) f->fixtures[0].target.intensity = 1.0; f->n_fixtures = 1; f->fade = 1.0; - f->delay = 1.0; + f->delay = 0.0; /* Start the fade */ f->fixtures[0].start = nl->fixtures[0].v; diff --git a/src/display.c b/src/display.c index 8181e5d..f4fa3c0 100644 --- a/src/display.c +++ b/src/display.c @@ -607,7 +607,8 @@ void create_main_window(struct lightctx *nl) /* Create main window */ mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_fullscreen(GTK_WINDOW(mainwindow)); + //gtk_window_fullscreen(GTK_WINDOW(mainwindow)); + gtk_window_set_default_size(GTK_WINDOW(mainwindow), 1024, 768); g_signal_connect_swapped(G_OBJECT(mainwindow), "destroy", gtk_main_quit, NULL); da = gtk_drawing_area_new(); @@ -623,5 +624,5 @@ void create_main_window(struct lightctx *nl) gtk_widget_grab_focus(GTK_WIDGET(da)); gtk_widget_show_all(mainwindow); - g_timeout_add(200, redraw_cb, nl); + g_timeout_add(50, redraw_cb, nl); } diff --git a/src/lightctx.h b/src/lightctx.h index 3017a5e..fb0ec1a 100644 --- a/src/lightctx.h +++ b/src/lightctx.h @@ -1,7 +1,7 @@ /* * nanolight.h * - * Copyright © 2019 Thomas White + * Copyright © 2019-2020 Thomas White * * This file is part of NanoLight. * @@ -25,6 +25,8 @@ #include +#include "scheme.h" + /* Fixture attributes */ #define INTENSITY (1<<0) #define COLOUR (1<<1) diff --git a/src/nanolight.c b/src/nanolight.c index 1bcb2ea..17411f1 100644 --- a/src/nanolight.c +++ b/src/nanolight.c @@ -1,7 +1,7 @@ /* * nanolight.c * - * Copyright © 2019 Thomas White + * Copyright © 2019-2020 Thomas White * * This file is part of NanoLight. * @@ -28,6 +28,7 @@ #include #include #include +#include #include #define _(x) gettext(x) @@ -35,6 +36,7 @@ #include "lightctx.h" #include "scanout.h" #include "display.h" +#include "scheme.h" static void show_help(const char *s) { @@ -56,6 +58,7 @@ int main(int argc, char *argv[]) struct lightctx nl; struct fixture_class cls; int c; + pthread_t repl_thread; gtk_init(&argc, &argv); @@ -194,7 +197,9 @@ int main(int argc, char *argv[]) create_fixture(&nl, &cls, "mh4", 0, 154, REVERSE_PAN); /* Set up output */ - g_timeout_add(100, scanout_cb, &nl); + g_timeout_add(50, scanout_cb, &nl); + + pthread_create(&repl_thread, NULL, run_repl, &nl); create_main_window(&nl); gtk_main(); diff --git a/src/scheme.c b/src/scheme.c new file mode 100644 index 0000000..b2a0771 --- /dev/null +++ b/src/scheme.c @@ -0,0 +1,79 @@ +/* + * scheme.c + * + * Copyright © 2019-2020 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 "lightctx.h" + + +static SCM fixture_type; + + +static SCM set_intensity(SCM fixture_scm, SCM intensity_scm) +{ + const int intensity = scm_to_int(intensity_scm); + + scm_assert_foreign_object_type(fixture_type, fixture_scm); + struct fixture *fixture = scm_foreign_object_ref(fixture_scm, 0); + + fixture->v.intensity = (float)intensity/100.0; + + return SCM_UNSPECIFIED; +} + + +static void finalize_fixture(SCM fixture) +{ + printf("finalise fixture!\n"); +} + + +void *register_scheme_funcs(void *data) +{ + struct lightctx *nl = data; + SCM name, slots; + int i; + scm_t_struct_finalize finalizer; + + 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); + + for ( i=0; in_fixtures; i++ ) { + SCM obj = scm_make_foreign_object_1(fixture_type, &nl->fixtures[i]); + scm_define(scm_from_utf8_symbol(nl->fixtures[i].label), obj); + } + + scm_c_define_gsubr("set-intensity", 2, 0, 0, &set_intensity); + + return NULL; +} + + +void *run_repl(void *pargsv) +{ + scm_with_guile(®ister_scheme_funcs, pargsv); + scm_shell(0, NULL); + return NULL; +} diff --git a/src/scheme.h b/src/scheme.h new file mode 100644 index 0000000..d3d9478 --- /dev/null +++ b/src/scheme.h @@ -0,0 +1,29 @@ +/* + * scheme.h + * + * Copyright © 2019-2020 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 SCHEME_H +#define SCHEME_H + +extern void *register_scheme_funcs(void *data); +extern void *run_repl(void *pargsv); + +#endif /* SCHEME_H */ -- cgit v1.2.3