1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.15 2001/03/05 20:36:04 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>
54 #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, MENU_HEIGHT);
113 menu_bar = new BMenuBar(rect, "main menu");
114 AddChild( menu_bar );
119 menu_bar->AddItem( m = new BMenu("File") );
120 menu_bar->ResizeToPreferred();
121 m->AddItem( new BMenuItem("Open file...", new BMessage(OPEN_FILE), 'O'));
122 m->AddItem( new BMenuItem("Open DVD...", new BMessage(OPEN_DVD), 'D'));
123 m->AddSeparatorItem();
124 m->AddItem( new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
128 rect.top += menu_bar->Bounds().IntegerHeight()+1;
131 p_view = new BBox( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW );
132 p_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
136 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
137 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
138 xStart += kRewindBitmapWidth;
139 TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
141 kPressedSkipBackBitmapBits,
142 kDisabledSkipBackBitmapBits,
143 new BMessage(SLOWER_PLAY));
144 p_view->AddChild( p_slow );
147 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
148 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
149 xStart += kPlayPauseBitmapWidth + 1.0;
150 PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
151 kPlayButtonBitmapBits,
152 kPressedPlayButtonBitmapBits,
153 kDisabledPlayButtonBitmapBits,
154 kPlayingPlayButtonBitmapBits,
155 kPressedPlayingPlayButtonBitmapBits,
156 kPausedPlayButtonBitmapBits,
157 kPressedPausedPlayButtonBitmapBits,
158 new BMessage(START_PLAYBACK));
160 p_view->AddChild( p_play );
161 p_play->SetPlaying();
164 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
165 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
166 xStart += kRewindBitmapWidth;
167 TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
168 kSkipForwardBitmapBits,
169 kPressedSkipForwardBitmapBits,
170 kDisabledSkipForwardBitmapBits,
171 new BMessage(FASTER_PLAY));
172 p_view->AddChild( p_fast );
175 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
176 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
177 xStart += kStopBitmapWidth;
178 TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
179 kStopButtonBitmapBits,
180 kPressedStopButtonBitmapBits,
181 kDisabledStopButtonBitmapBits,
182 new BMessage(STOP_PLAYBACK));
183 p_view->AddChild( p_stop );
185 ButtonRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
186 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSpeakerButtonSize);
187 xStart += kSpeakerIconBitmapWidth;
189 TransportButton* p_mute = new TransportButton(ButtonRect, B_EMPTY_STRING,
191 kPressedSpeakerIconBits,
193 new BMessage(VOLUME_MUTE));
195 p_view->AddChild( p_mute );
198 rgb_color fill_color = {0,255,0};
199 p_seek = new SeekSlider(BRect(5,10,250,30), this, 0, 100,
202 p_seek->UseFillColor(true, &fill_color);
203 p_view->AddChild( p_seek );
206 p_vol = new MediaSlider(BRect(xStart,40,250,60), new BMessage(VOLUME_CHG),
208 p_vol->SetValue(VOLUME_DEFAULT);
209 p_vol->UseFillColor(true, &fill_color);
210 p_view->AddChild( p_vol );
212 /* Set size and Show */
214 ResizeTo(260,70 + menu_bar->Bounds().IntegerHeight()+1);
218 InterfaceWindow::~InterfaceWindow()
222 /*****************************************************************************
223 * InterfaceWindow::MessageReceived
224 *****************************************************************************/
225 void InterfaceWindow::MessageReceived( BMessage * p_message )
227 int vol_val = p_vol->Value(); // remember the current volume
228 static int playback_status; // remember playback state
233 switch( p_message->what )
241 file_panel = new BFilePanel();
242 file_panel->SetTarget(this);
247 alert = new BAlert(VOUT_TITLE, "Opening DVDs not yet implemented", "Bummer");
252 // this currently stops playback not nicely
253 if (p_intf->p_input != NULL )
255 // silence the sound, otherwise very horrible
256 if (p_main->p_aout != NULL)
258 p_main->p_aout->vol = 0;
261 input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
265 // starts playing in normal mode
266 // if (p_intf->p_input != NULL )
268 // if (p_main->p_aout != NULL)
270 // p_main->p_aout->vol = vol_val;
273 // input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
274 // playback_status = PLAYING;
278 // pause the playback
279 if (p_intf->p_input != NULL )
281 // mute the volume if currently playing
282 if (playback_status == PLAYING)
284 if (p_main->p_aout != NULL)
286 p_main->p_aout->vol = 0;
288 playback_status = PAUSED;
291 // restore the volume
293 if (p_main->p_aout != NULL)
295 p_main->p_aout->vol = vol_val;
297 playback_status = PLAYING;
300 input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
304 // cycle the fast playback modes
305 if (p_intf->p_input != NULL )
307 if (p_main->p_aout != NULL)
309 p_main->p_aout->vol = 0;
312 input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
316 // cycle the slow playback modes
317 if (p_intf->p_input != NULL )
319 if (p_main->p_aout != NULL)
321 p_main->p_aout->vol = 0;
324 input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
328 // handled by semaphores;
329 /* if( p_intf->p_input != NULL )
332 if (p_message->FindFloat("be:value", &new_position) == B_OK)
334 printf("%e\n", new_position);
335 input_Seek( p_intf->p_input, new_position * 100 );
341 if (p_main->p_aout != NULL)
343 p_main->p_aout->vol = vol_val;
348 if (p_main->p_aout != NULL)
350 if (p_main->p_aout->vol == 0)
352 p_main->p_aout->vol = vol_val;
356 p_main->p_aout->vol = 0;
362 case B_REFS_RECEIVED:
366 if( p_message->FindRef( "refs", &ref ) == B_OK )
369 char * psz_name = strdup(path.Path());
370 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
376 BWindow::MessageReceived( p_message );
381 /*****************************************************************************
382 * InterfaceWindow::QuitRequested
383 *****************************************************************************/
385 bool InterfaceWindow::QuitRequested()
391 /*****************************************************************************
393 *****************************************************************************/
394 MediaSlider::MediaSlider(BRect frame,
398 :BSlider(frame, NULL, NULL, message, minValue, maxValue)
403 MediaSlider::~MediaSlider()
408 void MediaSlider::DrawThumb(void)
415 v->SetHighColor(0,0,0);
416 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/6);
418 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
423 /*****************************************************************************
425 *****************************************************************************/
426 SeekSlider::SeekSlider(BRect frame,
427 InterfaceWindow *owner,
430 thumb_style thumbType = B_TRIANGLE_THUMB)
431 :MediaSlider(frame, NULL, minValue, maxValue)
437 SeekSlider::~SeekSlider()
441 /*****************************************************************************
442 * SeekSlider::MouseDown
443 *****************************************************************************/
444 void SeekSlider::MouseDown(BPoint where)
446 BSlider::MouseDown(where);
447 fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
451 /*****************************************************************************
452 * SeekSlider::MouseUp
453 *****************************************************************************/
454 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
456 BSlider::MouseMoved(where, code, message);
459 release_sem(fOwner->fScrubSem);
462 /*****************************************************************************
463 * SeekSlider::MouseUp
464 *****************************************************************************/
465 void SeekSlider::MouseUp(BPoint where)
467 BSlider::MouseUp(where);
468 delete_sem(fOwner->fScrubSem);
469 fOwner->fScrubSem = B_ERROR;
477 /*****************************************************************************
479 *****************************************************************************/
480 static int intf_Probe ( probedata_t *p_data );
481 static int intf_Open ( intf_thread_t *p_intf );
482 static void intf_Close ( intf_thread_t *p_intf );
483 static void intf_Run ( intf_thread_t *p_intf );
485 /*****************************************************************************
486 * Functions exported as capabilities. They are declared as static so that
487 * we don't pollute the namespace too much.
488 *****************************************************************************/
489 void _M( intf_getfunctions )( function_list_t * p_function_list )
491 p_function_list->pf_probe = intf_Probe;
492 p_function_list->functions.intf.pf_open = intf_Open;
493 p_function_list->functions.intf.pf_close = intf_Close;
494 p_function_list->functions.intf.pf_run = intf_Run;
497 /*****************************************************************************
498 * intf_Probe: probe the interface and return a score
499 *****************************************************************************
500 * This function tries to initialize Gnome and returns a score to the
501 * plugin manager so that it can select the best plugin.
502 *****************************************************************************/
503 static int intf_Probe( probedata_t *p_data )
505 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
513 /*****************************************************************************
514 * intf_Open: initialize interface
515 *****************************************************************************/
516 static int intf_Open( intf_thread_t *p_intf )
518 /* Allocate instance and initialize some members */
519 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
520 if( p_intf->p_sys == NULL )
522 intf_ErrMsg("error: %s", strerror(ENOMEM));
525 p_intf->p_sys->i_key = -1;
527 /* Create the interface window */
528 p_intf->p_sys->p_window =
529 new InterfaceWindow( BRect( 50, 50, 400, 100 ),
530 VOUT_TITLE " (BeOS interface)", p_intf );
531 if( p_intf->p_sys->p_window == 0 )
533 free( p_intf->p_sys );
534 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
541 /*****************************************************************************
542 * intf_Close: destroy dummy interface
543 *****************************************************************************/
544 static void intf_Close( intf_thread_t *p_intf )
546 /* Destroy the interface window */
547 p_intf->p_sys->p_window->Lock();
548 p_intf->p_sys->p_window->Quit();
550 /* Destroy structure */
551 free( p_intf->p_sys );
555 /*****************************************************************************
556 * intf_Run: event loop
557 *****************************************************************************/
558 static void intf_Run( intf_thread_t *p_intf )
562 bool seekNeeded = false;
564 while( !p_intf->b_die )
567 /* Manage core vlc functions through the callback */
568 p_intf->pf_manage( p_intf );
570 /* Manage the slider */
571 if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
573 if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
580 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() *
581 p_intf->p_input->stream.p_selected_area->i_size) / 100;
582 input_Seek( p_intf->p_input, seekTo );
585 else if (p_intf->p_sys->p_window->Lock())
587 progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
588 p_intf->p_input->stream.p_selected_area->i_size;
589 p_intf->p_sys->p_window->p_seek->SetValue(progress);
590 p_intf->p_sys->p_window->Unlock();
595 msleep( INTF_IDLE_SLEEP );