summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-07-02 22:37:15 +0200
committerThomas White <taw@physics.org>2019-07-02 22:37:15 +0200
commitd4179a12792269f2af090d27a4307c6a570ef8a2 (patch)
treecce9559103c2861938bc88d5961cec412dbcfd03
parent2cc20dd211db43e31620661e674b20a0cb687a9b (diff)
Rename "struct nanolight" to "struct lightctx"
-rw-r--r--meson.build1
-rw-r--r--src/command.c10
-rw-r--r--src/command.h2
-rw-r--r--src/display.c32
-rw-r--r--src/display.h2
-rw-r--r--src/lightctx.c161
-rw-r--r--src/lightctx.h (renamed from src/nanolight.h)15
-rw-r--r--src/nanolight.c143
-rw-r--r--src/scanout.c4
-rw-r--r--src/scanout.h2
10 files changed, 200 insertions, 172 deletions
diff --git a/meson.build b/meson.build
index d75170b..d647b04 100644
--- a/meson.build
+++ b/meson.build
@@ -21,6 +21,7 @@ soup_dep = dependency('libsoup-2.4', required : true)
# Main program
executable('nanolight',
['src/nanolight.c',
+ 'src/lightctx.c',
'src/command.c',
'src/scanout.c',
'src/display.c',
diff --git a/src/command.c b/src/command.c
index e60a75a..f1387b8 100644
--- a/src/command.c
+++ b/src/command.c
@@ -28,7 +28,7 @@
#include <libintl.h>
#define _(x) gettext(x)
-#include "nanolight.h"
+#include "lightctx.h"
enum token_type
{
@@ -76,7 +76,7 @@ static int stop_char(char c)
}
-static int find_tokens(const char *cmd, struct token *tokens, struct nanolight *nl)
+static int find_tokens(const char *cmd, struct token *tokens, struct lightctx *nl)
{
int i;
int n = 0;
@@ -160,7 +160,7 @@ static const char *str_attr(int att)
return "???";
}
-static void show_tokens(struct token *tokens, int n, struct nanolight *nl)
+static void show_tokens(struct token *tokens, int n, struct lightctx *nl)
{
int i;
@@ -199,7 +199,7 @@ static void show_tokens(struct token *tokens, int n, struct nanolight *nl)
}
-static void set_level(struct nanolight *nl, int val)
+static void set_level(struct lightctx *nl, int val)
{
int i;
@@ -210,7 +210,7 @@ static void set_level(struct nanolight *nl, int val)
}
-int command_run(const char *cmd, struct nanolight *nl)
+int command_run(const char *cmd, struct lightctx *nl)
{
struct token tokens[1024];
int i, n;
diff --git a/src/command.h b/src/command.h
index 2d540d4..a2ca7d9 100644
--- a/src/command.h
+++ b/src/command.h
@@ -23,6 +23,6 @@
#ifndef COMMAND_H
#define COMMAND_H
-extern int command_run(const char *cmd, struct nanolight *nl);
+extern int command_run(const char *cmd, struct lightctx *nl);
#endif /* COMMAND_H */
diff --git a/src/display.c b/src/display.c
index b61d847..5c27999 100644
--- a/src/display.c
+++ b/src/display.c
@@ -32,7 +32,7 @@
#include <libintl.h>
#define _(x) gettext(x)
-#include "nanolight.h"
+#include "lightctx.h"
#include "command.h"
#define OVERALL_BORDER (20.0)
@@ -56,7 +56,7 @@ int key_attrs[] = {
};
-static int fixture_selected(struct nanolight *nl, struct fixture *fix)
+static int fixture_selected(struct lightctx *nl, struct fixture *fix)
{
int i;
for ( i=0; i<nl->n_sel; i++ ) {
@@ -67,7 +67,7 @@ static int fixture_selected(struct nanolight *nl, struct fixture *fix)
static void draw_fixture(cairo_t *cr, PangoContext *pc, PangoFontDescription *fontdesc,
- struct nanolight *nl, struct fixture *fix)
+ struct lightctx *nl, struct fixture *fix)
{
PangoLayout *layout;
const double w = 40.0;
@@ -151,7 +151,7 @@ static const char *attr_text(int cls)
}
-static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct nanolight *nl)
+static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct lightctx *nl)
{
int w, h;
int ch;
@@ -229,7 +229,7 @@ static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct nanolight *nl)
}
-static void redraw(struct nanolight *nl)
+static void redraw(struct lightctx *nl)
{
gint w, h;
w = gtk_widget_get_allocated_width(GTK_WIDGET(nl->da));
@@ -238,7 +238,7 @@ static void redraw(struct nanolight *nl)
}
-static gboolean im_commit_sig(GtkIMContext *im, gchar *str, struct nanolight *nl)
+static gboolean im_commit_sig(GtkIMContext *im, gchar *str, struct lightctx *nl)
{
size_t cmd_len = strlen(nl->cmdline);
if ( cmd_len+strlen(str) > 1023 ) return FALSE;
@@ -261,7 +261,7 @@ static size_t delete_char(char *str)
}
-static void set_start_pantilt(struct nanolight *nl)
+static void set_start_pantilt(struct lightctx *nl)
{
int i;
for ( i=0; i<nl->n_sel; i++ ) {
@@ -272,7 +272,7 @@ static void set_start_pantilt(struct nanolight *nl)
}
-static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, struct nanolight *nl)
+static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, struct lightctx *nl)
{
#if 0
GdkSeat *seat;
@@ -291,14 +291,14 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, struct na
}
-static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event, struct nanolight *nl)
+static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event, struct lightctx *nl)
{
nl->dragging = 0;
return FALSE;
}
-static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, struct nanolight *nl)
+static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, struct lightctx *nl)
{
int i;
double x_inc, y_inc;
@@ -341,7 +341,7 @@ static gboolean motion_sig(GtkWidget *da, GdkEventMotion *event, struct nanoligh
}
-static void home_value(struct nanolight *nl)
+static void home_value(struct lightctx *nl)
{
int i;
for ( i=0; i<nl->n_sel; i++ ) {
@@ -371,7 +371,7 @@ static void home_value(struct nanolight *nl)
}
-static void execute_command(struct nanolight *nl)
+static void execute_command(struct lightctx *nl)
{
if ( command_run(nl->cmdline, nl) == 0 ) {
nl->cmdline[0] = '\0';
@@ -381,7 +381,7 @@ static void execute_command(struct nanolight *nl)
}
-static gboolean key_release_sig(GtkWidget *da, GdkEventKey *event, struct nanolight *nl)
+static gboolean key_release_sig(GtkWidget *da, GdkEventKey *event, struct lightctx *nl)
{
switch ( event->keyval ) {
@@ -398,7 +398,7 @@ static gboolean key_release_sig(GtkWidget *da, GdkEventKey *event, struct nanoli
}
-static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanolight *nl)
+static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct lightctx *nl)
{
gboolean r;
int claim = 1;
@@ -534,7 +534,7 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct nanoligh
}
-static gint realise_sig(GtkWidget *da, struct nanolight *nl)
+static gint realise_sig(GtkWidget *da, struct lightctx *nl)
{
GdkWindow *win = gtk_widget_get_window(da);
PangoContext *pc;
@@ -566,7 +566,7 @@ static gint realise_sig(GtkWidget *da, struct nanolight *nl)
}
-void create_main_window(struct nanolight *nl)
+void create_main_window(struct lightctx *nl)
{
GtkWidget *mainwindow;
GtkWidget *da;
diff --git a/src/display.h b/src/display.h
index eb4cb3e..9c42645 100644
--- a/src/display.h
+++ b/src/display.h
@@ -23,6 +23,6 @@
#ifndef DISPLAY_H
#define DISPLAY_H
-extern void create_main_window(struct nanolight *nl);
+extern void create_main_window(struct lightctx *nl);
#endif /* DISPLAY_H */
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;
+
+ }
+
+ }
+}
diff --git a/src/nanolight.h b/src/lightctx.h
index 66bde5a..8c25699 100644
--- a/src/nanolight.h
+++ b/src/lightctx.h
@@ -20,8 +20,8 @@
*
*/
-#ifndef NANOLIGHT_H
-#define NANOLIGHT_H
+#ifndef LIGHTCTX_H
+#define LIGHTCTX_H
#include <gtk/gtk.h>
@@ -132,7 +132,7 @@ struct fixture
};
-struct nanolight
+struct lightctx
{
int n_fixtures;
int max_fixtures;
@@ -160,8 +160,11 @@ struct nanolight
double y_orig;
};
-extern void attr_movex(struct nanolight *nl, signed int d, int fine);
-extern void attr_movey(struct nanolight *nl, signed int d, int fine);
+extern void attr_movex(struct lightctx *nl, signed int d, int fine);
+extern void attr_movey(struct lightctx *nl, signed int d, int fine);
+extern struct fixture *create_fixture(struct lightctx *nl, struct fixture_class *cls,
+ const char *label, int universe, int base_addr,
+ int flags);
-#endif /* NANOLIGHT_H */
+#endif /* LIGHTCTX_H */
diff --git a/src/nanolight.c b/src/nanolight.c
index 42bd068..b78a6f8 100644
--- a/src/nanolight.c
+++ b/src/nanolight.c
@@ -32,7 +32,7 @@
#include <libintl.h>
#define _(x) gettext(x)
-#include "nanolight.h"
+#include "lightctx.h"
#include "scanout.h"
#include "display.h"
@@ -44,153 +44,16 @@ static void show_help(const char *s)
}
-static struct fixture *create_fixture(struct nanolight *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 gboolean scanout_cb(gpointer data)
{
- scanout_all((struct nanolight *)data);
+ scanout_all((struct lightctx *)data);
return G_SOURCE_CONTINUE;
}
-static void cap_value(float *val, float min, float max)
-{
- if ( *val > max ) *val = max;
- if ( *val < min ) *val = min;
-}
-
-
-void attr_movex(struct nanolight *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 nanolight *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;
-
- }
-
- }
-}
-
-
int main(int argc, char *argv[])
{
- struct nanolight nl;
+ struct lightctx nl;
struct fixture_class cls;
int c;
diff --git a/src/scanout.c b/src/scanout.c
index 57a03da..ce7bfc9 100644
--- a/src/scanout.c
+++ b/src/scanout.c
@@ -26,7 +26,7 @@
#include <assert.h>
#include <libsoup/soup.h>
-#include "nanolight.h"
+#include "lightctx.h"
static void set_val(int *dmx, int base_addr, int attr_offset, float value, int sixteenbit)
{
@@ -98,7 +98,7 @@ static void set_gobo(int *dmx, struct fixture *fix, int gobo)
}
-int scanout_all(struct nanolight *nl)
+int scanout_all(struct lightctx *nl)
{
SoupSession *sess;
SoupMessage *msg;
diff --git a/src/scanout.h b/src/scanout.h
index b474112..379b63f 100644
--- a/src/scanout.h
+++ b/src/scanout.h
@@ -23,6 +23,6 @@
#ifndef SCANOUT_H
#define SCANOUT_H
-extern int scanout_all(struct nanolight *nl);
+extern int scanout_all(struct lightctx *nl);
#endif /* SCANOUT_H */