Oolite
Loading...
Searching...
No Matches
OOJSSoundSource.m File Reference
import "OOJSSoundSource.h"
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 JSValue SoundSourceGetProperty (OOJS_GETTER_ARGS)
static JSValue SoundSourceSetProperty (OOJS_SETTER_ARGS)
static JSValue SoundSourceConstruct (OOJS_NATIVE_ARGS)
static JSValue SoundSourcePlay (OOJS_NATIVE_ARGS)
static JSValue SoundSourceStop (OOJS_NATIVE_ARGS)
static JSValue SoundSourcePlayOrRepeat (OOJS_NATIVE_ARGS)
void InitOOJSSoundSource (JSContext *context, JSValueConst global)

Variables

static JSClassID sSoundSourceClassID
static JSClassDef sSoundSourceClass
static const JSCFunctionListEntry sSoundSourceProperties []
static const JSCFunctionListEntry 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 48 of file OOJSSoundSource.m.

48 {
49 // Property IDs
57};
@ kSoundSource_loop
@ kSoundSource_positional
@ kSoundSource_volume
@ kSoundSource_position
@ kSoundSource_sound
@ kSoundSource_repeatCount
@ kSoundSource_isPlaying

Function Documentation

◆ InitOOJSSoundSource()

void InitOOJSSoundSource ( JSContext * context,
JSValueConst global )

Definition at line 83 of file OOJSSoundSource.m.

84{
86 OOJSInitClass(context, global, sSoundSourceClassID, JS_UNDEFINED, SoundSourceConstruct, 0,
89}
static JSBool SoundSourceConstruct(JSContext *context, uintN argc, jsval *vp)
static JSClass sSoundSourceClass
static JSFunctionSpec sSoundSourceMethods[]
static JSPropertySpec sSoundSourceProperties[]
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
static JSClassID sSoundSourceClassID
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References InitOOJSSoundSource(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), SoundSourceConstruct(), sSoundSourceClass, sSoundSourceClassID, sSoundSourceMethods, and sSoundSourceProperties.

Here is the call graph for this function:

◆ SoundSourceConstruct()

JSValue SoundSourceConstruct ( OOJS_NATIVE_ARGS )
static

Definition at line 91 of file OOJSSoundSource.m.

92{
93 OOJS_NATIVE_ENTER(context)
94
96 OOJSReportError(context, @"SoundSource() cannot be called as a function, it must be used as a constructor (as in new SoundSource()).");
97 return JS_EXCEPTION;
98 }
99
100 OOJS_RETURN_OBJECT([[[OOSoundSource alloc] init] autorelease]);
101
103}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_OBJECT(o)
void OOJSReportError(JSContext *context, NSString *format,...)
#define OOJS_IS_CONSTRUCTING

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

Here is the call graph for this function:

◆ SoundSourceGetProperty()

JSValue SoundSourceGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 107 of file OOJSSoundSource.m.

108{
109 OOJS_NATIVE_ENTER(context)
110
111 OOSoundSource* soundSource = nil;
112
113 if (!JSSoundSourceGetSoundSource(context, this, &soundSource))
114 return OOJSNativeFailure(context);
115
116 switch (magic) {
118 return OOJSValueFromNativeObject(context, [soundSource sound]);
119
121 return OOJSValueFromBOOL([soundSource isPlaying]);
122
124 return OOJSValueFromBOOL([soundSource loop]);
125
127 return JS_NewInt32(context, [soundSource repeatCount]);
128
130 OOJS_RETURN_VECTOR([soundSource position]);
131
133 return OOJSValueFromBOOL([soundSource positional]);
134
136 return JS_NewNumber(context, [soundSource gain]);
137
138 default:
140 return OOJSNativeFailure(context);
141 }
142
144}
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
#define OOJS_RETURN_VECTOR(value)
return nil
JSValue OOJSNativeFailure(JSContext *context)

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

Here is the call graph for this function:

◆ SoundSourcePlay()

JSValue SoundSourcePlay ( OOJS_NATIVE_ARGS )
static

Definition at line 219 of file OOJSSoundSource.m.

220{
221 OOJS_NATIVE_ENTER(context)
222
223 OOSoundSource* thisv = nil;
224 int32_t count = 0;
225
226 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
227 return OOJSNativeFailure(context);
228 if (argc > 0 && !JS_IsUndefined(OOJS_ARGV[0]) && !OOJSValueToInt32(context, OOJS_ARGV[0], &count)) {
229 OOJSReportBadArguments(context, @"SoundSource", @"play", 1, OOJS_ARGV, nil, @"integer count or no argument");
230 return OOJSNativeFailure(context);
231 }
232
233 if (count > 0) {
234 if (count > 100)
235 count = 100;
236 [thisv setRepeatCount:count];
237 }
238
240 [thisv play];
242
244
246}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_THIS
OOINLINE BOOL OOJSValueToInt32(JSContext *context, jsval value, int32_t *outValue)
#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_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSValueToInt32(), OOSoundSource::play, and OOSoundSource::setRepeatCount:.

Here is the call graph for this function:

◆ SoundSourcePlayOrRepeat()

JSValue SoundSourcePlayOrRepeat ( OOJS_NATIVE_ARGS )
static

Definition at line 268 of file OOJSSoundSource.m.

269{
270 OOJS_NATIVE_ENTER(context)
271
272 OOSoundSource* thisv = nil;
273
274 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
275 return OOJSNativeFailure(context);
276
278 [thisv playOrRepeat];
280
282
284}

References EXPECT_NOT, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), and OOSoundSource::playOrRepeat.

Here is the call graph for this function:

◆ SoundSourceSetProperty()

JSValue SoundSourceSetProperty ( OOJS_SETTER_ARGS )
static

Definition at line 146 of file OOJSSoundSource.m.

147{
148 OOJS_NATIVE_ENTER(context)
149
150 OOSoundSource* soundSource = nil;
151 int32_t iValue;
152 int bValue;
153 Vector vValue;
154 double fValue;
155
156 if (!JSSoundSourceGetSoundSource(context, this, &soundSource))
157 return OOJSNativeFailure(context);
158
159 switch (magic) {
161 [soundSource setSound:SoundFromJSValue(context, value)];
162 return JS_UNDEFINED;
163 break;
164
166 if ((bValue = JS_ToBool(context, value)) >= 0) {
167 [soundSource setLoop:bValue];
168 return JS_UNDEFINED;
169 }
170 break;
171
173 if (OOJSValueToInt32(context, value, &iValue)) {
174 if (iValue > 100)
175 iValue = 100;
176 if (100 < 1)
177 iValue = 1;
178 [soundSource setRepeatCount:iValue];
179 return JS_UNDEFINED;
180 }
181 break;
182
184 if (JSValueToVector(context, value, &vValue)) {
185 [soundSource setPosition:vValue];
186 return JS_UNDEFINED;
187 }
188 break;
189
191 if ((bValue = JS_ToBool(context, value)) >= 0) {
192 [soundSource setPositional:bValue];
193 return JS_UNDEFINED;
194 }
195 break;
196
198 if (JS_ToFloat64(context, &fValue, value) == 0) {
199 fValue = OOClamp_0_max_d(fValue, 1);
200 [soundSource setGain:fValue];
201 return JS_UNDEFINED;
202 }
203 break;
204
205 default:
207 return OOJSNativeFailure(context);
208 }
209
211 return OOJSNativeFailure(context);
212
214}
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_COUNT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SETTER_ARGS, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOJSValueToInt32(), OOSoundSource::setGain:, OOSoundSource::setLoop:, OOSoundSource::setPosition:, OOSoundSource::setPositional:, OOSoundSource::setRepeatCount:, OOSoundSource::setSound:, and sSoundSourceProperties.

Here is the call graph for this function:

◆ SoundSourceStop()

JSValue SoundSourceStop ( OOJS_NATIVE_ARGS )
static

Definition at line 249 of file OOJSSoundSource.m.

250{
251 OOJS_NATIVE_ENTER(context)
252
253 OOSoundSource* thisv = nil;
254
255 if (EXPECT_NOT(!JSSoundSourceGetSoundSource(context, OOJS_THIS, &thisv)))
256 return OOJSNativeFailure(context);
257
259 [thisv stop];
261
263
265}

References EXPECT_NOT, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), and OOSoundSource::stop.

Here is the call graph for this function:

Variable Documentation

◆ sSoundSourceClass

JSClassDef sSoundSourceClass
static
Initial value:
= {
.class_name = "SoundSource",
}
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 43 of file OOJSSoundSource.m.

43 {
44 .class_name = "SoundSource",
45 .finalizer = OOJSObjectWrapperFinalize,
46};

◆ sSoundSourceClassID

JSClassID sSoundSourceClassID
static

Definition at line 32 of file OOJSSoundSource.m.

Referenced by InitOOJSSoundSource().

◆ sSoundSourceMethods

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

70 {
71 // JS name, min args, function
72 JS_CFUNC_DEF("toString", 0, OOJSObjectWrapperToString),
73 JS_CFUNC_DEF("play", 0, SoundSourcePlay),
74 JS_CFUNC_DEF("playOrRepeat", 0, SoundSourcePlayOrRepeat),
75 // playSound is defined in oolite-global-prefix.js.
76 JS_CFUNC_DEF("stop", 0, SoundSourceStop),
77};

◆ sSoundSourceProperties

const JSCFunctionListEntry sSoundSourceProperties[]
static
Initial value:
= {
}
static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
#define OOJS_PROPERTY_RW(name, getter, setter, magic)
#define OOJS_PROPERTY_RO(name, getter, magic)

Definition at line 59 of file OOJSSoundSource.m.