From 25286c8f0b651af3c71a64caa27caa28e67da63d Mon Sep 17 00:00:00 2001 From: TomW Date: Sun, 23 Aug 2015 20:59:15 +0100 Subject: [PATCH] Windows MIDI out device now selectable. --- src/device.h | 1 + src/pc.c | 5 +++++ src/sound_sb.c | 19 +++++++++++++++++-- src/win-deviceconfig.c | 40 ++++++++++++++++++++++++++++++++++++++-- src/win-midi.c | 24 +++++++++++++++++++++--- src/win.c | 5 +---- 6 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/device.h b/src/device.h index e92a785..0c6050e 100644 --- a/src/device.h +++ b/src/device.h @@ -2,6 +2,7 @@ #define CONFIG_INT 1 #define CONFIG_BINARY 2 #define CONFIG_SELECTION 3 +#define CONFIG_MIDI 4 typedef struct device_config_selection_t { diff --git a/src/pc.c b/src/pc.c index f0e6104..5389fa4 100644 --- a/src/pc.c +++ b/src/pc.c @@ -201,6 +201,7 @@ void initpc() keyboard_init(); mouse_init(); joystick_init(); + midi_init(); loadconfig(NULL); pclog("Config loaded\n"); @@ -278,6 +279,9 @@ void resetpchard() device_close_all(); device_init(); + midi_close(); + midi_init(); + timer_reset(); sound_reset(); mem_resize(); @@ -463,6 +467,7 @@ void closepc() dumpregs(); closevideo(); device_close_all(); + midi_close(); } /*int main() diff --git a/src/sound_sb.c b/src/sound_sb.c index 46eb65f..a5d2983 100644 --- a/src/sound_sb.c +++ b/src/sound_sb.c @@ -616,6 +616,19 @@ static device_config_t sb_pro_config[] = } }; +static device_config_t sb_16_config[] = +{ + { + .name = "midi", + .description = "MIDI out device", + .type = CONFIG_MIDI, + .default_int = 0 + }, + { + .type = -1 + } +}; + device_t sb_1_device = { "Sound Blaster v1.0", @@ -685,7 +698,8 @@ device_t sb_16_device = NULL, sb_speed_changed, NULL, - sb_add_status_info + sb_add_status_info, + sb_16_config }; device_t sb_awe32_device = { @@ -696,5 +710,6 @@ device_t sb_awe32_device = sb_awe32_available, sb_speed_changed, NULL, - sb_add_status_info + sb_add_status_info, + sb_16_config }; diff --git a/src/win-deviceconfig.c b/src/win-deviceconfig.c index a7d1d23..8f6b72c 100644 --- a/src/win-deviceconfig.c +++ b/src/win-deviceconfig.c @@ -27,6 +27,8 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam HWND h = GetDlgItem(hdlg, id); int val_int; char *val_string; + int num; + char s[80]; switch (config->type) { @@ -53,6 +55,21 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam id += 2; break; + + case CONFIG_MIDI: + val_int = config_get_int(NULL, config->name, config->default_int); + + num = midi_get_num_devs(); + for (c = 0; c < num; c++) + { + midi_get_dev_name(c, s); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s); + if (val_int == c) + SendMessage(h, CB_SETCURSEL, c, 0); + } + + id += 2; + break; } config++; } @@ -100,6 +117,17 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam id += 2; break; + + case CONFIG_MIDI: + val_int = config_get_int(NULL, config->name, config->default_int); + + c = SendMessage(h, CB_GETCURSEL, 0, 0); + + if (val_int != c) + changed = 1; + + id += 2; + break; } config++; } @@ -142,6 +170,13 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam id += 2; break; + + case CONFIG_MIDI: + c = SendMessage(h, CB_GETCURSEL, 0, 0); + config_set_int(NULL, config->name, c); + + id += 2; + break; } config++; } @@ -177,7 +212,7 @@ void deviceconfig_open(HWND hwnd, device_t *device) dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU; dlg->x = 10; dlg->y = 10; - dlg->cx = 150; + dlg->cx = 220; dlg->cy = 70; data = (uint16_t *)(dlg + 1); @@ -218,13 +253,14 @@ void deviceconfig_open(HWND hwnd, device_t *device) break; case CONFIG_SELECTION: + case CONFIG_MIDI: /*Combo box*/ item = (DLGITEMTEMPLATE *)data; item->x = 70; item->y = y; item->id = id++; - item->cx = 70; + item->cx = 140; item->cy = 150; item->style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_VSCROLL; diff --git a/src/win-midi.c b/src/win-midi.c index 069f9e5..227e6da 100644 --- a/src/win-midi.c +++ b/src/win-midi.c @@ -15,13 +15,19 @@ void midi_init() MIDIOUTCAPS ocaps; MMRESULT hr; - midi_id=0; - + midi_id = config_get_int(NULL, "midi", 0); + hr = midiOutOpen(&midi_out_device, midi_id, 0, 0, CALLBACK_NULL); if (hr != MMSYSERR_NOERROR) { printf("midiOutOpen error - %08X\n",hr); - return; + midi_id = 0; + hr = midiOutOpen(&midi_out_device, midi_id, 0, + 0, CALLBACK_NULL); + if (hr != MMSYSERR_NOERROR) { + printf("midiOutOpen error - %08X\n",hr); + return; + } } midiOutReset(midi_out_device); @@ -37,6 +43,18 @@ void midi_close() } } +int midi_get_num_devs() +{ + return midiOutGetNumDevs(); +} +void midi_get_dev_name(int num, char *s) +{ + MIDIOUTCAPS caps; + + midiOutGetDevCaps(num, &caps, sizeof(caps)); + strcpy(s, caps.szPname); +} + static int midi_pos, midi_len; static uint32_t midi_command; static int midi_lengths[8] = {3, 3, 3, 3, 2, 2, 3, 1}; diff --git a/src/win.c b/src/win.c index 4d2dd23..75b757e 100644 --- a/src/win.c +++ b/src/win.c @@ -465,10 +465,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, get_registry_key_map(); ghwnd=hwnd; - - midi_init(); - atexit(midi_close); - + initpc(); vid_apis[0][vid_api].init(ghwnd);