1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: timer.cpp,v 1.11 2003/03/26 00:56:22 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() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
48 #include "wxwindows.h"
50 void DisplayStreamDate( wxControl *, intf_thread_t *, int );
52 /*****************************************************************************
54 *****************************************************************************/
55 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
58 p_main_interface = _p_main_interface;
59 i_old_playing_status = PAUSE_S;
61 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
68 /*****************************************************************************
70 *****************************************************************************/
71 /*****************************************************************************
72 * wxModeManage: actualise the aspect of the interface whenever the input
74 *****************************************************************************
75 * The lock has to be taken before you call the function.
76 *****************************************************************************/
77 static int wxModeManage( intf_thread_t * p_intf )
82 /*****************************************************************************
83 * wxSetupMenus: function that generates title/chapter/audio/subpic
84 * menus with help from preceding functions
85 *****************************************************************************
86 * Function called with the lock on stream
87 *****************************************************************************/
88 static int wxSetupMenus( intf_thread_t * p_intf )
93 /*****************************************************************************
94 * Manage: manage main thread messages
95 *****************************************************************************
96 * In this function, called approx. 10 times a second, we check what the
97 * main program wanted to tell us.
98 *****************************************************************************/
101 vlc_mutex_lock( &p_intf->change_lock );
103 /* If the "display popup" flag has changed */
104 if( p_intf->b_menu_change )
106 p_main_interface->p_popup_menu =
107 new PopupMenu( p_intf, p_main_interface );
108 p_intf->b_menu_change = 0;
111 /* Update the log window */
112 p_intf->p_sys->p_messages_window->UpdateLog();
114 /* Update the playlist */
115 p_intf->p_sys->p_playlist_window->Manage();
117 /* Update the input */
118 if( p_intf->p_sys->p_input == NULL )
120 p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
124 if(p_intf->p_sys->p_input)
126 p_main_interface->frame_sizer->Add(
127 p_main_interface->slider_frame, 1, wxGROW, 0 );
128 p_main_interface->slider_frame->Show();
129 p_main_interface->frame_sizer->Layout();
130 p_main_interface->frame_sizer->Fit( p_main_interface );
131 p_main_interface->statusbar->SetStatusText(
132 p_intf->p_sys->p_input->psz_source, 1 );
134 p_main_interface->TogglePlayButton( PLAYING_S );
135 i_old_playing_status = PLAYING_S;
138 else if( p_intf->p_sys->p_input->b_dead )
141 if(p_intf->p_sys->p_input)
143 p_main_interface->slider_frame->Hide();
144 p_main_interface->frame_sizer->Remove(
145 p_main_interface->slider_frame );
146 p_main_interface->frame_sizer->Layout();
147 p_main_interface->frame_sizer->Fit( p_main_interface );
149 p_main_interface->TogglePlayButton( PAUSE_S );
150 i_old_playing_status = PAUSE_S;
153 p_main_interface->statusbar->SetStatusText( "", 1 );
155 vlc_object_release( p_intf->p_sys->p_input );
156 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 )
185 stream_position_t position;
187 /* Update the slider if the user isn't dragging it. */
188 if( p_intf->p_sys->b_slider_free )
190 /* Update the value */
191 vlc_mutex_unlock( &p_input->stream.stream_lock );
192 input_Tell( p_input, &position );
193 vlc_mutex_lock( &p_input->stream.stream_lock );
194 p_intf->p_sys->i_slider_pos =
195 ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
197 p_main_interface->slider->SetValue(
198 p_intf->p_sys->i_slider_pos );
200 DisplayStreamDate( p_main_interface->slider_box,
202 p_intf->p_sys->i_slider_pos );
206 if( p_intf->p_sys->i_part !=
207 p_input->stream.p_selected_area->i_part )
209 p_intf->p_sys->b_chapter_update = 1;
210 wxSetupMenus( p_intf );
213 /* Manage Playing status */
214 if( i_old_playing_status != p_input->stream.control.i_status )
216 if( p_input->stream.control.i_status == PAUSE_S )
218 p_main_interface->TogglePlayButton( PAUSE_S );
222 p_main_interface->TogglePlayButton( PLAYING_S );
224 i_old_playing_status = p_input->stream.control.i_status;
228 vlc_mutex_unlock( &p_input->stream.stream_lock );
230 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
232 wxModeManage( p_intf );
233 p_intf->p_sys->b_playing = 0;
234 p_main_interface->TogglePlayButton( PAUSE_S );
235 i_old_playing_status = PAUSE_S;
240 vlc_mutex_unlock( &p_intf->change_lock );
242 /* Prepare to die, young Skywalker */
243 p_main_interface->Close(TRUE);
247 vlc_mutex_unlock( &p_intf->change_lock );
250 /*****************************************************************************
251 * DisplayStreamDate: display stream date
252 *****************************************************************************
253 * This function displays the current date related to the position in
254 * the stream. It is called whenever the slider changes its value.
255 * The lock has to be taken before you call the function.
256 *****************************************************************************/
257 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
260 if( p_intf->p_sys->p_input )
262 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
263 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
265 p_slider_frame->SetLabel(
266 input_OffsetToTime( p_intf->p_sys->p_input,
268 p_area->i_size * i_pos / SLIDER_MAX_POS ) );