1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /*************************************
24  *
25  * USED IN:
26  * Meet MediaBand
27  *
28  *************************************/
29 
30 /*
31 	-- SoundJam Copyright © Canter Technology 1995
32 	SoundJam
33 	II   mNew, numberOfChannels
34 	ISI  mDefineFileSound, fullPathName, numberOfBeats
35 	III  mDefineCastSound, castMemberNumber, numberOfBeats
36 	II   mUndefineSound, soundID
37 	III  mReadSome, soundID, byteCount
38 	II   mStartSound, soundID
39 	II   mSwitchNew, soundID
40 	II   mSwitchParallel, soundID
41 	I    mHasSwitchHappened
42 	X    mToggleMute
43 	X    mStop
44 	X    mDispose
45 */
46 
47 #include "director/director.h"
48 #include "director/window.h"
49 #include "director/sound.h"
50 #include "director/lingo/lingo.h"
51 #include "director/lingo/lingo-object.h"
52 #include "director/lingo/lingo-utils.h"
53 #include "director/lingo/xlibs/soundjam.h"
54 
55 namespace Director {
56 
57 const char *SoundJam::xlibName = "SoundJam";
58 const char *SoundJam::fileNames[] = {
59 	"SoundJam",
60 	0
61 };
62 
63 const int kJamChannel = 3;
64 
65 static MethodProto xlibMethods[] = {
66 	{ "new",				SoundJam::m_new,			 1, 1,	400 },
67 	{ "defineFileSound",	SoundJam::m_defineFileSound, 2, 2,	400 },
68 	{ "defineCastSound",	SoundJam::m_defineCastSound, 2, 2,	400 },
69 	{ "undefineSound",		SoundJam::m_undefineSound,	 1, 1,	400 },
70 	{ "readSome",			SoundJam::m_readSome,		 2, 2,	400 },
71 	{ "startSound",			SoundJam::m_startSound,		 1, 1,	400 },
72 	{ "switchNew",			SoundJam::m_switchNew,		 1, 1,	400 },
73 	{ "switchParallel",		SoundJam::m_switchParallel,	 1, 1,	400 },
74 	{ "hasSwitchHappened",	SoundJam::m_hasSwitchHappened, 0, 0, 400 },
75 	{ "toggleMute",			SoundJam::m_toggleMute,		 0, 0,	400 },
76 	{ "stop",				SoundJam::m_stop,			 0, 0,	400 },
77 	{ 0, 0, 0, 0, 0 }
78 };
79 
open(int type)80 void SoundJam::open(int type) {
81 	if (type == kXObj) {
82 		SoundJamObject::initMethods(xlibMethods);
83 		SoundJamObject *xobj = new SoundJamObject(kXObj);
84 		g_lingo->_globalvars[xlibName] = xobj;
85 	}
86 }
87 
close(int type)88 void SoundJam::close(int type) {
89 	if (type == kXObj) {
90 		SoundJamObject::cleanupMethods();
91 		g_lingo->_globalvars[xlibName] = Datum();
92 	}
93 }
94 
SoundJamObject(ObjectType objType)95 SoundJamObject::SoundJamObject(ObjectType objType) : Object<SoundJamObject>("SoundJam") {
96 	_objType = objType;
97 }
98 
m_new(int nargs)99 void SoundJam::m_new(int nargs) {
100 	int numberOfChannels = g_lingo->pop().asInt();
101 
102 	if (numberOfChannels != 1) {
103 		warning("SoundJam::m_new: Expected numberOfChannels = 1, got %d", numberOfChannels);
104 		g_lingo->push(Datum());
105 		return;
106 	}
107 
108 	g_lingo->push(g_lingo->_currentMe);
109 }
110 
m_defineFileSound(int nargs)111 void SoundJam::m_defineFileSound(int nargs) {
112 	g_lingo->printSTUBWithArglist("SoundJam::m_defineFileSound", nargs);
113 	g_lingo->dropStack(nargs);
114 	g_lingo->push(Datum());
115 }
116 
m_defineCastSound(int nargs)117 void SoundJam::m_defineCastSound(int nargs) {
118 	SoundJamObject *me = static_cast<SoundJamObject *>(g_lingo->_currentMe.u.obj);
119 
120 	/* Datum numberOfBeats = */ g_lingo->pop();
121 	CastMemberID castMemberNumber = g_lingo->pop().asMemberID();
122 
123 	int soundID = 0;
124 	while (me->_soundMap.contains(soundID))
125 		soundID++;
126 
127 	me->_soundMap[soundID] = castMemberNumber;
128 
129 	g_lingo->push(soundID);
130 }
131 
m_undefineSound(int nargs)132 void SoundJam::m_undefineSound(int nargs) {
133 	SoundJamObject *me = static_cast<SoundJamObject *>(g_lingo->_currentMe.u.obj);
134 	int soundID = g_lingo->pop().asInt();
135 
136 	if (soundID < 0) {
137 		g_lingo->push(0); // success
138 		return;
139 	}
140 
141 	if (!me->_soundMap.contains(soundID)) {
142 		warning("SoundJam::m_undefineSound: Sound %d is not defined", soundID);
143 		g_lingo->push(-1); // error
144 		return;
145 	}
146 
147 	me->_soundMap.erase(soundID);
148 	g_lingo->push(0); // success
149 }
150 
m_readSome(int nargs)151 void SoundJam::m_readSome(int nargs) {
152 	g_lingo->printSTUBWithArglist("SoundJam::m_readSome", nargs);
153 	g_lingo->dropStack(nargs);
154 	g_lingo->push(Datum());
155 }
156 
m_startSound(int nargs)157 void SoundJam::m_startSound(int nargs) {
158 	g_lingo->printSTUBWithArglist("SoundJam::m_startSound", nargs);
159 	g_lingo->dropStack(nargs);
160 	g_lingo->push(Datum());
161 }
162 
m_switchNew(int nargs)163 void SoundJam::m_switchNew(int nargs) {
164 	SoundJamObject *me = static_cast<SoundJamObject *>(g_lingo->_currentMe.u.obj);
165 	int soundID = g_lingo->pop().asInt();
166 
167 	if (!me->_soundMap.contains(soundID)) {
168 		warning("SoundJam::m_switchNew: Sound %d is not defined", soundID);
169 		g_lingo->push(-1); // error
170 		return;
171 	}
172 
173 	DirectorSound *sound = g_director->getCurrentWindow()->getSoundManager();
174 	sound->setPuppetSound(me->_soundMap[soundID], kJamChannel);
175 	sound->playPuppetSound(kJamChannel);
176 	g_lingo->push(0); // success
177 }
178 
m_switchParallel(int nargs)179 void SoundJam::m_switchParallel(int nargs) {
180 	g_lingo->printSTUBWithArglist("SoundJam::m_switchParallel", nargs);
181 	g_lingo->dropStack(nargs);
182 	g_lingo->push(Datum());
183 }
184 
m_hasSwitchHappened(int nargs)185 void SoundJam::m_hasSwitchHappened(int nargs) {
186 	g_lingo->printSTUBWithArglist("SoundJam::m_hasSwitchHappened", nargs);
187 	g_lingo->dropStack(nargs);
188 	g_lingo->push(Datum());
189 }
190 
m_toggleMute(int nargs)191 void SoundJam::m_toggleMute(int nargs) {
192 	g_lingo->printSTUBWithArglist("SoundJam::m_toggleMute", nargs);
193 	g_lingo->dropStack(nargs);
194 }
195 
m_stop(int nargs)196 void SoundJam::m_stop(int nargs) {
197 	DirectorSound *sound = g_director->getCurrentWindow()->getSoundManager();
198 	sound->setPuppetSound(SoundID(), kJamChannel);
199 	sound->playPuppetSound(kJamChannel);
200 }
201 
202 } // End of namespace Director
203 
204