Oolite 1.91.0.7646-241128-10e222e
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 62 of file OOJSSoundSource.m.

63{
64 // Property IDs
72};
@ 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 106 of file OOJSSoundSource.m.

107{
108 sSoundSourcePrototype = JS_InitClass(context, global, NULL, &sSoundSourceClass, SoundSourceConstruct, 0, sSoundSourceProperties, sSoundSourceMethods, NULL, NULL);
110}
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 OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), SoundSourceConstruct(), sSoundSourceClass, sSoundSourceMethods, sSoundSourceProperties, and sSoundSourcePrototype.

+ Here is the call graph for this function:

◆ SoundSourceConstruct()

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

Definition at line 113 of file OOJSSoundSource.m.

114{
115 OOJS_NATIVE_ENTER(context)
116
117 if (EXPECT_NOT(!JS_IsConstructing(context, vp)))
118 {
119 OOJSReportError(context, @"SoundSource() cannot be called as a function, it must be used as a constructor (as in new SoundSource()).");
120 return NO;
121 }
122
123 OOJS_RETURN_OBJECT([[[OOSoundSource alloc] init] autorelease]);
124
126}
#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().

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

◆ SoundSourceGetProperty()

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

Definition at line 131 of file OOJSSoundSource.m.

132{
133 if (!JSID_IS_INT(propID)) return YES;
134
135 OOJS_NATIVE_ENTER(context)
136
137 OOSoundSource *soundSource = nil;
138
139 if (!JSSoundSourceGetSoundSource(context, this, &soundSource)) return NO;
140
141 switch (JSID_TO_INT(propID))
142 {
144 *value = OOJSValueFromNativeObject(context, [soundSource sound]);
145 return YES;
146
148 *value = OOJSValueFromBOOL([soundSource isPlaying]);
149 return YES;
150
152 *value = OOJSValueFromBOOL([soundSource loop]);
153 return YES;
154
156 *value = INT_TO_JSVAL([soundSource repeatCount]);
157 return YES;
158
160 return VectorToJSValue(context, [soundSource position], value);
161
163 *value = OOJSValueFromBOOL([soundSource positional]);
164 return YES;
165
167 return JS_NewNumberValue(context, [soundSource gain], value);
168
169
170 default:
172 return NO;
173 }
174
176}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
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()

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

Definition at line 259 of file OOJSSoundSource.m.

260{
261 OOJS_NATIVE_ENTER(context)
262
263 OOSoundSource *thisv = nil;
264 int32 count = 0;
265
266 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv))) return NO;
267 if (argc > 0 && !JSVAL_IS_VOID(OOJS_ARGV[0]) && !JS_ValueToInt32(context, OOJS_ARGV[0], &count))
268 {
269 OOJSReportBadArguments(context, @"SoundSource", @"play", 1, OOJS_ARGV, nil, @"integer count or no argument");
270 return NO;
271 }
272
273 if (count > 0)
274 {
275 if (count > 100) count = 100;
276 [thisv setRepeatCount:count];
277 }
278
280 [thisv play];
282
284
286}
#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()

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

Definition at line 309 of file OOJSSoundSource.m.

310{
311 OOJS_NATIVE_ENTER(context)
312
313 OOSoundSource *thisv = nil;
314
315 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv))) return NO;
316
318 [thisv playOrRepeat];
320
322
324}

◆ SoundSourceSetProperty()

static 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)) return YES;
182
183 OOJS_NATIVE_ENTER(context)
184
185 OOSoundSource *soundSource = nil;
186 int32 iValue;
187 JSBool bValue;
188 Vector vValue;
189 double fValue;
190
191 if (!JSSoundSourceGetSoundSource(context, this, &soundSource)) return NO;
192
193 switch (JSID_TO_INT(propID))
194 {
196 [soundSource setSound:SoundFromJSValue(context, *value)];
197 return YES;
198 break;
199
201 if (JS_ValueToBoolean(context, *value, &bValue))
202 {
203 [soundSource setLoop:bValue];
204 return YES;
205 }
206 break;
207
209 if (JS_ValueToInt32(context, *value, &iValue))
210 {
211 if (iValue > 100) iValue = 100;
212 if (100 < 1) iValue = 1;
213 [soundSource setRepeatCount:iValue];
214 return YES;
215 }
216 break;
217
218
220 if (JSValueToVector(context, *value, &vValue))
221 {
222 [soundSource setPosition:vValue];
223 return YES;
224 }
225 break;
226
228 if (JS_ValueToBoolean(context, *value, &bValue))
229 {
230 [soundSource setPositional:bValue];
231 return YES;
232 }
233 break;
234
236 if (JS_ValueToNumber(context, *value, &fValue))
237 {
238 fValue = OOClamp_0_max_d(fValue, 1);
239 [soundSource setGain:fValue];
240 return YES;
241 }
242 break;
243
244 default:
246 return NO;
247 }
248
249 OOJSReportBadPropertyValue(context, this, propID, sSoundSourceProperties, *value);
250 return NO;
251
253}
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:259
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, 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()

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

Definition at line 290 of file OOJSSoundSource.m.

291{
292 OOJS_NATIVE_ENTER(context)
293
294 OOSoundSource *thisv = nil;
295
296 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv))) return NO;
297
299 [thisv stop];
301
303
305}

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 45 of file OOJSSoundSource.m.

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

Referenced by InitOOJSSoundSource().

◆ sSoundSourceMethods

JSFunctionSpec sSoundSourceMethods[]
static
Initial value:
=
{
{ "toString", OOJSObjectWrapperToString, 0, },
{ "play", SoundSourcePlay, 0, },
{ "playOrRepeat", SoundSourcePlayOrRepeat, 0, },
{ "stop", SoundSourceStop, 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 89 of file OOJSSoundSource.m.

90{
91 // JS name Function min args
92 { "toString", OOJSObjectWrapperToString, 0, },
93 { "play", SoundSourcePlay, 0, },
94 { "playOrRepeat", SoundSourcePlayOrRepeat, 0, },
95 // playSound is defined in oolite-global-prefix.js.
96 { "stop", SoundSourceStop, 0, },
97 { 0 }
98};

Referenced by InitOOJSSoundSource().

◆ sSoundSourceProperties

JSPropertySpec sSoundSourceProperties[]
static

◆ sSoundSourcePrototype

JSObject* sSoundSourcePrototype
static

Definition at line 32 of file OOJSSoundSource.m.

Referenced by InitOOJSSoundSource().