]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmboard.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Multimedia Library sample
4 // Author: Guilhem Lavaux (created from minimal by J. Smart)
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "mmboard.cpp"
23 // For compilers that support precompilation, includes "wx/wx.h".
24 #include "wx/wxprec.h"
30 // for all others, include the necessary headers (this file is usually all you
31 // need because it includes almost all "standard" wxWindows headers
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
39 // the application icon
40 #if defined(__WXGTK__) || defined(__WXMOTIF__)
41 #include "mondrian.xpm"
44 // include multimedia classes
54 #include "wx/statline.h"
55 #include "wx/stattext.h"
57 // include personnal classes
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // Main Multimedia Board frame
71 class MMBoardFrame
: public wxFrame
75 MMBoardFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
80 void OnQuit(wxCommandEvent
& event
);
81 void OnAbout(wxCommandEvent
& event
);
82 void OnOpen(wxCommandEvent
& event
);
83 void OnPlay(wxCommandEvent
& event
);
84 void OnStop(wxCommandEvent
& event
);
85 void OnPause(wxCommandEvent
& event
);
86 void OnRefreshInfo(wxEvent
& event
);
89 // any class wishing to process wxWindows events must use this macro
93 void UpdateMMedInfo();
94 void UpdateInfoText();
96 MMBoardFile
*m_opened_file
;
98 wxSlider
*m_positionSlider
;
99 wxBitmapButton
*m_playButton
, *m_pauseButton
, *m_stopButton
, *m_ejectButton
;
100 wxStaticText
*m_fileType
, *m_infoText
;
102 wxTimer
*m_refreshTimer
;
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 // IDs for the controls and the menu commands
116 MMBoard_PositionSlider
,
119 MMBoard_ResumeButton
,
125 // ----------------------------------------------------------------------------
126 // event tables and other macros for wxWindows
127 // ----------------------------------------------------------------------------
129 BEGIN_EVENT_TABLE(MMBoardFrame
, wxFrame
)
130 EVT_MENU(MMBoard_Quit
, MMBoardFrame::OnQuit
)
131 EVT_MENU(MMBoard_About
, MMBoardFrame::OnAbout
)
132 EVT_MENU(MMBoard_Open
, MMBoardFrame::OnOpen
)
133 EVT_BUTTON(MMBoard_PlayButton
, MMBoardFrame::OnPlay
)
134 EVT_BUTTON(MMBoard_StopButton
, MMBoardFrame::OnStop
)
135 EVT_BUTTON(MMBoard_PauseButton
, MMBoardFrame::OnPause
)
136 EVT_CUSTOM(wxEVT_TIMER
, MMBoard_RefreshInfo
, MMBoardFrame::OnRefreshInfo
)
139 // ---------------------------------------------------------------------------
140 // Main board application launcher
141 // ---------------------------------------------------------------------------
143 IMPLEMENT_APP(MMBoardApp
)
145 // ============================================================================
147 // ============================================================================
149 // ----------------------------------------------------------------------------
150 // the application class
151 // ----------------------------------------------------------------------------
153 bool MMBoardApp::OnInit()
155 // create the main application window
156 MMBoardFrame
*frame
= new MMBoardFrame("Multimedia Board",
157 wxPoint(50, 50), wxSize(450, 340));
159 // and show it (the frames, unlike simple controls, are not shown when
160 // created initially)
163 m_caps
= TestMultimediaCaps();
166 wxMessageBox("Your system has no multimedia capabilities. We are exiting now.", "Major error !", wxOK
| wxICON_ERROR
, NULL
);
171 msg
.Printf("Detected : %s%s%s", (m_caps
& MM_SOUND_OSS
) ? "OSS " : "",
172 (m_caps
& MM_SOUND_ESD
) ? "ESD " : "",
173 (m_caps
& MM_SOUND_WIN
) ? "WIN" : "");
175 wxMessageBox(msg
, "Good !", wxOK
| wxICON_INFORMATION
, NULL
);
177 // success: wxApp::OnRun() will be called which will enter the main message
178 // loop and the application will run. If we returned FALSE here, the
179 // application would exit immediately.
183 wxUint8
MMBoardApp::TestMultimediaCaps()
191 // We test the OSS (Open Sound System) support.
193 dev
= new wxSoundStreamOSS();
194 if (dev
->GetError() == wxSOUND_NOERR
)
195 caps
|= MM_SOUND_OSS
;
198 // We now test the ESD support
200 dev
= new wxSoundStreamESD();
201 if (dev
->GetError() == wxSOUND_NOERR
)
202 caps
|= MM_SOUND_ESD
;
207 // We test the Windows sound support.
209 dev
= new wxSoundStreamWin();
210 if (dev
->GetError() == wxSOUND_NOERR
)
211 caps
|= MM_SOUND_WIN
;
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
223 MMBoardFrame::MMBoardFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
224 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
227 // we need this in order to allow the about menu relocation, since ABOUT is
228 // not the default id of the about menu
229 wxApp::s_macAboutMenuItemId
= MMBoard_About
;
232 // set the frame icon
233 SetIcon(wxICON(mondrian
));
236 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
238 // the "About" item should be in the help menu
239 wxMenu
*helpMenu
= new wxMenu
;
240 helpMenu
->Append(MMBoard_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
242 menuFile
->Append(MMBoard_Open
, _T("&Open\tAlt-O"), _T("Open file"));
243 menuFile
->AppendSeparator();
244 menuFile
->Append(MMBoard_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
246 // now append the freshly created menu to the menu bar...
247 wxMenuBar
*menuBar
= new wxMenuBar();
248 menuBar
->Append(menuFile
, _T("&File"));
249 menuBar
->Append(helpMenu
, _T("&Help"));
251 // ... and attach this menu bar to the frame
255 // create a status bar just for fun (by default with 1 pane only)
257 SetStatusText(_T("Welcome to wxWindows!"));
258 #endif // wxUSE_STATUSBAR
261 m_opened_file
= NULL
;
263 wxPanel
*panel
= new wxPanel(this, -1);
265 // Initialize main slider
266 m_positionSlider
= new wxSlider( panel
, MMBoard_PositionSlider
, 0, 0, 60,
267 wxDefaultPosition
, wxSize(300, -1),
268 wxSL_HORIZONTAL
| wxSL_AUTOTICKS
);
269 m_positionSlider
->SetPageSize(60); // 60 secs
271 // Initialize info panel
272 wxPanel
*infoPanel
= new wxPanel( panel
, -1);
273 infoPanel
->SetBackgroundColour(*wxBLACK
);
274 infoPanel
->SetForegroundColour(*wxWHITE
);
276 wxBoxSizer
*infoSizer
= new wxBoxSizer(wxVERTICAL
);
278 m_fileType
= new wxStaticText(infoPanel
, -1, _T(""));
279 wxStaticLine
*line
= new wxStaticLine(infoPanel
, -1);
280 m_infoText
= new wxStaticText(infoPanel
, -1, "");
284 infoSizer
->Add(m_fileType
, 0, wxGROW
| wxALL
, 1);
285 infoSizer
->Add(line
, 0, wxGROW
| wxCENTRE
, 20);
286 infoSizer
->Add(m_infoText
, 0, wxGROW
| wxALL
, 1);
288 infoPanel
->SetSizer(infoSizer
);
289 infoPanel
->SetAutoLayout(TRUE
);
291 // Bitmap button panel
292 wxBoxSizer
*buttonSizer
= new wxBoxSizer(wxHORIZONTAL
);
294 wxBitmap
*play_bmp
= new wxBitmap(play_back_xpm
);
295 wxBitmap
*stop_bmp
= new wxBitmap(stop_back_xpm
);
296 wxBitmap
*eject_bmp
= new wxBitmap(eject_xpm
);
297 wxBitmap
*pause_bmp
= new wxBitmap(pause_xpm
);
299 m_playButton
= new wxBitmapButton(panel
, MMBoard_PlayButton
, *play_bmp
);
300 m_playButton
->Enable(FALSE
);
301 m_pauseButton
= new wxBitmapButton(panel
, MMBoard_PauseButton
, *pause_bmp
);
302 m_pauseButton
->Enable(FALSE
);
303 m_stopButton
= new wxBitmapButton(panel
, MMBoard_StopButton
, *stop_bmp
);
304 m_stopButton
->Enable(FALSE
);
305 m_ejectButton
= new wxBitmapButton(panel
, MMBoard_EjectButton
, *eject_bmp
);
306 m_ejectButton
->Enable(FALSE
);
308 buttonSizer
->Add(m_playButton
, 0, wxALL
, 2);
309 buttonSizer
->Add(m_pauseButton
, 0, wxALL
, 2);
310 buttonSizer
->Add(m_stopButton
, 0, wxALL
, 2);
311 buttonSizer
->Add(m_ejectButton
, 0, wxALL
, 2);
314 wxBoxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
315 sizer
->Add(new wxStaticLine(panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
316 sizer
->Add(m_positionSlider
, 0, wxCENTRE
| wxGROW
| wxALL
, 2);
317 sizer
->Add(new wxStaticLine(panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
318 sizer
->Add(buttonSizer
, 0, wxALL
, 0);
319 sizer
->Add(new wxStaticLine(panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
320 sizer
->Add(infoPanel
, 1, wxCENTRE
| wxGROW
, 0);
322 panel
->SetSizer(sizer
);
323 panel
->SetAutoLayout(TRUE
);
325 sizer
->SetSizeHints(this);
328 m_refreshTimer
= new wxTimer(this, MMBoard_RefreshInfo
);
331 MMBoardFrame::~MMBoardFrame()
334 delete m_opened_file
;
336 delete m_refreshTimer
;
341 void MMBoardFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
343 // TRUE is to force the frame to close
347 void MMBoardFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
350 msg
.Printf( _T("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
351 _T("an example of the capabilities of the wxWindows multimedia classes.\n")
352 _T("Copyright 1999, 2000, Guilhem Lavaux.\n"));
354 wxMessageBox(msg
, "About MMBoard", wxOK
| wxICON_INFORMATION
, this);
357 void MMBoardFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
359 wxString selected_file
;
361 // select a file to be opened
362 selected_file
= wxLoadFileSelector("multimedia", "*", NULL
, this);
363 if (selected_file
.IsNull())
366 m_opened_file
= MMBoardManager::Open(selected_file
);
368 // Change the range values of the slider.
371 length
= m_opened_file
->GetLength();
372 m_positionSlider
->SetRange(0, length
.hours
* 3600 + length
.minutes
* 60 + length
.seconds
);
377 SetStatusText(selected_file
, 2);
382 // Enable a few buttons
383 m_playButton
->Enable(TRUE
);
384 m_ejectButton
->Enable(TRUE
);
387 void MMBoardFrame::UpdateInfoText()
389 wxString infotext1
, infotext2
;
392 infotext1
= _T("File type:\n\t");
393 infotext1
+= m_opened_file
->GetStringType() + _T("\n");
395 infotext2
= _T("File informations:\n\n");
396 infotext2
+= m_opened_file
->GetStringInformation();
398 infotext1
= _T("File type: \n\tNo file opened");
399 infotext2
= _T("File informations:\nNo information\n\n\n\n\n");
402 m_fileType
->SetLabel(infotext1
);
403 m_infoText
->SetLabel(infotext2
);
406 void MMBoardFrame::UpdateMMedInfo()
408 wxString temp_string
;
409 MMBoardTime current
, length
;
412 current
= m_opened_file
->GetPosition();
413 length
= m_opened_file
->GetLength();
416 // We refresh the status bar
417 temp_string
.Printf("%02d:%02d / %02d:%02d", current
.hours
* 60 + current
.minutes
,
418 current
.seconds
, length
.hours
* 60 + length
.minutes
, length
.seconds
);
419 SetStatusText(temp_string
, 1);
421 // We set the slider position
422 m_positionSlider
->SetValue(current
.hours
* 3600 + current
.minutes
* 60 + current
.seconds
);
425 // ----------------------------------------------------------------------------
426 // Playing management, refreshers, ...
428 void MMBoardFrame::OnRefreshInfo(wxEvent
& WXUNUSED(event
))
432 if (m_opened_file
->IsStopped()) {
433 m_refreshTimer
->Stop();
434 m_playButton
->Enable(TRUE
);
435 m_stopButton
->Enable(FALSE
);
436 m_pauseButton
->Enable(FALSE
);
440 void MMBoardFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
442 m_refreshTimer
->Start(1000, FALSE
);
444 m_opened_file
->Play();
446 m_stopButton
->Enable(TRUE
);
447 m_pauseButton
->Enable(TRUE
);
448 m_playButton
->Enable(FALSE
);
451 void MMBoardFrame::OnStop(wxCommandEvent
& WXUNUSED(event
))
453 m_opened_file
->Stop();
454 m_refreshTimer
->Stop();
456 m_stopButton
->Enable(FALSE
);
457 m_playButton
->Enable(TRUE
);
462 void MMBoardFrame::OnPause(wxCommandEvent
& WXUNUSED(event
))
464 m_opened_file
->Pause();
466 m_playButton
->Enable(TRUE
);
467 m_pauseButton
->Enable(FALSE
);