]> git.saurik.com Git - wxWidgets.git/commitdiff
Still can't do "if (flags & wxSOUND_SYNC)..." because it will always
authorRobin Dunn <robin@alldunn.com>
Mon, 9 Aug 2004 23:04:22 +0000 (23:04 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 9 Aug 2004 23:04:22 +0000 (23:04 +0000)
be zero.  This is the 2nd or 3rd time I've fixed this, please stop
changing it back!

Fixes to allow ASYNC sounds to continue after the sound object has
been deleted, and so there won't be a crash the next time an async
sound is played.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/sound.cpp

index 3c4920a0cbb3b2151862179db165aeeac04874bd..fc24d21ac3e19667149956b233db28de767a6c1d 100644 (file)
 
 #include <QuickTimeComponents.h>
 
 
 #include <QuickTimeComponents.h>
 
-//Time inbetween timer calls
+//Time between timer calls
 #define MOVIE_DELAY 100
 
 #define MOVIE_DELAY 100
 
+static wxTimer* lastSoundTimer=NULL;
+static bool lastSoundIsPlaying=false;
+
 // ------------------------------------------------------------------
 //          wxQTTimer - Handle Asyncronous Playing
 // ------------------------------------------------------------------
 class wxQTTimer : public wxTimer
 {
 public:
 // ------------------------------------------------------------------
 //          wxQTTimer - Handle Asyncronous Playing
 // ------------------------------------------------------------------
 class wxQTTimer : public wxTimer
 {
 public:
-    wxQTTimer(Movie movie, bool bLoop, bool& playing) :
-        m_movie(movie), m_bLoop(bLoop), m_pbPlaying(&playing)
+    wxQTTimer(Movie movie, bool bLoop, bool* playing) :
+        m_movie(movie), m_bLoop(bLoop), m_pbPlaying(playing)
     {
     }
 
     {
     }
 
@@ -138,8 +141,8 @@ public:
 class wxSMTimer : public wxTimer
 {
 public:
 class wxSMTimer : public wxTimer
 {
 public:
-    wxSMTimer(void* hSnd, void* pSndChannel, const bool& bLoop, bool& playing)
-        : m_hSnd(hSnd), m_pSndChannel(pSndChannel), m_bLoop(bLoop), m_pbPlaying(&playing)
+    wxSMTimer(void* hSnd, void* pSndChannel, bool bLoop, bool* playing)
+        : m_hSnd(hSnd), m_pSndChannel(pSndChannel), m_bLoop(bLoop), m_pbPlaying(playing)
     {
     }
 
     {
     }
 
@@ -196,8 +199,6 @@ public:
 // ------------------------------------------------------------------
 //          wxSound
 // ------------------------------------------------------------------
 // ------------------------------------------------------------------
 //          wxSound
 // ------------------------------------------------------------------
-wxTimer* lastSoundTimer=NULL;
-bool lastSoundIsPlaying=false;
 
 //Determines whether version 4 of QT is installed
 Boolean wxIsQuickTime4Installed (void)
 
 //Determines whether version 4 of QT is installed
 Boolean wxIsQuickTime4Installed (void)
@@ -251,13 +252,6 @@ wxSound::wxSound(int size, const wxByte* data)
 
 wxSound::~wxSound()
 {
 
 wxSound::~wxSound()
 {
-    if(lastSoundIsPlaying)
-    {
-        if(m_type == wxSound_RESOURCE)
-            ((wxSMTimer*)lastSoundTimer)->m_pbPlaying = NULL;
-        else
-            ((wxQTTimer*)lastSoundTimer)->m_pbPlaying = NULL;
-    }
 }
 
 bool wxSound::Create(const wxString& fileName, bool isResource)
 }
 
 bool wxSound::Create(const wxString& fileName, bool isResource)
@@ -365,7 +359,8 @@ bool wxSound::DoPlay(unsigned flags) const
             {
                 lastSoundTimer = ((wxSMTimer*&)m_pTimer)
                     = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0,
             {
                 lastSoundTimer = ((wxSMTimer*&)m_pTimer)
                     = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0,
-                        lastSoundIsPlaying=true);
+                                    &lastSoundIsPlaying);
+                lastSoundIsPlaying = true;
 
                 ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
             }
 
                 ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
             }
@@ -429,11 +424,19 @@ bool wxSound::DoPlay(unsigned flags) const
         return false;
     }//end switch(m_type)
 
         return false;
     }//end switch(m_type)
 
-
     //Start the movie!
     StartMovie(movie);
 
     //Start the movie!
     StartMovie(movie);
 
-    if (flags & wxSOUND_SYNC)
+    if (flags & wxSOUND_ASYNC)
+    {
+        //Start timer and play movie asyncronously
+        lastSoundTimer = ((wxQTTimer*&)m_pTimer) =
+            new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0,
+                          &lastSoundIsPlaying);
+        lastSoundIsPlaying = true;
+        ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
+    }
+    else
     {
         wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time"));
 
     {
         wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time"));
 
@@ -443,12 +446,6 @@ bool wxSound::DoPlay(unsigned flags) const
 
         DisposeMovie(movie);
     }
 
         DisposeMovie(movie);
     }
-    else
-    {
-        //Start timer and play movie asyncronously
-        lastSoundTimer = ((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0,lastSoundIsPlaying=true);
-        ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
-    }
 
     return true;
 }
 
     return true;
 }
@@ -460,10 +457,11 @@ bool wxSound::IsPlaying()
 
 void wxSound::Stop()
 {
 
 void wxSound::Stop()
 {
-    if(lastSoundIsPlaying)
+    if (lastSoundIsPlaying)
     {
         delete (wxTimer*&) lastSoundTimer;
         lastSoundIsPlaying = false;
     {
         delete (wxTimer*&) lastSoundTimer;
         lastSoundIsPlaying = false;
+        lastSoundTimer = NULL;
     }
 }
 
     }
 }