Fixed the MCA MPU-401 and gave it its correct name;

Sound Blaster 16/AWE32 MPU-401 is now always the less-functional variant like it would be on real hardware and its IRQ is always shared with the sound card;
Standalone MPU-401 is now always the fully functional intelligent mode variant;
Standalone MPU-401 is now always available, even when Sound Blaster 16/AWE32 is in use;
Cleaned up sound/midi.c and win/win_midi.c.
This commit is contained in:
OBattler
2018-09-11 22:41:14 +02:00
parent a12430b779
commit 0ea3a1307c
8 changed files with 697 additions and 772 deletions

View File

@@ -11,117 +11,127 @@
#include "../plat_midi.h"
int midi_id = 0;
HANDLE m_event;
static HMIDIOUT midi_out_device = NULL;
static uint8_t midi_rt_buf[1024];
static uint8_t midi_cmd_buf[1024];
static int midi_cmd_pos = 0;
static int midi_cmd_len = 0;
static uint8_t midi_status = 0;
static unsigned int midi_sysex_start = 0;
static unsigned int midi_sysex_delay = 0;
void plat_midi_init()
typedef struct
{
/* This is for compatibility with old configuration files. */
midi_id = config_get_int("Sound", "midi_host_device", -1);
if (midi_id == -1)
{
midi_id = config_get_int(SYSTEM_MIDI_NAME, "midi", 0);
}
else
{
config_delete_var("Sound", "midi_host_device");
config_set_int(SYSTEM_MIDI_NAME, "midi", midi_id);
}
int midi_id;
MMRESULT hr = MMSYSERR_NOERROR;
HANDLE m_event;
memset(midi_rt_buf, 0, sizeof(midi_rt_buf));
memset(midi_cmd_buf, 0, sizeof(midi_cmd_buf));
HMIDIOUT midi_out_device;
midi_cmd_pos = midi_cmd_len = 0;
midi_status = 0;
MIDIHDR m_hdr;
} plat_midi_t;
midi_sysex_start = midi_sysex_delay = 0;
plat_midi_t *pm = NULL;
m_event = CreateEvent(NULL, TRUE, TRUE, NULL);
hr = midiOutOpen(&midi_out_device, midi_id, (uintptr_t) m_event,
0, CALLBACK_EVENT);
if (hr != MMSYSERR_NOERROR) {
printf("midiOutOpen error - %08X\n",hr);
midi_id = 0;
hr = midiOutOpen(&midi_out_device, midi_id, (uintptr_t) m_event,
0, CALLBACK_EVENT);
if (hr != MMSYSERR_NOERROR) {
printf("midiOutOpen error - %08X\n",hr);
return;
}
}
midiOutReset(midi_out_device);
}
void plat_midi_close()
void
plat_midi_init(void)
{
if (midi_out_device != NULL)
{
midiOutReset(midi_out_device);
midiOutClose(midi_out_device);
/* midi_out_device = NULL; */
CloseHandle(m_event);
}
}
MMRESULT hr;
int plat_midi_get_num_devs()
{
return midiOutGetNumDevs();
}
void plat_midi_get_dev_name(int num, char *s)
{
MIDIOUTCAPS caps;
pm = (plat_midi_t *) malloc(sizeof(plat_midi_t));
memset(pm, 0, sizeof(plat_midi_t));
midiOutGetDevCaps(num, &caps, sizeof(caps));
strcpy(s, caps.szPname);
}
pm->midi_id = config_get_int(SYSTEM_MIDI_NAME, "midi", 0);
void plat_midi_play_msg(uint8_t *msg)
{
midiOutShortMsg(midi_out_device, *(uint32_t *) msg);
}
hr = MMSYSERR_NOERROR;
MIDIHDR m_hdr;
pm->m_event = CreateEvent(NULL, TRUE, TRUE, NULL);
void plat_midi_play_sysex(uint8_t *sysex, unsigned int len)
{
MMRESULT result;
if (WaitForSingleObject(m_event, 2000) == WAIT_TIMEOUT)
return;
midiOutUnprepareHeader(midi_out_device, &m_hdr, sizeof(m_hdr));
m_hdr.lpData = (char *) sysex;
m_hdr.dwBufferLength = len;
m_hdr.dwBytesRecorded = len;
m_hdr.dwUser = 0;
result = midiOutPrepareHeader(midi_out_device, &m_hdr, sizeof(m_hdr));
if (result != MMSYSERR_NOERROR) return;
ResetEvent(m_event);
result = midiOutLongMsg(midi_out_device, &m_hdr, sizeof(m_hdr));
if (result != MMSYSERR_NOERROR)
{
SetEvent(m_event);
hr = midiOutOpen(&pm->midi_out_device, pm->midi_id,
(uintptr_t) pm->m_event, 0, CALLBACK_EVENT);
if (hr != MMSYSERR_NOERROR) {
printf("midiOutOpen error - %08X\n", hr);
pm->midi_id = 0;
hr = midiOutOpen(&pm->midi_out_device, pm->midi_id,
(uintptr_t) pm->m_event, 0, CALLBACK_EVENT);
if (hr != MMSYSERR_NOERROR) {
printf("midiOutOpen error - %08X\n", hr);
return;
}
}
midiOutReset(pm->midi_out_device);
}
int plat_midi_write(uint8_t val)
void
plat_midi_close(void)
{
return 0;
if (pm) {
if (pm->midi_out_device != NULL) {
midiOutReset(pm->midi_out_device);
midiOutClose(pm->midi_out_device);
CloseHandle(pm->m_event);
}
free(pm);
pm = NULL;
}
}
int
plat_midi_get_num_devs(void)
{
return midiOutGetNumDevs();
}
void
plat_midi_get_dev_name(int num, char *s)
{
MIDIOUTCAPS caps;
midiOutGetDevCaps(num, &caps, sizeof(caps));
strcpy(s, caps.szPname);
}
void
plat_midi_play_msg(uint8_t *msg)
{
if (!pm)
return;
midiOutShortMsg(pm->midi_out_device, *(uint32_t *) msg);
}
void
plat_midi_play_sysex(uint8_t *sysex, unsigned int len)
{
MMRESULT result;
if (!pm)
return;
if (WaitForSingleObject(pm->m_event, 2000) == WAIT_TIMEOUT)
return;
midiOutUnprepareHeader(pm->midi_out_device, &pm->m_hdr, sizeof(pm->m_hdr));
pm->m_hdr.lpData = (char *) sysex;
pm->m_hdr.dwBufferLength = len;
pm->m_hdr.dwBytesRecorded = len;
pm->m_hdr.dwUser = 0;
result = midiOutPrepareHeader(pm->midi_out_device, &pm->m_hdr, sizeof(pm->m_hdr));
if (result != MMSYSERR_NOERROR)
return;
ResetEvent(pm->m_event);
result = midiOutLongMsg(pm->midi_out_device, &pm->m_hdr, sizeof(pm->m_hdr));
if (result != MMSYSERR_NOERROR) {
SetEvent(pm->m_event);
return;
}
}
int
plat_midi_write(uint8_t val)
{
return 0;
}