]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/timer.cpp
3dc99456ea7a1bcc90edefb22e48f03b9b3d283e
[vlc] / modules / gui / wxwindows / timer.cpp
1 /*****************************************************************************
2  * timer.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: timer.cpp,v 1.12 2003/03/30 19:56:11 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/timer.h>
45
46 #include <vlc/intf.h>
47
48 #include "wxwindows.h"
49
50 void DisplayStreamDate( wxControl *, intf_thread_t *, int );
51
52 /*****************************************************************************
53  * Constructor.
54  *****************************************************************************/
55 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
56 {
57     p_intf = _p_intf;
58     p_main_interface = _p_main_interface;
59     i_old_playing_status = PAUSE_S;
60
61     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
62 }
63
64 Timer::~Timer()
65 {
66 }
67
68 /*****************************************************************************
69  * Private methods.
70  *****************************************************************************/
71 /*****************************************************************************
72  * wxModeManage: actualise the aspect of the interface whenever the input
73  * changes.
74  *****************************************************************************
75  * The lock has to be taken before you call the function.
76  *****************************************************************************/
77 static int wxModeManage( intf_thread_t * p_intf )
78 {
79     return 0;
80 }
81
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 )
89 {
90     return 0;
91 }
92
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  *****************************************************************************/
99 void Timer::Notify()
100 {
101     vlc_bool_t b_pace_control;
102
103     vlc_mutex_lock( &p_intf->change_lock );
104
105     /* If the "display popup" flag has changed */
106     if( p_intf->b_menu_change )
107     {
108         p_main_interface->p_popup_menu =
109             new PopupMenu( p_intf, p_main_interface );
110         p_intf->b_menu_change = 0;
111     }
112
113     /* Update the log window */
114     p_intf->p_sys->p_messages_window->UpdateLog();
115
116     /* Update the playlist */
117     p_intf->p_sys->p_playlist_window->Manage();
118
119     /* Update the input */
120     if( p_intf->p_sys->p_input == NULL )
121     {
122         p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
123                                                        VLC_OBJECT_INPUT,
124                                                        FIND_ANYWHERE );
125
126         /* Show slider */
127         if( p_intf->p_sys->p_input )
128         {
129             //if( p_intf->p_sys->p_input->stream.b_seekable )
130             {
131                 p_main_interface->slider_frame->Show();
132                 p_main_interface->frame_sizer->Show(
133                     p_main_interface->slider_frame );
134                 p_main_interface->frame_sizer->Layout();
135                 p_main_interface->frame_sizer->Fit( p_main_interface );
136             }
137
138             p_main_interface->statusbar->SetStatusText(
139                 p_intf->p_sys->p_input->psz_source, 1 );
140
141             p_main_interface->TogglePlayButton( PLAYING_S );
142             i_old_playing_status = PLAYING_S;
143         }
144
145         /* control buttons for free pace streams */
146         b_pace_control = p_intf->p_sys->p_input->stream.b_pace_control;
147
148     }
149     else if( p_intf->p_sys->p_input->b_dead )
150     {
151         /* Hide slider */
152         //if( p_intf->p_sys->p_input->stream.b_seekable )
153         {
154             p_main_interface->slider_frame->Hide();
155             p_main_interface->frame_sizer->Hide(
156                 p_main_interface->slider_frame );
157             p_main_interface->frame_sizer->Layout();
158             p_main_interface->frame_sizer->Fit( p_main_interface );
159
160             p_main_interface->TogglePlayButton( PAUSE_S );
161             i_old_playing_status = PAUSE_S;
162         }
163
164         p_main_interface->statusbar->SetStatusText( "", 1 );
165
166         vlc_object_release( p_intf->p_sys->p_input );
167         p_intf->p_sys->p_input = NULL;
168     }
169
170     if( p_intf->p_sys->p_input )
171     {
172         input_thread_t *p_input = p_intf->p_sys->p_input;
173
174         vlc_mutex_lock( &p_input->stream.stream_lock );
175
176         if( !p_input->b_die )
177         {
178             /* New input or stream map change */
179             p_intf->p_sys->b_playing = 1;
180 #if 0
181             if( p_input->stream.b_changed )
182             {
183                 wxModeManage( p_intf );
184                 wxSetupMenus( p_intf );
185                 p_intf->p_sys->b_playing = 1;
186
187                 p_main_interface->TogglePlayButton( PLAYING_S );
188                 i_old_playing_status = PLAYING_S;
189             }
190 #endif
191
192             /* Manage the slider */
193             if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
194             {
195                 stream_position_t position;
196
197                 /* Update the slider if the user isn't dragging it. */
198                 if( p_intf->p_sys->b_slider_free )
199                 {
200                     /* Update the value */
201                     vlc_mutex_unlock( &p_input->stream.stream_lock );
202                     input_Tell( p_input, &position );
203                     vlc_mutex_lock( &p_input->stream.stream_lock );
204                     if( position.i_size )
205                     {
206                         p_intf->p_sys->i_slider_pos =
207                         ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
208
209                         p_main_interface->slider->SetValue(
210                             p_intf->p_sys->i_slider_pos );
211
212                         DisplayStreamDate( p_main_interface->slider_box,p_intf,
213                                            p_intf->p_sys->i_slider_pos );
214                     }
215                 }
216             }
217
218             if( p_intf->p_sys->i_part !=
219                 p_input->stream.p_selected_area->i_part )
220             {
221                 p_intf->p_sys->b_chapter_update = 1;
222                 wxSetupMenus( p_intf );
223             }
224
225             /* Manage Playing status */
226             if( i_old_playing_status != p_input->stream.control.i_status )
227             {
228                 if( p_input->stream.control.i_status == PAUSE_S )
229                 {
230                     p_main_interface->TogglePlayButton( PAUSE_S );
231                 }
232                 else
233                 {
234                     p_main_interface->TogglePlayButton( PLAYING_S );
235                 }
236                 i_old_playing_status = p_input->stream.control.i_status;
237             }
238         }
239
240         vlc_mutex_unlock( &p_input->stream.stream_lock );
241     }
242     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
243     {
244         wxModeManage( p_intf );
245         p_intf->p_sys->b_playing = 0;
246         p_main_interface->TogglePlayButton( PAUSE_S );
247         i_old_playing_status = PAUSE_S;
248     }
249
250     if( p_intf->b_die )
251     {
252         vlc_mutex_unlock( &p_intf->change_lock );
253
254         /* Prepare to die, young Skywalker */
255         p_main_interface->Close(TRUE);
256         return;
257     }
258
259     vlc_mutex_unlock( &p_intf->change_lock );
260 }
261
262 /*****************************************************************************
263  * DisplayStreamDate: display stream date
264  *****************************************************************************
265  * This function displays the current date related to the position in
266  * the stream. It is called whenever the slider changes its value.
267  * The lock has to be taken before you call the function.
268  *****************************************************************************/
269 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
270                         int i_pos )
271 {
272     if( p_intf->p_sys->p_input )
273     {
274 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
275         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
276
277         p_slider_frame->SetLabel(
278             input_OffsetToTime( p_intf->p_sys->p_input,
279                                 psz_time,
280                                 p_area->i_size * i_pos / SLIDER_MAX_POS ) );
281 #undef p_area
282      }
283 }