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 /* Update the item name */
161 p_main_interface->statusbar->SetStatusText(
162 wxU(p_intf->p_sys->p_input->input.p_item->psz_name), 2 );
164 /* Manage the slider */
166 /* Change the name of b_old_seekable into b_show_bar or something like that */
167 var_Get( p_input, "position", &pos );
169 if( !b_old_seekable )
171 if( pos.f_float > 0.0 )
173 /* Done like this, as it's the only way to know if the slider
174 * has to be displayed */
175 b_old_seekable = VLC_TRUE;
176 p_main_interface->slider_frame->Show();
177 p_main_interface->frame_sizer->Show(
178 p_main_interface->slider_frame );
179 p_main_interface->frame_sizer->Layout();
180 p_main_interface->frame_sizer->Fit( p_main_interface );
185 if( p_intf->p_sys->b_playing && b_old_seekable )
187 /* Update the slider if the user isn't dragging it. */
188 if( p_intf->p_sys->b_slider_free )
190 char psz_time[ MSTRTIME_MAX_SIZE ];
191 char psz_total[ MSTRTIME_MAX_SIZE ];
195 /* Update the value */
196 if( pos.f_float >= 0.0 )
198 p_intf->p_sys->i_slider_pos =
199 (int)(SLIDER_MAX_POS * pos.f_float);
201 p_main_interface->slider->SetValue(
202 p_intf->p_sys->i_slider_pos );
204 var_Get( p_intf->p_sys->p_input, "time", &time );
205 i_seconds = time.i_time / 1000000;
206 secstotimestr ( psz_time, i_seconds );
208 var_Get( p_intf->p_sys->p_input, "length", &time );
209 i_seconds = time.i_time / 1000000;
210 secstotimestr ( psz_total, i_seconds );
212 p_main_interface->statusbar->SetStatusText(
213 wxU(psz_time) + wxString(wxT(" / ")) +
219 vlc_mutex_lock( &p_input->stream.stream_lock );
220 if( p_intf->p_sys->p_input->stream.b_seekable && !b_old_seekable )
222 /* Done like this because b_seekable is set slightly after
223 * the new input object is available. */
224 b_old_seekable = VLC_TRUE;
225 p_main_interface->slider_frame->Show();
226 p_main_interface->frame_sizer->Show(
227 p_main_interface->slider_frame );
228 p_main_interface->frame_sizer->Layout();
229 p_main_interface->frame_sizer->Fit( p_main_interface );
231 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
233 /* Update the slider if the user isn't dragging it. */
234 if( p_intf->p_sys->b_slider_free )
237 char psz_time[ MSTRTIME_MAX_SIZE ];
238 char psz_total[ MSTRTIME_MAX_SIZE ];
242 /* Update the value */
243 var_Get( p_input, "position", &pos );
244 if( pos.f_float >= 0.0 )
246 p_intf->p_sys->i_slider_pos =
247 (int)(SLIDER_MAX_POS * pos.f_float);
249 p_main_interface->slider->SetValue(
250 p_intf->p_sys->i_slider_pos );
252 var_Get( p_intf->p_sys->p_input, "time", &time );
253 i_seconds = time.i_time / 1000000;
254 secstotimestr ( psz_time, i_seconds );
256 var_Get( p_intf->p_sys->p_input, "length", &time );
257 i_seconds = time.i_time / 1000000;
258 secstotimestr ( psz_total, i_seconds );
260 p_main_interface->statusbar->SetStatusText(
261 wxU(psz_time) + wxString(wxT(" / ")) +
266 vlc_mutex_unlock( &p_input->stream.stream_lock );
268 /* Take care of the volume, etc... */
269 p_main_interface->Update();
271 /* Manage Playing status */
272 var_Get( p_input, "state", &val );
273 if( i_old_playing_status != val.i_int )
275 if( val.i_int == PAUSE_S )
277 p_main_interface->TogglePlayButton( PAUSE_S );
281 p_main_interface->TogglePlayButton( PLAYING_S );
283 i_old_playing_status = val.i_int;
286 /* Manage Speed status */
287 var_Get( p_input, "rate", &val );
288 if( i_old_rate != val.i_int )
290 p_main_interface->statusbar->SetStatusText(
291 wxString::Format(wxT("x%.2f"),
292 (float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
293 i_old_rate = val.i_int;
298 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
300 p_intf->p_sys->b_playing = 0;
301 p_main_interface->TogglePlayButton( PAUSE_S );
302 i_old_playing_status = PAUSE_S;
305 /* Show the interface, if requested */
306 if( p_intf->p_sys->b_intf_show )
308 p_main_interface->Raise();
309 p_intf->p_sys->b_intf_show = VLC_FALSE;
314 vlc_mutex_unlock( &p_intf->change_lock );
316 /* Prepare to die, young Skywalker */
317 p_main_interface->Close(TRUE);
321 vlc_mutex_unlock( &p_intf->change_lock );
324 /*****************************************************************************
325 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
326 * We don't show the menu directly here because we don't want the
327 * caller to block for a too long time.
328 *****************************************************************************/
329 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
330 vlc_value_t old_val, vlc_value_t new_val, void *param )
332 intf_thread_t *p_intf = (intf_thread_t *)param;
334 if( p_intf->p_sys->pf_show_dialog )
336 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
343 /*****************************************************************************
344 * IntfShowCB: callback triggered by the intf-show playlist variable.
345 *****************************************************************************/
346 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
347 vlc_value_t old_val, vlc_value_t new_val, void *param )
349 intf_thread_t *p_intf = (intf_thread_t *)param;
350 p_intf->p_sys->b_intf_show = VLC_TRUE;