X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3b3d8b979b9c8cb76a550cf3e0c0c42fa0dc3fa2..eea4d01c65f9b29baa1193db762b4c6b8144af24:/src/osx/core/sound.cpp diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 79ba5ffd62..ace90c2fde 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -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 -// RCS-ID: $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $ -// Copyright: (c) Ryan Norton +// Created: 2009-01-01 +// RCS-ID: $Id$ +// Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -14,10 +14,10 @@ #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" @@ -28,35 +28,49 @@ #include "wx/file.h" +#include "wx/osx/private.h" + +#include + class wxOSXAudioToolboxSoundData : public wxSoundData { public: wxOSXAudioToolboxSoundData(const wxString& fileName); ~wxOSXAudioToolboxSoundData(); - + virtual bool Play(unsigned flags); virtual void DoStop(); protected: static void CompletionCallback(SystemSoundID mySSID, void * soundRef); void SoundCompleted(); - - SystemSoundID m_soundID; + + SystemSoundID m_soundID; wxString m_sndname; //file path }; wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString& fileName) : m_soundID(NULL) -{ +{ 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() @@ -65,10 +79,10 @@ void wxOSXAudioToolboxSoundData::SoundCompleted() { if (m_flags & wxSOUND_LOOP) AudioServicesPlaySystemSound(m_soundID); - else + else Stop(); } - else + else { Stop(); CFRunLoopStop(CFRunLoopGetCurrent()); @@ -82,23 +96,23 @@ void wxOSXAudioToolboxSoundData::DoStop() { AudioServicesDisposeSystemSoundID (m_soundID); m_soundID = NULL; - + wxSound::SoundStopped(this); } } -bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags) const +bool wxOSXAudioToolboxSoundData::Play(unsigned flags) { Stop(); m_flags = flags; - + wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(m_sndname))); CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); wxCFRef 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); @@ -106,12 +120,27 @@ bool wxOSXAudioToolboxSoundData::DoPlay(unsigned flags) const if ( sync ) { - while( m_soundID ) + while( m_soundID ) { CFRunLoopRun(); } } - + + 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; }