]>
Commit | Line | Data |
---|---|---|
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(); | |
79 | ||
80 | wxString GetStringType(); | |
81 | wxString GetStringInformation(); | |
82 | ||
83 | protected: | |
84 | wxSoundFileStream *GetDecoder(); | |
85 | ||
86 | wxSoundStream *m_output_stream; | |
87 | wxInputStream *m_input_stream; | |
88 | wxSoundFileStream *m_file_stream; | |
89 | ||
90 | MMBoardTime m_length; | |
91 | }; | |
92 | ||
93 | // ---------------------------------------------------------------------------- | |
94 | // Implementation | |
95 | // ---------------------------------------------------------------------------- | |
96 | ||
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // MMBoardSoundFile | |
100 | ||
101 | MMBoardSoundFile::MMBoardSoundFile(const wxString& filename) | |
102 | : MMBoardFile() | |
103 | { | |
104 | m_input_stream = new wxFileInputStream(filename); | |
105 | m_output_stream = MMBoardManager::OpenSoundStream(); | |
106 | ||
107 | m_file_stream = GetDecoder(); | |
108 | ||
109 | if (!m_file_stream) | |
110 | SetError(MMBoard_UnknownFile); | |
111 | ||
112 | // Compute length | |
113 | wxUint32 length, seconds; | |
114 | ||
115 | length = m_file_stream->GetLength(); | |
116 | seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); | |
117 | m_length.seconds = seconds % 60; | |
118 | m_length.minutes = (seconds / 60) % 60; | |
119 | m_length.hours = seconds / 3600; | |
120 | } | |
121 | ||
122 | MMBoardSoundFile::~MMBoardSoundFile() | |
123 | { | |
124 | delete m_file_stream; | |
125 | MMBoardManager::UnrefSoundStream(m_output_stream); | |
126 | delete m_input_stream; | |
127 | } | |
128 | ||
129 | wxSoundFileStream *MMBoardSoundFile::GetDecoder() | |
130 | { | |
131 | wxSoundFileStream *f_stream; | |
132 | ||
133 | // First, we try a Wave decoder | |
134 | f_stream = new wxSoundWave(*m_input_stream, *m_output_stream); | |
135 | if (f_stream->CanRead()) | |
136 | return f_stream; | |
137 | delete f_stream; | |
138 | ||
139 | // Then, a AIFF decoder | |
140 | f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream); | |
141 | if (f_stream->CanRead()) | |
142 | return f_stream; | |
143 | delete f_stream; | |
144 | ||
145 | // TODO: automate | |
146 | ||
147 | return NULL; | |
148 | } | |
149 | ||
150 | MMBoardTime MMBoardSoundFile::GetLength() | |
151 | { | |
152 | return m_length; | |
153 | } | |
154 | ||
155 | bool MMBoardSoundFile::IsStopped() | |
156 | { | |
157 | return m_file_stream->IsStopped(); | |
158 | } | |
159 | ||
160 | MMBoardTime MMBoardSoundFile::GetPosition() | |
161 | { | |
162 | wxUint32 length, seconds; | |
163 | MMBoardTime file_time; | |
164 | ||
165 | file_time.seconds = file_time.minutes = file_time.hours = 0; | |
166 | if (m_file_stream->IsStopped()) | |
167 | return file_time; | |
168 | ||
169 | length = m_file_stream->GetPosition(); | |
170 | seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); | |
171 | file_time.seconds = seconds % 60; | |
172 | file_time.minutes = (seconds / 60) % 60; | |
173 | file_time.hours = seconds / 3600; | |
174 | ||
175 | return file_time; | |
176 | } | |
177 | ||
178 | bool MMBoardSoundFile::NeedWindow() | |
179 | { | |
180 | return FALSE; | |
181 | } | |
182 | ||
183 | void MMBoardSoundFile::SetWindow(wxWindow *window) | |
184 | { | |
185 | } | |
186 | ||
187 | void MMBoardSoundFile::Play() | |
188 | { | |
189 | m_file_stream->Play(); | |
190 | } | |
191 | ||
192 | void MMBoardSoundFile::Pause() | |
193 | { | |
194 | m_file_stream->Pause(); | |
195 | } | |
196 | ||
197 | void MMBoardSoundFile::Resume() | |
198 | { | |
199 | m_file_stream->Resume(); | |
200 | } | |
201 | ||
202 | void MMBoardSoundFile::Stop() | |
203 | { | |
204 | m_file_stream->Stop(); | |
205 | } | |
206 | ||
207 | wxString MMBoardSoundFile::GetStringType() | |
208 | { | |
209 | return wxString("WAVE file"); | |
210 | } | |
211 | ||
212 | wxString MMBoardSoundFile::GetStringInformation() | |
213 | { | |
214 | wxString info; | |
215 | wxSoundFormatBase *format; | |
216 | ||
217 | format = &(m_file_stream->GetSoundFormat()); | |
218 | ||
219 | info = _T("Data encoding: "); | |
220 | switch (format->GetType()) { | |
221 | case wxSOUND_PCM: { | |
222 | wxSoundFormatPcm *pcm_format = (wxSoundFormatPcm *)format; | |
223 | ||
224 | info += _T("PCM\n"); | |
225 | info += wxString::Format(_T("Sampling rate: %d\n") | |
226 | _T("Bits per sample: %d\n") | |
227 | _T("Number of channels: %d\n"), | |
228 | pcm_format->GetSampleRate(), | |
229 | pcm_format->GetBPS(), | |
230 | pcm_format->GetChannels()); | |
231 | ||
232 | break; | |
233 | } | |
234 | case wxSOUND_ULAW: { | |
235 | wxSoundFormatUlaw *ulaw_format = (wxSoundFormatUlaw *)format; | |
236 | info += _T("ULAW\n"); | |
237 | info += wxString::Format(_T("Sampling rate: %d\n"), ulaw_format->GetSampleRate()); | |
238 | break; | |
239 | } | |
240 | default: | |
241 | info += _T("Unknown"); | |
242 | break; | |
243 | } | |
244 | return info; | |
245 | } | |
246 | ||
247 | // ---------------------------------------------------------------------------- | |
248 | ||
249 | ||
250 | // ---------------------------------------------------------------------------- | |
251 | // MMBoardFile | |
252 | ||
253 | MMBoardFile::MMBoardFile() | |
254 | { | |
255 | m_error = 0; | |
256 | } | |
257 | ||
258 | MMBoardFile::~MMBoardFile() | |
259 | { | |
260 | } | |
261 | ||
262 | // | |
263 | // ---------------------------------------------------------------------------- | |
264 | ||
265 | // ---------------------------------------------------------------------------- | |
266 | // MMBoardManager | |
267 | ||
268 | MMBoardFile *MMBoardManager::Open(const wxString& filename) | |
269 | { | |
270 | MMBoardFile *file; | |
271 | ||
272 | file = new MMBoardSoundFile(filename); | |
273 | if (file->GetError()) { | |
274 | delete file; | |
275 | return NULL; | |
276 | } | |
277 | return file; | |
278 | } | |
279 | ||
280 | DECLARE_APP(MMBoardApp) | |
281 | ||
282 | wxSoundStream *MMBoardManager::OpenSoundStream() | |
283 | { | |
284 | #ifdef __UNIX__ | |
285 | if ((wxGetApp().m_caps & MM_SOUND_ESD) != 0) | |
286 | return new wxSoundStreamESD(); | |
287 | ||
288 | if ((wxGetApp().m_caps & MM_SOUND_OSS) != 0) | |
289 | return new wxSoundStreamOSS(); | |
290 | #endif | |
291 | ||
292 | #ifdef __WIN32__ | |
293 | if ((wxGetApp().m_caps & MM_SOUND_WIN) != 0) | |
294 | return new wxSoundStreamWin(); | |
295 | #endif | |
296 | ||
297 | wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK | wxICON_ERROR, NULL); | |
298 | ||
299 | return NULL; | |
300 | } | |
301 | ||
302 | void MMBoardManager::UnrefSoundStream(wxSoundStream *stream) | |
303 | { | |
304 | delete stream; | |
305 | } | |
306 | ||
307 | // ---------------------------------------------------------------------------- | |
308 |