--- np2/sound/vermouth/midiout.c 2003/10/16 17:58:10 1.1.1.1 +++ np2/sound/vermouth/midiout.c 2003/12/25 05:07:49 1.7 @@ -2,8 +2,8 @@ #include "midiout.h" -#define MIDIOUT_VERSION 0x101 -#define MIDIOUT_VERSTRING "VERMOUTH 1.01" +#define MIDIOUT_VERSION 0x104 +#define MIDIOUT_VERSTRING "VERMOUTH 1.04" static const char vermouthver[] = MIDIOUT_VERSTRING; @@ -406,6 +406,11 @@ static void allnotesoff(MIDIHDL midi, CH v = midi->voice; vterm = v + VOICE_MAX; do { +#if 1 + if ((v->phase & (VOICE_ON | VOICE_SUSTAIN)) && (v->channel == ch)) { + voice_off(v); + } +#else if ((v->phase & VOICE_ON) && (v->channel == ch)) { if (ch->flag & CHANNEL_SUSTAIN) { voice_setphase(v, VOICE_SUSTAIN); @@ -414,6 +419,7 @@ static void allnotesoff(MIDIHDL midi, CH voice_off(v); } } +#endif v++; } while(v < vterm); } @@ -447,6 +453,7 @@ static void ctrlchange(MIDIHDL midi, CHA case CTRL_EXPRESS: ch->expression = val; + TRACEOUT(("exp = %d", val)); volumeupdate(midi, ch); break; @@ -610,6 +617,7 @@ static void allresetmidi(MIDIHDL midi) { CHANNEL chterm; UINT flag; + midi->master = 127; ch = midi->channel; chterm = ch + 16; ZeroMemory(ch, sizeof(_CHANNEL) * 16); @@ -647,7 +655,7 @@ MIDIHDL midiout_create(MIDIMOD module, U worksize = min(worksize, 512); worksize = max(worksize, 16384); size = sizeof(_MIDIHDL); - size += sizeof(SINT32) * worksize; + size += sizeof(SINT32) * 2 * worksize; size += sizeof(_SAMPLE) * worksize; ret = (MIDIHDL)_MALLOC(size, "MIDIHDL"); if (ret) { @@ -655,11 +663,11 @@ MIDIHDL midiout_create(MIDIMOD module, U ret->samprate = module->samprate; ret->worksize = worksize; ret->module = module; - ret->master = 127; + // ret->master = 127; ret->bank0[0] = module->tone[0]; ret->bank0[1] = module->tone[1]; ret->sampbuf = (SINT32 *)(ret + 1); - ret->resampbuf = (SAMPLE)(ret->sampbuf + worksize); + ret->resampbuf = (SAMPLE)(ret->sampbuf + worksize * 2); allresetmidi(ret); } return(ret); @@ -725,14 +733,68 @@ void midiout_shortmsg(MIDIHDL hdl, UINT3 } } +static void longmsg_gm(MIDIHDL hdl, const BYTE *msg, UINT size) { + + if ((size > 5) && (msg[2] == 0x7f) && (msg[3] == 0x09)) { + allresetmidi(hdl); // GM reset + } +} + +static void longmsg_roland(MIDIHDL hdl, const BYTE *msg, UINT size) { + + UINT addr; + UINT part; + CHANNEL ch; + + if ((size > 10) && (msg[2] == 0x10) && + (msg[3] == 0x42) && (msg[4] == 0x12)) { // GS data set + addr = (msg[5] << 16) + (msg[6] << 8) + msg[7]; + if ((addr & (~0x400000)) == 0x7f) { // GS reset + allresetmidi(hdl); + TRACEOUT(("GS-Reset")); + } + else if (addr == 0x400004) { // Vol + hdl->master = msg[8] & 0x7f; + allvolupdate(hdl); + } + else if ((addr & (~(0x000f00))) == 0x401015) { // Tone/Rhythm + part = (addr >> 8) & 0x0f; + if (part == 0) { // part10 + part = 9; + } + else if (part < 10) { // part1-9 + part--; + } + ch = hdl->channel + part; + if (msg[8] == 0) { + ch->flag &= ~CHANNEL_RHYTHM; + TRACEOUT(("ch%d - tone", part + 1)); + } + else if ((msg[8] == 1) || (msg[8] == 2)) { + ch->flag |= CHANNEL_RHYTHM; + TRACEOUT(("ch%d - rhythm", part + 1)); + } + } + else { + TRACEOUT(("Roland GS - %.6x", addr)); + } + } +} + void midiout_longmsg(MIDIHDL hdl, const BYTE *msg, UINT size) { + UINT id; + if ((hdl == NULL) || (msg == NULL)) { return; } - if ((size > 5) && (msg[1] == 0x7e)) { // GM - if ((msg[2] == 0x7f) && (msg[3] == 0x09)) { - allresetmidi(hdl); // GM reset + if (size > 3) { // (msg[size - 1] == 0xf7) + id = msg[1]; + if (id == 0x7e) { // GM + longmsg_gm(hdl, msg, size); + } + else if (id == 0x41) { // Roland + longmsg_roland(hdl, msg, size); } } } @@ -882,7 +944,7 @@ void midiout_setgain(MIDIHDL hdl, int ga else if (gain > 8) { gain = 8; } - hdl->gain = (char)gain; + hdl->gain = (SINT8)gain; allvolupdate(hdl); } }