View Issue Details

IDProjectCategoryView StatusLast Update
0002608ardourbugspublic2020-04-19 20:13
Reporternickm Assigned Topaul  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionSVN/2.0-ongoing 
Summary0002608: [PATCH] fix BarController to display logarithmically scaled values correctly
DescriptionThe BarController in gtkmm2ext is used for entering values in LADSPA plugins.

Plugins such as the Triple Parametric EQ in the SWH plugins use this to control the frequency of the EQ band.

When using a plugin that specifies a logarithm hint on the port, the BarController doesn't display the value correctly when in spinner mode.

This patch fixes BarController to convert values appropriately when controlling a logarithmically scaled value.
TagsNo tags attached.

Relationships

related to 0002493 closednettings Illegal default parameters for LADSPA plugins 
related to 0002772 closedpaul Initial values for some LADSPA plugins wrong, strange behaviour when modifying it manually 
related to 0002437 closednettings Several Ladspa filter plug ins can't be set to any value. 

Activities

2009-03-31 01:57

 

2.0-ongoing-barcontroller-log.patch (4,190 bytes)   
Index: gtk2_ardour/generic_pluginui.cc
===================================================================
--- gtk2_ardour/generic_pluginui.cc	(revision 4920)
+++ gtk2_ardour/generic_pluginui.cc	(working copy)
@@ -494,6 +494,7 @@
 			control_ui->control->set_name (X_("PluginSlider"));
 			control_ui->control->set_style (BarController::LeftToRight);
 			control_ui->control->set_use_parent (true);
+			control_ui->control->set_logarithmic (control_ui->logarithmic);
 
 			control_ui->control->StartGesture.connect (bind (mem_fun(*this, &GenericPluginUI::start_touch), control_ui));
 			control_ui->control->StopGesture.connect (bind (mem_fun(*this, &GenericPluginUI::stop_touch), control_ui));
Index: libs/gtkmm2ext/gtkmm2ext/barcontroller.h
===================================================================
--- libs/gtkmm2ext/gtkmm2ext/barcontroller.h	(revision 4920)
+++ libs/gtkmm2ext/gtkmm2ext/barcontroller.h	(working copy)
@@ -50,6 +50,8 @@
 	void set_use_parent (bool yn);
 
 	void set_sensitive (bool yn);
+	
+	void set_logarithmic (bool yn) { logarithmic = yn; }
 
 	Gtk::SpinButton& get_spin_button() { return spinner; }
 
@@ -77,6 +79,7 @@
 	GdkWindow*          grab_window;
 	Gtk::SpinButton     spinner;
 	bool                use_parent;
+	bool                logarithmic;
 
 	virtual bool button_press (GdkEventButton *);
 	virtual bool button_release (GdkEventButton *);
@@ -92,6 +95,9 @@
 
 	void entry_activated ();
 	void drop_grab ();
+	
+	int entry_input (double* new_value);
+	bool entry_output ();
 };
 
 
Index: libs/gtkmm2ext/barcontroller.cc
===================================================================
--- libs/gtkmm2ext/barcontroller.cc	(revision 4920)
+++ libs/gtkmm2ext/barcontroller.cc	(working copy)
@@ -18,6 +18,7 @@
 */
 
 #include <string>
+#include <sstream>
 #include <climits>
 #include <cstdio>
 #include <cmath>
@@ -51,6 +52,7 @@
 	switch_on_release = false;
 	with_text = true;
 	use_parent = false;
+	logarithmic = false;
 
 	layout = darea.create_pango_layout("");
 
@@ -76,12 +78,72 @@
 
 	spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated));
 	spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out));
+	spinner.signal_output().connect (mem_fun (*this, &BarController::entry_output));
+	spinner.signal_input().connect (mem_fun (*this, &BarController::entry_input));
 	spinner.set_digits (3);
+	spinner.set_numeric (true);
 
 	add (darea);
 	show_all ();
 }
 
+/* 
+    This is called when we need to update the adjustment with the value
+    from the spinner's text entry.
+    
+    We need to use Gtk::Entry::get_text to avoid recursive nastiness :)
+    
+    If we're not in logarithmic mode we can return false to use the 
+    default conversion.
+    
+    In theory we should check for conversion errors but set numeric
+    mode to true on the spinner prevents invalid input.
+*/
+int
+BarController::entry_input (double* new_value)
+{
+	if (!logarithmic) {
+		return false;
+	}
+
+	// extract a double from the string and take its log
+	Entry *entry = dynamic_cast<Entry *>(&spinner);
+	stringstream stream(entry->get_text());
+
+	double value;
+	stream >> value;
+	
+	*new_value = log(value);
+	return true;
+}
+
+/* 
+    This is called when we need to update the spinner's text entry 
+    with the value of the adjustment.
+    
+    We need to use Gtk::Entry::set_text to avoid recursive nastiness :)
+    
+    If we're not in logarithmic mode we can return false to use the 
+    default conversion.
+*/
+bool
+BarController::entry_output ()
+{
+	if (!logarithmic) {
+		return false;
+	}
+
+	// generate the exponential and turn it into a string
+	stringstream stream;
+	stream.precision(spinner.get_digits());
+	stream << fixed << exp(spinner.get_adjustment()->get_value());
+	
+	Entry *entry = dynamic_cast<Entry *>(&spinner);
+	entry->set_text(stream.str());
+	
+	return true;
+}
+
 void
 BarController::drop_grab ()
 {
@@ -436,13 +498,6 @@
 void
 BarController::entry_activated ()
 {
-	string text = spinner.get_text ();
-	float val;
-
-	if (sscanf (text.c_str(), "%f", &val) == 1) {
-		adjustment.set_value (val);
-	}
-	
 	switch_to_bar ();
 }
 

seablade

2009-07-08 16:58

manager   ~0006400

Assigning to Paul to take a look at the patch. Sorry it took so long, still finding fun things like this throughout Mantis;)

nickm

2009-07-08 17:50

reporter   ~0006401

Here's an updated patch against 2.0-ongoing rev 5338

2009-07-08 17:52

 

2.0-ongoing-plugin-logarithm-5338.patch (4,451 bytes)   
Index: 2.0-ongoing-plugin-logarithm/gtk2_ardour/generic_pluginui.cc
===================================================================
--- 2.0-ongoing-plugin-logarithm/gtk2_ardour/generic_pluginui.cc	(revision 5338)
+++ 2.0-ongoing-plugin-logarithm/gtk2_ardour/generic_pluginui.cc	(working copy)
@@ -494,6 +494,7 @@
 			control_ui->control->set_name (X_("PluginSlider"));
 			control_ui->control->set_style (BarController::LeftToRight);
 			control_ui->control->set_use_parent (true);
+			control_ui->control->set_logarithmic (control_ui->logarithmic);
 
 			control_ui->control->StartGesture.connect (bind (mem_fun(*this, &GenericPluginUI::start_touch), control_ui));
 			control_ui->control->StopGesture.connect (bind (mem_fun(*this, &GenericPluginUI::stop_touch), control_ui));
Index: 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/gtkmm2ext/barcontroller.h
===================================================================
--- 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/gtkmm2ext/barcontroller.h	(revision 5338)
+++ 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/gtkmm2ext/barcontroller.h	(working copy)
@@ -50,6 +50,8 @@
 	void set_use_parent (bool yn);
 
 	void set_sensitive (bool yn);
+	
+	void set_logarithmic (bool yn) { logarithmic = yn; }
 
 	Gtk::SpinButton& get_spin_button() { return spinner; }
 
@@ -77,6 +79,7 @@
 	GdkWindow*          grab_window;
 	Gtk::SpinButton     spinner;
 	bool                use_parent;
+	bool                logarithmic;
 
 	virtual bool button_press (GdkEventButton *);
 	virtual bool button_release (GdkEventButton *);
@@ -92,6 +95,9 @@
 
 	void entry_activated ();
 	void drop_grab ();
+	
+	int entry_input (double* new_value);
+	bool entry_output ();
 };
 
 
Index: 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/barcontroller.cc
===================================================================
--- 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/barcontroller.cc	(revision 5338)
+++ 2.0-ongoing-plugin-logarithm/libs/gtkmm2ext/barcontroller.cc	(working copy)
@@ -18,6 +18,7 @@
 */
 
 #include <string>
+#include <sstream>
 #include <climits>
 #include <cstdio>
 #include <cmath>
@@ -51,6 +52,7 @@
 	switch_on_release = false;
 	with_text = true;
 	use_parent = false;
+	logarithmic = false;
 
 	layout = darea.create_pango_layout("");
 
@@ -76,12 +78,72 @@
 
 	spinner.signal_activate().connect (mem_fun (*this, &BarController::entry_activated));
 	spinner.signal_focus_out_event().connect (mem_fun (*this, &BarController::entry_focus_out));
+	spinner.signal_output().connect (mem_fun (*this, &BarController::entry_output));
+	spinner.signal_input().connect (mem_fun (*this, &BarController::entry_input));
 	spinner.set_digits (3);
+	spinner.set_numeric (true);
 
 	add (darea);
 	show_all ();
 }
 
+/* 
+    This is called when we need to update the adjustment with the value
+    from the spinner's text entry.
+    
+    We need to use Gtk::Entry::get_text to avoid recursive nastiness :)
+    
+    If we're not in logarithmic mode we can return false to use the 
+    default conversion.
+    
+    In theory we should check for conversion errors but set numeric
+    mode to true on the spinner prevents invalid input.
+*/
+int
+BarController::entry_input (double* new_value)
+{
+	if (!logarithmic) {
+		return false;
+	}
+
+	// extract a double from the string and take its log
+	Entry *entry = dynamic_cast<Entry *>(&spinner);
+	stringstream stream(entry->get_text());
+
+	double value;
+	stream >> value;
+	
+	*new_value = log(value);
+	return true;
+}
+
+/* 
+    This is called when we need to update the spinner's text entry 
+    with the value of the adjustment.
+    
+    We need to use Gtk::Entry::set_text to avoid recursive nastiness :)
+    
+    If we're not in logarithmic mode we can return false to use the 
+    default conversion.
+*/
+bool
+BarController::entry_output ()
+{
+	if (!logarithmic) {
+		return false;
+	}
+
+	// generate the exponential and turn it into a string
+	stringstream stream;
+	stream.precision(spinner.get_digits());
+	stream << fixed << exp(spinner.get_adjustment()->get_value());
+	
+	Entry *entry = dynamic_cast<Entry *>(&spinner);
+	entry->set_text(stream.str());
+	
+	return true;
+}
+
 void
 BarController::drop_grab ()
 {
@@ -436,13 +498,6 @@
 void
 BarController::entry_activated ()
 {
-	string text = spinner.get_text ();
-	float val;
-
-	if (sscanf (text.c_str(), "%f", &val) == 1) {
-		adjustment.set_value (val);
-	}
-	
 	switch_to_bar ();
 }
 

nickm

2009-07-08 17:55

reporter   ~0006402

By the way, I've been marking all my patches with "[PATCH]" so if you search for that you'll see them. There are a couple of other ones that haven't been looked at yet...

seablade

2009-07-08 18:47

manager   ~0006406

Yea I noticed, and in fact I am hoping later today when I am sitting around at work waiting for things to break I can go through and search for all the old patches that I missed in Mantis to assign as needed.

      Seablade

robsch

2009-07-23 18:32

reporter   ~0006461

I just tried the patch on rev. 5403. It does NOT solve the problems described in 0002437 and 0002772.

seablade

2009-07-23 18:37

manager   ~0006462

Hmm need to double check, but I believe if you applied the patch to 5403, you may have applied it twice. I _think_ this patch was committed in 5374. Let me check on this though.

    Seablade

nickm

2009-07-23 18:42

reporter   ~0006463

Based on the release announcement, this patch was included in 2.8.2.

I had a brief look at those two bugs and I don't think they are related to this bug at all. This patch deals with data entry + display for ports that have the logarithm hint set, eg the frequency control in SWH's triple band eq plugin.

There are certainly other little niggles present in ardour's LADSPA UI...

seablade

2009-07-23 18:51

manager   ~0006464

Resolving this particular issue out as the patch has been applied. I will take a closer look at the other issues, but for now they remain open.

     Seablade

system

2020-04-19 20:13

developer   ~0021887

Issue has been closed automatically, by Trigger Close Plugin.
Feel free to re-open with additional information if you think the issue is not resolved.

Issue History

Date Modified Username Field Change
2009-03-31 01:57 nickm New Issue
2009-03-31 01:57 nickm File Added: 2.0-ongoing-barcontroller-log.patch
2009-07-08 16:58 seablade Note Added: 0006400
2009-07-08 16:58 seablade Status new => acknowledged
2009-07-08 16:58 seablade Status acknowledged => assigned
2009-07-08 16:58 seablade Assigned To => paul
2009-07-08 17:00 seablade Relationship added related to 0002493
2009-07-08 17:00 seablade Relationship added related to 0002772
2009-07-08 17:02 seablade Relationship added related to 0002437
2009-07-08 17:50 nickm Note Added: 0006401
2009-07-08 17:52 nickm File Added: 2.0-ongoing-plugin-logarithm-5338.patch
2009-07-08 17:55 nickm Note Added: 0006402
2009-07-08 18:47 seablade Note Added: 0006406
2009-07-23 18:32 robsch Note Added: 0006461
2009-07-23 18:37 seablade Note Added: 0006462
2009-07-23 18:42 nickm Note Added: 0006463
2009-07-23 18:51 seablade cost => 0.00
2009-07-23 18:51 seablade Note Added: 0006464
2009-07-23 18:51 seablade Status assigned => resolved
2009-07-23 18:51 seablade Resolution open => fixed
2010-04-24 10:28 cth103 Category bugs => bugs2
2010-04-24 10:31 cth103 Category bugs2 => bugs
2020-04-19 20:13 system Note Added: 0021887
2020-04-19 20:13 system Status resolved => closed