]>
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"
57 // ----------------------------------------------------------------------------
58 // Private class definitions
59 // ----------------------------------------------------------------------------
61 class MMBoardSoundFile
: public MMBoardFile
{
63 MMBoardSoundFile(const wxString
& filename
);
68 void SetWindow(wxWindow
*window
);
75 MMBoardTime
GetPosition();
76 MMBoardTime
GetLength();
80 wxString
GetStringType();
81 wxString
GetStringInformation();
84 wxSoundFileStream
*GetDecoder();
86 wxSoundStream
*m_output_stream
;
87 wxInputStream
*m_input_stream
;
88 wxSoundFileStream
*m_file_stream
;
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
101 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
104 m_input_stream
= new wxFileInputStream(filename
);
105 m_output_stream
= MMBoardManager::OpenSoundStream();
107 m_file_stream
= GetDecoder();
110 SetError(MMBoard_UnknownFile
);
113 wxUint32 length
, seconds
;
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;
122 MMBoardSoundFile::~MMBoardSoundFile()
124 delete m_file_stream
;
125 MMBoardManager::UnrefSoundStream(m_output_stream
);
126 delete m_input_stream
;
129 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
131 wxSoundFileStream
*f_stream
;
133 // First, we try a Wave decoder
134 f_stream
= new wxSoundWave(*m_input_stream
, *m_output_stream
);
135 if (f_stream
->CanRead())
139 // Then, a AIFF decoder
140 f_stream
= new wxSoundAiff(*m_input_stream
, *m_output_stream
);
141 if (f_stream
->CanRead())
150 MMBoardTime
MMBoardSoundFile::GetLength()
155 bool MMBoardSoundFile::IsStopped()
157 return m_file_stream
->IsStopped();
160 MMBoardTime
MMBoardSoundFile::GetPosition()
162 wxUint32 length
, seconds
;
163 MMBoardTime file_time
;
165 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
166 if (m_file_stream
->IsStopped())
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;
178 bool MMBoardSoundFile::NeedWindow()
183 void MMBoardSoundFile::SetWindow(wxWindow
*window
)
187 void MMBoardSoundFile::Play()
189 m_file_stream
->Play();
192 void MMBoardSoundFile::Pause()
194 m_file_stream
->Pause();
197 void MMBoardSoundFile::Resume()
199 m_file_stream
->Resume();
202 void MMBoardSoundFile::Stop()
204 m_file_stream
->Stop();
207 wxString
MMBoardSoundFile::GetStringType()
209 return wxString("WAVE file");
212 wxString
MMBoardSoundFile::GetStringInformation()
215 wxSoundFormatBase
*format
;
217 format
= &(m_file_stream
->GetSoundFormat());
219 info
= _T("Data encoding: ");
220 switch (format
->GetType()) {
222 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
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());
235 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
236 info
+= _T("ULAW\n");
237 info
+= wxString::Format(_T("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
241 info
+= _T("Unknown");
247 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
253 MMBoardFile::MMBoardFile()
258 MMBoardFile::~MMBoardFile()
263 // ----------------------------------------------------------------------------
265 // ----------------------------------------------------------------------------
268 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
272 file
= new MMBoardSoundFile(filename
);
273 if (file
->GetError()) {
280 DECLARE_APP(MMBoardApp
)
282 wxSoundStream
*MMBoardManager::OpenSoundStream()
285 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
286 return new wxSoundStreamESD();
288 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
289 return new wxSoundStreamOSS();
293 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
294 return new wxSoundStreamWin();
297 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
302 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
307 // ----------------------------------------------------------------------------