]>
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 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
19 #include "wx/object.h"
20 #include "wx/string.h"
28 #include "wx/vector.h"
30 class wxSoundTimer
: public wxTimer
33 wxSoundTimer(wxSoundData
* snd
)
38 virtual ~wxSoundTimer()
55 wxVector
<wxSoundData
*> s_soundsPlaying
;
57 wxSoundData::wxSoundData()
60 m_markedForDeletion
= false;
63 wxSoundData::~wxSoundData()
67 void wxSoundData::MarkForDeletion()
69 m_markedForDeletion
= true;
72 void wxSoundData::Stop()
78 //Time between timer calls
79 #define MOVIE_DELAY 100
81 void wxSoundData::SoundTask()
85 void wxSoundData::CreateAndStartTimer()
87 //Start timer and play movie asyncronously
88 m_pTimer
= new wxSoundTimer(this);
89 m_pTimer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
97 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
100 Create(sFileName
, isResource
);
103 wxSound::wxSound(size_t size
, const void* data
)
106 Create( size
, data
);
111 // if the sound is in a playing state, just mark it to be deleted and
112 // delete it after it plays. Otherwise, async sounds created on the stack
113 // may never get the chance to play.
114 bool isPlaying
= false;
115 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
116 s
!= s_soundsPlaying
.rend(); ++s
)
126 m_data
->MarkForDeletion();
136 bool wxSound::DoPlay(unsigned flags
) const
140 s_soundsPlaying
.push_back(m_data
);
141 if ( !m_data
->Play(flags
) )
142 s_soundsPlaying
.pop_back();
148 bool wxSound::IsPlaying()
150 return s_soundsPlaying
.size() > 0;
155 for ( wxVector
<wxSoundData
*>::reverse_iterator s
= s_soundsPlaying
.rbegin();
156 s
!= s_soundsPlaying
.rend(); ++s
)
162 // Notification when a sound has stopped
163 void wxSound::SoundStopped(const wxSoundData
* data
)
165 for ( wxVector
<wxSoundData
*>::iterator s
= s_soundsPlaying
.begin();
166 s
!= s_soundsPlaying
.end(); ++s
)
170 s_soundsPlaying
.erase(s
);