timer.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:9k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * timer.cpp : WinCE gui plugin for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2000-2003 the VideoLAN team
  5.  * $Id: b7da9e9097b8604c61396a8f498af896e4532467 $
  6.  *
  7.  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
  8.  *          Gildas Bazin <gbazin@videolan.org>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. # include "config.h"
  29. #endif
  30. #include <vlc_common.h>
  31. #include <vlc_aout.h>
  32. #include <vlc_interface.h>
  33. #include <vlc_input.h>
  34. #include <vlc_playlist.h>
  35. #include "wince.h"
  36. #include <commctrl.h>
  37. /* Callback prototype */
  38. static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
  39.                         vlc_value_t old_val, vlc_value_t new_val, void * );
  40. /*****************************************************************************
  41.  * Constructor.
  42.  *****************************************************************************/
  43. Timer::Timer( intf_thread_t *_p_intf, HWND hwnd, Interface *_p_main_interface)
  44. {
  45.     p_intf = _p_intf;
  46.     p_main_interface = _p_main_interface;
  47.     i_old_playing_status = PAUSE_S;
  48.     i_old_rate = INPUT_RATE_DEFAULT;
  49.     /* Register callback for the intf-popupmenu variable */
  50.     playlist_t *p_playlist = pl_Hold( p_intf );
  51.     if( p_playlist != NULL )
  52.     {
  53.         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
  54.         pl_Release( p_intf );
  55.     }
  56.     SetTimer( hwnd, 1, 200 /*milliseconds*/, NULL );
  57. }
  58. Timer::~Timer()
  59. {
  60.     /* Unregister callback */
  61.     playlist_t *p_playlist = pl_Hold( p_intf );
  62.     if( p_playlist != NULL )
  63.     {
  64.         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
  65.         pl_Release( p_intf );
  66.     }
  67. }
  68. /*****************************************************************************
  69.  * Private methods.
  70.  *****************************************************************************/
  71. /*****************************************************************************
  72.  * Manage: manage main thread messages
  73.  *****************************************************************************
  74.  * In this function, called approx. 10 times a second, we check what the
  75.  * main program wanted to tell us.
  76.  *****************************************************************************/
  77. void Timer::Notify( void )
  78. {
  79.     vlc_value_t val;
  80.     char *shortname;
  81.     /* Update the input */
  82.     if( p_intf->p_sys->p_input == NULL )
  83.     {
  84.         p_intf->p_sys->p_input =
  85.             (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
  86.                                                FIND_ANYWHERE );
  87.         /* Show slider */
  88.         if( p_intf->p_sys->p_input )
  89.         {
  90.             ShowWindow( p_main_interface->hwndSlider, SW_SHOW );
  91.             ShowWindow( p_main_interface->hwndLabel, SW_SHOW );
  92.             ShowWindow( p_main_interface->hwndVol, SW_SHOW );
  93.             // only for local file, check if works well with net url
  94.             input_item_t *p_item =input_GetItem(p_intf->p_sys->p_input);
  95.             shortname = strrchr( input_item_GetURL(p_item), '\' );
  96.             if (! shortname)
  97.                 shortname = input_item_GetURL(p_item);
  98.             else shortname++;
  99.  
  100.             SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
  101.                          (WPARAM) 0, (LPARAM)_FROMMB(shortname) );
  102.             p_main_interface->TogglePlayButton( PLAYING_S );
  103.             i_old_playing_status = PLAYING_S;
  104.         }
  105.     }
  106.     else if( p_intf->p_sys->p_input->b_dead )
  107.     {
  108.         /* Hide slider */
  109.         ShowWindow( p_main_interface->hwndSlider, SW_HIDE);
  110.         ShowWindow( p_main_interface->hwndLabel, SW_HIDE);
  111.         ShowWindow( p_main_interface->hwndVol, SW_HIDE);
  112.         p_main_interface->TogglePlayButton( PAUSE_S );
  113.         i_old_playing_status = PAUSE_S;
  114.         SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
  115.                      (WPARAM) 0, (LPARAM)(LPCTSTR) TEXT(""));
  116.         vlc_object_release( p_intf->p_sys->p_input );
  117.         p_intf->p_sys->p_input = NULL;
  118.     }
  119.     if( p_intf->p_sys->p_input )
  120.     {
  121.         input_thread_t *p_input = p_intf->p_sys->p_input;
  122.         if( vlc_object_alive (p_input) )
  123.         {
  124.             /* New input or stream map change */
  125.             p_intf->p_sys->b_playing = 1;
  126.             /* Manage the slider */
  127.             if( /*p_input->stream.b_seekable &&*/ p_intf->p_sys->b_playing )
  128.             {
  129.                 /* Update the slider if the user isn't dragging it. */
  130.                 if( p_intf->p_sys->b_slider_free )
  131.                 {
  132.                     vlc_value_t pos;
  133.                     char psz_time[ MSTRTIME_MAX_SIZE ];
  134.                     vlc_value_t time;
  135.                     mtime_t i_seconds;
  136.                     /* Update the value */
  137.                     var_Get( p_input, "position", &pos );
  138.                     if( pos.f_float >= 0.0 )
  139.                     {
  140.                         p_intf->p_sys->i_slider_pos =
  141.                             (int)(SLIDER_MAX_POS * pos.f_float);
  142.                         SendMessage( p_main_interface->hwndSlider, TBM_SETPOS,
  143.                                      1, p_intf->p_sys->i_slider_pos );
  144.                         var_Get( p_intf->p_sys->p_input, "time", &time );
  145.                         i_seconds = time.i_time / 1000000;
  146.                         secstotimestr ( psz_time, i_seconds );
  147.                         SendMessage( p_main_interface->hwndLabel, WM_SETTEXT,
  148.                                      (WPARAM)1, (LPARAM)_FROMMB(psz_time) );
  149.                     }
  150.                 }
  151.             }
  152.             /* Take care of the volume, etc... */
  153.             p_main_interface->Update();
  154.             /* Manage Playing status */
  155.             var_Get( p_input, "state", &val );
  156.             if( i_old_playing_status != val.i_int )
  157.             {
  158.                 if( val.i_int == PAUSE_S )
  159.                 {
  160.                     p_main_interface->TogglePlayButton( PAUSE_S );
  161.                 }
  162.                 else
  163.                 {
  164.                     p_main_interface->TogglePlayButton( PLAYING_S );
  165.                 }
  166.                 i_old_playing_status = val.i_int;
  167.             }
  168.             /* Manage Speed status */
  169.             var_Get( p_input, "rate", &val );
  170.             if( i_old_rate != val.i_int )
  171.             {
  172.                 TCHAR psz_text[15];
  173.                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
  174.                 psz_text[0] = psz_text[1] = _T('t');
  175.                 SendMessage( p_main_interface->hwndSB, SB_SETTEXT,
  176.                              (WPARAM) 1, (LPARAM)(LPCTSTR) psz_text );
  177.                 i_old_rate = val.i_int;
  178.             }
  179.         }
  180.     }
  181.     else if( p_intf->p_sys->b_playing && vlc_object_alive( p_intf ) )
  182.     {
  183.         p_intf->p_sys->b_playing = 0;
  184.         p_main_interface->TogglePlayButton( PAUSE_S );
  185.         i_old_playing_status = PAUSE_S;
  186.     }
  187.     if( !vlc_object_alive( p_intf ) )
  188.     {
  189.         /* Prepare to die, young Skywalker */
  190. /*        p_main_interface->Close(TRUE);*/
  191.         return;
  192.     }
  193. }
  194. /*****************************************************************************
  195.  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
  196.  *  We don't show the menu directly here because we don't want the
  197.  *  caller to block for a too long time.
  198.  *****************************************************************************/
  199. static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
  200.                         vlc_value_t old_val, vlc_value_t new_val, void *param )
  201. {
  202.     intf_thread_t *p_intf = (intf_thread_t *)param;
  203.     if( p_intf->p_sys->pf_show_dialog )
  204.     {
  205.         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
  206.                                        new_val.b_bool, 0 );
  207.     }
  208.     return VLC_SUCCESS;
  209. }