]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/sound.cpp
Fix wxOSX compilation without PCH.
[wxWidgets.git] / src / osx / core / sound.cpp
index 79ba5ffd621b15aa47dd93cb7e81e2601ba9625e..386e62a561503fec192558016d2984bca0a0c3ed 100644 (file)
@@ -1,11 +1,11 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/carbon/sound.cpp
-// Purpose:     wxSound class implementation: optional
-// Author:      Ryan Norton
+// Name:        src/osx/core/sound.cpp
+// Purpose:     wxSound class implementation using AudioToolbox
+// Author:      Stefan Csomor
 // Modified by: Stefan Csomor
-// Created:     1998-01-01
+// Created:     2009-01-01
 // RCS-ID:      $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $
-// Copyright:   (c) Ryan Norton
+// Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 
 #if wxUSE_SOUND
 
-#if wxOSX_USE_AUDIOTOOLBOX
-
 #include "wx/sound.h"
 
+#if wxOSX_USE_AUDIOTOOLBOX
+
 #ifndef WX_PRECOMP
     #include "wx/object.h"
     #include "wx/string.h"
 
 #include "wx/file.h"
 
+#include "wx/osx/private.h"
+
+#include <AudioToolbox/AudioToolbox.h>
+
 class wxOSXAudioToolboxSoundData : public wxSoundData
 {
 public:
@@ -52,11 +56,21 @@ wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString& fileName)
     m_sndname = fileName;
 }
 
-void wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID  mySSID, void * soundRef)
+wxOSXAudioToolboxSoundData::~wxOSXAudioToolboxSoundData()
+{
+    DoStop();
+}
+
+void
+wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID WXUNUSED(mySSID),
+                                               void * soundRef)
 {
     wxOSXAudioToolboxSoundData* data = (wxOSXAudioToolboxSoundData*) soundRef;
     
     data->SoundCompleted();
+    
+    if (data->IsMarkedForDeletion())
+        delete data;
 }
 
 void wxOSXAudioToolboxSoundData::SoundCompleted()
@@ -87,7 +101,7 @@ void wxOSXAudioToolboxSoundData::DoStop()
     }
 }
 
-bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags) const
+bool wxOSXAudioToolboxSoundData::Play(unsigned flags)
 {
     Stop();
 
@@ -98,7 +112,7 @@ bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags) const
     wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
 
     AudioServicesCreateSystemSoundID(url, &m_soundID);
-    AudioServicesAddSystemSoundCompletion( m_soundID, NULL, NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this );
+    AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this );
 
     bool sync = !(flags & wxSOUND_ASYNC);
 
@@ -115,6 +129,21 @@ bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags) const
     return true;
 }
 
+bool wxSound::Create(int WXUNUSED(size), const wxByte* WXUNUSED(data))
+{
+    wxFAIL_MSG( "not implemented" );
+
+    return false;
+}
+
+bool wxSound::Create(const wxString& fileName, bool isResource)
+{
+    wxCHECK_MSG( !isResource, false, "not implemented" );
+    
+    m_data = new wxOSXAudioToolboxSoundData(fileName);
+    return true;
+}
+
 #endif // wxOSX_USE_AUDIOTOOLBOX
 
 #endif //wxUSE_SOUND