]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/timer.cpp
* InterfaceWindow.cpp: removed warnigs
[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.5 2002/11/23 16:17:12 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
60     Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
61 }
62
63 Timer::~Timer()
64 {
65 }
66
67 /*****************************************************************************
68  * Private methods.
69  *****************************************************************************/
70 /*****************************************************************************
71  * wxModeManage: actualise the aspect of the interface whenever the input
72  * changes.
73  *****************************************************************************
74  * The lock has to be taken before you call the function.
75  *****************************************************************************/
76 static int wxModeManage( intf_thread_t * p_intf )
77 {
78     return 0;
79 }
80
81 /*****************************************************************************
82  * wxSetupMenus: function that generates title/chapter/audio/subpic
83  * menus with help from preceding functions
84  *****************************************************************************
85  * Function called with the lock on stream
86  *****************************************************************************/
87 static int wxSetupMenus( intf_thread_t * p_intf )
88 {
89     return 0;
90 }
91
92 /*****************************************************************************
93  * Manage: manage main thread messages
94  *****************************************************************************
95  * In this function, called approx. 10 times a second, we check what the
96  * main program wanted to tell us.
97  *****************************************************************************/
98 void Timer::Notify()
99 {
100     int i_stop;
101
102     vlc_mutex_lock( &p_intf->change_lock );
103
104     /* If the "display popup" flag has changed */
105     if( p_intf->b_menu_change )
106     {
107         p_intf->b_menu_change = 0;
108     }
109
110     /* Update the log window */
111     vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
112     i_stop = *p_intf->p_sys->p_sub->pi_stop;
113     vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
114
115     if( p_intf->p_sys->p_sub->i_start != i_stop )
116     {
117         /* Append all messages to log window */
118     }
119
120     /* Update the playlist */
121     p_intf->p_sys->p_playlist_window->Manage();
122
123     /* Update the input */
124     if( p_intf->p_sys->p_input == NULL )
125     {
126         p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
127                                                        VLC_OBJECT_INPUT,
128                                                        FIND_ANYWHERE );
129         /* Show slider */
130         if(p_intf->p_sys->p_input)
131         {
132             p_main_interface->frame_sizer->Add(
133                 p_main_interface->slider_frame, 1, wxGROW, 0 );
134             p_main_interface->slider_frame->Show();
135             p_main_interface->frame_sizer->Layout();
136             p_main_interface->frame_sizer->Fit( p_main_interface );
137             p_main_interface->statusbar->SetStatusText(
138                 p_intf->p_sys->p_input->psz_source, 1 );
139         }
140     }
141     else if( p_intf->p_sys->p_input->b_dead )
142     {
143         /* Hide slider */
144         if(p_intf->p_sys->p_input)
145         {
146             p_main_interface->slider_frame->Hide();
147             p_main_interface->frame_sizer->Remove(
148                 p_main_interface->slider_frame );
149             p_main_interface->frame_sizer->Layout();
150             p_main_interface->frame_sizer->Fit( p_main_interface );
151         }
152
153         p_main_interface->statusbar->SetStatusText( "", 1 );
154
155         vlc_object_release( p_intf->p_sys->p_input );
156         p_intf->p_sys->p_input = NULL;
157     }
158
159     if( p_intf->p_sys->p_input )
160     {
161         input_thread_t *p_input = p_intf->p_sys->p_input;
162
163         vlc_mutex_lock( &p_input->stream.stream_lock );
164
165         if( !p_input->b_die )
166         {
167             /* New input or stream map change */
168             if( p_input->stream.b_changed )
169             {
170                 wxModeManage( p_intf );
171                 wxSetupMenus( p_intf );
172                 p_intf->p_sys->b_playing = 1;
173             }
174
175             /* Manage the slider */
176             if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
177             {
178
179                 stream_position_t position;
180
181                 /* If the user hasn't touched the slider since the last time,
182                  * then the input can safely change it */
183                 if( p_intf->p_sys->i_slider_pos ==
184                     p_intf->p_sys->i_slider_oldpos )
185                 {
186                     /* Update the value */
187                     vlc_mutex_unlock( &p_input->stream.stream_lock );
188                     input_Tell( p_input, &position );
189                     vlc_mutex_lock( &p_input->stream.stream_lock );
190                     p_intf->p_sys->i_slider_oldpos =
191                         ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
192
193                     if( p_intf->p_sys->i_slider_pos !=
194                         p_intf->p_sys->i_slider_oldpos )
195                     {
196                         p_intf->p_sys->i_slider_pos =
197                             p_intf->p_sys->i_slider_oldpos;
198
199                         p_main_interface->slider->SetValue(
200                             p_intf->p_sys->i_slider_pos );
201
202                         DisplayStreamDate( p_main_interface->slider_box,
203                                            p_intf,
204                                            p_intf->p_sys->i_slider_pos );
205                     }
206                 }
207
208                 /* Otherwise, send message to the input if the user has
209                  * finished dragging the slider */
210                 else if( p_intf->p_sys->b_slider_free )
211                 {
212                     /* release the lock to be able to seek */
213                     vlc_mutex_unlock( &p_input->stream.stream_lock );
214                     input_Seek( p_input, p_intf->p_sys->i_slider_pos *
215                                 100 / SLIDER_MAX_POS,
216                                 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
217                     vlc_mutex_lock( &p_input->stream.stream_lock );
218
219                     /* Update the old value */
220                     p_intf->p_sys->i_slider_oldpos =
221                         p_intf->p_sys->i_slider_pos;
222                 }
223             }
224
225             if( p_intf->p_sys->i_part !=
226                 p_input->stream.p_selected_area->i_part )
227             {
228                 p_intf->p_sys->b_chapter_update = 1;
229                 wxSetupMenus( p_intf );
230             }
231         }
232
233         vlc_mutex_unlock( &p_input->stream.stream_lock );
234     }
235     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
236     {
237         wxModeManage( p_intf );
238         p_intf->p_sys->b_playing = 0;
239     }
240
241     if( p_intf->b_die )
242     {
243         vlc_mutex_unlock( &p_intf->change_lock );
244
245         /* Prepare to die, young Skywalker */
246         p_main_interface->Close(TRUE);
247         return;
248     }
249
250     vlc_mutex_unlock( &p_intf->change_lock );
251 }
252
253 /*****************************************************************************
254  * DisplayStreamDate: display stream date
255  *****************************************************************************
256  * This function displays the current date related to the position in
257  * the stream. It is called whenever the slider changes its value.
258  * The lock has to be taken before you call the function.
259  *****************************************************************************/
260 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
261                         int i_pos )
262 {
263     if( p_intf->p_sys->p_input )
264     {
265 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
266         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
267
268         p_slider_frame->SetLabel(
269             input_OffsetToTime( p_intf->p_sys->p_input,
270                                 psz_time,
271                                 p_area->i_size * i_pos / SLIDER_MAX_POS ) );
272 #undef p_area
273      }
274 }