From e08b473d0eeb467ad358ba5314157753b4f37c18 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 5 Jan 2020 23:26:04 +0100 Subject: Implement commandline config override (Fixes #26) --- midimonster.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index 2ec165b..583601e 100644 --- a/midimonster.c +++ b/midimonster.c @@ -274,9 +274,30 @@ static int args_parse(int argc, char** argv, char** cfg_file){ version(); return 1; } - - //if nothing else matches, it's probably the configuration file - *cfg_file = argv[u]; + else if(!strcmp(argv[u], "-i")){ + if(!argv[u + 1]){ + fprintf(stderr, "Missing instance override specification\n"); + return 1; + } + if(config_add_override(override_instance, argv[u + 1])){ + return 1; + } + u++; + } + else if(!strcmp(argv[u], "-b")){ + if(!argv[u + 1]){ + fprintf(stderr, "Missing backend override specification\n"); + return 1; + } + if(config_add_override(override_backend, argv[u + 1])){ + return 1; + } + u++; + } + else{ + //if nothing else matches, it's probably the configuration file + *cfg_file = argv[u]; + } } return 0; @@ -317,6 +338,7 @@ int main(int argc, char** argv){ map_free(); fds_free(); plugins_close(); + config_free(); return usage(argv[0]); } @@ -403,6 +425,7 @@ bail: fds_free(); event_free(); plugins_close(); + config_free(); return rv; } -- cgit v1.2.3 From 78b21a9ac3f975f35ec7b61108531e1495eb91c0 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 12 Jan 2020 17:34:14 +0100 Subject: Rework instance creation --- midimonster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index 583601e..b6f7758 100644 --- a/midimonster.c +++ b/midimonster.c @@ -341,7 +341,7 @@ int main(int argc, char** argv){ config_free(); return usage(argv[0]); } - + //load an initial timestamp update_timestamp(); -- cgit v1.2.3 From 8c32598449895e506b4d0eab71be0abf219a62da Mon Sep 17 00:00:00 2001 From: cbdev Date: Mon, 13 Jan 2020 22:49:33 +0100 Subject: Hide core-internal structures --- midimonster.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index b6f7758..d9a99d9 100644 --- a/midimonster.c +++ b/midimonster.c @@ -14,6 +14,7 @@ #include "backend.h" #include "plugin.h" +/* Core-internal structures */ typedef struct /*_event_collection*/ { size_t alloc; size_t n; @@ -21,6 +22,12 @@ typedef struct /*_event_collection*/ { channel_value* value; } event_collection; +typedef struct /*_mm_channel_mapping*/ { + channel* from; + size_t destinations; + channel** to; +} channel_mapping; + static size_t mappings = 0; static channel_mapping* map = NULL; static size_t fds = 0; -- cgit v1.2.3 From 9c564af18dc3faad8910bfe14b45ed4ab884d797 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 29 Feb 2020 15:35:08 +0100 Subject: Keep console alive when exiting as last process on Windows --- midimonster.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index d9a99d9..9cbc3a9 100644 --- a/midimonster.c +++ b/midimonster.c @@ -264,13 +264,27 @@ static fd_set fds_collect(int* max_fd){ } static int platform_initialize(){ -#ifdef _WIN32 + #ifdef _WIN32 WSADATA wsa; WORD version = MAKEWORD(2, 2); if(WSAStartup(version, &wsa)){ return 1; } -#endif + #endif + return 0; +} + +static int platform_shutdown(){ + #ifdef _WIN32 + DWORD processes; + if(GetConsoleProcessList(&processes, 1) == 1){ + fprintf(stderr, "\nMIDIMonster is the last process in this console, please press any key to exit\n"); + HANDLE input = GetStdHandle(STD_INPUT_HANDLE); + SetConsoleMode(input, 0); + FlushConsoleInputBuffer(input); + WaitForSingleObject(input, INFINITE); + } + #endif return 0; } @@ -346,7 +360,7 @@ int main(int argc, char** argv){ fds_free(); plugins_close(); config_free(); - return usage(argv[0]); + return (usage(argv[0]) | platform_shutdown()); } //load an initial timestamp @@ -433,6 +447,7 @@ bail: event_free(); plugins_close(); config_free(); + platform_shutdown(); return rv; } -- cgit v1.2.3 From 20e8f4632b8e11415435d143ec3c7c4528c54d46 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 8 Mar 2020 13:25:00 +0100 Subject: Allow managed_fd implementation data to be updated --- midimonster.c | 1 + 1 file changed, 1 insertion(+) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index 9cbc3a9..2087c28 100644 --- a/midimonster.c +++ b/midimonster.c @@ -127,6 +127,7 @@ MM_API int mm_manage_fd(int new_fd, char* back, int manage, void* impl){ //find exact match for(u = 0; u < fds; u++){ if(fd[u].fd == new_fd && fd[u].backend == b){ + fd[u].impl = impl; if(!manage){ fd[u].fd = -1; fd[u].backend = NULL; -- cgit v1.2.3 From aa5650c77af9379fc80c5329e0c0ffbe1f5d2355 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 8 Mar 2020 13:44:34 +0100 Subject: Print proper error messages from core select on Windows --- midimonster.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index 2087c28..b8594b4 100644 --- a/midimonster.c +++ b/midimonster.c @@ -333,6 +333,9 @@ int main(int argc, char** argv){ managed_fd* signaled_fds = NULL; int rv = EXIT_FAILURE, error, maxfd = -1; char* cfg_file = DEFAULT_CFG; + #ifdef _WIN32 + char* error_message = NULL; + #endif //parse commandline arguments if(args_parse(argc, argv, &cfg_file)){ @@ -392,7 +395,15 @@ int main(int argc, char** argv){ tv = backend_timeout(); error = select(maxfd + 1, &read_fds, NULL, NULL, &tv); if(error < 0){ + #ifndef _WIN32 fprintf(stderr, "select failed: %s\n", strerror(errno)); + #else + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error_message, 0, NULL); + fprintf(stderr, "select failed: %s\n", error_message); + LocalFree(error_message); + error_message = NULL; + #endif break; } -- cgit v1.2.3