/libs/ObjectAL/OpenAL/ALListener.m
Objective C | 224 lines | 164 code | 34 blank | 26 comment | 8 complexity | a51199fa28739f0fb6966d48e3afd45d MD5 | raw file
Possible License(s): Apache-2.0
1// 2// ALListener.m 3// ObjectAL 4// 5// Created by Karl Stenerud on 10-01-07. 6// 7// Copyright 2009 Karl Stenerud 8// 9// Licensed under the Apache License, Version 2.0 (the "License"); 10// you may not use this file except in compliance with the License. 11// You may obtain a copy of the License at 12// 13// http://www.apache.org/licenses/LICENSE-2.0 14// 15// Unless required by applicable law or agreed to in writing, software 16// distributed under the License is distributed on an "AS IS" BASIS, 17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18// See the License for the specific language governing permissions and 19// limitations under the License. 20// 21// Note: You are NOT required to make the license available from within your 22// iOS application. Including it in your project is sufficient. 23// 24// Attribution is not required, but appreciated :) 25// 26 27#import "ALListener.h" 28#import "ObjectALMacros.h" 29#import "ALWrapper.h" 30#import "ALContext.h" 31 32 33@implementation ALListener 34 35#pragma mark Object Management 36 37+ (id) listenerForContext:(ALContext*) context 38{ 39 return [[[self alloc] initWithContext:context] autorelease]; 40} 41 42- (id) initWithContext:(ALContext*) contextIn 43{ 44 if(nil != (self = [super init])) 45 { 46 suspendHandler = [[OALSuspendHandler alloc] initWithTarget:nil selector:nil]; 47 48 context = contextIn; 49 gain = 1.0f; 50 } 51 return self; 52} 53 54- (void) dealloc 55{ 56 [suspendHandler release]; 57 [super dealloc]; 58} 59 60#pragma mark Properties 61 62@synthesize context; 63 64- (bool) muted 65{ 66 OPTIONALLY_SYNCHRONIZED(self) 67 { 68 return muted; 69 } 70} 71 72- (void) setMuted:(bool) value 73{ 74 OPTIONALLY_SYNCHRONIZED(self) 75 { 76 if(self.suspended) 77 { 78 OAL_LOG_DEBUG(@"%@: Called mutator on suspended object", self); 79 return; 80 } 81 82 muted = value; 83 // Force a re-evaluation of gain. 84 [self setGain:gain]; 85 } 86} 87 88- (float) gain 89{ 90 OPTIONALLY_SYNCHRONIZED(self) 91 { 92 return gain; 93 } 94} 95 96- (void) setGain:(float) value 97{ 98 OPTIONALLY_SYNCHRONIZED(self) 99 { 100 if(self.suspended) 101 { 102 OAL_LOG_DEBUG(@"%@: Called mutator on suspended object", self); 103 return; 104 } 105 106 gain = value; 107 if(muted) 108 { 109 value = 0; 110 } 111 [ALWrapper listenerf:AL_GAIN value:value]; 112 } 113} 114 115- (ALOrientation) orientation 116{ 117 ALOrientation result; 118 OPTIONALLY_SYNCHRONIZED(self) 119 { 120 [ALWrapper getListenerfv:AL_ORIENTATION values:(float*)&result]; 121 } 122 return result; 123} 124 125- (void) setOrientation:(ALOrientation) value 126{ 127 OPTIONALLY_SYNCHRONIZED(self) 128 { 129 if(self.suspended) 130 { 131 OAL_LOG_DEBUG(@"%@: Called mutator on suspended object", self); 132 return; 133 } 134 135 [ALWrapper listenerfv:AL_ORIENTATION values:(float*)&value]; 136 } 137} 138 139- (ALPoint) position 140{ 141 ALPoint result; 142 OPTIONALLY_SYNCHRONIZED(self) 143 { 144 [ALWrapper getListener3f:AL_POSITION v1:&result.x v2:&result.y v3:&result.z]; 145 } 146 return result; 147} 148 149- (void) setPosition:(ALPoint) value 150{ 151 OPTIONALLY_SYNCHRONIZED(self) 152 { 153 if(self.suspended) 154 { 155 OAL_LOG_DEBUG(@"%@: Called mutator on suspended object", self); 156 return; 157 } 158 159 [ALWrapper listener3f:AL_POSITION v1:value.x v2:value.y v3:value.z]; 160 } 161} 162 163- (ALVector) velocity 164{ 165 ALVector result; 166 OPTIONALLY_SYNCHRONIZED(self) 167 { 168 [ALWrapper getListener3f:AL_VELOCITY v1:&result.x v2:&result.y v3:&result.z]; 169 } 170 return result; 171} 172 173- (void) setVelocity:(ALVector) value 174{ 175 OPTIONALLY_SYNCHRONIZED(self) 176 { 177 if(self.suspended) 178 { 179 OAL_LOG_DEBUG(@"%@: Called mutator on suspended object", self); 180 return; 181 } 182 183 [ALWrapper listener3f:AL_VELOCITY v1:value.x v2:value.y v3:value.z]; 184 } 185} 186 187#pragma mark Suspend Handler 188 189- (void) addSuspendListener:(id<OALSuspendListener>) listener 190{ 191 [suspendHandler addSuspendListener:listener]; 192} 193 194- (void) removeSuspendListener:(id<OALSuspendListener>) listener 195{ 196 [suspendHandler removeSuspendListener:listener]; 197} 198 199- (bool) manuallySuspended 200{ 201 return suspendHandler.manuallySuspended; 202} 203 204- (void) setManuallySuspended:(bool) value 205{ 206 suspendHandler.manuallySuspended = value; 207} 208 209- (bool) interrupted 210{ 211 return suspendHandler.interrupted; 212} 213 214- (void) setInterrupted:(bool) value 215{ 216 suspendHandler.interrupted = value; 217} 218 219- (bool) suspended 220{ 221 return suspendHandler.suspended; 222} 223 224@end