Oolite
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 42 of file OOSoundSource.h.

Method Documentation

◆ channel:didFinishPlayingSound:

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

Definition at line 276 of file OOSoundSource.m.

276 :(OOSoundChannel*)channel didFinishPlayingSound:(OOSound*)sound
277{
278 assert(_channel == channel);
279
281
282 if (--_remainingCount) {
283 [_channel playSound:[self sound] looped:NO];
284 } else {
285 [_channel setDelegate:nil];
287 _channel = nil;
288 [self release];
289 }
291}
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 64 of file OOSoundSource.m.

65{
66 [self stop];
67 [_sound autorelease];
68
69 [super dealloc];
70}

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 72 of file OOSoundSource.m.

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

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 249 of file OOSoundSource.m.

250{
251 return _gain;
252}

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 41 of file OOSoundSource.m.

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

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 9973 of file Universe.m.

9973 :(NSString*)key
9974{
9975 OOSound* theSound = [OOSound soundWithCustomSoundKey:key];
9976 if (theSound != nil) {
9977 self = [self initWithSound:theSound];
9978 } else {
9979 [self release];
9980 self = nil;
9981 }
9982 return self;
9983}
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:9950

◆ initWithSound:

- (id) initWithSound: (OOSound*) inSound

Definition at line 53 of file OOSoundSource.m.

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

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 115 of file OOSoundSource.m.

116{
117 return _channel != nil;
118}

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 95 of file OOSoundSource.m.

96{
97 return _loop;
98}

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

341{
342 return @"SoundSource";
343}

◆ oo_jsValueInContext:

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

Provided by category OOSoundSource(OOJavaScriptExtentions).

Definition at line 324 of file OOJSSoundSource.m.

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

◆ play

- (void) play

Definition at line 120 of file OOSoundSource.m.

121{
122 if ([self sound] == nil)
123 return;
124
126
127 if (_channel)
128 [self stop];
129
131 if (nil != _channel) {
132 _remainingCount = [self repeatCount];
133 [_channel setDelegate:self];
134 [_channel setPosition:_position];
135 [_channel setGain:_gain];
136 [_channel playSound:[self sound] looped:[self loop]];
137 [self retain];
138 }
139
141 sPlayingSoundSources = [[NSMutableSet alloc] init];
142 }
143 [sPlayingSoundSources addObject:self];
144
146}
#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(), 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 9985 of file Universe.m.

9985 :(NSString*)key
9986{
9987 OOSound* theSound = [OOSound soundWithCustomSoundKey:key];
9988 if (theSound != nil)
9989 [self playSound:theSound];
9990}

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 148 of file OOSoundSource.m.

149{
150 if (![self isPlaying])
151 [self play];
152 else
154}

References _remainingCount, isPlaying, play, and playOrRepeat.

Referenced by playOrRepeat, playOrRepeatSound:, SoundSourcePlayOrRepeat(), 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 199 of file OOSoundSource.m.

199 :(OOSound*)sound
200{
201 if (_sound != sound)
202 [self playSound:sound];
203 else
204 [self playOrRepeat];
205}
OOSound * _sound

References _sound, playOrRepeat, playSound:, and sound.

Here is the call graph for this function:

◆ playSound:

- (void) playSound: (OOSound*) inSound

Definition at line 186 of file OOSoundSource.m.

186 :(OOSound*)sound
187{
188 [self playSound:sound repeatCount:_repeatCount];
189}

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 191 of file OOSoundSource.m.

191 :(OOSound*)sound repeatCount:(uint8_t)count
192{
193 [self stop];
194 [self setSound:sound];
195 [self setRepeatCount:count];
196 [self play];
197}
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 236 of file OOSoundSource.m.

237{
238 return _position;
239}

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 220 of file OOSoundSource.m.

221{
222 return _positional;
223}

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 271 of file OOSoundSource.m.

271 :(OOSoundReferencePoint*)inPoint
272{
273}

◆ repeatCount

- (uint8_t) repeatCount

Definition at line 105 of file OOSoundSource.m.

106{
107 return _repeatCount ? _repeatCount : 1;
108}
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 263 of file OOSoundSource.m.

263 :(float)inAngle
264{
265}

◆ setGain:

- (void) setGain: (float) gain

Definition at line 241 of file OOSoundSource.m.

241 :(float)gain
242{
243 _gain = gain;
244 if (_channel) {
245 [_channel setGain:_gain];
246 }
247}

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

Referenced by OOMusic::setMusicGain:, SoundSourceSetProperty(), 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 267 of file OOSoundSource.m.

267 :(float)inInside outsideCone:(float)inOutside
268{
269}

◆ setLoop:

- (void) setLoop: (BOOL) inLoop

Definition at line 100 of file OOSoundSource.m.

100 :(BOOL)loop
101{
102 _loop = !!loop;
103}

References _loop, and loop.

Referenced by OOMusic::playLooped:, SoundSourceSetProperty(), 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 259 of file OOSoundSource.m.

259 :(Vector)inOrientation
260{
261}
struct Vector Vector

◆ setPosition:

- (void) setPosition: (Vector) inPosition

Definition at line 225 of file OOSoundSource.m.

225 :(Vector)inPosition
226{
227 _position = inPosition;
228 if (inPosition.x != 0.0 || inPosition.y != 0.0 || inPosition.z != 0.0) {
229 _positional = YES;
230 }
231 if (_channel) {
232 [_channel setPosition:_position];
233 }
234}
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References _channel, _position, _positional, OOSoundChannel::setPosition:, Vector::x, Vector::y, and Vector::z.

Referenced by PlayTrumbleIdle(), PlayTrumbleSqueal(), setPositional:, PlayerEntity(Sound)::setUpSound, SoundSourceSetProperty(), 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 207 of file OOSoundSource.m.

207 :(BOOL)inPositional
208{
209 if (inPositional) {
210 _positional = YES;
211 } else {
212 /* OpenAL doesn't easily do non-positional sounds beyond the
213 * stereo/mono distinction, but setting the position to the
214 * zero vector is probably close enough */
215 _positional = NO;
216 [self setPosition:kZeroVector];
217 }
218}

References _positional, and setPosition:.

Referenced by SoundSourceSetProperty(), and 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 110 of file OOSoundSource.m.

110 :(uint8_t)count
111{
113}

References _repeatCount, and count.

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

Here is the caller graph for this function:

◆ setSound:

- (void) setSound: (OOSound*) inSound

Definition at line 86 of file OOSoundSource.m.

86 :(OOSound*)sound
87{
88 if (_sound != sound) {
89 [self stop];
90 [_sound autorelease];
91 _sound = [sound retain];
92 }
93}

References _sound, sound, and stop.

Referenced by initWithSound:, OOMusic::playLooped:, playSound:repeatCount:, SoundSourceSetProperty(), 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 255 of file OOSoundSource.m.

255 :(Vector)inVelocity
256{
257}

◆ sound

- (OOSound *) sound

Definition at line 81 of file OOSoundSource.m.

82{
83 return _sound;
84}

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 9968 of file Universe.m.

9968 :(NSString*)key
9969{
9970 return [[[self alloc] initWithCustomSoundKey:key] autorelease];
9971}

◆ sourceWithSound:

+ (instancetype) sourceWithSound: (OOSound*) inSound

Definition at line 36 of file OOSoundSource.m.

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

◆ stop

- (void) stop

Definition at line 156 of file OOSoundSource.m.

157{
159
160 if (nil != _channel) {
161 [_channel setDelegate:[self class]];
162 [_channel stop];
163 _channel = nil;
164
165 [sPlayingSoundSources removeObject:self];
166 [self release];
167 }
168
170}

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

Referenced by dealloc, play, OOMusic::playLooped:, playSound:repeatCount:, setSound:, SoundSourceStop(), 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 172 of file OOSoundSource.m.

173{
174 /* We're not allowed to mutate sPlayingSoundSources during iteration. The
175 normal solution would be to copy the set, but since we know it will
176 end up empty we may as well use the original set and let a new one be
177 set up lazily.
178 */
179 NSMutableSet* playing = sPlayingSoundSources;
181
182 [playing makeObjectsPerformSelector:@selector(stop)];
183 [playing release];
184}

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 45 of file OOSoundSource.h.

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

◆ _gain

- (float) _gain
private

Definition at line 51 of file OOSoundSource.h.

Referenced by gain, init, and setGain:.

◆ _loop

- (BOOL) _loop
private

Definition at line 46 of file OOSoundSource.h.

Referenced by loop, and setLoop:.

◆ _position

- (Vector) _position
private

Definition at line 49 of file OOSoundSource.h.

Referenced by init, position, and setPosition:.

◆ _positional

- (BOOL) _positional
private

Definition at line 50 of file OOSoundSource.h.

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

◆ _remainingCount

- (uint8_t) _remainingCount
private

Definition at line 48 of file OOSoundSource.h.

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

◆ _repeatCount

- (uint8_t) _repeatCount
private

Definition at line 47 of file OOSoundSource.h.

Referenced by repeatCount, and setRepeatCount:.

◆ _sound

- (OOSound*) _sound
private

Definition at line 44 of file OOSoundSource.h.

Referenced by playOrRepeatSound:, setSound:, and sound.


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