]>
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
);
88 void OpenVideoWindow();
89 void CloseVideoWindow();
92 // any class wishing to process wxWindows events must use this macro
96 void UpdateMMedInfo();
97 void UpdateInfoText();
99 MMBoardFile
*m_opened_file
;
101 wxSlider
*m_positionSlider
;
102 wxBitmapButton
*m_playButton
, *m_pauseButton
, *m_stopButton
, *m_ejectButton
;
103 wxStaticText
*m_fileType
, *m_infoText
;
104 wxWindow
*m_video_window
;
109 wxTimer
*m_refreshTimer
;
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 // IDs for the controls and the menu commands
124 MMBoard_PositionSlider
,
127 MMBoard_ResumeButton
,
133 // ----------------------------------------------------------------------------
134 // event tables and other macros for wxWindows
135 // ----------------------------------------------------------------------------
137 BEGIN_EVENT_TABLE(MMBoardFrame
, wxFrame
)
138 EVT_MENU(MMBoard_Quit
, MMBoardFrame::OnQuit
)
139 EVT_MENU(MMBoard_About
, MMBoardFrame::OnAbout
)
140 EVT_MENU(MMBoard_Open
, MMBoardFrame::OnOpen
)
141 EVT_BUTTON(MMBoard_PlayButton
, MMBoardFrame::OnPlay
)
142 EVT_BUTTON(MMBoard_StopButton
, MMBoardFrame::OnStop
)
143 EVT_BUTTON(MMBoard_PauseButton
, MMBoardFrame::OnPause
)
144 EVT_CUSTOM(wxEVT_TIMER
, MMBoard_RefreshInfo
, MMBoardFrame::OnRefreshInfo
)
147 // ---------------------------------------------------------------------------
148 // Main board application launcher
149 // ---------------------------------------------------------------------------
151 IMPLEMENT_APP(MMBoardApp
)
153 // ============================================================================
155 // ============================================================================
157 // ----------------------------------------------------------------------------
158 // the application class
159 // ----------------------------------------------------------------------------
161 bool MMBoardApp::OnInit()
163 // create the main application window
164 MMBoardFrame
*frame
= new MMBoardFrame("Multimedia Board",
165 wxPoint(50, 50), wxSize(450, 340));
167 // and show it (the frames, unlike simple controls, are not shown when
168 // created initially)
171 m_caps
= TestMultimediaCaps();
174 wxMessageBox("Your system has no multimedia capabilities. We are exiting now.", "Major error !", wxOK
| wxICON_ERROR
, NULL
);
179 msg
.Printf("Detected : %s%s%s", (m_caps
& MM_SOUND_OSS
) ? "OSS " : "",
180 (m_caps
& MM_SOUND_ESD
) ? "ESD " : "",
181 (m_caps
& MM_SOUND_WIN
) ? "WIN" : "");
183 wxMessageBox(msg
, "Good !", wxOK
| wxICON_INFORMATION
, NULL
);
185 // success: wxApp::OnRun() will be called which will enter the main message
186 // loop and the application will run. If we returned FALSE here, the
187 // application would exit immediately.
191 wxUint8
MMBoardApp::TestMultimediaCaps()
199 // We test the OSS (Open Sound System) support.
201 dev
= new wxSoundStreamOSS();
202 if (dev
->GetError() == wxSOUND_NOERR
)
203 caps
|= MM_SOUND_OSS
;
206 // We now test the ESD support
208 dev
= new wxSoundStreamESD();
209 if (dev
->GetError() == wxSOUND_NOERR
)
210 caps
|= MM_SOUND_ESD
;
215 // We test the Windows sound support.
217 dev
= new wxSoundStreamWin();
218 if (dev
->GetError() == wxSOUND_NOERR
)
219 caps
|= MM_SOUND_WIN
;
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
231 MMBoardFrame::MMBoardFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
232 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
235 // we need this in order to allow the about menu relocation, since ABOUT is
236 // not the default id of the about menu
237 wxApp::s_macAboutMenuItemId
= MMBoard_About
;
240 // set the frame icon
241 SetIcon(wxICON(mondrian
));
244 wxMenu
*menuFile
= new wxMenu(_T(""), wxMENU_TEAROFF
);
246 // the "About" item should be in the help menu
247 wxMenu
*helpMenu
= new wxMenu
;
248 helpMenu
->Append(MMBoard_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
250 menuFile
->Append(MMBoard_Open
, _T("&Open\tAlt-O"), _T("Open file"));
251 menuFile
->AppendSeparator();
252 menuFile
->Append(MMBoard_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
254 // now append the freshly created menu to the menu bar...
255 wxMenuBar
*menuBar
= new wxMenuBar();
256 menuBar
->Append(menuFile
, _T("&File"));
257 menuBar
->Append(helpMenu
, _T("&Help"));
259 // ... and attach this menu bar to the frame
263 // create a status bar just for fun (by default with 1 pane only)
265 SetStatusText(_T("Welcome to wxWindows!"));
266 #endif // wxUSE_STATUSBAR
269 m_opened_file
= NULL
;
271 m_panel
= new wxPanel(this, -1);
273 // Initialize main slider
274 m_positionSlider
= new wxSlider( m_panel
, MMBoard_PositionSlider
, 0, 0, 60,
275 wxDefaultPosition
, wxSize(300, -1),
276 wxSL_HORIZONTAL
| wxSL_AUTOTICKS
);
277 m_positionSlider
->SetPageSize(60); // 60 secs
279 // Initialize info panel
280 wxPanel
*infoPanel
= new wxPanel( m_panel
, -1);
281 infoPanel
->SetBackgroundColour(*wxBLACK
);
282 infoPanel
->SetForegroundColour(*wxWHITE
);
284 wxBoxSizer
*infoSizer
= new wxBoxSizer(wxVERTICAL
);
286 m_fileType
= new wxStaticText(infoPanel
, -1, _T(""));
287 wxStaticLine
*line
= new wxStaticLine(infoPanel
, -1);
288 m_infoText
= new wxStaticText(infoPanel
, -1, "");
292 infoSizer
->Add(m_fileType
, 0, wxGROW
| wxALL
, 1);
293 infoSizer
->Add(line
, 0, wxGROW
| wxCENTRE
, 20);
294 infoSizer
->Add(m_infoText
, 0, wxGROW
| wxALL
, 1);
296 infoPanel
->SetSizer(infoSizer
);
297 infoPanel
->SetAutoLayout(TRUE
);
299 // Bitmap button panel
300 wxBoxSizer
*buttonSizer
= new wxBoxSizer(wxHORIZONTAL
);
302 wxBitmap
*play_bmp
= new wxBitmap(play_back_xpm
);
303 wxBitmap
*stop_bmp
= new wxBitmap(stop_back_xpm
);
304 wxBitmap
*eject_bmp
= new wxBitmap(eject_xpm
);
305 wxBitmap
*pause_bmp
= new wxBitmap(pause_xpm
);
307 m_playButton
= new wxBitmapButton(m_panel
, MMBoard_PlayButton
, *play_bmp
);
308 m_playButton
->Enable(FALSE
);
309 m_pauseButton
= new wxBitmapButton(m_panel
, MMBoard_PauseButton
, *pause_bmp
);
310 m_pauseButton
->Enable(FALSE
);
311 m_stopButton
= new wxBitmapButton(m_panel
, MMBoard_StopButton
, *stop_bmp
);
312 m_stopButton
->Enable(FALSE
);
313 m_ejectButton
= new wxBitmapButton(m_panel
, MMBoard_EjectButton
, *eject_bmp
);
314 m_ejectButton
->Enable(FALSE
);
316 buttonSizer
->Add(m_playButton
, 0, wxALL
, 2);
317 buttonSizer
->Add(m_pauseButton
, 0, wxALL
, 2);
318 buttonSizer
->Add(m_stopButton
, 0, wxALL
, 2);
319 buttonSizer
->Add(m_ejectButton
, 0, wxALL
, 2);
322 m_sizer
= new wxBoxSizer(wxVERTICAL
);
323 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
324 m_sizer
->Add(m_positionSlider
, 0, wxCENTRE
| wxGROW
| wxALL
, 2);
325 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
326 m_sizer
->Add(buttonSizer
, 0, wxALL
, 0);
327 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
328 m_sizer
->Add(infoPanel
, 1, wxCENTRE
| wxGROW
, 0);
330 m_panel
->SetSizer(m_sizer
);
331 m_panel
->SetAutoLayout(TRUE
);
333 m_sizer
->SetSizeHints(this);
336 m_refreshTimer
= new wxTimer(this, MMBoard_RefreshInfo
);
339 m_video_window
= NULL
;
342 m_opened_file
= NULL
;
345 MMBoardFrame::~MMBoardFrame()
348 delete m_opened_file
;
350 delete m_refreshTimer
;
353 void MMBoardFrame::OpenVideoWindow()
358 m_video_window
= new wxWindow(m_panel
, -1, wxDefaultPosition
, wxSize(400, 400));
359 m_video_window
->SetBackgroundColour(*wxBLACK
);
360 m_sizer
->Prepend(m_video_window
, 0, wxGROW
| wxSHRINK
| wxCENTRE
, 0);
365 void MMBoardFrame::CloseVideoWindow()
370 m_sizer
->Remove(m_video_window
);
371 delete m_video_window
;
372 m_video_window
= NULL
;
379 void MMBoardFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
381 // TRUE is to force the frame to close
385 void MMBoardFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
388 msg
.Printf( _T("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
389 _T("an example of the capabilities of the wxWindows multimedia classes.\n")
390 _T("Copyright 1999, 2000, Guilhem Lavaux.\n"));
392 wxMessageBox(msg
, "About MMBoard", wxOK
| wxICON_INFORMATION
, this);
395 void MMBoardFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
397 wxString selected_file
;
400 if (!m_opened_file
->IsStopped()) {
401 wxCommandEvent event2
;
404 delete m_opened_file
;
407 // select a file to be opened
408 selected_file
= wxLoadFileSelector("multimedia", "*", NULL
, this);
409 if (selected_file
.IsNull())
412 m_opened_file
= MMBoardManager::Open(selected_file
);
414 // Change the range values of the slider.
417 length
= m_opened_file
->GetLength();
418 m_positionSlider
->SetRange(0, length
.hours
* 3600 + length
.minutes
* 60 + length
.seconds
);
423 SetStatusText(selected_file
, 2);
428 // Enable a few buttons
429 m_playButton
->Enable(TRUE
);
430 m_ejectButton
->Enable(TRUE
);
432 if (m_opened_file
->NeedWindow()) {
434 m_opened_file
->SetWindow(m_video_window
);
439 void MMBoardFrame::UpdateInfoText()
441 wxString infotext1
, infotext2
;
444 infotext1
= _T("File type:\n\t");
445 infotext1
+= m_opened_file
->GetStringType() + _T("\n");
447 infotext2
= _T("File informations:\n\n");
448 infotext2
+= m_opened_file
->GetStringInformation();
450 infotext1
= _T("File type: \n\tNo file opened");
451 infotext2
= _T("File informations:\nNo information\n\n\n\n\n");
454 m_fileType
->SetLabel(infotext1
);
455 m_infoText
->SetLabel(infotext2
);
458 void MMBoardFrame::UpdateMMedInfo()
460 wxString temp_string
;
461 MMBoardTime current
, length
;
464 current
= m_opened_file
->GetPosition();
465 length
= m_opened_file
->GetLength();
468 // We refresh the status bar
469 temp_string
.Printf("%02d:%02d / %02d:%02d", current
.hours
* 60 + current
.minutes
,
470 current
.seconds
, length
.hours
* 60 + length
.minutes
, length
.seconds
);
471 SetStatusText(temp_string
, 1);
473 // We set the slider position
474 m_positionSlider
->SetValue(current
.hours
* 3600 + current
.minutes
* 60 + current
.seconds
);
477 // ----------------------------------------------------------------------------
478 // Playing management, refreshers, ...
480 void MMBoardFrame::OnRefreshInfo(wxEvent
& WXUNUSED(event
))
484 if (m_opened_file
->IsStopped()) {
485 m_refreshTimer
->Stop();
486 m_playButton
->Enable(TRUE
);
487 m_stopButton
->Enable(FALSE
);
488 m_pauseButton
->Enable(FALSE
);
492 void MMBoardFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
494 m_stopButton
->Enable(TRUE
);
495 m_pauseButton
->Enable(TRUE
);
496 m_playButton
->Enable(FALSE
);
498 if (m_opened_file
->IsPaused()) {
499 m_opened_file
->Resume();
503 m_refreshTimer
->Start(1000, FALSE
);
505 m_opened_file
->Play();
507 m_stopButton
->Enable(TRUE
);
508 m_pauseButton
->Enable(TRUE
);
509 m_playButton
->Enable(FALSE
);
512 void MMBoardFrame::OnStop(wxCommandEvent
& WXUNUSED(event
))
514 m_opened_file
->Stop();
515 m_refreshTimer
->Stop();
517 m_stopButton
->Enable(FALSE
);
518 m_playButton
->Enable(TRUE
);
523 void MMBoardFrame::OnPause(wxCommandEvent
& WXUNUSED(event
))
525 m_opened_file
->Pause();
527 m_playButton
->Enable(TRUE
);
528 m_pauseButton
->Enable(FALSE
);