MIDI/Controllables for monitor section, and related fixes
[ardour.git] / gtk2_ardour / utils.cc
index 9aba168ef1cdc35a6824470480def27857190de9..aa57a3b773cb87a60f3ab79fd6a9542958477e93 100644 (file)
@@ -47,6 +47,7 @@
 #include "i18n.h"
 #include "rgb_macros.h"
 #include "canvas_impl.h"
+#include "gui_thread.h"
 
 using namespace std;
 using namespace Gtk;
@@ -519,6 +520,12 @@ relay_key_press (GdkEventKey* ev, Gtk::Window* win)
        }
 }
 
+bool
+forward_key_press (GdkEventKey* ev)
+{
+        return PublicEditor::instance().on_key_press_event(ev);
+}
+
 bool
 key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev)
 {
@@ -1016,3 +1023,59 @@ pixbuf_from_ustring(const ustring& name, Pango::FontDescription* font, int clip_
 
        return buf;
 }
+
+/** Replace _ with __ in a string; for use with menu item text to make underscores displayed correctly */
+string
+escape_underscores (string const & s)
+{
+       string o;
+       string::size_type const N = s.length ();
+
+       for (string::size_type i = 0; i < N; ++i) {
+               if (s[i] == '_') {
+                       o += "__";
+               } else {
+                       o += s[i];
+               }
+       }
+
+       return o;
+}
+
+static void
+adjustment_to_controllable (Gtk::Adjustment* adj, boost::weak_ptr<Controllable> wcont)
+{
+        boost::shared_ptr<Controllable> cont = wcont.lock();
+
+        if (cont) {
+                double val = adj->get_value();
+                if (val != cont->get_value()) {
+                        cont->set_value (val);
+                }
+        }
+}
+
+static void
+controllable_to_adjustment (Gtk::Adjustment* adj, boost::weak_ptr<Controllable> wcont)
+{
+        boost::shared_ptr<Controllable> cont = wcont.lock();
+
+        if (cont) {
+                float val = cont->get_value();
+                
+                if (val != adj->get_value()) {
+                        adj->set_value (val);
+                }
+        }
+}
+
+void
+control_link (ScopedConnectionList& scl, boost::shared_ptr<Controllable> c, Gtk::Adjustment& a)
+{
+        boost::weak_ptr<Controllable> wc (c);
+
+        a.signal_value_changed().connect (sigc::bind (sigc::ptr_fun (adjustment_to_controllable), &a, wc));
+        c->Changed.connect (scl, MISSING_INVALIDATOR, boost::bind (controllable_to_adjustment, &a, wc),
+                            gui_context());
+}
+