]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmbman.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Multimedia Board manager
4 // Author: Guilhem Lavaux, <guilhem.lavaux@libertysurf.fr>
8 // Copyright: (c) 2000, Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mmbman.cpp"
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers
35 #include "wx/stream.h"
36 #include "wx/wfstream.h"
66 // ----------------------------------------------------------------------------
67 // Private class definitions
68 // ----------------------------------------------------------------------------
70 class MMBoardSoundFile
: public MMBoardFile
{
72 MMBoardSoundFile(const wxString
& filename
);
77 void SetWindow(wxWindow
*window
);
84 MMBoardTime
GetPosition();
85 MMBoardTime
GetLength();
90 wxString
GetStringType();
91 wxString
GetStringInformation();
94 wxSoundFileStream
*GetDecoder();
96 wxSoundStream
*m_output_stream
;
97 wxInputStream
*m_input_stream
;
98 wxSoundFileStream
*m_file_stream
;
100 MMBoardTime m_length
;
104 class MMBoardVideoFile
: public MMBoardFile
{
106 MMBoardVideoFile(const wxString
& filename
);
111 void SetWindow(wxWindow
*window
);
118 MMBoardTime
GetPosition();
119 MMBoardTime
GetLength();
124 wxString
GetStringType();
125 wxString
GetStringInformation();
128 wxWindow
*m_output_window
;
129 wxInputStream
*m_input_stream
;
130 wxVideoBaseDriver
*m_video_driver
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 #define MMBoard_UNKNOWNTYPE 0
138 #define MMBoard_WAVE 1
139 #define MMBoard_AIFF 2
141 // ----------------------------------------------------------------------------
144 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
147 m_input_stream
= new wxFileInputStream(filename
);
148 m_output_stream
= MMBoardManager::OpenSoundStream();
150 m_file_stream
= GetDecoder();
152 if (!m_file_stream
) {
153 SetError(MMBoard_UnknownFile
);
158 wxUint32 length
, seconds
;
160 length
= m_file_stream
->GetLength();
161 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
162 m_length
.seconds
= seconds
% 60;
163 m_length
.minutes
= (seconds
/ 60) % 60;
164 m_length
.hours
= seconds
/ 3600;
167 MMBoardSoundFile::~MMBoardSoundFile()
170 delete m_file_stream
;
171 MMBoardManager::UnrefSoundStream(m_output_stream
);
172 delete m_input_stream
;
175 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
177 wxSoundFileStream
*f_stream
;
179 // First, we try a Wave decoder
180 f_stream
= new wxSoundWave(*m_input_stream
, *m_output_stream
);
181 m_file_type
= MMBoard_WAVE
;
182 if (f_stream
->CanRead())
186 // Then, a AIFF decoder
187 f_stream
= new wxSoundAiff(*m_input_stream
, *m_output_stream
);
188 m_file_type
= MMBoard_AIFF
;
189 if (f_stream
->CanRead())
193 m_file_type
= MMBoard_UNKNOWNTYPE
;
200 MMBoardTime
MMBoardSoundFile::GetLength()
205 bool MMBoardSoundFile::IsStopped()
207 return m_file_stream
->IsStopped();
210 bool MMBoardSoundFile::IsPaused()
212 return m_file_stream
->IsPaused();
215 MMBoardTime
MMBoardSoundFile::GetPosition()
217 wxUint32 length
, seconds
;
218 MMBoardTime file_time
;
220 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
221 if (m_file_stream
->IsStopped())
224 length
= m_file_stream
->GetPosition();
225 seconds
= m_file_stream
->GetSoundFormat().GetTimeFromBytes(length
);
226 file_time
.seconds
= seconds
% 60;
227 file_time
.minutes
= (seconds
/ 60) % 60;
228 file_time
.hours
= seconds
/ 3600;
233 bool MMBoardSoundFile::NeedWindow()
238 void MMBoardSoundFile::SetWindow(wxWindow
*window
)
242 void MMBoardSoundFile::Play()
244 m_file_stream
->Play();
247 void MMBoardSoundFile::Pause()
249 m_file_stream
->Pause();
252 void MMBoardSoundFile::Resume()
254 m_file_stream
->Resume();
257 void MMBoardSoundFile::Stop()
259 m_file_stream
->Stop();
262 wxString
MMBoardSoundFile::GetStringType()
264 switch (m_file_type
) {
266 return wxString(wxT("WAVE file"));
269 return wxString(wxT("AIFF file"));
272 return wxString(wxT("Unknown file"));
277 wxString
MMBoardSoundFile::GetStringInformation()
280 wxSoundFormatBase
*format
;
282 format
= &(m_file_stream
->GetSoundFormat());
284 info
= wxT("Data encoding: ");
285 switch (format
->GetType()) {
287 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
289 info
+= wxT("PCM\n");
290 info
+= wxString::Format(wxT("Sampling rate: %d\n")
291 wxT("Bits per sample: %d\n")
292 wxT("Number of channels: %d\n"),
293 pcm_format
->GetSampleRate(),
294 pcm_format
->GetBPS(),
295 pcm_format
->GetChannels());
300 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
301 info
+= wxT("ULAW\n");
302 info
+= wxString::Format(wxT("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
306 info
+= wxT("Unknown");
312 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
318 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
320 m_output_window
= NULL
;
322 #if defined(__UNIX__)
323 m_video_driver
= new wxVideoXANIM(filename
);
324 #elif defined(__WIN32__)
325 m_video_driver
= new wxVideoWindows(filename
);
327 m_video_driver
= NULL
;
328 SetError(MMBoard_UnknownFile
);
332 MMBoardVideoFile::~MMBoardVideoFile()
335 delete m_video_driver
;
337 delete m_input_stream
;
340 bool MMBoardVideoFile::NeedWindow()
345 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
347 m_output_window
= window
;
348 m_video_driver
->AttachOutput(*window
);
351 void MMBoardVideoFile::Play()
353 m_video_driver
->Play();
356 void MMBoardVideoFile::Pause()
358 m_video_driver
->Pause();
361 void MMBoardVideoFile::Resume()
363 m_video_driver
->Resume();
366 void MMBoardVideoFile::Stop()
368 m_video_driver
->Stop();
371 MMBoardTime
MMBoardVideoFile::GetPosition()
375 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
379 MMBoardTime
MMBoardVideoFile::GetLength()
384 btime
.minutes
= btime
.hours
= 0;
388 bool MMBoardVideoFile::IsStopped()
390 return m_video_driver
->IsStopped();
393 bool MMBoardVideoFile::IsPaused()
395 return m_video_driver
->IsPaused();
398 wxString
MMBoardVideoFile::GetStringType()
400 return wxString(wxT("Video XANIM"));
403 wxString
MMBoardVideoFile::GetStringInformation()
405 return wxString(wxT("No info"));
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
413 MMBoardFile::MMBoardFile()
418 MMBoardFile::~MMBoardFile()
423 // ----------------------------------------------------------------------------
425 // ----------------------------------------------------------------------------
428 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
432 // Test the audio codec
433 file
= new MMBoardSoundFile(filename
);
434 if (!file
->GetError())
438 // Test the video codec
439 file
= new MMBoardVideoFile(filename
);
440 if (!file
->GetError())
444 // Arrrgh, we just could not see what is that file ...
448 DECLARE_APP(MMBoardApp
)
450 wxSoundStream
*MMBoardManager::OpenSoundStream()
453 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
454 return new wxSoundStreamESD();
456 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
457 return new wxSoundStreamOSS();
461 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
462 return new wxSoundStreamWin();
465 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
470 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
475 // ----------------------------------------------------------------------------