Initial commit of MIDI IN.

This commit is contained in:
TC1995
2020-01-01 20:20:16 +01:00
parent b9c189ea27
commit 9562a20a63
19 changed files with 1752 additions and 359 deletions

View File

@@ -649,6 +649,12 @@ load_sound(void)
else
midi_device_current = 0;
p = config_get_string(cat, "midi_in_device", NULL);
if (p != NULL)
midi_input_device_current = midi_in_device_get_from_internal_name(p);
else
midi_input_device_current = 0;
mpu401_standalone_enable = !!config_get_int(cat, "mpu401_standalone", 0);
SSI2001 = !!config_get_int(cat, "ssi2001", 0);
@@ -1531,6 +1537,11 @@ save_sound(void)
else
config_set_string(cat, "midi_device", midi_device_get_internal_name(midi_device_current));
if (!strcmp(midi_in_device_get_internal_name(midi_input_device_current), "none"))
config_delete_var(cat, "midi_in_device");
else
config_set_string(cat, "midi_in_device", midi_in_device_get_internal_name(midi_input_device_current));
if (mpu401_standalone_enable == 0)
config_delete_var(cat, "mpu401_standalone");
else

View File

@@ -50,6 +50,7 @@
#define CONFIG_HEX16 7
#define CONFIG_HEX20 8
#define CONFIG_MAC 9
#define CONFIG_MIDI_IN 10
enum {

View File

@@ -7,3 +7,9 @@ extern int plat_midi_write(uint8_t val);
extern int plat_midi_get_num_devs(void);
extern void plat_midi_get_dev_name(int num, char *s);
extern void plat_midi_input_init(void);
extern void plat_midi_input_close(void);
extern int plat_midi_in_get_num_devs(void);
extern void plat_midi_in_get_dev_name(int num, char *s);

View File

@@ -8,7 +8,7 @@
*
* MIDI device core module.
*
* Version: @(#)midi.c 1.0.1 2018/10/10
* Version: @(#)midi.c 1.0.2 2018/12/31
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -37,28 +37,22 @@
#ifdef USE_MUNT
# include "midi_mt32.h"
#endif
#include "midi_input.h"
#define SYSEX_SIZE 1024
#define RAWBUF 1024
int midi_device_current = 0;
static int midi_device_last = 0;
int midi_input_device_current = 0;
static int midi_input_device_last = 0;
midi_t *midi = NULL;
typedef struct
{
uint8_t midi_rt_buf[1024], midi_cmd_buf[1024],
midi_status, midi_sysex_data[1026];
int midi_cmd_pos, midi_cmd_len;
unsigned int midi_sysex_start, midi_sysex_delay,
midi_pos;
midi_device_t* m_device;
} midi_t;
void (*input_msg)(uint8_t *msg);
int (*input_sysex)(uint8_t *buffer, uint32_t len, int abort);
static midi_t *midi = NULL;
uint8_t MIDI_InSysexBuf[SYSEX_SIZE];
static uint8_t MIDI_evt_len[256] = {
uint8_t MIDI_evt_len[256] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x00 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x10 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x20 */
@@ -85,7 +79,7 @@ typedef struct
{
const char *name, *internal_name;
const device_t *device;
} MIDI_DEVICE;
} MIDI_DEVICE, MIDI_IN_DEVICE;
static const MIDI_DEVICE devices[] =
{
@@ -101,6 +95,12 @@ static const MIDI_DEVICE devices[] =
{"", "", NULL}
};
static const MIDI_IN_DEVICE midi_in_devices[] =
{
{"None", "none", NULL},
{MIDI_INPUT_NAME, MIDI_INPUT_INTERNAL_NAME, &midi_input_device},
{"", "", NULL}
};
int
midi_device_available(int card)
@@ -172,16 +172,39 @@ midi_init(midi_device_t* device)
midi = (midi_t *) malloc(sizeof(midi_t));
memset(midi, 0, sizeof(midi_t));
midi->m_device = device;
midi->m_out_device = device;
}
void
midi_in_init(midi_device_t* device, midi_t **mididev)
{
*mididev = (midi_t *)malloc(sizeof(midi_t));
memset(*mididev, 0, sizeof(midi_t));
(*mididev)->m_in_device = device;
}
void
midi_close(void)
{
if (midi && midi->m_device) {
free(midi->m_device);
midi->m_device = NULL;
if (midi && midi->m_out_device) {
free(midi->m_out_device);
midi->m_out_device = NULL;
}
if (midi) {
free(midi);
midi = NULL;
}
}
void
midi_in_close(void)
{
if (midi && midi->m_in_device) {
free(midi->m_in_device);
midi->m_in_device = NULL;
}
if (midi) {
@@ -194,36 +217,119 @@ midi_close(void)
void
midi_poll(void)
{
if (midi && midi->m_device && midi->m_device->poll)
midi->m_device->poll();
if (midi && midi->m_out_device && midi->m_out_device->poll)
midi->m_out_device->poll();
}
void
play_msg(uint8_t *msg)
{
if (midi->m_device->play_msg)
midi->m_device->play_msg(msg);
if (midi->m_out_device->play_msg)
midi->m_out_device->play_msg(msg);
}
void
play_sysex(uint8_t *sysex, unsigned int len)
{
if (midi->m_device->play_sysex)
midi->m_device->play_sysex(sysex, len);
if (midi->m_out_device->play_sysex)
midi->m_out_device->play_sysex(sysex, len);
}
int
midi_in_device_available(int card)
{
if (midi_in_devices[card].device)
return device_available(midi_in_devices[card].device);
return 1;
}
char *
midi_in_device_getname(int card)
{
return (char *) midi_in_devices[card].name;
}
const device_t *
midi_in_device_getdevice(int card)
{
return midi_in_devices[card].device;
}
int
midi_in_device_has_config(int card)
{
if (!midi_in_devices[card].device)
return 0;
return midi_in_devices[card].device->config ? 1 : 0;
}
char *
midi_in_device_get_internal_name(int card)
{
return (char *) midi_in_devices[card].internal_name;
}
int
midi_in_device_get_from_internal_name(char *s)
{
int c = 0;
while (strlen(midi_in_devices[c].internal_name)) {
if (!strcmp(midi_in_devices[c].internal_name, s))
return c;
c++;
}
return 0;
}
void
midi_write(uint8_t val)
midi_in_device_init()
{
if (midi_in_devices[midi_input_device_current].device)
device_add(midi_in_devices[midi_input_device_current].device);
midi_input_device_last = midi_input_device_current;
}
void
midi_raw_out_rt_byte(uint8_t val)
{
if (!midi || !midi->m_out_device || !midi->m_in_device)
return;
if (!midi->midi_realtime)
return;
if ((!midi->midi_clockout && (val == 0xf8)))
return;
midi->midi_cmd_r = val << 24;
pclog("Play RT Byte msg\n");
play_msg((uint8_t *)&midi->midi_cmd_r);
}
void
midi_raw_out_thru_rt_byte(uint8_t val)
{
if (midi->thruchan)
midi_raw_out_rt_byte(val);
}
void
midi_raw_out_byte(uint8_t val)
{
uint32_t passed_ticks;
if (!midi || !midi->m_device)
if (!midi || !midi->m_out_device)
return;
if (midi->m_device->write && midi->m_device->write(val))
if ((midi->m_out_device->write && midi->m_out_device->write(val)))
return;
if (midi->midi_sysex_start) {
@@ -289,3 +395,12 @@ midi_write(uint8_t val)
}
}
}
void
midi_clear_buffer(void)
{
midi->midi_pos = 0;
midi->midi_status = 0x00;
midi->midi_cmd_pos = 0;
midi->midi_cmd_len = 0;
}

View File

@@ -2,18 +2,34 @@
# define EMU_SOUND_MIDI_H
extern int midi_device_current;
#define SYSEX_SIZE 8192
extern uint8_t MIDI_InSysexBuf[SYSEX_SIZE];
extern uint8_t MIDI_evt_len[256];
extern int midi_device_current;
extern int midi_input_device_current;
extern void (*input_msg)(uint8_t *msg);
extern int (*input_sysex)(uint8_t *buffer, uint32_t len, int abort);
int midi_device_available(int card);
int midi_in_device_available(int card);
char *midi_device_getname(int card);
char *midi_in_device_getname(int card);
#ifdef EMU_DEVICE_H
const device_t *midi_device_getdevice(int card);
const device_t *midi_in_device_getdevice(int card);
#endif
int midi_device_has_config(int card);
int midi_in_device_has_config(int card);
char *midi_device_get_internal_name(int card);
char *midi_in_device_get_internal_name(int card);
int midi_device_get_from_internal_name(char *s);
int midi_in_device_get_from_internal_name(char *s);
void midi_device_init();
void midi_in_device_init();
typedef struct midi_device_t
{
@@ -23,9 +39,27 @@ typedef struct midi_device_t
int (*write)(uint8_t val);
} midi_device_t;
typedef struct midi_t
{
uint8_t midi_rt_buf[8], midi_cmd_buf[8],
midi_status, midi_sysex_data[SYSEX_SIZE];
int midi_cmd_pos, midi_cmd_len, midi_cmd_r,
midi_realtime, thruchan, midi_clockout;
unsigned int midi_sysex_start, midi_sysex_delay,
midi_pos;
midi_device_t *m_out_device, *m_in_device;
} midi_t;
extern midi_t *midi;
void midi_init(midi_device_t* device);
void midi_in_init(midi_device_t* device, midi_t **mididev);
void midi_close();
void midi_write(uint8_t val);
void midi_in_close(void);
void midi_raw_out_rt_byte(uint8_t val);
void midi_raw_out_thru_rt_byte(uint8_t val);
void midi_raw_out_byte(uint8_t val);
void midi_clear_buffer(void);
void midi_poll();
#if 0
@@ -41,5 +75,7 @@ void midi_poll();
#define SYSTEM_MIDI_INTERNAL_NAME "system_midi"
#endif
#define MIDI_INPUT_NAME "MIDI Input Device"
#define MIDI_INPUT_INTERNAL_NAME "midi_in"
#endif /*EMU_SOUND_MIDI_H*/

1
src/sound/midi_input.h Normal file
View File

@@ -0,0 +1 @@
extern const device_t midi_input_device;

View File

@@ -9,6 +9,7 @@
#include "../plat_midi.h"
#include "midi.h"
#include "midi_system.h"
#include "midi_input.h"
void* system_midi_init(const device_t *info)
@@ -16,6 +17,8 @@ void* system_midi_init(const device_t *info)
midi_device_t* dev = malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t));
pclog("MIDI Output\n");
dev->play_msg = plat_midi_play_msg;
dev->play_sysex = plat_midi_play_sysex;
dev->write = plat_midi_write;
@@ -27,6 +30,24 @@ void* system_midi_init(const device_t *info)
return dev;
}
void* midi_input_init(const device_t *info)
{
midi_device_t* dev = malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t));
pclog("MIDI Input\n");
plat_midi_input_init();
midi_in_init(dev, &midi);
midi->midi_realtime = device_get_config_int("realtime");
midi->thruchan = device_get_config_int("thruchan");
midi->midi_clockout = device_get_config_int("clockout");
return dev;
}
void system_midi_close(void* p)
{
plat_midi_close();
@@ -34,11 +55,23 @@ void system_midi_close(void* p)
midi_close();
}
void midi_input_close(void* p)
{
plat_midi_input_close();
midi_close();
}
int system_midi_available(void)
{
return plat_midi_get_num_devs();
}
int midi_input_available(void)
{
return plat_midi_in_get_num_devs();
}
static const device_config_t system_midi_config[] =
{
{
@@ -52,6 +85,37 @@ static const device_config_t system_midi_config[] =
}
};
static const device_config_t midi_input_config[] =
{
{
.name = "midi_input",
.description = "MIDI in device",
.type = CONFIG_MIDI_IN,
.default_int = 0
},
{
.name = "realtime",
.description = "MIDI Real time",
.type = CONFIG_BINARY,
.default_int = 0
},
{
.name = "thruchan",
.description = "MIDI Thru",
.type = CONFIG_BINARY,
.default_int = 1
},
{
.name = "clockout",
.description = "MIDI Clockout",
.type = CONFIG_BINARY,
.default_int = 1
},
{
.type = -1
}
};
const device_t system_midi_device =
{
SYSTEM_MIDI_NAME,
@@ -64,3 +128,17 @@ const device_t system_midi_device =
NULL,
system_midi_config
};
const device_t midi_input_device =
{
MIDI_INPUT_NAME,
0, 0,
midi_input_init,
midi_input_close,
NULL,
midi_input_available,
NULL,
NULL,
midi_input_config
};

View File

@@ -13,6 +13,8 @@
#include "../pci.h"
#include "../timer.h"
#include "sound.h"
#include "midi.h"
#include "snd_mpu401.h"
#include "snd_audiopci.h"
@@ -23,6 +25,8 @@
static float low_fir_es1371_coef[ES1371_NCoef];
typedef struct {
mpu_t mpu;
uint8_t pci_command, pci_serr;
uint32_t base_addr;
@@ -116,14 +120,21 @@ typedef struct {
#define INT_DAC1_EN (1<<6)
#define INT_DAC2_EN (1<<5)
#define INT_UART_EN (1<<3)
#define SI_P2_INTR_EN (1<<9)
#define SI_P1_INTR_EN (1<<8)
#define INT_STATUS_INTR (1<<31)
#define INT_STATUS_UART (1<<3)
#define INT_STATUS_DAC1 (1<<2)
#define INT_STATUS_DAC2 (1<<1)
#define UART_CTRL_TXINTEN (1<<5)
#define UART_STATUS_TXINT (1<<2)
#define UART_STATUS_TXRDY (1<<1)
#define FORMAT_MONO_8 0
#define FORMAT_STEREO_8 1
#define FORMAT_MONO_16 2
@@ -164,8 +175,13 @@ static void es1371_update_irqs(es1371_t *es1371)
if ((es1371->int_status & INT_STATUS_DAC1) && (es1371->si_cr & SI_P1_INTR_EN))
irq = 1;
if ((es1371->int_status & INT_STATUS_DAC2) && (es1371->si_cr & SI_P2_INTR_EN))
if ((es1371->int_status & INT_STATUS_DAC2) && (es1371->si_cr & SI_P2_INTR_EN)) {
irq = 1;
}
/*MIDI input is unsupported for now*/
if ((es1371->int_status & INT_STATUS_UART) && (es1371->uart_status & UART_STATUS_TXINT)) {
irq = 1;
}
if (irq)
es1371->int_status |= INT_STATUS_INTR;
@@ -219,10 +235,10 @@ static uint8_t es1371_inb(uint16_t port, void *p)
case 0x07:
ret = (es1371->int_status >> 24) & 0xff;
break;
case 0x09:
ret = es1371->uart_status;
ret = es1371->uart_status & 0xc7;
audiopci_log("ES1371 UART Status = %02x\n", es1371->uart_status);
break;
case 0x0c:
@@ -253,7 +269,7 @@ static uint8_t es1371_inb(uint16_t port, void *p)
audiopci_log("Bad es1371_inb: port=%04x\n", port);
}
// audiopci_log("es1371_inb: port=%04x ret=%02x\n", port, ret);
audiopci_log("es1371_inb: port=%04x ret=%02x\n", port, ret);
// output = 3;
return ret;
}
@@ -340,31 +356,51 @@ static uint32_t es1371_inl(uint16_t port, void *p)
ret |= CODEC_READY;
break;
case 0x34:
switch (es1371->mem_page)
{
case 0x30:
switch (es1371->mem_page) {
case 0xe: case 0xf:
audiopci_log("ES1371 0x30 read UART FIFO: val = %02x\n", ret & 0xff);
break;
}
break;
case 0x34:
switch (es1371->mem_page) {
case 0xc:
ret = es1371->dac[0].size | (es1371->dac[0].count << 16);
break;
case 0xd:
ret = es1371->adc.size | (es1371->adc.count << 16);
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x34 read UART FIFO: val = %02x\n", ret & 0xff);
break;
default:
audiopci_log("Bad es1371_inl: mem_page=%x port=%04x\n", es1371->mem_page, port);
}
break;
case 0x38:
switch (es1371->mem_page) {
case 0xe: case 0xf:
audiopci_log("ES1371 0x38 read UART FIFO: val = %02x\n", ret & 0xff);
break;
}
break;
case 0x3c:
switch (es1371->mem_page)
{
switch (es1371->mem_page) {
case 0xc:
ret = es1371->dac[1].size | (es1371->dac[1].count << 16);
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x3c read UART FIFO: val = %02x\n", ret & 0xff);
break;
default:
audiopci_log("Bad es1371_inl: mem_page=%x port=%04x\n", es1371->mem_page, port);
}
@@ -374,7 +410,7 @@ static uint32_t es1371_inl(uint16_t port, void *p)
audiopci_log("Bad es1371_inl: port=%04x\n", port);
}
// audiopci_log("es1371_inl: port=%04x ret=%08x %08x\n", port, ret, cpu_state.pc);
audiopci_log("es1371_inl: port=%04x ret=%08x\n", port, ret);
return ret;
}
@@ -382,7 +418,7 @@ static void es1371_outb(uint16_t port, uint8_t val, void *p)
{
es1371_t *es1371 = (es1371_t *)p;
// audiopci_log("es1371_outb: port=%04x val=%02x %04x:%08x\n", port, val, cs, cpu_state.pc);
audiopci_log("es1371_outb: port=%04x val=%02x\n", port, val);
switch (port & 0x3f)
{
case 0x00:
@@ -412,8 +448,13 @@ static void es1371_outb(uint16_t port, uint8_t val, void *p)
es1371->int_ctrl = (es1371->int_ctrl & 0x00ffffff) | (val << 24);
break;
case 0x08:
midi_raw_out_byte(val);
break;
case 0x09:
es1371->uart_ctrl = val;
es1371->uart_ctrl = val & 0xe3;
audiopci_log("ES1371 UART Cntrl = %02x\n", es1371->uart_ctrl);
break;
case 0x0c:
@@ -481,7 +522,7 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p)
{
es1371_t *es1371 = (es1371_t *)p;
// audiopci_log("es1371_outl: port=%04x val=%08x %04x:%08x\n", port, val, CS, cpu_state.pc);
audiopci_log("es1371_outl: port=%04x val=%08x\n", port, val);
switch (port & 0x3f)
{
case 0x04:
@@ -593,6 +634,10 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p)
// audiopci_log("DAC1 addr %08x\n", val);
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x30 write UART FIFO: val = %02x\n", val & 0xff);
break;
default:
audiopci_log("Bad es1371_outl: mem_page=%x port=%04x val=%08x\n", es1371->mem_page, port, val);
}
@@ -615,6 +660,10 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p)
es1371->adc.count = val >> 16;
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x34 write UART FIFO: val = %02x\n", val & 0xff);
break;
default:
audiopci_log("Bad es1371_outl: mem_page=%x port=%04x val=%08x\n", es1371->mem_page, port, val);
}
@@ -633,6 +682,10 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p)
case 0xd:
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x38 write UART FIFO: val = %02x\n", val & 0xff);
break;
default:
audiopci_log("Bad es1371_outl: mem_page=%x port=%04x val=%08x\n", es1371->mem_page, port, val);
@@ -649,6 +702,10 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p)
case 0xc:
es1371->dac[1].size = val & 0xffff;
es1371->dac[1].count = val >> 16;
break;
case 0xe: case 0xf:
audiopci_log("ES1371 0x3c write UART FIFO: val = %02x\n", val & 0xff);
break;
default:
@@ -1107,10 +1164,33 @@ static void es1371_poll(void *p)
timer_advance_u64(&es1371->dac[1].timer, es1371->dac[1].latch);
es1371_update(es1371);
if (es1371->int_ctrl & INT_DAC1_EN)
{
es1371_update(es1371);
if (es1371->int_ctrl & INT_UART_EN) {
audiopci_log("UART INT Enabled\n");
if (es1371->uart_ctrl & 0x80) { /*We currently don't implement MIDI Input.*/
/*But if anything sets MIDI Input and Output together we'd have to take account
of the MIDI Output case, and disable IRQ's and RX bits when MIDI Input is enabled as well but not in the MIDI Output portion*/
if (es1371->uart_ctrl & UART_CTRL_TXINTEN)
es1371->int_status |= INT_STATUS_UART;
else
es1371->int_status &= ~INT_STATUS_UART;
} else if (!(es1371->uart_ctrl & 0x80) && ((es1371->uart_ctrl & UART_CTRL_TXINTEN))) { /*Or enable the UART IRQ and the respective TX bits only when the MIDI Output is enabled*/
es1371->int_status |= INT_STATUS_UART;
}
if (es1371->uart_ctrl & 0x80) {
if (es1371->uart_ctrl & UART_CTRL_TXINTEN)
es1371->uart_status |= (UART_STATUS_TXINT | UART_STATUS_TXRDY);
else
es1371->uart_status &= ~(UART_STATUS_TXINT | UART_STATUS_TXRDY);
} else
es1371->uart_status |= (UART_STATUS_TXINT | UART_STATUS_TXRDY);
es1371_update_irqs(es1371);
}
if (es1371->int_ctrl & INT_DAC1_EN) {
int frac = es1371->dac[0].ac & 0x7fff;
int idx = es1371->dac[0].ac >> 15;
int samp1_l = es1371->dac[0].filtered_l[idx];

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
*
* Roland MPU-401 emulation.
*
* Version: @(#)sound_mpu401.h 1.0.3 2018/09/11
* Version: @(#)sound_mpu401.h 1.0.4 2018/09/31
*
* Author: Sarah Walker, <http://pcem-emulator.co.uk/>
* DOSBox Team,
@@ -22,10 +22,16 @@
#define MPU401_VERSION 0x15
#define MPU401_REVISION 0x01
#define MPU401_QUEUE 32
#define MPU401_QUEUE 64
#define MPU401_INPUT_QUEUE 1024
#define MPU401_TIMECONSTANT (60000000/1000.0f)
#define MPU401_RESETBUSY 27.0f
/*helpers*/
#define M_GETKEY key[key/32]&(1<<(key%32))
#define M_SETKEY key[key/32]|=(1<<(key%32))
#define M_DELKEY key[key/32]&=~(1<<(key%32))
typedef enum MpuMode
{
M_UART,
@@ -43,6 +49,13 @@ typedef enum MpuDataType
T_COMMAND
} MpuDataType;
typedef enum RecState
{
M_RECOFF,
M_RECSTB,
M_RECON
} RecState;
/* Messages sent to MPU-401 from host */
#define MSG_EOX 0xf7
#define MSG_OVERFLOW 0xf8
@@ -57,6 +70,7 @@ typedef enum MpuDataType
typedef struct mpu_t
{
int midi_thru;
int uart_mode, intelligent,
irq,
queue_pos, queue_used;
@@ -64,10 +78,13 @@ typedef struct mpu_t
status,
queue[MPU401_QUEUE], pos_regs[8];
MpuMode mode;
uint8_t rec_queue[MPU401_INPUT_QUEUE];
int rec_queue_pos, rec_queue_used;
uint32_t ch_toref[16];
struct track
{
int counter;
uint8_t value[8], sys_val,
uint8_t value[3], sys_val,
vlength,length;
MpuDataType type;
} playbuf[8], condbuf;
@@ -77,23 +94,50 @@ typedef struct mpu_t
playing, reset,
wsd, wsm, wsd_start,
run_irq, irq_pending,
track_req,
send_now, eoi_scheduled,
data_onoff;
data_onoff, clock_to_host,
sync_in, sysex_in_finished,
rec_copy;
RecState rec;
uint8_t tmask, cmask,
amask,
channel, old_chan;
last_rtcmd;
uint16_t midi_mask, req_mask;
uint32_t command_byte, cmd_pending;
uint32_t command_byte, cmd_pending,
track, old_track;
} state;
struct {
uint8_t timebase, old_timebase,
tempo, old_tempo,
tempo_rel, old_tempo_rel,
tempo_grad,
cth_rate, cth_counter;
int clock_to_host,cth_active;
tempo_grad, cth_rate[4],
cth_mode, midimetro,
metromeas;
uint32_t cth_counter, cth_old,
rec_counter;
int32_t measure_counter, meas_old,
freq;
int ticks_in, active;
float freq_mod;
} clock;
struct {
int all_thru, midi_thru,
sysex_thru, commonmsgs_thru,
modemsgs_in, commonmsgs_in,
bender_in, sysex_in,
allnotesoff_out, rt_affection,
rt_out, rt_in,
timing_in_stop, data_in_stop,
rec_measure_end;
uint8_t prchg_buf[16];
uint16_t prchg_mask;
} filter;
struct {
int on;
uint8_t chan, trmask;
uint32_t key[4];
} chanref[5], inputref[16];
pc_timer_t mpu401_event_callback, mpu401_eoi_callback,
mpu401_reset_callback;
} mpu_t;

View File

@@ -32,6 +32,7 @@
#include "../rom.h"
#include "../device.h"
#include "sound.h"
#include "midi.h"
#include "filters.h"
#include "snd_emu8k.h"
#include "snd_mpu401.h"
@@ -188,6 +189,12 @@ sb_log(const char *fmt, ...)
#endif
static void
sb_dsp_set_midi_in(sb_dsp_t *src_dsp_midi_in)
{
dspin = src_dsp_midi_in;
}
/* sb 1, 1.5, 2, 2 mvc do not have a mixer, so signal is hardwired */
static void sb_get_buffer_sb2(int32_t *buffer, int len, void *p)
{
@@ -1041,6 +1048,11 @@ void *sb_1_init()
io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl);
}
sound_add_handler(sb_get_buffer_sb2, sb);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
void *sb_15_init()
@@ -1067,6 +1079,11 @@ void *sb_15_init()
io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl);
}
sound_add_handler(sb_get_buffer_sb2, sb);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1090,6 +1107,11 @@ void *sb_mcv_init()
mca_add(sb_mcv_read, sb_mcv_write, sb_mcv_feedb, sb);
sb->pos_regs[0] = 0x84;
sb->pos_regs[1] = 0x50;
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
void *sb_2_init()
@@ -1137,6 +1159,10 @@ void *sb_2_init()
else
sound_add_handler(sb_get_buffer_sb2, sb);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1170,6 +1196,10 @@ void *sb_pro_v1_init()
io_sethandler(addr+4, 0x0002, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, sb);
sound_add_handler(sb_get_buffer_sbpro, sb);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1202,6 +1232,10 @@ void *sb_pro_v2_init()
io_sethandler(addr+4, 0x0002, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, sb);
sound_add_handler(sb_get_buffer_sbpro, sb);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1227,6 +1261,10 @@ void *sb_pro_mcv_init()
sb->pos_regs[0] = 0x03;
sb->pos_regs[1] = 0x51;
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1261,6 +1299,11 @@ void *sb_16_init()
} else
sb->mpu = NULL;
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}
@@ -1305,6 +1348,10 @@ void *sb_awe32_init()
sb->mpu = NULL;
emu8k_init(&sb->emu8k, emu_addr, onboard_ram);
sb_dsp_set_midi_in(&sb->dsp);
input_msg = sb_dsp_input_msg;
input_sysex = sb_dsp_input_sysex;
return sb;
}

View File

@@ -119,7 +119,7 @@ uint8_t adjustMap2[24] = {
};
float low_fir_sb16_coef[SB16_NCoef];
sb_dsp_t *dspin;
#ifdef ENABLE_SB_DSP_LOG
int sb_dsp_do_log = ENABLE_SB_DSP_LOG;
@@ -147,7 +147,6 @@ sinc(double x)
return sin(M_PI * x) / (M_PI * x);
}
static void
recalc_sb16_filter(int playback_freq)
{
@@ -207,6 +206,8 @@ sb_irqc(sb_dsp_t *dsp, int irq8)
void
sb_dsp_reset(sb_dsp_t *dsp)
{
midi_clear_buffer();
timer_disable(&dsp->output_timer);
timer_disable(&dsp->input_timer);
@@ -218,7 +219,7 @@ sb_dsp_reset(sb_dsp_t *dsp)
sb_irqc(dsp, 0);
sb_irqc(dsp, 1);
dsp->sb_16_pause = 0;
dsp->sb_read_wp = dsp->sb_read_rp = 0;
dsp->sb_read_wp = dsp->sb_read_rp = 0;
dsp->sb_data_stat = -1;
dsp->sb_speaker = 0;
dsp->sb_pausetime = -1LL;
@@ -393,7 +394,6 @@ sb_dsp_setdma16(sb_dsp_t *dsp, int dma)
dsp->sb_16_dmanum = dma;
}
void
sb_exec_command(sb_dsp_t *dsp)
{
@@ -457,19 +457,35 @@ sb_exec_command(sb_dsp_t *dsp)
if (dsp->sb_type >= SB15)
sb_start_dma_i(dsp, 1, 1, 0, dsp->sb_data[0] + (dsp->sb_data[1] << 8));
break;
case 0x30: case 0x31:
case 0x30: /* MIDI Polling mode input */
pclog("MIDI polling mode input\n");
dsp->midi_in_poll = 1;
dsp->uart_irq = 0;
break;
case 0x34: /* MIDI (UART mode) */
case 0x31: /* MIDI Interrupt mode input */
pclog("MIDI interrupt mode input\n");
dsp->midi_in_poll = 0;
dsp->uart_irq = 1;
break;
case 0x34: /* MIDI In poll */
if (dsp->sb_type < SB2)
break;
pclog("MIDI poll in\n");
dsp->midi_in_poll = 1;
dsp->uart_midi = 1;
dsp->uart_irq = 0;
break;
case 0x35: /* MIDI (UART mode) */
case 0x35: /* MIDI In irq */
if (dsp->sb_type < SB2)
break;
pclog("MIDI irq in\n");
dsp->midi_in_poll = 0;
dsp->uart_midi = 1;
dsp->uart_irq = 1;
break;
case 0x36: case 0x37:
case 0x36: case 0x37: /* MIDI timestamps */
break;
case 0x38: /* MIDI (Normal mode) */
case 0x38: /* Write to SB MIDI Output (Raw) */
dsp->onebyte_midi = 1;
break;
case 0x40: /* Set time constant */
@@ -724,17 +740,22 @@ sb_write(uint16_t a, uint8_t v, void *priv)
switch (a & 0xF) {
case 6: /* Reset */
if (!(v & 1) && (dsp->sbreset & 1)) {
sb_dsp_reset(dsp);
sb_add_data(dsp, 0xAA);
if (!dsp->uart_midi) {
if (!(v & 1) && (dsp->sbreset & 1)) {
sb_dsp_reset(dsp);
sb_add_data(dsp, 0xAA);
}
dsp->sbreset = v;
}
dsp->sbreset = v;
dsp->uart_midi = 0;
dsp->uart_irq = 0;
dsp->onebyte_midi = 0;
return;
case 0xC: /* Command/data write */
if (dsp->uart_midi || dsp->onebyte_midi) {
midi_write(v);
if (dsp->uart_midi || dsp->onebyte_midi ) {
midi_raw_out_byte(v);
dsp->onebyte_midi = 0;
return;
return;
}
timer_set_delay_u64(&dsp->wb_timer, TIMER_USEC * 1);
if (dsp->asp_data_len) {
@@ -768,9 +789,9 @@ sb_read(uint16_t a, void *priv)
switch (a & 0xf) {
case 0xA: /* Read data */
if (mpu && dsp->uart_midi)
if (mpu && dsp->uart_midi) {
ret = MPU401_ReadData(mpu);
else {
} else {
dsp->sbreaddat = dsp->sb_read_data[dsp->sb_read_rp];
if (dsp->sb_read_rp != dsp->sb_read_wp) {
dsp->sb_read_rp++;
@@ -814,6 +835,47 @@ sb_dsp_set_mpu(mpu_t *src_mpu)
mpu = src_mpu;
}
void
sb_dsp_input_msg(uint8_t *msg)
{
pclog("MIDI in sysex = %d, uart irq = %d, midi in = %d\n", dspin->midi_in_sysex, dspin->uart_irq, dspin->midi_in_poll);
if (dspin->midi_in_sysex) {
return;
}
uint8_t len = msg[3];
uint8_t i = 0;
if (dspin->uart_irq) {
for (i=0;i<len;i++)
sb_add_data(dspin, msg[i]);
if (!dspin->sb_irq8) sb_irq(dspin, 1);
} else if (dspin->midi_in_poll) {
for (i=0;i<len;i++)
sb_add_data(dspin, msg[i]);
}
}
int
sb_dsp_input_sysex(uint8_t *buffer, uint32_t len, int abort)
{
uint32_t i;
if (abort) {
dspin->midi_in_sysex = 0;
return 0;
}
dspin->midi_in_sysex = 1;
for (i=0;i<len;i++) {
if (dspin->sb_read_rp == dspin->sb_read_wp) {
pclog("Length sysex SB = %d\n", len-i);
return (len-i);
}
sb_add_data(dspin, buffer[i]);
}
dspin->midi_in_sysex = 0;
return 0;
}
void
sb_dsp_init(sb_dsp_t *dsp, int type)

View File

@@ -9,14 +9,18 @@ typedef struct sb_dsp_t
int sb_pausetime;
uint8_t sb_read_data[256];
int sb_read_wp, sb_read_rp;
int sb_read_wp, sb_read_rp;
int sb_speaker;
int muted;
int sb_data_stat;
int uart_midi;
int uart_irq;
int onebyte_midi;
int midi_in_sysex;
int midi_in_poll;
int uart_midi;
int uart_irq;
int onebyte_midi;
int midi_in_timestamp;
int sb_irqnum;
@@ -72,6 +76,12 @@ typedef struct sb_dsp_t
int pos;
} sb_dsp_t;
extern sb_dsp_t *dspin;
void sb_dsp_input_msg(uint8_t *msg);
int sb_dsp_input_sysex(uint8_t *buffer, uint32_t len, int abort);
void sb_dsp_set_mpu(mpu_t *src_mpu);
void sb_dsp_init(sb_dsp_t *dsp, int type);

View File

@@ -107,7 +107,6 @@ static const SOUND_CARD sound_cards[] =
{ "[MCA] Sound Blaster MCV", "sbmcv", &sb_mcv_device },
{ "[MCA] Sound Blaster Pro MCV", "sbpromcv", &sb_pro_mcv_device },
{ "[PCI] Ensoniq AudioPCI (ES1371)", "es1371", &es1371_device },
{ "[PCI] Sound Blaster PCI 128", "sbpci128", &es1371_device },
{ "", "", NULL }
};
@@ -442,6 +441,7 @@ sound_reset(void)
sound_realloc_buffers();
midi_device_init();
midi_in_device_init();
inital();
timer_add(&sound_poll_timer, sound_poll, NULL, 1);

View File

@@ -380,34 +380,39 @@ 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,101,94,10
CONTROL "Use FLOAT32 sound",IDC_CHECK_FLOAT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,147,81,94,10
BS_AUTOCHECKBOX | WS_TABSTOP,147,101,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 +422,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 +451,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: */
@@ -149,6 +150,7 @@
#define IDC_CONFIGURE_MPU401 1077
#define IDC_CHECK_FLOAT 1078
#define IDC_CHECK_GUSMAX 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,13 +13,15 @@
typedef struct
{
int midi_id;
int midi_id, midi_input_id;
HANDLE m_event;
HANDLE m_callback;
HMIDIOUT midi_out_device;
HMIDIIN midi_in_device;
MIDIHDR m_hdr;
MIDIHDR m_hdr, m_hdr_in;
} plat_midi_t;
plat_midi_t *pm = NULL;
@@ -39,6 +41,7 @@ plat_midi_init(void)
pm->m_event = CreateEvent(NULL, TRUE, TRUE, NULL);
pclog("Plat MIDI Out init\n");
hr = midiOutOpen(&pm->midi_out_device, pm->midi_id,
(uintptr_t) pm->m_event, 0, CALLBACK_EVENT);
if (hr != MMSYSERR_NOERROR) {
@@ -65,7 +68,7 @@ plat_midi_close(void)
midiOutClose(pm->midi_out_device);
CloseHandle(pm->m_event);
}
free(pm);
pm = NULL;
}
@@ -135,3 +138,119 @@ 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) {
pclog("MIDI: wMsg:%x %x %x\n",wMsg, dwParam1, dwParam2);
uint8_t msg[4] = {((dwParam1&0xff)),(((dwParam1&0xff00)>>8)),
(((dwParam1&0xff0000)>>16)),MIDI_evt_len[((dwParam1&0xff))]};
uint8_t *sysex;
int len;
int cnt;
MIDIHDR *t_hdr;
switch (wMsg) {
case MM_MIM_DATA: /* 0x3C3 - midi message */
input_msg(msg);
break;
case MM_MIM_OPEN: /* 0x3C1 */
break;
case MM_MIM_CLOSE: /* 0x3C2 */
break;
case MM_MIM_LONGDATA: /* 0x3C4 - sysex */
pclog("MIDI sysex\n");
t_hdr = (MIDIHDR *)dwParam1;
sysex = (uint8_t *)t_hdr->lpData;
len = (unsigned int)t_hdr->dwBytesRecorded;
cnt = 5;
while (cnt) { /*abort if timed out*/
int ret = input_sysex(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(sysex, 0, 0);
midiInUnprepareHeader(hMidiIn, t_hdr, sizeof(*t_hdr));
t_hdr->dwBytesRecorded = 0;
midiInPrepareHeader(hMidiIn, t_hdr, sizeof(*t_hdr));
break;
case MM_MIM_ERROR:
case MM_MIM_LONGERROR:
break;
default:
break;
}
}
void
plat_midi_input_init(void)
{
MMRESULT hr;
pm = (plat_midi_t *) malloc(sizeof(plat_midi_t));
memset(pm, 0, sizeof(plat_midi_t));
pclog("Plat MIDI Input init\n");
pm->midi_input_id = config_get_int(MIDI_INPUT_NAME, "midi_input", 0);
hr = midiInOpen(&pm->midi_in_device, pm->midi_input_id,
(uintptr_t) plat_midi_in_callback, 0, CALLBACK_FUNCTION);
if (hr != MMSYSERR_NOERROR) {
pclog("midiInOpen error - %08X\n", hr);
pm->midi_input_id = 0;
hr = midiInOpen(&pm->midi_in_device, pm->midi_input_id,
(uintptr_t) plat_midi_in_callback, 0, CALLBACK_FUNCTION);
if (hr != MMSYSERR_NOERROR) {
pclog("midiInOpen error - %08X\n", hr);
return;
}
}
pm->m_hdr_in.lpData = (char*)&MIDI_InSysexBuf[0];
pm->m_hdr_in.dwBufferLength = SYSEX_SIZE;
pm->m_hdr_in.dwBytesRecorded = 0 ;
pm->m_hdr_in.dwUser = 0;
pclog("Prepare MIDI In\n");
midiInPrepareHeader(pm->midi_in_device,&pm->m_hdr_in,sizeof(pm->m_hdr_in));
midiInStart(pm->midi_in_device);
}
void
plat_midi_input_close(void)
{
if (pm) {
if (pm->midi_in_device != NULL) {
midiInStop(pm->midi_in_device);
midiInClose(pm->midi_in_device);
}
free(pm);
pm = 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

@@ -84,7 +84,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 +123,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 +219,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 +331,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 +434,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,12 +1104,13 @@ 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;
}
@@ -1195,12 +1200,45 @@ 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);
@@ -1270,6 +1308,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);
@@ -1292,6 +1355,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);