13
0

extend ArdourKnob ToolTips

allow to set/change tooltip-prefix and set a "printer" in preparation
for properly using the Knob in Plugin UIs
This commit is contained in:
Robin Gareus 2016-07-11 03:45:13 +02:00
parent bcfe7c2daa
commit d43d220f1f
2 changed files with 22 additions and 10 deletions

View File

@ -33,6 +33,7 @@
#include "gtkmm2ext/gui_thread.h" #include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/keyboard.h" #include "gtkmm2ext/keyboard.h"
#include "ardour/automation_control.h"
#include "ardour/rc_configuration.h" // for widget prelight preference #include "ardour/rc_configuration.h" // for widget prelight preference
#include "ardour_knob.h" #include "ardour_knob.h"
@ -69,7 +70,8 @@ ArdourKnob::ArdourKnob (Element e, Flags flags)
UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler)); UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ArdourKnob::color_handler));
// watch automation :( // watch automation :(
Timers::rapid_connect (sigc::mem_fun (*this, &ArdourKnob::controllable_changed)); // TODO only use for GainAutomation
Timers::rapid_connect (sigc::bind (sigc::mem_fun (*this, &ArdourKnob::controllable_changed), false));
} }
ArdourKnob::~ArdourKnob() ArdourKnob::~ArdourKnob()
@ -460,7 +462,7 @@ ArdourKnob::set_controllable (boost::shared_ptr<Controllable> c)
binding_proxy.set_controllable (c); binding_proxy.set_controllable (c);
c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourKnob::controllable_changed, this), gui_context()); c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourKnob::controllable_changed, this, false), gui_context());
_normal = c->internal_to_interface(c->normal()); _normal = c->internal_to_interface(c->normal());
@ -468,7 +470,7 @@ ArdourKnob::set_controllable (boost::shared_ptr<Controllable> c)
} }
void void
ArdourKnob::controllable_changed () ArdourKnob::controllable_changed (bool force_update)
{ {
boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable(); boost::shared_ptr<PBD::Controllable> c = binding_proxy.get_controllable();
if (!c) return; if (!c) return;
@ -476,13 +478,19 @@ ArdourKnob::controllable_changed ()
float val = c->get_interface(); float val = c->get_interface();
val = min( max(0.0f, val), 1.0f); // clamp val = min( max(0.0f, val), 1.0f); // clamp
if (val == _val) { if (val == _val && !force_update) {
return; return;
} }
_val = val; _val = val;
if (!_tooltip_prefix.empty()) { if (!_tooltip_prefix.empty()) {
_tooltip.set_tip (_tooltip_prefix + c->get_user_string()); boost::shared_ptr<ARDOUR::AutomationControl> ac = boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (c);
if (_printer && ac) {
_tooltip.set_tip (_tooltip_prefix + _printer->value_as_string (ac));
} else {
_tooltip.set_tip (_tooltip_prefix + c->get_user_string());
}
} }
set_dirty(); set_dirty();
} }

View File

@ -25,6 +25,8 @@
#include <gtkmm/action.h> #include <gtkmm/action.h>
#include "pbd/signals.h" #include "pbd/signals.h"
#include "ardour/automatable.h"
#include "gtkmm2ext/binding_proxy.h" #include "gtkmm2ext/binding_proxy.h"
#include "gtkmm2ext/activatable.h" #include "gtkmm2ext/activatable.h"
#include "gtkmm2ext/cairo_widget.h" #include "gtkmm2ext/cairo_widget.h"
@ -74,7 +76,7 @@ public:
void add_elements (Element); void add_elements (Element);
static Element default_elements; static Element default_elements;
void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; } void set_tooltip_prefix (std::string pfx) { _tooltip_prefix = pfx; controllable_changed (true); }
boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); } boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
void set_controllable (boost::shared_ptr<PBD::Controllable> c); void set_controllable (boost::shared_ptr<PBD::Controllable> c);
@ -84,6 +86,8 @@ public:
bool on_scroll_event (GdkEventScroll* ev); bool on_scroll_event (GdkEventScroll* ev);
bool on_motion_notify_event (GdkEventMotion *ev) ; bool on_motion_notify_event (GdkEventMotion *ev) ;
void set_printer (boost::shared_ptr<ARDOUR::Automatable> p) { _printer = p; controllable_changed (true); }
void color_handler (); void color_handler ();
protected: protected:
@ -97,14 +101,14 @@ public:
bool on_focus_in_event (GdkEventFocus*); bool on_focus_in_event (GdkEventFocus*);
bool on_focus_out_event (GdkEventFocus*); bool on_focus_out_event (GdkEventFocus*);
void controllable_changed (); void controllable_changed (bool force_update = false);
PBD::ScopedConnection watch_connection; PBD::ScopedConnection watch_connection;
private: private:
Element _elements; Element _elements;
BindingProxy binding_proxy;
BindingProxy binding_proxy; boost::shared_ptr<ARDOUR::Automatable> _printer;
bool _hovering; bool _hovering;
float _grabbed_x; float _grabbed_x;