1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: timer.cpp,v 1.25 2003/06/23 16:09:13 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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() */
35 #ifdef WIN32 /* mingw32 hack */
40 /* Let vlc take care of the i18n stuff */
41 #define WXINTL_NO_GETTEXT_MACRO
43 #include <wx/wxprec.h>
49 #include "wxwindows.h"
51 void DisplayStreamDate( wxControl *, intf_thread_t *, int );
53 /* Callback prototype */
54 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
55 vlc_value_t old_val, vlc_value_t new_val, void *param );
57 /*****************************************************************************
59 *****************************************************************************/
60 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
63 p_main_interface = _p_main_interface;
64 i_old_playing_status = PAUSE_S;
65 i_old_rate = DEFAULT_RATE;
67 /* Register callback for the intf-popupmenu variable */
68 playlist_t *p_playlist =
69 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
71 if( p_playlist != NULL )
73 var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
74 vlc_object_release( p_playlist );
77 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
84 /*****************************************************************************
86 *****************************************************************************/
88 /*****************************************************************************
89 * Manage: manage main thread messages
90 *****************************************************************************
91 * In this function, called approx. 10 times a second, we check what the
92 * main program wanted to tell us.
93 *****************************************************************************/
96 vlc_bool_t b_pace_control;
98 vlc_mutex_lock( &p_intf->change_lock );
100 /* If the "display popup" flag has changed */
101 if( p_intf->p_sys->b_popup_change )
103 wxPoint mousepos = wxGetMousePosition();
105 wxMouseEvent event = wxMouseEvent( wxEVT_RIGHT_UP );
106 event.m_x = p_main_interface->ScreenToClient(mousepos).x;
107 event.m_y = p_main_interface->ScreenToClient(mousepos).y;
109 p_main_interface->AddPendingEvent(event);
111 p_intf->p_sys->b_popup_change = VLC_FALSE;
114 /* Update the log window */
115 p_intf->p_sys->p_messages_window->UpdateLog();
117 /* Update the playlist */
118 p_intf->p_sys->p_playlist_window->UpdatePlaylist();
120 /* Update the fileinfo windows */
121 p_intf->p_sys->p_fileinfo_window->UpdateFileInfo();
123 /* Update the input */
124 if( p_intf->p_sys->p_input == NULL )
126 p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
131 if( p_intf->p_sys->p_input )
133 //if( p_intf->p_sys->p_input->stream.b_seekable )
135 p_main_interface->slider_frame->Show();
136 p_main_interface->frame_sizer->Show(
137 p_main_interface->slider_frame );
138 p_main_interface->frame_sizer->Layout();
139 p_main_interface->frame_sizer->Fit( p_main_interface );
142 p_main_interface->statusbar->SetStatusText(
143 wxU(p_intf->p_sys->p_input->psz_source), 2 );
145 p_main_interface->TogglePlayButton( PLAYING_S );
146 i_old_playing_status = PLAYING_S;
148 /* Take care of the volume */
149 audio_volume_t i_volume;
150 aout_VolumeGet( p_intf, &i_volume );
151 p_main_interface->volctrl->SetValue( i_volume * 200 /
153 p_main_interface->volctrl->SetToolTip(
154 wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
155 i_volume * 200 / AOUT_VOLUME_MAX ) );
157 /* control buttons for free pace streams */
158 b_pace_control = p_intf->p_sys->p_input->stream.b_pace_control;
161 else if( p_intf->p_sys->p_input->b_dead )
164 //if( p_intf->p_sys->p_input->stream.b_seekable )
166 p_main_interface->slider_frame->Hide();
167 p_main_interface->frame_sizer->Hide(
168 p_main_interface->slider_frame );
169 p_main_interface->frame_sizer->Layout();
170 p_main_interface->frame_sizer->Fit( p_main_interface );
172 p_main_interface->TogglePlayButton( PAUSE_S );
173 i_old_playing_status = PAUSE_S;
176 p_main_interface->statusbar->SetStatusText( wxT(""), 2 );
178 vlc_object_release( p_intf->p_sys->p_input );
179 p_intf->p_sys->p_input = NULL;
184 if( p_intf->p_sys->p_input )
186 input_thread_t *p_input = p_intf->p_sys->p_input;
188 vlc_mutex_lock( &p_input->stream.stream_lock );
190 if( !p_input->b_die )
192 /* New input or stream map change */
193 p_intf->p_sys->b_playing = 1;
195 if( p_input->stream.b_changed )
197 wxModeManage( p_intf );
198 wxSetupMenus( p_intf );
199 p_intf->p_sys->b_playing = 1;
201 p_main_interface->TogglePlayButton( PLAYING_S );
202 i_old_playing_status = PLAYING_S;
206 /* Manage the slider */
207 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
209 stream_position_t position;
211 /* Update the slider if the user isn't dragging it. */
212 if( p_intf->p_sys->b_slider_free )
214 /* Update the value */
215 vlc_mutex_unlock( &p_input->stream.stream_lock );
216 input_Tell( p_input, &position );
217 vlc_mutex_lock( &p_input->stream.stream_lock );
218 if( position.i_size )
220 p_intf->p_sys->i_slider_pos =
221 ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
223 p_main_interface->slider->SetValue(
224 p_intf->p_sys->i_slider_pos );
226 DisplayStreamDate( p_main_interface->slider_box,p_intf,
227 p_intf->p_sys->i_slider_pos );
232 /* Manage Playing status */
233 if( i_old_playing_status != p_input->stream.control.i_status )
235 if( p_input->stream.control.i_status == PAUSE_S )
237 p_main_interface->TogglePlayButton( PAUSE_S );
241 p_main_interface->TogglePlayButton( PLAYING_S );
243 i_old_playing_status = p_input->stream.control.i_status;
246 /* Manage Speed status */
247 if( i_old_rate != p_input->stream.control.i_rate )
249 p_main_interface->statusbar->SetStatusText(
250 wxString::Format(wxT("x%.2f"),
251 1000.0 / p_input->stream.control.i_rate), 1 );
252 i_old_rate = p_input->stream.control.i_rate;
256 vlc_mutex_unlock( &p_input->stream.stream_lock );
258 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
260 p_intf->p_sys->b_playing = 0;
261 p_main_interface->TogglePlayButton( PAUSE_S );
262 i_old_playing_status = PAUSE_S;
267 vlc_mutex_unlock( &p_intf->change_lock );
269 /* Prepare to die, young Skywalker */
270 p_main_interface->Close(TRUE);
274 vlc_mutex_unlock( &p_intf->change_lock );
277 /*****************************************************************************
278 * DisplayStreamDate: display stream date
279 *****************************************************************************
280 * This function displays the current date related to the position in
281 * the stream. It is called whenever the slider changes its value.
282 * The lock has to be taken before you call the function.
283 *****************************************************************************/
284 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
287 if( p_intf->p_sys->p_input )
289 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
290 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
292 p_slider_frame->SetLabel(
293 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
294 psz_time, p_area->i_size * i_pos / SLIDER_MAX_POS )) );
299 /*****************************************************************************
300 * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
301 * We don't show the menu directly here because we don't want the
302 * caller to block for a too long time.
303 *****************************************************************************/
304 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
305 vlc_value_t old_val, vlc_value_t new_val, void *param )
307 intf_thread_t *p_intf = (intf_thread_t *)param;
309 p_intf->p_sys->b_popup_change = VLC_TRUE;