applied patch #997019: '[wxMac] updated wxSound', adds static IsPlaying() and Stop()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28557 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2,11 +2,11 @@
|
|||||||
// Name: sound.h
|
// Name: sound.h
|
||||||
// Purpose: wxSound class (loads and plays short Windows .wav files).
|
// Purpose: wxSound class (loads and plays short Windows .wav files).
|
||||||
// Optional on non-Windows platforms.
|
// Optional on non-Windows platforms.
|
||||||
// Author: Stefan Csomor
|
// Author: Ryan Norton, Stefan Csomor
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 1998-01-01
|
// Created: 1998-01-01
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Stefan Csomor
|
// Copyright: (c) Ryan Norton, Stefan Csomor
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -32,12 +32,11 @@ public:
|
|||||||
public:
|
public:
|
||||||
bool Create(const wxString& fileName, bool isResource = FALSE);
|
bool Create(const wxString& fileName, bool isResource = FALSE);
|
||||||
bool IsOk() const { return !m_sndname.IsEmpty(); }
|
bool IsOk() const { return !m_sndname.IsEmpty(); }
|
||||||
|
static void Stop();
|
||||||
|
static bool IsPlaying();
|
||||||
|
|
||||||
void* GetHandle();
|
void* GetHandle();
|
||||||
protected:
|
protected:
|
||||||
// prevent collision with some BSD definitions of macro Free()
|
|
||||||
bool FreeData();
|
|
||||||
|
|
||||||
bool DoPlay(unsigned flags) const;
|
bool DoPlay(unsigned flags) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: sound.cpp
|
// Name: sound.cpp
|
||||||
// Purpose: wxSound class implementation: optional
|
// Purpose: wxSound class implementation: optional
|
||||||
// Author: Ryan Norton, Stefan Csomor
|
// Author: Ryan Norton
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 1998-01-01
|
// Created: 1998-01-01
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
@@ -72,21 +72,18 @@
|
|||||||
class wxQTTimer : public wxTimer
|
class wxQTTimer : public wxTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxQTTimer(Movie movie, bool bLoop) :
|
wxQTTimer(Movie movie, bool bLoop, bool& playing) :
|
||||||
m_movie(movie), m_bLoop(bLoop)
|
m_movie(movie), m_bLoop(bLoop), m_pbPlaying(&playing)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~wxQTTimer()
|
~wxQTTimer()
|
||||||
{
|
{
|
||||||
Shutdown();
|
if(m_pbPlaying)
|
||||||
}
|
*m_pbPlaying = false;
|
||||||
|
|
||||||
void Shutdown()
|
|
||||||
{
|
|
||||||
StopMovie(m_movie);
|
StopMovie(m_movie);
|
||||||
DisposeMovie(m_movie);
|
DisposeMovie(m_movie);
|
||||||
m_movie = NULL ;
|
|
||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
//Note that ExitMovies() is not neccessary, but
|
//Note that ExitMovies() is not neccessary, but
|
||||||
@@ -98,8 +95,18 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shutdown()
|
||||||
|
{
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
void Notify()
|
void Notify()
|
||||||
{
|
{
|
||||||
|
if (m_pbPlaying && !*m_pbPlaying)
|
||||||
|
{
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
if(IsMovieDone(m_movie))
|
if(IsMovieDone(m_movie))
|
||||||
{
|
{
|
||||||
if (!m_bLoop)
|
if (!m_bLoop)
|
||||||
@@ -117,27 +124,40 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Movie& GetMovie() {return m_movie;}
|
Movie& GetMovie() {return m_movie;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Movie m_movie;
|
Movie m_movie;
|
||||||
bool m_bLoop;
|
bool m_bLoop;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool* m_pbPlaying;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class wxSMTimer : public wxTimer
|
class wxSMTimer : public wxTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxSMTimer(void* hSnd, void* pSndChannel, const bool& bLoop)
|
wxSMTimer(void* hSnd, void* pSndChannel, const bool& bLoop, bool& playing)
|
||||||
: m_hSnd(hSnd), m_pSndChannel(pSndChannel), m_bLoop(bLoop)
|
: m_hSnd(hSnd), m_pSndChannel(pSndChannel), m_bLoop(bLoop), m_pbPlaying(&playing)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~wxSMTimer()
|
~wxSMTimer()
|
||||||
{
|
{
|
||||||
Shutdown();
|
if(m_pbPlaying)
|
||||||
|
*m_pbPlaying = false;
|
||||||
|
SndDisposeChannel((SndChannelPtr)m_pSndChannel, TRUE);
|
||||||
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notify()
|
void Notify()
|
||||||
{
|
{
|
||||||
|
if (m_pbPlaying && !*m_pbPlaying)
|
||||||
|
{
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
SCStatus stat;
|
SCStatus stat;
|
||||||
|
|
||||||
if (SndChannelStatus((SndChannelPtr)m_pSndChannel, sizeof(SCStatus), &stat) != 0)
|
if (SndChannelStatus((SndChannelPtr)m_pSndChannel, sizeof(SCStatus), &stat) != 0)
|
||||||
@@ -159,19 +179,25 @@ public:
|
|||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
SndDisposeChannel((SndChannelPtr)m_pSndChannel, TRUE);
|
delete this;
|
||||||
Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* GetChannel() {return m_pSndChannel;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void* m_hSnd;
|
void* m_hSnd;
|
||||||
void* m_pSndChannel;
|
void* m_pSndChannel;
|
||||||
bool m_bLoop;
|
bool m_bLoop;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool* m_pbPlaying;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// wxSound
|
// wxSound
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
wxTimer* lastSoundTimer=NULL;
|
||||||
|
bool lastSoundIsPlaying=false;
|
||||||
|
|
||||||
//Determines whether version 4 of QT is installed
|
//Determines whether version 4 of QT is installed
|
||||||
Boolean wxIsQuickTime4Installed (void)
|
Boolean wxIsQuickTime4Installed (void)
|
||||||
@@ -221,20 +247,22 @@ wxSound::wxSound(const wxString& sFileName, bool isResource)
|
|||||||
wxSound::wxSound(int size, const wxByte* data)
|
wxSound::wxSound(int size, const wxByte* data)
|
||||||
: m_hSnd((char*)data), m_waveLength(size), m_pTimer(NULL), m_type(wxSound_MEMORY)
|
: m_hSnd((char*)data), m_waveLength(size), m_pTimer(NULL), m_type(wxSound_MEMORY)
|
||||||
{
|
{
|
||||||
if (!wxInitQT())
|
|
||||||
m_type = wxSound_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if(!wxInitQT())
|
Stop();
|
||||||
return false;
|
|
||||||
|
|
||||||
FreeData();
|
|
||||||
|
|
||||||
if (isResource)
|
if (isResource)
|
||||||
{
|
{
|
||||||
@@ -262,8 +290,7 @@ bool wxSound::Create(const wxString& fileName, bool isResource)
|
|||||||
|
|
||||||
bool wxSound::DoPlay(unsigned flags) const
|
bool wxSound::DoPlay(unsigned flags) const
|
||||||
{
|
{
|
||||||
// wxASSERT(m_pTimer == NULL || !((wxTimer*)m_pTimer)->IsRunning() );
|
Stop();
|
||||||
FreeData();
|
|
||||||
|
|
||||||
Movie movie;
|
Movie movie;
|
||||||
|
|
||||||
@@ -271,6 +298,8 @@ bool wxSound::DoPlay(unsigned flags) const
|
|||||||
{
|
{
|
||||||
case wxSound_MEMORY:
|
case wxSound_MEMORY:
|
||||||
{
|
{
|
||||||
|
if (!wxInitQT())
|
||||||
|
return false;
|
||||||
Handle myHandle, dataRef = nil;
|
Handle myHandle, dataRef = nil;
|
||||||
MovieImportComponent miComponent;
|
MovieImportComponent miComponent;
|
||||||
Track targetTrack = nil;
|
Track targetTrack = nil;
|
||||||
@@ -326,15 +355,17 @@ bool wxSound::DoPlay(unsigned flags) const
|
|||||||
|
|
||||||
SndChannelPtr pSndChannel;
|
SndChannelPtr pSndChannel;
|
||||||
SndNewChannel(&pSndChannel, sampledSynth,
|
SndNewChannel(&pSndChannel, sampledSynth,
|
||||||
initNoInterp +
|
initNoInterp
|
||||||
(data.numChannels == 1 ? initMono : initStereo), NULL);
|
+ (data.numChannels == 1 ? initMono : initStereo), NULL);
|
||||||
|
|
||||||
if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr)
|
if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (flags & wxSOUND_ASYNC)
|
if (flags & wxSOUND_ASYNC)
|
||||||
{
|
{
|
||||||
((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);
|
||||||
|
|
||||||
((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
|
((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
|
||||||
}
|
}
|
||||||
@@ -346,6 +377,9 @@ bool wxSound::DoPlay(unsigned flags) const
|
|||||||
break;
|
break;
|
||||||
case wxSound_FILE:
|
case wxSound_FILE:
|
||||||
{
|
{
|
||||||
|
if (!wxInitQT())
|
||||||
|
return false;
|
||||||
|
|
||||||
short movieResFile;
|
short movieResFile;
|
||||||
FSSpec sfFile;
|
FSSpec sfFile;
|
||||||
|
|
||||||
@@ -399,13 +433,7 @@ bool wxSound::DoPlay(unsigned flags) const
|
|||||||
//Start the movie!
|
//Start the movie!
|
||||||
StartMovie(movie);
|
StartMovie(movie);
|
||||||
|
|
||||||
if (flags & wxSOUND_ASYNC)
|
if (flags & wxSOUND_SYNC)
|
||||||
{
|
|
||||||
//Start timer and play movie asyncronously
|
|
||||||
((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0);
|
|
||||||
((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(!(flags & wxSOUND_LOOP), "Can't loop and play syncronously at the same time");
|
wxASSERT_MSG(!(flags & wxSOUND_LOOP), "Can't loop and play syncronously at the same time");
|
||||||
|
|
||||||
@@ -415,26 +443,36 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSound::IsPlaying()
|
||||||
|
{
|
||||||
|
return lastSoundIsPlaying;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSound::Stop()
|
||||||
|
{
|
||||||
|
if(lastSoundIsPlaying)
|
||||||
|
{
|
||||||
|
delete (wxTimer*&) lastSoundTimer;
|
||||||
|
lastSoundIsPlaying = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void* wxSound::GetHandle()
|
void* wxSound::GetHandle()
|
||||||
{
|
{
|
||||||
|
if(m_type == wxSound_RESOURCE)
|
||||||
|
return (void*) ((wxSMTimer*)m_pTimer)->GetChannel();
|
||||||
|
|
||||||
return (void*) ((wxQTTimer*) m_pTimer)->GetMovie();
|
return (void*) ((wxQTTimer*) m_pTimer)->GetMovie();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSound::FreeData()
|
|
||||||
{
|
|
||||||
if (m_pTimer != NULL)
|
|
||||||
{
|
|
||||||
delete (wxQTTimer*) m_pTimer;
|
|
||||||
m_pTimer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif //wxUSE_SOUND
|
#endif //wxUSE_SOUND
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user