[jokosher-devel] [PATCH] Added volume sliders to instrument viewer



PATCH: Developed against SVN revision 1512.
Affects: trunk/Jokosher/InstrumentViewer.py and trunk/Jokosher/MixerStrip.py

Hello again!

This one is just a small accessibility patch - it kinda annoyed me the way the only obvious way of changing a track's volume was by opening the mixer view. This patch adds volume sliders to each track in the project. Those of you who've used something like Sony Sound Acid should be familiar with this - although this version works via a volume percentage (as it does in the mixer view), whilst Sound Acid uses decibels.

One thing I couldn't figure out: When changing the volume, the text to the right of the slider changes to reflect the new value. When you go into 3 digit figures, the text shifts to the right a little, and becomes very slightly obscured. I couldn't figure out how to stop this from happening - is it a GTK bug or something? A similar thing happens when opening the mixer view while you have a few tracks present. It just looks a bit messy - not a massive problem for now anyway :P

This patch works well - and I even made sure that altering the volume via the slider would be reflected in the mixer view and vice-versa (try it out with the mixer view opened to see what I mean). Aren't I nice!

Peace,
Tom
Index: Jokosher/InstrumentViewer.py
===================================================================
--- Jokosher/InstrumentViewer.py	(revision 1512)
+++ Jokosher/InstrumentViewer.py	(working copy)
@@ -120,6 +120,43 @@
 		self.labelbox.pack_start(self.image, False)
 		self.labelbox.pack_end(self.labeleventbox)
 		self.headerBox.pack_start(self.labelbox)
+		
+		#Create an instrument volume slider so user doesn't have to go through mixer every time
+		self.volumeHBox = 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.volumeHBox.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.volumeHBox.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.volumeHBox.pack_start(self.volumeLabel, False)
+		
+		self.headerBox.pack_start(self.volumeHBox, False)
+		
+		#Create the controls box
 		self.controlsBox = ControlsBox.ControlsBox(project,mainview,instrument,includeEffects=True)
 		self.headerBox.pack_start(self.controlsBox, False)
 		
@@ -495,6 +532,40 @@
 		AddInstrumentDialog.AddInstrumentDialog(self.project, self.mainview, self.instrument)
 		    
 	#______________________________________________________________________
+	
+	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)
+		for strip in self.mainview.workspace.mixView.mixerStripList:
+			if strip.instrument == self.instrument:
+				strip.vu.queue_draw()
+		
+		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 ChangeSize(self, small):
 		"""
Index: Jokosher/MixerStrip.py
===================================================================
--- Jokosher/MixerStrip.py	(revision 1512)
+++ Jokosher/MixerStrip.py	(working copy)
@@ -205,6 +205,9 @@
 			vol -- volume value to set this Instrument's volume to.
 		"""
 		self.instrument.SetVolume(vol)
+		for viewer in self.mainview.workspace.recordingView.views:
+			if viewer[1].instrument == self.instrument:
+				viewer[1].volumeSlider.set_value(vol)
 		
 	#_____________________________________________________________________
 	


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]