]>
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
7 // RCS-ID: $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $
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()
83 //Time between timer calls
84 #define MOVIE_DELAY 100
86 void wxSoundData::SoundTask()
90 void wxSoundData::CreateAndStartTimer()
92 //Start timer and play movie asyncronously
93 m_pTimer
= new wxSoundTimer(this);
94 m_pTimer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
102 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
105 Create(sFileName
, isResource
);
108 wxSound::wxSound(int size
, const wxByte
* data
)
111 Create( size
, data
);
116 // if the sound is in a playing state, just mark it to be deleted and
117 // delete it after it plays. Otherwise, async sounds created on the stack
118 // may never get the chance to play.
119 bool isPlaying
= false;
120 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
121 s
!= s_soundsPlaying
.rend(); ++s
)
131 m_data
->MarkForDeletion();
141 bool wxSound::DoPlay(unsigned flags
) const
145 s_soundsPlaying
.push_back(m_data
);
146 if ( !m_data
->Play(flags
) )
147 s_soundsPlaying
.pop_back();
153 bool wxSound::IsPlaying()
155 return s_soundsPlaying
.size() > 0;
160 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
161 s
!= s_soundsPlaying
.rend(); ++s
)
167 // Notification when a sound has stopped
168 void wxSound::SoundStopped(const wxSoundData
* data
)
170 for ( wxVector
<wxSoundData
*>::iterator s
= s_soundsPlaying
.begin();
171 s
!= s_soundsPlaying
.end(); ++s
)
175 s_soundsPlaying
.erase(s
);