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 prototype */
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 );
45 /*****************************************************************************
47 *****************************************************************************/
48 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
51 p_main_interface = _p_main_interface;
53 i_old_playing_status = PAUSE_S;
54 i_old_rate = INPUT_RATE_DEFAULT;
56 /* Register callback for the intf-popupmenu variable */
57 playlist_t *p_playlist =
58 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
60 if( p_playlist != NULL )
62 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
63 vlc_object_release( p_playlist );
66 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
71 /* Unregister callback */
72 playlist_t *p_playlist =
73 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
75 if( p_playlist != NULL )
77 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
78 vlc_object_release( p_playlist );
82 /*****************************************************************************
84 *****************************************************************************/
86 /*****************************************************************************
87 * Manage: manage main thread messages
88 *****************************************************************************
89 * In this function, called approx. 10 times a second, we check what the
90 * main program wanted to tell us.
91 *****************************************************************************/
94 #if defined( __WXMSW__ ) /* Work-around a bug with accelerators */
97 p_main_interface->Init();
102 vlc_mutex_lock( &p_intf->change_lock );
104 /* Update the input */
105 if( p_intf->p_sys->p_input == NULL )
107 p_intf->p_sys->p_input =
108 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
111 /* Refresh interface */
112 if( p_intf->p_sys->p_input )
114 p_main_interface->slider->SetValue( 0 );
115 b_old_seekable = VLC_FALSE;
117 p_main_interface->statusbar->SetStatusText(
118 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
120 p_main_interface->TogglePlayButton( PLAYING_S );
121 i_old_playing_status = PLAYING_S;
124 else if( p_intf->p_sys->p_input->b_dead )
127 p_main_interface->slider_frame->Hide();
128 p_main_interface->frame_sizer->Hide(
129 p_main_interface->slider_frame );
130 p_main_interface->frame_sizer->Layout();
131 p_main_interface->frame_sizer->Fit( p_main_interface );
133 p_main_interface->TogglePlayButton( PAUSE_S );
134 i_old_playing_status = PAUSE_S;
136 p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
137 p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
139 vlc_object_release( p_intf->p_sys->p_input );
140 p_intf->p_sys->p_input = NULL;
144 if( p_intf->p_sys->p_input )
146 input_thread_t *p_input = p_intf->p_sys->p_input;
149 if( !p_input->b_die )
153 /* New input or stream map change */
154 p_intf->p_sys->b_playing = 1;
156 /* Manage the slider */
158 /* Change the name of b_old_seekable into b_show_bar or something like that */
159 var_Get( p_input, "position", &pos );
161 if( !b_old_seekable )
163 if( pos.f_float > 0.0 )
165 /* Done like this, as it's the only way to know if the slider
166 * has to be displayed */
167 b_old_seekable = VLC_TRUE;
168 p_main_interface->slider_frame->Show();
169 p_main_interface->frame_sizer->Show(
170 p_main_interface->slider_frame );
171 p_main_interface->frame_sizer->Layout();
172 p_main_interface->frame_sizer->Fit( p_main_interface );
177 if( p_intf->p_sys->b_playing && b_old_seekable )
179 /* Update the slider if the user isn't dragging it. */
180 if( p_intf->p_sys->b_slider_free )
182 char psz_time[ MSTRTIME_MAX_SIZE ];
183 char psz_total[ MSTRTIME_MAX_SIZE ];
187 /* Update the value */
188 if( pos.f_float >= 0.0 )
190 p_intf->p_sys->i_slider_pos =
191 (int)(SLIDER_MAX_POS * pos.f_float);
193 p_main_interface->slider->SetValue(
194 p_intf->p_sys->i_slider_pos );
196 var_Get( p_intf->p_sys->p_input, "time", &time );
197 i_seconds = time.i_time / 1000000;
198 secstotimestr ( psz_time, i_seconds );
200 var_Get( p_intf->p_sys->p_input, "length", &time );
201 i_seconds = time.i_time / 1000000;
202 secstotimestr ( psz_total, i_seconds );
204 p_main_interface->statusbar->SetStatusText(
205 wxU(psz_time) + wxString(wxT(" / ")) +
211 vlc_mutex_lock( &p_input->stream.stream_lock );
212 if( p_intf->p_sys->p_input->stream.b_seekable && !b_old_seekable )
214 /* Done like this because b_seekable is set slightly after
215 * the new input object is available. */
216 b_old_seekable = VLC_TRUE;
217 p_main_interface->slider_frame->Show();
218 p_main_interface->frame_sizer->Show(
219 p_main_interface->slider_frame );
220 p_main_interface->frame_sizer->Layout();
221 p_main_interface->frame_sizer->Fit( p_main_interface );
223 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
225 /* Update the slider if the user isn't dragging it. */
226 if( p_intf->p_sys->b_slider_free )
229 char psz_time[ MSTRTIME_MAX_SIZE ];
230 char psz_total[ MSTRTIME_MAX_SIZE ];
234 /* Update the value */
235 var_Get( p_input, "position", &pos );
236 if( pos.f_float >= 0.0 )
238 p_intf->p_sys->i_slider_pos =
239 (int)(SLIDER_MAX_POS * pos.f_float);
241 p_main_interface->slider->SetValue(
242 p_intf->p_sys->i_slider_pos );
244 var_Get( p_intf->p_sys->p_input, "time", &time );
245 i_seconds = time.i_time / 1000000;
246 secstotimestr ( psz_time, i_seconds );
248 var_Get( p_intf->p_sys->p_input, "length", &time );
249 i_seconds = time.i_time / 1000000;
250 secstotimestr ( psz_total, i_seconds );
252 p_main_interface->statusbar->SetStatusText(
253 wxU(psz_time) + wxString(wxT(" / ")) +
258 vlc_mutex_unlock( &p_input->stream.stream_lock );
260 /* Take care of the volume, etc... */
261 p_main_interface->Update();
263 /* Manage Playing status */
264 var_Get( p_input, "state", &val );
265 if( i_old_playing_status != val.i_int )
267 if( val.i_int == PAUSE_S )
269 p_main_interface->TogglePlayButton( PAUSE_S );
273 p_main_interface->TogglePlayButton( PLAYING_S );
275 i_old_playing_status = val.i_int;
278 /* Manage Speed status */
279 var_Get( p_input, "rate", &val );
280 if( i_old_rate != val.i_int )
282 p_main_interface->statusbar->SetStatusText(
283 wxString::Format(wxT("x%.2f"),
284 (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
285 i_old_rate = val.i_int;
290 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
292 p_intf->p_sys->b_playing = 0;
293 p_main_interface->TogglePlayButton( PAUSE_S );
294 i_old_playing_status = PAUSE_S;
299 vlc_mutex_unlock( &p_intf->change_lock );
301 /* Prepare to die, young Skywalker */
302 p_main_interface->Close(TRUE);
306 vlc_mutex_unlock( &p_intf->change_lock );
309 /*****************************************************************************
310 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
311 * We don't show the menu directly here because we don't want the
312 * caller to block for a too long time.
313 *****************************************************************************/
314 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
315 vlc_value_t old_val, vlc_value_t new_val, void *param )
317 intf_thread_t *p_intf = (intf_thread_t *)param;
319 if( p_intf->p_sys->pf_show_dialog )
321 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,