// // SoundManagerIos.mm // Halibut Engine // // Created by vvv ооо on 21.07.12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #include #include #include #import #import "PASoundMgr.h" #import "PASoundListener.h" #import "PASoundSource.h" #include "include/Utils/Utils.h" #include "include/SoundManager/SoundManagerIos.h" namespace SE { std::map AudioSourceMap; TSoundManagerIos::TSoundManagerIos() { [PASoundMgr sharedSoundManager]; [[[PASoundMgr sharedSoundManager] listener] setPosition:CGPointMake(0, 0)]; } TSoundManagerIos::~TSoundManagerIos() { for (std::map::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