From d370095a576b2ea949ec2c169a9f081f1cb307b0 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 12 Nov 2017 16:50:03 +0100 Subject: Clarify some documentation, add debugging macro --- midimonster.h | 33 +++++++++++++++++++++++---------- monster.cfg | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/midimonster.h b/midimonster.h index 3cf6771..630399a 100644 --- a/midimonster.h +++ b/midimonster.h @@ -4,6 +4,13 @@ #include #include #define max(a,b) (((a) > (b)) ? (a) : (b)) +#ifdef DEBUG + #define DBGPF(format, ...) fprintf(stderr, (format), __VA_ARGS__) + #define DBG(message) fprintf(stderr, "%s", (message)) +#else + #define DBGPF(format, ...) + #define DBG(message) +#endif #define DEFAULT_CFG "monster.cfg" @@ -150,24 +157,30 @@ instance* mm_instance_find(char* backend, uint64_t ident); /* * Provides a pointer to a channel structure, pre-filled with * the provided instance reference and identifier. - * Will return previous allocations if the provided fields - * match. - * This API is just a convenience function. The array - * of channels is only used for mapping internally, - * creating and managing your own channel store is - * possible. - * For each channel with a non-NULL impl field, the backend - * will receive a call to its channel_free function. + * The `create` parameter is a boolean flag indicating whether + * a channel matching the `ident` parameter should be created if + * none exists. If the instance already registered a channel + * matching `ident`, a pointer to it is returned. + * This API is just a convenience function. The array of channels is + * only used for mapping internally, creating and managing your own + * channel store is possible. + * For each channel with a non-NULL `impl` field registered using + * this function, the backend will receive a call to its channel_free + * function. */ channel* mm_channel(instance* i, uint64_t ident, uint8_t create); //TODO channel* mm_channel_find() /* * Register a file descriptor to be selected on. The backend * will be notified via the mmbackend_process_fd call. - * This function may only be called from within the - * mmbackend_start procedure. + * This function may only be called from within the mmbackend_start + * procedure. */ int mm_manage_fd(int fd, char* backend, int manage, void* impl); +/* + * Notifies the core of a channel event. Used by backends to + * inject events gathered from their backing implementation. + */ int mm_channel_event(channel* c, channel_value v); /* * Query all active instances for a given backend. diff --git a/monster.cfg b/monster.cfg index c459262..558478e 100644 --- a/monster.cfg +++ b/monster.cfg @@ -22,3 +22,4 @@ dest = learn@8001 [map] osc1./1/xy:0 <> net1.1+2 osc1./1/xy:1 <> net1.3+4 +osc1./1/fader1 <> net1.20+21 -- cgit v1.2.3 From 06a87606cdef8af477c4341d764102c0d3f3e7e2 Mon Sep 17 00:00:00 2001 From: cbdev Date: Mon, 13 Nov 2017 03:08:49 +0100 Subject: Add debug messages --- backend.c | 6 ++++++ makefile | 1 + midimonster.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/backend.c b/backend.c index eeb789d..38abc7f 100644 --- a/backend.c +++ b/backend.c @@ -26,6 +26,7 @@ int backends_handle(size_t nfds, managed_fd* fds){ } } + DBGPF("Notifying backend %s of %zu waiting FDs\n", backends[u].name, n); rv |= backends[u].process(n, fds); } return rv; @@ -55,6 +56,7 @@ int backends_notify(size_t nev, channel** c, channel_value* v){ } } + DBGPF("Calling handler for instance %s with %zu events\n", instances[u]->name, n); rv |= instances[u]->backend->handle(instances[u], n, c, v); } @@ -65,14 +67,17 @@ channel* mm_channel(instance* i, uint64_t ident, uint8_t create){ size_t u; for(u = 0; u < nchannels; u++){ if(channels[u]->instance == i && channels[u]->ident == ident){ + DBGPF("Requested channel %zu on instance %s already exists, reusing\n", ident, i->name); return channels[u]; } } if(!create){ + DBGPF("Requested unknown channel %zu on instance %s\n", ident, i->name); return NULL; } + DBGPF("Creating previously unknown channel %zu on instance %s\n", ident, i->name); channel** new_chan = realloc(channels, (nchannels + 1) * sizeof(channel*)); if(!new_chan){ fprintf(stderr, "Failed to allocate memory\n"); @@ -169,6 +174,7 @@ void instances_free(){ void channels_free(){ size_t u; for(u = 0; u < nchannels; u++){ + DBGPF("Destroying channel %zu on instance %s\n", channels[u]->ident, channels[u]->instance->name); if(channels[u]->impl){ channels[u]->instance->backend->channel_free(channels[u]); } diff --git a/makefile b/makefile index 2101e96..f87005e 100644 --- a/makefile +++ b/makefile @@ -4,6 +4,7 @@ OBJS = config.o backend.o plugin.o PLUGINDIR = "\"./\"" CFLAGS ?= -g -Wall +#CFLAGS += -DDEBUG %.so: CFLAGS += -fPIC %.so: LDFLAGS += -shared diff --git a/midimonster.c b/midimonster.c index 8f30686..c8a0109 100644 --- a/midimonster.c +++ b/midimonster.c @@ -248,6 +248,7 @@ int main(int argc, char** argv){ } //create initial fd set + DBGPF("Building selector set from %zu FDs registered to core\n", fds); FD_ZERO(&all_fds); for(u = 0; u < fds; u++){ if(fd[u].fd >= 0){ @@ -277,6 +278,7 @@ int main(int argc, char** argv){ } //run backend processing, collect events + DBGPF("%zu backend FDs signaled\n", n); if(backends_handle(n, signaled_fds)){ fprintf(stderr, "Backends failed to handle input\n"); goto bail; @@ -284,6 +286,7 @@ int main(int argc, char** argv){ while(primary->n){ //swap primary and secondary event collectors + DBGPF("Swapping event collectors, %zu events in primary\n", primary->n); for(u = 0; u < sizeof(event_pool)/sizeof(event_collection); u++){ if(primary != event_pool + u){ secondary = primary; -- cgit v1.2.3 From 04e248a5e75e677f71b504cd9ad7f6ecf17b00a9 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 2 Dec 2017 17:33:17 +0100 Subject: Simplify config parsing, OSC keyboard sample config --- config.c | 3 +-- configs/osc-kbd.cfg | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 configs/osc-kbd.cfg diff --git a/config.c b/config.c index 708b057..72b662c 100644 --- a/config.c +++ b/config.c @@ -213,8 +213,7 @@ int config_read(char* cfg_file){ else{ //pass to parser //find separator - for(separator = line; *separator && *separator != '='; separator++){ - } + separator = strchr(line, '='); if(!*separator){ fprintf(stderr, "Not an assignment: %s\n", line); diff --git a/configs/osc-kbd.cfg b/configs/osc-kbd.cfg new file mode 100644 index 0000000..0abd131 --- /dev/null +++ b/configs/osc-kbd.cfg @@ -0,0 +1,25 @@ +; Maps a TouchOSC simpl keyboard layout to MIDI notes + +[backend midi] +name = MIDIMonster + +[midi out] +write = FLUID + +[osc pad] +bind = * 8000 +dest = learn@8001 + +[map] +pad./1/push1 > out.note0.60 +pad./1/push2 > out.note0.61 +pad./1/push3 > out.note0.62 +pad./1/push4 > out.note0.63 +pad./1/push5 > out.note0.64 +pad./1/push6 > out.note0.65 +pad./1/push7 > out.note0.66 +pad./1/push8 > out.note0.67 +pad./1/push9 > out.note0.68 +pad./1/push10 > out.note0.69 +pad./1/push11 > out.note0.70 +pad./1/push12 > out.note0.71 -- cgit v1.2.3 From 8874c3bff295f93f2012ae016d5d34270bdb1ebb Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 2 Dec 2017 17:38:07 +0100 Subject: Fix check on return value --- config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config.c b/config.c index 72b662c..f03d98a 100644 --- a/config.c +++ b/config.c @@ -214,8 +214,7 @@ int config_read(char* cfg_file){ //pass to parser //find separator separator = strchr(line, '='); - - if(!*separator){ + if(!separator){ fprintf(stderr, "Not an assignment: %s\n", line); goto bail; } -- cgit v1.2.3