From 65bd41387c8dbf67812de1881198a47c9bb4b55e Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 5 Oct 2019 19:30:22 +0200 Subject: Implement detect option for winmidi --- backends/maweb.c | 7 ++++--- backends/midi.c | 3 +-- backends/winmidi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) (limited to 'backends') diff --git a/backends/maweb.c b/backends/maweb.c index baa516a..c98d04b 100644 --- a/backends/maweb.c +++ b/backends/maweb.c @@ -5,7 +5,6 @@ #include #endif -#define DEBUG #include "libmmbackend.h" #include "maweb.h" @@ -891,10 +890,12 @@ static int maweb_set(instance* inst, size_t num, channel** c, channel_value* v){ snprintf(xmit_buffer, sizeof(xmit_buffer), "{\"keyname\":\"%s\"," "\"autoSubmit\":%s," - "\"value\":%d" + "\"value\":%d," + "\"session\":%" PRIu64 "}", cmdline_keys[chan->index].name, cmdline_keys[chan->index].auto_submit ? "true" : "null", - (v[n].normalised > 0.9) ? 1 : 0); + (v[n].normalised > 0.9) ? 1 : 0, + data->session); } else{ continue; diff --git a/backends/midi.c b/backends/midi.c index d9ac698..536457d 100644 --- a/backends/midi.c +++ b/backends/midi.c @@ -56,8 +56,7 @@ static int midi_configure(char* option, char* value){ sequencer_name = strdup(value); return 0; } - - if(!strcmp(option, "detect")){ + else if(!strcmp(option, "detect")){ midi_config.detect = 1; if(!strcmp(value, "off")){ midi_config.detect = 0; diff --git a/backends/winmidi.c b/backends/winmidi.c index 13c4b4a..83d0c7e 100644 --- a/backends/winmidi.c +++ b/backends/winmidi.c @@ -9,6 +9,7 @@ static struct { uint8_t list_devices; + uint8_t detect; int socket_pair[2]; CRITICAL_SECTION push_events; @@ -60,6 +61,13 @@ static int winmidi_configure(char* option, char* value){ } return 0; } + else if(!strcmp(option, "detect")){ + backend_config.detect = 0; + if(!strcmp(value, "on")){ + backend_config.detect = 1; + } + return 0; + } fprintf(stderr, "Unknown winmidi backend option %s\n", option); return 1; @@ -232,6 +240,22 @@ static int winmidi_set(instance* inst, size_t num, channel** c, channel_value* v return 0; } +static char* winmidi_type_name(uint8_t typecode){ + switch(typecode){ + case note: + return "note"; + case cc: + return "cc"; + case pressure: + return "pressure"; + case aftertouch: + return "aftertouch"; + case pitchbend: + return "pitch"; + } + return "unknown"; +} + static int winmidi_handle(size_t num, managed_fd* fds){ size_t u; ssize_t bytes = 0; @@ -249,6 +273,23 @@ static int winmidi_handle(size_t num, managed_fd* fds){ //push queued events EnterCriticalSection(&backend_config.push_events); for(u = 0; u < backend_config.events_active; u++){ + if(backend_config.detect){ + //pretty-print channel-wide events + if(backend_config.event[u].channel.fields.type == pitchbend + || backend_config.event[u].channel.fields.type == aftertouch){ + fprintf(stderr, "Incoming MIDI data on channel %s.ch%d.%s\n", + backend_config.event[u].inst->name, + backend_config.event[u].channel.fields.channel, + winmidi_type_name(backend_config.event[u].channel.fields.type)); + } + else{ + fprintf(stderr, "Incoming MIDI data on channel %s.ch%d.%s%d\n", + backend_config.event[u].inst->name, + backend_config.event[u].channel.fields.channel, + winmidi_type_name(backend_config.event[u].channel.fields.type), + backend_config.event[u].channel.fields.control); + } + } chan = mm_channel(backend_config.event[u].inst, backend_config.event[u].channel.label, 0); if(chan){ mm_channel_event(chan, backend_config.event[u].value); -- cgit v1.2.3