diff options
-rw-r--r-- | artnet.c | 15 | ||||
-rw-r--r-- | artnet.h | 4 | ||||
-rw-r--r-- | backend.c | 79 | ||||
-rw-r--r-- | backend.h | 3 | ||||
-rw-r--r-- | config.c | 5 | ||||
-rw-r--r-- | midi.c | 5 | ||||
-rw-r--r-- | midi.h | 1 | ||||
-rw-r--r-- | midimonster.c | 69 | ||||
-rw-r--r-- | midimonster.h | 5 | ||||
-rw-r--r-- | monster.cfg | 1 |
10 files changed, 123 insertions, 64 deletions
@@ -13,6 +13,7 @@ int artnet_init(){ .channel = artnet_channel, .handle = artnet_set, .process = artnet_handle, + .start = artnet_start, .shutdown = artnet_shutdown }; @@ -64,6 +65,15 @@ static int artnet_configure_instance(instance* instance, char* option, char* val data->uni = strtoul(value, NULL, 10); return 0; } + else if(!strcmp(option, "output")){ + if(!strcmp(value, "true")){ + data->mode |= MODE_OUTPUT; + } + else{ + data->mode &= ~MODE_OUTPUT; + } + return 0; + } fprintf(stderr, "Unknown ArtNet instance option %s\n", option); return 1; @@ -85,6 +95,11 @@ static int artnet_handle(size_t num, int* fd, void** data){ return 1; } +static int artnet_start(){ + //TODO + return 1; +} + static int artnet_shutdown(){ size_t n, p; instance** inst = NULL; @@ -7,9 +7,13 @@ static instance* artnet_instance(); static channel* artnet_channel(instance* instance, char* spec); static int artnet_set(size_t num, channel* c, channel_value* v); static int artnet_handle(size_t num, int* fd, void** data); +static int artnet_start(); static int artnet_shutdown(); +#define MODE_OUTPUT 1 + typedef struct /*_artnet_instance_model*/ { uint8_t net; uint8_t uni; + uint8_t mode; } artnet_instance_data; @@ -4,6 +4,66 @@ static size_t nbackends = 0; static backend* backends = NULL; +static size_t ninstances = 0; +static instance** instances = NULL; + +instance* mm_instance(){ + instance** new_inst = realloc(instances, (ninstances + 1) * sizeof(instance*)); + if(!new_inst){ + //TODO free + fprintf(stderr, "Failed to allocate memory\n"); + ninstances = 0; + return NULL; + } + instances = new_inst; + instances[ninstances] = calloc(1, sizeof(instance)); + if(!instances[ninstances]){ + fprintf(stderr, "Failed to allocate memory\n"); + return NULL; + } + + return instances[ninstances++]; +} + +int mm_backend_instances(char* name, size_t* ninst, instance*** inst){ + backend* b = backend_match(name); + size_t n = 0, u; + //count number of affected instances + for(u = 0; u < ninstances; u++){ + if(instances[u]->backend == b){ + n++; + } + } + + *ninst = n; + *inst = calloc(n, sizeof(instance*)); + if(!*inst){ + fprintf(stderr, "Failed to allocate memory\n"); + return 1; + } + + n = 0; + for(u = 0; u < ninstances; u++){ + if(instances[u]->backend == b){ + (*inst)[n] = instances[u]; + n++; + } + } + return 0; +} + +void instances_free(){ + size_t u; + for(u = 0; u < ninstances; u++){ + free(instances[u]->name); + instances[u]->name = NULL; + instances[u]->backend = NULL; + free(instances[u]); + instances[u] = NULL; + } + free(instances); + ninstances = 0; +} backend* backend_match(char* name){ size_t u; @@ -15,6 +75,16 @@ backend* backend_match(char* name){ return NULL; } +instance* instance_match(char* name){ + size_t u; + for(u = 0; u < ninstances; u++){ + if(!strcmp(instances[u]->name, name)){ + return instances[u]; + } + } + return NULL; +} + int mm_backend_register(backend b){ if(!backend_match(b.name)){ backends = realloc(backends, (nbackends + 1) * sizeof(backend)); @@ -32,6 +102,15 @@ int mm_backend_register(backend b){ return 1; } +int backends_start(){ + int rv = 0; + size_t u; + for(u = 0; u < nbackends; u++){ + rv |= backends[u].start(); + } + return rv; +} + int backends_stop(){ size_t u; for(u = 0; u < nbackends; u++){ @@ -1,2 +1,5 @@ backend* backend_match(char* name); +instance* instance_match(char* name); +int backends_start(); int backends_stop(); +void instances_free(); @@ -85,6 +85,11 @@ int config_read(char* cfg_file){ goto bail; } + if(instance_match(separator)){ + fprintf(stderr, "Duplicate instance name %s\n", separator); + goto bail; + } + current_instance = current_backend->create(); if(!current_instance){ fprintf(stderr, "Failed to instantiate backend %s\n", line); @@ -14,6 +14,7 @@ int midi_init(){ .channel = midi_channel, .handle = midi_set, .process = midi_handle, + .start = midi_start, .shutdown = midi_shutdown }; @@ -82,6 +83,10 @@ static int midi_handle(size_t num, int* fd, void** data){ return 1; } +static int midi_start(){ + return 1; +} + static int midi_shutdown(){ size_t n, p; instance** inst = NULL; @@ -7,4 +7,5 @@ static instance* midi_instance(); static channel* midi_channel(instance* instance, char* spec); static int midi_set(size_t num, channel* c, channel_value* v); static int midi_handle(size_t num, int* fd, void** data); +static int midi_start(); static int midi_shutdown(); diff --git a/midimonster.c b/midimonster.c index 765c1ce..e59b7f9 100644 --- a/midimonster.c +++ b/midimonster.c @@ -8,67 +8,6 @@ int artnet_init(); int midi_init(); int osc_init(); -static size_t ninstances = 0; -static instance** instances = NULL; - -instance* mm_instance(){ - instance** new_inst = realloc(instances, (ninstances + 1) * sizeof(instance*)); - if(!new_inst){ - //TODO free - fprintf(stderr, "Failed to allocate memory\n"); - ninstances = 0; - return NULL; - } - instances = new_inst; - instances[ninstances] = calloc(1, sizeof(instance)); - if(!instances[ninstances]){ - fprintf(stderr, "Failed to allocate memory\n"); - return NULL; - } - - return instances[ninstances++]; -} - -int mm_backend_instances(char* name, size_t* ninst, instance*** inst){ - backend* b = backend_match(name); - size_t n = 0, u; - //count number of affected instances - for(u = 0; u < ninstances; u++){ - if(instances[u]->backend == b){ - n++; - } - } - - *ninst = n; - *inst = calloc(n, sizeof(instance*)); - if(!*inst){ - fprintf(stderr, "Failed to allocate memory\n"); - return 1; - } - - n = 0; - for(u = 0; u < ninstances; u++){ - if(instances[u]->backend == b){ - (*inst)[n] = instances[u]; - n++; - } - } - return 0; -} - -static void instances_free(){ - size_t u; - for(u = 0; u < ninstances; u++){ - free(instances[u]->name); - instances[u]->name = NULL; - instances[u]->backend = NULL; - free(instances[u]); - instances[u] = NULL; - } - free(instances); - ninstances = 0; -} - int usage(char* fn){ fprintf(stderr, "MIDIMonster v0.1\n"); fprintf(stderr, "Usage:\n"); @@ -98,7 +37,13 @@ int main(int argc, char** argv){ return usage(argv[0]); } - //wait for events + //start backends + if(backends_start()){ + fprintf(stderr, "Failed to start backends\n"); + goto bail; + } + + //TODO wait for & translate events rv = EXIT_SUCCESS; bail: diff --git a/midimonster.h b/midimonster.h index f15d39c..9026222 100644 --- a/midimonster.h +++ b/midimonster.h @@ -34,19 +34,20 @@ typedef struct /*_mm_backend*/ { mmbackend_parse_channel channel; mmbackend_handle_event handle; mmbackend_process_fd process; + mmbackend_start start; mmbackend_shutdown shutdown; } backend; typedef struct _backend_instance { backend* backend; - size_t ident; + uint64_t ident; /*FIXME needed? identification provided by name*/ void* impl; char* name; } instance; typedef struct _backend_channel { instance* instance; - size_t ident; + uint64_t ident; void* impl; } channel; diff --git a/monster.cfg b/monster.cfg index ccb0d11..4bb7bd2 100644 --- a/monster.cfg +++ b/monster.cfg @@ -22,6 +22,7 @@ port = Translation Output 1 [artnet net1] net = 1 uni = 1 +output = true [artnet foo] net = 0 |