Common subdirectories: scummvm.orig/CVS and scummvm.new/CVS
diff -u scummvm.orig/Makefile scummvm.new/Makefile
--- scummvm.orig/Makefile	Mon Nov 19 11:23:52 2001
+++ scummvm.new/Makefile	Wed Nov 21 20:34:01 2001
@@ -2,7 +2,7 @@
 
 CC	= gcc
 CFLAGS	= -g -Wno-multichar
-DEFINES	= -DUNIX -DHAVE_READLINE -DUSE_TIMIDITY
+DEFINES	= -DUNIX -DHAVE_READLINE
 LDFLAGS := 
 INCLUDES:= `sdl-config --cflags`
 CPPFLAGS= $(DEFINES) $(INCLUDES)
Common subdirectories: scummvm.orig/debian and scummvm.new/debian
diff -u scummvm.orig/imuse.cpp scummvm.new/imuse.cpp
--- scummvm.orig/imuse.cpp	Mon Nov 19 11:23:52 2001
+++ scummvm.new/imuse.cpp	Thu Nov 22 02:13:51 2001
@@ -26,7 +26,9 @@
 #include "scumm.h"
 #include "sound.h"
 
-#ifdef USE_TIMIDITY
+/* includes needed for unix midi support through timidity or internal sequencer */
+#ifndef WIN32
+
 #include <sys/time.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -40,7 +42,7 @@
 /* Copy-pasted from Timidity */
 #define SEQ_MIDIPUTC		5
 
-#endif /* USE_TIMIDITY */
+#endif
 
 #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
 
@@ -155,6 +157,207 @@
 	return 0;
 }
 
+void SoundEngine::midiSetDriver(int devicetype, int seq_device) {
+	_midi_driver.DeviceType = devicetype;
+	_midi_driver.SeqDevice = seq_device;
+	_midi_driver.midiInit();
+}
+
+void SoundEngine::midiSetDriver(int devicetype) {
+	_midi_driver.DeviceType = devicetype;
+	_midi_driver.midiInit();
+}
+
+int MidiDriver::connect_to_timidity(int port) {
+	struct hostent *serverhost;
+	struct sockaddr_in sadd;
+	int s;
+	
+	serverhost = gethostbyname("localhost");
+	if (serverhost == NULL)
+		error("Could not resolve host");
+	sadd.sin_family = serverhost->h_addrtype;
+	sadd.sin_port = htons(port);
+	memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length);
+	
+	s = socket(AF_INET,SOCK_STREAM,0);
+	if (s < 0)
+		error("Could not open socket");
+	if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0)
+		error("Could not connect to server");
+	
+	return s;
+}
+
+int MidiDriver::open_sequencer_device() {
+	int device;
+	device = (open("/dev/sequencer", O_RDWR, 0));
+	if (device < 0) {
+			warning("Cannot open sequencer device - using /dev/null (no music will be heard) ");
+		device = (open(("/dev/null"), O_RDWR, 0));
+		if (device < 0)
+			error("Cannot open /dev/null to dump midi output");
+	}
+	return device;
+}
+
+void MidiDriver::midiInitTimidity() {
+	int s, s2;
+	int len;
+	int dummy, newport;
+	char buf[256];
+	
+	SeqDevice = 0;
+
+	s = connect_to_timidity(7777);
+	len = read(s, buf, 256);
+	buf[len] = '\0';
+	printf("%s", buf);
+
+	sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15);
+	write(s, buf, strlen(buf));
+	len = read(s, buf, 256);
+	buf[len] = '\0';
+	printf("%s", buf);	
+	
+	sprintf(buf, "OPEN lsb\n");
+	write(s, buf, strlen(buf));
+	len = read(s, buf, 256);
+	buf[len] = '\0';
+	printf("%s", buf);	
+
+	sscanf(buf, "%d %d", &dummy, &newport);
+	printf("	 => port = %d\n", newport);
+	
+	s2 = connect_to_timidity(newport);
+	_mo = (void *) s2;
+}
+
+void MidiDriver::midiInitSeq() {
+	int device;
+	device = open_sequencer_device();
+	_mo = (void *) device;
+}
+
+void MidiDriver::midiInitWindows() {
+	#ifdef WIN32
+	if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR)
+		error("midiOutOpen failed");
+	#endif
+}
+
+void MidiDriver::midiInitNull() {
+	warning("Using the NULL midi driver, no music will be heard");
+}
+
+void MidiDriver::midiInit() {
+	if (MidiInitialized != true) {
+		switch (DeviceType) {
+		case MIDI_NULL:
+			midiInitNull();
+			break;
+		case MIDI_WINDOWS:
+			midiInitWindows();
+			break;
+		case MIDI_TIMIDITY:
+			midiInitTimidity();
+			break;
+		case MIDI_SEQ:
+			midiInitSeq();
+			break;
+		default:
+			#ifdef WIN32
+			midiInitWindows();
+			#else
+			DeviceType = 0;
+			midiInitNull();
+			#endif
+			break;
+		}
+		MidiInitialized = true;
+	} else {
+		error("Midi driver already initialized");
+	}
+}
+
+void MidiDriver::MidiOutSeq(void *a, int b) {
+	int s = (int) a;
+	unsigned char buf[256];
+	int position = 0;
+	switch (b & 0xF0) {
+	case 0x80:
+	case 0x90:
+	case 0xA0:
+	case 0xB0:
+	case 0xE0:
+		buf[position++] = SEQ_MIDIPUTC;
+		buf[position++] = b;
+		buf[position++] = SeqDevice;		
+		buf[position++] = 0;
+		buf[position++] = SEQ_MIDIPUTC;
+		buf[position++] = (b >> 8) & 0x7F;
+		buf[position++] = SeqDevice;		
+		buf[position++] = 0;
+		buf[position++] = SEQ_MIDIPUTC;
+		buf[position++] = (b >> 16) & 0x7F;
+		buf[position++] = SeqDevice;		
+		buf[position++] = 0;
+		break;
+	case 0xC0:
+	case 0xD0:
+		buf[position++] = SEQ_MIDIPUTC;
+		buf[position++] = b;
+		buf[position++] = SeqDevice;		
+		buf[position++] = 0;
+		buf[position++] = SEQ_MIDIPUTC;
+		buf[position++] = (b >> 8) & 0x7F;
+		buf[position++] = SeqDevice;		
+		buf[position++] = 0;
+		break;
+	default:
+		fprintf(stderr, "Unknown : %08x\n", b);
+		break;
+	}
+	write(s, buf, position);
+}
+
+void MidiDriver::MidiOutWindows(void *a, int b) {
+	#ifdef WIN32
+	midiOutShortMsg((HMIDIOUT) a, b);
+	#endif	
+}
+
+void MidiDriver::MidiOut(void *a, int b) {
+	if (MidiInitialized != true) {
+		#ifdef WIN32
+		DeviceType = MIDI_WINDOWS;
+		midiInit();
+		#else
+		DeviceType = MIDI_NULL;
+		midiInit();
+		#endif
+	}
+	
+	if (MidiInitialized == true) {
+		switch (DeviceType) {
+		case MIDI_NULL:
+			break;
+		case MIDI_WINDOWS:
+			MidiOutWindows(a, b);
+			break;
+		case MIDI_TIMIDITY:
+		case MIDI_SEQ:
+			MidiOutSeq(a, b);
+			break;
+		default:
+			error("Invalid midi device type ");
+			break;
+		}
+	} else {
+		warning("Trying to write midi data without the driver being initialized");
+	}
+}
+
 /**********************************************************************/
 
 byte *SoundEngine::findTag(int sound, char *tag, int index) {
@@ -914,7 +1117,6 @@
 	init_volume_fader();
 	init_queue();
 	init_parts();
-	midiInit();
 
 	_initialized = true;
 	
@@ -2462,186 +2664,74 @@
 	}
 }
 
-#if defined(WIN32)
-
-void SoundEngine::midiInit() {
-	if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR)
-		error("midiOutOpen failed");
-}
-
-#define MIDI_OUT(a,b) midiOutShortMsg((HMIDIOUT)(a), (b))
-
-#elif defined(USE_TIMIDITY)
-
-static int connect_to_timidity(int port)
-{
-	struct hostent *serverhost;
-	struct sockaddr_in sadd;
-	int s;
-	
-	serverhost = gethostbyname("localhost");
-	if (serverhost == NULL)
-		error("Could not resolve host");
-	sadd.sin_family = serverhost->h_addrtype;
-	sadd.sin_port = htons(port);
-	memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length);
-	
-	s = socket(AF_INET,SOCK_STREAM,0);
-	if (s < 0)
-		error("Could not open socket");
-	if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0)
-		error("Could not connect to server");
-	
-	return s;
-}
-
-void SoundEngine::midiInit() {
-	int s, s2;
-	int len;
-	int dummy, newport;
-	char buf[256];
-
-	s = connect_to_timidity(7777);
-	len = read(s, buf, 256);
-	buf[len] = '\0';
-	printf("%s", buf);
-
-	sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15);
-	write(s, buf, strlen(buf));
-	len = read(s, buf, 256);
-	buf[len] = '\0';
-	printf("%s", buf);	
-	
-	sprintf(buf, "OPEN lsb\n");
-	write(s, buf, strlen(buf));
-	len = read(s, buf, 256);
-	buf[len] = '\0';
-	printf("%s", buf);	
-
-	sscanf(buf, "%d %d", &dummy, &newport);
-	printf("	 => port = %d\n", newport);
-	
-	s2 = connect_to_timidity(newport);
-	_mo = (void *) s2;
-}
-
-#define DEVICE_NUM 0
-
-static inline void MIDI_OUT(void *a, int b) {
-	int s = (int) a;
-	unsigned char buf[256];
-	int position = 0;
-	
-	switch (b & 0xF0) {
-	case 0x80:
-	case 0x90:
-	case 0xA0:
-	case 0xB0:
-	case 0xE0:
-		buf[position++] = SEQ_MIDIPUTC;
-		buf[position++] = b;
-		buf[position++] = DEVICE_NUM;		
-		buf[position++] = 0;
-		buf[position++] = SEQ_MIDIPUTC;
-		buf[position++] = (b >> 8) & 0x7F;
-		buf[position++] = DEVICE_NUM;		
-		buf[position++] = 0;
-		buf[position++] = SEQ_MIDIPUTC;
-		buf[position++] = (b >> 16) & 0x7F;
-		buf[position++] = DEVICE_NUM;		
-		buf[position++] = 0;
-		break;
-	case 0xC0:
-	case 0xD0:
-		buf[position++] = SEQ_MIDIPUTC;
-		buf[position++] = b;
-		buf[position++] = DEVICE_NUM;		
-		buf[position++] = 0;
-		buf[position++] = SEQ_MIDIPUTC;
-		buf[position++] = (b >> 8) & 0x7F;
-		buf[position++] = DEVICE_NUM;		
-		buf[position++] = 0;
-		break;
-	default:
-		fprintf(stderr, "Unknown : %08x\n", b);
-		break;
-	}
-	write(s, buf, position);
-}
-
-#else
-#define MIDI_OUT(a,b)
-void SoundEngine::midiInit() { }
-#endif
-
 void SoundEngine::midiPitchBend(byte chan, int16 pitchbend) {
 	uint16 tmp;
 
 	if (_midi_pitchbend_last[chan] != pitchbend) {
 		_midi_pitchbend_last[chan] = pitchbend;
 		tmp = (pitchbend<<2) + 0x2000;
-		MIDI_OUT(_mo, ((tmp>>7)&0x7F)<<16 | (tmp&0x7F)<<8 | 0xE0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, ((tmp>>7)&0x7F)<<16 | (tmp&0x7F)<<8 | 0xE0 | chan);
 	}
 }
 
 void SoundEngine::midiVolume(byte chan, byte volume) {
 	if (_midi_volume_last[chan] != volume) {
 		_midi_volume_last[chan] = volume;
-		MIDI_OUT(_mo, volume<<16 | 7<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, volume<<16 | 7<<8 | 0xB0 | chan);
 	}
 }
 void SoundEngine::midiPedal(byte chan, bool pedal) {
 	if (_midi_pedal_last[chan] != pedal) {
 		_midi_pedal_last[chan] = pedal;
-		MIDI_OUT(_mo, pedal<<16 | 64<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, pedal<<16 | 64<<8 | 0xB0 | chan);
 	}
 }
 
 void SoundEngine::midiModWheel(byte chan, byte modwheel) {
 	if (_midi_modwheel_last[chan] != modwheel) {
 		_midi_modwheel_last[chan] = modwheel;
-		MIDI_OUT(_mo, modwheel<<16 | 1<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, modwheel<<16 | 1<<8 | 0xB0 | chan);
 	}
 }
 
 void SoundEngine::midiEffectLevel(byte chan, byte level) {
 	if (_midi_effectlevel_last[chan] != level) {
 		_midi_effectlevel_last[chan] = level;
-		MIDI_OUT(_mo, level<<16 | 91<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, level<<16 | 91<<8 | 0xB0 | chan);
 	}
 }
 
 void SoundEngine::midiChorus(byte chan, byte chorus) {
 	if (_midi_chorus_last[chan] != chorus) {
 		_midi_chorus_last[chan] = chorus;
-		MIDI_OUT(_mo, chorus<<16 | 93<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, chorus<<16 | 93<<8 | 0xB0 | chan);
 	}
 }
 
 void SoundEngine::midiControl0(byte chan, byte value) {
-	MIDI_OUT(_mo, value<<16 | 0<<8 | 0xB0 | chan);
+	_midi_driver.MidiOut(_midi_driver._mo, value<<16 | 0<<8 | 0xB0 | chan);
 }
 
 void SoundEngine::midiProgram(byte chan, byte program) {
-	MIDI_OUT(_mo, program<<8 | 0xC0 | chan);
+	_midi_driver.MidiOut(_midi_driver._mo, program<<8 | 0xC0 | chan);
 }
 
 void SoundEngine::midiPan(byte chan, int8 pan) {
 	if (_midi_pan_last[chan] != pan) {
 		_midi_pan_last[chan] = pan;
-		MIDI_OUT(_mo, ((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan);
+		_midi_driver.MidiOut(_midi_driver._mo, ((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan);
 	}
 }
 
 void SoundEngine::midiNoteOn(byte chan, byte note, byte velocity) {
-	MIDI_OUT(_mo, velocity<<16 | note<<8 | 0x90 | chan);	
+	_midi_driver.MidiOut(_midi_driver._mo, velocity<<16 | note<<8 | 0x90 | chan);	
 }
 
 void SoundEngine::midiNoteOff(byte chan, byte note) {
-	MIDI_OUT(_mo, note<<8 | 0x80 | chan);	
+	_midi_driver.MidiOut(_midi_driver._mo, note<<8 | 0x80 | chan);	
 }
 
 void SoundEngine::midiSilence(byte chan) {
-	MIDI_OUT(_mo, (64<<8)|0xB0|chan);
-	MIDI_OUT(_mo, (123<<8)|0xB0|chan);
+	_midi_driver.MidiOut(_midi_driver._mo, (64<<8)|0xB0|chan);
+	_midi_driver.MidiOut(_midi_driver._mo, (123<<8)|0xB0|chan);
 }
diff -u scummvm.orig/readme.txt scummvm.new/readme.txt
--- scummvm.orig/readme.txt	Mon Nov 19 11:23:52 2001
+++ scummvm.new/readme.txt	Wed Nov 21 20:33:10 2001
@@ -42,25 +42,26 @@
 Ctrl-s shows memory consumption.
 
 
-Playing sound with Timidity:
+Playing music in Unix with a sound card 
+---------------------------------------
+*Compile ScummVM as per the instructions above
+*Start ScummVM as follows:
+
+$ scummvm -sX
+where X is the device number of your midi output (On most cards, 0 is the external midi device and 1 is the internal midi synth. Be warned, very few cards apart from Soundblaster Live and Soundblaster AWE cards actually have an internal synth that works in linux)
+
+
+Playing music in Unix with Timidity:
 ----------------------------
-Start Timidity with the following command line :
+*Compile ScummVM as per the instructions above
+*Make sure you have timidity set up with a set of sounds (see the timidity docs for this)
+*Start timidity with the following command line:
 
 $ timidity -irv 7777
+If you get errors about invalid interfaces, make sure you have compiled timidity with the configure option "--enable-server"
 
-Then just start ScummVM and you should have sound.
+*Start ScummVM and you should have music.
 
 
 Good Luck,
 Ludvig Strigeus
-
-
-
-
-
-
-
-
-
-
-
diff -u scummvm.orig/scumm.h scummvm.new/scumm.h
--- scummvm.orig/scumm.h	Thu Nov 15 07:09:39 2001
+++ scummvm.new/scumm.h	Wed Nov 21 20:13:28 2001
@@ -357,6 +357,13 @@
 	RF_USAGE_MAX = RF_USAGE
 };
 
+enum {
+	MIDI_NULL = 0,
+	MIDI_WINDOWS = 1,
+	MIDI_TIMIDITY = 2,
+	MIDI_SEQ = 3,
+};
+
 #define _maxRooms res.num[rtRoom]
 #define _maxScripts res.num[rtScript]
 #define _maxCostumes res.num[rtCostume]
@@ -686,6 +693,8 @@
 
 	int _keyPressed;
 
+	int _midi_driver;
+	int _midi_seq_device;
 	void *_soundDriver;
 
 	uint16 *_inventory;
diff -u scummvm.orig/scummvm.cpp scummvm.new/scummvm.cpp
--- scummvm.orig/scummvm.cpp	Thu Nov 15 07:09:39 2001
+++ scummvm.new/scummvm.cpp	Wed Nov 21 20:14:20 2001
@@ -382,6 +382,15 @@
 			s++;
 			while (*s) {
 				switch(tolower(*s)) {
+				#ifndef WIN32
+				case 't':
+					_midi_driver = MIDI_TIMIDITY;
+					goto NextArg;
+				case 's':
+					_midi_driver = MIDI_SEQ;
+					_midi_seq_device = atoi(s+1);
+					goto NextArg;
+				#endif
 				case 'b': 
 					_bootParam = atoi(s+1);
 					goto NextArg;
@@ -396,6 +405,10 @@
 						"\tscummvm [-b<num>] game\n"
 						"Flags:\n"
 						"\tb<num> - start in that room\n"
+						#ifndef WIN32
+						"\tt - use timidity for music output\n"
+						"\ts<num> - use a midi sequencer device <num> for music output\n"
+						#endif
 						"\tf - fullscreen mode\n");
 					exit(1);
 				}
diff -u scummvm.orig/sdl.cpp scummvm.new/sdl.cpp
--- scummvm.orig/sdl.cpp	Thu Nov 15 05:37:38 2001
+++ scummvm.new/sdl.cpp	Wed Nov 21 20:13:56 2001
@@ -565,7 +565,12 @@
 
 	scumm._gui = &gui;
 	scumm.scummMain(argc, argv);
-
+	
+	if (scumm._midi_driver == MIDI_SEQ)
+		sound.midiSetDriver(scumm._midi_driver, scumm._midi_seq_device);
+	else
+		sound.midiSetDriver(scumm._midi_driver);
+		
 	gui.init(&scumm);
 
 	last_time = SDL_GetTicks();
diff -u scummvm.orig/sound.h scummvm.new/sound.h
--- scummvm.orig/sound.h	Thu Nov 15 05:37:38 2001
+++ scummvm.new/sound.h	Wed Nov 21 20:42:10 2001
@@ -30,6 +30,26 @@
 struct HookDatas;
 struct SoundEngine;
 
+struct MidiDriver {
+	bool MidiInitialized;
+	int DeviceType;
+	int SeqDevice;
+	void *_mo; /* midi out */
+	
+	void midiInit();
+	void midiInitTimidity();
+	void midiInitSeq();
+	void midiInitWindows();
+	void midiInitNull();
+	
+	void MidiOut(void *a, int b);
+	void MidiOutSeq(void *a, int b);
+	void MidiOutWindows(void *a, int b);
+	
+	int connect_to_timidity(int port);
+	int open_sequencer_device();
+};
+
 struct Part {
 	SoundEngine *_se;
 	Part *_next, *_prev;
@@ -236,8 +256,6 @@
 };
 
 struct SoundEngine {
-	void *_mo; /* midi out */
-
 	byte **_base_sounds;
 
 	Scumm *_s;
@@ -268,6 +286,7 @@
 	uint16 _channel_volume_eff[8]; /* NoSave */
 	uint16 _volchan_table[8];
 	
+	MidiDriver _midi_driver;
 	Player _players[8];
 	SustainingNotes _sustaining_notes[24];
 	VolumeFader _volume_fader[8];
@@ -341,8 +360,10 @@
 	void midiNoteOn(byte chan, byte note, byte velocity);
 	void midiNoteOff(byte chan, byte note);
 	void midiSilence(byte chan);
-	void midiInit();
 
+	void midiSetDriver(int devicetype);
+	void midiSetDriver(int devicetype, int seq_device);
+	
 	void adjust_priorities();
 
 	void fix_parts_after_load();
Common subdirectories: scummvm.orig/wince and scummvm.new/wince
