engine/src/SoundManager/SoundManagerIos.mm
2013-01-19 20:02:34 +00:00

132 lines
3.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SoundManagerIos.mm
// Halibut Engine
//
// Created by vvv ооо on 21.07.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <string>
#include <map>
#import <Foundation/Foundation.h>
#import "PASoundMgr.h"
#import "PASoundListener.h"
#import "PASoundSource.h"
#include "include/Utils/Utils.h"
#include "include/SoundManager/SoundManagerIos.h"
namespace SE
{
std::map<std::string, PASoundSource*> AudioSourceMap;
TSoundManagerIos::TSoundManagerIos()
{
[PASoundMgr sharedSoundManager];
[[[PASoundMgr sharedSoundManager] listener] setPosition:CGPointMake(0, 0)];
}
TSoundManagerIos::~TSoundManagerIos()
{
for (std::map<std::string, PASoundSource*>::iterator i = AudioSourceMap.begin(); i != AudioSourceMap.end(); ++i)
{
//[i->second release];
}
AudioSourceMap.clear();
}
void TSoundManagerIos::LoadSound(const std::string& soundFileName)
{
LoadMusic(soundFileName);
}
void TSoundManagerIos::PlaySound(const std::string& soundName)
{
PlayMusic(soundName);
}
void TSoundManagerIos::LoadMusicLooped(const std::string& musicFileName)
{
//Hack for ios, see below
std::string musicName = GetFileName(musicFileName);
std::string fullFileName = GetPathToResources() + musicFileName;
NSString* nsFileName = [NSString stringWithCString:fullFileName.c_str() encoding:NSUTF8StringEncoding];
NSString* nsFileNameWithoutExt = [nsFileName stringByDeletingPathExtension];
NSString* nsFileExt = [nsFileName pathExtension];
if (AudioSourceMap.count(musicName) > 0)
{
//[AudioSourceMap[musicName] release];
}
/*AudioSourceMap[musicFileName] = [[[PASoundMgr sharedSoundManager] addSound:@"trance-loop" withExtension:@"ogg" position:CGPointMake(0, 0) looped:NO] retain];*/
AudioSourceMap[musicName] = [[PASoundMgr sharedSoundManager] addSound:nsFileNameWithoutExt withExtension:nsFileExt position:CGPointMake(0, 0) looped:YES];
}
void TSoundManagerIos::LoadMusic(const std::string& musicFileName)
{
std::string musicName = GetFileName(musicFileName);
std::string fullFileName = GetPathToResources() + musicFileName;
NSString* nsFileName = [NSString stringWithCString:fullFileName.c_str() encoding:NSUTF8StringEncoding];
NSString* nsFileNameWithoutExt = [nsFileName stringByDeletingPathExtension];
NSString* nsFileExt = [nsFileName pathExtension];
if (AudioSourceMap.count(musicName) > 0)
{
//[AudioSourceMap[musicName] release];
}
/*AudioSourceMap[musicFileName] = [[[PASoundMgr sharedSoundManager] addSound:@"trance-loop" withExtension:@"ogg" position:CGPointMake(0, 0) looped:NO] retain];*/
AudioSourceMap[musicName] = [[PASoundMgr sharedSoundManager] addSound:nsFileNameWithoutExt withExtension:nsFileExt position:CGPointMake(0, 0) looped:NO];
}
void TSoundManagerIos::PlayMusic(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
AudioSourceMap[musicName].looped = false;
[AudioSourceMap[musicName] playAtListenerPosition];
}
void TSoundManagerIos::PlayMusicLooped(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
AudioSourceMap[musicName].looped = true;
[AudioSourceMap[musicName] playAtListenerPosition];
}
void TSoundManagerIos::StopMusic(const std::string& musicName)
{
if (AudioSourceMap.count(musicName) == 0)
{
throw ErrorToLog("Sound or music not exists: "+musicName);
}
[AudioSourceMap[musicName] stop];
}
} //namespace SE