1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2003 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
36 #include "wxwindows.h"
39 //void DisplayStreamDate( wxControl *, intf_thread_t *, int );
41 /* Callback prototypes */
42 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
43 vlc_value_t old_val, vlc_value_t new_val, void *param );
44 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
45 vlc_value_t old_val, vlc_value_t new_val, void *param );
47 /*****************************************************************************
49 *****************************************************************************/
50 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
53 p_main_interface = _p_main_interface;
55 i_old_playing_status = PAUSE_S;
56 i_old_rate = INPUT_RATE_DEFAULT;
58 /* Register callback for the intf-popupmenu variable */
59 playlist_t *p_playlist =
60 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
62 if( p_playlist != NULL )
64 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
65 var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
66 vlc_object_release( p_playlist );
69 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
74 /* Unregister callback */
75 playlist_t *p_playlist =
76 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
78 if( p_playlist != NULL )
80 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
81 var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
82 vlc_object_release( p_playlist );
86 /*****************************************************************************
88 *****************************************************************************/
90 /*****************************************************************************
91 * Manage: manage main thread messages
92 *****************************************************************************
93 * In this function, called approx. 10 times a second, we check what the
94 * main program wanted to tell us.
95 *****************************************************************************/
98 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
101 p_main_interface->Init();
106 vlc_mutex_lock( &p_intf->change_lock );
108 /* Update the input */
109 if( p_intf->p_sys->p_input == NULL )
111 p_intf->p_sys->p_input =
112 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
115 /* Refresh interface */
116 if( p_intf->p_sys->p_input )
118 p_main_interface->slider->SetValue( 0 );
119 b_old_seekable = VLC_FALSE;
121 p_main_interface->statusbar->SetStatusText(
122 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
124 p_main_interface->TogglePlayButton( PLAYING_S );
125 i_old_playing_status = PLAYING_S;
128 else if( p_intf->p_sys->p_input->b_dead )
131 p_main_interface->slider_frame->Hide();
132 p_main_interface->frame_sizer->Hide(
133 p_main_interface->slider_frame );
134 p_main_interface->frame_sizer->Layout();
135 p_main_interface->frame_sizer->Fit( p_main_interface );
137 p_main_interface->TogglePlayButton( PAUSE_S );
138 i_old_playing_status = PAUSE_S;
140 p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
141 p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
143 vlc_object_release( p_intf->p_sys->p_input );
144 p_intf->p_sys->p_input = NULL;
148 if( p_intf->p_sys->p_input )
150 input_thread_t *p_input = p_intf->p_sys->p_input;
153 if( !p_input->b_die )
157 /* New input or stream map change */
158 p_intf->p_sys->b_playing = 1;
160 /* Manage the slider */
162 /* Change the name of b_old_seekable into b_show_bar or something like that */
163 var_Get( p_input, "position", &pos );
165 if( !b_old_seekable )
167 if( pos.f_float > 0.0 )
169 /* Done like this, as it's the only way to know if the slider
170 * has to be displayed */
171 b_old_seekable = VLC_TRUE;
172 p_main_interface->slider_frame->Show();
173 p_main_interface->frame_sizer->Show(
174 p_main_interface->slider_frame );
175 p_main_interface->frame_sizer->Layout();
176 p_main_interface->frame_sizer->Fit( p_main_interface );
181 if( p_intf->p_sys->b_playing && b_old_seekable )
183 /* Update the slider if the user isn't dragging it. */
184 if( p_intf->p_sys->b_slider_free )
186 char psz_time[ MSTRTIME_MAX_SIZE ];
187 char psz_total[ MSTRTIME_MAX_SIZE ];
191 /* Update the value */
192 if( pos.f_float >= 0.0 )
194 p_intf->p_sys->i_slider_pos =
195 (int)(SLIDER_MAX_POS * pos.f_float);
197 p_main_interface->slider->SetValue(
198 p_intf->p_sys->i_slider_pos );
200 var_Get( p_intf->p_sys->p_input, "time", &time );
201 i_seconds = time.i_time / 1000000;
202 secstotimestr ( psz_time, i_seconds );
204 var_Get( p_intf->p_sys->p_input, "length", &time );
205 i_seconds = time.i_time / 1000000;
206 secstotimestr ( psz_total, i_seconds );
208 p_main_interface->statusbar->SetStatusText(
209 wxU(psz_time) + wxString(wxT(" / ")) +
215 vlc_mutex_lock( &p_input->stream.stream_lock );
216 if( p_intf->p_sys->p_input->stream.b_seekable && !b_old_seekable )
218 /* Done like this because b_seekable is set slightly after
219 * the new input object is available. */
220 b_old_seekable = VLC_TRUE;
221 p_main_interface->slider_frame->Show();
222 p_main_interface->frame_sizer->Show(
223 p_main_interface->slider_frame );
224 p_main_interface->frame_sizer->Layout();
225 p_main_interface->frame_sizer->Fit( p_main_interface );
227 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
229 /* Update the slider if the user isn't dragging it. */
230 if( p_intf->p_sys->b_slider_free )
233 char psz_time[ MSTRTIME_MAX_SIZE ];
234 char psz_total[ MSTRTIME_MAX_SIZE ];
238 /* Update the value */
239 var_Get( p_input, "position", &pos );
240 if( pos.f_float >= 0.0 )
242 p_intf->p_sys->i_slider_pos =
243 (int)(SLIDER_MAX_POS * pos.f_float);
245 p_main_interface->slider->SetValue(
246 p_intf->p_sys->i_slider_pos );
248 var_Get( p_intf->p_sys->p_input, "time", &time );
249 i_seconds = time.i_time / 1000000;
250 secstotimestr ( psz_time, i_seconds );
252 var_Get( p_intf->p_sys->p_input, "length", &time );
253 i_seconds = time.i_time / 1000000;
254 secstotimestr ( psz_total, i_seconds );
256 p_main_interface->statusbar->SetStatusText(
257 wxU(psz_time) + wxString(wxT(" / ")) +
262 vlc_mutex_unlock( &p_input->stream.stream_lock );
264 /* Take care of the volume, etc... */
265 p_main_interface->Update();
267 /* Manage Playing status */
268 var_Get( p_input, "state", &val );
269 if( i_old_playing_status != val.i_int )
271 if( val.i_int == PAUSE_S )
273 p_main_interface->TogglePlayButton( PAUSE_S );
277 p_main_interface->TogglePlayButton( PLAYING_S );
279 i_old_playing_status = val.i_int;
282 /* Manage Speed status */
283 var_Get( p_input, "rate", &val );
284 if( i_old_rate != val.i_int )
286 p_main_interface->statusbar->SetStatusText(
287 wxString::Format(wxT("x%.2f"),
288 (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
289 i_old_rate = val.i_int;
294 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
296 p_intf->p_sys->b_playing = 0;
297 p_main_interface->TogglePlayButton( PAUSE_S );
298 i_old_playing_status = PAUSE_S;
301 /* Show the interface, if requested */
302 if( p_intf->p_sys->b_intf_show )
304 p_main_interface->Raise();
305 p_intf->p_sys->b_intf_show = VLC_FALSE;
310 vlc_mutex_unlock( &p_intf->change_lock );
312 /* Prepare to die, young Skywalker */
313 p_main_interface->Close(TRUE);
317 vlc_mutex_unlock( &p_intf->change_lock );
320 /*****************************************************************************
321 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
322 * We don't show the menu directly here because we don't want the
323 * caller to block for a too long time.
324 *****************************************************************************/
325 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
326 vlc_value_t old_val, vlc_value_t new_val, void *param )
328 intf_thread_t *p_intf = (intf_thread_t *)param;
330 if( p_intf->p_sys->pf_show_dialog )
332 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
339 /*****************************************************************************
340 * IntfShowCB: callback triggered by the intf-show playlist variable.
341 *****************************************************************************/
342 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
343 vlc_value_t old_val, vlc_value_t new_val, void *param )
345 intf_thread_t *p_intf = (intf_thread_t *)param;
346 p_intf->p_sys->b_intf_show = VLC_TRUE;