Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOMusicController Class Reference

#include <OOMusicController.h>

+ Inheritance diagram for OOMusicController:
+ Collaboration diagram for OOMusicController:

Instance Methods

(void) - playMusicNamed:loop:
 
(void) - playMusicNamed:loop:gain:
 
(void) - playThemeMusic
 
(void) - playDockingMusic
 
(void) - playDockedMusic
 
(void) - setMissionMusic:
 
(void) - playMissionMusic
 
(void) - justStop
 
(void) - stop
 
(void) - stopMusicNamed:
 
(void) - stopThemeMusic
 
(void) - stopDockingMusic
 
(void) - stopMissionMusic
 
(void) - toggleDockingMusic
 
(OOSoundSource *) - soundSource
 
(NSString *) - playingMusic
 
(BOOL) - isPlaying
 
(OOMusicMode- mode
 
(void) - setMode:
 
(id) - init [implementation]
 
(void) - playiTunesPlaylist: [implementation]
 
(void) - pauseiTunes [implementation]
 
(id) - copyWithZone: [implementation]
 
(id) - retain [implementation]
 
(NSUInteger) - retainCount [implementation]
 
(void) - release [implementation]
 
(id) - autorelease [implementation]
 

Class Methods

(OOMusicController *) + sharedController
 
(id) + allocWithZone: [implementation]
 

Private Attributes

OOMusicMode _mode
 
NSString * _missionMusic
 
OOMusic_current
 
uint8_t _special
 

Detailed Description

Definition at line 51 of file OOMusicController.h.

Method Documentation

◆ allocWithZone:

+ (id) allocWithZone: (NSZone *) inZone
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

306 :(NSZone *)inZone
307{
308 if (sSingleton == nil)
309 {
310 sSingleton = [super allocWithZone:inZone];
311 return sSingleton;
312 }
313 return nil;
314}
static OODebugMonitor * sSingleton
return nil

◆ autorelease

- (id) autorelease
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

340{
341 return self;
342}

◆ copyWithZone:

- (id) copyWithZone: (NSZone *) inZone
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

317 :(NSZone *)inZone
318{
319 return self;
320}

◆ init

- (id) init
implementation

Definition at line 32 of file OOMusicController.m.

69{
70 self = [super init];
71 if (self != nil)
72 {
73 NSString *modeString = [[NSUserDefaults standardUserDefaults] stringForKey:@"music mode"];
74 if ([modeString isEqualToString:@"off"]) _mode = kOOMusicOff;
75 else if ([modeString isEqualToString:@"iTunes"]) _mode = kOOMusicITunes;
76 else _mode = kOOMusicOn;
77
78 // Handle unlikely case of taking prefs from iTunes-enabled system to other.
80
81 [self setMissionMusic:@"OoliteTheme.ogg"];
82 }
83
84 return self;
85}
@ kOOMusicOn
@ kOOMusicITunes
@ kOOMusicOff
@ kOOMusicModeMax

◆ isPlaying

- (BOOL) isPlaying

Definition at line 32 of file OOMusicController.m.

240{
241 return [_current isPlaying];
242}

Referenced by PlayerEntity(OOControlsPrivate)::handleAutopilotOn:.

+ Here is the caller graph for this function:

◆ justStop

- (void) justStop

Definition at line 32 of file OOMusicController.m.

171{
172 [_current stop];
173 [_current release];
174 _current = nil;
176}
@ kSpecialNone

◆ mode

Definition at line 32 of file OOMusicController.m.

246{
247 return _mode;
248}

◆ pauseiTunes

- (void) pauseiTunes
implementation

Provided by category OOMusicController(Private).

Definition at line 32 of file OOMusicController.m.

374{
375 NSString *ootunesScriptString = [NSString stringWithFormat:@"try\nignoring application responses\ntell application \"iTunes\" to pause\nend ignoring\nend try"];
376 NSAppleScript *ootunesScript = [[NSAppleScript alloc] initWithSource:ootunesScriptString];
377 NSDictionary *errDict = nil;
378 [ootunesScript executeAndReturnError:&errDict];
379 if (errDict)
380 OOLog(@"sound.music.iTunesIntegration.failed", @"ootunes returned :%@", errDict);
381 [ootunesScript release];
382}
#define OOLog(class, format,...)
Definition OOLogging.h:88

◆ playDockedMusic

- (void) playDockedMusic

Definition at line 32 of file OOMusicController.m.

138{
140
141 if (_mode == kOOMusicITunes)
142 {
143 [self playiTunesPlaylist:@"Oolite-Docked"];
144 }
145 else
146 {
147 [self playMusicNamed:@"OoliteDocked.ogg" loop:NO];
148 }
149}
@ kSpecialDocked

◆ playDockingMusic

- (void) playDockingMusic

Definition at line 32 of file OOMusicController.m.

123{
125
126 if (_mode == kOOMusicITunes)
127 {
128 [self playiTunesPlaylist:@"Oolite-Docking"];
129 }
130 else
131 {
132 [self playMusicNamed:@"BlueDanube.ogg" loop:YES];
133 }
134}
@ kSpecialDocking

◆ playingMusic

- (NSString *) playingMusic

Definition at line 32 of file OOMusicController.m.

234{
235 return [_current name];
236}

◆ playiTunesPlaylist:

- (void) playiTunesPlaylist: (NSString *) playlistName
implementation

Provided by category OOMusicController(Private).

Definition at line 32 of file OOMusicController.m.

350 :(NSString *)playlistName
351{
352 NSString *ootunesScriptString =
353 [NSString stringWithFormat:
354 @"with timeout of 1 second\n"
355 " tell application \"iTunes\"\n"
356 " copy playlist \"%@\" to thePlaylist\n"
357 " if thePlaylist exists then\n"
358 " play some track of thePlaylist\n"
359 " end if\n"
360 " end tell\n"
361 "end timeout",
362 playlistName];
363
364 NSAppleScript *ootunesScript = [[[NSAppleScript alloc] initWithSource:ootunesScriptString] autorelease];
365 NSDictionary *errDict = nil;
366
367 [ootunesScript executeAndReturnError:&errDict];
368 if (errDict)
369 OOLog(@"sound.music.iTunesIntegration.failed", @"ootunes returned :%@", errDict);
370}

◆ playMissionMusic

- (void) playMissionMusic

Definition at line 32 of file OOMusicController.m.

160{
161 if (_missionMusic != nil)
162 {
164 [self playMusicNamed:_missionMusic loop:NO];
165 }
166}
@ kSpecialMission

◆ playMusicNamed:loop:

- (void) playMusicNamed: (NSString *) name
loop: (BOOL) loop 

Definition at line 32 of file OOMusicController.m.

88 :(NSString *)name loop:(BOOL)loop
89{
90 [self playMusicNamed:name loop:loop gain:OO_DEFAULT_SOUNDSOURCE_GAIN];
91}

◆ playMusicNamed:loop:gain:

- (void) playMusicNamed: (NSString *) name
loop: (BOOL) loop
gain: (float) gain 

Definition at line 32 of file OOMusicController.m.

94 :(NSString *)name loop:(BOOL)loop gain:(float)gain
95{
96 if ([self isPlaying] && [name isEqual:[self playingMusic]]) return;
97
98 if (_mode == kOOMusicOn || (_mode == kOOMusicITunes && [name isEqualToString:@"OoliteTheme.ogg"]))
99 {
100 OOMusic *music = [ResourceManager ooMusicNamed:name inFolder:@"Music"];
101 if (music != nil)
102 {
103 [_current stop];
104
105 [music setMusicGain:OOClamp_0_1_f(gain)];
106 [music playLooped:loop];
107
108 [_current release];
109 _current = [music retain];
110 }
111 }
112}
void setMusicGain:(float newValue)
Definition OOALMusic.m:74
void playLooped:(BOOL looped)
Definition OOALMusic.m:90
OOMusic * ooMusicNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

Referenced by SoundStaticPlayMusic().

+ Here is the caller graph for this function:

◆ playThemeMusic

- (void) playThemeMusic

Definition at line 32 of file OOMusicController.m.

116{
118 [self playMusicNamed:@"OoliteTheme.ogg" loop:YES];
119}
@ kSpecialTheme

◆ release

- (void) release
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

336{}

◆ retain

- (id) retain
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

324{
325 return self;
326}

◆ retainCount

- (NSUInteger) retainCount
implementation

Provided by category OOMusicController(Singleton).

Definition at line 32 of file OOMusicController.m.

330{
331 return UINT_MAX;
332}

◆ setMissionMusic:

- (void) setMissionMusic: (NSString *) missionMusicName

Definition at line 32 of file OOMusicController.m.

152 :(NSString *)missionMusicName
153{
154 [_missionMusic autorelease];
155 _missionMusic = [missionMusicName copy];
156}

Referenced by MissionRunScreen().

+ Here is the caller graph for this function:

◆ setMode:

- (void) setMode: (OOMusicMode) mode

Definition at line 32 of file OOMusicController.m.

252{
253 if (mode <= kOOMusicModeMax && _mode != mode)
254 {
255 if (_mode == kOOMusicITunes) [self pauseiTunes];
256 _mode = mode;
257
258 if (_mode == kOOMusicOff) [self stop];
259 else switch (_special)
260 {
261 case kSpecialNone:
262 [self stop];
263 break;
264
265 case kSpecialTheme:
266 [self playThemeMusic];
267 break;
268
269 case kSpecialDocked:
270 [self playDockedMusic];
271 break;
272
273 case kSpecialDocking:
274 [self playDockingMusic];
275 break;
276
277 case kSpecialMission:
278 [self playMissionMusic];
279 break;
280 }
281
282 NSString *modeString = nil;
283 switch (_mode)
284 {
285 case kOOMusicOff: modeString = @"off"; break;
286 case kOOMusicOn: modeString = @"on"; break;
287 case kOOMusicITunes: modeString = @"iTunes"; break;
288 }
289 [[NSUserDefaults standardUserDefaults] setObject:modeString forKey:@"music mode"];
290 }
291}
OOMusicMode
const char int mode
Definition ioapi.h:133

◆ sharedController

+ (OOMusicController *) sharedController

Definition at line 32 of file OOMusicController.m.

58{
59 if (sSingleton == nil)
60 {
61 sSingleton = [[self alloc] init];
62 }
63
64 return sSingleton;
65}

Referenced by PlayerEntity(OOControlsPrivate)::handleAutopilotOn:, MissionRunScreen(), OOSound(OOJavaScriptExtentions)::oo_jsClassName, SoundStaticMusicSoundSource(), and SoundStaticPlayMusic().

+ Here is the caller graph for this function:

◆ soundSource

- (OOSoundSource *) soundSource

Definition at line 32 of file OOMusicController.m.

228{
229 return [_current musicSoundSource];
230}

Referenced by SoundStaticMusicSoundSource().

+ Here is the caller graph for this function:

◆ stop

- (void) stop

Definition at line 32 of file OOMusicController.m.

180{
181 [self justStop];
182
183 if (_mode == kOOMusicITunes)
184 {
185 [self playiTunesPlaylist:@"Oolite-Inflight"];
186 }
187}

Referenced by OOSound(OOJavaScriptExtentions)::oo_jsClassName.

+ Here is the caller graph for this function:

◆ stopDockingMusic

- (void) stopDockingMusic

Definition at line 32 of file OOMusicController.m.

207{
208 if (_special == kSpecialDocking) [self stop];
209}

◆ stopMissionMusic

- (void) stopMissionMusic

Definition at line 32 of file OOMusicController.m.

213{
214 if (_special == kSpecialMission) [self stop];
215}

◆ stopMusicNamed:

- (void) stopMusicNamed: (NSString *) name

Definition at line 32 of file OOMusicController.m.

190 :(NSString *)name
191{
192 if ([name isEqual:[self playingMusic]]) [self stop];
193}

◆ stopThemeMusic

- (void) stopThemeMusic

Definition at line 32 of file OOMusicController.m.

197{
198 if (_special == kSpecialTheme)
199 {
200 [self justStop];
201 [self playDockedMusic];
202 }
203}

◆ toggleDockingMusic

- (void) toggleDockingMusic

Definition at line 32 of file OOMusicController.m.

219{
220 if (_mode != kOOMusicOn) return;
221
222 if (![self isPlaying]) [self playDockingMusic];
223 else if (_special == kSpecialDocking) [self stop];
224}

Referenced by PlayerEntity(OOControlsPrivate)::handleAutopilotOn:.

+ Here is the caller graph for this function:

Member Data Documentation

◆ _current

- (OOMusic*) _current
private

Definition at line 56 of file OOMusicController.h.

◆ _missionMusic

- (NSString*) _missionMusic
private

Definition at line 55 of file OOMusicController.h.

◆ _mode

- (OOMusicMode) _mode
private

Definition at line 54 of file OOMusicController.h.

◆ _special

- (uint8_t) _special
private

Definition at line 57 of file OOMusicController.h.


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