[Scummvm-cvs-logs] SF.net SVN: scummvm:[49117] scummvm/trunk/engines/groovie/music.cpp

jvprat at users.sourceforge.net jvprat at users.sourceforge.net
Thu May 20 17:16:10 CEST 2010


Revision: 49117
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49117&view=rev
Author:   jvprat
Date:     2010-05-20 15:16:09 +0000 (Thu, 20 May 2010)

Log Message:
-----------
Groovie: Add support for MT-32 custom instruments

Modified Paths:
--------------
    scummvm/trunk/engines/groovie/music.cpp

Modified: scummvm/trunk/engines/groovie/music.cpp
===================================================================
--- scummvm/trunk/engines/groovie/music.cpp	2010-05-20 13:46:18 UTC (rev 49116)
+++ scummvm/trunk/engines/groovie/music.cpp	2010-05-20 15:16:09 UTC (rev 49117)
@@ -609,18 +609,66 @@
 	}
 }
 
+
+#include "common/pack-start.h"	// START STRUCT PACKING
+
+struct RolandInstrumentSysex {
+	byte roland_id;
+	byte device_id;
+	byte model_id;
+	byte command;
+	byte address[3];
+	byte instrument[0xF6];
+	byte checksum;
+} PACKED_STRUCT;
+
+#include "common/pack-end.h"	// END STRUCT PACKING
+
+void setRolandInstrument(MidiDriver *drv, byte channel, byte *instrument) {
+	RolandInstrumentSysex sysex;
+	memcpy(&sysex.instrument, instrument, 0xF6);
+
+	// Show the timbre name as extra debug information
+	Common::String name((char *)instrument, 10);
+	debugC(5, kGroovieDebugMIDI | kGroovieDebugAll, "Groovie::Music: Setting MT32 timbre '%s' to channel %d", name.c_str(), channel);
+
+	sysex.roland_id = 0x41;
+	sysex.device_id = channel; // Unit#
+	sysex.model_id = 0x16; // MT32
+	sysex.command = 0x12; // Data set
+
+	// Remap instrument to appropriate address space.
+	int address = 0x008000;
+	sysex.address[0] = (address >> 14) & 0x7F;
+	sysex.address[1] = (address >>  7) & 0x7F;
+	sysex.address[2] = (address      ) & 0x7F;
+
+	// Compute the checksum.
+	byte checksum = 0;
+	byte *ptr = sysex.address;
+	for (int i = 4; i < (int)sizeof(RolandInstrumentSysex) - 1; ++i)
+		checksum -= *ptr++;
+	sysex.checksum = checksum & 0x7F;
+
+	// Send sysex
+	drv->sysEx((byte *)&sysex, sizeof(RolandInstrumentSysex));
+
+
+	// Wait the time it takes to send the SysEx data
+	uint32 delay = (sizeof(RolandInstrumentSysex) + 2) * 1000 / 3125;
+
+	// Plus an additional delay for the MT-32 rev00
+	delay += 40;
+
+	g_system->delayMillis(delay);
+}
+
 void MusicPlayerXMI::setTimbreMT(byte channel, const Timbre &timbre) {
 	// Verify the timbre size
-	if (timbre.size != 0xF6) {
+	if (timbre.size != 0xF6)
 		error("Groovie::Music: Invalid size for an MT-32 timbre: %d", timbre.size);
-	}
 
-	// Show the timbre name as extra debug information
-	Common::String name((char*)timbre.data, 10);
-	debugC(5, kGroovieDebugMIDI | kGroovieDebugAll, "Groovie::Music: Using MT32 timbre: %s", name.c_str());
-
-	// TODO: Support MT-32 custom instruments
-	warning("Groovie::Music: Setting MT32 custom instruments isn't supported yet");
+	setRolandInstrument(_driver, channel, timbre.data);
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list