Fixed MIDI output to file and some minor changes

This commit is contained in:
Volker Ruppert 2013-11-14 18:11:23 +00:00
parent d75a04b48d
commit c64dceadb4

View File

@ -3075,13 +3075,15 @@ void bx_sb16_c::writemidicommand(int command, int length, Bit8u data[])
return; return;
} else if ((BX_SB16_THIS midimode == 2) || } else if ((BX_SB16_THIS midimode == 2) ||
(BX_SB16_THIS midimode == 3)) { (BX_SB16_THIS midimode == 3)) {
MIDIDATA = fopen(SIM->get_param_string("midi", base)->getptr(),"wb");
if (MIDIDATA == NULL) { if (MIDIDATA == NULL) {
writelog (MIDILOG(2), "Error opening file %s. Midimode disabled.", MIDIDATA = fopen(SIM->get_param_string("midi", base)->getptr(),"wb");
SIM->get_param_string("midi", base)->getptr()); if (MIDIDATA == NULL) {
BX_SB16_THIS midimode = 0; writelog (MIDILOG(2), "Error opening file %s. Midimode disabled.",
} else if (BX_SB16_THIS midimode == 2) { SIM->get_param_string("midi", base)->getptr());
initmidifile(); BX_SB16_THIS midimode = 0;
} else if (BX_SB16_THIS midimode == 2) {
initmidifile();
}
} }
} }
@ -3272,8 +3274,8 @@ void bx_sb16_c::finishmidifile()
Bit8u delta, statusbyte, metaevent, length; Bit8u delta, statusbyte, metaevent, length;
} metatrackend = { 0, 0xff, 0x2f, 0 }; } metatrackend = { 0, 0xff, 0x2f, 0 };
// Meta event track end (0xff 0x2f 0x00) plus leading delta time // Meta event track end (0xff 0x2f 0x00) plus leading delta time
fwrite(&metatrackend, 1, sizeof metatrackend, MIDIDATA); fwrite(&metatrackend, 1, sizeof(metatrackend), MIDIDATA);
Bit32u tracklen = ftell(MIDIDATA); Bit32u tracklen = ftell(MIDIDATA);
if (tracklen < 0) if (tracklen < 0)
@ -3284,9 +3286,7 @@ void bx_sb16_c::finishmidifile()
fseek(MIDIDATA, 22 - 4, SEEK_SET); fseek(MIDIDATA, 22 - 4, SEEK_SET);
// value has to be in big endian // value has to be in big endian
#ifdef BX_LITTLE_ENDIAN #ifdef BX_LITTLE_ENDIAN
tracklen = (tracklen << 24) | (tracklen >> 24) | tracklen = bx_bswap32(tracklen);
((tracklen & 0x00ff0000) >> 8) |
((tracklen & 0x0000ff00) << 8);
#endif #endif
fwrite(&tracklen, 4, 1, MIDIDATA); fwrite(&tracklen, 4, 1, MIDIDATA);
} }