/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/Sound/SoundEffect.m

00001 //
00002 //  SoundEffect.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 03/07/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "SoundEffect.h"
00010 
00011 
00012 @implementation SoundEffect
00013 
00014 - (id) init {
00015     self = [super init];
00016     if (self != nil) {
00017         sound = nil;
00018         name = nil;
00019     }
00020     return self;
00021 }
00022 
00023 -(id) initSound:(QTMovie *)newSound withName:(NSString *)newName {
00024     self = [self init];
00025     if (self != nil) {
00026         sound = newSound;
00027         name = newName;
00028     }
00029     return self;
00030 }
00031 
00032 - (bool) loadSoundWithName:(NSString*)soundName {
00033 
00034     // assume in resources/SoundEffects, and an .au file
00035     NSString *pathToResources = [[NSBundle mainBundle] resourcePath];
00036     NSString *pathToSound = [NSString stringWithFormat:@"%@/%@.au", pathToResources, soundName];
00037     [self setName:soundName];    
00038     
00039     [self setSound:[QTMovie movieWithFile:pathToSound error:nil]];
00040     if (sound != nil) {
00041         return YES;
00042     } else {
00043         NSLog(@"SoundEffect.loadSoundWithName %@ failed", soundName);
00044         return NO;
00045     }
00046 }
00047 
00048 -(QTMovie *)sound {
00049     return sound;
00050 }
00051 
00052 -(NSString *)name {
00053     return name;
00054 }
00055 
00056 -(void) setSound:(QTMovie *)newSound {
00057     [sound release];
00058     sound = newSound;
00059     [sound retain];
00060 }
00061 
00062 -(void) setName:(NSString *)newName {
00063     [name release];
00064     name = newName;
00065     [name retain];
00066 }
00067 
00068 -(void) play {
00069     NSLog(@"SoundEffect.play sound %@", name);
00070     [sound play];
00071 }
00072 
00073 -(void) playWithVolume:(float)vol {
00074     [sound setVolume:vol];
00075     [sound gotoBeginning];
00076     NSLog(@"SoundEffect.playWithVolume %f sound %@", vol, name);
00077     [sound play];
00078 }
00079 
00080 -(void) playWithVolume:(float)vol balance:(float)bal {
00081     // assume bal is between -1 and 1
00082     // convert to -128 to 127
00083     short balance = 127 * bal; // sort of..    
00084 
00085     // QTMovie * is actually a void pntr to the raw QT data media handler
00086     MediaSetSoundBalance((void*)sound, balance); 
00087     [sound setVolume:vol];
00088     NSLog(@"SoundEffect.playWithVolume %f balance %f (%d) sound %@", vol, bal, balance, name);
00089     [sound play];
00090 }
00091 
00092 @end

Generated on Fri Jul 28 19:15:23 2006 for MacTrek by  doxygen 1.4.7