]>
Commit | Line | Data |
---|---|---|
55196c54 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mmbman.cpp | |
3 | // Purpose: Multimedia Board manager | |
4 | // Author: Guilhem Lavaux, <guilhem.lavaux@libertysurf.fr> | |
5 | // Modified by: | |
6 | // Created: 13/02/2000 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2000, Guilhem Lavaux | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "mmbman.cpp" | |
14 | #endif | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | // for all others, include the necessary headers (this file is usually all you | |
28 | // need because it includes almost all "standard" wxWindows headers | |
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/wx.h" | |
31 | #endif | |
32 | ||
33 | // Personnal headers | |
34 | ||
35 | #include "wx/stream.h" | |
36 | #include "wx/wfstream.h" | |
37 | ||
38 | #include "sndbase.h" | |
39 | #include "sndfile.h" | |
40 | #include "sndwav.h" | |
41 | #include "sndaiff.h" | |
42 | #include "sndpcm.h" | |
43 | #include "sndulaw.h" | |
44 | ||
45 | #ifdef __UNIX__ | |
46 | #include "sndoss.h" | |
47 | #include "sndesd.h" | |
48 | #endif | |
49 | ||
50 | #ifdef __WIN32__ | |
51 | #include "sndwin.h" | |
52 | #endif | |
53 | ||
54 | #include "mmboard.h" | |
55 | #include "mmbman.h" | |
56 | ||
57 | // ---------------------------------------------------------------------------- | |
58 | // Private class definitions | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | class MMBoardSoundFile: public MMBoardFile { | |
62 | public: | |
63 | MMBoardSoundFile(const wxString& filename); | |
64 | ~MMBoardSoundFile(); | |
65 | ||
66 | bool NeedWindow(); | |
67 | ||
68 | void SetWindow(wxWindow *window); | |
69 | ||
70 | void Play(); | |
71 | void Pause(); | |
72 | void Resume(); | |
73 | void Stop(); | |
74 | ||
75 | MMBoardTime GetPosition(); | |
76 | MMBoardTime GetLength(); | |
77 | ||
78 | bool IsStopped(); | |
5bee458a | 79 | bool IsPaused(); |
55196c54 GL |
80 | |
81 | wxString GetStringType(); | |
82 | wxString GetStringInformation(); | |
83 | ||
84 | protected: | |
85 | wxSoundFileStream *GetDecoder(); | |
86 | ||
87 | wxSoundStream *m_output_stream; | |
88 | wxInputStream *m_input_stream; | |
89 | wxSoundFileStream *m_file_stream; | |
90 | ||
91 | MMBoardTime m_length; | |
92 | }; | |
93 | ||
94 | // ---------------------------------------------------------------------------- | |
95 | // Implementation | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
98 | ||
99 | // ---------------------------------------------------------------------------- | |
100 | // MMBoardSoundFile | |
101 | ||
102 | MMBoardSoundFile::MMBoardSoundFile(const wxString& filename) | |
103 | : MMBoardFile() | |
104 | { | |
105 | m_input_stream = new wxFileInputStream(filename); | |
106 | m_output_stream = MMBoardManager::OpenSoundStream(); | |
107 | ||
108 | m_file_stream = GetDecoder(); | |
109 | ||
110 | if (!m_file_stream) | |
111 | SetError(MMBoard_UnknownFile); | |
112 | ||
113 | // Compute length | |
114 | wxUint32 length, seconds; | |
115 | ||
116 | length = m_file_stream->GetLength(); | |
117 | seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); | |
118 | m_length.seconds = seconds % 60; | |
119 | m_length.minutes = (seconds / 60) % 60; | |
120 | m_length.hours = seconds / 3600; | |
121 | } | |
122 | ||
123 | MMBoardSoundFile::~MMBoardSoundFile() | |
124 | { | |
125 | delete m_file_stream; | |
126 | MMBoardManager::UnrefSoundStream(m_output_stream); | |
127 | delete m_input_stream; | |
128 | } | |
129 | ||
130 | wxSoundFileStream *MMBoardSoundFile::GetDecoder() | |
131 | { | |
132 | wxSoundFileStream *f_stream; | |
133 | ||
134 | // First, we try a Wave decoder | |
135 | f_stream = new wxSoundWave(*m_input_stream, *m_output_stream); | |
136 | if (f_stream->CanRead()) | |
137 | return f_stream; | |
138 | delete f_stream; | |
139 | ||
140 | // Then, a AIFF decoder | |
141 | f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream); | |
142 | if (f_stream->CanRead()) | |
143 | return f_stream; | |
144 | delete f_stream; | |
145 | ||
146 | // TODO: automate | |
147 | ||
148 | return NULL; | |
149 | } | |
150 | ||
151 | MMBoardTime MMBoardSoundFile::GetLength() | |
152 | { | |
153 | return m_length; | |
154 | } | |
155 | ||
156 | bool MMBoardSoundFile::IsStopped() | |
157 | { | |
158 | return m_file_stream->IsStopped(); | |
159 | } | |
160 | ||
5bee458a GL |
161 | bool MMBoardSoundFile::IsPaused() |
162 | { | |
163 | return m_file_stream->IsPaused(); | |
164 | } | |
165 | ||
55196c54 GL |
166 | MMBoardTime MMBoardSoundFile::GetPosition() |
167 | { | |
168 | wxUint32 length, seconds; | |
169 | MMBoardTime file_time; | |
170 | ||
171 | file_time.seconds = file_time.minutes = file_time.hours = 0; | |
172 | if (m_file_stream->IsStopped()) | |
173 | return file_time; | |
174 | ||
175 | length = m_file_stream->GetPosition(); | |
176 | seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); | |
177 | file_time.seconds = seconds % 60; | |
178 | file_time.minutes = (seconds / 60) % 60; | |
179 | file_time.hours = seconds / 3600; | |
180 | ||
181 | return file_time; | |
182 | } | |
183 | ||
184 | bool MMBoardSoundFile::NeedWindow() | |
185 | { | |
186 | return FALSE; | |
187 | } | |
188 | ||
189 | void MMBoardSoundFile::SetWindow(wxWindow *window) | |
190 | { | |
191 | } | |
192 | ||
193 | void MMBoardSoundFile::Play() | |
194 | { | |
195 | m_file_stream->Play(); | |
196 | } | |
197 | ||
198 | void MMBoardSoundFile::Pause() | |
199 | { | |
200 | m_file_stream->Pause(); | |
201 | } | |
202 | ||
203 | void MMBoardSoundFile::Resume() | |
204 | { | |
205 | m_file_stream->Resume(); | |
206 | } | |
207 | ||
208 | void MMBoardSoundFile::Stop() | |
209 | { | |
210 | m_file_stream->Stop(); | |
211 | } | |
212 | ||
213 | wxString MMBoardSoundFile::GetStringType() | |
214 | { | |
215 | return wxString("WAVE file"); | |
216 | } | |
217 | ||
218 | wxString MMBoardSoundFile::GetStringInformation() | |
219 | { | |
220 | wxString info; | |
221 | wxSoundFormatBase *format; | |
222 | ||
223 | format = &(m_file_stream->GetSoundFormat()); | |
224 | ||
225 | info = _T("Data encoding: "); | |
226 | switch (format->GetType()) { | |
227 | case wxSOUND_PCM: { | |
228 | wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format; | |
229 | ||
230 | info += _T("PCM\n"); | |
231 | info += wxString::Format(_T("Sampling rate: %d\n") | |
232 | _T("Bits per sample: %d\n") | |
233 | _T("Number of channels: %d\n"), | |
234 | pcm_format->GetSampleRate(), | |
235 | pcm_format->GetBPS(), | |
236 | pcm_format->GetChannels()); | |
237 | ||
238 | break; | |
239 | } | |
240 | case wxSOUND_ULAW: { | |
241 | wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format; | |
242 | info += _T("ULAW\n"); | |
243 | info += wxString::Format(_T("Sampling rate: %d\n"), ulaw_format->GetSampleRate()); | |
244 | break; | |
245 | } | |
246 | default: | |
247 | info += _T("Unknown"); | |
248 | break; | |
249 | } | |
250 | return info; | |
251 | } | |
252 | ||
253 | // ---------------------------------------------------------------------------- | |
254 | ||
255 | ||
256 | // ---------------------------------------------------------------------------- | |
257 | // MMBoardFile | |
258 | ||
259 | MMBoardFile::MMBoardFile() | |
260 | { | |
261 | m_error = 0; | |
262 | } | |
263 | ||
264 | MMBoardFile::~MMBoardFile() | |
265 | { | |
266 | } | |
267 | ||
268 | // | |
269 | // ---------------------------------------------------------------------------- | |
270 | ||
271 | // ---------------------------------------------------------------------------- | |
272 | // MMBoardManager | |
273 | ||
274 | MMBoardFile *MMBoardManager::Open(const wxString& filename) | |
275 | { | |
276 | MMBoardFile *file; | |
277 | ||
278 | file = new MMBoardSoundFile(filename); | |
279 | if (file->GetError()) { | |
280 | delete file; | |
281 | return NULL; | |
282 | } | |
283 | return file; | |
284 | } | |
285 | ||
286 | DECLARE_APP(MMBoardApp) | |
287 | ||
288 | wxSoundStream *MMBoardManager::OpenSoundStream() | |
289 | { | |
290 | #ifdef __UNIX__ | |
291 | if ((wxGetApp().m_caps & MM_SOUND_ESD) != 0) | |
292 | return new wxSoundStreamESD(); | |
293 | ||
294 | if ((wxGetApp().m_caps & MM_SOUND_OSS) != 0) | |
295 | return new wxSoundStreamOSS(); | |
296 | #endif | |
297 | ||
298 | #ifdef __WIN32__ | |
299 | if ((wxGetApp().m_caps & MM_SOUND_WIN) != 0) | |
300 | return new wxSoundStreamWin(); | |
301 | #endif | |
302 | ||
303 | wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK | wxICON_ERROR, NULL); | |
304 | ||
305 | return NULL; | |
306 | } | |
307 | ||
308 | void MMBoardManager::UnrefSoundStream(wxSoundStream *stream) | |
309 | { | |
310 | delete stream; | |
311 | } | |
312 | ||
313 | // ---------------------------------------------------------------------------- | |
314 |