]>
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("WAVE file");
269 return wxString("AIFF file");
272 return wxString("Unknown file");
277 wxString
MMBoardSoundFile::GetStringInformation()
280 wxSoundFormatBase
*format
;
282 format
= &(m_file_stream
->GetSoundFormat());
284 info
= _T("Data encoding: ");
285 switch (format
->GetType()) {
287 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
290 info
+= wxString::Format(_T("Sampling rate: %d\n")
291 _T("Bits per sample: %d\n")
292 _T("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
+= _T("ULAW\n");
302 info
+= wxString::Format(_T("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
306 info
+= _T("Unknown");
312 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
318 MMBoardVideoFile::MMBoardVideoFile(const wxString
& filename
)
320 m_output_window
= NULL
;
321 m_input_stream
= new wxFileInputStream(filename
);
323 #if defined(__UNIX__)
324 m_video_driver
= new wxVideoXANIM(*m_input_stream
);
325 #elif defined(__WIN32__)
326 m_video_driver
= new wxVideoWindows(m_input_stream
);
328 m_video_driver
= NULL
;
329 SetError(MMBoard_UnknownFile
);
333 MMBoardVideoFile::~MMBoardVideoFile()
336 delete m_video_driver
;
338 delete m_input_stream
;
341 bool MMBoardVideoFile::NeedWindow()
346 void MMBoardVideoFile::SetWindow(wxWindow
*window
)
348 m_output_window
= window
;
349 m_video_driver
->AttachOutput(*window
);
352 void MMBoardVideoFile::Play()
354 m_video_driver
->Play();
357 void MMBoardVideoFile::Pause()
359 m_video_driver
->Pause();
362 void MMBoardVideoFile::Resume()
364 m_video_driver
->Resume();
367 void MMBoardVideoFile::Stop()
369 m_video_driver
->Stop();
372 MMBoardTime
MMBoardVideoFile::GetPosition()
376 btime
.seconds
= btime
.minutes
= btime
.hours
= 0;
380 MMBoardTime
MMBoardVideoFile::GetLength()
385 btime
.minutes
= btime
.hours
= 0;
389 bool MMBoardVideoFile::IsStopped()
391 return m_video_driver
->IsStopped();
394 bool MMBoardVideoFile::IsPaused()
396 return m_video_driver
->IsPaused();
399 wxString
MMBoardVideoFile::GetStringType()
401 return wxString("Video XANIM");
404 wxString
MMBoardVideoFile::GetStringInformation()
406 return wxString("No info");
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
414 MMBoardFile::MMBoardFile()
419 MMBoardFile::~MMBoardFile()
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
429 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
433 // Test the audio codec
434 file
= new MMBoardSoundFile(filename
);
435 if (!file
->GetError())
439 // Test the video codec
440 file
= new MMBoardVideoFile(filename
);
441 if (!file
->GetError())
445 // Arrrgh, we just could not see what is that file ...
449 DECLARE_APP(MMBoardApp
)
451 wxSoundStream
*MMBoardManager::OpenSoundStream()
454 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
455 return new wxSoundStreamESD();
457 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
458 return new wxSoundStreamOSS();
462 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
463 return new wxSoundStreamWin();
466 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
471 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
476 // ----------------------------------------------------------------------------