Coded against SVN Revision 1519

Updated version of the instrument volume slider patch. The volume slider is
now part of the ControlsBox. When creating the controls box, you should add
a 'includeVolumeSlider=True' to the parameters. For example, the code used
in InstrumentViewer.py is:

self.controlsBox =
> ControlsBox.ControlsBox(project,mainview,instrument,includeEffects=True,includeVolumeSlider=True)
>

This means the volume slider is an optional control (for example, the mixer
strip omits the volume slider for obvious reasons).

Peace,
Tom
Index: Jokosher/InstrumentViewer.py
===================================================================
--- Jokosher/InstrumentViewer.py        (revision 1519)
+++ Jokosher/InstrumentViewer.py        (working copy)
@@ -120,7 +120,7 @@
                self.labelbox.pack_start(self.image, False)
                self.labelbox.pack_end(self.labeleventbox)
                self.headerBox.pack_start(self.labelbox)
-               self.controlsBox = 
ControlsBox.ControlsBox(project,mainview,instrument,includeEffects=True)
+               self.controlsBox = 
ControlsBox.ControlsBox(project,mainview,instrument,includeEffects=True,includeVolumeSlider=True)
                self.headerBox.pack_start(self.controlsBox, False)
                
                self.separator = gtk.HSeparator()
@@ -513,6 +513,7 @@
                else:
                        self.image.set_from_pixbuf(self.instrument.pixbuf)
                        self.controlsBox.show()
+                       self.controlsBox.UpdateSlider()
                        self.separator.hide()
 
        #____________________________________________________________________   
Index: Jokosher/ControlsBox.py
===================================================================
--- Jokosher/ControlsBox.py     (revision 1519)
+++ Jokosher/ControlsBox.py     (working copy)
@@ -20,9 +20,9 @@
 
 #=========================================================================
 
-class ControlsBox(gtk.HBox):
+class ControlsBox(gtk.VBox):
 
-       def __init__(self, project, mainview, instrument, includeEffects=True):
+       def __init__(self, project, mainview, instrument, includeEffects=True, 
includeVolumeSlider=False):
                gtk.Container.__init__(self)
                """
                Creates a new instance of ControlsBox.
@@ -68,9 +68,13 @@
                self.soloTip.set_tip(self.soloButton, self.soloTipDisabled, 
None)
                self.soloButton.connect("toggled", self.OnSolo)
                
-               self.add(self.recButton)
-               self.add(self.muteButton)
-               self.add(self.soloButton)
+               self.mainControls = gtk.HBox()
+               
+               self.mainControls.add(self.recButton)
+               self.mainControls.add(self.muteButton)
+               self.mainControls.add(self.soloButton)
+               
+               self.pack_start(self.mainControls, False)
 
                if includeEffects:
                        self.propsButton = gtk.Button()
@@ -82,15 +86,52 @@
                        self.propsButton.connect("clicked", 
self.OnEffectsButtonClicked)
                        self.propsTip = gtk.Tooltips()
                        self.propsTip.set_tip(self.propsButton, _("Instrument 
Effects"), None)
-                       self.add(self.propsButton)
+                       self.mainControls.add(self.propsButton)
                
                self.instrument.connect("solo", self.OnInstrumentSolo)
                self.instrument.connect("arm", self.OnInstrumentArm)
                self.instrument.connect("mute", self.OnInstrumentMute)
                
+               if includeVolumeSlider:
+                       self.volumeControl = gtk.HBox(False, 2)
+               
+                       self.volumeTextLabel = gtk.Label("Vol:")
+                       self.volumeTextLabel.set_width_chars(4)
+                       self.volumeTextLabel.set_max_width_chars(4)
+                       self.volumeTextLabel.set_single_line_mode(True)
+                       self.volumeControl.pack_start(self.volumeTextLabel, 
False)
+               
+                       self.volumeSlider = gtk.HScale()
+                       self.volumeSlider.set_range(0.0, 2.0)
+                       self.volumeSlider.set_increments(0.01, 0.1)
+                       self.volumeSlider.set_draw_value(False)
+                       self.volTip = gtk.Tooltips()
+                       self.volTip.set_tip(self.volumeSlider, _("Adjust 
instrument volume. Right-click to center."), None)
+               
+                       if self.instrument.volume:
+                               
self.volumeSlider.set_value(self.instrument.volume)
+                       
+                       self.volumeSlider.connect("value-changed", 
self.OnVolumeSliderAdjust)
+                       self.volumeSlider.connect("button-press-event", 
self.OnVolumeSliderClick)
+                       self.volumeControl.pack_start(self.volumeSlider, True)
+       
+                       pcValue = int((self.volumeSlider.get_value() / 1.0) * 
100)
+                       volLabel = "%i%%" % (pcValue)
+       
+                       self.volumeLabel = gtk.Label(volLabel)
+                       self.volumeLabel.set_width_chars(4)
+                       self.volumeLabel.set_max_width_chars(4)
+                       self.volumeLabel.set_single_line_mode(True)
+                       self.volumeLabel.set_alignment(1.0, 0.0)
+                       self.volumeControl.pack_start(self.volumeLabel, False)
+                       
+                       self.pack_start(self.volumeControl, False)
+               
                #initialize the images on the buttons
                for i in (self.OnInstrumentArm, self.OnInstrumentMute, 
self.OnInstrumentSolo):
                        i(self.instrument)
+                       
+                       
 
        #_____________________________________________________________________
 
@@ -232,4 +273,46 @@
                self.effectsDialog = None
                
        #______________________________________________________________________
+       
+       def OnVolumeSliderAdjust(self, slider):
+               """Called when the volume slider is adjusted
+               
+               Parameters:
+                       widget -- reserved for GTK callbacks, don't use it 
explicitly.
+                       event -- reserved for GTK callbacks, don't use it 
explicitly.
+               """
+               
+               value = slider.get_value()
+               self.instrument.SetVolume(value)                
+               pcValue = int((self.volumeSlider.get_value() / 1.0) * 100)
+               volLabel = "%i%%" % (pcValue)
+               self.volumeLabel.set_text(volLabel)
+               
+               
+       #______________________________________________________________________ 
+       
+       def OnVolumeSliderClick(self, slider, mouse):
+               """Called when the volume slider is clicked / button pressed
+               
+               Parameters:
+                       widget -- reserved for GTK callbacks, don't use it 
explicitly.
+                       event -- reserved for GTK callbacks, don't use it 
explicitly.
+               """
+               if mouse.button == 3:
+                       slider.set_value(1.0)
+                       return True
+               
+       #______________________________________________________________________ 
+       
+       def UpdateSlider(self):
+               """Updates the slider when the ControlsBox is shown again.
+               This is only ever called from InstrumentViewer.ChangeSize
+               
+               Parameters:
+                       widget -- reserved for GTK callbacks, don't use it 
explicitly
+               """
+               
+               self.volumeSlider.set_value(self.instrument.volume)
+               
+       #______________________________________________________________________
 #=========================================================================
_______________________________________________
jokosher-devel-list mailing list
jokosher-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/jokosher-devel-list

Reply via email to