[vlc-commits] skins2: add $R to display current playback speed

Erwan Tulou git at videolan.org
Thu Feb 23 14:15:44 CET 2012


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Oct  4 00:14:52 2011 +0200| [5c277fc5b8565308e70b88032d7a843c6df19fac] | committer: Erwan Tulou

skins2: add $R to display current playback speed

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5c277fc5b8565308e70b88032d7a843c6df19fac
---

 modules/gui/skins2/src/vlcproc.cpp    |   27 +++++++++++++++++++++------
 modules/gui/skins2/src/vlcproc.hpp    |    6 ++++++
 modules/gui/skins2/utils/var_text.cpp |    9 +++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index 37fb708..8e8f5f9 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -75,6 +75,11 @@ void VlcProc::destroy( intf_thread_t *pIntf )
     pIntf->p_sys->p_vlcProc = NULL;
 }
 
+#define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
+#define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
+#define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
+#define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
+#define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
 
 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     m_varEqBands( pIntf ), m_pVout( NULL ), m_pAout( NULL ),
@@ -125,6 +130,9 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
 
 #undef REGISTER_VAR
+    m_cVarSpeed = VariablePtr( new VarText( getIntf(), false ) );
+    pVarManager->registerVar( m_cVarSpeed, "speed" );
+    SET_TEXT( m_cVarSpeed, UString( getIntf(), "1") );
     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
     pVarManager->registerVar( m_cVarStreamName, "streamName" );
     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
@@ -440,6 +448,7 @@ int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
         {
             case INPUT_EVENT_STATE:
             case INPUT_EVENT_POSITION:
+            case INPUT_EVENT_RATE:
             case INPUT_EVENT_ES:
             case INPUT_EVENT_CHAPTER:
             case INPUT_EVENT_RECORD:
@@ -468,12 +477,6 @@ int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
 }
 
 
-#define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
-#define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
-#define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
-#define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
-#define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
-
 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
 {
     (void)p_obj;
@@ -534,6 +537,18 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
             break;
         }
 
+        case INPUT_EVENT_RATE:
+        {
+            float rate = var_GetFloat( pInput, "rate" );
+            char* buffer;
+            if( asprintf( &buffer, "%.3g", rate ) != -1 )
+            {
+                SET_TEXT( m_cVarSpeed, UString( getIntf(), buffer ) );
+                free( buffer );
+            }
+            break;
+        }
+
         case INPUT_EVENT_ES:
         {
             // Do we have audio
diff --git a/modules/gui/skins2/src/vlcproc.hpp b/modules/gui/skins2/src/vlcproc.hpp
index b004c0b..72e9a14 100644
--- a/modules/gui/skins2/src/vlcproc.hpp
+++ b/modules/gui/skins2/src/vlcproc.hpp
@@ -65,6 +65,10 @@ public:
     /// Getter for the volume variable
     Volume &getVolumeVar() { return *((Volume*)(m_cVarVolume.get())); }
 
+    /// Getter for the current playback speed
+    VarText &getSpeedVar()
+       { return *((VarText*)(m_cVarSpeed.get())); }
+
     /// Getter for the stream name variable
     VarText &getStreamNameVar()
        { return *((VarText*)(m_cVarStreamName.get())); }
@@ -129,6 +133,8 @@ private:
     VariablePtr m_cVarTime;
     /// Variable for audio volume
     VariablePtr m_cVarVolume;
+    /// Variable for speed playback
+    VariablePtr m_cVarSpeed;
     /// Variable for current stream properties
     VariablePtr m_cVarStreamName;
     VariablePtr m_cVarStreamURI;
diff --git a/modules/gui/skins2/utils/var_text.cpp b/modules/gui/skins2/utils/var_text.cpp
index 18ff625..ccce193 100644
--- a/modules/gui/skins2/utils/var_text.cpp
+++ b/modules/gui/skins2/utils/var_text.cpp
@@ -123,6 +123,10 @@ const UString VarText::get() const
     {
         temp.replace( pos, 2, pVlcProc->getStreamSampleRateVar().get() );
     }
+    while( (pos = temp.find( "$R" )) != UString::npos )
+    {
+        temp.replace( pos, 2, pVlcProc->getSpeedVar().get() );
+    }
 
     return temp;
 }
@@ -180,6 +184,10 @@ void VarText::set( const UString &rText )
         {
             pVlcProc->getStreamSampleRateVar().addObserver( this );
         }
+        if( m_text.find( "$R" ) != UString::npos )
+        {
+            pVlcProc->getSpeedVar().addObserver( this );
+        }
     }
 
     notify();
@@ -223,6 +231,7 @@ void VarText::delObservers()
     {
         pVlcProc->getTimeVar().delObserver( this );
         pVlcProc->getVolumeVar().delObserver( this );
+        pVlcProc->getSpeedVar().delObserver( this );
         pVlcProc->getStreamNameVar().delObserver( this );
         pVlcProc->getStreamURIVar().delObserver( this );
         pVlcProc->getStreamBitRateVar().delObserver( this );



More information about the vlc-commits mailing list