project_files/HedgewarsMobile/Classes/AudioManagerController.m
author koda
Sun, 19 Feb 2012 00:39:44 +0100
changeset 6717 080e716e6990
parent 6700 e04da46ee43c
child 6832 fae8fd118da9
permissions -rw-r--r--
missions page rotates correctly
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
 *
6700
e04da46ee43c the most important commit of the year
koda
parents: 6667
diff changeset
    18
 * File created on 23/09/2012.
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
    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
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
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 "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
    23
#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
    24
#import <AudioToolbox/AudioToolbox.h>
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    25
#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
    26
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 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
    28
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
    29
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
    30
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
    31
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    32
static NSOperationQueue *audioFaderQueue = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    33
static MXAudioPlayerFadeOperation *fadeIn = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    34
static MXAudioPlayerFadeOperation *fadeOut = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    35
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    36
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
    37
@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
    38
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
#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
    40
#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
    41
+(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
    42
    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
    43
    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
    44
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.delegate = nil;
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    46
    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
    47
    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
    48
    [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
    49
}
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
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
+(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
    52
    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
    53
        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
    54
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
    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
    56
        [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
    57
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    58
    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
    59
    [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
    60
}
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
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
+(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
    63
    [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
    64
}
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
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
+(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
    67
    [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
    68
}
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
    69
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    70
+(void) fadeOutBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    71
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    72
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    73
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    74
    if (audioFaderQueue == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    75
        audioFaderQueue = [[NSOperationQueue alloc] init];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    76
    if (backgroundMusic == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    77
        [AudioManagerController loadBackgroundMusic];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    78
    if (fadeOut == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    79
        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
    80
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    81
    [audioFaderQueue addOperation:fadeOut];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    82
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    83
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    84
+(void) fadeInBackgroundMusic {
6667
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    85
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO)
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    86
        return;
142fe596e75e ios check for music preference also for fading methods
koda
parents: 6656
diff changeset
    87
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    88
    if (audioFaderQueue == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    89
        audioFaderQueue = [[NSOperationQueue alloc] init];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    90
    if (backgroundMusic == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    91
        [AudioManagerController loadBackgroundMusic];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    92
    if (fadeIn == nil)
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    93
        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
    94
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    95
    [audioFaderQueue addOperation:fadeIn];
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    96
}
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
    97
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
    98
#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
    99
#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
   100
+(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
   101
    // 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
   102
    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
   103
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
    // 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
   105
    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
   106
    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
   107
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
    // 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
   109
    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
   110
    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
   111
}
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
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
+(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
   114
    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
   115
        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
   116
    
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
    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
   118
        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
   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
    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
   121
}
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
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
+(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
   124
    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
   125
        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
   126
    
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
    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
   128
        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
   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
    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
   131
}
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
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
+(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
   134
    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
   135
        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
   136
    
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
    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
   138
        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
   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
    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
   141
}
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
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
   143
#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
   144
#pragma mark memory management
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6017
diff changeset
   145
+(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
   146
    [backgroundMusic stop];
6017
24631fd2fb9e better memory cleanup for audiomanager and position of lower stats button
koda
parents: 6006
diff changeset
   147
    [backgroundMusic release], backgroundMusic = nil;
6656
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   148
    [fadeOut release], fadeOut = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   149
    [fadeIn release], fadeIn = nil;
6aeaba3ee584 ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents: 6208
diff changeset
   150
    [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
   151
    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
   152
    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
   153
    AudioServicesDisposeSystemSoundID(selSound), selSound = -1;
6017
24631fd2fb9e better memory cleanup for audiomanager and position of lower stats button
koda
parents: 6006
diff changeset
   154
    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
   155
}
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
   156
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
   157
@end