Fixed midi input code. Currently only MPU401 (standalone) and SB cards have MIDI Input capabilities, es1371 and GUS will be done for a later time.
This commit is contained in:
@@ -45,10 +45,11 @@ static int midi_device_last = 0;
|
||||
int midi_input_device_current = 0;
|
||||
static int midi_input_device_last = 0;
|
||||
|
||||
midi_t *midi = NULL;
|
||||
midi_t *midi = NULL, *midi_in = NULL;
|
||||
|
||||
void (*input_msg)(uint8_t *msg);
|
||||
int (*input_sysex)(uint8_t *buffer, uint32_t len, int abort);
|
||||
void (*input_msg)(void *p, uint8_t *msg);
|
||||
int (*input_sysex)(void *p, uint8_t *buffer, uint32_t len, int abort);
|
||||
void *midi_in_p;
|
||||
|
||||
uint8_t MIDI_InSysexBuf[SYSEX_SIZE];
|
||||
|
||||
@@ -202,14 +203,14 @@ midi_close(void)
|
||||
void
|
||||
midi_in_close(void)
|
||||
{
|
||||
if (midi && midi->m_in_device) {
|
||||
free(midi->m_in_device);
|
||||
midi->m_in_device = NULL;
|
||||
if (midi_in && midi_in->m_in_device) {
|
||||
free(midi_in->m_in_device);
|
||||
midi_in->m_in_device = NULL;
|
||||
}
|
||||
|
||||
if (midi) {
|
||||
free(midi);
|
||||
midi = NULL;
|
||||
if (midi_in) {
|
||||
free(midi_in);
|
||||
midi_in = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,24 +301,21 @@ midi_in_device_init()
|
||||
void
|
||||
midi_raw_out_rt_byte(uint8_t val)
|
||||
{
|
||||
if (!midi || !midi->m_out_device || !midi->m_in_device)
|
||||
if (!midi_in->midi_realtime)
|
||||
return;
|
||||
|
||||
if (!midi->midi_realtime)
|
||||
return;
|
||||
|
||||
if ((!midi->midi_clockout && (val == 0xf8)))
|
||||
if ((!midi_in->midi_clockout && (val == 0xf8)))
|
||||
return;
|
||||
|
||||
midi->midi_cmd_r = val << 24;
|
||||
midi_in->midi_cmd_r = val << 24;
|
||||
pclog("Play RT Byte msg\n");
|
||||
play_msg((uint8_t *)&midi->midi_cmd_r);
|
||||
play_msg((uint8_t *)&midi_in->midi_cmd_r);
|
||||
}
|
||||
|
||||
void
|
||||
midi_raw_out_thru_rt_byte(uint8_t val)
|
||||
{
|
||||
if (midi->thruchan)
|
||||
if (midi_in->thruchan)
|
||||
midi_raw_out_rt_byte(val);
|
||||
}
|
||||
|
||||
@@ -326,11 +324,13 @@ midi_raw_out_byte(uint8_t val)
|
||||
{
|
||||
uint32_t passed_ticks;
|
||||
|
||||
if (!midi || !midi->m_out_device)
|
||||
if (!midi || !midi->m_out_device) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((midi->m_out_device->write && midi->m_out_device->write(val)))
|
||||
if ((midi->m_out_device->write && midi->m_out_device->write(val))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (midi->midi_sysex_start) {
|
||||
passed_ticks = plat_get_ticks() - midi->midi_sysex_start;
|
||||
|
||||
@@ -10,8 +10,9 @@ 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);
|
||||
extern void (*input_msg)(void *p, uint8_t *msg);
|
||||
extern int (*input_sysex)(void *p, uint8_t *buffer, uint32_t len, int abort);
|
||||
extern void *midi_in_p;
|
||||
|
||||
int midi_device_available(int card);
|
||||
int midi_in_device_available(int card);
|
||||
@@ -50,7 +51,7 @@ typedef struct midi_t
|
||||
midi_device_t *m_out_device, *m_in_device;
|
||||
} midi_t;
|
||||
|
||||
extern midi_t *midi;
|
||||
extern midi_t *midi, *midi_in;
|
||||
|
||||
void midi_init(midi_device_t* device);
|
||||
void midi_in_init(midi_device_t* device, midi_t **mididev);
|
||||
|
||||
@@ -17,8 +17,6 @@ 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;
|
||||
@@ -35,15 +33,13 @@ 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_in_init(dev, &midi_in);
|
||||
|
||||
midi->midi_realtime = device_get_config_int("realtime");
|
||||
midi->thruchan = device_get_config_int("thruchan");
|
||||
midi->midi_clockout = device_get_config_int("clockout");
|
||||
midi_in->midi_realtime = device_get_config_int("realtime");
|
||||
midi_in->thruchan = device_get_config_int("thruchan");
|
||||
midi_in->midi_clockout = device_get_config_int("clockout");
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,6 @@ static void MPU401_EOIHandler(void *priv);
|
||||
static void MPU401_EOIHandlerDispatch(void *p);
|
||||
static void MPU401_NotesOff(mpu_t *mpu, int i);
|
||||
|
||||
static mpu_t *mpuin;
|
||||
static mutex_t *mpu_lock;
|
||||
|
||||
#ifdef ENABLE_MPU401_LOG
|
||||
int mpu401_do_log = ENABLE_MPU401_LOG;
|
||||
@@ -79,12 +77,6 @@ mpu401_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
mpu401_set_midi_in(mpu_t *src_mpu_in)
|
||||
{
|
||||
mpuin = src_mpu_in;
|
||||
}
|
||||
|
||||
static void
|
||||
MPU401_ReCalcClock(mpu_t *mpu)
|
||||
{
|
||||
@@ -169,14 +161,7 @@ static void
|
||||
MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, int block)
|
||||
{
|
||||
uint32_t cnt;
|
||||
|
||||
if (block) {
|
||||
if (mpu_lock)
|
||||
thread_wait_mutex(mpu_lock);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cnt = 0;
|
||||
while (cnt < len) {
|
||||
if (mpu->rec_queue_used < MPU401_INPUT_QUEUE) {
|
||||
@@ -195,8 +180,6 @@ MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, int block)
|
||||
|
||||
if (mpu->queue_used == 0) {
|
||||
if (mpu->state.rec_copy || mpu->state.irq_pending) {
|
||||
if (block && mpu_lock)
|
||||
thread_release_mutex(mpu_lock);
|
||||
if (mpu->state.irq_pending) {
|
||||
picintc(1 << mpu->irq);
|
||||
mpu->state.irq_pending = 0;
|
||||
@@ -210,9 +193,6 @@ MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, int block)
|
||||
mpu->rec_queue_used--;
|
||||
mpu->rec_queue_pos++;
|
||||
}
|
||||
|
||||
if (block && mpu_lock)
|
||||
thread_release_mutex(mpu_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -341,8 +321,6 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val)
|
||||
if ((val != 0x3f) && (val != 0xff) && !mpu->intelligent)
|
||||
return;
|
||||
|
||||
thread_wait_mutex(mpu_lock);
|
||||
|
||||
/*hack:enable midi through after the first mpu401 command is written*/
|
||||
mpu->midi_thru = 1;
|
||||
|
||||
@@ -402,7 +380,6 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val)
|
||||
MPU401_QueueByte(mpu, MSG_MPU_END);
|
||||
mpu->filter.prchg_mask = 0;
|
||||
mpu->clock.rec_counter = 0;
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0x20: /* Start */
|
||||
if (!(mpu->state.rec == M_RECON)) {
|
||||
@@ -430,7 +407,6 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val)
|
||||
MPU401_RecQueueBuffer(mpu, recmsg, 3, 0);
|
||||
mpu->filter.prchg_mask &= ~(1 << i);
|
||||
}
|
||||
thread_release_mutex(mpu_lock);
|
||||
} else if ((val >= 0xa0) && (val <= 0xa7)) { /* Request play counter */
|
||||
MPU401_QueueByte(mpu, mpu->playbuf[val & 7].counter);
|
||||
} else if ((val >= 0xd0) && (val <= 0xd7)) { /* Send data */
|
||||
@@ -545,22 +521,18 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val)
|
||||
case 0xab: /* Request and clear recording counter */
|
||||
MPU401_QueueByte(mpu, MSG_MPU_ACK);
|
||||
MPU401_QueueByte(mpu, 0);
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0xac: /* Request version */
|
||||
MPU401_QueueByte(mpu, MSG_MPU_ACK);
|
||||
MPU401_QueueByte(mpu, MPU401_VERSION);
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0xad: /* Request revision */
|
||||
MPU401_QueueByte(mpu, MSG_MPU_ACK);
|
||||
MPU401_QueueByte(mpu, MPU401_REVISION);
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0xaf: /* Request tempo */
|
||||
MPU401_QueueByte(mpu, MSG_MPU_ACK);
|
||||
MPU401_QueueByte(mpu, mpu->clock.tempo);
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0xb1: /* Reset relative tempo */
|
||||
mpu->clock.old_tempo_rel = mpu->clock.tempo_rel;
|
||||
@@ -623,7 +595,6 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val)
|
||||
}
|
||||
|
||||
MPU401_QueueByte(mpu, MSG_MPU_ACK);
|
||||
thread_release_mutex(mpu_lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -790,13 +761,10 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val)
|
||||
return;
|
||||
}
|
||||
|
||||
thread_wait_mutex(mpu_lock);
|
||||
|
||||
if (mpu->state.cond_req) {
|
||||
/* Command */
|
||||
switch (mpu->state.data_onoff) {
|
||||
case -1:
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
case 0: /* Timing byte */
|
||||
mpu->condbuf.length = 0;
|
||||
@@ -833,7 +801,6 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val)
|
||||
mpu->state.cond_req = 0;
|
||||
break;
|
||||
}
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -848,7 +815,6 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val)
|
||||
mpu->state.data_onoff = -1;
|
||||
MPU401_EOIHandlerDispatch(mpu);
|
||||
mpu->state.track_req = 0;
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
}
|
||||
mpu->state.send_now = !val ? 1 : 0;
|
||||
@@ -879,7 +845,6 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val)
|
||||
mpu->state.data_onoff = -1;
|
||||
MPU401_EOIHandler(mpu);
|
||||
mpu->state.track_req = 0;
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
default: /* MIDI with running status */
|
||||
cnt++;
|
||||
@@ -901,7 +866,6 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val)
|
||||
break;
|
||||
}
|
||||
|
||||
thread_release_mutex(mpu_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1070,8 +1034,7 @@ MPU401_ReadData(mpu_t *mpu)
|
||||
uint8_t ret;
|
||||
|
||||
ret = MSG_MPU_ACK;
|
||||
thread_wait_mutex(mpu_lock);
|
||||
|
||||
|
||||
if (mpu->queue_used) {
|
||||
if (mpu->queue_pos >= MPU401_QUEUE)
|
||||
mpu->queue_pos -= MPU401_QUEUE;
|
||||
@@ -1085,7 +1048,6 @@ MPU401_ReadData(mpu_t *mpu)
|
||||
if (mpu->state.irq_pending) {
|
||||
picintc(1 << mpu->irq);
|
||||
mpu->state.irq_pending = 0;
|
||||
thread_release_mutex(mpu_lock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -1094,7 +1056,6 @@ MPU401_ReadData(mpu_t *mpu)
|
||||
if (mpu->state.rec_copy && !mpu->rec_queue_used) {
|
||||
mpu->state.rec_copy = 0;
|
||||
MPU401_EOIHandler(mpu);
|
||||
thread_release_mutex(mpu_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1137,8 +1098,6 @@ MPU401_ReadData(mpu_t *mpu)
|
||||
MPU401_EOIHandlerDispatch(mpu);
|
||||
}
|
||||
|
||||
thread_release_mutex(mpu_lock);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@@ -1251,9 +1210,7 @@ MPU401_Event(void *priv)
|
||||
}
|
||||
}
|
||||
if (!mpu->state.irq_pending && mpu->state.req_mask) {
|
||||
thread_wait_mutex(mpu_lock);
|
||||
MPU401_EOIHandler(mpu);
|
||||
thread_release_mutex(mpu_lock);
|
||||
}
|
||||
|
||||
next_event:
|
||||
@@ -1291,42 +1248,44 @@ MPU401_NotesOff(mpu_t *mpu, int i)
|
||||
|
||||
/*Input handler for SysEx */
|
||||
static int
|
||||
MPU401_InputSysex(uint8_t *buffer, uint32_t len, int abort)
|
||||
MPU401_InputSysex(void *p, uint8_t *buffer, uint32_t len, int abort)
|
||||
{
|
||||
pclog("MPU401 Input Sysex\n");
|
||||
mpu_t *mpu = (mpu_t *)p;
|
||||
|
||||
mpu401_log("MPU401 Input Sysex\n");
|
||||
|
||||
int i;
|
||||
|
||||
if (mpuin->filter.sysex_in) {
|
||||
if (mpu->filter.sysex_in) {
|
||||
if (abort) {
|
||||
mpuin->state.sysex_in_finished=1;
|
||||
mpuin->rec_queue_used=0;/*reset also the input queue*/
|
||||
mpu->state.sysex_in_finished=1;
|
||||
mpu->rec_queue_used=0;/*reset also the input queue*/
|
||||
return 0;
|
||||
}
|
||||
if (mpuin->state.sysex_in_finished) {
|
||||
if (mpuin->rec_queue_used>=MPU401_INPUT_QUEUE)
|
||||
if (mpu->state.sysex_in_finished) {
|
||||
if (mpu->rec_queue_used>=MPU401_INPUT_QUEUE)
|
||||
return len;
|
||||
uint8_t val_ff=0xff;
|
||||
MPU401_RecQueueBuffer(mpuin,&val_ff,1,1);
|
||||
mpuin->state.sysex_in_finished=0;
|
||||
mpuin->clock.rec_counter=0;
|
||||
MPU401_RecQueueBuffer(mpu,&val_ff,1,1);
|
||||
mpu->state.sysex_in_finished=0;
|
||||
mpu->clock.rec_counter=0;
|
||||
}
|
||||
if (mpuin->rec_queue_used>=MPU401_INPUT_QUEUE)
|
||||
if (mpu->rec_queue_used>=MPU401_INPUT_QUEUE)
|
||||
return len;
|
||||
int available=MPU401_INPUT_QUEUE-mpuin->rec_queue_used;
|
||||
int available=MPU401_INPUT_QUEUE-mpu->rec_queue_used;
|
||||
|
||||
if (available>=len) {
|
||||
MPU401_RecQueueBuffer(mpuin,buffer,len,1);
|
||||
MPU401_RecQueueBuffer(mpu,buffer,len,1);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
MPU401_RecQueueBuffer(mpuin,buffer,available,1);
|
||||
if (mpuin->state.sysex_in_finished)
|
||||
MPU401_RecQueueBuffer(mpu,buffer,available,1);
|
||||
if (mpu->state.sysex_in_finished)
|
||||
return 0;
|
||||
return (len-available);
|
||||
}
|
||||
}
|
||||
else if (mpuin->filter.sysex_thru && mpuin->midi_thru) {
|
||||
else if (mpu->filter.sysex_thru && mpu->midi_thru) {
|
||||
midi_raw_out_byte(0xf0);
|
||||
for (i=0;i<len;i++)
|
||||
midi_raw_out_byte(*(buffer+i));
|
||||
@@ -1337,15 +1296,17 @@ MPU401_InputSysex(uint8_t *buffer, uint32_t len, int abort)
|
||||
|
||||
/*Input handler for MIDI*/
|
||||
static void
|
||||
MPU401_InputMsg(uint8_t *msg)
|
||||
MPU401_InputMsg(void *p, uint8_t *msg)
|
||||
{
|
||||
pclog("MPU401 Input Msg\n");
|
||||
mpu_t *mpu = (mpu_t *)p;
|
||||
|
||||
/*abort if sysex transfer is in progress*/
|
||||
if (!mpuin->state.sysex_in_finished) {
|
||||
pclog("SYSEX in progress\n");
|
||||
if (!mpu->state.sysex_in_finished) {
|
||||
mpu401_log("SYSEX in progress\n");
|
||||
return;
|
||||
}
|
||||
|
||||
mpu401_log("MPU401 Input Msg\n");
|
||||
|
||||
int i;
|
||||
static uint8_t old_msg=0;
|
||||
@@ -1354,41 +1315,41 @@ MPU401_InputMsg(uint8_t *msg)
|
||||
int send_thru=0;
|
||||
int retrigger_thru=0;
|
||||
int midistatus=0;
|
||||
if (mpuin->mode==M_INTELLIGENT) {
|
||||
if (mpu->mode==M_INTELLIGENT) {
|
||||
if (msg[0]<0x80) { /* Expand running status */
|
||||
midistatus=1;
|
||||
msg[2]=msg[1];msg[1]=msg[0];msg[0]=old_msg;
|
||||
}
|
||||
old_msg=msg[0];
|
||||
int chan=msg[0]&0xf;
|
||||
int chrefnum=mpuin->ch_toref[chan];
|
||||
int chrefnum=mpu->ch_toref[chan];
|
||||
uint8_t key=msg[1]&0x7f;
|
||||
if (msg[0]<0xf0) { //if non-system msg
|
||||
if (!(mpuin->state.midi_mask&(1<<chan)) && mpuin->filter.all_thru)
|
||||
if (!(mpu->state.midi_mask&(1<<chan)) && mpu->filter.all_thru)
|
||||
send_thru=1;
|
||||
else if (mpuin->filter.midi_thru)
|
||||
else if (mpu->filter.midi_thru)
|
||||
send_thru=1;
|
||||
switch (msg[0]&0xf0) {
|
||||
case 0x80: /*note off*/
|
||||
if (send_thru) {
|
||||
if (mpuin->chanref[chrefnum].on && (mpuin->chanref[chrefnum].M_GETKEY))
|
||||
if (mpu->chanref[chrefnum].on && (mpu->chanref[chrefnum].M_GETKEY))
|
||||
send_thru=0;
|
||||
if (!mpuin->filter.midi_thru)
|
||||
if (!mpu->filter.midi_thru)
|
||||
break;
|
||||
if (!(mpuin->inputref[chan].M_GETKEY))
|
||||
if (!(mpu->inputref[chan].M_GETKEY))
|
||||
send_thru=0;
|
||||
mpuin->inputref[chan].M_DELKEY;
|
||||
mpu->inputref[chan].M_DELKEY;
|
||||
}
|
||||
break;
|
||||
case 0x90: /*note on*/
|
||||
if (send_thru) {
|
||||
if (mpuin->chanref[chrefnum].on && (mpuin->chanref[chrefnum].M_GETKEY))
|
||||
if (mpu->chanref[chrefnum].on && (mpu->chanref[chrefnum].M_GETKEY))
|
||||
retrigger_thru=1;
|
||||
if (!mpuin->filter.midi_thru)
|
||||
if (!mpu->filter.midi_thru)
|
||||
break;
|
||||
if (mpuin->inputref[chan].M_GETKEY)
|
||||
if (mpu->inputref[chan].M_GETKEY)
|
||||
retrigger_thru=1;
|
||||
mpuin->inputref[chan].M_SETKEY;
|
||||
mpu->inputref[chan].M_SETKEY;
|
||||
}
|
||||
break;
|
||||
case 0xb0:
|
||||
@@ -1396,112 +1357,112 @@ MPU401_InputMsg(uint8_t *msg)
|
||||
send_thru=0;
|
||||
if (msg[1]==123) { /* All notes off */
|
||||
for (key=0;key<128;key++) {
|
||||
if (!(mpuin->chanref[chrefnum].on && (mpuin->chanref[chrefnum].M_GETKEY)))
|
||||
if (mpuin->inputref[chan].on && mpuin->inputref[chan].M_GETKEY) {
|
||||
if (!(mpu->chanref[chrefnum].on && (mpu->chanref[chrefnum].M_GETKEY)))
|
||||
if (mpu->inputref[chan].on && mpu->inputref[chan].M_GETKEY) {
|
||||
midi_raw_out_byte(0x80|chan);
|
||||
midi_raw_out_byte(key);
|
||||
midi_raw_out_byte(0);
|
||||
}
|
||||
mpuin->inputref[chan].M_DELKEY;
|
||||
mpu->inputref[chan].M_DELKEY;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (msg[0]>=0xf0 || (mpuin->state.midi_mask&(1<<chan)))
|
||||
if (msg[0]>=0xf0 || (mpu->state.midi_mask&(1<<chan)))
|
||||
switch (msg[0]&0xf0) {
|
||||
case 0xa0: /*aftertouch*/
|
||||
if (!mpuin->filter.bender_in)
|
||||
if (!mpu->filter.bender_in)
|
||||
send=0;
|
||||
break;
|
||||
case 0xb0: /*control change*/
|
||||
if (!mpuin->filter.bender_in && msg[1]<64)
|
||||
if (!mpu->filter.bender_in && msg[1]<64)
|
||||
send=0;
|
||||
if (msg[1]>=120) {
|
||||
if (mpuin->filter.modemsgs_in)
|
||||
if (mpu->filter.modemsgs_in)
|
||||
send=1;
|
||||
}
|
||||
break;
|
||||
case 0xc0: /*program change*/
|
||||
if ((mpuin->state.rec!=M_RECON) && !mpuin->filter.data_in_stop) {
|
||||
mpuin->filter.prchg_buf[chan]=msg[1];
|
||||
mpuin->filter.prchg_mask|=1<<chan;
|
||||
if ((mpu->state.rec!=M_RECON) && !mpu->filter.data_in_stop) {
|
||||
mpu->filter.prchg_buf[chan]=msg[1];
|
||||
mpu->filter.prchg_mask|=1<<chan;
|
||||
}
|
||||
break;
|
||||
case 0xd0: /*ch pressure*/
|
||||
case 0xe0: /*pitch wheel*/
|
||||
if (!mpuin->filter.bender_in)
|
||||
if (!mpu->filter.bender_in)
|
||||
send=0;
|
||||
break;
|
||||
case 0xf0: //system message
|
||||
if (msg[0]==0xf8) {
|
||||
send=0;
|
||||
if (mpuin->clock.active && mpuin->state.sync_in) {
|
||||
if (mpu->clock.active && mpu->state.sync_in) {
|
||||
send = 0;/*don't pass to host in this mode?*/
|
||||
int tick=mpuin->clock.timebase/24;
|
||||
if (mpuin->clock.ticks_in!=tick) {
|
||||
if (!mpuin->clock.ticks_in || (mpuin->clock.ticks_in>tick*2))
|
||||
mpuin->clock.freq_mod*=2.0;
|
||||
int tick=mpu->clock.timebase/24;
|
||||
if (mpu->clock.ticks_in!=tick) {
|
||||
if (!mpu->clock.ticks_in || (mpu->clock.ticks_in>tick*2))
|
||||
mpu->clock.freq_mod*=2.0;
|
||||
else {
|
||||
if (ABS(mpuin->clock.ticks_in-tick)==1)
|
||||
mpuin->clock.freq_mod/=mpuin->clock.ticks_in/(float)(tick*2);
|
||||
if (ABS(mpu->clock.ticks_in-tick)==1)
|
||||
mpu->clock.freq_mod/=mpu->clock.ticks_in/(float)(tick*2);
|
||||
else
|
||||
mpuin->clock.freq_mod/=mpuin->clock.ticks_in/(float)(tick);
|
||||
mpu->clock.freq_mod/=mpu->clock.ticks_in/(float)(tick);
|
||||
}
|
||||
MPU401_ReCalcClock(mpuin);
|
||||
MPU401_ReCalcClock(mpu);
|
||||
}
|
||||
mpuin->clock.ticks_in=0;
|
||||
mpu->clock.ticks_in=0;
|
||||
}
|
||||
}
|
||||
else if (msg[0]>0xf8) { /*realtime*/
|
||||
if (!(mpuin->filter.rt_in && msg[0]<=0xfc && msg[0]>=0xfa)) {
|
||||
if (!(mpu->filter.rt_in && msg[0]<=0xfc && msg[0]>=0xfa)) {
|
||||
uint8_t recdata[2]={0xff,msg[0]};
|
||||
MPU401_RecQueueBuffer(mpuin,recdata,2,1);
|
||||
MPU401_RecQueueBuffer(mpu,recdata,2,1);
|
||||
send=0;
|
||||
}
|
||||
}
|
||||
else { /*common or system*/
|
||||
send=0;
|
||||
if (msg[0]==0xf2 || msg[0]==0xf3 || msg[0]==0xf6) {
|
||||
if (mpuin->filter.commonmsgs_in)
|
||||
if (mpu->filter.commonmsgs_in)
|
||||
send=1;
|
||||
if (mpuin->filter.commonmsgs_thru)
|
||||
if (mpu->filter.commonmsgs_thru)
|
||||
for (i=0;i<len;i++)
|
||||
midi_raw_out_byte(msg[i]);
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
uint8_t recmsg[4]={0xff,msg[0],msg[1],msg[2]};
|
||||
MPU401_RecQueueBuffer(mpuin,recmsg,len+1,1);
|
||||
MPU401_RecQueueBuffer(mpu,recmsg,len+1,1);
|
||||
}
|
||||
if (mpuin->filter.rt_affection) switch(msg[0]) {
|
||||
if (mpu->filter.rt_affection) switch(msg[0]) {
|
||||
case 0xf2:case 0xf3:
|
||||
mpuin->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpuin,0xb8);/*clear play counters*/
|
||||
mpu->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpu,0xb8);/*clear play counters*/
|
||||
break;
|
||||
case 0xfa:
|
||||
mpuin->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpuin,0xa);/*start,play*/
|
||||
if (mpuin->filter.rt_out)
|
||||
mpu->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpu,0xa);/*start,play*/
|
||||
if (mpu->filter.rt_out)
|
||||
midi_raw_out_rt_byte(msg[0]);
|
||||
break;
|
||||
case 0xfb:
|
||||
mpuin->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpuin,0xb);/*continue,play*/
|
||||
if (mpuin->filter.rt_out)
|
||||
mpu->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpu,0xb);/*continue,play*/
|
||||
if (mpu->filter.rt_out)
|
||||
midi_raw_out_rt_byte(msg[0]);
|
||||
break;
|
||||
case 0xfc:
|
||||
mpuin->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpuin,0xd);/*stop: play,rec,midi*/
|
||||
if (mpuin->filter.rt_out)
|
||||
mpu->state.block_ack=1;
|
||||
MPU401_WriteCommand(mpu,0xd);/*stop: play,rec,midi*/
|
||||
if (mpu->filter.rt_out)
|
||||
midi_raw_out_rt_byte(msg[0]);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (send_thru && mpuin->midi_thru) {
|
||||
if (send_thru && mpu->midi_thru) {
|
||||
if (retrigger_thru) {
|
||||
midi_raw_out_byte(0x80|(msg[0]&0xf));
|
||||
midi_raw_out_byte(msg[1]);
|
||||
@@ -1511,29 +1472,29 @@ MPU401_InputMsg(uint8_t *msg)
|
||||
midi_raw_out_byte(msg[i]);
|
||||
}
|
||||
if (send) {
|
||||
if (mpuin->state.rec==M_RECON) {
|
||||
uint8_t recmsg[4]={mpuin->clock.rec_counter,msg[0],msg[1],msg[2]};
|
||||
MPU401_RecQueueBuffer(mpuin,recmsg,len+1,1);
|
||||
mpuin->clock.rec_counter=0;
|
||||
if (mpu->state.rec==M_RECON) {
|
||||
uint8_t recmsg[4]={mpu->clock.rec_counter,msg[0],msg[1],msg[2]};
|
||||
MPU401_RecQueueBuffer(mpu,recmsg,len+1,1);
|
||||
mpu->clock.rec_counter=0;
|
||||
}
|
||||
else if (mpuin->filter.data_in_stop) {
|
||||
if (mpuin->filter.timing_in_stop) {
|
||||
else if (mpu->filter.data_in_stop) {
|
||||
if (mpu->filter.timing_in_stop) {
|
||||
uint8_t recmsg[4]={0,msg[0],msg[1],msg[2]};
|
||||
MPU401_RecQueueBuffer(mpuin,recmsg,len+1,1);
|
||||
MPU401_RecQueueBuffer(mpu,recmsg,len+1,1);
|
||||
}
|
||||
else {
|
||||
uint8_t recmsg[4]={msg[0],msg[1],msg[2],0};
|
||||
MPU401_RecQueueBuffer(mpuin,recmsg,len,1);
|
||||
MPU401_RecQueueBuffer(mpu,recmsg,len,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*UART mode input*/
|
||||
thread_wait_mutex(mpu_lock);
|
||||
for (i=0;i<len;i++)
|
||||
MPU401_QueueByte(mpuin, msg[i]);
|
||||
thread_release_mutex(mpu_lock);
|
||||
for (i=0;i<len;i++) {
|
||||
MPU401_QueueByte(mpu, msg[i]);
|
||||
picint(1 << mpu->irq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1644,10 +1605,9 @@ mpu401_standalone_init(const device_t *info)
|
||||
irq = device_get_config_int("irq");
|
||||
}
|
||||
|
||||
mpu401_set_midi_in(mpu);
|
||||
mpu_lock = thread_create_mutex(L"86Box.MPU401Mutex");
|
||||
input_msg = MPU401_InputMsg;
|
||||
input_sysex = MPU401_InputSysex;
|
||||
midi_in_p = mpu;
|
||||
|
||||
mpu401_init(mpu, base, irq, M_INTELLIGENT);
|
||||
|
||||
@@ -1660,8 +1620,6 @@ mpu401_standalone_close(void *priv)
|
||||
{
|
||||
mpu_t *mpu = (mpu_t *)priv;
|
||||
|
||||
thread_close_mutex(mpu_lock);
|
||||
|
||||
free(mpu);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,12 +189,6 @@ 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)
|
||||
{
|
||||
@@ -1049,9 +1043,9 @@ void *sb_1_init()
|
||||
}
|
||||
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;
|
||||
input_sysex = sb_dsp_input_sysex;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1080,9 +1074,9 @@ void *sb_15_init()
|
||||
}
|
||||
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;
|
||||
input_sysex = sb_dsp_input_sysex;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1108,9 +1102,9 @@ void *sb_mcv_init()
|
||||
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;
|
||||
input_sysex = sb_dsp_input_sysex;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1159,9 +1153,9 @@ 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;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1196,9 +1190,9 @@ 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;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1232,9 +1226,9 @@ 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;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1261,9 +1255,9 @@ 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;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1300,9 +1294,9 @@ void *sb_16_init()
|
||||
sb->mpu = NULL;
|
||||
|
||||
|
||||
sb_dsp_set_midi_in(&sb->dsp);
|
||||
input_msg = sb_dsp_input_msg;
|
||||
input_sysex = sb_dsp_input_sysex;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
@@ -1348,9 +1342,9 @@ 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;
|
||||
midi_in_p = &sb->dsp;
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -458,19 +458,19 @@ sb_exec_command(sb_dsp_t *dsp)
|
||||
sb_start_dma_i(dsp, 1, 1, 0, dsp->sb_data[0] + (dsp->sb_data[1] << 8));
|
||||
break;
|
||||
case 0x30: /* MIDI Polling mode input */
|
||||
pclog("MIDI polling mode input\n");
|
||||
sb_dsp_log("MIDI polling mode input\n");
|
||||
dsp->midi_in_poll = 1;
|
||||
dsp->uart_irq = 0;
|
||||
break;
|
||||
case 0x31: /* MIDI Interrupt mode input */
|
||||
pclog("MIDI interrupt mode input\n");
|
||||
sb_dsp_log("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");
|
||||
sb_dsp_log("MIDI poll in\n");
|
||||
dsp->midi_in_poll = 1;
|
||||
dsp->uart_midi = 1;
|
||||
dsp->uart_irq = 0;
|
||||
@@ -478,7 +478,7 @@ sb_exec_command(sb_dsp_t *dsp)
|
||||
case 0x35: /* MIDI In irq */
|
||||
if (dsp->sb_type < SB2)
|
||||
break;
|
||||
pclog("MIDI irq in\n");
|
||||
sb_dsp_log("MIDI irq in\n");
|
||||
dsp->midi_in_poll = 0;
|
||||
dsp->uart_midi = 1;
|
||||
dsp->uart_irq = 1;
|
||||
@@ -836,44 +836,50 @@ sb_dsp_set_mpu(mpu_t *src_mpu)
|
||||
}
|
||||
|
||||
void
|
||||
sb_dsp_input_msg(uint8_t *msg)
|
||||
sb_dsp_input_msg(void *p, 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);
|
||||
sb_dsp_t *dsp = (sb_dsp_t *) p;
|
||||
|
||||
if (dspin->midi_in_sysex) {
|
||||
sb_dsp_log("MIDI in sysex = %d, uart irq = %d, msg = %d\n", dsp->midi_in_sysex, dsp->uart_irq, msg[3]);
|
||||
|
||||
if (dsp->midi_in_sysex) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t len = msg[3];
|
||||
uint8_t i = 0;
|
||||
if (dspin->uart_irq) {
|
||||
if (dsp->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) {
|
||||
sb_add_data(dsp, msg[i]);
|
||||
sb_dsp_log("SB IRQ8 = %d\n", dsp->sb_irq8);
|
||||
if (!dsp->sb_irq8)
|
||||
picint(1 << dsp->sb_irqnum);
|
||||
} else if (dsp->midi_in_poll) {
|
||||
for (i=0;i<len;i++)
|
||||
sb_add_data(dspin, msg[i]);
|
||||
sb_add_data(dsp, msg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
sb_dsp_input_sysex(uint8_t *buffer, uint32_t len, int abort)
|
||||
sb_dsp_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort)
|
||||
{
|
||||
sb_dsp_t *dsp = (sb_dsp_t *) p;
|
||||
|
||||
uint32_t i;
|
||||
|
||||
if (abort) {
|
||||
dspin->midi_in_sysex = 0;
|
||||
dsp->midi_in_sysex = 0;
|
||||
return 0;
|
||||
}
|
||||
dspin->midi_in_sysex = 1;
|
||||
dsp->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);
|
||||
if (dsp->sb_read_rp == dsp->sb_read_wp) {
|
||||
sb_dsp_log("Length sysex SB = %d\n", len-i);
|
||||
return (len-i);
|
||||
}
|
||||
sb_add_data(dspin, buffer[i]);
|
||||
sb_add_data(dsp, buffer[i]);
|
||||
}
|
||||
dspin->midi_in_sysex = 0;
|
||||
dsp->midi_in_sysex = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -943,7 +949,7 @@ pollsb(void *p)
|
||||
break;
|
||||
dsp->sbdat = (data[0] ^ 0x80) << 8;
|
||||
if ((dsp->sb_type >= SBPRO) && (dsp->sb_type < SB16) && dsp->stereo) {
|
||||
pclog("pollsb: Mono unsigned, dsp->stereo, %s channel, %04X\n",
|
||||
sb_dsp_log("pollsb: Mono unsigned, dsp->stereo, %s channel, %04X\n",
|
||||
dsp->sbleftright ? "left" : "right", dsp->sbdat);
|
||||
if (dsp->sbleftright)
|
||||
dsp->sbdatl = dsp->sbdat;
|
||||
@@ -960,7 +966,7 @@ pollsb(void *p)
|
||||
break;
|
||||
dsp->sbdat = data[0] << 8;
|
||||
if ((dsp->sb_type >= SBPRO) && (dsp->sb_type < SB16) && dsp->stereo) {
|
||||
pclog("pollsb: Mono signed, dsp->stereo, %s channel, %04X\n",
|
||||
sb_dsp_log("pollsb: Mono signed, dsp->stereo, %s channel, %04X\n",
|
||||
dsp->sbleftright ? "left" : "right", data[0], dsp->sbdat);
|
||||
if (dsp->sbleftright)
|
||||
dsp->sbdatl = dsp->sbdat;
|
||||
@@ -1020,7 +1026,7 @@ pollsb(void *p)
|
||||
}
|
||||
|
||||
if ((dsp->sb_type >= SBPRO) && (dsp->sb_type < SB16) && dsp->stereo) {
|
||||
pclog("pollsb: ADPCM 4, dsp->stereo, %s channel, %04X\n",
|
||||
sb_dsp_log("pollsb: ADPCM 4, dsp->stereo, %s channel, %04X\n",
|
||||
dsp->sbleftright ? "left" : "right", dsp->sbdat);
|
||||
if (dsp->sbleftright)
|
||||
dsp->sbdatl = dsp->sbdat;
|
||||
@@ -1063,7 +1069,7 @@ pollsb(void *p)
|
||||
}
|
||||
|
||||
if ((dsp->sb_type >= SBPRO) && (dsp->sb_type < SB16) && dsp->stereo) {
|
||||
pclog("pollsb: ADPCM 26, dsp->stereo, %s channel, %04X\n",
|
||||
sb_dsp_log("pollsb: ADPCM 26, dsp->stereo, %s channel, %04X\n",
|
||||
dsp->sbleftright ? "left" : "right", dsp->sbdat);
|
||||
if (dsp->sbleftright)
|
||||
dsp->sbdatl = dsp->sbdat;
|
||||
@@ -1099,7 +1105,7 @@ pollsb(void *p)
|
||||
}
|
||||
|
||||
if ((dsp->sb_type >= SBPRO) && (dsp->sb_type < SB16) && dsp->stereo) {
|
||||
pclog("pollsb: ADPCM 2, dsp->stereo, %s channel, %04X\n",
|
||||
sb_dsp_log("pollsb: ADPCM 2, dsp->stereo, %s channel, %04X\n",
|
||||
dsp->sbleftright ? "left" : "right", dsp->sbdat);
|
||||
if (dsp->sbleftright)
|
||||
dsp->sbdatl = dsp->sbdat;
|
||||
|
||||
@@ -76,11 +76,10 @@ typedef struct sb_dsp_t
|
||||
int pos;
|
||||
} sb_dsp_t;
|
||||
|
||||
extern sb_dsp_t *dspin;
|
||||
|
||||
void sb_dsp_input_msg(uint8_t *msg);
|
||||
void sb_dsp_input_msg(void *p, uint8_t *msg);
|
||||
|
||||
int sb_dsp_input_sysex(uint8_t *buffer, uint32_t len, int abort);
|
||||
int sb_dsp_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort);
|
||||
|
||||
void sb_dsp_set_mpu(mpu_t *src_mpu);
|
||||
|
||||
|
||||
@@ -16,15 +16,14 @@ typedef struct
|
||||
int midi_id, midi_input_id;
|
||||
|
||||
HANDLE m_event;
|
||||
HANDLE m_callback;
|
||||
|
||||
HMIDIOUT midi_out_device;
|
||||
HMIDIIN midi_in_device;
|
||||
|
||||
MIDIHDR m_hdr, m_hdr_in;
|
||||
MIDIHDR m_hdr;
|
||||
} plat_midi_t;
|
||||
|
||||
plat_midi_t *pm = NULL;
|
||||
plat_midi_t *pm = NULL, *pm_in = NULL;
|
||||
|
||||
|
||||
void
|
||||
@@ -41,7 +40,6 @@ 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) {
|
||||
@@ -140,30 +138,29 @@ plat_midi_write(uint8_t val)
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
int len;
|
||||
uint32_t len;
|
||||
int cnt;
|
||||
MIDIHDR *t_hdr;
|
||||
MIDIHDR *hdr;
|
||||
switch (wMsg) {
|
||||
case MM_MIM_DATA: /* 0x3C3 - midi message */
|
||||
input_msg(msg);
|
||||
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 */
|
||||
pclog("MIDI sysex\n");
|
||||
t_hdr = (MIDIHDR *)dwParam1;
|
||||
sysex = (uint8_t *)t_hdr->lpData;
|
||||
len = (unsigned int)t_hdr->dwBytesRecorded;
|
||||
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(sysex, len, 0);
|
||||
int ret = input_sysex(midi_in_p, sysex, len, 0);
|
||||
if (!ret) {
|
||||
len = 0;
|
||||
break;
|
||||
@@ -177,11 +174,11 @@ plat_midi_in_callback(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PT
|
||||
Sleep(5);/*msec*/
|
||||
}
|
||||
if (len)
|
||||
input_sysex(sysex, 0, 0);
|
||||
input_sysex(midi_in_p, sysex, 0, 0);
|
||||
|
||||
midiInUnprepareHeader(hMidiIn, t_hdr, sizeof(*t_hdr));
|
||||
t_hdr->dwBytesRecorded = 0;
|
||||
midiInPrepareHeader(hMidiIn, t_hdr, sizeof(*t_hdr));
|
||||
midiInUnprepareHeader(hMidiIn, hdr, sizeof(*hdr));
|
||||
hdr->dwBytesRecorded = 0;
|
||||
midiInPrepareHeader(hMidiIn, hdr, sizeof(*hdr));
|
||||
break;
|
||||
case MM_MIM_ERROR:
|
||||
case MM_MIM_LONGERROR:
|
||||
@@ -196,46 +193,45 @@ plat_midi_input_init(void)
|
||||
{
|
||||
MMRESULT hr;
|
||||
|
||||
pm = (plat_midi_t *) malloc(sizeof(plat_midi_t));
|
||||
memset(pm, 0, sizeof(plat_midi_t));
|
||||
pm_in = (plat_midi_t *) malloc(sizeof(plat_midi_t));
|
||||
memset(pm_in, 0, sizeof(plat_midi_t));
|
||||
|
||||
pclog("Plat MIDI Input init\n");
|
||||
|
||||
pm->midi_input_id = config_get_int(MIDI_INPUT_NAME, "midi_input", 0);
|
||||
pm_in->midi_input_id = config_get_int(MIDI_INPUT_NAME, "midi_input", 0);
|
||||
|
||||
hr = midiInOpen(&pm->midi_in_device, pm->midi_input_id,
|
||||
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) {
|
||||
pclog("midiInOpen error - %08X\n", hr);
|
||||
pm->midi_input_id = 0;
|
||||
hr = midiInOpen(&pm->midi_in_device, pm->midi_input_id,
|
||||
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) {
|
||||
pclog("midiInOpen error - %08X\n", hr);
|
||||
printf("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);
|
||||
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) {
|
||||
if (pm->midi_in_device != NULL) {
|
||||
midiInStop(pm->midi_in_device);
|
||||
midiInClose(pm->midi_in_device);
|
||||
if (pm_in) {
|
||||
if (pm_in->midi_in_device != NULL) {
|
||||
midiInStop(pm_in->midi_in_device);
|
||||
midiInClose(pm_in->midi_in_device);
|
||||
}
|
||||
|
||||
free(pm);
|
||||
pm = NULL;
|
||||
free(pm_in);
|
||||
pm_in = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user