From 4f467a30f88a628e0e49858986d9278e12a92ce5 Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 1 May 2020 16:49:49 +0200 Subject: Implement wininput skeleton and mouse output --- backends/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index 700c9b3..9b66728 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -1,6 +1,6 @@ .PHONY: all clean full LINUX_BACKENDS = midi.so evdev.so -WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll +WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so OPTIONAL_BACKENDS = ola.so BACKEND_LIB = libmmbackend.o -- cgit v1.2.3 From 9b9256b55ec4f61f14d5199be2a010ad3aeb1896 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 10 May 2020 12:58:52 +0200 Subject: Refactor wininput channel parsing, implement basic joystick queries --- backends/Makefile | 2 + backends/wininput.c | 167 ++++++++++++++++++++++++++++------------------------ 2 files changed, 92 insertions(+), 77 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index 9b66728..dbb9f55 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -53,6 +53,8 @@ rtpmidi.dll: LDLIBS += -lws2_32 -liphlpapi winmidi.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) winmidi.dll: LDLIBS += -lwinmm -lws2_32 +wininput.dll: LDLIBS += -lwinmm + jack.so: LDLIBS = -ljack -lpthread midi.so: LDLIBS = -lasound evdev.so: CFLAGS += $(shell pkg-config --cflags libevdev || echo "-DBUILD_ERROR=\"Missing pkg-config data for libevdev\"") diff --git a/backends/wininput.c b/backends/wininput.c index 0c7e490..f5303cc 100644 --- a/backends/wininput.c +++ b/backends/wininput.c @@ -4,8 +4,9 @@ #include #include "wininput.h" +#include + //TODO check whether feedback elimination is required -//TODO refactor & simplify static key_info keys[] = { {VK_LBUTTON, "lmb", button}, {VK_RBUTTON, "rmb", button}, {VK_MBUTTON, "mmb", button}, @@ -117,16 +118,16 @@ static int wininput_instance(instance* inst){ return 0; } -static int wininput_subscribe(wininput_channel_ident ident, channel* chan){ +static int wininput_subscribe(uint64_t ident, channel* chan){ size_t u, n; //find an existing request for(u = 0; u < cfg.requests; u++){ - if(cfg.request[u].ident.label == ident.label){ + if(cfg.request[u].ident.label == ident){ break; } } - + if(u == cfg.requests){ //create a new request cfg.request = realloc(cfg.request, (cfg.requests + 1) * sizeof(wininput_request)); @@ -136,7 +137,7 @@ static int wininput_subscribe(wininput_channel_ident ident, channel* chan){ return 1; } - cfg.request[u].ident.label = ident.label; + cfg.request[u].ident.label = ident; cfg.request[u].channels = 0; cfg.request[u].channel = NULL; cfg.request[u].state = 0; @@ -162,95 +163,96 @@ static int wininput_subscribe(wininput_channel_ident ident, channel* chan){ return 0; } -static channel* wininput_channel(instance* inst, char* spec, uint8_t flags){ +static uint64_t wininput_channel_mouse(instance* inst, char* spec, uint8_t flags){ size_t u; - channel* chan = NULL; - uint16_t scancode = 0; - char* token = spec; wininput_channel_ident ident = { - .label = 0 + .fields.type = mouse }; - if(!strncmp(spec, "mouse.", 6)){ - //TODO wheel - token += 6; - ident.fields.type = mouse; - if(!strcmp(token, "x")){ - ident.fields.channel = position; - } - else if(!strcmp(token, "y")){ - ident.fields.channel = position; - ident.fields.control = 1; - } - else{ - //check the buttons - for(u = 0; u < sizeof(keys) / sizeof(keys[0]); u++){ - if(keys[u].channel == button && !strcmp(keys[u].name, token)){ - DBGPF("Using keymap %" PRIsize_t " (%d) for spec %s", u, keys[u].keycode, token); - ident.fields.channel = button; - ident.fields.control = keys[u].keycode; - break; - } - } - - if(u == sizeof(keys) / sizeof(keys[0])){ - LOGPF("Unknown mouse control %s", token); - return NULL; - } - } + if(!strcmp(spec, "x")){ + ident.fields.channel = position; } - else if(!strncmp(spec, "key.", 4)){ - token += 4; - ident.fields.type = keyboard; - ident.fields.channel = keypress; - + else if(!strcmp(spec, "y")){ + ident.fields.channel = position; + ident.fields.control = 1; + } + else{ + //check the buttons for(u = 0; u < sizeof(keys) / sizeof(keys[0]); u++){ - if(keys[u].channel == keypress && !strcmp(keys[u].name, token)){ - DBGPF("Using keymap %" PRIsize_t " (%d) for spec %s", u, keys[u].keycode, token); + if(keys[u].channel == button && !strcmp(keys[u].name, spec)){ + DBGPF("Using keymap %" PRIsize_t " (%d) for spec %s", u, keys[u].keycode, spec); + ident.fields.channel = button; ident.fields.control = keys[u].keycode; break; } } - //no entry in translation table if(u == sizeof(keys) / sizeof(keys[0])){ - if(strlen(token) == 1){ - //try to translate - scancode = VkKeyScan(token[0]); - if(scancode != 0x7f7f){ - DBGPF("Using keyscan result %02X (via %04X) for spec %s", scancode & 0xFF, scancode, token); - ident.fields.type = keyboard; - ident.fields.channel = keypress; - ident.fields.control = scancode & 0xFF; - } - else{ - LOGPF("Invalid channel specification %s", token); - return NULL; - } - } - else if(strlen(token) > 1){ - //try to use as literal - scancode = strtoul(token, NULL, 0); - if(!scancode){ - LOGPF("Invalid channel specification %s", token); - return NULL; - } - DBGPF("Using direct conversion %d for spec %s", scancode & 0xFF, token); - ident.fields.control = scancode & 0xFF; - } - else{ - LOGPF("Invalid channel specification %s", spec); - return NULL; - } + LOGPF("Unknown mouse control %s", spec); + return 0; } } + + return ident.label; +} + +static uint64_t wininput_channel_key(instance* inst, char* spec, uint8_t flags){ + size_t u; + uint16_t scancode = 0; + wininput_channel_ident ident = { + .fields.type = keyboard, + .fields.channel = keypress + }; + + for(u = 0; u < sizeof(keys) / sizeof(keys[0]); u++){ + if(keys[u].channel == keypress && !strcmp(keys[u].name, spec)){ + DBGPF("Using keymap %" PRIsize_t " (%d) for spec %s", u, keys[u].keycode, spec); + ident.fields.control = keys[u].keycode; + return ident.label; + } + } + + //no entry in translation table + if(strlen(spec) == 1){ + //try to translate + scancode = VkKeyScan(spec[0]); + if(scancode != 0x7f7f){ + DBGPF("Using keyscan result %02X (via %04X) for spec %s", scancode & 0xFF, scancode, spec); + ident.fields.control = scancode & 0xFF; + return ident.label; + } + } + else if(strlen(spec) > 1){ + //try to use as literal + scancode = strtoul(spec, NULL, 0); + if(scancode){ + DBGPF("Using direct conversion %d for spec %s", scancode & 0xFF, spec); + ident.fields.control = scancode & 0xFF; + return ident.label; + } + } + + LOGPF("Invalid channel specification %s", spec); + return 0; +} + +static channel* wininput_channel(instance* inst, char* spec, uint8_t flags){ + channel* chan = NULL; + uint64_t label = 0; + + if(!strncmp(spec, "mouse.", 6)){ + label = wininput_channel_mouse(inst, spec + 6, flags); + } + else if(!strncmp(spec, "key.", 4)){ + label = wininput_channel_key(inst, spec + 4, flags); + } else{ - LOGPF("Unknown channel spec %s", spec); + LOGPF("Unknown channel spec type %s", spec); } - if(ident.label){ - chan = mm_channel(inst, ident.label, 1); - if(chan && (flags & mmchannel_input) && wininput_subscribe(ident, chan)){ + if(label){ + chan = mm_channel(inst, label, 1); + if(chan && (flags & mmchannel_input) && wininput_subscribe(label, chan)){ return NULL; } return chan; @@ -448,13 +450,24 @@ static int wininput_handle(size_t num, managed_fd* fds){ } static int wininput_start(size_t n, instance** inst){ + size_t u; POINT cursor_position; + JOYINFOEX joy_info; //if no input requested, don't request polling if(!cfg.requests){ cfg.interval = 0; } + DBGPF("This system supports a maximum of %u joysticks", joyGetNumDevs()); + for(u = 0; u < joyGetNumDevs(); u++){ + joy_info.dwSize = sizeof(joy_info); + joy_info.dwFlags = 0; + if(joyGetPosEx(u, &joy_info) == JOYERR_NOERROR){ + LOGPF("Joystick %" PRIsize_t " is available for input", u); + } + } + //read virtual desktop extents for later normalization cfg.virtual_width = GetSystemMetrics(SM_CXVIRTUALSCREEN); cfg.virtual_height = GetSystemMetrics(SM_CYVIRTUALSCREEN); -- cgit v1.2.3 From 4e5cc42d2eb245bfd2ac616ca6898e4855ec5363 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 27 Jun 2020 19:26:26 +0200 Subject: Remove manually built backends with clean target --- backends/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index dbb9f55..09f5b96 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -3,6 +3,7 @@ LINUX_BACKENDS = midi.so evdev.so WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so OPTIONAL_BACKENDS = ola.so +MANUAL_BACKENDS = lua.dll BACKEND_LIB = libmmbackend.o SYSTEM := $(shell uname -s) @@ -97,4 +98,4 @@ windows: ../libmmapi.a $(BACKEND_LIB) $(WINDOWS_BACKENDS) full: $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) clean: - $(RM) $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) $(WINDOWS_BACKENDS) + $(RM) $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) $(WINDOWS_BACKENDS) $(MANUAL_BACKENDS) -- cgit v1.2.3 From 690aec061db4cfab50b998822628f732e115e11e Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 15 Aug 2020 11:15:01 +0200 Subject: Improve some documentation --- README.md | 2 +- backends/Makefile | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'backends/Makefile') diff --git a/README.md b/README.md index ea079bf..3a3fcbd 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ side must have exactly one channel. Example multi-channel mapping: ``` -instance-a.channel{1..5} > instance-b.{1,2,3,4,5} +instance-a.channel{1..5} > instance-b.{a,b,c,d,e} ``` ## Backend documentation diff --git a/backends/Makefile b/backends/Makefile index 09f5b96..4f89b43 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -1,17 +1,26 @@ .PHONY: all clean full +# Backends that can only be built on Linux LINUX_BACKENDS = midi.so evdev.so -WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll -BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so +# Backends that can only be built on Windows (mostly due to the .DLL extension) +WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll visca.dll +# Backends that can be built on any platform that can load .SO libraries +BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so visca.so +# Backends that require huge dependencies to be installed OPTIONAL_BACKENDS = ola.so +# Backends that need to be built manually (but still should be included in the clean target) MANUAL_BACKENDS = lua.dll + +# The backend library, providing platform-independent abstractions for common things BACKEND_LIB = libmmbackend.o +# Evaluate which system we are on SYSTEM := $(shell uname -s) # Generate debug symbols unless overridden CFLAGS ?= -g CPPFLAGS ?= -g +# All backends are shared libraries CFLAGS += -fPIC -I../ -Wall -Wpedantic CPPFLAGS += -fPIC -I../ LDFLAGS += -shared @@ -25,6 +34,7 @@ ifeq ($(SYSTEM),Darwin) LDFLAGS += -undefined dynamic_lookup endif +# Most of these next few backends just pull in the backend lib, some set additional flags artnet.so: ADDITIONAL_OBJS += $(BACKEND_LIB) artnet.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) artnet.dll: LDLIBS += -lws2_32 @@ -37,6 +47,10 @@ sacn.so: ADDITIONAL_OBJS += $(BACKEND_LIB) sacn.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) sacn.dll: LDLIBS += -lws2_32 +visca.so: ADDITIONAL_OBJS += $(BACKEND_LIB) +visca.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) +visca.dll: LDLIBS += -lws2_32 + openpixelcontrol.so: ADDITIONAL_OBJS += $(BACKEND_LIB) openpixelcontrol.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) openpixelcontrol.dll: LDLIBS += -lws2_32 @@ -73,6 +87,7 @@ lua.dll: LDLIBS += -L../ -llua53 python.so: CFLAGS += $(shell pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") python.so: CFLAGS += $(shell pkg-config --libs python3 || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +# Generic rules on how to build .SO/.DLL's from C and CPP sources %.so :: %.c %.h $(BACKEND_LIB) $(CC) $(CFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) @@ -82,11 +97,14 @@ python.so: CFLAGS += $(shell pkg-config --libs python3 || pkg-config --libs pyth %.so :: %.cpp %.h $(CXX) $(CPPFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) +# This is the actual first named target, and thus the default all: $(BACKEND_LIB) $(BACKENDS) +# Build an import lib for the windows build if it's not already there ../libmmapi.a: $(MAKE) -C ../ midimonster.exe +# Override a bunch of stuff for the windows target and it's DLL dependencies %.dll: export CC = x86_64-w64-mingw32-gcc %.dll: LDLIBS += -lmmapi %.dll: LDFLAGS += -L../ @@ -95,7 +113,9 @@ windows: CFLAGS += -Wno-format -Wno-pointer-sign windows: export CC = x86_64-w64-mingw32-gcc windows: ../libmmapi.a $(BACKEND_LIB) $(WINDOWS_BACKENDS) +# Optional target including the backends that require large dependencies full: $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) +# Clean up all generated files clean: $(RM) $(BACKEND_LIB) $(BACKENDS) $(OPTIONAL_BACKENDS) $(WINDOWS_BACKENDS) $(MANUAL_BACKENDS) -- cgit v1.2.3 From bb122923379f3439c62241652b82ed403ad835f7 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 24 Oct 2020 12:31:27 +0200 Subject: Add generic lua pkg-config data --- TODO | 4 ++++ backends/Makefile | 6 +++--- backends/visca.c | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'backends/Makefile') diff --git a/TODO b/TODO index 44336d4..5662479 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,7 @@ make event collectors threadsafe to stop marshalling data... collect & check backend API version move all connection establishment to _start to be able to hot-stop/start all backends event deduplication in core? + +per-channel filters + * invert + * edge detection diff --git a/backends/Makefile b/backends/Makefile index 4f89b43..d815f84 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -79,9 +79,9 @@ ola.so: CPPFLAGS += -Wno-write-strings # The pkg-config name for liblua5.3 is subject to discussion. I prefer 'lua5.3' (which works on Debian and OSX), # but Arch requires 'lua53' which works on Debian, too, but breaks on OSX. -lua.so: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5.3 || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") -lua.so: LDLIBS += $(shell pkg-config --libs lua53 || pkg-config --libs lua5.3 || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") -lua.dll: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5.3 || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") +lua.so: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5.3 || pkg-config --cflags lua || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") +lua.so: LDLIBS += $(shell pkg-config --libs lua53 || pkg-config --libs lua5.3 || pkg-config --libs lua || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") +lua.dll: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5.3 || pkg-config --cflags lua || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") lua.dll: LDLIBS += -L../ -llua53 python.so: CFLAGS += $(shell pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") diff --git a/backends/visca.c b/backends/visca.c index 9f398a2..ba81f8d 100644 --- a/backends/visca.c +++ b/backends/visca.c @@ -8,8 +8,9 @@ /* TODO * VISCA server - * Rate limiting + * Command output rate limiting / deduplication * Inquiry + * Reconnect on connection close */ MM_PLUGIN_API int init(){ -- cgit v1.2.3 From 378c38aee6dae85c75be924e04f0ba5f90145518 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 6 Dec 2020 17:11:46 +0100 Subject: Add MQTT backend to backend makefile --- backends/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index d815f84..aa9c988 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -2,9 +2,9 @@ # Backends that can only be built on Linux LINUX_BACKENDS = midi.so evdev.so # Backends that can only be built on Windows (mostly due to the .DLL extension) -WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll visca.dll +WINDOWS_BACKENDS = artnet.dll osc.dll loopback.dll sacn.dll maweb.dll winmidi.dll openpixelcontrol.dll rtpmidi.dll wininput.dll visca.dll mqtt.dll # Backends that can be built on any platform that can load .SO libraries -BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so visca.so +BACKENDS = artnet.so osc.so loopback.so sacn.so lua.so maweb.so jack.so openpixelcontrol.so python.so rtpmidi.so visca.so mqtt.so # Backends that require huge dependencies to be installed OPTIONAL_BACKENDS = ola.so # Backends that need to be built manually (but still should be included in the clean target) @@ -51,6 +51,10 @@ visca.so: ADDITIONAL_OBJS += $(BACKEND_LIB) visca.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) visca.dll: LDLIBS += -lws2_32 +mqtt.so: ADDITIONAL_OBJS += $(BACKEND_LIB) +mqtt.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) +mqtt.dll: LDLIBS += -lws2_32 + openpixelcontrol.so: ADDITIONAL_OBJS += $(BACKEND_LIB) openpixelcontrol.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) openpixelcontrol.dll: LDLIBS += -lws2_32 -- cgit v1.2.3 From a89dcd7942958e0ebe5881dde4820ceb77d29e9b Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 23 Jun 2021 22:27:15 +0200 Subject: Fix build with recent environments, fix Coverity CID 371602 and 355842 --- backends/Makefile | 12 +++++++----- backends/mqtt.c | 7 ++++--- backends/rtpmidi.c | 11 ++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index aa9c988..4697a5a 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -60,7 +60,7 @@ openpixelcontrol.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) openpixelcontrol.dll: LDLIBS += -lws2_32 maweb.so: ADDITIONAL_OBJS += $(BACKEND_LIB) -maweb.so: LDLIBS = -lssl +maweb.so: LDLIBS = $(shell pkg-config --libs openssl || echo "-DBUILD_ERROR=\"Missing pkg-config data for openssl\"") maweb.dll: ADDITIONAL_OBJS += $(BACKEND_LIB) maweb.dll: LDLIBS += -lws2_32 maweb.dll: CFLAGS += -DMAWEB_NO_LIBSSL @@ -88,18 +88,20 @@ lua.so: LDLIBS += $(shell pkg-config --libs lua53 || pkg-config --libs lua5.3 || lua.dll: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5.3 || pkg-config --cflags lua || echo "-DBUILD_ERROR=\"Missing pkg-config data for lua53\"") lua.dll: LDLIBS += -L../ -llua53 -python.so: CFLAGS += $(shell pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") -python.so: CFLAGS += $(shell pkg-config --libs python3 || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +# Python seems to ship their own little python3-config tool instead of properly maintaining their pkg-config files. +# This one also spams a good deal of unwanted flags into CFLAGS, so we use only --includes and --libs +python.so: CFLAGS += $(shell python3-config --includes || pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.so: LDLIBS += $(shell python3-config --libs || pkg-config --libs python3 || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") # Generic rules on how to build .SO/.DLL's from C and CPP sources %.so :: %.c %.h $(BACKEND_LIB) - $(CC) $(CFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) + $(CC) $(CFLAGS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) $(LDLIBS) %.dll :: %.c %.h $(BACKEND_LIB) $(CC) $(CFLAGS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) $(LDLIBS) %.so :: %.cpp %.h - $(CXX) $(CPPFLAGS) $(LDLIBS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) + $(CXX) $(CPPFLAGS) $< $(ADDITIONAL_OBJS) -o $@ $(LDFLAGS) $(LDLIBS) # This is the actual first named target, and thus the default all: $(BACKEND_LIB) $(BACKENDS) diff --git a/backends/mqtt.c b/backends/mqtt.c index f2a7c83..47042f1 100644 --- a/backends/mqtt.c +++ b/backends/mqtt.c @@ -775,14 +775,15 @@ static int mqtt_handle_publish(instance* inst, uint8_t type, uint8_t* variable_h property_offset += mqtt_pop_varint(variable_header + property_offset, length - property_offset, NULL); //parse properties - while(property_offset < payload_offset){ + while(property_offset < payload_offset && property_offset < length){ DBGPF("Property %02X at offset %" PRIsize_t " of %" PRIu32, variable_header[property_offset], property_offset, property_length); + //read payload format indicator - if(variable_header[property_offset] == 0x01){ + if(variable_header[property_offset] == 0x01 && property_offset < length - 1){ content_utf8 = variable_header[property_offset + 1]; } //read topic alias - else if(variable_header[property_offset] == 0x23){ + else if(variable_header[property_offset] == 0x23 && property_offset < length - 2){ topic_alias = (variable_header[property_offset + 1] << 8) | variable_header[property_offset + 2]; } diff --git a/backends/rtpmidi.c b/backends/rtpmidi.c index f0987f2..922075e 100644 --- a/backends/rtpmidi.c +++ b/backends/rtpmidi.c @@ -1329,13 +1329,14 @@ static int rtpmidi_mdns_detach(instance* inst){ } offset += bytes; - //TODO length-checks here - frame[offset++] = strlen(inst->name); - memcpy(frame + offset, inst->name, strlen(inst->name)); - offset += strlen(inst->name); + //calculate maximum permitted instance name length + bytes = min(min(strlen(inst->name), sizeof(frame) - offset - 3), 255); + frame[offset++] = bytes; + memcpy(frame + offset, inst->name, bytes); + offset += bytes; frame[offset++] = 0xC0; frame[offset++] = sizeof(dns_header); - rr->data = htobe16(1 + strlen(inst->name) + 2); + rr->data = htobe16(1 + bytes + 2); free(name.name); return rtpmidi_mdns_broadcast(frame, offset); -- cgit v1.2.3 From f646d10ae1c7f9df1cc91243d7166d74791b487b Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 23 Jun 2021 22:41:23 +0200 Subject: Prefer pkg-config over python3-config for linker info --- backends/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index 4697a5a..5054236 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -89,9 +89,10 @@ lua.dll: CFLAGS += $(shell pkg-config --cflags lua53 || pkg-config --cflags lua5 lua.dll: LDLIBS += -L../ -llua53 # Python seems to ship their own little python3-config tool instead of properly maintaining their pkg-config files. -# This one also spams a good deal of unwanted flags into CFLAGS, so we use only --includes and --libs +# This one also spams a good deal of unwanted flags into CFLAGS, so we use only --includes. On the other hand, the --libs +# info from this one seems to include the actual interpreter library only on some systems, which makes it worse than useless. python.so: CFLAGS += $(shell python3-config --includes || pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") -python.so: LDLIBS += $(shell python3-config --libs || pkg-config --libs python3 || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.so: LDLIBS += $(shell pkg-config --libs python3-embed || python3-config --libs || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") # Generic rules on how to build .SO/.DLL's from C and CPP sources %.so :: %.c %.h $(BACKEND_LIB) -- cgit v1.2.3 From 011be343cd1427a1be68f9a0da38401b89de0fec Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 27 Jun 2021 16:20:52 +0200 Subject: Fix python backend calls --- backends/Makefile | 2 +- backends/python.c | 13 +++++++++++-- backends/python.md | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index 5054236..6c46007 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -92,7 +92,7 @@ lua.dll: LDLIBS += -L../ -llua53 # This one also spams a good deal of unwanted flags into CFLAGS, so we use only --includes. On the other hand, the --libs # info from this one seems to include the actual interpreter library only on some systems, which makes it worse than useless. python.so: CFLAGS += $(shell python3-config --includes || pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") -python.so: LDLIBS += $(shell pkg-config --libs python3-embed || python3-config --libs || pkg-config --libs python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.so: LDLIBS += $(shell pkg-config --libs python3-embed || python3-config --libs || pkg-config --libs python3 || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") # Generic rules on how to build .SO/.DLL's from C and CPP sources %.so :: %.c %.h $(BACKEND_LIB) diff --git a/backends/python.c b/backends/python.c index b9b6518..c1a21be 100644 --- a/backends/python.c +++ b/backends/python.c @@ -1,4 +1,5 @@ #define BACKEND_NAME "python" +//#define DEBUG #define PY_SSIZE_T_CLEAN #include @@ -34,6 +35,8 @@ MM_PLUGIN_API int init(){ LOG("Failed to register backend"); return 1; } + + //Py_UnbufferedStdioFlag = 1; return 0; } @@ -159,7 +162,7 @@ static PyObject* mmpy_output(PyObject* self, PyObject* args){ else{ mm_channel_event(mm_channel(inst, u, 0), val); } - return 0; + break; } } @@ -401,6 +404,7 @@ static int mmpy_exec(PyObject* module) { PyObject* capsule = PyDict_GetItemString(PyThreadState_GetDict(), MMPY_INSTANCE_KEY); if(capsule && inst){ *inst = PyCapsule_GetPointer(capsule, NULL); + DBGPF("Initializing extension module on instance %s", (*inst)->name); return 0; } @@ -415,6 +419,7 @@ static int python_configure_instance(instance* inst, char* option, char* value){ //load python script if(!strcmp(option, "module")){ //swap to interpreter + //PyThreadState_Swap(data->interpreter); PyEval_RestoreThread(data->interpreter); //import the module module = PyImport_ImportModule(value); @@ -491,8 +496,10 @@ static int python_instance(instance* inst){ Py_SetProgramName(program_name); //initialize python Py_InitializeEx(0); - //create, acquire and release the GIL + #if PY_MINOR_VERSION < 7 + //in python 3.6 and earlier, this was required to set up the GIL PyEval_InitThreads(); + #endif python_main = PyEval_SaveThread(); } @@ -717,6 +724,8 @@ static int python_start(size_t n, instance** inst){ //release interpreter PyEval_ReleaseThread(data->interpreter); } + + last_timestamp = mm_timestamp(); return 0; } diff --git a/backends/python.md b/backends/python.md index 2114a08..1c0c96f 100644 --- a/backends/python.md +++ b/backends/python.md @@ -79,8 +79,8 @@ The `python` backend does not take any global configuration. | Option | Example value | Default value | Description | |-----------------------|-----------------------|-----------------------|-----------------------------------------------| -| `module` | `my_handlers.py` | none | (Path to) Python module source file, relative to configuration file location | -| `default-handler` | `mu_handlers.default` | none | Function to be called as handler for all top-level channels (not belonging to a module) | +| `module` | `my_handlers` | none | Name of the python module to load (normally the name of a`.py` file without the extension) | +| `default-handler` | `my_handlers.default` | none | Function to be called as handler for all top-level channels (not belonging to a module) | A single instance may have multiple `module` options specified. This will make all handlers available within their module namespaces (see the section on channel specification). -- cgit v1.2.3 From 979ca16917cfca16b42f6f0464ff6c5cd41473b1 Mon Sep 17 00:00:00 2001 From: cbdev Date: Mon, 28 Jun 2021 22:30:02 +0200 Subject: Improve windows build --- backends/Makefile | 3 +++ backends/libmmbackend.c | 8 ++++++-- backends/python.c | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'backends/Makefile') diff --git a/backends/Makefile b/backends/Makefile index 6c46007..be870d6 100644 --- a/backends/Makefile +++ b/backends/Makefile @@ -93,6 +93,9 @@ lua.dll: LDLIBS += -L../ -llua53 # info from this one seems to include the actual interpreter library only on some systems, which makes it worse than useless. python.so: CFLAGS += $(shell python3-config --includes || pkg-config --cflags python3 || pkg-config --cflags python || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") python.so: LDLIBS += $(shell pkg-config --libs python3-embed || python3-config --libs || pkg-config --libs python3 || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.so: LDFLAGS += $(shell python3-config --ldflags || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.dll: CFLAGS += $(shell python3-config --includes || echo "-DBUILD_ERROR=\"Missing pkg-config data for python3\"") +python.dll: LDLIBS += -L../ -lpython3 # Generic rules on how to build .SO/.DLL's from C and CPP sources %.so :: %.c %.h $(BACKEND_LIB) diff --git a/backends/libmmbackend.c b/backends/libmmbackend.c index bad048c..18611e1 100644 --- a/backends/libmmbackend.c +++ b/backends/libmmbackend.c @@ -3,6 +3,10 @@ #define LOGPF(format, ...) fprintf(stderr, "libmmbe\t" format "\n", __VA_ARGS__) #define LOG(message) fprintf(stderr, "libmmbe\t%s\n", (message)) +#ifndef _WIN32 + #define closesocket close +#endif + int mmbackend_strdup(char** dest, char* src){ if(*dest){ free(*dest); @@ -186,14 +190,14 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener, uin if(listener){ status = bind(fd, addr_it->ai_addr, addr_it->ai_addrlen); if(status < 0){ - close(fd); + closesocket(fd); continue; } } else{ status = connect(fd, addr_it->ai_addr, addr_it->ai_addrlen); if(status < 0){ - close(fd); + closesocket(fd); continue; } } diff --git a/backends/python.c b/backends/python.c index c1a21be..9c0caa1 100644 --- a/backends/python.c +++ b/backends/python.c @@ -1,6 +1,10 @@ #define BACKEND_NAME "python" //#define DEBUG +#ifdef _WIN32 + #include +#endif + #define PY_SSIZE_T_CLEAN #include #include -- cgit v1.2.3