]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/board/mmboard.cpp
f20d3ea6d9c94b4af6ca8f57af104a4546165d27
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 OnEject(wxCommandEvent
& event
);
87 void OnRefreshInfo(wxEvent
& event
);
88 void OnSetPosition(wxCommandEvent
& event
);
90 void OpenVideoWindow();
91 void CloseVideoWindow();
94 // any class wishing to process wxWindows events must use this macro
98 void UpdateMMedInfo();
99 void UpdateInfoText();
101 MMBoardFile
*m_opened_file
;
103 wxSlider
*m_positionSlider
;
104 wxBitmapButton
*m_playButton
, *m_pauseButton
, *m_stopButton
, *m_ejectButton
;
105 wxStaticText
*m_fileType
, *m_infoText
;
106 wxWindow
*m_video_window
;
111 wxTimer
*m_refreshTimer
;
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 // IDs for the controls and the menu commands
125 MMBoard_PositionSlider
,
128 MMBoard_ResumeButton
,
134 // ----------------------------------------------------------------------------
135 // event tables and other macros for wxWindows
136 // ----------------------------------------------------------------------------
138 BEGIN_EVENT_TABLE(MMBoardFrame
, wxFrame
)
139 EVT_MENU(MMBoard_Quit
, MMBoardFrame::OnQuit
)
140 EVT_MENU(MMBoard_About
, MMBoardFrame::OnAbout
)
141 EVT_MENU(MMBoard_Open
, MMBoardFrame::OnOpen
)
142 EVT_BUTTON(MMBoard_PlayButton
, MMBoardFrame::OnPlay
)
143 EVT_BUTTON(MMBoard_StopButton
, MMBoardFrame::OnStop
)
144 EVT_BUTTON(MMBoard_PauseButton
, MMBoardFrame::OnPause
)
145 EVT_BUTTON(MMBoard_EjectButton
, MMBoardFrame::OnEject
)
146 EVT_SLIDER(MMBoard_PositionSlider
, MMBoardFrame::OnSetPosition
)
147 EVT_CUSTOM(wxEVT_TIMER
, MMBoard_RefreshInfo
, MMBoardFrame::OnRefreshInfo
)
150 // ---------------------------------------------------------------------------
151 // Main board application launcher
152 // ---------------------------------------------------------------------------
154 IMPLEMENT_APP(MMBoardApp
)
156 // ============================================================================
158 // ============================================================================
160 // ----------------------------------------------------------------------------
161 // the application class
162 // ----------------------------------------------------------------------------
164 bool MMBoardApp::OnInit()
166 // create the main application window
167 MMBoardFrame
*frame
= new MMBoardFrame("Multimedia Board",
168 wxPoint(50, 50), wxSize(450, 340));
170 // and show it (the frames, unlike simple controls, are not shown when
171 // created initially)
174 m_caps
= TestMultimediaCaps();
177 wxMessageBox("Your system has no multimedia capabilities. We are exiting now.", "Major error !", wxOK
| wxICON_ERROR
, NULL
);
182 msg
.Printf("Detected : %s%s%s", (m_caps
& MM_SOUND_OSS
) ? "OSS " : "",
183 (m_caps
& MM_SOUND_ESD
) ? "ESD " : "",
184 (m_caps
& MM_SOUND_WIN
) ? "WIN" : "");
186 wxMessageBox(msg
, "Good !", wxOK
| wxICON_INFORMATION
, NULL
);
188 // success: wxApp::OnRun() will be called which will enter the main message
189 // loop and the application will run. If we returned FALSE here, the
190 // application would exit immediately.
194 wxUint8
MMBoardApp::TestMultimediaCaps()
202 // We now test the ESD support
204 dev
= new wxSoundStreamESD();
205 if (dev
->GetError() == wxSOUND_NOERROR
)
206 caps
|= MM_SOUND_ESD
;
209 // We test the OSS (Open Sound System) support.
210 // WARNING: There is a conflict between ESD and ALSA
212 dev
= new wxSoundStreamOSS();
213 if (dev
->GetError() == wxSOUND_NOERROR
)
214 caps
|= MM_SOUND_OSS
;
219 // We test the Windows sound support.
221 dev
= new wxSoundStreamWin();
222 if (dev
->GetError() == wxSOUND_NOERR
)
223 caps
|= MM_SOUND_WIN
;
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
235 MMBoardFrame::MMBoardFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
236 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
239 // we need this in order to allow the about menu relocation, since ABOUT is
240 // not the default id of the about menu
241 wxApp::s_macAboutMenuItemId
= MMBoard_About
;
244 // set the frame icon
245 SetIcon(wxICON(mondrian
));
248 wxMenu
*menuFile
= new wxMenu(wxT(""), wxMENU_TEAROFF
);
250 // the "About" item should be in the help menu
251 wxMenu
*helpMenu
= new wxMenu
;
252 helpMenu
->Append(MMBoard_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
254 menuFile
->Append(MMBoard_Open
, wxT("&Open\tAlt-O"), wxT("Open file"));
255 menuFile
->AppendSeparator();
256 menuFile
->Append(MMBoard_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
258 // now append the freshly created menu to the menu bar...
259 wxMenuBar
*menuBar
= new wxMenuBar();
260 menuBar
->Append(menuFile
, wxT("&File"));
261 menuBar
->Append(helpMenu
, wxT("&Help"));
263 // ... and attach this menu bar to the frame
267 // create a status bar just for fun (by default with 1 pane only)
269 SetStatusText(wxT("Welcome to wxWindows!"));
270 #endif // wxUSE_STATUSBAR
273 m_opened_file
= NULL
;
275 m_panel
= new wxPanel(this, -1);
277 // Initialize main slider
278 m_positionSlider
= new wxSlider( m_panel
, MMBoard_PositionSlider
, 0, 0, 60,
279 wxDefaultPosition
, wxSize(300, -1),
280 wxSL_HORIZONTAL
| wxSL_AUTOTICKS
);
281 m_positionSlider
->SetPageSize(60); // 60 secs
282 m_positionSlider
->Enable(FALSE
);
284 // Initialize info panel
285 wxPanel
*infoPanel
= new wxPanel( m_panel
, -1);
286 infoPanel
->SetBackgroundColour(*wxBLACK
);
287 infoPanel
->SetForegroundColour(*wxWHITE
);
289 wxBoxSizer
*infoSizer
= new wxBoxSizer(wxVERTICAL
);
291 m_fileType
= new wxStaticText(infoPanel
, -1, wxT(""));
292 wxStaticLine
*line
= new wxStaticLine(infoPanel
, -1);
293 m_infoText
= new wxStaticText(infoPanel
, -1, "");
297 infoSizer
->Add(m_fileType
, 0, wxGROW
| wxALL
, 1);
298 infoSizer
->Add(line
, 0, wxGROW
| wxCENTRE
, 20);
299 infoSizer
->Add(m_infoText
, 0, wxGROW
| wxALL
, 1);
301 infoPanel
->SetSizer(infoSizer
);
302 infoPanel
->SetAutoLayout(TRUE
);
304 // Bitmap button panel
305 wxBoxSizer
*buttonSizer
= new wxBoxSizer(wxHORIZONTAL
);
307 wxBitmap
*play_bmp
= new wxBitmap(play_back_xpm
);
308 wxBitmap
*stop_bmp
= new wxBitmap(stop_back_xpm
);
309 wxBitmap
*eject_bmp
= new wxBitmap(eject_xpm
);
310 wxBitmap
*pause_bmp
= new wxBitmap(pause_xpm
);
312 m_playButton
= new wxBitmapButton(m_panel
, MMBoard_PlayButton
, *play_bmp
);
313 m_playButton
->Enable(FALSE
);
314 m_pauseButton
= new wxBitmapButton(m_panel
, MMBoard_PauseButton
, *pause_bmp
);
315 m_pauseButton
->Enable(FALSE
);
316 m_stopButton
= new wxBitmapButton(m_panel
, MMBoard_StopButton
, *stop_bmp
);
317 m_stopButton
->Enable(FALSE
);
318 m_ejectButton
= new wxBitmapButton(m_panel
, MMBoard_EjectButton
, *eject_bmp
);
319 m_ejectButton
->Enable(FALSE
);
321 buttonSizer
->Add(m_playButton
, 0, wxALL
, 2);
322 buttonSizer
->Add(m_pauseButton
, 0, wxALL
, 2);
323 buttonSizer
->Add(m_stopButton
, 0, wxALL
, 2);
324 buttonSizer
->Add(m_ejectButton
, 0, wxALL
, 2);
327 m_sizer
= new wxBoxSizer(wxVERTICAL
);
328 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
329 m_sizer
->Add(m_positionSlider
, 0, wxCENTRE
| wxGROW
| wxALL
, 2);
330 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
331 m_sizer
->Add(buttonSizer
, 0, wxALL
, 0);
332 m_sizer
->Add(new wxStaticLine(m_panel
, -1), 0, wxGROW
| wxCENTRE
, 0);
333 m_sizer
->Add(infoPanel
, 1, wxCENTRE
| wxGROW
, 0);
335 m_panel
->SetSizer(m_sizer
);
336 m_panel
->SetAutoLayout(TRUE
);
338 m_sizer
->SetSizeHints(this);
341 m_refreshTimer
= new wxTimer(this, MMBoard_RefreshInfo
);
344 m_video_window
= NULL
;
347 m_opened_file
= NULL
;
350 MMBoardFrame::~MMBoardFrame()
353 delete m_opened_file
;
355 delete m_refreshTimer
;
358 void MMBoardFrame::OpenVideoWindow()
363 m_video_window
= new wxWindow(m_panel
, -1, wxDefaultPosition
, wxSize(200, 200));
364 m_video_window
->SetBackgroundColour(*wxBLACK
);
365 m_sizer
->Prepend(m_video_window
, 2, wxGROW
| wxSHRINK
| wxCENTRE
, 1);
370 void MMBoardFrame::CloseVideoWindow()
375 m_sizer
->Remove(m_video_window
);
376 delete m_video_window
;
377 m_video_window
= NULL
;
384 void MMBoardFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
386 // TRUE is to force the frame to close
390 void MMBoardFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
393 msg
.Printf( wxT("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
394 wxT("an example of the capabilities of the wxWindows multimedia classes.\n")
395 wxT("Copyright 1999, 2000, Guilhem Lavaux.\n"));
397 wxMessageBox(msg
, "About MMBoard", wxOK
| wxICON_INFORMATION
, this);
400 void MMBoardFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
402 wxString selected_file
;
405 if (!m_opened_file
->IsStopped()) {
406 wxCommandEvent event2
;
409 delete m_opened_file
;
412 // select a file to be opened
413 selected_file
= wxLoadFileSelector("multimedia", "*", NULL
, this);
414 if (selected_file
.IsNull())
417 m_opened_file
= MMBoardManager::Open(selected_file
);
419 // Change the range values of the slider.
422 length
= m_opened_file
->GetLength();
423 m_positionSlider
->SetRange(0, length
.hours
* 3600 + length
.minutes
* 60 + length
.seconds
);
428 SetStatusText(selected_file
, 2);
433 // Enable a few buttons
434 m_playButton
->Enable(TRUE
);
435 m_ejectButton
->Enable(TRUE
);
436 m_positionSlider
->Enable(TRUE
);
438 if (m_opened_file
->NeedWindow()) {
440 m_opened_file
->SetWindow(m_video_window
);
445 void MMBoardFrame::UpdateInfoText()
447 wxString infotext1
, infotext2
;
450 infotext1
= wxT("File type:\n\t");
451 infotext1
+= m_opened_file
->GetStringType() + wxT("\n");
453 infotext2
= wxT("File informations:\n\n");
454 infotext2
+= m_opened_file
->GetStringInformation();
456 infotext1
= wxT("File type: \n\tNo file opened");
457 infotext2
= wxT("File informations:\nNo information\n\n\n\n\n");
460 m_fileType
->SetLabel(infotext1
);
461 m_infoText
->SetLabel(infotext2
);
464 void MMBoardFrame::UpdateMMedInfo()
466 wxString temp_string
;
467 MMBoardTime current
, length
;
470 current
= m_opened_file
->GetPosition();
471 length
= m_opened_file
->GetLength();
473 current
.hours
= current
.minutes
= current
.seconds
= 0;
477 // We refresh the status bar
478 temp_string
.Printf(wxT("%02d:%02d / %02d:%02d"), current
.hours
* 60 + current
.minutes
,
479 current
.seconds
, length
.hours
* 60 + length
.minutes
, length
.seconds
);
480 SetStatusText(temp_string
, 1);
482 // We set the slider position
483 m_positionSlider
->SetValue(current
.hours
* 3600 + current
.minutes
* 60 + current
.seconds
);
486 // ----------------------------------------------------------------------------
487 // Playing management, refreshers, ...
489 void MMBoardFrame::OnRefreshInfo(wxEvent
& WXUNUSED(event
))
493 if (m_opened_file
->IsStopped()) {
494 m_refreshTimer
->Stop();
495 m_playButton
->Enable(TRUE
);
496 m_stopButton
->Enable(FALSE
);
497 m_pauseButton
->Enable(FALSE
);
501 void MMBoardFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
503 m_stopButton
->Enable(TRUE
);
504 m_pauseButton
->Enable(TRUE
);
505 m_playButton
->Enable(FALSE
);
507 if (m_opened_file
->IsPaused()) {
508 m_opened_file
->Resume();
512 m_refreshTimer
->Start(1000, FALSE
);
514 m_opened_file
->Play();
516 m_stopButton
->Enable(TRUE
);
517 m_pauseButton
->Enable(TRUE
);
518 m_playButton
->Enable(FALSE
);
521 void MMBoardFrame::OnStop(wxCommandEvent
& WXUNUSED(event
))
523 m_opened_file
->Stop();
524 m_refreshTimer
->Stop();
526 m_stopButton
->Enable(FALSE
);
527 m_playButton
->Enable(TRUE
);
532 void MMBoardFrame::OnPause(wxCommandEvent
& WXUNUSED(event
))
534 m_opened_file
->Pause();
536 m_playButton
->Enable(TRUE
);
537 m_pauseButton
->Enable(FALSE
);
540 void MMBoardFrame::OnEject(wxCommandEvent
& WXUNUSED(event
))
542 m_opened_file
->Stop();
544 delete m_opened_file
;
545 m_opened_file
= NULL
;
547 m_playButton
->Enable(FALSE
);
548 m_pauseButton
->Enable(FALSE
);
549 m_stopButton
->Enable(FALSE
);
550 m_ejectButton
->Enable(FALSE
);
551 m_positionSlider
->Enable(FALSE
);
557 void MMBoardFrame::OnSetPosition(wxCommandEvent
& WXUNUSED(event
))
562 itime
= m_positionSlider
->GetValue();
563 btime
.seconds
= itime
% 60;
564 btime
.minutes
= (itime
/ 60) % 60;
565 btime
.hours
= itime
/ 3600;
566 m_opened_file
->SetPosition(btime
);