Browse Source

Move toward a plugin API

master
Gavan Fantom 18 years ago
parent
commit
bafa106f11
  1. 4
      src/lsi/Makefile
  2. 4
      src/lsi/beatdetect.c
  3. 2
      src/lsi/beatdetect.h
  4. 3
      src/lsi/dmx.c
  5. 2
      src/lsi/dmx.h
  6. 41
      src/lsi/main.c
  7. 3
      src/lsi/midi.c
  8. 2
      src/lsi/midi.h
  9. 4
      src/lsi/mouse.c
  10. 2
      src/lsi/mouse.h

4
src/lsi/Makefile

@ -2,8 +2,8 @@
PREFIX?= /usr/local PREFIX?= /usr/local
OBJS= main.o vm.o dmx.o midi.o beatdetect.o fft.o map3d.o mouse.o OBJS= main.o vm.o plugins.o dmx.o midi.o beatdetect.o fft.o map3d.o mouse.o
SRCS= main.c vm.c dmx.c midi.c beatdetect.c fft.c map3d.c mouse.c SRCS= main.c vm.c plugins.c dmx.c midi.c beatdetect.c fft.c map3d.c mouse.c
COMMONOBJS= mem.o hash.o COMMONOBJS= mem.o hash.o
COMMONDIR= ../common COMMONDIR= ../common

4
src/lsi/beatdetect.c

@ -114,7 +114,7 @@ double beatdetect_getconfidence(void)
return confidence; return confidence;
} }
void beatdetect_init(void) int beatdetect_init(void)
{ {
audio_info_t info, oinfo; audio_info_t info, oinfo;
@ -156,6 +156,8 @@ void beatdetect_init(void)
/* vm_register_blah */ /* vm_register_blah */
vm_register_signal_fd(audiofd, VM_BEATQ); vm_register_signal_fd(audiofd, VM_BEATQ);
return 1;
} }
int beatdetect_read(void) int beatdetect_read(void)

2
src/lsi/beatdetect.h

@ -1,6 +1,6 @@
/* beatdetect.h */ /* beatdetect.h */
void beatdetect_init(void); int beatdetect_init(void);
void beatdetect_close(void); void beatdetect_close(void);
double beatdetect_getphase(void); double beatdetect_getphase(void);
double beatdetect_getconfidence(void); double beatdetect_getconfidence(void);

3
src/lsi/dmx.c

@ -92,7 +92,7 @@ out:
printf("%x %x %x %x %x %x %x %x %x %x %x %x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); printf("%x %x %x %x %x %x %x %x %x %x %x %x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
} }
void dmx_init(void) int dmx_init(void)
{ {
dmx_open(); dmx_open();
dmxpacket[0] = 0x7e; dmxpacket[0] = 0x7e;
@ -104,6 +104,7 @@ void dmx_init(void)
dmxpacket[DMX_UNIVERSESIZE+5] = 0xe7; dmxpacket[DMX_UNIVERSESIZE+5] = 0xe7;
dmxuniverse = dmxpacket+5; dmxuniverse = dmxpacket+5;
// dmx_dumpparams(); // dmx_dumpparams();
return 1;
} }
void dmx_setchannel(int channel, int value) void dmx_setchannel(int channel, int value)

2
src/lsi/dmx.h

@ -3,7 +3,7 @@
#define DMX_UNIVERSESIZE 512 #define DMX_UNIVERSESIZE 512
void dmx_close(void); void dmx_close(void);
void dmx_init(void); int dmx_init(void);
void dmx_setchannel(int channel, int value); void dmx_setchannel(int channel, int value);
void dmx_output(void); void dmx_output(void);

41
src/lsi/main.c

@ -2,18 +2,25 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <err.h> #include <err.h>
#include "vm.h" #include "vm.h"
#include "dmx.h" #include "plugins.h"
#include "midi.h"
#include "beatdetect.h" /* This macro exists purely to shorten subsequent lines for readability */
#include "mouse.h" #define PT(i) plugins_table[i]
void finish(void) void finish(void)
{ {
dmx_close(); int i;
midi_close();
beatdetect_close(); for (i = nplugins-1; i >= 0; i--) {
printf("Shutting down plugin '%s'\n", PT(i).pl_name);
(PT(i).pl_init)();
printf("Plugin '%s' shut down\n", PT(i).pl_name);
PT(i).pl_active = 0;
}
exit(0); exit(0);
} }
@ -24,6 +31,8 @@ void sigint_handler(int signal)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i;
argv++; argv++;
argc--; argc--;
if (argc != 1) if (argc != 1)
@ -31,10 +40,20 @@ int main(int argc, char *argv[])
vm_init(); vm_init();
vm_load(argv[0]); vm_load(argv[0]);
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
midi_init();
dmx_init(); /* Initialise plugins */
beatdetect_init(); for (i = 0; i < nplugins; i++) {
mouse_init(); printf("Initialising plugin '%s'\n", PT(i).pl_name);
if ((PT(i).pl_init)()) {
printf("Plugin '%s' initialised\n", PT(i).pl_name);
PT(i).pl_active = 1;
} else {
printf("Plugin '%s' failed\n", PT(i).pl_name);
PT(i).pl_active = 0;
}
}
/* Showtime */
vm_spawn("main"); vm_spawn("main");
vm_run(); vm_run();
finish(); finish();

3
src/lsi/midi.c

@ -16,7 +16,7 @@ int midi_bytes;
seq_event_rec midi_buf; seq_event_rec midi_buf;
int midi_initialised = 0; int midi_initialised = 0;
void midi_init(void) int midi_init(void)
{ {
midi_fd = open(PORT, O_NONBLOCK | O_RDONLY, 0); midi_fd = open(PORT, O_NONBLOCK | O_RDONLY, 0);
if (midi_fd == -1) { if (midi_fd == -1) {
@ -25,6 +25,7 @@ void midi_init(void)
midi_bytes = 0; midi_bytes = 0;
midi_initialised = 1; midi_initialised = 1;
vm_register_signal_fd(midi_fd, VM_MIDIQ); vm_register_signal_fd(midi_fd, VM_MIDIQ);
return 1;
} }
void midi_close(void) void midi_close(void)

2
src/lsi/midi.h

@ -1,6 +1,6 @@
/* midi.h */ /* midi.h */
void midi_init(void); int midi_init(void);
void midi_close(void); void midi_close(void);
int midi_filter(void); int midi_filter(void);
int midi_read(void); int midi_read(void);

4
src/lsi/mouse.c

@ -50,7 +50,7 @@ struct wscons_event mouse_buf;
int mouse_initialised = 0; int mouse_initialised = 0;
int mouse_x, mouse_y, mouse_z; int mouse_x, mouse_y, mouse_z;
void mouse_init(void) int mouse_init(void)
{ {
mouse_fd = open(MOUSEDEVICE, O_RDONLY); mouse_fd = open(MOUSEDEVICE, O_RDONLY);
if (mouse_fd < 0) if (mouse_fd < 0)
@ -61,6 +61,8 @@ void mouse_init(void)
mouse_x = 0; mouse_x = 0;
mouse_y = 0; mouse_y = 0;
mouse_z = 0; mouse_z = 0;
return 1;
} }
void mouse_close(void) void mouse_close(void)

2
src/lsi/mouse.h

@ -1,6 +1,6 @@
/* mouse.h */ /* mouse.h */
void mouse_init(void); int mouse_init(void);
void mouse_close(void); void mouse_close(void);
int mouse_filter(void); int mouse_filter(void);
void mouse_getpos(int *, int *, int *); void mouse_getpos(int *, int *, int *);

Loading…
Cancel
Save