]>
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();
81 wxString
GetStringType();
82 wxString
GetStringInformation();
85 wxSoundFileStream
*GetDecoder();
87 wxSoundStream
*m_output_stream
;
88 wxInputStream
*m_input_stream
;
89 wxSoundFileStream
*m_file_stream
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
102 MMBoardSoundFile::MMBoardSoundFile(const wxString
& filename
)
105 m_input_stream
= new wxFileInputStream(filename
);
106 m_output_stream
= MMBoardManager::OpenSoundStream();
108 m_file_stream
= GetDecoder();
111 SetError(MMBoard_UnknownFile
);
114 wxUint32 length
, seconds
;
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;
123 MMBoardSoundFile::~MMBoardSoundFile()
125 delete m_file_stream
;
126 MMBoardManager::UnrefSoundStream(m_output_stream
);
127 delete m_input_stream
;
130 wxSoundFileStream
*MMBoardSoundFile::GetDecoder()
132 wxSoundFileStream
*f_stream
;
134 // First, we try a Wave decoder
135 f_stream
= new wxSoundWave(*m_input_stream
, *m_output_stream
);
136 if (f_stream
->CanRead())
140 // Then, a AIFF decoder
141 f_stream
= new wxSoundAiff(*m_input_stream
, *m_output_stream
);
142 if (f_stream
->CanRead())
151 MMBoardTime
MMBoardSoundFile::GetLength()
156 bool MMBoardSoundFile::IsStopped()
158 return m_file_stream
->IsStopped();
161 bool MMBoardSoundFile::IsPaused()
163 return m_file_stream
->IsPaused();
166 MMBoardTime
MMBoardSoundFile::GetPosition()
168 wxUint32 length
, seconds
;
169 MMBoardTime file_time
;
171 file_time
.seconds
= file_time
.minutes
= file_time
.hours
= 0;
172 if (m_file_stream
->IsStopped())
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;
184 bool MMBoardSoundFile::NeedWindow()
189 void MMBoardSoundFile::SetWindow(wxWindow
*window
)
193 void MMBoardSoundFile::Play()
195 m_file_stream
->Play();
198 void MMBoardSoundFile::Pause()
200 m_file_stream
->Pause();
203 void MMBoardSoundFile::Resume()
205 m_file_stream
->Resume();
208 void MMBoardSoundFile::Stop()
210 m_file_stream
->Stop();
213 wxString
MMBoardSoundFile::GetStringType()
215 return wxString("WAVE file");
218 wxString
MMBoardSoundFile::GetStringInformation()
221 wxSoundFormatBase
*format
;
223 format
= &(m_file_stream
->GetSoundFormat());
225 info
= _T("Data encoding: ");
226 switch (format
->GetType()) {
228 wxSoundFormatPcm
*pcm_format
= (wxSoundFormatPcm
*)format
;
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());
241 wxSoundFormatUlaw
*ulaw_format
= (wxSoundFormatUlaw
*)format
;
242 info
+= _T("ULAW\n");
243 info
+= wxString::Format(_T("Sampling rate: %d\n"), ulaw_format
->GetSampleRate());
247 info
+= _T("Unknown");
253 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
259 MMBoardFile::MMBoardFile()
264 MMBoardFile::~MMBoardFile()
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
274 MMBoardFile
*MMBoardManager::Open(const wxString
& filename
)
278 file
= new MMBoardSoundFile(filename
);
279 if (file
->GetError()) {
286 DECLARE_APP(MMBoardApp
)
288 wxSoundStream
*MMBoardManager::OpenSoundStream()
291 if ((wxGetApp().m_caps
& MM_SOUND_ESD
) != 0)
292 return new wxSoundStreamESD();
294 if ((wxGetApp().m_caps
& MM_SOUND_OSS
) != 0)
295 return new wxSoundStreamOSS();
299 if ((wxGetApp().m_caps
& MM_SOUND_WIN
) != 0)
300 return new wxSoundStreamWin();
303 wxMessageBox("You are trying to open a multimedia but you have not devices", "Error", wxOK
| wxICON_ERROR
, NULL
);
308 void MMBoardManager::UnrefSoundStream(wxSoundStream
*stream
)
313 // ----------------------------------------------------------------------------