]> git.saurik.com Git - wxWidgets.git/blame - src/osx/sound_osx.cpp
missing commit for RAW_CONTROL changes
[wxWidgets.git] / src / osx / sound_osx.cpp
CommitLineData
3b3d8b97
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/sound_osx.cpp
3// Purpose: wxSound class common osx code
4// Author: Stefan Csomor
ce00f59b 5// Modified by:
3b3d8b97 6// Created: 2009-09-01
b5b208a1 7// RCS-ID: $Id$
3b3d8b97
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#if wxUSE_SOUND
16
17#include "wx/sound.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/object.h"
21 #include "wx/string.h"
22 #include "wx/intl.h"
23 #include "wx/log.h"
24 #include "wx/timer.h"
25#endif
26
27#include "wx/file.h"
28
29#include "wx/vector.h"
30
31class wxSoundTimer : public wxTimer
32{
33public:
34 wxSoundTimer(wxSoundData* snd)
35 : m_sound(snd)
36 {
37 }
ce00f59b 38
3b3d8b97
SC
39 virtual ~wxSoundTimer()
40 {
41 Stop();
509da835
KO
42 if (m_sound)
43 m_sound->DoStop();
3b3d8b97 44 }
ce00f59b 45
3b3d8b97
SC
46 void Notify()
47 {
509da835
KO
48 if (m_sound)
49 m_sound->SoundTask();
3b3d8b97 50 }
ce00f59b 51
3b3d8b97
SC
52protected:
53 wxSoundData* m_sound;
54};
55
56wxVector<wxSoundData*> s_soundsPlaying;
57
58wxSoundData::wxSoundData()
59{
60 m_pTimer = NULL;
509da835 61 m_markedForDeletion = false;
3b3d8b97
SC
62}
63
64wxSoundData::~wxSoundData()
65{
66}
67
509da835
KO
68void wxSoundData::MarkForDeletion()
69{
70 m_markedForDeletion = true;
71}
72
3b3d8b97
SC
73void wxSoundData::Stop()
74{
75 DoStop();
5276b0a5 76 wxDELETE(m_pTimer);
3b3d8b97
SC
77}
78
79//Time between timer calls
80#define MOVIE_DELAY 100
81
82void wxSoundData::SoundTask()
83{
84}
85
86void wxSoundData::CreateAndStartTimer()
87{
88 //Start timer and play movie asyncronously
89 m_pTimer = new wxSoundTimer(this);
90 m_pTimer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
91}
92
ce00f59b 93wxSound::wxSound()
3b3d8b97
SC
94{
95 Init();
96}
97
98wxSound::wxSound(const wxString& sFileName, bool isResource)
99{
100 Init();
101 Create(sFileName, isResource);
102}
103
104wxSound::wxSound(int size, const wxByte* data)
105{
106 Init();
107 Create( size, data );
108}
109
110wxSound::~wxSound()
111{
509da835
KO
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 )
118 {
119 if (*s == m_data)
120 {
121 isPlaying = true;
122 break;
123 }
124 }
ce00f59b 125
509da835
KO
126 if (isPlaying)
127 m_data->MarkForDeletion();
128 else
129 delete m_data;
3b3d8b97
SC
130}
131
132void wxSound::Init()
133{
134 m_data = NULL;
135}
136
137bool wxSound::DoPlay(unsigned flags) const
138{
139 if ( m_data )
140 {
141 s_soundsPlaying.push_back(m_data);
142 if ( !m_data->Play(flags) )
143 s_soundsPlaying.pop_back();
144 }
ce00f59b 145
3b3d8b97
SC
146 return false;
147}
148
149bool wxSound::IsPlaying()
150{
151 return s_soundsPlaying.size() > 0;
152}
153
154void wxSound::Stop()
155{
156 for ( wxVector<wxSoundData*>::reverse_iterator s = s_soundsPlaying.rbegin();
157 s != s_soundsPlaying.rend(); ++s )
158 {
159 (*s)->Stop();
160 }
161}
162
163// Notification when a sound has stopped
164void wxSound::SoundStopped(const wxSoundData* data)
165{
166 for ( wxVector<wxSoundData*>::iterator s = s_soundsPlaying.begin();
167 s != s_soundsPlaying.end(); ++s )
168 {
ce00f59b 169 if ( (*s) == data )
3b3d8b97
SC
170 {
171 s_soundsPlaying.erase(s);
172 break;
173 }
174 }
175}
176
177#endif //wxUSE_SOUND