changeset 6619:f554e7271587

fix volume handling ( step 2 ) -- add balance support and some code cleanup and fix
author pontscho
date Tue, 02 Jul 2002 13:35:04 +0000
parents d6c07ebda746
children 7560037301a3
files Gui/interface.c Gui/interface.h Gui/mplayer/mplayer.c Gui/mplayer/mplayer.h Gui/mplayer/mw.h Gui/mplayer/sw.h Gui/wm/ws.c mplayer.c mplayer.h
diffstat 9 files changed, 79 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/Gui/interface.c	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/interface.c	Tue Jul 02 13:35:04 2002 +0000
@@ -7,6 +7,7 @@
 #include "ws.h"
 #include "mplayer/play.h"
 #include "interface.h"
+#include "skin/skin.h"
 
 #include "../mplayer.h"
 #include "mplayer/widgets.h"
@@ -15,6 +16,7 @@
 #include "../libvo/x11_common.h"
 #include "../libvo/video_out.h"
 #include "../input/input.h"
+#include "../libao2/audio_out.h"
 
 #include <inttypes.h>
 #include <sys/types.h>
@@ -65,12 +67,15 @@
  int disp_w,disp_h;
 } tmp_sh_video_t;
 
+extern ao_functions_t * audio_out;
+
 void guiGetEvent( int type,char * arg )
 {
  stream_t * stream = (stream_t *) arg;
 #ifdef USE_DVDREAD
  dvd_priv_t * dvdp = (dvd_priv_t *) arg;
 #endif 
+
  switch ( type )
   {
    case guiXEvent:
@@ -172,12 +177,38 @@
 	if ( (unsigned int)arg & guiVCD ) guiIntfStruct.VCDTracks=0;
 #endif
 	break;
+   case guiReDraw:
+//        if ( audio_out )
+//         {
+//	  float l,r;
+ //	  mixer_getvolume( &l,&r );
+//	  guiIntfStruct.Volume=(r>l?r:l);
+//	  printf( "!!! guiIntfStruct.Volume: %.2f   \n",guiIntfStruct.Volume );
+//	 }
+	mplEventHandling( evRedraw,0 );
+	break;
+   case guiSetVolume:
+        if ( audio_out )
+	{
+	 float l,r;
+	 mixer_getvolume( &l,&r );
+	 guiIntfStruct.Volume=(r>l?r:l);
+	 if ( r != l ) guiIntfStruct.Balance=( ( r - l ) + 100 ) * 0.5f;
+	   else guiIntfStruct.Balance=0.0f;
+	 btnModify( evSetVolume,guiIntfStruct.Volume );
+	 btnModify( evSetBalance,guiIntfStruct.Balance );
+	}
+        break;
   }
 }
 
+extern unsigned int GetTimerMS( void );
+extern int mplTimer;
+
 void guiEventHandling( void )
 {
- if ( ( use_gui && !guiIntfStruct.Playing )||( guiIntfStruct.AudioOnly ) ) wsHandleEvents();
+ if ( !guiIntfStruct.Playing || guiIntfStruct.AudioOnly ) wsHandleEvents();
  gtkEventHandling();
- mplTimerHandler(); // handle GUI timer events
+ mplTimer=GetTimerMS() / 20;
+// if ( !( GetTimerMS()%2 ) ) 
 }
--- a/Gui/interface.h	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/interface.h	Tue Jul 02 13:35:04 2002 +0000
@@ -10,7 +10,6 @@
  #include "../libmpdemux/stream.h"
 #endif
 
-
 typedef struct
 {
  int x;
@@ -74,9 +73,7 @@
    int    MovieHeight;
 
    float  Volume;
-   int    VolumeChanged;
    float  Balance;
-   int    Mute;
 
    int    Track;
    int    AudioType;
@@ -111,6 +108,8 @@
 #define guiSetShVideo       8
 #define guiSetStream        9
 #define guiClearStruct      10
+#define guiReDraw	    11
+#define guiSetVolume        12
 
 #define guiSetStop  0
 #define guiSetPlay  1
--- a/Gui/mplayer/mplayer.c	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/mplayer/mplayer.c	Tue Jul 02 13:35:04 2002 +0000
@@ -35,13 +35,6 @@
 #include "sw.h"
 #include "widgets.h"
 
-void mplTimerHandler( void )
-{
- mplTimer++;
- mplRedrawTimer--;
- if ( mplRedrawTimer == 0 ) mplEventHandling( evRedraw,0 );
-}
-
 void mplInit( void * disp )
 {
  int i;
--- a/Gui/mplayer/mplayer.h	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/mplayer/mplayer.h	Tue Jul 02 13:35:04 2002 +0000
@@ -14,6 +14,5 @@
 
 extern void mplInit( void * disp );
 extern void mplEventHandling( int msg,float param );
-extern void mplTimerHandler( void );
 
 #endif
--- a/Gui/mplayer/mw.h	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/mplayer/mw.h	Tue Jul 02 13:35:04 2002 +0000
@@ -3,6 +3,8 @@
 
 #include "../../libmpdemux/stream.h"
 #include "../../mixer.h"
+#include "../../libvo/sub.h"
+#include "../../mplayer.h"
 
 unsigned char * mplDrawBuffer = NULL;
 int             mplMainRender = 1;
@@ -100,7 +102,7 @@
        case 'l': if ( guiIntfStruct.Playing == 1 ) strcat( trbuf,"p" ); break;
        case 'e': if ( guiIntfStruct.Playing == 2 ) strcat( trbuf,"e" ); break;
        case 'a':
-//            if ( guiIntfStruct.Mute ) { strcat( trbuf,"n" ); break; }
+            if ( muted ) { strcat( trbuf,"n" ); break; }
             switch ( guiIntfStruct.AudioType )
              {
               case 0: strcat( trbuf,"n" ); break;
@@ -214,6 +216,7 @@
 extern char * dvd_device;
 extern int vcd_track;
 extern char * cdrom_device;
+extern int osd_visible;
 
 void mplEventHandling( int msg,float param )
 {
@@ -261,11 +264,11 @@
          {
 	  case STREAMTYPE_STREAM:
 	  case STREAMTYPE_FILE:
-	       guiGetEvent( guiClearStruct,guiALL );
+	       guiGetEvent( guiClearStruct,(char *)guiALL );
 	       break;
 #ifdef HAVE_VCD
           case STREAMTYPE_VCD:
-	       guiGetEvent( guiClearStruct,guiALL - guiVCD );
+	       guiGetEvent( guiClearStruct,(char *)(guiALL - guiVCD ) );
 	       if ( !cdrom_device )
 	        {
 		 cdrom_device=DEFAULT_CDROM_DEVICE;
@@ -285,7 +288,7 @@
 #endif
 #ifdef USE_DVDREAD
           case STREAMTYPE_DVD:
-	       guiGetEvent( guiClearStruct,guiALL - guiDVD );
+	       guiGetEvent( guiClearStruct,(char *)(guiALL - guiDVD ) );
 	       if ( !dvd_device ) 
 	        {
 	         dvd_device=DEFAULT_DVD_DEVICE;
@@ -375,9 +378,32 @@
 
    case evIncVolume:  vo_x11_putkey( wsGrayMul ); break;
    case evDecVolume:  vo_x11_putkey( wsGrayDiv ); break;
-   case evMute:       mixer_mute(); guiIntfStruct.Mute=muted; break;
+   case evMute:       mixer_mute(); break;
+
    case evSetVolume:
-   case evSetBalance: guiIntfStruct.VolumeChanged=1; break;
+        guiIntfStruct.Volume=param;
+	goto set_volume;
+   case evSetBalance: 
+        guiIntfStruct.Balance=param;
+set_volume:
+        {
+	 float l = guiIntfStruct.Volume * ( ( 100.0 - guiIntfStruct.Balance ) / 50.0 );
+	 float r = guiIntfStruct.Volume * ( ( guiIntfStruct.Balance ) / 50.0 );
+	 if ( l > guiIntfStruct.Volume ) l=guiIntfStruct.Volume;
+	 if ( r > guiIntfStruct.Volume ) r=guiIntfStruct.Volume;
+//	 printf( "!!! v: %.2f b: %.2f -> %.2f x %.2f\n",guiIntfStruct.Volume,guiIntfStruct.Balance,l,r );
+         mixer_setvolume( l,r );
+	}
+#ifdef USE_OSD
+	if ( osd_level )
+	 {
+	  osd_visible=vo_mouse_timer_const;
+	  vo_osd_progbar_type=OSD_VOLUME;
+	  vo_osd_progbar_value=( ( guiIntfStruct.Volume ) * 256.0 ) / 100.0;
+	  vo_osd_changed( OSDTYPE_PROGBAR );
+	 }
+#endif
+        break;
 
 
    case evIconify:
@@ -426,7 +452,6 @@
    case evRedraw:
         mplMainRender=1;
         wsPostRedisplay( &appMPlayer.mainWindow );
-        XFlush( wsDisplay );
         mplRedrawTimer=mplRedrawTimerConst;
         break;
 // --- system events
@@ -499,13 +524,7 @@
             case itPotmeter:
             case itHPotmeter:
                  btnModify( item->msg,(float)( X - item->x ) / item->width * 100.0f );
-                 switch ( item->msg )
-                  {
-                   case evSetVolume:
-                        guiIntfStruct.VolumeChanged=1;
-                        guiIntfStruct.Volume=item->value;
-                        break;
-                  }
+		 mplEventHandling( item->msg,item->value );
                  value=item->value;
                  break;
            }
@@ -527,13 +546,6 @@
            {
             item->value+=value;
             btnModify( item->msg,item->value );
-            switch ( item->msg )
-             {
-              case evSetVolume:
-                   guiIntfStruct.VolumeChanged=1;
-                   guiIntfStruct.Volume=item->value;
-                   break;
-             }
             mplEventHandling( item->msg,item->value );
             mplMainRender=1;
            }
@@ -559,20 +571,12 @@
 potihandled:
                  if ( item->value > 100.0f ) item->value=100.0f;
                  if ( item->value < 0.0f ) item->value=0.0f;
-                 switch ( item->msg )
-                  {
-                   case evSetVolume:
-                        guiIntfStruct.VolumeChanged=1;
-                        guiIntfStruct.Volume=item->value;
-                        break;
-                  }
                  mplEventHandling( item->msg,item->value );
-                 mplMainRender=1; wsPostRedisplay( &appMPlayer.mainWindow );
                  break;
            }
           break;
   }
- if ( Button != wsMoveMouse ) wsPostRedisplay( &appMPlayer.mainWindow );
+// if ( Button != wsMoveMouse ) wsPostRedisplay( &appMPlayer.mainWindow );
 }
 
 int keyPressed = 0;
--- a/Gui/mplayer/sw.h	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/mplayer/sw.h	Tue Jul 02 13:35:04 2002 +0000
@@ -18,7 +18,6 @@
  if ( mplSubRender )
   {
    if ( appMPlayer.sub.Bitmap.Image ) wsPutImage( &appMPlayer.subWindow );
-//   XFlush( wsDisplay );
   }
  appMPlayer.subWindow.State=0;
 }
--- a/Gui/wm/ws.c	Tue Jul 02 13:32:08 2002 +0000
+++ b/Gui/wm/ws.c	Tue Jul 02 13:35:04 2002 +0000
@@ -699,8 +699,6 @@
  }
 }
 
-extern void mplTimerHandler( void );
-
 void wsMainLoop( void )
 {
  int delay=20;
@@ -718,7 +716,6 @@
    wsEvents( wsDisplay,&wsEvent,NULL );
    delay=0;
  }
- mplTimerHandler(); // handle timer event
  usleep(delay*1000); // FIXME!
  if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity)
 }
--- a/mplayer.c	Tue Jul 02 13:32:08 2002 +0000
+++ b/mplayer.c	Tue Jul 02 13:35:04 2002 +0000
@@ -172,6 +172,7 @@
 int use_gui=0;
 
 int osd_level=2;
+int osd_visible=100;
 
 // seek:
 char *seek_to_sec=NULL;
@@ -501,7 +502,6 @@
 int out_fmt=0;
 int eof=0;
 
-int osd_visible=100;
 int osd_function=OSD_PLAY;
 int osd_last_pts=-303;
 int osd_show_av_delay = 0;
@@ -807,8 +807,9 @@
 #ifdef HAVE_NEW_INPUT
         mp_cmd_t* cmd;                                                                                   
 #endif
-	usleep(40000);
+	usleep(20000);
 	guiEventHandling();
+	guiGetEvent( guiReDraw,NULL );
 #ifdef HAVE_NEW_INPUT
 	if ( (cmd = mp_input_get_cmd(0,0)) != NULL) guiGetEvent( guiIEvent,(char *)cmd->id );
 #endif
@@ -1392,6 +1393,7 @@
      guiGetEvent( guiSetStream,(char *)stream );
      if ( sh_audio ) guiIntfStruct.AudioType=sh_audio->channels; else guiIntfStruct.AudioType=0;
      if ( !sh_video && sh_audio ) guiGetEvent( guiSetAudioOnly,1 ); else guiGetEvent( guiSetAudioOnly,0 );
+     guiGetEvent( guiSetVolume,NULL );
     }
 #endif
 
@@ -1953,6 +1955,7 @@
 #ifdef HAVE_NEW_GUI
              if(use_gui){
 		guiEventHandling();
+		guiGetEvent( guiReDraw,NULL );
 		if(guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) break;
              }
 #endif
@@ -2905,23 +2908,9 @@
 	}
 	if ( sh_video ) guiIntfStruct.TimeSec=d_video->pts;
 	  else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->timer;
+	guiGetEvent( guiReDraw,NULL );
 	if(guiIntfStruct.Playing==0) break; // STOP
 	if(guiIntfStruct.Playing==2) osd_function=OSD_PAUSE;
-	if ( guiIntfStruct.VolumeChanged ) 
-	 {
-	  mixer_setvolume( guiIntfStruct.Volume,guiIntfStruct.Volume );
-	  guiIntfStruct.VolumeChanged=0;
-#ifdef USE_OSD
-          if ( osd_level )
-	   {
-            osd_visible=sh_video->fps; // 1 sec
-            vo_osd_progbar_type=OSD_VOLUME;
-            vo_osd_progbar_value=( ( guiIntfStruct.Volume ) * 256.0 ) / 100.0;
-	    vo_osd_changed(OSDTYPE_PROGBAR);
-           }
-#endif
-	 } 
-	guiIntfStruct.Volume=(float)mixer_getbothvolume();
         if ( guiIntfStruct.DiskChanged ) goto goto_next_file;
 #ifdef USE_DVDREAD
         if ( stream->type == STREAMTYPE_DVD )
@@ -3108,12 +3097,7 @@
   }	
 #endif
 
-if(use_gui || playtree_iter != NULL
-// once use_gui is set, this won't be reached -> useless: --A'rpi
-//#if defined( HAVE_NEW_GUI ) && defined( USE_DVDREAD )
-// || ( guiIntfStruct.DVDChanged && use_gui )
-//#endif 
-){
+if(use_gui || playtree_iter != NULL){
 
   current_module="uninit_acodec";
   if(sh_audio) uninit_audio(sh_audio);
--- a/mplayer.h	Tue Jul 02 13:32:08 2002 +0000
+++ b/mplayer.h	Tue Jul 02 13:35:04 2002 +0000
@@ -7,6 +7,9 @@
 extern int fullscreen;
 extern int vcd_track;
 
+extern int osd_level;
+extern int osd_visible;
+
 extern void exit_player(char* how);
 
 #endif