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