1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.16 2001/03/05 22:29:02 richards Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tcastley@mail.powerup.com.au>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 #define MODULE_NAME beos
28 #include "modules_inner.h"
30 /*****************************************************************************
32 *****************************************************************************/
36 #include <stdlib.h> /* malloc(), free() */
38 #include <kernel/OS.h>
39 #include <storage/Path.h>
45 #include <StatusBar.h>
46 #include <Application.h>
50 #include <DirectWindow.h>
55 #include <FilePanel.h>
68 #include "stream_control.h"
69 #include "input_ext-intf.h"
71 #include "interface.h"
72 #include "intf_plst.h"
74 #include "audio_output.h"
81 #include "InterfaceWindow.h"
83 #include "TransportButton.h"
85 /*****************************************************************************
86 * intf_sys_t: description and status of FB interface
87 *****************************************************************************/
88 typedef struct intf_sys_s
90 InterfaceWindow * p_window;
94 /*****************************************************************************
96 *****************************************************************************/
98 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_interface )
99 : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
100 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK |B_ASYNCHRONOUS_CONTROLS)
103 p_intf = p_interface;
108 SetName( "interface" );
109 SetTitle(VOUT_TITLE " (BeOS interface)");
110 BRect rect(0, 0, 0, 0);
113 menu_bar = new BMenuBar(rect, "main menu");
114 AddChild( menu_bar );
118 menu_bar->AddItem( m = new BMenu("File") );
119 menu_bar->ResizeToPreferred();
120 m->AddItem( new BMenuItem("Open file...", new BMessage(OPEN_FILE), 'O'));
121 m->AddItem( new BMenuItem("Open DVD...", new BMessage(OPEN_DVD), 'D'));
122 m->AddSeparatorItem();
123 m->AddItem( new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
127 rect.top += menu_bar->Bounds().IntegerHeight()+1;
130 p_view = new BBox( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW );
131 p_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
135 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
136 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
137 xStart += kRewindBitmapWidth;
138 TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
140 kPressedSkipBackBitmapBits,
141 kDisabledSkipBackBitmapBits,
142 new BMessage(SLOWER_PLAY));
143 p_view->AddChild( p_slow );
146 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
147 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
148 xStart += kPlayPauseBitmapWidth + 1.0;
149 PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
150 kPlayButtonBitmapBits,
151 kPressedPlayButtonBitmapBits,
152 kDisabledPlayButtonBitmapBits,
153 kPlayingPlayButtonBitmapBits,
154 kPressedPlayingPlayButtonBitmapBits,
155 kPausedPlayButtonBitmapBits,
156 kPressedPausedPlayButtonBitmapBits,
157 new BMessage(START_PLAYBACK));
159 p_view->AddChild( p_play );
160 p_play->SetPlaying();
163 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
164 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
165 xStart += kRewindBitmapWidth;
166 TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
167 kSkipForwardBitmapBits,
168 kPressedSkipForwardBitmapBits,
169 kDisabledSkipForwardBitmapBits,
170 new BMessage(FASTER_PLAY));
171 p_view->AddChild( p_fast );
174 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
175 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
176 xStart += kStopBitmapWidth;
177 TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
178 kStopButtonBitmapBits,
179 kPressedStopButtonBitmapBits,
180 kDisabledStopButtonBitmapBits,
181 new BMessage(STOP_PLAYBACK));
182 p_view->AddChild( p_stop );
184 ButtonRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
185 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSpeakerButtonSize);
186 xStart += kSpeakerIconBitmapWidth;
188 TransportButton* p_mute = new TransportButton(ButtonRect, B_EMPTY_STRING,
190 kPressedSpeakerIconBits,
192 new BMessage(VOLUME_MUTE));
194 p_view->AddChild( p_mute );
197 rgb_color fill_color = {0,255,0};
198 p_seek = new SeekSlider(BRect(5,10,250,30), this, 0, 100,
201 p_seek->UseFillColor(true, &fill_color);
202 p_view->AddChild( p_seek );
205 p_vol = new MediaSlider(BRect(xStart,40,250,60), new BMessage(VOLUME_CHG),
207 p_vol->SetValue(VOLUME_DEFAULT);
208 p_vol->UseFillColor(true, &fill_color);
209 p_view->AddChild( p_vol );
211 /* Set size and Show */
213 ResizeTo(260,70 + menu_bar->Bounds().IntegerHeight()+1);
217 InterfaceWindow::~InterfaceWindow()
221 /*****************************************************************************
222 * InterfaceWindow::MessageReceived
223 *****************************************************************************/
224 void InterfaceWindow::MessageReceived( BMessage * p_message )
226 int vol_val = p_vol->Value(); // remember the current volume
227 static int playback_status; // remember playback state
231 switch( p_message->what )
239 file_panel = new BFilePanel();
240 file_panel->SetTarget(this);
245 alert = new BAlert(VOUT_TITLE, "Opening DVD not yet supported", "Bummer");
247 //intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, "dvd:/dev/disk/ide/atapi/1/master/0/raw" );
251 // this currently stops playback not nicely
252 if (p_intf->p_input != NULL )
254 // silence the sound, otherwise very horrible
255 if (p_main->p_aout != NULL)
257 p_main->p_aout->vol = 0;
260 input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
264 // starts playing in normal mode
265 // if (p_intf->p_input != NULL )
267 // if (p_main->p_aout != NULL)
269 // p_main->p_aout->vol = vol_val;
272 // input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
273 // playback_status = PLAYING;
277 // pause the playback
278 if (p_intf->p_input != NULL )
280 // mute the volume if currently playing
281 if (playback_status == PLAYING)
283 if (p_main->p_aout != NULL)
285 p_main->p_aout->vol = 0;
287 playback_status = PAUSED;
290 // restore the volume
292 if (p_main->p_aout != NULL)
294 p_main->p_aout->vol = vol_val;
296 playback_status = PLAYING;
299 input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
303 // cycle the fast playback modes
304 if (p_intf->p_input != NULL )
306 if (p_main->p_aout != NULL)
308 p_main->p_aout->vol = 0;
311 input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
315 // cycle the slow playback modes
316 if (p_intf->p_input != NULL )
318 if (p_main->p_aout != NULL)
320 p_main->p_aout->vol = 0;
323 input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
327 // handled by semaphores;
328 /* if( p_intf->p_input != NULL )
331 if (p_message->FindFloat("be:value", &new_position) == B_OK)
333 printf("%e\n", new_position);
334 input_Seek( p_intf->p_input, new_position * 100 );
340 if (p_main->p_aout != NULL)
342 p_main->p_aout->vol = vol_val;
347 if (p_main->p_aout != NULL)
349 if (p_main->p_aout->vol == 0)
351 p_vol->SetEnabled(true);
352 p_main->p_aout->vol = vol_val;
356 p_vol->SetEnabled(false);
357 p_main->p_aout->vol = 0;
363 case B_REFS_RECEIVED:
367 if( p_message->FindRef( "refs", &ref ) == B_OK )
370 char * psz_name = strdup(path.Path());
371 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
377 BWindow::MessageReceived( p_message );
382 /*****************************************************************************
383 * InterfaceWindow::QuitRequested
384 *****************************************************************************/
386 bool InterfaceWindow::QuitRequested()
392 /*****************************************************************************
394 *****************************************************************************/
395 MediaSlider::MediaSlider(BRect frame,
399 :BSlider(frame, NULL, NULL, message, minValue, maxValue)
404 MediaSlider::~MediaSlider()
409 void MediaSlider::DrawThumb(void)
416 v->SetHighColor(0,0,0);
417 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/6);
419 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
424 /*****************************************************************************
426 *****************************************************************************/
427 SeekSlider::SeekSlider(BRect frame,
428 InterfaceWindow *owner,
431 thumb_style thumbType = B_TRIANGLE_THUMB)
432 :MediaSlider(frame, NULL, minValue, maxValue)
438 SeekSlider::~SeekSlider()
442 /*****************************************************************************
443 * SeekSlider::MouseDown
444 *****************************************************************************/
445 void SeekSlider::MouseDown(BPoint where)
447 BSlider::MouseDown(where);
448 fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
452 /*****************************************************************************
453 * SeekSlider::MouseUp
454 *****************************************************************************/
455 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
457 BSlider::MouseMoved(where, code, message);
460 release_sem(fOwner->fScrubSem);
463 /*****************************************************************************
464 * SeekSlider::MouseUp
465 *****************************************************************************/
466 void SeekSlider::MouseUp(BPoint where)
468 BSlider::MouseUp(where);
469 delete_sem(fOwner->fScrubSem);
470 fOwner->fScrubSem = B_ERROR;
478 /*****************************************************************************
480 *****************************************************************************/
481 static int intf_Probe ( probedata_t *p_data );
482 static int intf_Open ( intf_thread_t *p_intf );
483 static void intf_Close ( intf_thread_t *p_intf );
484 static void intf_Run ( intf_thread_t *p_intf );
486 /*****************************************************************************
487 * Functions exported as capabilities. They are declared as static so that
488 * we don't pollute the namespace too much.
489 *****************************************************************************/
490 void _M( intf_getfunctions )( function_list_t * p_function_list )
492 p_function_list->pf_probe = intf_Probe;
493 p_function_list->functions.intf.pf_open = intf_Open;
494 p_function_list->functions.intf.pf_close = intf_Close;
495 p_function_list->functions.intf.pf_run = intf_Run;
498 /*****************************************************************************
499 * intf_Probe: probe the interface and return a score
500 *****************************************************************************
501 * This function tries to initialize Gnome and returns a score to the
502 * plugin manager so that it can select the best plugin.
503 *****************************************************************************/
504 static int intf_Probe( probedata_t *p_data )
506 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
514 /*****************************************************************************
515 * intf_Open: initialize interface
516 *****************************************************************************/
517 static int intf_Open( intf_thread_t *p_intf )
519 /* Allocate instance and initialize some members */
520 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
521 if( p_intf->p_sys == NULL )
523 intf_ErrMsg("error: %s", strerror(ENOMEM));
526 p_intf->p_sys->i_key = -1;
528 /* Create the interface window */
529 p_intf->p_sys->p_window =
530 new InterfaceWindow( BRect( 50, 50, 400, 100 ),
531 VOUT_TITLE " (BeOS interface)", p_intf );
532 if( p_intf->p_sys->p_window == 0 )
534 free( p_intf->p_sys );
535 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
542 /*****************************************************************************
543 * intf_Close: destroy dummy interface
544 *****************************************************************************/
545 static void intf_Close( intf_thread_t *p_intf )
547 /* Destroy the interface window */
548 p_intf->p_sys->p_window->Lock();
549 p_intf->p_sys->p_window->Quit();
551 /* Destroy structure */
552 free( p_intf->p_sys );
556 /*****************************************************************************
557 * intf_Run: event loop
558 *****************************************************************************/
559 static void intf_Run( intf_thread_t *p_intf )
563 bool seekNeeded = false;
565 while( !p_intf->b_die )
568 /* Manage core vlc functions through the callback */
569 p_intf->pf_manage( p_intf );
571 /* Manage the slider */
572 if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
574 if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
581 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() *
582 p_intf->p_input->stream.p_selected_area->i_size) / 100;
583 input_Seek( p_intf->p_input, seekTo );
586 else if (p_intf->p_sys->p_window->Lock())
588 progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
589 p_intf->p_input->stream.p_selected_area->i_size;
590 p_intf->p_sys->p_window->p_seek->SetValue(progress);
591 p_intf->p_sys->p_window->Unlock();
596 msleep( INTF_IDLE_SLEEP );