]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/sound_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/sound_osx.cpp
3 // Purpose: wxSound class common osx code
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/object.h"
21 #include "wx/string.h"
29 #include "wx/vector.h"
31 class wxSoundTimer
: public wxTimer
34 wxSoundTimer(wxSoundData
* snd
)
39 virtual ~wxSoundTimer()
56 wxVector
<wxSoundData
*> s_soundsPlaying
;
58 wxSoundData::wxSoundData()
61 m_markedForDeletion
= false;
64 wxSoundData::~wxSoundData()
68 void wxSoundData::MarkForDeletion()
70 m_markedForDeletion
= true;
73 void wxSoundData::Stop()
79 //Time between timer calls
80 #define MOVIE_DELAY 100
82 void wxSoundData::SoundTask()
86 void wxSoundData::CreateAndStartTimer()
88 //Start timer and play movie asyncronously
89 m_pTimer
= new wxSoundTimer(this);
90 m_pTimer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
98 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
101 Create(sFileName
, isResource
);
104 wxSound::wxSound(int size
, const wxByte
* data
)
107 Create( size
, data
);
112 // if the sound is in a playing state, just mark it to be deleted and
113 // delete it after it plays. Otherwise, async sounds created on the stack
114 // may never get the chance to play.
115 bool isPlaying
= false;
116 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
117 s
!= s_soundsPlaying
.rend(); ++s
)
127 m_data
->MarkForDeletion();
137 bool wxSound::DoPlay(unsigned flags
) const
141 s_soundsPlaying
.push_back(m_data
);
142 if ( !m_data
->Play(flags
) )
143 s_soundsPlaying
.pop_back();
149 bool wxSound::IsPlaying()
151 return s_soundsPlaying
.size() > 0;
156 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
157 s
!= s_soundsPlaying
.rend(); ++s
)
163 // Notification when a sound has stopped
164 void wxSound::SoundStopped(const wxSoundData
* data
)
166 for ( wxVector
<wxSoundData
*>::iterator s
= s_soundsPlaying
.begin();
167 s
!= s_soundsPlaying
.end(); ++s
)
171 s_soundsPlaying
.erase(s
);