Oolite 1.91.0.7665-250419-c535bfe
All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 317 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()

References _channel, _remainingCount, nil, OOSoundAcquireLock, OOSoundReleaseLock, OOSoundChannel::playSound:looped:, OOSoundMixer::pushChannel:, OOSoundChannel::setDelegate:, OOSoundMixer::sharedMixer, and sound.

+ Here is the call graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 66 of file OOSoundSource.m.

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

References dealloc, and stop.

Referenced by dealloc.

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

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Definition at line 75 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}

References descriptionComponents, isPlaying, loop, and repeatCount.

Referenced by descriptionComponents.

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

◆ gain

- (float) gain

Definition at line 279 of file OOSoundSource.m.

280{
281 return _gain;
282}

References _gain, and gain.

Referenced by gain, OOMusic::musicGain, and setGain:.

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

◆ init

- (id) init
implementation

Definition at line 43 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

References _gain, _position, _positional, init, kZeroVector, and nil.

Referenced by init, and initWithSound:.

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

◆ initWithCustomSoundKey:

- (id) initWithCustomSoundKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 11080 of file Universe.m.

11080 :(NSString *)key
11081{
11082 OOSound *theSound = [OOSound soundWithCustomSoundKey:key];
11083 if (theSound != nil)
11084 {
11085 self = [self initWithSound:theSound];
11086 }
11087 else
11088 {
11089 [self release];
11090 self = nil;
11091 }
11092 return self;
11093}
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:11055

◆ initWithSound:

- (id) initWithSound: (OOSound *) inSound

Definition at line 55 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}

References init, nil, and setSound:.

Referenced by OOSoundSource(OOCustomSounds)::initWithCustomSoundKey:.

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

◆ isPlaying

- (BOOL) isPlaying

Definition at line 129 of file OOSoundSource.m.

130{
131 return _channel != nil;
132}

References _channel, isPlaying, and nil.

Referenced by descriptionComponents, PlayerEntity(Sound)::isBeeping, OOMusic::isPlaying, isPlaying, and playOrRepeat.

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

◆ loop

- (BOOL) loop

Definition at line 105 of file OOSoundSource.m.

106{
107 return _loop;
108}

References _loop, and loop.

Referenced by descriptionComponents, loop, play, and setLoop:.

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

◆ oo_jsClassName

- (NSString *) oo_jsClassName
implementation

Provided by category OOSoundSource(OOJavaScriptExtentions).

Definition at line 345 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 329 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 135 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()

References _channel, _remainingCount, EXPECT_NOT, loop, nil, OOSoundAcquireLock, OOSoundReleaseLock, play, OOSoundChannel::playSound:looped:, OOSoundMixer::popChannel, repeatCount, OOSoundChannel::setDelegate:, OOSoundChannel::setGain:, OOSoundChannel::setPosition:, OOSoundMixer::sharedMixer, sound, sPlayingSoundSources, and stop.

Referenced by play, OOMusic::playLooped:, playOrRepeat, playSound:repeatCount:, SoundSourcePlay(), and PlayerEntity(Sound)::updateAfterburnerSound.

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

◆ playCustomSoundWithKey:

- (void) playCustomSoundWithKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 11096 of file Universe.m.

11096 :(NSString *)key
11097{
11098 OOSound *theSound = [OOSound soundWithCustomSoundKey:key];
11099 if (theSound != nil) [self playSound:theSound];
11100}

Referenced by PlayerEntity(Sound)::playDockWithStation, PlayerEntity(Sound)::playExitWitchspace, PlayerEntity(Sound)::playFiredECMSound, PlayerEntity(Sound)::playGalacticHyperspace, PlayerEntity(Sound)::playHitByECMSound, PlayerEntity(Sound)::playHyperspaceAborted, PlayerEntity(Sound)::playLaunchFromStation, and PlayerEntity(Sound)::playStandardHyperspace.

+ Here is the caller graph for this function:

◆ playOrRepeat

- (void) playOrRepeat

Definition at line 164 of file OOSoundSource.m.

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

References _remainingCount, isPlaying, play, and playOrRepeat.

Referenced by playOrRepeat, playOrRepeatSound:, and SoundSourcePlayOrRepeat().

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

◆ playOrRepeatSound:

- (void) playOrRepeatSound: (OOSound *) inSound

Definition at line 219 of file OOSoundSource.m.

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

References _sound, playOrRepeat, playSound:, and sound.

+ Here is the call graph for this function:

◆ playSound:

- (void) playSound: (OOSound *) inSound

Definition at line 204 of file OOSoundSource.m.

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

References playSound:repeatCount:.

Referenced by OOSoundSource(OOCustomSounds)::playCustomSoundWithKey:, PlayerEntity(Sound)::playInterfaceBeep:, playOrRepeatSound:, PlayTrumbleIdle(), and PlayTrumbleSqueal().

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

◆ playSound:repeatCount:

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

Definition at line 210 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()

References play, setRepeatCount:, setSound:, and stop.

Referenced by playSound:.

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

◆ position

- (Vector) position

Definition at line 263 of file OOSoundSource.m.

264{
265 return _position;
266}

References _position, and position.

Referenced by position.

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

◆ positional

- (BOOL) positional

Definition at line 243 of file OOSoundSource.m.

244{
245 return _positional;
246}

References _positional, and positional.

Referenced by positional.

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

◆ positionRelativeTo:

- (void) positionRelativeTo: (OOSoundReferencePoint *) inPoint

Definition at line 310 of file OOSoundSource.m.

310 :(OOSoundReferencePoint *)inPoint
311{
312
313}

◆ repeatCount

- (uint8_t) repeatCount

Definition at line 117 of file OOSoundSource.m.

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

References _repeatCount, and repeatCount.

Referenced by descriptionComponents, play, and repeatCount.

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

◆ setConeAngle:

- (void) setConeAngle: (float) inAngle

Definition at line 298 of file OOSoundSource.m.

298 :(float)inAngle
299{
300
301}

◆ setGain:

- (void) setGain: (float) gain

Definition at line 269 of file OOSoundSource.m.

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

References _channel, _gain, gain, and OOSoundChannel::setGain:.

Referenced by OOMusic::setMusicGain:, and SoundSourceSetProperty().

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

◆ setGainInsideCone:outsideCone:

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

Definition at line 304 of file OOSoundSource.m.

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

◆ setLoop:

- (void) setLoop: (BOOL) inLoop

Definition at line 111 of file OOSoundSource.m.

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

References _loop, and loop.

Referenced by OOMusic::playLooped:, and SoundSourceSetProperty().

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

◆ setOrientation:

- (void) setOrientation: (Vector) inOrientation

Definition at line 292 of file OOSoundSource.m.

292 :(Vector)inOrientation
293{
294
295}

◆ setPosition:

- (void) setPosition: (Vector) inPosition

Definition at line 249 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}

References _channel, _position, _positional, and OOSoundChannel::setPosition:.

Referenced by PlayTrumbleIdle(), PlayTrumbleSqueal(), setPositional:, PlayerEntity(Sound)::setUpSound, and SoundSourceSetProperty().

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

◆ setPositional:

- (void) setPositional: (BOOL) inPositional

Definition at line 226 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}

References _positional, and setPosition:.

Referenced by SoundSourceSetProperty().

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

◆ setRepeatCount:

- (void) setRepeatCount: (uint8_t) inCount

Definition at line 123 of file OOSoundSource.m.

123 :(uint8_t)count
124{
126}

References _repeatCount, and count.

Referenced by playSound:repeatCount:, SoundSourcePlay(), and SoundSourceSetProperty().

+ Here is the caller graph for this function:

◆ setSound:

- (void) setSound: (OOSound *) inSound

Definition at line 94 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}

References _sound, sound, and stop.

Referenced by initWithSound:, OOMusic::playLooped:, playSound:repeatCount:, SoundSourceSetProperty(), and OOMusic::stop.

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

◆ setVelocity:

- (void) setVelocity: (Vector) inVelocity

Definition at line 286 of file OOSoundSource.m.

286 :(Vector)inVelocity
287{
288
289}

◆ sound

- (OOSound *) sound

Definition at line 88 of file OOSoundSource.m.

89{
90 return _sound;
91}

References _sound, and sound.

Referenced by channel:didFinishPlayingSound:, play, playOrRepeatSound:, setSound:, and sound.

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

◆ sourceWithCustomSoundKey:

+ (id) sourceWithCustomSoundKey: (NSString *) key

Provided by category OOSoundSource(OOCustomSounds).

Definition at line 11074 of file Universe.m.

11074 :(NSString *)key
11075{
11076 return [[[self alloc] initWithCustomSoundKey:key] autorelease];
11077}

◆ sourceWithSound:

+ (instancetype) sourceWithSound: (OOSound *) inSound

Definition at line 37 of file OOSoundSource.m.

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

◆ stop

- (void) stop

Definition at line 171 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}

References _channel, nil, OOSoundAcquireLock, OOSoundReleaseLock, OOSoundChannel::setDelegate:, OOSoundChannel::stop, and stop.

Referenced by dealloc, play, OOMusic::playLooped:, playSound:repeatCount:, setSound:, SoundSourceStop(), OOMusic::stop, and stop.

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

◆ stopAll

+ (void) stopAll

Definition at line 189 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}

References nil, sPlayingSoundSources, and stopAll.

Referenced by PlayerEntity::completeSetUpAndSetTarget:, and stopAll.

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

Member Data Documentation

◆ _channel

- (OOSoundChannel*) _channel
private

Definition at line 47 of file OOSoundSource.h.

Referenced by channel:didFinishPlayingSound:, isPlaying, play, setGain:, setPosition:, and stop.

◆ _gain

- (float) _gain
private

Definition at line 53 of file OOSoundSource.h.

Referenced by gain, init, and setGain:.

◆ _loop

- (BOOL) _loop
private

Definition at line 48 of file OOSoundSource.h.

Referenced by loop, and setLoop:.

◆ _position

- (Vector) _position
private

Definition at line 51 of file OOSoundSource.h.

Referenced by init, position, and setPosition:.

◆ _positional

- (BOOL) _positional
private

Definition at line 52 of file OOSoundSource.h.

Referenced by init, positional, setPosition:, and setPositional:.

◆ _remainingCount

- (uint8_t) _remainingCount
private

Definition at line 50 of file OOSoundSource.h.

Referenced by channel:didFinishPlayingSound:, play, and playOrRepeat.

◆ _repeatCount

- (uint8_t) _repeatCount
private

Definition at line 49 of file OOSoundSource.h.

Referenced by repeatCount, and setRepeatCount:.

◆ _sound

- (OOSound*) _sound
private

Definition at line 46 of file OOSoundSource.h.

Referenced by playOrRepeatSound:, setSound:, and sound.


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