Oolite
Loading...
Searching...
No Matches
OOJSSoundSource.m File Reference
import "OOJSSound.h"
import "OOJSVector.h"
import "OOJavaScriptEngine.h"
import "OOSound.h"
import "ResourceManager.h"
Include dependency graph for OOJSSoundSource.m:

Go to the source code of this file.

Enumerations

enum  {
  kSoundSource_sound , kSoundSource_isPlaying , kSoundSource_loop , kSoundSource_position ,
  kSoundSource_positional , kSoundSource_repeatCount , kSoundSource_volume
}

Functions

static JSBool SoundSourceGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SoundSourceSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool SoundSourceConstruct (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundSourcePlay (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundSourceStop (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundSourcePlayOrRepeat (JSContext *context, uintN argc, jsval *vp)
void InitOOJSSoundSource (JSContext *context, JSObject *global)

Variables

static JSObject * sSoundSourcePrototype
static JSClass sSoundSourceClass
static JSPropertySpec sSoundSourceProperties []
static JSFunctionSpec sSoundSourceMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSoundSource_sound 
kSoundSource_isPlaying 
kSoundSource_loop 
kSoundSource_position 
kSoundSource_positional 
kSoundSource_repeatCount 
kSoundSource_volume 

Definition at line 57 of file OOJSSoundSource.m.

57 {
58 // Property IDs
66};
@ kSoundSource_loop
@ kSoundSource_positional
@ kSoundSource_volume
@ kSoundSource_position
@ kSoundSource_sound
@ kSoundSource_repeatCount
@ kSoundSource_isPlaying

Function Documentation

◆ InitOOJSSoundSource()

void InitOOJSSoundSource ( JSContext * context,
JSObject * global )

Definition at line 110 of file OOJSSoundSource.m.

111{
112 sSoundSourcePrototype = JS_InitClass(context, global, NULL, &sSoundSourceClass, SoundSourceConstruct, 0, sSoundSourceProperties, sSoundSourceMethods, NULL, NULL);
114}
static JSBool SoundSourceConstruct(JSContext *context, uintN argc, jsval *vp)
static JSClass sSoundSourceClass
static JSFunctionSpec sSoundSourceMethods[]
static JSObject * sSoundSourcePrototype
static JSPropertySpec sSoundSourceProperties[]
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References InitOOJSSoundSource(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), SoundSourceConstruct(), sSoundSourceClass, sSoundSourceMethods, sSoundSourceProperties, and sSoundSourcePrototype.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, InitOOJSSoundSource(), and InitOOJSSoundSource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SoundSourceConstruct()

JSBool SoundSourceConstruct ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 116 of file OOJSSoundSource.m.

117{
118 OOJS_NATIVE_ENTER(context)
119
120 if (EXPECT_NOT(!JS_IsConstructing(context, vp))) {
121 OOJSReportError(context, @"SoundSource() cannot be called as a function, it must be used as a constructor (as in new SoundSource()).");
122 return NO;
123 }
124
125 OOJS_RETURN_OBJECT([[[OOSoundSource alloc] init] autorelease]);
126
128}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_OBJECT(o)
void OOJSReportError(JSContext *context, NSString *format,...)

References EXPECT_NOT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJSReportError().

Referenced by InitOOJSSoundSource(), and InitOOJSSoundSource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SoundSourceGetProperty()

JSBool SoundSourceGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 132 of file OOJSSoundSource.m.

133{
134 if (!JSID_IS_INT(propID))
135 return YES;
136
137 OOJS_NATIVE_ENTER(context)
138
139 OOSoundSource* soundSource = nil;
140
141 if (!JSSoundSourceGetSoundSource(context, this, &soundSource))
142 return NO;
143
144 switch (JSID_TO_INT(propID)) {
146 *value = OOJSValueFromNativeObject(context, [soundSource sound]);
147 return YES;
148
150 *value = OOJSValueFromBOOL([soundSource isPlaying]);
151 return YES;
152
154 *value = OOJSValueFromBOOL([soundSource loop]);
155 return YES;
156
158 *value = INT_TO_JSVAL([soundSource repeatCount]);
159 return YES;
160
162 return VectorToJSValue(context, [soundSource position], value);
163
165 *value = OOJSValueFromBOOL([soundSource positional]);
166 return YES;
167
169 return JS_NewNumberValue(context, [soundSource gain], value);
170
171 default:
173 return NO;
174 }
175
177}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
return nil

References kSoundSource_isPlaying, kSoundSource_loop, kSoundSource_position, kSoundSource_positional, kSoundSource_repeatCount, kSoundSource_sound, kSoundSource_volume, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), sSoundSourceProperties, and VectorToJSValue().

Here is the call graph for this function:

◆ SoundSourcePlay()

JSBool SoundSourcePlay ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 255 of file OOJSSoundSource.m.

256{
257 OOJS_NATIVE_ENTER(context)
258
259 OOSoundSource* thisv = nil;
260 int32 count = 0;
261
262 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
263 return NO;
264 if (argc > 0 && !JSVAL_IS_VOID(OOJS_ARGV[0]) && !JS_ValueToInt32(context, OOJS_ARGV[0], &count)) {
265 OOJSReportBadArguments(context, @"SoundSource", @"play", 1, OOJS_ARGV, nil, @"integer count or no argument");
266 return NO;
267 }
268
269 if (count > 0) {
270 if (count > 100)
271 count = 100;
272 [thisv setRepeatCount:count];
273 }
274
276 [thisv play];
278
280
282}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_THIS
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_VOID
unsigned count
void setRepeatCount:(uint8_t inCount)

References count, EXPECT_NOT, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSReportBadArguments(), OOSoundSource::play, and OOSoundSource::setRepeatCount:.

Here is the call graph for this function:

◆ SoundSourcePlayOrRepeat()

JSBool SoundSourcePlayOrRepeat ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 304 of file OOJSSoundSource.m.

305{
306 OOJS_NATIVE_ENTER(context)
307
308 OOSoundSource* thisv = nil;
309
310 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
311 return NO;
312
314 [thisv playOrRepeat];
316
318
320}

References EXPECT_NOT, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, and OOSoundSource::playOrRepeat.

Here is the call graph for this function:

◆ SoundSourceSetProperty()

JSBool SoundSourceSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 179 of file OOJSSoundSource.m.

180{
181 if (!JSID_IS_INT(propID))
182 return YES;
183
184 OOJS_NATIVE_ENTER(context)
185
186 OOSoundSource* soundSource = nil;
187 int32 iValue;
188 JSBool bValue;
189 Vector vValue;
190 double fValue;
191
192 if (!JSSoundSourceGetSoundSource(context, this, &soundSource))
193 return NO;
194
195 switch (JSID_TO_INT(propID)) {
197 [soundSource setSound:SoundFromJSValue(context, *value)];
198 return YES;
199 break;
200
202 if (JS_ValueToBoolean(context, *value, &bValue)) {
203 [soundSource setLoop:bValue];
204 return YES;
205 }
206 break;
207
209 if (JS_ValueToInt32(context, *value, &iValue)) {
210 if (iValue > 100)
211 iValue = 100;
212 if (100 < 1)
213 iValue = 1;
214 [soundSource setRepeatCount:iValue];
215 return YES;
216 }
217 break;
218
220 if (JSValueToVector(context, *value, &vValue)) {
221 [soundSource setPosition:vValue];
222 return YES;
223 }
224 break;
225
227 if (JS_ValueToBoolean(context, *value, &bValue)) {
228 [soundSource setPositional:bValue];
229 return YES;
230 }
231 break;
232
234 if (JS_ValueToNumber(context, *value, &fValue)) {
235 fValue = OOClamp_0_max_d(fValue, 1);
236 [soundSource setGain:fValue];
237 return YES;
238 }
239 break;
240
241 default:
243 return NO;
244 }
245
246 OOJSReportBadPropertyValue(context, this, propID, sSoundSourceProperties, *value);
247 return NO;
248
250}
OOINLINE double OOClamp_0_max_d(double value, double max) INLINE_CONST_FUNC
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void setPositional:(BOOL inPositional)
void setLoop:(BOOL inLoop)
void setGain:(float gain)
void setPosition:(Vector inPosition)
void setSound:(OOSound *inSound)

References JSValueToVector(), kSoundSource_loop, kSoundSource_position, kSoundSource_positional, kSoundSource_repeatCount, kSoundSource_sound, kSoundSource_volume, nil, OOClamp_0_max_d(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOSoundSource::setGain:, OOSoundSource::setLoop:, OOSoundSource::setPosition:, OOSoundSource::setPositional:, OOSoundSource::setRepeatCount:, OOSoundSource::setSound:, and sSoundSourceProperties.

Here is the call graph for this function:

◆ SoundSourceStop()

JSBool SoundSourceStop ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 285 of file OOJSSoundSource.m.

286{
287 OOJS_NATIVE_ENTER(context)
288
289 OOSoundSource* thisv = nil;
290
291 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
292 return NO;
293
295 [thisv stop];
297
299
301}

References EXPECT_NOT, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, and OOSoundSource::stop.

Here is the call graph for this function:

Variable Documentation

◆ sSoundSourceClass

JSClass sSoundSourceClass
static
Initial value:
= {
"SoundSource",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 42 of file OOJSSoundSource.m.

42 {
43 "SoundSource",
44 JSCLASS_HAS_PRIVATE,
45
46 JS_PropertyStub, // addProperty
47 JS_PropertyStub, // delProperty
48 SoundSourceGetProperty, // getProperty
49 SoundSourceSetProperty, // setProperty
50 JS_EnumerateStub, // enumerate
51 JS_ResolveStub, // resolve
52 JS_ConvertStub, // convert
53 OOJSObjectWrapperFinalize, // finalize
54 JSCLASS_NO_OPTIONAL_MEMBERS
55};

Referenced by InitOOJSSoundSource(), InitOOJSSoundSource(), and OOSoundSource(OOJavaScriptExtentions)::oo_jsValueInContext:.

◆ sSoundSourceMethods

JSFunctionSpec sSoundSourceMethods[]
static
Initial value:
= {
{
"toString",
0,
},
{
"play",
0,
},
{
"playOrRepeat",
0,
},
{
"stop",
0,
},
{ 0 }
}
static JSBool SoundSourcePlay(JSContext *context, uintN argc, jsval *vp)
static JSBool SoundSourcePlayOrRepeat(JSContext *context, uintN argc, jsval *vp)
static JSBool SoundSourceStop(JSContext *context, uintN argc, jsval *vp)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)

Definition at line 80 of file OOJSSoundSource.m.

80 {
81 // JS name Function min args
82 {
83 "toString",
85 0,
86 },
87 {
88 "play",
90 0,
91 },
92 {
93 "playOrRepeat",
95 0,
96 },
97 // playSound is defined in oolite-global-prefix.js.
98 {
99 "stop",
101 0,
102 },
103 { 0 }
104};

Referenced by InitOOJSSoundSource(), and InitOOJSSoundSource().

◆ sSoundSourceProperties

◆ sSoundSourcePrototype

JSObject* sSoundSourcePrototype
static