diff options
author | cbdev <cb@cbcdn.com> | 2020-03-08 17:12:03 +0100 |
---|---|---|
committer | cbdev <cb@cbcdn.com> | 2020-03-08 17:12:03 +0100 |
commit | e0000797c80789d9d4559bb5264b982c187e1137 (patch) | |
tree | 746a063886aa0a3e51a21ce83bc8e2189d6adcd9 /midimonster.c | |
parent | 8558c3acef273833d7366e1af3659514fff9c942 (diff) | |
parent | 5f4b349aff49be0a5f6895631a93c47fcafcff93 (diff) | |
download | midimonster-e0000797c80789d9d4559bb5264b982c187e1137.tar.gz midimonster-e0000797c80789d9d4559bb5264b982c187e1137.tar.bz2 midimonster-e0000797c80789d9d4559bb5264b982c187e1137.zip |
Merge branch 'master' into debian/master
Diffstat (limited to 'midimonster.c')
-rw-r--r-- | midimonster.c | 71 |
1 files changed, 64 insertions, 7 deletions
diff --git a/midimonster.c b/midimonster.c index 2ec165b..b8594b4 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; @@ -120,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; @@ -257,13 +265,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; } @@ -274,9 +296,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; @@ -290,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)){ @@ -317,9 +363,10 @@ int main(int argc, char** argv){ map_free(); fds_free(); plugins_close(); - return usage(argv[0]); + config_free(); + return (usage(argv[0]) | platform_shutdown()); } - + //load an initial timestamp update_timestamp(); @@ -348,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; } @@ -403,6 +458,8 @@ bail: fds_free(); event_free(); plugins_close(); + config_free(); + platform_shutdown(); return rv; } |