[Scummvm-cvs-logs] CVS: scummvm/sound mididrv.cpp,1.36,1.37 mididrv.h,1.10,1.11 midistreamer.cpp,1.4,1.5 midistreamer.h,1.2,1.3

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


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

Modified Files:
	mididrv.cpp mididrv.h midistreamer.cpp midistreamer.h 
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: mididrv.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mididrv.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- mididrv.cpp	11 Dec 2002 02:08:32 -0000	1.36
+++ mididrv.cpp	11 Dec 2002 16:09:56 -0000	1.37
@@ -42,7 +42,7 @@
 
 
 /* retrieve a string representation of an error code */
-const char *MidiDriver::get_error_name(int error_code)
+const char *MidiDriver::getErrorName(int error_code)
 {
 	static const char *const midi_errors[] = {
 		"No error",
@@ -69,14 +69,12 @@
 #include "morphos_sound.h"
 
 /* MorphOS MIDI driver */
-class MidiDriver_ETUDE:public MidiDriver_MPU401 {
+class MidiDriver_ETUDE : public MidiDriver_MPU401 {
 public:
+	MidiDriver_ETUDE();
 	int open(int mode);
 	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:
 	enum {
@@ -85,88 +83,37 @@
 		BUFFER_SIZE = MIDI_EVENT_SIZE * 12,
 	};
 
-	static void midi_callback(ULONG msg, struct IOMidiRequest *req, APTR user_data);
-	void fill_all();
 	uint32 property(int prop, uint32 param);
 
-	StreamCallback *_stream_proc;
-	void *_stream_param;
-	IOMidiRequest *_stream_req[NUM_BUFFERS];
-	void *_stream_buf[NUM_BUFFERS];
-	bool _req_sent[NUM_BUFFERS];
-	int _mode;
-	uint16 _time_div;
+	bool _isOpen;
 };
 
-void MidiDriver_ETUDE::set_stream_callback(void *param, StreamCallback *sc)
+MidiDriver_ETUDE::MidiDriver_ETUDE()
 {
-	_stream_param = param;
-	_stream_proc = sc;
+	_isOpen = false;
 }
 
-int MidiDriver_ETUDE::open(int mode)
+int MidiDriver_ETUDE::open()
 {
-	if (_mode != 0)
+	if (_isOpen)
 		return MERR_ALREADY_OPEN;
-	_mode = mode;
-	if (!init_morphos_music(0, _mode == MO_STREAMING ? ETUDEF_STREAMING : ETUDEF_DIRECT))
+	_isOpen = true;
+	if (!init_morphos_music(0, ETUDEF_DIRECT))
 		return MERR_DEVICE_NOT_AVAILABLE;
 
-	if (_mode == MO_STREAMING && ScummMidiRequest) {
-		_stream_req[0] = ScummMidiRequest;
-		_stream_req[1] = (IOMidiRequest *) AllocVec(sizeof (IOMidiRequest), MEMF_PUBLIC);
-		_stream_buf[0] = AllocVec(BUFFER_SIZE, MEMF_PUBLIC);
-		_stream_buf[1] = AllocVec(BUFFER_SIZE, MEMF_PUBLIC);
-		_req_sent[0] = _req_sent[1] = false;
-
-		if (_stream_req[1] == NULL || _stream_buf[0] == NULL || _stream_buf[1] == NULL) {
-			close();
-			return MERR_DEVICE_NOT_AVAILABLE;
-		}
-
-		if (ScummMidiRequest)
-		{
-			memcpy(_stream_req[1], _stream_req[0], sizeof (IOMidiRequest));
-			struct TagItem MidiStreamTags[] = { { ESA_Callback, (ULONG) &midi_callback },
-															{ ESA_UserData, (ULONG) this },
-															{ ESA_TimeDiv, _time_div },
-															{ TAG_DONE, 0 }
-														 };
-			SetMidiStreamAttrsA(ScummMidiRequest, MidiStreamTags);
-			fill_all();
-		}
-	}
-
 	return 0;
 }
 
 void MidiDriver_ETUDE::close()
 {
-	if (_mode == MO_STREAMING) {
-		if (_req_sent[0]) {
-			AbortIO((IORequest *) _stream_req[0]);
-			WaitIO((IORequest *) _stream_req[0]);
-			_req_sent[0] = false;
-		}
-		if (_req_sent[1]) {
-			AbortIO((IORequest *) _stream_req[1]);
-			WaitIO((IORequest *) _stream_req[1]);
-			_req_sent[1] = false;
-		}
-
-		if (_stream_req[1]) FreeVec(_stream_req[1]);
-		if (_stream_buf[0]) FreeVec(_stream_buf[0]);
-		if (_stream_buf[1]) FreeVec(_stream_buf[1]);
-	}
-
 	exit_morphos_music();
-	_mode = 0;
+	_isOpen = false;
 }
 
 void MidiDriver_ETUDE::send(uint32 b)
 {
-	if (_mode != MO_SIMPLE)
-		error("MidiDriver_ETUDE::send called but driver is not in simple mode");
+	if (_isOpen)
+		error("MidiDriver_ETUDE::send called but driver was no opened");
 
 	if (ScummMidiRequest) {
 		ULONG midi_data = READ_LE_UINT32(&b);
@@ -174,103 +121,12 @@
 	}
 }
 
-void MidiDriver_ETUDE::midi_callback(ULONG msg, struct IOMidiRequest *req, APTR user_data)
-{
-	switch (msg) {
-		case ETUDE_STREAM_MSG_BLOCKEND: {
-			MidiDriver_ETUDE *md = ((MidiDriver_ETUDE *) user_data);
-			if (md && md->_mode)
-				md->fill_all();
-			break;
-		}
-	}
-}
-
-void MidiDriver_ETUDE::fill_all()
-{
-	if (_stream_proc == NULL) {
-		error("MidiDriver_ETUDE::fill_all() called, but _stream_proc == NULL");
-	}
-
-	uint buf;
-	MidiEvent my_evs[64];
-
-	for (buf = 0; buf < NUM_BUFFERS; buf++) {
-		if (!_req_sent[buf] || CheckIO((IORequest *) _stream_req[buf])) {
-			int num = _stream_proc(_stream_param, my_evs, 64);
-
-			if (_req_sent[buf]) {
-				WaitIO((IORequest *) _stream_req[buf]);
-				_req_sent[buf] = false;
-			}
-
-			/* end of stream? */
-			if (num == 0)
-				break;
-
-			MIDIEVENT *ev = (MIDIEVENT *) _stream_buf[buf];
-			MidiEvent *my_ev = my_evs;
-
-			for (int i = 0; i < num; i++, my_ev++) {
-				ev->me_StreamID = 0;
-				ev->me_DeltaTime = my_ev->delta;
-
-				switch (my_ev->event >> 24) {
-				case 0:
-					ev->me_Event = my_ev->event;
-					break;
-				case ME_TEMPO:
-					/* change tempo event */
-					ev->me_Event = (MEVT_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);
-			}
-
-			ConvertWindowsMidiStream(_stream_buf[buf], num * 12);
-
-			_stream_req[buf]->emr_Std.io_Command = CMD_WRITE;
-			_stream_req[buf]->emr_Std.io_Data = _stream_buf[buf];
-			_stream_req[buf]->emr_Std.io_Length = num * 12;
-		   SendIO((IORequest *) _stream_req[buf]);
-			_req_sent[buf] = true;
-		}
-	}
-}
-
-void MidiDriver_ETUDE::pause(bool p)
-{
-	if (_mode == MO_STREAMING && ScummMidiRequest) {
-		if (p)
-			PauseMidiStream(ScummMidiRequest);
-		else
-			RestartMidiStream(ScummMidiRequest);
-	}
-}
-
-uint32 MidiDriver_ETUDE::property(int prop, uint32 param)
-{
-	switch (prop) {
-		/* 16-bit time division according to standard midi specification */
-		case PROP_TIMEDIV:
-			_time_div = (uint16)param;
-			return 1;
-	}
-
-	return 0;
-}
-
-extern MidiDriver* EtudeMidiDriver;
+extern MidiDriver* EtudeMidiDriver = NULL;
 
 MidiDriver *MidiDriver_ETUDE_create()
 {
-	EtudeMidiDriver = new MidiDriver_ETUDE();
+	if (!EtudeMidiDriver)
+		EtudeMidiDriver = new MidiDriver_ETUDE();
 	return EtudeMidiDriver;
 }
 
@@ -280,39 +136,31 @@
 #define SEQ_MIDIPUTC    5
 #define SPECIAL_CHANNEL 9
 
-class MidiDriver_SEQ:public MidiDriver_MPU401 {
+class MidiDriver_SEQ : public MidiDriver_MPU401 {
 public:
 	MidiDriver_SEQ();
-	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:
-	StreamCallback *_stream_proc;
-	void *_stream_param;
-	int _mode;
+	bool _isOpen;
 	int device, _device_num;
 };
 
 MidiDriver_SEQ::MidiDriver_SEQ()
 {
-	_mode = 0;
+	_isOpen = false;
 	device = 0;
 	_device_num = 0;
 }
 
-int MidiDriver_SEQ::open(int mode)
+int MidiDriver_SEQ::open()
 {
-	if (_mode != 0)
+	if (_isOpen)
 		return MERR_ALREADY_OPEN;
+	_isOpen = true;
 	device = 0;
-	if (mode != MO_SIMPLE)
-		return MERR_STREAMING_NOT_AVAILABLE;
-
-	_mode = mode;
 
 	char *device_name = getenv("SCUMMVM_MIDI");
 	if (device_name != NULL) {
@@ -339,7 +187,7 @@
 void MidiDriver_SEQ::close()
 {
 	::close(device);
-	_mode = 0;
+	_isOpen = false;
 }
 
 
@@ -383,18 +231,6 @@
 		break;
 	}
 	write(device, buf, position);
-}
-
-void MidiDriver_SEQ::pause(bool p)
-{
-	if (_mode == MO_STREAMING) {
-	}
-}
-
-void MidiDriver_SEQ::set_stream_callback(void *param, StreamCallback *sc)
-{
-	_stream_param = param;
-	_stream_proc = sc;
 }
 
 MidiDriver *MidiDriver_SEQ_create()

Index: mididrv.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mididrv.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mididrv.h	8 Dec 2002 19:50:36 -0000	1.10
+++ mididrv.h	11 Dec 2002 16:09:56 -0000	1.11
@@ -36,19 +36,6 @@
 class MidiDriver {
 
 public:
-	/* called whenever the midi driver is in streaming mode,
-	 * and more midi commands need to be generated
-	 * return 0 to tell the mididriver that the end of stream was reached
-	 */
-	typedef int StreamCallback (void *param, MidiEvent * ev, int num);
-
-
-	/* open modes, pass one of those to open() */
-	enum {
-		MO_SIMPLE = 1,
-		MO_STREAMING = 2,
-	};
-
 	/* Special events that can be inserted in a MidiEvent.
 	 * event = (ME_xxx<<24) | <24-bit data associated with event>
 	 */
@@ -58,11 +45,11 @@
 	};
 
 	/* error codes returned by open.
-	 * can be converted to a string with get_error_name()
+	 * can be converted to a string with getErrorName()
 	 */
 	enum {
 		MERR_CANNOT_CONNECT = 1,
-		MERR_STREAMING_NOT_AVAILABLE = 2,
+//		MERR_STREAMING_NOT_AVAILABLE = 2,
 		MERR_DEVICE_NOT_AVAILABLE = 3,
 		MERR_ALREADY_OPEN = 4,
 	};
@@ -73,33 +60,21 @@
 	};
 
 
-	/* open the midi driver.
-	 * returns 0 if successful.
-	 * otherwise an error code. */
-	virtual int open(int mode) = 0;
+	// open the midi driver.
+	// returns 0 if successful, otherwise an error code.
+	virtual int open() = 0;
 
-	/* close the midi driver */
+	// close the midi driver
 	virtual void close() = 0;
 
-	/* output a packed midi command to the midi stream
-	 * valid only if mode is MO_SIMPLE
-	 */
+	// output a packed midi command to the midi stream
 	virtual void send(uint32 b) = 0;
 
-	/* set callback when more streams need to be generated.
-	 * valid only when mode==MO_STREAMING
-	 */
-	virtual void set_stream_callback(void *param, StreamCallback *sc) = 0;
-
-	/* Pause or resume streaming MIDI */
-	virtual void pause(bool pause) = 0;
-
-
 	/* Get or set a property */
 	virtual uint32 property(int prop, uint32 param);
 
 	/* retrieve a string representation of an error code */
-	static const char *get_error_name(int error_code);
+	static const char *getErrorName(int error_code);
 
 	// HIGH-LEVEL SEMANTIC METHODS
 	virtual void setPitchBendRange (byte channel, uint range)

Index: midistreamer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/midistreamer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- midistreamer.cpp	21 Nov 2002 19:26:44 -0000	1.4
+++ midistreamer.cpp	11 Dec 2002 16:09:57 -0000	1.5
@@ -27,7 +27,7 @@
 _target (target),
 _stream_proc (0),
 _stream_param (0),
-_mode (0),
+_isOpen (false),
 _paused (false),
 _event_count (0),
 _event_index (0),
@@ -41,7 +41,7 @@
 	_stream_param = param;
 	_stream_proc = sc;
 
-	if (_mode) {
+	if (_isOpen) {
 		_event_count = _stream_proc (_stream_param, _events, ARRAYSIZE (_events));
 		_event_index = 0;
 	}
@@ -80,23 +80,19 @@
 	} // end while
 }
 
-int MidiStreamer::open (int mode)
+int MidiStreamer::open()
 {
-	if (_mode != 0)
+	if (_isOpen)
 		close();
 
-	int res = _target->open (MidiDriver::MO_SIMPLE);
+	int res = _target->open();
 	if (res && res != MERR_ALREADY_OPEN)
 		return res;
 
 	_event_index = _event_count = _delay = 0;
-	_mode = mode;
+	_isOpen = true;
 	_paused = false;
 
-	if (mode == MO_SIMPLE)
-		return 0;
-
-//	g_system->create_thread (timer_thread, this);
 	_driver_tempo = _target->getBaseTempo() / 500;
 
 	_target->setTimerCallback (this, &timer_thread);
@@ -105,7 +101,7 @@
 
 void MidiStreamer::close()
 {
-	if (!_mode)
+	if (!_isOpen)
 		return;
 
 	_target->setTimerCallback (NULL, NULL);
@@ -116,7 +112,7 @@
 	for (i = 0; i < 16; ++i)
 		_target->send ((0x7B << 8) | 0xB0 | i);
 
-	_mode = 0;
+	_isOpen = false;
 	_paused = true;
 }
 

Index: midistreamer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/midistreamer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- midistreamer.h	26 Nov 2002 16:54:58 -0000	1.2
+++ midistreamer.h	11 Dec 2002 16:09:58 -0000	1.3
@@ -27,11 +27,19 @@
 #include "mididrv.h"
 
 class MidiStreamer : public MidiDriver {
+public:
+	/* called whenever the midi driver is in streaming mode,
+	 * and more midi commands need to be generated
+	 * return 0 to tell the mididriver that the end of stream was reached
+	 */
+	typedef int StreamCallback (void *param, MidiEvent * ev, int num);
+
 private:
+
 	MidiDriver *_target;
 	StreamCallback *_stream_proc;
 	void *_stream_param;
-	int _mode;
+	bool _isOpen;
 	bool _paused;
 
 	MidiEvent _events [64];
@@ -43,19 +51,21 @@
 	uint16 _ticks_per_beat;
 	long _delay;
 
-	uint32 property(int prop, uint32 param);
 	static void timer_thread (void *param);
 	void on_timer();
 
 public:
+
 	MidiStreamer (MidiDriver *target);
 
-	int open(int mode);
+	int open();
 	void close();
-	void send(uint32 b) { if (_mode) _target->send (b); }
+	void send(uint32 b) { if (_isOpen) _target->send (b); }
+	uint32 property(int prop, uint32 param);
+	void setPitchBendRange (byte channel, uint range) { _target->setPitchBendRange (channel, range); }
+
 	void pause(bool p) { _paused = p; }
 	void set_stream_callback(void *param, StreamCallback *sc);
-	void setPitchBendRange (byte channel, uint range) { _target->setPitchBendRange (channel, range); }
 
 	void setTimerCallback (void *timer_param, void (*timer_proc) (void *)) { }
 	uint32 getBaseTempo (void) { return _target->getBaseTempo(); }





More information about the Scummvm-git-logs mailing list