From ae6123446091daa392e7db5b35b9ce3694050a3a Mon Sep 17 00:00:00 2001 From: Andreas Zdziarstek Date: Sun, 7 Feb 2021 22:19:04 +0100 Subject: [PATCH] Windows version! --- linux_src/midi_dev.c | 4 ++ win32_src/Makefile | 2 +- win32_src/midi_dev.c | 151 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 135 insertions(+), 22 deletions(-) diff --git a/linux_src/midi_dev.c b/linux_src/midi_dev.c index 638c61c..1d27960 100644 --- a/linux_src/midi_dev.c +++ b/linux_src/midi_dev.c @@ -146,6 +146,10 @@ void mididev_add_optstr(char *optstr) { } int mididev_parse_arg(int c, const char *optarg) { + if(c != 'p') { + fprintf(stderr, "ERROR: Unknown option \'%c\'.\n", c); + return -1; + } size_t len = strlen(optarg); char *temparg = (char*) malloc(len+1); if(temparg == NULL) { diff --git a/win32_src/Makefile b/win32_src/Makefile index f9fbafa..be9da81 100644 --- a/win32_src/Makefile +++ b/win32_src/Makefile @@ -15,7 +15,7 @@ CFLAGS = $(INCLUDE) -O2 -ffunction-sections -fdata-sections -static-libgcc -stat CXXFLAGS = $(INCLUDE) -O2 -ffunction-sections -fdata-sections -static-libgcc -static-libstdc++ -Wl,--gc-sections -Wall -Werror $(DEFINE) -LIBS = +LIBS = -lwinmm OBJ = mt32-pi.o midi_dev.o delay.o diff --git a/win32_src/midi_dev.c b/win32_src/midi_dev.c index 4119681..5555c82 100644 --- a/win32_src/midi_dev.c +++ b/win32_src/midi_dev.c @@ -7,45 +7,154 @@ * Copyright (C) 2021 Andreas Zdziarstek * */ - +#include #include +#include + +#include "windows.h" + +#include "midi_dev.h" + +int output_port = -1; +HMIDIOUT midi_handle = NULL; +static volatile bool port_busy = false; +static char *dev_optstr = "lp:"; + +static void list_midi_outputs(void); +void CALLBACK midi_out_cb( + HMIDIOUT mh, + UINT wMsg, + DWORD_PTR dwInst, + DWORD_PTR dwp1, + DWORD_PTR dwp2 + ); int mididev_init(void) { + if(output_port == -1) { + fprintf(stderr, "ERROR: You must specify the MIDI output port number with \"-p PORT\". You can list available ports with \"-l\".\n"); + return -1; + } + + if(midiOutOpen(&midi_handle, output_port, (DWORD)(void*)midi_out_cb, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { + fprintf(stderr, "ERROR: Could not open MIDI output port %d.\n", output_port); + return -1; + } return 0; } int mididev_deinit(void) { + midiOutClose(midi_handle); return 0; } - int mididev_send_bytes(const unsigned char *buf, int len) { - if(len==0) return 0; + if(len==0) return 0; - if((buf[0] == 0xF0 && buf[len-1] == 0xF7) || len==3) { - for(int i=0; i