diff options
author | cbdev <cb@cbcdn.com> | 2017-06-06 02:22:37 +0200 |
---|---|---|
committer | cbdev <cb@cbcdn.com> | 2017-06-06 02:22:37 +0200 |
commit | ebb683ae0f538e7842403d4ce28f4d8188f64373 (patch) | |
tree | 1c93601969de6f0a125a882a6a35dbad6fc3d2ba /midimonster.c | |
parent | 1cbf63996a51a67bdd221257d74adec61f03ea32 (diff) | |
download | midimonster-ebb683ae0f538e7842403d4ce28f4d8188f64373.tar.gz midimonster-ebb683ae0f538e7842403d4ce28f4d8188f64373.tar.bz2 midimonster-ebb683ae0f538e7842403d4ce28f4d8188f64373.zip |
Working MIDI translation
Diffstat (limited to 'midimonster.c')
-rw-r--r-- | midimonster.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/midimonster.c b/midimonster.c index 33858fd..b1c14e2 100644 --- a/midimonster.c +++ b/midimonster.c @@ -16,6 +16,10 @@ static size_t mappings = 0; static channel_mapping* map = NULL; static size_t fds = 0; static managed_fd* fd = NULL; +static size_t ev_alloc = 0; +static size_t evs = 0; +static channel** ev_channel = NULL; +static channel_value* ev_value = NULL; volatile static sig_atomic_t shutdown_requested = 0; void signal_handler(int signum){ @@ -40,6 +44,7 @@ int mm_map_channel(channel* from, channel* to){ } memset(map + mappings, 0, sizeof(channel_mapping)); mappings++; + map[u].from = from; } //check whether the target is already mapped @@ -134,11 +139,52 @@ void fds_free(){ } int mm_channel_event(channel* c, channel_value v){ - //TODO - fprintf(stderr, "Stub implementation: Channel on %s at value %f\n", c->instance->name, v.normalised); + size_t u, p; + + //find mapped channels + for(u = 0; u < mappings; u++){ + if(map[u].from == c){ + break; + } + } + + if(u == mappings){ + //target-only channel + return 0; + } + + //resize event structures to fit additional events + if(evs + map[u].destinations >= ev_alloc){ + ev_channel = realloc(ev_channel, (ev_alloc + map[u].destinations) * sizeof(channel*)); + ev_value = realloc(ev_value, (ev_alloc + map[u].destinations) * sizeof(channel_value)); + + if(!ev_channel || !ev_value){ + fprintf(stderr, "Failed to allocate memory\n"); + ev_alloc = 0; + evs = 0; + return 1; + } + + ev_alloc += map[u].destinations; + } + + //enqueue channel events + //FIXME this might lead to one channel being mentioned multiple times in an apply call + for(p = 0; p < map[u].destinations; p++){ + ev_channel[evs + p] = map[u].to[p]; + ev_value[evs + p] = v; + } + + evs += map[u].destinations; return 0; } +void event_free(){ + free(ev_channel); + free(ev_value); + ev_alloc = 0; +} + int usage(char* fn){ fprintf(stderr, "MIDIMonster v0.1\n"); fprintf(stderr, "Usage:\n"); @@ -225,7 +271,14 @@ int main(int argc, char** argv){ goto bail; } - //TODO push collected events to target backends + //push collected events to target backends + if(evs && backends_notify(evs, ev_channel, ev_value)){ + fprintf(stderr, "Backends failed to handle output\n"); + goto bail; + } + + //reset the event count + evs = 0; } rv = EXIT_SUCCESS; @@ -237,6 +290,7 @@ bail: instances_free(); map_free(); fds_free(); + event_free(); return rv; } |