aboutsummaryrefslogtreecommitdiff
path: root/engines/glk
diff options
context:
space:
mode:
authorPaul Gilbert2018-12-07 21:52:24 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit3661fc61ec319752a767e5981581ded026a57dd1 (patch)
treef8fb4b8852a9c2576a728ef27298622de5556648 /engines/glk
parentf6abb3ea33c7b073066732f794a9d071c38a044d (diff)
downloadscummvm-rg350-3661fc61ec319752a767e5981581ded026a57dd1.tar.gz
scummvm-rg350-3661fc61ec319752a767e5981581ded026a57dd1.tar.bz2
scummvm-rg350-3661fc61ec319752a767e5981581ded026a57dd1.zip
GLK: Beginnings of Sounds manager
Diffstat (limited to 'engines/glk')
-rw-r--r--engines/glk/blorb.cpp4
-rw-r--r--engines/glk/glk.cpp9
-rw-r--r--engines/glk/glk.h2
-rw-r--r--engines/glk/glk_api.cpp12
-rw-r--r--engines/glk/glk_api.h1
-rw-r--r--engines/glk/glk_types.h2
-rw-r--r--engines/glk/module.mk1
-rw-r--r--engines/glk/sound.cpp72
-rw-r--r--engines/glk/sound.h87
9 files changed, 176 insertions, 14 deletions
diff --git a/engines/glk/blorb.cpp b/engines/glk/blorb.cpp
index 038a79e046..5ffd0b03b0 100644
--- a/engines/glk/blorb.cpp
+++ b/engines/glk/blorb.cpp
@@ -146,7 +146,7 @@ Common::ErrorCode Blorb::load() {
ce._filename += ".rect";
} else if (ce._type == ID_Snd) {
- ce._filename = Common::String::format("snd%u", ce._number);
+ ce._filename = Common::String::format("sound%u", ce._number);
if (ce._id == ID_MIDI)
ce._filename += ".midi";
else if (ce._id == ID_MP3)
@@ -156,7 +156,7 @@ Common::ErrorCode Blorb::load() {
else if (ce._id == ID_AIFF)
ce._filename += ".aiff";
else if (ce._id == ID_OGG)
- ce._filename += ".ogg";
+ ce._filename += ".ogg";
else if (ce._id == ID_MOD)
ce._filename += ".mod";
diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp
index a22f9e9aca..c8a63c5bd3 100644
--- a/engines/glk/glk.cpp
+++ b/engines/glk/glk.cpp
@@ -35,6 +35,7 @@
#include "glk/picture.h"
#include "glk/screen.h"
#include "glk/selection.h"
+#include "glk/sound.h"
#include "glk/streams.h"
#include "glk/windows.h"
@@ -45,9 +46,9 @@ GlkEngine *g_vm;
GlkEngine::GlkEngine(OSystem *syst, const GlkGameDescription &gameDesc) :
_gameDescription(gameDesc), Engine(syst), _random("Glk"), _blorb(nullptr),
_clipboard(nullptr), _conf(nullptr), _events(nullptr), _pictures(nullptr),
- _screen(nullptr), _selection(nullptr), _windows(nullptr), _copySelect(false),
- _terminated(false), gli_unregister_obj(nullptr), gli_register_arr(nullptr),
- gli_unregister_arr(nullptr) {
+ _screen(nullptr), _selection(nullptr), _sounds(nullptr), _windows(nullptr),
+ _copySelect(false), _terminated(false), gli_unregister_obj(nullptr),
+ gli_register_arr(nullptr), gli_unregister_arr(nullptr) {
g_vm = this;
}
@@ -59,6 +60,7 @@ GlkEngine::~GlkEngine() {
delete _pictures;
delete _screen;
delete _selection;
+ delete _sounds;
delete _streams;
delete _windows;
}
@@ -79,6 +81,7 @@ void GlkEngine::initialize() {
_events = new Events();
_pictures = new Pictures();
_selection = new Selection();
+ _sounds = new Sounds();
_streams = new Streams();
_windows = new Windows(_screen);
}
diff --git a/engines/glk/glk.h b/engines/glk/glk.h
index 923e29587f..91702c56be 100644
--- a/engines/glk/glk.h
+++ b/engines/glk/glk.h
@@ -41,6 +41,7 @@ class Events;
class Pictures;
class Screen;
class Selection;
+class Sounds;
class Streams;
class Windows;
@@ -107,6 +108,7 @@ public:
Screen *_screen;
Selection *_selection;
Streams *_streams;
+ Sounds *_sounds;
Windows *_windows;
bool _copySelect;
bool _terminated;
diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp
index 32d6177f9a..11047893ef 100644
--- a/engines/glk/glk_api.cpp
+++ b/engines/glk/glk_api.cpp
@@ -24,6 +24,7 @@
#include "glk/conf.h"
#include "glk/events.h"
#include "glk/picture.h"
+#include "glk/sound.h"
#include "glk/streams.h"
#include "glk/unicode.h"
#include "glk/windows.h"
@@ -970,22 +971,19 @@ void GlkAPI::glk_window_set_background_color(winid_t win, glui32 color) {
}
schanid_t GlkAPI::glk_schannel_create(glui32 rock) {
- // TODO
- return nullptr;
+ return _sounds->create(rock);
}
void GlkAPI::glk_schannel_destroy(schanid_t chan) {
- // TODO
+ delete chan;
}
schanid_t GlkAPI::glk_schannel_iterate(schanid_t chan, glui32 *rockptr) {
- // TODO
- return nullptr;
+ return _sounds->iterate(chan, rockptr);
}
glui32 GlkAPI::glk_schannel_get_rock(schanid_t chan) {
- // TODO
- return 0;
+ return chan->_rock;
}
glui32 GlkAPI::glk_schannel_play(schanid_t chan, glui32 snd) {
diff --git a/engines/glk/glk_api.h b/engines/glk/glk_api.h
index 3081ac2b27..2dd2501f72 100644
--- a/engines/glk/glk_api.h
+++ b/engines/glk/glk_api.h
@@ -26,6 +26,7 @@
#include "glk/glk.h"
#include "glk/glk_types.h"
#include "glk/blorb.h"
+#include "glk/sound.h"
#include "glk/time.h"
#include "glk/windows.h"
diff --git a/engines/glk/glk_types.h b/engines/glk/glk_types.h
index 81a36d8108..abae785ae8 100644
--- a/engines/glk/glk_types.h
+++ b/engines/glk/glk_types.h
@@ -68,8 +68,6 @@ enum InterpreterType {
#define GLK_MODULE_DATETIME
#define GLK_MODULE_GARGLKTEXT
-typedef struct glk_schannel_struct *schanid_t;
-
/**
* Usurp C1 space for ligatures and smart typography glyphs
*/
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index c09bfac6cc..de69645db5 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -11,6 +11,7 @@ MODULE_OBJS := \
raw_decoder.o \
screen.o \
selection.o \
+ sound.o \
streams.o \
time.o \
unicode.o \
diff --git a/engines/glk/sound.cpp b/engines/glk/sound.cpp
new file mode 100644
index 0000000000..5c98b93e09
--- /dev/null
+++ b/engines/glk/sound.cpp
@@ -0,0 +1,72 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software{} you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation{} either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY{} without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program{} if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "glk/sound.h"
+
+namespace Glk {
+
+Sounds::~Sounds() {
+ for (int idx = (int)_sounds.size() - 1; idx >= 0; --idx)
+ delete _sounds[idx];
+}
+
+void Sounds::removeSound(schanid_t snd) {
+ for (uint idx = 0; idx < _sounds.size(); ++idx) {
+ if (_sounds[idx] == snd) {
+ _sounds.remove_at(idx);
+ break;
+ }
+ }
+}
+
+schanid_t Sounds::create(glui32 rock) {
+ schanid_t snd = new SoundChannel();
+ _sounds.push_back(snd);
+ return snd;
+}
+
+schanid_t Sounds::iterate(schanid_t chan, glui32 *rockptr) {
+ for (int idx = 0; idx < (int)_sounds.size() - 1; ++idx) {
+ if (_sounds[idx] == chan) {
+ schanid_t next = _sounds[idx + 1];
+ if (*rockptr)
+ *rockptr = next->_rock;
+
+ return next;
+ }
+ }
+
+ return nullptr;
+}
+
+/*--------------------------------------------------------------------------*/
+
+SoundChannel::~SoundChannel() {
+ _owner->removeSound(this);
+ delete _stream;
+}
+
+void SoundChannel::play(uint soundNum) {
+ // TODO
+}
+
+} // End of namespace Glk
diff --git a/engines/glk/sound.h b/engines/glk/sound.h
new file mode 100644
index 0000000000..05875eaa32
--- /dev/null
+++ b/engines/glk/sound.h
@@ -0,0 +1,87 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef GLK_SOUND_H
+#define GLK_SOUND_H
+
+#include "glk/glk_types.h"
+#include "audio/audiostream.h"
+#include "common/array.h"
+
+namespace Glk {
+
+class Sounds;
+
+/**
+ * Holds the data for a playing sound
+ */
+struct SoundChannel {
+ Sounds *_owner;
+ Audio::AudioStream *_stream;
+ glui32 _rock;
+
+ /**
+ * Destructor
+ */
+ SoundChannel() : _stream(nullptr), _rock(0) {}
+
+ /**
+ * Destructor
+ */
+ ~SoundChannel();
+
+ /**
+ * Play a sound
+ */
+ void play(uint soundNum);
+};
+typedef SoundChannel *schanid_t;
+
+/**
+ * Sound manager
+ */
+class Sounds {
+ friend struct SoundChannel;
+private:
+ Common::Array<schanid_t> _sounds;
+private:
+ /**
+ * Remove a sound from the sounds list
+ */
+ void removeSound(schanid_t snd);
+public:
+ ~Sounds();
+
+ /**
+ * Create a new channel
+ */
+ schanid_t create(glui32 rock = 0);
+
+ /**
+ * Used to iterate over the current list of sound channels
+ */
+ schanid_t iterate(schanid_t chan, glui32 *rockptr = nullptr);
+};
+
+} // End of namespace Glk
+
+#endif