Oolite
Loading...
Searching...
No Matches
OOALMusic.m
Go to the documentation of this file.
1
/*
2
3
OOALMusic.m
4
5
6
OOALSound - OpenAL sound implementation for Oolite.
7
Copyright (C) 2005-2013 Jens Ayton
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in all
17
copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
SOFTWARE.
26
27
*/
28
29
#import "
OOALMusic.h
"
30
31
static
OOMusic
*
sPlayingMusic
=
nil
;
32
static
OOSoundSource
*
sMusicSource
=
nil
;
33
34
@implementation
OOMusic
35
36
+ (id)allocWithZone:(NSZone*)inZone
37
{
38
return
NSAllocateObject([
OOMusic
class
], 0, inZone);
39
}
40
41
- (void)
dealloc
42
{
43
if
(
sPlayingMusic
==
self
)
44
[
self
stop
];
45
[
sound
release];
46
47
[
super
dealloc];
48
}
49
50
- (id)initWithContentsOfFile:(NSString*)inPath
51
{
52
self
= [
super
init
];
53
if
(
nil
!=
self
) {
54
sound
= [[
OOSound
alloc] initWithContentsOfFile:inPath];
55
if
(
nil
==
sound
) {
56
[
self
release];
57
self
=
nil
;
58
}
59
}
60
61
return
self
;
62
}
63
64
- (NSString*)
name
65
{
66
return
[
sound
name
];
67
}
68
69
- (void)setMusicGain:(
float
)newValue
70
{
71
if
(
nil
!=
sMusicSource
) {
72
[
sMusicSource
setGain
:newValue];
73
}
74
}
75
76
- (float)
musicGain
77
{
78
if
(
nil
==
sMusicSource
)
79
return
0.0f;
80
return
[
sMusicSource
gain
];
81
}
82
83
- (void)playLooped:(BOOL)inLoop
84
{
85
if
(
sPlayingMusic
!=
self
) {
86
if
(
nil
==
sMusicSource
) {
87
sMusicSource
= [[
OOSoundSource
alloc] init];
88
}
89
[
sMusicSource
stop
];
90
[
sMusicSource
setLoop
:inLoop];
91
[
sMusicSource
setSound
:sound];
92
[
sMusicSource
play
];
93
94
sPlayingMusic
=
self
;
95
}
96
}
97
98
- (
OOSoundSource
*)
musicSoundSource
99
{
100
return
sMusicSource
;
101
}
102
103
- (BOOL)
isPlaying
104
{
105
return
sPlayingMusic
==
self
&& [
sMusicSource
isPlaying
];
106
}
107
108
- (void)
stop
109
{
110
if
(
sPlayingMusic
==
self
) {
111
sPlayingMusic
=
nil
;
112
[
sMusicSource
stop
];
113
[
sMusicSource
setSound
:nil];
114
}
115
}
116
117
@end
OOALMusic.h
sPlayingMusic
static OOMusic * sPlayingMusic
Definition
OOALMusic.m:31
sMusicSource
static OOSoundSource * sMusicSource
Definition
OOALMusic.m:32
nil
return nil
Definition
OOProbabilitySet.m:393
OOMusic
Definition
OOALMusic.h:36
-[OOMusic isPlaying]
BOOL isPlaying()
Definition
OOALMusic.m:103
-[OOMusic musicSoundSource]
OOSoundSource * musicSoundSource()
Definition
OOALMusic.m:98
OOMusic::sound
OOSound * sound
Definition
OOALMusic.h:38
-[OOMusic name]
NSString * name()
Definition
OOALMusic.m:64
-[OOMusic stop]
void stop()
Definition
OOALMusic.m:108
-[OOMusic dealloc]
void dealloc()
Definition
OOALMusic.m:41
-[OOMusic musicGain]
float musicGain()
Definition
OOALMusic.m:76
OOSoundSource
Definition
OOSoundSource.h:42
-[OOSoundSource isPlaying]
BOOL isPlaying()
Definition
OOSoundSource.m:115
-[OOSoundSource gain]
float gain()
Definition
OOSoundSource.m:249
-[OOSoundSource setLoop:]
void setLoop:(BOOL inLoop)
Definition
OOSoundSource.m:100
-[OOSoundSource setGain:]
void setGain:(float gain)
Definition
OOSoundSource.m:241
-[OOSoundSource play]
void play()
Definition
OOSoundSource.m:120
-[OOSoundSource setSound:]
void setSound:(OOSound *inSound)
Definition
OOSoundSource.m:86
-[OOSoundSource stop]
void stop()
Definition
OOSoundSource.m:156
OOSound
Definition
OOALSound.h:31
-[OOSound init]
id init()
Definition
OOALSound.m:84
-[OOSound name]
NSString * name()
Definition
OOALSound.m:130
src
Core
OOALMusic.m
Generated by
1.15.0