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;
52 i_old_playing_status = PAUSE_S;
53 i_old_rate = DEFAULT_RATE;
55 /* Register callback for the intf-popupmenu variable */
56 playlist_t *p_playlist =
57 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
59 if( p_playlist != NULL )
61 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
62 vlc_object_release( p_playlist );
65 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
70 /* Unregister callback */
71 playlist_t *p_playlist =
72 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
74 if( p_playlist != NULL )
76 var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
77 vlc_object_release( p_playlist );
81 /*****************************************************************************
83 *****************************************************************************/
85 /*****************************************************************************
86 * Manage: manage main thread messages
87 *****************************************************************************
88 * In this function, called approx. 10 times a second, we check what the
89 * main program wanted to tell us.
90 *****************************************************************************/
93 vlc_bool_t b_pace_control;
95 vlc_mutex_lock( &p_intf->change_lock );
97 /* Update the input */
98 if( p_intf->p_sys->p_input == NULL )
100 p_intf->p_sys->p_input =
101 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
105 if( p_intf->p_sys->p_input )
107 //if( p_intf->p_sys->p_input->stream.b_seekable )
109 p_main_interface->slider_frame->Show();
110 p_main_interface->frame_sizer->Show(
111 p_main_interface->slider_frame );
112 p_main_interface->frame_sizer->Layout();
113 p_main_interface->frame_sizer->Fit( p_main_interface );
116 p_main_interface->statusbar->SetStatusText(
117 wxU(p_intf->p_sys->p_input->psz_source), 2 );
119 p_main_interface->TogglePlayButton( PLAYING_S );
120 i_old_playing_status = PLAYING_S;
122 /* Take care of the volume */
123 audio_volume_t i_volume;
124 aout_VolumeGet( p_intf, &i_volume );
125 p_main_interface->volctrl->SetValue( i_volume * 200 * 2 /
127 p_main_interface->volctrl->SetToolTip(
128 wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
129 i_volume * 200 / AOUT_VOLUME_MAX ) );
131 /* control buttons for free pace streams */
132 b_pace_control = p_intf->p_sys->p_input->stream.b_pace_control;
135 else if( p_intf->p_sys->p_input->b_dead )
138 //if( p_intf->p_sys->p_input->stream.b_seekable )
140 p_main_interface->slider_frame->Hide();
141 p_main_interface->frame_sizer->Hide(
142 p_main_interface->slider_frame );
143 p_main_interface->frame_sizer->Layout();
144 p_main_interface->frame_sizer->Fit( p_main_interface );
146 p_main_interface->TogglePlayButton( PAUSE_S );
147 i_old_playing_status = PAUSE_S;
150 p_main_interface->statusbar->SetStatusText( wxT(""), 0 );
151 p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
153 vlc_object_release( p_intf->p_sys->p_input );
154 p_intf->p_sys->p_input = NULL;
159 if( p_intf->p_sys->p_input )
161 input_thread_t *p_input = p_intf->p_sys->p_input;
163 vlc_mutex_lock( &p_input->stream.stream_lock );
165 if( !p_input->b_die )
167 /* New input or stream map change */
168 p_intf->p_sys->b_playing = 1;
170 if( p_input->stream.b_changed )
172 wxModeManage( p_intf );
173 wxSetupMenus( p_intf );
174 p_intf->p_sys->b_playing = 1;
176 p_main_interface->TogglePlayButton( PLAYING_S );
177 i_old_playing_status = PLAYING_S;
181 /* Manage the slider */
182 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
184 /* Update the slider if the user isn't dragging it. */
185 if( p_intf->p_sys->b_slider_free )
188 char psz_time[ MSTRTIME_MAX_SIZE ];
189 char psz_total[ MSTRTIME_MAX_SIZE ];
193 /* Update the value */
194 var_Get( p_input, "position", &pos );
195 if( pos.f_float >= 0.0 )
197 p_intf->p_sys->i_slider_pos =
198 (int)(SLIDER_MAX_POS * pos.f_float);
200 p_main_interface->slider->SetValue(
201 p_intf->p_sys->i_slider_pos );
203 var_Get( p_intf->p_sys->p_input, "time", &time );
204 i_seconds = time.i_time / 1000000;
205 secstotimestr ( psz_time, i_seconds );
207 var_Get( p_intf->p_sys->p_input, "length", &time );
208 i_seconds = time.i_time / 1000000;
209 secstotimestr ( psz_total, i_seconds );
211 p_main_interface->statusbar->SetStatusText(
212 wxU(psz_time) + wxString(wxT(" / ")) +
218 /* Manage Playing status */
219 if( i_old_playing_status != p_input->stream.control.i_status )
221 if( p_input->stream.control.i_status == PAUSE_S )
223 p_main_interface->TogglePlayButton( PAUSE_S );
227 p_main_interface->TogglePlayButton( PLAYING_S );
229 i_old_playing_status = p_input->stream.control.i_status;
232 /* Manage Speed status */
233 if( i_old_rate != p_input->stream.control.i_rate )
235 p_main_interface->statusbar->SetStatusText(
236 wxString::Format(wxT("x%.2f"),
237 1000.0 / p_input->stream.control.i_rate), 1 );
238 i_old_rate = p_input->stream.control.i_rate;
242 vlc_mutex_unlock( &p_input->stream.stream_lock );
244 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
246 p_intf->p_sys->b_playing = 0;
247 p_main_interface->TogglePlayButton( PAUSE_S );
248 i_old_playing_status = PAUSE_S;
253 vlc_mutex_unlock( &p_intf->change_lock );
255 /* Prepare to die, young Skywalker */
256 p_main_interface->Close(TRUE);
260 vlc_mutex_unlock( &p_intf->change_lock );
263 /*****************************************************************************
264 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
265 * We don't show the menu directly here because we don't want the
266 * caller to block for a too long time.
267 *****************************************************************************/
268 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
269 vlc_value_t old_val, vlc_value_t new_val, void *param )
271 intf_thread_t *p_intf = (intf_thread_t *)param;
273 if( p_intf->p_sys->pf_show_dialog )
275 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,