aboutsummaryrefslogtreecommitdiffhomepage
path: root/midimonster.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2017-06-04 22:49:27 +0200
committercbdev <cb@cbcdn.com>2017-06-04 22:49:27 +0200
commitc47b0765a8605b9afcc6205a6d2396ccbe3d5e05 (patch)
tree6cea50c068b08f67039649ef0f76ad9df68b3d85 /midimonster.c
parent11e9dec049e64989c5f3656415d00c6c69851e8e (diff)
downloadmidimonster-c47b0765a8605b9afcc6205a6d2396ccbe3d5e05.tar.gz
midimonster-c47b0765a8605b9afcc6205a6d2396ccbe3d5e05.tar.bz2
midimonster-c47b0765a8605b9afcc6205a6d2396ccbe3d5e05.zip
Implement channel mapping
Diffstat (limited to 'midimonster.c')
-rw-r--r--midimonster.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/midimonster.c b/midimonster.c
index e59b7f9..aeaf04d 100644
--- a/midimonster.c
+++ b/midimonster.c
@@ -8,6 +8,48 @@ int artnet_init();
int midi_init();
int osc_init();
+static size_t mappings = 0;
+static channel_mapping* map = NULL;
+
+int mm_map_channel(channel* from, channel* to){
+ size_t u, m;
+ //find existing source mapping
+ for(u = 0; u < mappings; u++){
+ if(map[u].from == from){
+ break;
+ }
+ }
+
+ //create new entry
+ if(u == mappings){
+ map = realloc(map, (mappings + 1) * sizeof(channel_mapping));
+ if(!map){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return 1;
+ }
+ memset(map + mappings, 0, sizeof(channel_mapping));
+ mappings++;
+ }
+
+ //check whether the target is already mapped
+ for(m = 0; m < map[u].destinations; m++){
+ if(map[u].to[m] == to){
+ return 0;
+ }
+ }
+
+ map[u].to = realloc(map[u].to, (map[u].destinations + 1) * sizeof(channel*));
+ if(!map[u].to){
+ fprintf(stderr, "Failed to allocate memory\n");
+ map[u].destinations = 0;
+ return 1;
+ }
+
+ map[u].to[map[u].destinations] = to;
+ map[u].destinations++;
+ return 0;
+}
+
int usage(char* fn){
fprintf(stderr, "MIDIMonster v0.1\n");
fprintf(stderr, "Usage:\n");
@@ -49,6 +91,7 @@ int main(int argc, char** argv){
bail:
//free all data
backends_stop();
+ channels_free();
instances_free();
return rv;