Implement Volume control
authorRafaël Carré <funman@videolan.org>
Tue, 21 Nov 2006 12:06:37 +0000 (12:06 +0000)
committerRafaël Carré <funman@videolan.org>
Tue, 21 Nov 2006 12:06:37 +0000 (12:06 +0000)
extras/dbus-vlc.glade
extras/dbus-vlc.py
modules/control/dbus.c
modules/control/dbus.h

index b0beeda..1f1ea20 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.0.2 on Mon Nov 20 00:07:47 2006 by fun@zod-->
+<!--Generated with glade3 3.0.2 on Tue Nov 21 12:55:24 2006 by fun@zod-->
 <glade-interface>
   <widget class="GtkWindow" id="window1">
     <property name="resizable">False</property>
         <child>
           <widget class="GtkExpander" id="expander2">
             <property name="visible">True</property>
+            <property name="expanded">True</property>
             <property name="tooltip" translatable="yes">Show more options</property>
             <child>
               <widget class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
+                <child>
+                  <widget class="GtkHBox" id="hbox2">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkHScale" id="times">
+                        <property name="width_request">107</property>
+                        <property name="height_request">20</property>
+                        <property name="visible">True</property>
+                        <property name="adjustment">0 0 100 1 10 10</property>
+                        <property name="digits">-1</property>
+                        <property name="draw_value">False</property>
+                        <property name="value_pos">GTK_POS_RIGHT</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkLabel" id="timel">
+                        <property name="width_request">30</property>
+                        <property name="height_request">20</property>
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">time</property>
+                      </widget>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkSpinButton" id="vol">
+                        <property name="width_request">42</property>
+                        <property name="height_request">20</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="adjustment">100 0 100 1 10 10</property>
+                        <property name="snap_to_ticks">True</property>
+                        <property name="numeric">True</property>
+                        <property name="wrap">True</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </widget>
+                </child>
                 <child>
                   <widget class="GtkHBox" id="hbox4">
                     <property name="visible">True</property>
                       </packing>
                     </child>
                   </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
                 </child>
                 <child>
                   <widget class="GtkHBox" id="hbox3">
                     </child>
                   </widget>
                   <packing>
-                    <property name="position">1</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
               </widget>
index d9f8cb4..23f8f24 100755 (executable)
@@ -63,6 +63,7 @@ def Stop(widget):
 
 def update(widget):
     itemchange_handler(str(interface.GetPlayingItem()))
+    vol.set_value(interface.VolumeGet())
     GetPlayStatus(0)
 
 def GetPlayStatus(widget):
@@ -83,8 +84,11 @@ def TogglePause(widget):
         img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR)
     update(0)
 
+def volchange(widget):
+    interface.VolumeSet(vol.get_value_as_int())
+
 def expander(widget):
-    if exp.get_label() == "More":
+    if exp.get_expanded() == False:
         exp.set_label("Less")
     else:
         exp.set_label("More")
@@ -133,7 +137,7 @@ expvbox     = xml.get_widget('expandvbox')
 menu        = xml.get_widget('menu1')
 menuitem    = xml.get_widget('menuquit')
 vlcicon     = xml.get_widget('eventicon')
-
+vol         = xml.get_widget('vol')
 
 window.connect('delete_event',  delete_event)
 window.connect('destroy',       destroy)
@@ -168,6 +172,7 @@ exp.connect('activate',         expander)
 menuitem.connect('activate',    destroy)
 vlcicon.set_events(gtk.gdk.BUTTON_PRESS_MASK)
 vlcicon.connect('button_press_event', icon_clicked)
+vol.connect('value-changed',    volchange)
 
 library = "/media/mp3"
 
index 2e31aa0..c1b7cfe 100644 (file)
@@ -55,6 +55,7 @@
 #include "dbus.h"
 
 #include <vlc/vlc.h>
+#include <vlc/aout.h>
 #include <vlc/intf.h>
 #include <vlc_meta.h>
 #include <vlc_input.h>
@@ -109,6 +110,44 @@ DBUS_METHOD( Quit )
     REPLY_SEND;
 }
 
+DBUS_METHOD( VolumeGet )
+{ /* get volume in percentage */
+    REPLY_INIT;
+    OUT_ARGUMENTS;
+    dbus_uint16_t i_vol;
+    /* 2nd argument of aout_VolumeGet is uint16 */
+    aout_VolumeGet( (vlc_object_t*) p_this, &i_vol );
+    i_vol = ( 100 * i_vol ) / AOUT_VOLUME_MAX;
+    ADD_UINT16( &i_vol );
+    REPLY_SEND;
+}
+
+DBUS_METHOD( VolumeSet )
+{ /* set volume in percentage */
+    REPLY_INIT;
+
+    DBusError error;
+    dbus_error_init( &error );
+
+    dbus_uint16_t i_vol;
+
+    dbus_message_get_args( p_from, &error,
+            DBUS_TYPE_UINT16, &i_vol,
+            DBUS_TYPE_INVALID );
+
+    if( dbus_error_is_set( &error ) )
+    {
+        msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
+                error.message );
+        dbus_error_free( &error );
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    aout_VolumeSet( (vlc_object_t*) p_this, ( AOUT_VOLUME_MAX / 100 ) * i_vol );
+
+    REPLY_SEND;
+}
+
 DBUS_METHOD( Next )
 { /* next playlist item */
     REPLY_INIT;
@@ -291,6 +330,8 @@ DBUS_METHOD( handle_messages )
     METHOD_FUNC( "Next",            Next );
     METHOD_FUNC( "Quit",            Quit );
     METHOD_FUNC( "Stop",            Stop );
+    METHOD_FUNC( "VolumeSet",       VolumeSet );
+    METHOD_FUNC( "VolumeGet",       VolumeGet );
 
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
index 7f62970..581448f 100644 (file)
@@ -67,6 +67,7 @@
 #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
 #define ADD_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i )
+#define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, i )
 
 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
 
@@ -103,6 +104,12 @@ const char* psz_introspection_xml_data =
 "    </method>\n"
 "    <method name=\"Stop\">\n"
 "    </method>\n"
+"    <method name=\"VolumeSet\">\n"
+"      <arg type=\"q\" direction=\"in\" />\n"
+"    </method>\n"
+"    <method name=\"VolumeGet\">\n"
+"      <arg type=\"q\" direction=\"out\" />\n"
+"    </method>\n"
 "  </interface>\n"
 "</node>\n"
 ;