aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/sfx/device.h98
-rw-r--r--engines/sci/sfx/seq/instrument-map.cpp33
-rw-r--r--engines/sci/sfx/seq/map-mt32-to-gm.cpp8
3 files changed, 65 insertions, 74 deletions
diff --git a/engines/sci/sfx/device.h b/engines/sci/sfx/device.h
index c7a87a2afd..c27dcb9cb5 100644
--- a/engines/sci/sfx/device.h
+++ b/engines/sci/sfx/device.h
@@ -55,60 +55,54 @@ struct _midi_device {
*/
};
-// 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
+ */
+
+ 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
*/
-typedef struct _midi_writer {
- MIDI_WRITER_BODY
-} midi_writer_t;
+ 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);
diff --git a/engines/sci/sfx/seq/instrument-map.cpp b/engines/sci/sfx/seq/instrument-map.cpp
index 40079e4d22..4fd3094745 100644
--- a/engines/sci/sfx/seq/instrument-map.cpp
+++ b/engines/sci/sfx/seq/instrument-map.cpp
@@ -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 @@ sfx_instrument_map_free(sfx_instrument_map_t *map) {
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 @@ patch001_type0_length(byte *data, size_t length) {
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 @@ sfx_instrument_map_load_sci(byte *data, size_t size) {
/* 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 @@ close_decorated(decorated_midi_writer_t *self) {
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 @@ write_decorated(decorated_midi_writer_t *self, byte *buf, int len) {
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 @@ init(midi_writer_t *writer, byte *data, size_t len) {
args = 2;
}
- if (args > len - offset) {
+ if (args + offset > len) {
fprintf(stderr, "[instrument-map] Insufficient bytes remaining for MIDI command %02x\n", op);
return;
}
diff --git a/engines/sci/sfx/seq/map-mt32-to-gm.cpp b/engines/sci/sfx/seq/map-mt32-to-gm.cpp
index 10ba4bdbc5..83bfd444f9 100644
--- a/engines/sci/sfx/seq/map-mt32-to-gm.cpp
+++ b/engines/sci/sfx/seq/map-mt32-to-gm.cpp
@@ -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 {