[Scummvm-cvs-logs] CVS: scummvm/backends/midi adlib.cpp,1.7,1.8 alsa.cpp,1.1,1.2 coreaudio.cpp,1.1,1.2 null.cpp,1.2,1.3 quicktime.cpp,1.1,1.2 windows.cpp,1.2,1.3

Max Horn fingolfin at users.sourceforge.net
Wed Dec 11 08:11:05 CET 2002


Update of /cvsroot/scummvm/scummvm/backends/midi
In directory sc8-pr-cvs1:/tmp/cvs-serv3198/backends/midi

Modified Files:
	adlib.cpp alsa.cpp coreaudio.cpp null.cpp quicktime.cpp 
	windows.cpp 
Log Message:
ripped out obsolete midi streaming code from backends (this may break Alsa/SEQ/Windows/Morphos compile, I tried my best, but you'll have to clean up after me)

Index: adlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/adlib.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- adlib.cpp	8 Dec 2002 20:19:01 -0000	1.7
+++ adlib.cpp	11 Dec 2002 16:09:53 -0000	1.8
@@ -488,11 +488,9 @@
 public:
 	MidiDriver_ADLIB();
 
-	int open(int mode);
+	int open();
 	void close();
 	void send(uint32 b);
-	void pause(bool p) { }
-	void set_stream_callback(void *param, StreamCallback *sc) { } // No streaming support. Use MidiStreamer wrapper
 	uint32 property (int prop, uint32 param);
 
 	void setPitchBendRange (byte channel, uint range); 
@@ -511,7 +509,7 @@
 	MidiChannel *getPercussionChannel() { return NULL; } // Percussion currently not supported
 
 private:
-	int _mode;
+	bool _isOpen;
 	bool _game_SmallHeader;
 
 	FM_OPL *_opl;
@@ -720,15 +718,14 @@
 		_parts[i].init (this);
 	}
 	_game_SmallHeader = false;
+	_isOpen = false;
 }
 
-int MidiDriver_ADLIB::open (int mode)
+int MidiDriver_ADLIB::open ()
 {
-	if (_mode != 0)
+	if (_isOpen)
 		return MERR_ALREADY_OPEN;
-	if (mode != MO_SIMPLE)
-		return MERR_STREAMING_NOT_AVAILABLE;
-	_mode = mode;
+	_isOpen = true;
 
 	int i;
 	MidiChannelAdl *mc;
@@ -750,6 +747,7 @@
 
 	_mixer = g_mixer;
 	_mixer->setupPremix(this, premix_proc);
+	
 	return 0;
 }
 
@@ -763,13 +761,12 @@
 
 	// Detach the premix callback handler
 	_mixer->setupPremix (0, 0);
+
+	_isOpen = false;
 }
 
 void MidiDriver_ADLIB::send (uint32 b)
 {
-	if (_mode != MO_SIMPLE)
-		error("MidiDriver_ADLIB::send called but driver is not in simple mode");
-
 	//byte param3 = (byte) ((b >> 24) & 0xFF);
 	byte param2 = (byte) ((b >> 16) & 0xFF);
 	byte param1 = (byte) ((b >>  8) & 0xFF);

Index: alsa.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/alsa.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- alsa.cpp	8 Dec 2002 20:47:42 -0000	1.1
+++ alsa.cpp	11 Dec 2002 16:09:54 -0000	1.2
@@ -51,72 +51,33 @@
 class MidiDriver_ALSA:public MidiDriver_MPU401 {
 public:
 	MidiDriver_ALSA();
-	int open(int mode);
+	int open();
 	void close();
 	void send(uint32 b);
-	void pause(bool p);
-	void set_stream_callback(void *param, StreamCallback *sc);
-	// void setPitchBendRange (byte channel, uint range);
 
 private:
 	void send_event(int do_flush);
+	bool _isOpen;
 	snd_seq_event_t ev;
-	StreamCallback *_stream_proc;
-	void *_stream_param;
-	int _mode;
 	snd_seq_t *seq_handle;
 	int seq_client, seq_port;
 	int my_client, my_port;
 	static int parse_addr(char *arg, int *client, int *port);
 };
 
-MidiDriver_ALSA::MidiDriver_ALSA():_mode(0), seq_handle(0), seq_client(0), seq_port(0), my_client(0),
-my_port(0)
-{
-}
-
-int MidiDriver_ALSA::parse_addr(char *arg, int *client, int *port)
-{
-	char *p;
-
-	if (isdigit(*arg)) {
-		if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
-			return -1;
-		*client = atoi(arg);
-		*port = atoi(p + 1);
-	} else {
-		if (*arg == 's' || *arg == 'S') {
-			*client = SND_SEQ_ADDRESS_SUBSCRIBERS;
-			*port = 0;
-		} else
-			return -1;
-	}
-	return 0;
-}
-
-void MidiDriver_ALSA::send_event(int do_flush)
+MidiDriver_ALSA::MidiDriver_ALSA()
+ : _isOpen(false), seq_handle(0), seq_client(0), seq_port(0), my_client(0), my_port(0)
 {
-	snd_seq_ev_set_direct(&ev);
-	snd_seq_ev_set_source(&ev, my_port);
-	snd_seq_ev_set_dest(&ev, seq_client, seq_port);
-
-	snd_seq_event_output(seq_handle, &ev);
-	if (do_flush)
-		snd_seq_flush_output(seq_handle);
 }
 
-int MidiDriver_ALSA::open(int mode)
+int MidiDriver_ALSA::open()
 {
 	char *var;
 	unsigned int caps;
 
-	if (_mode != 0)
+	if (_isOpen)
 		return MERR_ALREADY_OPEN;
-
-	if (mode != MO_SIMPLE)
-		return MERR_STREAMING_NOT_AVAILABLE;
-
-	_mode = mode;
+	_isOpen = true;
 
 	if (!(var = getenv("SCUMMVM_PORT"))) {
 		// default alsa port if none specified
@@ -225,17 +186,34 @@
 	}
 }
 
-void MidiDriver_ALSA::pause(bool p)
+int MidiDriver_ALSA::parse_addr(char *arg, int *client, int *port)
 {
-	if (_mode == MO_STREAMING) {
-		/* Err... and what? */
+	char *p;
+
+	if (isdigit(*arg)) {
+		if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
+			return -1;
+		*client = atoi(arg);
+		*port = atoi(p + 1);
+	} else {
+		if (*arg == 's' || *arg == 'S') {
+			*client = SND_SEQ_ADDRESS_SUBSCRIBERS;
+			*port = 0;
+		} else
+			return -1;
 	}
+	return 0;
 }
 
-void MidiDriver_ALSA::set_stream_callback(void *param, StreamCallback *sc)
+void MidiDriver_ALSA::send_event(int do_flush)
 {
-	_stream_param = param;
-	_stream_proc = sc;
+	snd_seq_ev_set_direct(&ev);
+	snd_seq_ev_set_source(&ev, my_port);
+	snd_seq_ev_set_dest(&ev, seq_client, seq_port);
+
+	snd_seq_event_output(seq_handle, &ev);
+	if (do_flush)
+		snd_seq_flush_output(seq_handle);
 }
 
 MidiDriver *MidiDriver_ALSA_create()

Index: coreaudio.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/coreaudio.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- coreaudio.cpp	8 Dec 2002 20:19:01 -0000	1.1
+++ coreaudio.cpp	11 Dec 2002 16:09:54 -0000	1.2
@@ -39,30 +39,21 @@
 class MidiDriver_CORE : public MidiDriver_MPU401 {
 public:
 	MidiDriver_CORE() : au_MusicDevice(0), au_output(0) { }
-	int open(int mode);
+	int open();
 	void close();
 	void send(uint32 b);
-	void pause(bool p) { }
-	void set_stream_callback(void *param, StreamCallback *sc) { }
 
 private:
 	AudioUnit au_MusicDevice;
 	AudioUnit au_output;
-
-	int _mode;
 };
 
 
-int MidiDriver_CORE::open(int mode)
+int MidiDriver_CORE::open()
 {
 	if (au_output != NULL)
 		return MERR_ALREADY_OPEN;
 
-	if (mode == MO_STREAMING)
-		return MERR_STREAMING_NOT_AVAILABLE;
-
-	_mode = mode;
-
 	int err;
 	AudioUnitConnection auconnect;
 	ComponentDescription compdesc;
@@ -106,8 +97,6 @@
 	// Cleanup
 	CloseComponent(au_output);
 	CloseComponent(au_MusicDevice);
-
-	_mode = 0;
 }
 
 void MidiDriver_CORE::send(uint32 b)

Index: null.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/null.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- null.cpp	9 Dec 2002 02:40:22 -0000	1.2
+++ null.cpp	11 Dec 2002 16:09:54 -0000	1.3
@@ -25,14 +25,12 @@
 /* NULL driver */
 class MidiDriver_NULL : public MidiDriver_MPU401 {
 public:
-	int open(int mode);
+	int open();
 	void close() { }
 	void send(uint32 b) { }
-	void pause(bool p) { }
-	void set_stream_callback(void *param, StreamCallback *sc) { }
 };
 
-int MidiDriver_NULL::open(int mode)
+int MidiDriver_NULL::open()
 {
 	warning("Music not enabled - MIDI support selected with no MIDI driver available. Try Adlib");
 	return 0;

Index: quicktime.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/quicktime.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- quicktime.cpp	8 Dec 2002 20:19:01 -0000	1.1
+++ quicktime.cpp	11 Dec 2002 16:09:54 -0000	1.2
@@ -46,11 +46,11 @@
  */
 class MidiDriver_QT : public MidiDriver_MPU401 {
 public:
-	int open(int mode);
+	MidiDriver_QT();
+	
+	int open();
 	void close();
 	void send(uint32 b);
-	void pause(bool p) { }
-	void set_stream_callback(void *param, StreamCallback *sc);
 	void setPitchBendRange (byte channel, uint range);
 
 private:
@@ -58,33 +58,24 @@
 	NoteChannel qtNoteChannel[16];
 	NoteRequest simpleNoteRequest;
 
-	StreamCallback *_stream_proc;
-	void *_stream_param;
-	int _mode;
-
 	// Pitch bend tracking. Necessary since QTMA handles
 	// pitch bending so differently from MPU401.
 	uint16 _pitchbend [16];
 	byte _pitchbend_range [16];
 };
 
-void MidiDriver_QT::set_stream_callback(void *param, StreamCallback *sc)
+MidiDriver_QT::MidiDriver_QT()
 {
-	_stream_param = param;
-	_stream_proc = sc;
+	qtNoteAllocator = NULL;
 }
 
-int MidiDriver_QT::open(int mode)
+int MidiDriver_QT::open()
 {
 	ComponentResult qtErr = noErr;
 	int i;
 
-	qtNoteAllocator = NULL;
-
-	if (mode == MO_STREAMING)
-		return MERR_STREAMING_NOT_AVAILABLE;
-
-	_mode = mode;
+	if (qtNoteAllocator != NULL)
+		return MERR_ALREADY_OPEN;
 
 	for (i = 0; i < 15; i++)
 		qtNoteChannel[i] = NULL;
@@ -126,8 +117,6 @@
 
 void MidiDriver_QT::close()
 {
-	_mode = 0;
-
 	for (int i = 0; i < 15; i++) {
 		if (qtNoteChannel[i] != NULL)
 			NADisposeNoteChannel(qtNoteAllocator, qtNoteChannel[i]);
@@ -142,9 +131,6 @@
 
 void MidiDriver_QT::send(uint32 b)
 {
-	if (_mode != MO_SIMPLE)
-		error("MidiDriver_QT:send called but driver is not in simple mode");
-
 	MusicMIDIPacket midPacket;
 	unsigned char *midiCmd = midPacket.data;
 	midPacket.length = 3;

Index: windows.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/windows.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- windows.cpp	11 Dec 2002 02:38:38 -0000	1.2
+++ windows.cpp	11 Dec 2002 16:09:54 -0000	1.3
@@ -32,189 +32,41 @@
 
 class MidiDriver_WIN : public MidiDriver_MPU401 {
 public:
+	MidiDriver_WIN();
 	int open(int mode);
 	void close();
 	void send(uint32 b);
-	void pause(bool p);
-	void set_stream_callback(void *param, StreamCallback *sc);
 
 private:
-	struct MyMidiHdr {
-		MIDIHDR hdr;
-	};
-
-	enum {
-		NUM_PREPARED_HEADERS = 2,
-		MIDI_EVENT_SIZE = 64,
-		BUFFER_SIZE = MIDI_EVENT_SIZE * 12,
-	};
-
-	StreamCallback *_stream_proc;
-	void *_stream_param;
-	int _mode;
-
 	HMIDIOUT _mo;
-	HMIDISTRM _ms;
-
-	MyMidiHdr *_prepared_headers;
-
-	uint16 _time_div;
 
-	void unprepare();
-	void prepare();
 	void check_error(MMRESULT result);
-	void fill_all();
 	uint32 property(int prop, uint32 param);
-
-	static void CALLBACK midi_callback(HMIDIOUT hmo, UINT wMsg,
-	                                   DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
 };
 
-void MidiDriver_WIN::set_stream_callback(void *param, StreamCallback *sc)
-{
-	_stream_param = param;
-	_stream_proc = sc;
-}
-
-void CALLBACK MidiDriver_WIN::midi_callback(HMIDIOUT hmo, UINT wMsg,
-                                            DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
+MidiDriver_WIN::MidiDriver_WIN()
 {
-	switch (wMsg) {
-	case MM_MOM_DONE:{
-			MidiDriver_WIN *md = ((MidiDriver_WIN *) dwInstance);
-			if (md->_mode)
-				md->fill_all();
-			break;
-		}
-	}
+	_isOpen = false;
 }
 
-int MidiDriver_WIN::open(int mode)
+int MidiDriver_WIN::open()
 {
-	if (_mode != 0)
+	if (_isOpen)
 		return MERR_ALREADY_OPEN;
 
-	_mode = mode;
-
-	if (mode == MO_SIMPLE) {
-		MMRESULT res = midiOutOpen((HMIDIOUT *) & _mo, MIDI_MAPPER, 0, 0, 0);
-		if (res != MMSYSERR_NOERROR)
-			check_error(res);
-	} else {
-		// Streaming mode
-		MIDIPROPTIMEDIV mptd;
-		UINT _midi_device_id = 0;
-
-		check_error(midiStreamOpen(&_ms, &_midi_device_id, 1,
-                                   (uint32)midi_callback, (uint32)this, CALLBACK_FUNCTION));
-
-		prepare();
-
-		mptd.cbStruct = sizeof(mptd);
-		mptd.dwTimeDiv = _time_div;
-
-		check_error(midiStreamProperty(_ms, (byte *)&mptd, MIDIPROP_SET | MIDIPROP_TIMEDIV));
+	_isOpen = true;
 
-		fill_all();
-	}
+	MMRESULT res = midiOutOpen((HMIDIOUT *) &_mo, MIDI_MAPPER, 0, 0, 0);
+	if (res != MMSYSERR_NOERROR)
+		check_error(res);
 
 	return 0;
 }
 
-void MidiDriver_WIN::fill_all()
-{
-	if (_stream_proc == NULL) {
-		error("MidiDriver_WIN::fill_all() called, but _stream_proc==NULL");
-	}
-
-	uint i;
-	MyMidiHdr *mmh = _prepared_headers;
-	MidiEvent my_evs[64];
-
-	for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) {
-		if (!(mmh->hdr.dwFlags & MHDR_INQUEUE)) {
-			int num = _stream_proc(_stream_param, my_evs, 64);
-			int i;
-
-			// End of stream?
-			if (num == 0)
-				break;
-
-			MIDIEVENT *ev = (MIDIEVENT *)mmh->hdr.lpData;
-			MidiEvent *my_ev = my_evs;
-
-			for (i = 0; i != num; i++, my_ev++) {
-				ev->dwStreamID = 0;
-				ev->dwDeltaTime = my_ev->delta;
-
-				switch (my_ev->event >> 24) {
-				case 0:
-					ev->dwEvent = my_ev->event;
-					break;
-				case ME_TEMPO:
-					// Change tempo event
-					ev->dwEvent = (ME_TEMPO << 24) | (my_ev->event & 0xFFFFFF);
-					break;
-				default:
-					error("Invalid event type passed");
-				}
-
-				// Increase stream pointer by 12 bytes.
-				// (Need to be 12 bytes, and sizeof(MIDIEVENT) is 16)
-				ev = (MIDIEVENT *)((byte *)ev + 12);
-			}
-
-			mmh->hdr.dwBytesRecorded = num * 12;
-			check_error(midiStreamOut(_ms, &mmh->hdr, sizeof(mmh->hdr)));
-		}
-	}
-}
-
-void MidiDriver_WIN::prepare()
-{
-	int i;
-	MyMidiHdr *mmh;
-
-	_prepared_headers = (MyMidiHdr *) calloc(sizeof(MyMidiHdr), 2);
-
-	for (i = 0, mmh = _prepared_headers; i != NUM_PREPARED_HEADERS; i++, mmh++) {
-		mmh->hdr.dwBufferLength = BUFFER_SIZE;
-		mmh->hdr.lpData = (LPSTR) calloc(BUFFER_SIZE, 1);
-
-		check_error(midiOutPrepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr)));
-	}
-}
-
-void MidiDriver_WIN::unprepare()
-{
-	uint i;
-	MyMidiHdr *mmh = _prepared_headers;
-
-	for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) {
-		check_error(midiOutUnprepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr)));
-		free(mmh->hdr.lpData);
-		mmh->hdr.lpData = NULL;
-	}
-
-	free(_prepared_headers);
-}
-
 void MidiDriver_WIN::close()
 {
-	int mode_was = _mode;
-	_mode = 0;
-
-	switch (mode_was) {
-	case MO_SIMPLE:
-		check_error(midiOutClose(_mo));
-		break;
-	case MO_STREAMING:;
-		check_error(midiStreamStop(_ms));
-		check_error(midiOutReset((HMIDIOUT) _ms));
-		unprepare();
-		check_error(midiStreamClose(_ms));
-		break;
-	}
+	_isOpen = false;
+	check_error(midiOutClose(_mo));
 }
 
 void MidiDriver_WIN::send(uint32 b)
@@ -224,9 +76,6 @@
 		BYTE bData[4];
 	} u;
 
-	if (_mode != MO_SIMPLE)
-		error("MidiDriver_WIN:send called but driver is not in simple mode");
-
 	u.bData[3] = (byte)((b & 0xFF000000) >> 24);
 	u.bData[2] = (byte)((b & 0x00FF0000) >> 16);
 	u.bData[1] = (byte)((b & 0x0000FF00) >> 8);
@@ -236,16 +85,6 @@
 	check_error(midiOutShortMsg(_mo, u.dwData));
 }
 
-void MidiDriver_WIN::pause(bool p)
-{
-	if (_mode == MO_STREAMING) {
-		if (p)
-			check_error(midiStreamPause(_ms));
-		else
-			check_error(midiStreamRestart(_ms));
-	}
-}
-
 void MidiDriver_WIN::check_error(MMRESULT result)
 {
 	char buf[200];
@@ -253,19 +92,6 @@
 		midiOutGetErrorText(result, buf, 200);
 		warning("MM System Error '%s'", buf);
 	}
-}
-
-uint32 MidiDriver_WIN::property(int prop, uint32 param)
-{
-	switch (prop) {
-
-	// 16-bit time division per the standard MIDI specification
-	case PROP_TIMEDIV:
-		_time_div = (uint16)param;
-		return 1;
-	}
-
-	return 0;
 }
 
 MidiDriver *MidiDriver_WIN_create()





More information about the Scummvm-git-logs mailing list