Merge pull request #535 from 86Box/feature/midi_in

Feature/midi in
This commit is contained in:
OBattler
2020-01-12 18:57:44 +01:00
committed by GitHub
20 changed files with 2169 additions and 551 deletions

View File

@@ -366,7 +366,7 @@ BEGIN
PUSHBUTTON "Joystick 4...",IDC_JOY4,209,44,50,14
END
DLG_CFG_SOUND DIALOG DISCARDABLE 97, 0, 267, 116
DLG_CFG_SOUND DIALOG DISCARDABLE 97, 0, 267, 199
STYLE DS_CONTROL | WS_CHILD
FONT 9, "Segoe UI"
BEGIN
@@ -380,34 +380,41 @@ BEGIN
LTEXT "MIDI Out Device:",IDT_1712,7,26,59,10
PUSHBUTTON "Configure",IDC_CONFIGURE_MIDI,214,25,46,12
COMBOBOX IDC_COMBO_MIDI_IN,71,43,140,120,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "MIDI In Device:",IDT_1713,7,44,59,10
PUSHBUTTON "Configure",IDC_CONFIGURE_MIDI_IN,214,43,46,12
CONTROL "Standalone MPU-401",IDC_CHECK_MPU401,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,7,45,199,10
PUSHBUTTON "Configure",IDC_CONFIGURE_MPU401,214,44,46,12
BS_AUTOCHECKBOX | WS_TABSTOP,7,65,199,10
PUSHBUTTON "Configure",IDC_CONFIGURE_MPU401,214,64,46,12
CONTROL "Innovation SSI-2001",IDC_CHECK_SSI,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,7,63,94,10
BS_AUTOCHECKBOX | WS_TABSTOP,7,83,94,10
CONTROL "CMS / Game Blaster",IDC_CHECK_CMS,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,147,63,94,10
BS_AUTOCHECKBOX | WS_TABSTOP,147,83,94,10
CONTROL "Gravis Ultrasound",IDC_CHECK_GUS,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,7,81,94,10
BS_AUTOCHECKBOX | WS_TABSTOP,7,99,94,10
PUSHBUTTON "Configure",IDC_CONFIGURE_GUS,214,99,46,12
CONTROL "Use FLOAT32 sound",IDC_CHECK_FLOAT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,147,81,94,10
BS_AUTOCHECKBOX | WS_TABSTOP,7,115,94,10
END
DLG_CFG_NETWORK DIALOG DISCARDABLE 97, 0, 267, 63
STYLE DS_CONTROL | WS_CHILD
FONT 9, "Segoe UI"
BEGIN
LTEXT "Network type:",IDT_1713,7,8,59,10
LTEXT "Network type:",IDT_1714,7,8,59,10
COMBOBOX IDC_COMBO_NET_TYPE,71,7,189,120,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "PCap device:",IDT_1714,7,26,59,10
LTEXT "PCap device:",IDT_1715,7,26,59,10
COMBOBOX IDC_COMBO_PCAP,71,25,189,120,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "Network adapter:",IDT_1715,7,44,59,10
LTEXT "Network adapter:",IDT_1716,7,44,59,10
COMBOBOX IDC_COMBO_NET,71,43,140,120,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
PUSHBUTTON "Configure",IDC_CONFIGURE_NET,214,43,46,12
@@ -417,15 +424,15 @@ DLG_CFG_PORTS DIALOG DISCARDABLE 97, 0, 267, 117
STYLE DS_CONTROL | WS_CHILD
FONT 9, "Segoe UI"
BEGIN
LTEXT "LPT1 Device:",IDT_1716,7,8,61,10
LTEXT "LPT1 Device:",IDT_1717,7,8,61,10
COMBOBOX IDC_COMBO_LPT1,71,7,189,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LPT2 Device:",IDT_1717,7,27,61,10
LTEXT "LPT2 Device:",IDT_1718,7,27,61,10
COMBOBOX IDC_COMBO_LPT2,71,26,189,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LPT3 Device:",IDT_1718,7,46,61,10
LTEXT "LPT3 Device:",IDT_1719,7,46,61,10
COMBOBOX IDC_COMBO_LPT3,71,45,189,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
@@ -446,12 +453,12 @@ DLG_CFG_PERIPHERALS DIALOG DISCARDABLE 97, 0, 267, 200
STYLE DS_CONTROL | WS_CHILD
FONT 9, "Segoe UI"
BEGIN
LTEXT "SCSI Controller:",IDT_1716,7,8,48,10
LTEXT "SCSI Controller:",IDT_1717,7,8,48,10
COMBOBOX IDC_COMBO_SCSI,64,7,155,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,222,7,38,12
LTEXT "HD Controller:",IDT_1717,7,26,48,10
LTEXT "HD Controller:",IDT_1718,7,26,48,10
COMBOBOX IDC_COMBO_HDC,64,25,155,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Configure",IDC_CONFIGURE_HDC,222,25,38,12

View File

@@ -54,12 +54,13 @@
#define IDT_1710 1710 /* Joystick: */
#define IDT_1711 1711 /* Sound card: */
#define IDT_1712 1712 /* MIDI Out Device: */
#define IDT_1713 1713 /* Network type: */
#define IDT_1714 1714 /* PCap device: */
#define IDT_1715 1715 /* Network adapter: */
#define IDT_1716 1716 /* SCSI Controller: */
#define IDT_1717 1717 /* HD Controller: */
#define IDT_1718 1718
#define IDT_1713 1713 /* MIDI In Device: */
#define IDT_1714 1714 /* Network type: */
#define IDT_1715 1715 /* PCap device: */
#define IDT_1716 1716 /* Network adapter: */
#define IDT_1717 1717 /* SCSI Controller: */
#define IDT_1718 1718 /* HD Controller: */
#define IDT_1719 1719
#define IDT_1720 1720 /* Hard disks: */
#define IDT_1721 1721 /* Bus: */
#define IDT_1722 1722 /* Channel: */
@@ -148,7 +149,8 @@
#define IDC_CHECK_MPU401 1076
#define IDC_CONFIGURE_MPU401 1077
#define IDC_CHECK_FLOAT 1078
#define IDC_CHECK_GUSMAX 1079
#define IDC_CONFIGURE_GUS 1079
#define IDC_COMBO_MIDI_IN 1080
#define IDC_COMBO_NET_TYPE 1090 /* network config */
#define IDC_COMBO_PCAP 1091
@@ -241,6 +243,7 @@
#define IDC_CONFIGURE_PCAP 1306
#define IDC_CONFIGURE_NET 1307
#define IDC_CONFIGURE_MIDI 1308
#define IDC_CONFIGURE_MIDI_IN 1309
#define IDC_JOY1 1310
#define IDC_JOY2 1311
#define IDC_JOY3 1312

View File

@@ -108,6 +108,21 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
id += 2;
break;
case CONFIG_MIDI_IN:
val_int = config_get_int((char *) config_device.name,
(char *) config->name, config->default_int);
num = plat_midi_in_get_num_devs();
for (c = 0; c < num; c++) {
plat_midi_in_get_dev_name(c, s);
mbstowcs(lptsTemp, s, strlen(s) + 1);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)lptsTemp);
if (val_int == c)
SendMessage(h, CB_SETCURSEL, c, 0);
}
id += 2;
break;
case CONFIG_SPINNER:
val_int = config_get_int((char *) config_device.name,
(char *) config->name, config->default_int);
@@ -205,6 +220,17 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
c = SendMessage(h, CB_GETCURSEL, 0, 0);
if (val_int != c)
changed = 1;
id += 2;
break;
case CONFIG_MIDI_IN:
val_int = config_get_int((char *) config_device.name,
(char *) config->name, config->default_int);
c = SendMessage(h, CB_GETCURSEL, 0, 0);
if (val_int != c)
changed = 1;
@@ -302,6 +328,12 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
c = SendMessage(h, CB_GETCURSEL, 0, 0);
config_set_int((char *) config_device.name, (char *) config->name, c);
id += 2;
break;
case CONFIG_MIDI_IN:
c = SendMessage(h, CB_GETCURSEL, 0, 0);
config_set_int((char *) config_device.name, (char *) config->name, c);
id += 2;
break;
case CONFIG_FNAME:
@@ -358,6 +390,7 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
break;
case CONFIG_SELECTION:
case CONFIG_MIDI:
case CONFIG_MIDI_IN:
case CONFIG_SPINNER:
id += 2;
break;
@@ -478,6 +511,7 @@ deviceconfig_inst_open(HWND hwnd, const device_t *device, int inst)
case CONFIG_SELECTION:
case CONFIG_MIDI:
case CONFIG_MIDI_IN:
case CONFIG_HEX16:
case CONFIG_HEX20:
/*Combo box*/

View File

@@ -13,16 +13,17 @@
typedef struct
{
int midi_id;
int midi_id, midi_input_id;
HANDLE m_event;
HMIDIOUT midi_out_device;
HMIDIIN midi_in_device;
MIDIHDR m_hdr;
} plat_midi_t;
plat_midi_t *pm = NULL;
plat_midi_t *pm = NULL, *pm_in = NULL;
void
@@ -65,7 +66,7 @@ plat_midi_close(void)
midiOutClose(pm->midi_out_device);
CloseHandle(pm->m_event);
}
free(pm);
pm = NULL;
}
@@ -135,3 +136,117 @@ plat_midi_write(uint8_t val)
{
return 0;
}
void CALLBACK
plat_midi_in_callback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
uint8_t msg[4] = {((dwParam1&0xff)),(((dwParam1&0xff00)>>8)),
(((dwParam1&0xff0000)>>16)),MIDI_evt_len[((dwParam1&0xff))]};
uint8_t *sysex;
uint32_t len;
int cnt;
MIDIHDR *hdr;
switch (wMsg) {
case MM_MIM_DATA: /* 0x3C3 - midi message */
input_msg(midi_in_p, msg);
break;
case MM_MIM_OPEN: /* 0x3C1 */
break;
case MM_MIM_CLOSE: /* 0x3C2 */
break;
case MM_MIM_LONGDATA: /* 0x3C4 - sysex */
hdr = (MIDIHDR *)dwParam1;
sysex = (uint8_t *)hdr->lpData;
len = (uint32_t)hdr->dwBytesRecorded;
cnt = 5;
while (cnt) { /*abort if timed out*/
int ret = input_sysex(midi_in_p, sysex, len, 0);
if (!ret) {
len = 0;
break;
}
if (len==ret)
cnt--;
else
cnt = 5;
sysex += len-ret;
len = ret;
Sleep(5);/*msec*/
}
if (len)
input_sysex(midi_in_p, sysex, 0, 0);
midiInUnprepareHeader(hMidiIn, hdr, sizeof(*hdr));
hdr->dwBytesRecorded = 0;
midiInPrepareHeader(hMidiIn, hdr, sizeof(*hdr));
break;
case MM_MIM_ERROR:
case MM_MIM_LONGERROR:
break;
default:
break;
}
}
void
plat_midi_input_init(void)
{
MMRESULT hr;
pm_in = (plat_midi_t *) malloc(sizeof(plat_midi_t));
memset(pm_in, 0, sizeof(plat_midi_t));
pm_in->midi_input_id = config_get_int(MIDI_INPUT_NAME, "midi_input", 0);
hr = MMSYSERR_NOERROR;
hr = midiInOpen(&pm_in->midi_in_device, pm_in->midi_input_id,
(uintptr_t) plat_midi_in_callback, 0, CALLBACK_FUNCTION);
if (hr != MMSYSERR_NOERROR) {
printf("midiInOpen error - %08X\n", hr);
pm_in->midi_input_id = 0;
hr = midiInOpen(&pm_in->midi_in_device, pm_in->midi_input_id,
(uintptr_t) plat_midi_in_callback, 0, CALLBACK_FUNCTION);
if (hr != MMSYSERR_NOERROR) {
printf("midiInOpen error - %08X\n", hr);
return;
}
}
pm_in->m_hdr.lpData = (char*)&MIDI_InSysexBuf[0];
pm_in->m_hdr.dwBufferLength = SYSEX_SIZE;
pm_in->m_hdr.dwBytesRecorded = 0;
pm_in->m_hdr.dwUser = 0;
midiInPrepareHeader(pm_in->midi_in_device,&pm_in->m_hdr,sizeof(pm_in->m_hdr));
midiInStart(pm_in->midi_in_device);
}
void
plat_midi_input_close(void)
{
if (pm_in) {
if (pm_in->midi_in_device != NULL) {
midiInStop(pm_in->midi_in_device);
midiInClose(pm_in->midi_in_device);
}
free(pm_in);
pm_in = NULL;
}
}
int
plat_midi_in_get_num_devs(void)
{
return midiInGetNumDevs();
}
void
plat_midi_in_get_dev_name(int num, char *s)
{
MIDIINCAPS caps;
midiInGetDevCaps(num, &caps, sizeof(caps));
strcpy(s, caps.szPname);
}

View File

@@ -56,6 +56,7 @@
#include "../sound/sound.h"
#include "../sound/midi.h"
#include "../sound/snd_mpu401.h"
#include "../sound/snd_gus.h"
#include "../video/video.h"
#include "../video/vid_voodoo.h"
#include "../plat.h"
@@ -84,7 +85,7 @@ static int temp_gfxcard, temp_voodoo;
static int temp_mouse, temp_joystick;
/* Sound category */
static int temp_sound_card, temp_midi_device, temp_mpu401, temp_SSI2001, temp_GAMEBLASTER, temp_GUS;
static int temp_sound_card, temp_midi_device, temp_midi_input_device, temp_mpu401, temp_SSI2001, temp_GAMEBLASTER, temp_GUS;
static int temp_float;
/* Network category */
@@ -123,6 +124,7 @@ extern int is486;
static int listtomachine[256], machinetolist[256];
static int settings_device_to_list[2][20], settings_list_to_device[2][20];
static int settings_midi_to_list[20], settings_list_to_midi[20];
static int settings_midi_in_to_list[20], settings_list_to_midi_in[20];
static int max_spt = 63, max_hpc = 255, max_tracks = 266305;
static uint64_t mfm_tracking, esdi_tracking, xta_tracking, ide_tracking, scsi_tracking[2];
@@ -218,6 +220,7 @@ win_settings_init(void)
/* Sound category */
temp_sound_card = sound_card_current;
temp_midi_device = midi_device_current;
temp_midi_input_device = midi_input_device_current;
temp_mpu401 = mpu401_standalone_enable;
temp_SSI2001 = SSI2001;
temp_GAMEBLASTER = GAMEBLASTER;
@@ -329,6 +332,7 @@ win_settings_changed(void)
/* Sound category */
i = i || (sound_card_current != temp_sound_card);
i = i || (midi_device_current != temp_midi_device);
i = i || (midi_input_device_current != temp_midi_input_device);
i = i || (mpu401_standalone_enable != temp_mpu401);
i = i || (SSI2001 != temp_SSI2001);
i = i || (GAMEBLASTER != temp_GAMEBLASTER);
@@ -431,6 +435,7 @@ win_settings_save(void)
/* Sound category */
sound_card_current = temp_sound_card;
midi_device_current = temp_midi_device;
midi_input_device_current = temp_midi_input_device;
mpu401_standalone_enable = temp_mpu401;
SSI2001 = temp_SSI2001;
GAMEBLASTER = temp_GAMEBLASTER;
@@ -1100,19 +1105,19 @@ mpu401_present(void)
int
mpu401_standalone_allow(void)
{
char *md;
char *md, *mdin;
md = midi_device_get_internal_name(temp_midi_device);
mdin = midi_in_device_get_internal_name(temp_midi_input_device);
if (md != NULL) {
if (!strcmp(md, "none"))
if (!strcmp(md, "none") && !strcmp(mdin, "none"))
return 0;
}
return 1;
}
#if defined(__amd64__) || defined(__aarch64__)
static LRESULT CALLBACK
#else
@@ -1195,19 +1200,55 @@ win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
else
EnableWindow(h, FALSE);
h = GetDlgItem(hdlg, IDC_COMBO_MIDI_IN);
c = d = 0;
while (1) {
s = midi_in_device_getname(c);
if (!s[0])
break;
settings_midi_in_to_list[c] = d;
if (midi_in_device_available(c)) {
if (c == 0)
SendMessage(h, CB_ADDSTRING, 0, win_get_string(IDS_2112));
else {
mbstowcs(lptsTemp, s, strlen(s) + 1);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM) lptsTemp);
}
settings_list_to_midi_in[d] = c;
d++;
}
c++;
}
SendMessage(h, CB_SETCURSEL, settings_midi_in_to_list[temp_midi_input_device], 0);
h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI_IN);
if (midi_in_device_has_config(temp_midi_input_device))
EnableWindow(h, TRUE);
else
EnableWindow(h, FALSE);
h = GetDlgItem(hdlg, IDC_CHECK_MPU401);
SendMessage(h, BM_SETCHECK, temp_mpu401, 0);
EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE);
h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401);
EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE);
h=GetDlgItem(hdlg, IDC_CHECK_CMS);
SendMessage(h, BM_SETCHECK, temp_GAMEBLASTER, 0);
h=GetDlgItem(hdlg, IDC_CHECK_GUS);
SendMessage(h, BM_SETCHECK, temp_GUS, 0);
h = GetDlgItem(hdlg, IDC_CONFIGURE_GUS);
EnableWindow(h, (temp_GUS) ? TRUE : FALSE);
h=GetDlgItem(hdlg, IDC_CHECK_SSI);
SendMessage(h, BM_SETCHECK, temp_SSI2001, 0);
@@ -1270,6 +1311,31 @@ win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device));
break;
case IDC_COMBO_MIDI_IN:
h = GetDlgItem(hdlg, IDC_COMBO_MIDI_IN);
temp_midi_input_device = settings_list_to_midi_in[SendMessage(h, CB_GETCURSEL, 0, 0)];
h = GetDlgItem(hdlg, IDC_CONFIGURE_MIDI_IN);
if (midi_in_device_has_config(temp_midi_input_device))
EnableWindow(h, TRUE);
else
EnableWindow(h, FALSE);
h = GetDlgItem(hdlg, IDC_CHECK_MPU401);
SendMessage(h, BM_SETCHECK, temp_mpu401, 0);
EnableWindow(h, mpu401_standalone_allow() ? TRUE : FALSE);
h = GetDlgItem(hdlg, IDC_CONFIGURE_MPU401);
EnableWindow(h, (mpu401_standalone_allow() && temp_mpu401) ? TRUE : FALSE);
break;
case IDC_CONFIGURE_MIDI_IN:
h = GetDlgItem(hdlg, IDC_COMBO_MIDI_IN);
temp_midi_input_device = settings_list_to_midi_in[SendMessage(h, CB_GETCURSEL, 0, 0)];
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_in_device_getdevice(temp_midi_input_device));
break;
case IDC_CHECK_MPU401:
h = GetDlgItem(hdlg, IDC_CHECK_MPU401);
temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0);
@@ -1282,6 +1348,18 @@ win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
temp_deviceconfig |= deviceconfig_open(hdlg, (machines[temp_machine].flags & MACHINE_MCA) ?
(void *)&mpu401_mca_device : (void *)&mpu401_device);
break;
case IDC_CHECK_GUS:
h = GetDlgItem(hdlg, IDC_CHECK_GUS);
temp_GUS = SendMessage(h, BM_GETCHECK, 0, 0);
h = GetDlgItem(hdlg, IDC_CONFIGURE_GUS);
EnableWindow(h, temp_GUS ? TRUE : FALSE);
break;
case IDC_CONFIGURE_GUS:
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&gus_device);
break;
}
return FALSE;
@@ -1292,6 +1370,9 @@ win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
h = GetDlgItem(hdlg, IDC_COMBO_MIDI);
temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)];
h = GetDlgItem(hdlg, IDC_COMBO_MIDI_IN);
temp_midi_input_device = settings_list_to_midi_in[SendMessage(h, CB_GETCURSEL, 0, 0)];
h = GetDlgItem(hdlg, IDC_CHECK_MPU401);
temp_mpu401 = SendMessage(h, BM_GETCHECK, 0, 0);