Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOSoundSource Class Reference

#include <OOSoundSource.h>

+ Inheritance diagram for OOSoundSource:
+ Collaboration diagram for OOSoundSource:

Instance Methods

(id) - initWithSound:
 
(OOSound *) - sound
 
(void) - setSound:
 
(BOOL) - loop
 
(void) - setLoop:
 
(uint8_t) - repeatCount
 
(void) - setRepeatCount:
 
(BOOL) - isPlaying
 
(void) - play
 
(void) - playOrRepeat
 
(void) - stop
 
(void) - playSound:
 
(void) - playSound:repeatCount:
 
(void) - playOrRepeatSound:
 
(void) - setPositional:
 
(BOOL) - positional
 
(void) - setPosition:
 
(Vector) - position
 
(void) - setGain:
 
(float) - gain
 
(void) - setVelocity:
 
(void) - setOrientation:
 
(void) - setConeAngle:
 
(void) - setGainInsideCone:outsideCone:
 
(void) - positionRelativeTo:
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(void) - channel:didFinishPlayingSound: [implementation]
 
(id) - initWithCustomSoundKey:
 
(void) - playCustomSoundWithKey:
 
(jsval) - oo_jsValueInContext: [implementation]
 
(NSString *) - oo_jsClassName [implementation]
 

Class Methods

(instancetype) + sourceWithSound:
 
(void) + stopAll
 
(id) + sourceWithCustomSoundKey:
 

Private Attributes

OOSound_sound
 
OOSoundChannel_channel
 
BOOL _loop
 
uint8_t _repeatCount
 
uint8_t _remainingCount
 
Vector _position
 
BOOL _positional
 
float _gain
 

Detailed Description

Definition at line 43 of file OOSoundSource.h.

Method Documentation

◆ channel:didFinishPlayingSound:

- (void) channel: (OOSoundChannel *) channel
didFinishPlayingSound: (OOSound *) sound 
implementation

Definition at line 32 of file OOSoundSource.m.

317 :(OOSoundChannel *)channel didFinishPlayingSound:(OOSound *)sound
318{
319 assert(_channel == channel);
320
322
323 if (--_remainingCount)
324 {
325 [_channel playSound:[self sound] looped:NO];
326 }
327 else
328 {
329 [_channel setDelegate:nil];
331 _channel = nil;
332 [self release];
333 }
335}
return nil
#define OOSoundReleaseLock()
#define OOSoundAcquireLock()
void pushChannel:(OOSoundChannel *channel)
OOSoundChannel * _channel
uint8_t _remainingCount
OOSound * sound()

◆ dealloc

- (void) dealloc
implementation

Definition at line 32 of file OOSoundSource.m.

67{
68 [self stop];
69 [_sound autorelease];
70
71 [super dealloc];
72}

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Definition at line 32 of file OOSoundSource.m.

76{
77 if ([self isPlaying])
78 {
79 return [NSString stringWithFormat:@"sound=%@, loop=%s, repeatCount=%u, playing on channel %@", _sound, [self loop] ? "YES" : "NO", [self repeatCount], _channel];
80 }
81 else
82 {
83 return [NSString stringWithFormat:@"sound=%@, loop=%s, repeatCount=%u, not playing", _sound, [self loop] ? "YES" : "NO", [self repeatCount]];
84 }
85}

◆ gain

- (float) gain

Definition at line 32 of file OOSoundSource.m.

280{
281 return _gain;
282}

◆ init

- (id) init
implementation

Definition at line 32 of file OOSoundSource.m.

44{
45 self = [super init];
46 if (!self) return nil;
47
48 _positional = NO;
50 _gain = OO_DEFAULT_SOUNDSOURCE_GAIN;
51 return self;
52}
const Vector kZeroVector
Definition OOVector.m:28

◆ initWithCustomSoundKey:

- (id) initWithCustomSoundKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 10697 of file Universe.m.

11057 :(NSString *)key
11058{
11059 OOSound *theSound = [OOSound soundWithCustomSoundKey:key];
11060 if (theSound != nil)
11061 {
11062 self = [self initWithSound:theSound];
11063 }
11064 else
11065 {
11066 [self release];
11067 self = nil;
11068 }
11069 return self;
11070}
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:11032

◆ initWithSound:

- (id) initWithSound: (OOSound *) inSound

Definition at line 32 of file OOSoundSource.m.

55 :(OOSound *)inSound
56{
57 self = [self init];
58 if (!self) return nil;
59
60 [self setSound:inSound];
61
62 return self;
63}

◆ isPlaying

- (BOOL) isPlaying

Definition at line 32 of file OOSoundSource.m.

130{
131 return _channel != nil;
132}

◆ loop

- (BOOL) loop

Definition at line 32 of file OOSoundSource.m.

106{
107 return _loop;
108}

◆ oo_jsClassName

- (NSString *) oo_jsClassName
implementation

Provided by category OOSoundSource(OOJavaScriptExtentions).

Definition at line 309 of file OOJSSoundSource.m.

346{
347 return @"SoundSource";
348}

◆ oo_jsValueInContext:

- (jsval) oo_jsValueInContext: (JSContext *) context
implementation

Provided by category OOSoundSource(OOJavaScriptExtentions).

Definition at line 309 of file OOJSSoundSource.m.

329 :(JSContext *)context
330{
331 JSObject *jsSelf = NULL;
332 jsval result = JSVAL_NULL;
333
334 jsSelf = JS_NewObject(context, &sSoundSourceClass, sSoundSourcePrototype, NULL);
335 if (jsSelf != NULL)
336 {
337 if (!JS_SetPrivate(context, jsSelf, [self retain])) jsSelf = NULL;
338 }
339 if (jsSelf != NULL) result = OBJECT_TO_JSVAL(jsSelf);
340
341 return result;
342}
static JSClass sSoundSourceClass
static JSObject * sSoundSourcePrototype

◆ play

- (void) play

Definition at line 32 of file OOSoundSource.m.

136{
137 if ([self sound] == nil) return;
138
140
141 if (_channel) [self stop];
142
144 if (nil != _channel)
145 {
146 _remainingCount = [self repeatCount];
147 [_channel setDelegate:self];
148 [_channel setPosition:_position];
149 [_channel setGain:_gain];
150 [_channel playSound:[self sound] looped:[self loop]];
151 [self retain];
152 }
153
155 {
156 sPlayingSoundSources = [[NSMutableSet alloc] init];
157 }
158 [sPlayingSoundSources addObject:self];
159
161}
#define EXPECT_NOT(x)
static NSMutableSet * sPlayingSoundSources
OOSoundChannel * popChannel()

Referenced by SoundSourcePlay().

+ Here is the caller graph for this function:

◆ playCustomSoundWithKey:

- (void) playCustomSoundWithKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 10697 of file Universe.m.

11073 :(NSString *)key
11074{
11075 OOSound *theSound = [OOSound soundWithCustomSoundKey:key];
11076 if (theSound != nil) [self playSound:theSound];
11077}

◆ playOrRepeat

- (void) playOrRepeat

Definition at line 32 of file OOSoundSource.m.

165{
166 if (![self isPlaying]) [self play];
167 else ++_remainingCount;
168}

Referenced by OOSoundSource(OOJavaScriptExtentions)::oo_jsClassName.

+ Here is the caller graph for this function:

◆ playOrRepeatSound:

- (void) playOrRepeatSound: (OOSound *) inSound

Definition at line 32 of file OOSoundSource.m.

219 :(OOSound *)sound
220{
221 if (_sound != sound) [self playSound:sound];
222 else [self playOrRepeat];
223}
OOSound * _sound

◆ playSound:

- (void) playSound: (OOSound *) inSound

Definition at line 32 of file OOSoundSource.m.

204 :(OOSound *)sound
205{
206 [self playSound:sound repeatCount:_repeatCount];
207}

Referenced by OOTrumble::actionBlink, and PlayTrumbleIdle().

+ Here is the caller graph for this function:

◆ playSound:repeatCount:

- (void) playSound: (OOSound *) inSound
repeatCount: (uint8_t) inCount 

Definition at line 32 of file OOSoundSource.m.

210 :(OOSound *)sound repeatCount:(uint8_t)count
211{
212 [self stop];
213 [self setSound:sound];
214 [self setRepeatCount:count];
215 [self play];
216}
unsigned count
uint8_t repeatCount()

◆ position

- (Vector) position

Definition at line 32 of file OOSoundSource.m.

264{
265 return _position;
266}

◆ positional

- (BOOL) positional

Definition at line 32 of file OOSoundSource.m.

244{
245 return _positional;
246}

◆ positionRelativeTo:

- (void) positionRelativeTo: (OOSoundReferencePoint *) inPoint

Definition at line 32 of file OOSoundSource.m.

◆ repeatCount

- (uint8_t) repeatCount

Definition at line 32 of file OOSoundSource.m.

118{
119 return _repeatCount ? _repeatCount : 1;
120}
uint8_t _repeatCount

◆ setConeAngle:

- (void) setConeAngle: (float) inAngle

Definition at line 32 of file OOSoundSource.m.

298 :(float)inAngle
299{
300
301}

◆ setGain:

- (void) setGain: (float) gain

Definition at line 32 of file OOSoundSource.m.

269 :(float)gain
270{
271 _gain = gain;
272 if (_channel)
273 {
274 [_channel setGain:_gain];
275 }
276}

Referenced by SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setGainInsideCone:outsideCone:

- (void) setGainInsideCone: (float) inInside
outsideCone: (float) inOutside 

Definition at line 32 of file OOSoundSource.m.

304 :(float)inInside outsideCone:(float)inOutside
305{
306
307}

◆ setLoop:

- (void) setLoop: (BOOL) inLoop

Definition at line 32 of file OOSoundSource.m.

111 :(BOOL)loop
112{
113 _loop = !!loop;
114}

Referenced by SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setOrientation:

- (void) setOrientation: (Vector) inOrientation

Definition at line 32 of file OOSoundSource.m.

292 :(Vector)inOrientation
293{
294
295}

◆ setPosition:

- (void) setPosition: (Vector) inPosition

Definition at line 32 of file OOSoundSource.m.

249 :(Vector)inPosition
250{
251 _position = inPosition;
252 if (inPosition.x != 0.0 || inPosition.y != 0.0 || inPosition.z != 0.0)
253 {
254 _positional = YES;
255 }
256 if (_channel)
257 {
258 [_channel setPosition:_position];
259 }
260}

Referenced by OOTrumble::actionBlink, PlayTrumbleIdle(), and SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setPositional:

- (void) setPositional: (BOOL) inPositional

Definition at line 32 of file OOSoundSource.m.

226 :(BOOL)inPositional
227{
228 if (inPositional)
229 {
230 _positional = YES;
231 }
232 else
233 {
234 /* OpenAL doesn't easily do non-positional sounds beyond the
235 * stereo/mono distinction, but setting the position to the
236 * zero vector is probably close enough */
237 _positional = NO;
238 [self setPosition:kZeroVector];
239 }
240}

Referenced by SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setRepeatCount:

- (void) setRepeatCount: (uint8_t) inCount

Definition at line 32 of file OOSoundSource.m.

123 :(uint8_t)count
124{
126}

Referenced by SoundSourcePlay(), and SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setSound:

- (void) setSound: (OOSound *) inSound

Definition at line 32 of file OOSoundSource.m.

94 :(OOSound *)sound
95{
96 if (_sound != sound)
97 {
98 [self stop];
99 [_sound autorelease];
100 _sound = [sound retain];
101 }
102}

Referenced by SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setVelocity:

- (void) setVelocity: (Vector) inVelocity

Definition at line 32 of file OOSoundSource.m.

286 :(Vector)inVelocity
287{
288
289}

◆ sound

- (OOSound *) sound

Definition at line 32 of file OOSoundSource.m.

89{
90 return _sound;
91}

◆ sourceWithCustomSoundKey:

+ (id) sourceWithCustomSoundKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 10697 of file Universe.m.

11051 :(NSString *)key
11052{
11053 return [[[self alloc] initWithCustomSoundKey:key] autorelease];
11054}

◆ sourceWithSound:

+ (instancetype) sourceWithSound: (OOSound *) inSound

Definition at line 32 of file OOSoundSource.m.

37 :(OOSound *)inSound
38{
39 return [[[self alloc] initWithSound:inSound] autorelease];
40}

◆ stop

- (void) stop

Definition at line 32 of file OOSoundSource.m.

172{
174
175 if (nil != _channel)
176 {
177 [_channel setDelegate:[self class]];
178 [_channel stop];
179 _channel = nil;
180
181 [sPlayingSoundSources removeObject:self];
182 [self release];
183 }
184
186}

Referenced by SoundSourceStop().

+ Here is the caller graph for this function:

◆ stopAll

+ (void) stopAll

Definition at line 32 of file OOSoundSource.m.

190{
191 /* We're not allowed to mutate sPlayingSoundSources during iteration. The
192 normal solution would be to copy the set, but since we know it will
193 end up empty we may as well use the original set and let a new one be
194 set up lazily.
195 */
196 NSMutableSet *playing = sPlayingSoundSources;
198
199 [playing makeObjectsPerformSelector:@selector(stop)];
200 [playing release];
201}

Member Data Documentation

◆ _channel

- (OOSoundChannel*) _channel
private

Definition at line 47 of file OOSoundSource.h.

◆ _gain

- (float) _gain
private

Definition at line 53 of file OOSoundSource.h.

◆ _loop

- (BOOL) _loop
private

Definition at line 48 of file OOSoundSource.h.

◆ _position

- (Vector) _position
private

Definition at line 51 of file OOSoundSource.h.

◆ _positional

- (BOOL) _positional
private

Definition at line 52 of file OOSoundSource.h.

◆ _remainingCount

- (uint8_t) _remainingCount
private

Definition at line 50 of file OOSoundSource.h.

◆ _repeatCount

- (uint8_t) _repeatCount
private

Definition at line 49 of file OOSoundSource.h.

◆ _sound

- (OOSound*) _sound
private

Definition at line 46 of file OOSoundSource.h.


The documentation for this class was generated from the following files: