Adds Cocos libraries.
authordsc <david.schoonover@gmail.com>
Wed, 8 Jun 2011 23:08:20 +0000 (16:08 -0700)
committerdsc <david.schoonover@gmail.com>
Wed, 8 Jun 2011 23:08:20 +0000 (16:08 -0700)
198 files changed:
libs/CocosDenshion/CDAudioManager.h [new file with mode: 0644]
libs/CocosDenshion/CDAudioManager.m [new file with mode: 0644]
libs/CocosDenshion/CDConfig.h [new file with mode: 0644]
libs/CocosDenshion/CDOpenALSupport.h [new file with mode: 0644]
libs/CocosDenshion/CDOpenALSupport.m [new file with mode: 0644]
libs/CocosDenshion/CocosDenshion.h [new file with mode: 0644]
libs/CocosDenshion/CocosDenshion.m [new file with mode: 0644]
libs/CocosDenshion/SimpleAudioEngine.h [new file with mode: 0644]
libs/CocosDenshion/SimpleAudioEngine.m [new file with mode: 0644]
libs/FontLabel/FontLabel.h [new file with mode: 0644]
libs/FontLabel/FontLabel.m [new file with mode: 0644]
libs/FontLabel/FontLabelStringDrawing.h [new file with mode: 0644]
libs/FontLabel/FontLabelStringDrawing.m [new file with mode: 0644]
libs/FontLabel/FontManager.h [new file with mode: 0644]
libs/FontLabel/FontManager.m [new file with mode: 0644]
libs/FontLabel/ZAttributedString.h [new file with mode: 0644]
libs/FontLabel/ZAttributedString.m [new file with mode: 0644]
libs/FontLabel/ZAttributedStringPrivate.h [new file with mode: 0644]
libs/FontLabel/ZFont.h [new file with mode: 0644]
libs/FontLabel/ZFont.m [new file with mode: 0644]
libs/TouchJSON/CDataScanner.h [new file with mode: 0644]
libs/TouchJSON/CDataScanner.m [new file with mode: 0644]
libs/TouchJSON/Extensions/CDataScanner_Extensions.h [new file with mode: 0644]
libs/TouchJSON/Extensions/CDataScanner_Extensions.m [new file with mode: 0644]
libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.h [new file with mode: 0644]
libs/TouchJSON/Extensions/NSDictionary_JSONExtensions.m [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONDeserializer.h [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONDeserializer.m [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONScanner.h [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONScanner.m [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONSerializer.h [new file with mode: 0644]
libs/TouchJSON/JSON/CJSONSerializer.m [new file with mode: 0644]
libs/TouchJSON/JSON/JSONRepresentation.h [new file with mode: 0644]
libs/cocos2d/CCAction.h [new file with mode: 0644]
libs/cocos2d/CCAction.m [new file with mode: 0644]
libs/cocos2d/CCActionCamera.h [new file with mode: 0644]
libs/cocos2d/CCActionCamera.m [new file with mode: 0644]
libs/cocos2d/CCActionEase.h [new file with mode: 0644]
libs/cocos2d/CCActionEase.m [new file with mode: 0644]
libs/cocos2d/CCActionGrid.h [new file with mode: 0644]
libs/cocos2d/CCActionGrid.m [new file with mode: 0644]
libs/cocos2d/CCActionGrid3D.h [new file with mode: 0644]
libs/cocos2d/CCActionGrid3D.m [new file with mode: 0644]
libs/cocos2d/CCActionInstant.h [new file with mode: 0644]
libs/cocos2d/CCActionInstant.m [new file with mode: 0644]
libs/cocos2d/CCActionInterval.h [new file with mode: 0644]
libs/cocos2d/CCActionInterval.m [new file with mode: 0644]
libs/cocos2d/CCActionManager.h [new file with mode: 0644]
libs/cocos2d/CCActionManager.m [new file with mode: 0644]
libs/cocos2d/CCActionPageTurn3D.h [new file with mode: 0644]
libs/cocos2d/CCActionPageTurn3D.m [new file with mode: 0644]
libs/cocos2d/CCActionProgressTimer.h [new file with mode: 0644]
libs/cocos2d/CCActionProgressTimer.m [new file with mode: 0644]
libs/cocos2d/CCActionTiledGrid.h [new file with mode: 0644]
libs/cocos2d/CCActionTiledGrid.m [new file with mode: 0644]
libs/cocos2d/CCActionTween.h [new file with mode: 0644]
libs/cocos2d/CCActionTween.m [new file with mode: 0644]
libs/cocos2d/CCAnimation.h [new file with mode: 0644]
libs/cocos2d/CCAnimation.m [new file with mode: 0644]
libs/cocos2d/CCAnimationCache.h [new file with mode: 0644]
libs/cocos2d/CCAnimationCache.m [new file with mode: 0644]
libs/cocos2d/CCAtlasNode.h [new file with mode: 0644]
libs/cocos2d/CCAtlasNode.m [new file with mode: 0644]
libs/cocos2d/CCBlockSupport.h [new file with mode: 0644]
libs/cocos2d/CCBlockSupport.m [new file with mode: 0644]
libs/cocos2d/CCCamera.h [new file with mode: 0644]
libs/cocos2d/CCCamera.m [new file with mode: 0644]
libs/cocos2d/CCConfiguration.h [new file with mode: 0644]
libs/cocos2d/CCConfiguration.m [new file with mode: 0644]
libs/cocos2d/CCDirector.h [new file with mode: 0644]
libs/cocos2d/CCDirector.m [new file with mode: 0644]
libs/cocos2d/CCDrawingPrimitives.h [new file with mode: 0644]
libs/cocos2d/CCDrawingPrimitives.m [new file with mode: 0644]
libs/cocos2d/CCGrabber.h [new file with mode: 0644]
libs/cocos2d/CCGrabber.m [new file with mode: 0644]
libs/cocos2d/CCGrid.h [new file with mode: 0644]
libs/cocos2d/CCGrid.m [new file with mode: 0644]
libs/cocos2d/CCLabelAtlas.h [new file with mode: 0644]
libs/cocos2d/CCLabelAtlas.m [new file with mode: 0644]
libs/cocos2d/CCLabelBMFont.h [new file with mode: 0644]
libs/cocos2d/CCLabelBMFont.m [new file with mode: 0644]
libs/cocos2d/CCLabelTTF.h [new file with mode: 0644]
libs/cocos2d/CCLabelTTF.m [new file with mode: 0644]
libs/cocos2d/CCLayer.h [new file with mode: 0644]
libs/cocos2d/CCLayer.m [new file with mode: 0644]
libs/cocos2d/CCMenu.h [new file with mode: 0644]
libs/cocos2d/CCMenu.m [new file with mode: 0644]
libs/cocos2d/CCMenuItem.h [new file with mode: 0644]
libs/cocos2d/CCMenuItem.m [new file with mode: 0644]
libs/cocos2d/CCMotionStreak.h [new file with mode: 0644]
libs/cocos2d/CCMotionStreak.m [new file with mode: 0644]
libs/cocos2d/CCNode.h [new file with mode: 0644]
libs/cocos2d/CCNode.m [new file with mode: 0644]
libs/cocos2d/CCParallaxNode.h [new file with mode: 0644]
libs/cocos2d/CCParallaxNode.m [new file with mode: 0644]
libs/cocos2d/CCParticleExamples.h [new file with mode: 0644]
libs/cocos2d/CCParticleExamples.m [new file with mode: 0644]
libs/cocos2d/CCParticleSystem.h [new file with mode: 0644]
libs/cocos2d/CCParticleSystem.m [new file with mode: 0644]
libs/cocos2d/CCParticleSystemPoint.h [new file with mode: 0644]
libs/cocos2d/CCParticleSystemPoint.m [new file with mode: 0644]
libs/cocos2d/CCParticleSystemQuad.h [new file with mode: 0644]
libs/cocos2d/CCParticleSystemQuad.m [new file with mode: 0644]
libs/cocos2d/CCProgressTimer.h [new file with mode: 0644]
libs/cocos2d/CCProgressTimer.m [new file with mode: 0644]
libs/cocos2d/CCProtocols.h [new file with mode: 0644]
libs/cocos2d/CCRenderTexture.h [new file with mode: 0644]
libs/cocos2d/CCRenderTexture.m [new file with mode: 0644]
libs/cocos2d/CCRibbon.h [new file with mode: 0644]
libs/cocos2d/CCRibbon.m [new file with mode: 0644]
libs/cocos2d/CCScene.h [new file with mode: 0644]
libs/cocos2d/CCScene.m [new file with mode: 0644]
libs/cocos2d/CCScheduler.h [new file with mode: 0644]
libs/cocos2d/CCScheduler.m [new file with mode: 0644]
libs/cocos2d/CCSprite.h [new file with mode: 0644]
libs/cocos2d/CCSprite.m [new file with mode: 0644]
libs/cocos2d/CCSpriteBatchNode.h [new file with mode: 0644]
libs/cocos2d/CCSpriteBatchNode.m [new file with mode: 0644]
libs/cocos2d/CCSpriteFrame.h [new file with mode: 0644]
libs/cocos2d/CCSpriteFrame.m [new file with mode: 0644]
libs/cocos2d/CCSpriteFrameCache.h [new file with mode: 0644]
libs/cocos2d/CCSpriteFrameCache.m [new file with mode: 0644]
libs/cocos2d/CCTMXLayer.h [new file with mode: 0644]
libs/cocos2d/CCTMXLayer.m [new file with mode: 0644]
libs/cocos2d/CCTMXObjectGroup.h [new file with mode: 0644]
libs/cocos2d/CCTMXObjectGroup.m [new file with mode: 0644]
libs/cocos2d/CCTMXTiledMap.h [new file with mode: 0644]
libs/cocos2d/CCTMXTiledMap.m [new file with mode: 0644]
libs/cocos2d/CCTMXXMLParser.h [new file with mode: 0644]
libs/cocos2d/CCTMXXMLParser.m [new file with mode: 0644]
libs/cocos2d/CCTexture2D.h [new file with mode: 0644]
libs/cocos2d/CCTexture2D.m [new file with mode: 0644]
libs/cocos2d/CCTextureAtlas.h [new file with mode: 0644]
libs/cocos2d/CCTextureAtlas.m [new file with mode: 0644]
libs/cocos2d/CCTextureCache.h [new file with mode: 0644]
libs/cocos2d/CCTextureCache.m [new file with mode: 0644]
libs/cocos2d/CCTexturePVR.h [new file with mode: 0644]
libs/cocos2d/CCTexturePVR.m [new file with mode: 0644]
libs/cocos2d/CCTileMapAtlas.h [new file with mode: 0644]
libs/cocos2d/CCTileMapAtlas.m [new file with mode: 0644]
libs/cocos2d/CCTransition.h [new file with mode: 0644]
libs/cocos2d/CCTransition.m [new file with mode: 0644]
libs/cocos2d/CCTransitionPageTurn.h [new file with mode: 0644]
libs/cocos2d/CCTransitionPageTurn.m [new file with mode: 0644]
libs/cocos2d/CCTransitionRadial.h [new file with mode: 0644]
libs/cocos2d/CCTransitionRadial.m [new file with mode: 0644]
libs/cocos2d/Platforms/CCGL.h [new file with mode: 0644]
libs/cocos2d/Platforms/CCNS.h [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/CCDirectorMac.h [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/CCDirectorMac.m [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/CCEventDispatcher.h [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/CCEventDispatcher.m [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/MacGLView.h [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/MacGLView.m [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/MacWindow.h [new file with mode: 0644]
libs/cocos2d/Platforms/Mac/MacWindow.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCDirectorIOS.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCDirectorIOS.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCTouchDispatcher.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCTouchHandler.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/CCTouchHandler.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/EAGLView.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/EAGLView.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/ES1Renderer.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/ES1Renderer.m [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/ESRenderer.h [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/glu.c [new file with mode: 0644]
libs/cocos2d/Platforms/iOS/glu.h [new file with mode: 0644]
libs/cocos2d/Support/CCArray.h [new file with mode: 0644]
libs/cocos2d/Support/CCArray.m [new file with mode: 0644]
libs/cocos2d/Support/CCFileUtils.h [new file with mode: 0644]
libs/cocos2d/Support/CCFileUtils.m [new file with mode: 0644]
libs/cocos2d/Support/CCProfiling.h [new file with mode: 0644]
libs/cocos2d/Support/CCProfiling.m [new file with mode: 0644]
libs/cocos2d/Support/CGPointExtension.h [new file with mode: 0644]
libs/cocos2d/Support/CGPointExtension.m [new file with mode: 0644]
libs/cocos2d/Support/OpenGL_Internal.h [new file with mode: 0644]
libs/cocos2d/Support/TGAlib.h [new file with mode: 0644]
libs/cocos2d/Support/TGAlib.m [new file with mode: 0644]
libs/cocos2d/Support/TransformUtils.h [new file with mode: 0644]
libs/cocos2d/Support/TransformUtils.m [new file with mode: 0644]
libs/cocos2d/Support/ZipUtils.h [new file with mode: 0644]
libs/cocos2d/Support/ZipUtils.m [new file with mode: 0644]
libs/cocos2d/Support/base64.c [new file with mode: 0644]
libs/cocos2d/Support/base64.h [new file with mode: 0644]
libs/cocos2d/Support/ccCArray.h [new file with mode: 0644]
libs/cocos2d/Support/ccUtils.c [new file with mode: 0644]
libs/cocos2d/Support/ccUtils.h [new file with mode: 0644]
libs/cocos2d/Support/uthash.h [new file with mode: 0644]
libs/cocos2d/Support/utlist.h [new file with mode: 0644]
libs/cocos2d/ccConfig.h [new file with mode: 0644]
libs/cocos2d/ccMacros.h [new file with mode: 0644]
libs/cocos2d/ccTypes.h [new file with mode: 0644]
libs/cocos2d/cocos2d.h [new file with mode: 0644]
libs/cocos2d/cocos2d.m [new file with mode: 0644]
src/game/QQGame.mm

diff --git a/libs/CocosDenshion/CDAudioManager.h b/libs/CocosDenshion/CDAudioManager.h
new file mode 100644 (file)
index 0000000..2475929
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ Copyright (c) 2010 Steve Oldmeadow
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ $Id$
+ */
+
+#import "CocosDenshion.h"
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
+    #import <AVFoundation/AVFoundation.h>
+#else
+    #import "CDXMacOSXSupport.h"
+#endif
+
+/** Different modes of the engine */
+typedef enum {
+       kAMM_FxOnly,                                    //!Other apps will be able to play audio
+       kAMM_FxPlusMusic,                               //!Only this app will play audio
+       kAMM_FxPlusMusicIfNoOtherAudio, //!If another app is playing audio at start up then allow it to continue and don't play music
+       kAMM_MediaPlayback,                             //!This app takes over audio e.g music player app
+       kAMM_PlayAndRecord                              //!App takes over audio and has input and output
+} tAudioManagerMode;
+
+/** Possible states of the engine */
+typedef enum {
+       kAMStateUninitialised, //!Audio manager has not been initialised - do not use
+       kAMStateInitialising,  //!Audio manager is in the process of initialising - do not use
+       kAMStateInitialised        //!Audio manager is initialised - safe to use
+} tAudioManagerState;
+
+typedef enum {
+       kAMRBDoNothing,                     //Audio manager will not do anything on resign or becoming active
+       kAMRBStopPlay,                          //Background music is stopped on resign and resumed on become active
+       kAMRBStop                                       //Background music is stopped on resign but not resumed - maybe because you want to do this from within your game
+} tAudioManagerResignBehavior;
+
+/** Notifications */
+extern NSString * const kCDN_AudioManagerInitialised;
+
+@interface CDAsynchInitialiser : NSOperation {}        
+@end
+
+/** CDAudioManager supports two long audio source channels called left and right*/
+typedef enum {
+       kASC_Left = 0,
+       kASC_Right = 1
+} tAudioSourceChannel; 
+
+typedef enum {
+       kLAS_Init,
+       kLAS_Loaded,
+       kLAS_Playing,
+       kLAS_Paused,
+       kLAS_Stopped,
+} tLongAudioSourceState;
+
+@class CDLongAudioSource;
+@protocol CDLongAudioSourceDelegate <NSObject>
+@optional
+/** The audio source completed playing */
+- (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource;
+/** The file used to load the audio source has changed */
+- (void) cdAudioSourceFileDidChange:(CDLongAudioSource *) audioSource;
+@end
+
+/**
+ CDLongAudioSource represents an audio source that has a long duration which makes
+ it costly to load into memory for playback as an effect using CDSoundEngine. Examples
+ include background music and narration tracks. The audio file may or may not be compressed.
+ Bear in mind that current iDevices can only use hardware to decode a single compressed
+ audio file at a time and playing multiple compressed files will result in a performance drop
+ as software decompression will take place.
+ @since v0.99
+ */
+@interface CDLongAudioSource : NSObject <AVAudioPlayerDelegate, CDAudioInterruptProtocol>{
+       AVAudioPlayer   *audioSourcePlayer;
+       NSString                *audioSourceFilePath;
+       NSInteger               numberOfLoops;
+       float                   volume;
+       id<CDLongAudioSourceDelegate> delegate; 
+       BOOL                    mute;
+       BOOL                    enabled_;
+       BOOL                    backgroundMusic;
+@public        
+       BOOL                    systemPaused;//Used for auto resign handling
+       NSTimeInterval  systemPauseLocation;//Used for auto resign handling
+@protected
+       tLongAudioSourceState state;
+}      
+@property (readonly) AVAudioPlayer *audioSourcePlayer;
+@property (readonly) NSString *audioSourceFilePath;
+@property (readwrite, nonatomic) NSInteger numberOfLoops;
+@property (readwrite, nonatomic) float volume;
+@property (assign) id<CDLongAudioSourceDelegate> delegate;
+/* This long audio source functions as background music */
+@property (readwrite, nonatomic) BOOL backgroundMusic;
+
+/** Loads the file into the audio source */
+-(void) load:(NSString*) filePath;
+/** Plays the audio source */
+-(void) play;
+/** Stops playing the audio soruce */
+-(void) stop;
+/** Pauses the audio source */
+-(void) pause;
+/** Rewinds the audio source */
+-(void) rewind;
+/** Resumes playing the audio source if it was paused */
+-(void) resume;
+/** Returns whether or not the audio source is playing */
+-(BOOL) isPlaying;
+
+@end
+
+/** 
+ CDAudioManager manages audio requirements for a game.  It provides access to a CDSoundEngine object
+ for playing sound effects.  It provides access to two CDLongAudioSource object (left and right channel)
+ for playing long duration audio such as background music and narration tracks.  Additionally it manages
+ the audio session to take care of things like audio session interruption and interacting with the audio
+ of other apps that are running on the device.
+ Requirements:
+ - Firmware: OS 2.2 or greater 
+ - Files: CDAudioManager.*, CocosDenshion.*
+ - Frameworks: OpenAL, AudioToolbox, AVFoundation
+ @since v0.8
+ */
+@interface CDAudioManager : NSObject <CDLongAudioSourceDelegate, CDAudioInterruptProtocol, AVAudioSessionDelegate> {
+       CDSoundEngine           *soundEngine;
+       CDLongAudioSource       *backgroundMusic;
+       NSMutableArray          *audioSourceChannels;
+       NSString*                       _audioSessionCategory;
+       BOOL                            _audioWasPlayingAtStartup;
+       tAudioManagerMode       _mode;
+       SEL backgroundMusicCompletionSelector;
+       id backgroundMusicCompletionListener;
+       BOOL willPlayBackgroundMusic;
+       BOOL _mute;
+       BOOL _resigned;
+       BOOL _interrupted;
+       BOOL _audioSessionActive;
+       BOOL enabled_;
+       
+       //For handling resign/become active
+       BOOL _isObservingAppEvents;
+       tAudioManagerResignBehavior _resignBehavior;
+}
+
+@property (readonly) CDSoundEngine *soundEngine;
+@property (readonly) CDLongAudioSource *backgroundMusic;
+@property (readonly) BOOL willPlayBackgroundMusic;
+
+/** Returns the shared singleton */
++ (CDAudioManager *) sharedManager;
++ (tAudioManagerState) sharedManagerState;
+/** Configures the shared singleton with a mode*/
++ (void) configure: (tAudioManagerMode) mode;
+/** Initializes the engine asynchronously with a mode */
++ (void) initAsynchronously: (tAudioManagerMode) mode;
+/** Initializes the engine synchronously with a mode, channel definition and a total number of channels */
+- (id) init: (tAudioManagerMode) mode;
+-(void) audioSessionInterrupted;
+-(void) audioSessionResumed;
+-(void) setResignBehavior:(tAudioManagerResignBehavior) resignBehavior autoHandle:(BOOL) autoHandle;
+/** Returns true is audio is muted at a hardware level e.g user has ringer switch set to off */
+-(BOOL) isDeviceMuted;
+/** Returns true if another app is playing audio such as the iPod music player */
+-(BOOL) isOtherAudioPlaying;
+/** Sets the way the audio manager interacts with the operating system such as whether it shares output with other apps or obeys the mute switch */
+-(void) setMode:(tAudioManagerMode) mode;
+/** Shuts down the shared audio manager instance so that it can be reinitialised */
++(void) end;
+
+/** Call if you want to use built in resign behavior but need to do some additional audio processing on resign active. */
+- (void) applicationWillResignActive;
+/** Call if you want to use built in resign behavior but need to do some additional audio processing on become active. */
+- (void) applicationDidBecomeActive;
+
+//New AVAudioPlayer API
+/** Loads the data from the specified file path to the channel's audio source */
+-(CDLongAudioSource*) audioSourceLoad:(NSString*) filePath channel:(tAudioSourceChannel) channel;
+/** Retrieves the audio source for the specified channel */
+-(CDLongAudioSource*) audioSourceForChannel:(tAudioSourceChannel) channel;
+
+//Legacy AVAudioPlayer API
+/** Plays music in background. The music can be looped or not
+ It is recommended to use .aac files as background music since they are decoded by the device (hardware).
+ */
+-(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop;
+/** Preloads a background music */
+-(void) preloadBackgroundMusic:(NSString*) filePath;
+/** Stops playing the background music */
+-(void) stopBackgroundMusic;
+/** Pauses the background music */
+-(void) pauseBackgroundMusic;
+/** Rewinds the background music */
+-(void) rewindBackgroundMusic;
+/** Resumes playing the background music */
+-(void) resumeBackgroundMusic;
+/** Returns whether or not the background music is playing */
+-(BOOL) isBackgroundMusicPlaying;
+
+-(void) setBackgroundMusicCompletionListener:(id) listener selector:(SEL) selector;
+
+@end
+
+/** Fader for long audio source objects */
+@interface CDLongAudioSourceFader : CDPropertyModifier{}
+@end
+
+static const int kCDNoBuffer = -1;
+
+/** Allows buffers to be associated with file names */
+@interface CDBufferManager:NSObject{
+       NSMutableDictionary* loadedBuffers;
+       NSMutableArray  *freedBuffers;
+       CDSoundEngine *soundEngine;
+       int nextBufferId;
+}
+
+-(id) initWithEngine:(CDSoundEngine *) theSoundEngine;
+-(int) bufferForFile:(NSString*) filePath create:(BOOL) create;
+-(void) releaseBufferForFile:(NSString *) filePath;
+
+@end
+
diff --git a/libs/CocosDenshion/CDAudioManager.m b/libs/CocosDenshion/CDAudioManager.m
new file mode 100644 (file)
index 0000000..0929f3c
--- /dev/null
@@ -0,0 +1,887 @@
+/*
+ Copyright (c) 2010 Steve Oldmeadow
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ $Id$
+ */
+
+
+#import "CDAudioManager.h"
+
+NSString * const kCDN_AudioManagerInitialised = @"kCDN_AudioManagerInitialised";
+
+//NSOperation object used to asynchronously initialise 
+@implementation CDAsynchInitialiser
+
+-(void) main {
+       [super main];
+       [CDAudioManager sharedManager];
+}      
+
+@end
+
+@implementation CDLongAudioSource
+
+@synthesize audioSourcePlayer, audioSourceFilePath, delegate, backgroundMusic;
+
+-(id) init {
+       if ((self = [super init])) {
+               state = kLAS_Init;
+               volume = 1.0f;
+               mute = NO;
+               enabled_ = YES;
+       }
+       return self;
+}
+
+-(void) dealloc {
+       CDLOGINFO(@"Denshion::CDLongAudioSource - deallocating %@", self);
+       [audioSourcePlayer release];
+       [audioSourceFilePath release];
+       [super dealloc];
+}      
+
+-(void) load:(NSString*) filePath {
+       //We have alread loaded a file previously,  check if we are being asked to load the same file
+       if (state == kLAS_Init || ![filePath isEqualToString:audioSourceFilePath]) {
+               CDLOGINFO(@"Denshion::CDLongAudioSource - Loading new audio source %@",filePath);
+               //New file
+               if (state != kLAS_Init) {
+                       [audioSourceFilePath release];//Release old file path
+                       [audioSourcePlayer release];//Release old AVAudioPlayer, they can't be reused
+               }
+               audioSourceFilePath = [filePath copy];
+               NSError *error = nil;
+               NSString *path = [CDUtilities fullPathFromRelativePath:audioSourceFilePath];
+               audioSourcePlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
+               if (error == nil) {
+                       [audioSourcePlayer prepareToPlay];
+                       audioSourcePlayer.delegate = self;
+                       if (delegate && [delegate respondsToSelector:@selector(cdAudioSourceFileDidChange:)]) {
+                               //Tell our delegate the file has changed
+                               [delegate cdAudioSourceFileDidChange:self];
+                       }       
+               } else {
+                       CDLOG(@"Denshion::CDLongAudioSource - Error initialising audio player: %@",error);
+               }       
+       } else {
+               //Same file - just return it to a consistent state
+               [self pause];
+               [self rewind];
+       }
+       audioSourcePlayer.volume = volume;
+       audioSourcePlayer.numberOfLoops = numberOfLoops;
+       state = kLAS_Loaded;
+}      
+
+-(void) play {
+       if (enabled_) {
+               self->systemPaused = NO;
+               [audioSourcePlayer play];
+       } else {
+               CDLOGINFO(@"Denshion::CDLongAudioSource long audio source didn't play because it is disabled");
+       }       
+}      
+
+-(void) stop {
+       [audioSourcePlayer stop];
+}      
+
+-(void) pause {
+       [audioSourcePlayer pause];
+}      
+
+-(void) rewind {
+       [audioSourcePlayer setCurrentTime:0];
+}
+
+-(void) resume {
+       [audioSourcePlayer play];
+}      
+
+-(BOOL) isPlaying {
+       if (state != kLAS_Init) {
+               return [audioSourcePlayer isPlaying];
+       } else {
+               return NO;
+       }
+}
+
+-(void) setVolume:(float) newVolume
+{
+       volume = newVolume;
+       if (state != kLAS_Init && !mute) {
+               audioSourcePlayer.volume = newVolume;
+       }       
+}
+
+-(float) volume 
+{
+       return volume;
+}
+
+#pragma mark Audio Interrupt Protocol
+-(BOOL) mute
+{
+       return mute;
+}      
+
+-(void) setMute:(BOOL) muteValue 
+{
+       if (mute != muteValue) {
+               if (mute) {
+                       //Turn sound back on
+                       audioSourcePlayer.volume = volume;
+               } else {
+                       audioSourcePlayer.volume = 0.0f;
+               }
+               mute = muteValue;
+       }       
+}      
+
+-(BOOL) enabled 
+{
+       return enabled_;
+}      
+
+-(void) setEnabled:(BOOL)enabledValue 
+{
+       if (enabledValue != enabled_) {
+               enabled_ = enabledValue;
+               if (!enabled_) {
+                       //"Stop" the sounds
+                       [self pause];
+                       [self rewind];
+               }       
+       }       
+}      
+
+-(NSInteger) numberOfLoops {
+       return numberOfLoops;
+}      
+
+-(void) setNumberOfLoops:(NSInteger) loopCount
+{
+       audioSourcePlayer.numberOfLoops = loopCount;
+       numberOfLoops = loopCount;
+}      
+
+- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
+       CDLOGINFO(@"Denshion::CDLongAudioSource - audio player finished");
+#if TARGET_IPHONE_SIMULATOR    
+       CDLOGINFO(@"Denshion::CDLongAudioSource - workaround for OpenAL clobbered audio issue");
+       //This is a workaround for an issue in all simulators (tested to 3.1.2).  Problem is 
+       //that OpenAL audio playback is clobbered when an AVAudioPlayer stops.  Workaround
+       //is to keep the player playing on an endless loop with 0 volume and then when
+       //it is played again reset the volume and set loop count appropriately.
+       //NB: this workaround is not foolproof but it is good enough for most situations.
+       player.numberOfLoops = -1;
+       player.volume = 0;
+       [player play];
+#endif 
+       if (delegate && [delegate respondsToSelector:@selector(cdAudioSourceDidFinishPlaying:)]) {
+               [delegate cdAudioSourceDidFinishPlaying:self];
+       }       
+}      
+
+-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {
+       CDLOGINFO(@"Denshion::CDLongAudioSource - audio player interrupted");
+}
+
+-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player {
+       CDLOGINFO(@"Denshion::CDLongAudioSource - audio player resumed");
+       if (self.backgroundMusic) {
+               //Check if background music can play as rules may have changed during 
+               //the interruption. This is to address a specific issue in 4.x when
+               //fast task switching
+               if([CDAudioManager sharedManager].willPlayBackgroundMusic) {
+                       [player play];
+               }       
+       } else {
+               [player play];
+       }       
+}      
+
+@end
+
+
+@interface CDAudioManager (PrivateMethods)
+-(BOOL) audioSessionSetActive:(BOOL) active;
+-(BOOL) audioSessionSetCategory:(NSString*) category;
+-(void) badAlContextHandler;
+@end
+
+
+@implementation CDAudioManager
+#define BACKGROUND_MUSIC_CHANNEL kASC_Left
+
+@synthesize soundEngine, willPlayBackgroundMusic;
+static CDAudioManager *sharedManager;
+static tAudioManagerState _sharedManagerState = kAMStateUninitialised;
+static tAudioManagerMode configuredMode;
+static BOOL configured = FALSE;
+
+-(BOOL) audioSessionSetActive:(BOOL) active {
+       NSError *activationError = nil;
+       if ([[AVAudioSession sharedInstance] setActive:active error:&activationError]) {
+               _audioSessionActive = active;
+               CDLOGINFO(@"Denshion::CDAudioManager - Audio session set active %i succeeded", active); 
+               return YES;
+       } else {
+               //Failed
+               CDLOG(@"Denshion::CDAudioManager - Audio session set active %i failed with error %@", active, activationError); 
+               return NO;
+       }       
+}      
+
+-(BOOL) audioSessionSetCategory:(NSString*) category {
+       NSError *categoryError = nil;
+       if ([[AVAudioSession sharedInstance] setCategory:category error:&categoryError]) {
+               CDLOGINFO(@"Denshion::CDAudioManager - Audio session set category %@ succeeded", category); 
+               return YES;
+       } else {
+               //Failed
+               CDLOG(@"Denshion::CDAudioManager - Audio session set category %@ failed with error %@", category, categoryError); 
+               return NO;
+       }       
+}      
+
+// Init
++ (CDAudioManager *) sharedManager
+{
+       @synchronized(self)     {
+               if (!sharedManager) {
+                       if (!configured) {
+                               //Set defaults here
+                               configuredMode = kAMM_FxPlusMusicIfNoOtherAudio;
+                       }
+                       sharedManager = [[CDAudioManager alloc] init:configuredMode];
+                       _sharedManagerState = kAMStateInitialised;//This is only really relevant when using asynchronous initialisation
+                       [[NSNotificationCenter defaultCenter] postNotificationName:kCDN_AudioManagerInitialised object:nil];
+               }       
+       }
+       return sharedManager;
+}
+
++ (tAudioManagerState) sharedManagerState {
+       return _sharedManagerState;
+}      
+
+/**
+ * Call this to set up audio manager asynchronously.  Initialisation is finished when sharedManagerState == kAMStateInitialised
+ */
++ (void) initAsynchronously: (tAudioManagerMode) mode {
+       @synchronized(self) {
+               if (_sharedManagerState == kAMStateUninitialised) {
+                       _sharedManagerState = kAMStateInitialising;
+                       [CDAudioManager configure:mode];
+                       CDAsynchInitialiser *initOp = [[[CDAsynchInitialiser alloc] init] autorelease];
+                       NSOperationQueue *opQ = [[[NSOperationQueue alloc] init] autorelease];
+                       [opQ addOperation:initOp];
+               }       
+       }
+}      
+
++ (id) alloc
+{
+       @synchronized(self)     {
+               NSAssert(sharedManager == nil, @"Attempted to allocate a second instance of a singleton.");
+               return [super alloc];
+       }
+       return nil;
+}
+
+/*
+ * Call this method before accessing the shared manager in order to configure the shared audio manager
+ */
++ (void) configure: (tAudioManagerMode) mode {
+       configuredMode = mode;
+       configured = TRUE;
+}      
+
+-(BOOL) isOtherAudioPlaying {
+       UInt32 isPlaying = 0;
+       UInt32 varSize = sizeof(isPlaying);
+       AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, &varSize, &isPlaying);
+       return (isPlaying != 0);
+}
+
+-(void) setMode:(tAudioManagerMode) mode {
+
+       _mode = mode;
+       switch (_mode) {
+                       
+               case kAMM_FxOnly:
+                       //Share audio with other app
+                  &