project_files/HedgewarsMobile/Classes/AudioManagerController.m
author koda
Wed, 28 Mar 2012 01:56:42 +0200
changeset 6832 fae8fd118da9
parent 6700 e04da46ee43c
child 6869 a187c280dd3d
permissions -rw-r--r--
dates are no more!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     1
/*
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
6700
e04da46ee43c the most important commit of the year
koda
parents: 6667
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     4
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     8
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    13
 *
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    17
 */
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    18
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    19
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    20
#import "AudioManagerController.h"
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    21
#import "AVFoundation/AVAudioPlayer.h"
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    22
#import <AudioToolbox/AudioToolbox.h>
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    23
#import "MXAudioPlayerFadeOperation.h"
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    24
6832
fae8fd118da9 dates are no more!
koda
parents: 6700
diff changeset
    25
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    26
static AVAudioPlayer *backgroundMusic = nil;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    27
static SystemSoundID clickSound = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    28
static SystemSoundID backSound = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    29
static SystemSoundID selSound = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    30
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    31
static NSOperationQueue *audioFaderQueue = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    32
static MXAudioPlayerFadeOperation *fadeIn = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    33
static MXAudioPlayerFadeOperation *fadeOut = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    34
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    35
@implementation AudioManagerController
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    36
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    37
#pragma mark -
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    38
#pragma mark background music control
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    39
+(void) loadBackgroundMusic {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    40
    NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    41
    backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    42
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    43
    backgroundMusic.delegate = nil;
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    44
    backgroundMusic.volume = 0;
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    45
    backgroundMusic.numberOfLoops = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    46
    [backgroundMusic prepareToPlay];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    47
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    48
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    49
+(void) playBackgroundMusic {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    50
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    51
        return;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    52
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    53
    if (backgroundMusic == nil)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    54
        [AudioManagerController loadBackgroundMusic];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    55
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    56
    backgroundMusic.volume = 0.45f;
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    57
    [backgroundMusic play];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    58
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    59
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    60
+(void) pauseBackgroundMusic {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    61
    [backgroundMusic pause];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    62
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    63
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    64
+(void) stopBackgroundMusic {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    65
    [backgroundMusic stop];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    66
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    67
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    68
+(void) fadeOutBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    69
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    70
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    71
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    72
    if (audioFaderQueue == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    73
        audioFaderQueue = [[NSOperationQueue alloc] init];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    74
    if (backgroundMusic == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    75
        [AudioManagerController loadBackgroundMusic];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    76
    if (fadeOut == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    77
        fadeOut = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:backgroundMusic toVolume:0.0 overDuration:3.0];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    78
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    79
    [audioFaderQueue addOperation:fadeOut];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    80
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    81
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    82
+(void) fadeInBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    83
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    84
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    85
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    86
    if (audioFaderQueue == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    87
        audioFaderQueue = [[NSOperationQueue alloc] init];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    88
    if (backgroundMusic == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    89
        [AudioManagerController loadBackgroundMusic];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    90
    if (fadeIn == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    91
        fadeIn = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:backgroundMusic toVolume:0.45 overDuration:2.0];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    92
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    93
    [audioFaderQueue addOperation:fadeIn];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    94
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    95
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    96
#pragma mark -
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    97
#pragma mark sound effects control
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    98
+(SystemSoundID) loadSound:(NSString *)snd {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
    99
    // get the filename of the sound file:
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   100
    NSString *path = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],snd];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   101
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   102
    // declare a system sound id and get a URL for the sound file
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   103
    SystemSoundID soundID;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   104
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   105
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   106
    // use audio sevices to create and play the sound
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   107
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   108
    return soundID;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   109
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   110
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   111
+(void) playClickSound {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   112
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   113
        return;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   114
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   115
    if (clickSound == -1)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   116
        clickSound = [AudioManagerController loadSound:@"clickSound.wav"];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   117
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   118
    AudioServicesPlaySystemSound(clickSound);
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   119
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   120
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   121
+(void) playBackSound {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   122
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   123
        return;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   124
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   125
    if (backSound == -1)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   126
        backSound = [AudioManagerController loadSound:@"backSound.wav"];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   127
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   128
    AudioServicesPlaySystemSound(backSound);
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   129
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   130
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   131
+(void) playSelectSound {
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   132
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   133
        return;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   134
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   135
    if (selSound == -1)
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   136
        selSound = [AudioManagerController loadSound:@"selSound.wav"];
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   137
    
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   138
    AudioServicesPlaySystemSound(selSound);
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   139
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   140
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   141
#pragma mark -
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   142
#pragma mark memory management
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6017
diff changeset
   143
+(void) releaseCache {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   144
    [backgroundMusic stop];
6017
24631fd2fb9e better memory cleanup for audiomanager and position of lower stats button
koda
parents: 6006
diff changeset
   145
    [backgroundMusic release], backgroundMusic = nil;
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   146
    [fadeOut release], fadeOut = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   147
    [fadeIn release], fadeIn = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   148
    [audioFaderQueue release], audioFaderQueue = nil;
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   149
    AudioServicesDisposeSystemSoundID(clickSound), clickSound = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   150
    AudioServicesDisposeSystemSoundID(backSound), backSound = -1;
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   151
    AudioServicesDisposeSystemSoundID(selSound), selSound = -1;
6017
24631fd2fb9e better memory cleanup for audiomanager and position of lower stats button
koda
parents: 6006
diff changeset
   152
    MSG_MEMCLEAN();
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   153
}
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   154
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff changeset
   155
@end