[Scummvm-cvs-logs] SF.net SVN: scummvm:[38755] scummvm/trunk/engines/sci/sfx

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Feb 21 23:14:26 CET 2009


Revision: 38755
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38755&view=rev
Author:   fingolfin
Date:     2009-02-21 22:14:26 +0000 (Sat, 21 Feb 2009)

Log Message:
-----------
SCI: Replaced evil MIDI_WRITER_BODY with C++ subclassing; some compile fixes to currently unused files

Modified Paths:
--------------
    scummvm/trunk/engines/sci/sfx/device.h
    scummvm/trunk/engines/sci/sfx/seq/instrument-map.cpp
    scummvm/trunk/engines/sci/sfx/seq/map-mt32-to-gm.cpp

Modified: scummvm/trunk/engines/sci/sfx/device.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/device.h	2009-02-21 22:13:59 UTC (rev 38754)
+++ scummvm/trunk/engines/sci/sfx/device.h	2009-02-21 22:14:26 UTC (rev 38755)
@@ -55,62 +55,56 @@
 	*/
 };
 
-// FIXME: This evil hack below is needed to create the
-// decorated_midi_writer struct in instrumen-map.c -- in C++, this can
-// be replaced by simple subclassing.
-#define MIDI_WRITER_BODY	\
-	char *name; /* Name description of the device */		\
-									\
-	int (*init)(struct _midi_writer *self);				\
-	/* Initializes the writer					\
-	** Parameters: (midi_writer_t *) self: Self reference		\
-	** Returns   : (int) SFX_OK on success, SFX_ERROR if the device could not be \
-	**                   opened					\
-	*/								\
-									\
-	int (*set_option)(struct _midi_writer *self, char *name, char *value); \
-	/* Sets an option for the writer				\
-	** Parameters: (char *) name: Name of the option to set		\
-	**             (char *) value: Value of the option to set	\
-	** Returns   : (int) SFX_OK on success, SFX_ERROR otherwise (unsupported option) \
-	*/								\
-									\
-	int (*write)(struct _midi_writer *self, unsigned char *buf, int len); \
-	/* Writes some bytes to the MIDI stream				\
-	** Parameters: (char *) buf: The buffer to write		\
-	**             (int) len: Number of bytes to write		\
-	** Returns   : (int) SFX_OK on success, SFX_ERROR on failure	\
-	** No delta time is expected here.				\
-	*/								\
-									\
-	void (*delay)(struct _midi_writer *self, int ticks);		\
-	/* Introduces an explicit delay					\
-	** Parameters: (int) ticks: Number of 60 Hz ticks to sleep	\
-	*/								\
-									\
-	void (*flush)(struct _midi_writer *self); /* May be NULL */	\
-	/* Flushes the MIDI file descriptor				\
-	** Parameters: (midi_writer_t *) self: Self reference		\
-	*/								\
-									\
-	void (*reset_timer)(struct _midi_writer *self);			\
-	/* Resets the timer associated with this device			\
-	** Parameters: (midi_writer_t *) self: Self reference		\
-	** This function makes sure that a subsequent write would have effect \
-	** immediately, and any delay() would be relative to the point in time \
-	** this function was invoked at.				\
-	*/								\
-									\
-	void (*close)(struct _midi_writer *self);			\
-	/* Closes the associated MIDI device				\
-	** Parameters: (midi_writer_t *) self: Self reference		\
+struct midi_writer_t {
+	char *name; /* Name description of the device */
+
+	int (*init)(midi_writer_t *self);
+	/* Initializes the writer
+	** Parameters: (midi_writer_t *) self: Self reference
+	** Returns   : (int) SFX_OK on success, SFX_ERROR if the device could not be
+	**                   opened
 	*/
 
-typedef struct _midi_writer {
-	MIDI_WRITER_BODY
-} midi_writer_t;
+	int (*set_option)(midi_writer_t *self, char *name, char *value);
+	/* Sets an option for the writer
+	** Parameters: (char *) name: Name of the option to set
+	**             (char *) value: Value of the option to set
+	** Returns   : (int) SFX_OK on success, SFX_ERROR otherwise (unsupported option)
+	*/
 
+	int (*write)(midi_writer_t *self, unsigned char *buf, int len);
+	/* Writes some bytes to the MIDI stream
+	** Parameters: (char *) buf: The buffer to write
+	**             (int) len: Number of bytes to write
+	** Returns   : (int) SFX_OK on success, SFX_ERROR on failure
+	** No delta time is expected here.
+	*/
 
+	void (*delay)(midi_writer_t *self, int ticks);
+	/* Introduces an explicit delay
+	** Parameters: (int) ticks: Number of 60 Hz ticks to sleep
+	*/
+
+	void (*flush)(midi_writer_t *self); /* May be NULL */
+	/* Flushes the MIDI file descriptor
+	** Parameters: (midi_writer_t *) self: Self reference
+	*/
+
+	void (*reset_timer)(midi_writer_t *self);
+	/* Resets the timer associated with this device
+	** Parameters: (midi_writer_t *) self: Self reference
+	** This function makes sure that a subsequent write would have effect
+	** immediately, and any delay() would be relative to the point in time
+	** this function was invoked at.
+	*/
+
+	void (*close)(midi_writer_t *self);
+	/* Closes the associated MIDI device
+	** Parameters: (midi_writer_t *) self: Self reference
+	*/
+};
+
+
 void *sfx_find_device(int type, char *name);
 /* Looks up a device by name
 ** Parameters: (int) type: Device type to look up

Modified: scummvm/trunk/engines/sci/sfx/seq/instrument-map.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/seq/instrument-map.cpp	2009-02-21 22:13:59 UTC (rev 38754)
+++ scummvm/trunk/engines/sci/sfx/seq/instrument-map.cpp	2009-02-21 22:14:26 UTC (rev 38755)
@@ -23,11 +23,11 @@
  *
  */
 
-#include <assert.h>
-#include "sci_midi.h"
-#include "sci_memory.h"
-#include "instrument-map.h"
-#include "sfx_engine.h"
+#include "common/scummsys.h"
+#include "sci/include/sci_midi.h"
+#include "sci/include/sci_memory.h"
+#include "sci/sfx/seq/instrument-map.h"
+#include "sci/sfx/sfx_engine.h"
 
 namespace Sci {
 
@@ -75,17 +75,17 @@
 	if (map->velocity_map) {
 		int i;
 		for (i = 0; i < map->velocity_maps_nr; i++)
-			sci_free(map->velocity_map[i]);
-		sci_free(map->velocity_map);
+			free(map->velocity_map[i]);
+		free(map->velocity_map);
 		map->velocity_map = NULL;
 	}
 
 	if (map->initialisation_block) {
-		sci_free(map->initialisation_block);
+		free(map->initialisation_block);
 		map->initialisation_block = NULL;
 	}
 
-	sci_free(map);
+	free(map);
 }
 
 #define PATCH_MAP_OFFSET		0x0000
@@ -127,7 +127,7 @@
 
 static int
 patch001_type1_length(byte *data, size_t length) {
-	if ((length >= 1155) && (((data[1154] << 8) + data[1153] + 1155) == length))
+	if ((length >= 1155) && (((data[1154] << 8) + data[1153] + 1155) == (int)length))
 		return 1;
 	return 0;
 }
@@ -213,10 +213,7 @@
 /* Output with the instrument map */
 #define MIDI_CHANNELS_NR 0x10
 
-// FIXME: Replace this ugly hack with simple subclassing once converting to C++
-struct decorated_midi_writer_t {
-	MIDI_WRITER_BODY
-
+struct decorated_midi_writer_t : public midi_writer_t {
 	midi_writer_t *writer;
 	sfx_patch_map_t patches[MIDI_CHANNELS_NR];
 	sfx_instrument_map_t *map;
@@ -260,9 +257,9 @@
 	sfx_instrument_map_free(self->map);
 	self->map = NULL;
 	self->writer->close(self->writer);
-	sci_free((void *)self->name);
+	free((void *)self->name);
 	self->name = NULL;
-	sci_free(self);
+	free(self);
 }
 
 #define BOUND_127(x) (((x) < 0)? 0 : (((x) > 0x7f)? 0x7f : (x)))
@@ -428,7 +425,7 @@
 
 static void
 init(midi_writer_t *writer, byte *data, size_t len) {
-	int offset = 0;
+	size_t offset = 0;
 	byte status = 0;
 
 	/* Send init data as separate MIDI commands */
@@ -474,7 +471,7 @@
 			args = 2;
 		}
 
-		if (args > len - offset) {
+		if (args + offset > len) {
 			fprintf(stderr, "[instrument-map] Insufficient bytes remaining for MIDI command %02x\n", op);
 			return;
 		}

Modified: scummvm/trunk/engines/sci/sfx/seq/map-mt32-to-gm.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/seq/map-mt32-to-gm.cpp	2009-02-21 22:13:59 UTC (rev 38754)
+++ scummvm/trunk/engines/sci/sfx/seq/map-mt32-to-gm.cpp	2009-02-21 22:14:26 UTC (rev 38755)
@@ -23,10 +23,10 @@
  *
  */
 
-#include <sciresource.h>
-#include <engine.h>
-#include <stdarg.h>
-#include "instrument-map.h"
+#include "common/scummsys.h"
+#include "sci/include/sciresource.h"
+#include "sci/include/engine.h"
+#include "sci/sfx/seq/instrument-map.h"
 
 namespace Sci {
 


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