]> git.sesse.net Git - vlc/blob - plugins/beos/intf_beos.cpp
dc532b9cbb4c42297fecb7259c1e41991bd011b6
[vlc] / plugins / beos / intf_beos.cpp
1 /*****************************************************************************
2  * intf_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: intf_beos.cpp,v 1.12 2001/03/04 16:20:16 sam Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #define MODULE_NAME beos
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <stdio.h>
34 #include <stdlib.h>                                      /* malloc(), free() */
35
36 #include <kernel/OS.h>
37 #include <storage/Path.h>
38 #include <Alert.h>
39 #include <View.h>
40 #include <CheckBox.h>
41 #include <Button.h>
42 #include <Slider.h>
43 #include <StatusBar.h>
44 #include <Application.h>
45 #include <Message.h>
46 #include <NodeInfo.h>
47 #include <Locker.h>
48 #include <DirectWindow.h>
49
50 #include <malloc.h>
51 #include <string.h>
52
53 extern "C"
54 {
55 #include "config.h"
56 #include "common.h"
57 #include "threads.h"
58 #include "mtime.h"
59 #include "tests.h"
60 #include "modules.h"
61
62 #include "stream_control.h"
63 #include "input_ext-intf.h"
64
65 #include "interface.h"
66 #include "intf_plst.h"
67 #include "intf_msg.h"
68 #include "audio_output.h"
69 #include "MsgVals.h"
70
71
72 #include "main.h"
73 }
74
75 #include "InterfaceWindow.h"
76 #include "Bitmaps.h"
77 #include "TransportButton.h"
78
79 /*****************************************************************************
80  * intf_sys_t: description and status of FB interface
81  *****************************************************************************/
82 typedef struct intf_sys_s
83 {
84     InterfaceWindow * p_window;
85     char              i_key;
86 } intf_sys_t;
87
88 /*****************************************************************************
89  * InterfaceWindow
90  *****************************************************************************/
91  
92 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t  *p_interface )
93     : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
94         B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK |B_ASYNCHRONOUS_CONTROLS)
95 {
96     p_intf = p_interface;
97         BRect ButtonRect;
98         float xStart = 2.0;
99         float yStart = 10.0;
100
101     SetName( "interface" );
102     SetTitle("VideoLan Client for BeOS");
103     
104     BView* p_view;
105
106         /* Add the view */
107     p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
108         p_view->SetViewColor(216,216,216);
109     
110         /* Buttons */
111         /* Slow play */
112         ButtonRect.SetLeftTop(BPoint(xStart, yStart));
113         ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
114         xStart += kRewindBitmapWidth;
115         TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
116                                                                                         kSkipBackBitmapBits,
117                                                                                         kPressedSkipBackBitmapBits,
118                                                                                         kDisabledSkipBackBitmapBits,
119                                                                                         new BMessage(SLOWER_PLAY));
120         p_view->AddChild( p_slow );
121
122         /* Play Pause */
123         ButtonRect.SetLeftTop(BPoint(xStart, yStart));
124         ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
125         xStart += kPlayPauseBitmapWidth + 1.0;
126         PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
127                                                                                         kPlayButtonBitmapBits,
128                                                                                         kPressedPlayButtonBitmapBits,
129                                                                                         kDisabledPlayButtonBitmapBits,
130                                                                                         kPlayingPlayButtonBitmapBits,
131                                                                                         kPressedPlayingPlayButtonBitmapBits,
132                                                                                         kPausedPlayButtonBitmapBits,
133                                                                                         kPressedPausedPlayButtonBitmapBits,
134                                                                                         new BMessage(START_PLAYBACK));
135    
136         p_view->AddChild( p_play );
137         p_play->SetPlaying();
138
139         /* Fast Foward */
140         ButtonRect.SetLeftTop(BPoint(xStart, yStart));
141         ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
142         xStart += kRewindBitmapWidth;
143         TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
144                                                                                         kSkipForwardBitmapBits,
145                                                                                         kPressedSkipForwardBitmapBits,
146                                                                                         kDisabledSkipForwardBitmapBits,
147                                                                                         new BMessage(FASTER_PLAY));
148         p_view->AddChild( p_fast );
149
150         /* Stop */
151         ButtonRect.SetLeftTop(BPoint(xStart, yStart));
152         ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
153         xStart += kStopBitmapWidth;
154         TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
155                                                                                         kStopButtonBitmapBits,
156                                                                                         kPressedStopButtonBitmapBits,
157                                                                                         kDisabledStopButtonBitmapBits,
158                                                                                         new BMessage(STOP_PLAYBACK));
159         p_view->AddChild( p_stop );
160         
161         /* Seek Status */       
162         p_seek = new SeekSlider(BRect(5,35,355,65), this, 0, 100,
163                                                 B_TRIANGLE_THUMB);
164         p_seek->SetValue(0);
165         p_seek->UseFillColor(TRUE);
166     p_view->AddChild( p_seek );
167
168         /* Volume Slider */     
169         p_vol = new BSlider(BRect(xStart,2,300,20), "vol", "Volume", 
170                                                  new BMessage(VOLUME_CHG), 0, VOLUME_MAX);
171         p_vol->SetValue(VOLUME_DEFAULT);
172     p_view->AddChild( p_vol );
173     
174     /* Volume Mute */
175         p_mute = new BCheckBox(BRect(300,10,355,25), "mute", "Mute",
176                                                  new BMessage(VOLUME_MUTE));
177     p_view->AddChild( p_mute );
178                                                          
179         /* Set size and Show */
180     AddChild( p_view );
181         ResizeTo(360,70);
182     Show();
183 }
184
185 InterfaceWindow::~InterfaceWindow()
186 {
187 }
188
189 /*****************************************************************************
190  * InterfaceWindow::MessageReceived
191  *****************************************************************************/
192 void InterfaceWindow::MessageReceived( BMessage * p_message )
193 {
194         int vol_val = p_vol->Value();   // remember the current volume
195         static int playback_status;             // remember playback state
196         
197         Activate();
198     switch( p_message->what )
199     {
200     case OPEN_DVD:
201         break;
202     case STOP_PLAYBACK:
203         // this currently stops playback not nicely
204                 if (p_intf->p_input != NULL )
205                 {
206                         // silence the sound, otherwise very horrible
207                         p_main->p_aout->vol = 0;
208                         snooze(400000);
209                         input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
210                 }
211         break;
212         case START_PLAYBACK:
213                 // starts playing in normal mode
214 //              if (p_intf->p_input != NULL )
215 //              {                       
216 //                      p_main->p_aout->vol = vol_val;
217 //                      snooze(400000);
218 //                      input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
219 //                      playback_status = PLAYING;
220 //              } 
221 //              break;
222         case PAUSE_PLAYBACK:
223                 // pause the playback
224                 if (p_intf->p_input != NULL )
225                 {
226                         // mute the volume if currently playing
227                         if (playback_status == PLAYING)
228                         {
229                                 p_main->p_aout->vol = 0;
230                                 playback_status = PAUSED;
231                         }
232                         else
233                         // restore the volume
234                         {
235                                 p_main->p_aout->vol = vol_val;
236                                 playback_status = PLAYING;
237                         }
238                         snooze(400000);
239                         input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
240                 }
241                 break;
242         case FASTER_PLAY:
243                 // cycle the fast playback modes
244                 if (p_intf->p_input != NULL )
245                 {
246                         p_main->p_aout->vol = 0;
247                         snooze(400000);
248                         input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
249                 }
250                 break;
251         case SLOWER_PLAY:
252                 // cycle the slow playback modes
253                 if (p_intf->p_input != NULL )
254                 {
255                         p_main->p_aout->vol = 0;
256                         snooze(400000);
257                         input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
258                 }
259                 break;
260         case SEEK_PLAYBACK:
261                 // handled by semaphores;
262 /*          if( p_intf->p_input != NULL )
263             {
264                 float new_position;
265                     if (p_message->FindFloat("be:value", &new_position) == B_OK)
266                     {
267                         printf("%e\n", new_position);
268                         input_Seek( p_intf->p_input, new_position * 100 );
269                     }
270             } */
271                 break;
272         case VOLUME_CHG:
273                 // adjust the volume
274         if (p_main->p_aout != NULL) 
275         {
276                         p_main->p_aout->vol = vol_val;
277                 }
278                 break;
279         case VOLUME_MUTE:
280                 // mute
281         if (p_main->p_aout != NULL) 
282             {
283                         if (p_mute->Value() == B_CONTROL_OFF)
284                         {
285                                 p_main->p_aout->vol = vol_val;
286                         }       
287                         else
288                         {
289                                 p_main->p_aout->vol = 0;
290                         }
291                 }
292                 break;
293         case SELECT_CHANNEL:
294                 break;
295     case B_SIMPLE_DATA:
296         {
297             entry_ref ref;
298             if( p_message->FindRef( "refs", &ref ) == B_OK )
299             {
300                 BPath path( &ref );
301                 char * psz_name = strdup(path.Path());
302                 intf_WarnMsg( 1, "intf: dropped text/uri-list data `%s'",
303                               psz_name );
304                 intf_PlstAdd( p_main->p_playlist, PLAYLIST_END, psz_name );
305             }
306
307         }
308         break;
309     default:
310         BWindow::MessageReceived( p_message );
311         break;
312     }
313 }
314
315 /*****************************************************************************
316  * InterfaceWindow::QuitRequested
317  *****************************************************************************/
318
319 bool InterfaceWindow::QuitRequested()
320 {
321     p_intf->b_die = 1;
322
323     return( false );
324 }
325
326 /*****************************************************************************
327  * SeekSlider
328  *****************************************************************************/
329 SeekSlider::SeekSlider(BRect frame,
330                                 InterfaceWindow *owner,
331                                 int32 minValue,
332                                 int32 maxValue,
333                                 thumb_style thumbType = B_TRIANGLE_THUMB)
334                         :BSlider(frame, B_EMPTY_STRING, B_EMPTY_STRING,
335                                         NULL, minValue, maxValue, thumbType)
336 {
337         fOwner = owner;
338         fMouseDown = false;
339 }
340
341 SeekSlider::~SeekSlider()
342 {
343 }
344
345 /*****************************************************************************
346  * SeekSlider::MouseDown
347  *****************************************************************************/
348 void SeekSlider::MouseDown(BPoint where)
349 {
350         BSlider::MouseDown(where);
351         fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
352         fMouseDown = true;                                      
353 }
354
355 /*****************************************************************************
356  * SeekSlider::MouseUp
357  *****************************************************************************/
358 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
359 {
360         BSlider::MouseMoved(where, code, message);
361         if (!fMouseDown)
362                 return;
363         release_sem(fOwner->fScrubSem);
364 }
365
366 /*****************************************************************************
367  * SeekSlider::MouseUp
368  *****************************************************************************/
369 void SeekSlider::MouseUp(BPoint where)
370 {
371         BSlider::MouseUp(where);
372         delete_sem(fOwner->fScrubSem);
373         fOwner->fScrubSem = B_ERROR;
374         fMouseDown = false;                                     
375 }
376         
377
378 extern "C"
379 {
380
381 /*****************************************************************************
382  * Local prototypes.
383  *****************************************************************************/
384 static int  intf_Probe     ( probedata_t *p_data );
385 static int  intf_Open      ( intf_thread_t *p_intf );
386 static void intf_Close     ( intf_thread_t *p_intf );
387 static void intf_Run       ( intf_thread_t *p_intf );
388
389 /*****************************************************************************
390  * Functions exported as capabilities. They are declared as static so that
391  * we don't pollute the namespace too much.
392  *****************************************************************************/
393 void _M( intf_getfunctions )( function_list_t * p_function_list )
394 {
395     p_function_list->pf_probe = intf_Probe;
396     p_function_list->functions.intf.pf_open  = intf_Open;
397     p_function_list->functions.intf.pf_close = intf_Close;
398     p_function_list->functions.intf.pf_run   = intf_Run;
399 }
400
401 /*****************************************************************************
402  * intf_Probe: probe the interface and return a score
403  *****************************************************************************
404  * This function tries to initialize Gnome and returns a score to the
405  * plugin manager so that it can select the best plugin.
406  *****************************************************************************/
407 static int intf_Probe( probedata_t *p_data )
408 {
409     if( TestMethod( INTF_METHOD_VAR, "beos" ) )
410     {
411         return( 999 );
412     }
413
414     return( 100 );
415 }
416
417 /*****************************************************************************
418  * intf_Open: initialize interface
419  *****************************************************************************/
420 static int intf_Open( intf_thread_t *p_intf )
421 {
422     /* Allocate instance and initialize some members */
423     p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
424     if( p_intf->p_sys == NULL )
425     {
426         intf_ErrMsg("error: %s", strerror(ENOMEM));
427         return( 1 );
428     }
429     p_intf->p_sys->i_key = -1;
430     
431     /* Create the interface window */
432     p_intf->p_sys->p_window =
433         new InterfaceWindow( BRect( 50, 50, 400, 100 ),
434                              VOUT_TITLE " (BeOS interface)", p_intf );
435     if( p_intf->p_sys->p_window == 0 )
436     {
437         free( p_intf->p_sys );
438         intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
439         return( 1 );
440     }
441     
442     return( 0 );
443 }
444
445 /*****************************************************************************
446  * intf_Close: destroy dummy interface
447  *****************************************************************************/
448 static void intf_Close( intf_thread_t *p_intf )
449 {
450     /* Destroy the interface window */
451     p_intf->p_sys->p_window->Lock();
452     p_intf->p_sys->p_window->Quit();    
453
454     /* Destroy structure */
455     free( p_intf->p_sys );
456 }
457
458
459 /*****************************************************************************
460  * intf_Run: event loop
461  *****************************************************************************/
462 static void intf_Run( intf_thread_t *p_intf )
463 {
464         
465         float progress;
466         bool seekNeeded = false;
467         
468     while( !p_intf->b_die )
469     {
470
471         /* Manage core vlc functions through the callback */
472         p_intf->pf_manage( p_intf );
473
474             /* Manage the slider */
475             if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
476         {
477             if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
478                         {
479                                 seekNeeded = true;
480                         }               
481
482                         if (seekNeeded)
483             {
484                 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() * 
485                                 p_intf->p_input->stream.p_selected_area->i_size) / 100;
486                                 input_Seek( p_intf->p_input, seekTo );
487                                 seekNeeded = false;             
488             }
489                         else if (p_intf->p_sys->p_window->Lock())
490             {
491                     progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
492                                         p_intf->p_input->stream.p_selected_area->i_size;
493                     p_intf->p_sys->p_window->p_seek->SetValue(progress);
494                     p_intf->p_sys->p_window->Unlock();
495                 }
496          }
497
498         /* Wait a bit */
499         msleep( INTF_IDLE_SLEEP );
500     }
501 }
502
503 } /* extern "C" */