a) fix special button press handling for solo+mute buttons
[ardour.git] / gtk2_ardour / route_ui.cc
index bd9c535ecd4702558d49fd392a00f93c3762544a..8ed4bcd1c8cd537e8203781ad684131c6b98347d 100644 (file)
     $Id$
 */
 
-#include <gtkmmext/gtk_ui.h>
-#include <gtkmmext/stop_signal.h>
-#include <gtkmmext/choice.h>
-#include <gtkmmext/bindable_button.h>
-#include <gtkmmext/doi.h>
+#include <gtkmm2ext/gtk_ui.h>
+#include <gtkmm2ext/stop_signal.h>
+#include <gtkmm2ext/choice.h>
+#include <gtkmm2ext/bindable_button.h>
+#include <gtkmm2ext/doi.h>
 
 #include <ardour/route_group.h>
 
 #include <ardour/diskstream.h>
 
 #include "i18n.h"
-
-using namespace SigC;
+using namespace sigc;
 using namespace Gtk;
-using namespace Gtkmmext;
+using namespace Gtkmm2ext;
 using namespace ARDOUR;
 
 
@@ -55,6 +54,7 @@ RouteUI::RouteUI (ARDOUR::Route& rt, ARDOUR::Session& sess, const char* m_name,
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
+       remote_control_menu = 0;
        ignore_toggle = false;
        wait_for_release = false;
        route_active_menu_item = 0;
@@ -63,8 +63,8 @@ RouteUI::RouteUI (ARDOUR::Route& rt, ARDOUR::Session& sess, const char* m_name,
                set_color (unique_random_color());
        }
 
-       _route.GoingAway.connect (slot (*this, &RouteUI::route_removed));
-       _route.active_changed.connect (slot (*this, &RouteUI::route_active_changed));
+       _route.GoingAway.connect (mem_fun (*this, &RouteUI::route_removed));
+       _route.active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
 
         mute_button = manage (new BindableToggleButton (& _route.midi_mute_control(), m_name ));
        mute_button->set_bind_button_state (2, GDK_CONTROL_MASK);
@@ -74,10 +74,9 @@ RouteUI::RouteUI (ARDOUR::Route& rt, ARDOUR::Session& sess, const char* m_name,
        if (is_audio_track()) {
                AudioTrack* at = dynamic_cast<AudioTrack*>(&_route);
 
-               get_diskstream()->record_enable_changed.connect (slot (*this, &RouteUI::route_rec_enable_changed));
+               get_diskstream()->record_enable_changed.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed));
 
-               _session.RecordEnabled.connect (slot (*this, &RouteUI::session_rec_enable_changed));
-               _session.RecordDisabled.connect (slot (*this, &RouteUI::session_rec_enable_changed));
+               _session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed));
 
                rec_enable_button = manage (new BindableToggleButton (& at->midi_rec_enable_control(), r_name ));
                rec_enable_button->set_bind_button_state (2, GDK_CONTROL_MASK);
@@ -86,9 +85,9 @@ RouteUI::RouteUI (ARDOUR::Route& rt, ARDOUR::Session& sess, const char* m_name,
                rec_enable_button = manage (new BindableToggleButton (0, r_name ));
        }
        
-       mute_button->unset_flags (GTK_CAN_FOCUS);
-       solo_button->unset_flags (GTK_CAN_FOCUS);
-       rec_enable_button->unset_flags (GTK_CAN_FOCUS);
+       mute_button->unset_flags (Gtk::CAN_FOCUS);
+       solo_button->unset_flags (Gtk::CAN_FOCUS);
+       rec_enable_button->unset_flags (Gtk::CAN_FOCUS);
 
        /* map the current state */
 
@@ -158,7 +157,7 @@ RouteUI::mute_press(GdkEventButton* ev)
 
        }
 
-       return stop_signal (*mute_button, "button-press-event");
+       return true;
 }
 
 gint
@@ -170,10 +169,9 @@ RouteUI::mute_release(GdkEventButton* ev)
                        // undo the last op
                        // because the press was the last undoable thing we did
                        _session.undo (1U);
-                       stop_signal (*mute_button, "button-release-event");
                }
        }
-       return TRUE;
+       return true;
 }
 
 gint
@@ -251,24 +249,23 @@ RouteUI::solo_press(GdkEventButton* ev)
                }
        }
 
-       return stop_signal (*solo_button, "button-press-event");
+       return true;
 }
 
 gint
 RouteUI::solo_release(GdkEventButton* ev)
 {
-       if(!ignore_toggle){
-               if (wait_for_release){
+       if (!ignore_toggle) {
+               if (wait_for_release) {
                        wait_for_release = false;
                        // undo the last op
                        // because the press was the last undoable thing we did
 
                        _session.undo (1U);
-
-                       stop_signal (*solo_button, "button-release-event");
                }
        }
-       return TRUE;
+
+       return true;
 }
 
 gint
@@ -315,7 +312,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 void
 RouteUI::solo_changed(void* src)
 {
-       Gtkmmext::UI::instance()->call_slot (slot (*this, &RouteUI::update_solo_display));
+       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
 }
 
 void
@@ -341,7 +338,7 @@ RouteUI::update_solo_display ()
 void
 RouteUI::mute_changed(void* src)
 {
-       Gtkmmext::UI::instance()->call_slot (slot (*this, &RouteUI::update_mute_display));
+       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
 }
 
 void
@@ -359,13 +356,13 @@ RouteUI::update_mute_display ()
 void
 RouteUI::route_rec_enable_changed (void *src)
 {
-       Gtkmmext::UI::instance()->call_slot (slot (*this, &RouteUI::update_rec_display));
+       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
 }
 
 void
 RouteUI::session_rec_enable_changed ()
 {
-       Gtkmmext::UI::instance()->call_slot (slot (*this, &RouteUI::update_rec_display));
+       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
 }
 
 void
@@ -391,22 +388,74 @@ RouteUI::update_rec_display ()
                switch (_session.record_status ()) {
                case Session::Disabled:
                case Session::Enabled:
-                       if (rec_enable_button->get_state() != GTK_STATE_ACTIVE) {
-                               rec_enable_button->set_state (GTK_STATE_ACTIVE);
+                       if (rec_enable_button->get_state() != Gtk::STATE_ACTIVE) {
+                               rec_enable_button->set_state (Gtk::STATE_ACTIVE);
                        }
                        break;
 
                case Session::Recording:
-                       if (rec_enable_button->get_state() != GTK_STATE_SELECTED) {
-                               rec_enable_button->set_state (GTK_STATE_SELECTED);
+                       if (rec_enable_button->get_state() != Gtk::STATE_SELECTED) {
+                               rec_enable_button->set_state (Gtk::STATE_SELECTED);
                        }
                        break;
                }
 
        } else {
-               if (rec_enable_button->get_state() != GTK_STATE_NORMAL) {
-                       rec_enable_button->set_state (GTK_STATE_NORMAL);
+               if (rec_enable_button->get_state() != Gtk::STATE_NORMAL) {
+                       rec_enable_button->set_state (Gtk::STATE_NORMAL);
+               }
+       }
+}
+
+void
+RouteUI::build_remote_control_menu ()
+{
+       remote_control_menu = manage (new Menu);
+       refresh_remote_control_menu ();
+}
+
+void
+RouteUI::refresh_remote_control_menu ()
+{
+       using namespace Menu_Helpers;
+
+       RadioMenuItem::Group rc_group;
+       CheckMenuItem* rc_active;
+       uint32_t limit = _session.ntracks();
+       char buf[32];
+
+       MenuList& rc_items = remote_control_menu->items();
+       rc_items.clear ();
+
+       /* note that this menu list starts at zero, not 1, because zero
+          is a valid, if useless, ID.
+       */
+
+       limit += 4; /* leave some breathing room */
+       
+       for (uint32_t i = 0; i < limit; ++i) {
+               snprintf (buf, sizeof (buf), "%u", i);
+               rc_items.push_back (RadioMenuElem (rc_group, buf));
+               rc_active = dynamic_cast<RadioMenuItem*>(&rc_items.back());
+               if (_route.remote_control_id() == i) {
+                       rc_active = dynamic_cast<CheckMenuItem*> (&rc_items.back());
+                       rc_active->set_active ();
                }
+               rc_active->signal_activate().connect (bind (mem_fun (*this, &RouteUI::set_remote_control_id), i, rc_active));
+       }
+}
+
+void
+RouteUI::set_remote_control_id (uint32_t id, CheckMenuItem* item)
+{
+       /* this is called when the radio menu item is toggled, and so 
+          is actually invoked twice per menu selection. we only
+          care about the invocation for the item that was being
+          marked active.
+       */
+
+       if (item->get_active()) {
+               _route.set_remote_control_id (id);
        }
 }
 
@@ -422,13 +471,13 @@ RouteUI::build_solo_menu (void)
 
        check = new CheckMenuItem(_("Solo-safe"));
        check->set_active (_route.solo_safe());
-       check->toggled.connect (bind (slot (*this, &RouteUI::toggle_solo_safe), check));
-       _route.solo_safe_changed.connect(bind (slot (*this, &RouteUI::solo_safe_toggle), check));
+       check->signal_toggled().connect (bind (mem_fun (*this, &RouteUI::toggle_solo_safe), check));
+       _route.solo_safe_changed.connect(bind (mem_fun (*this, &RouteUI::solo_safe_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("MIDI Bind"), slot (*mute_button, &BindableToggleButton::midi_learn)));
+       items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
        
 }
 
@@ -444,34 +493,34 @@ RouteUI::build_mute_menu(void)
        
        check = new CheckMenuItem(_("Pre Fader"));
        init_mute_menu(PRE_FADER, check);
-       check->toggled.connect(bind (slot (*this, &RouteUI::toggle_mute_menu), PRE_FADER, check));
-       _route.pre_fader_changed.connect(bind (slot (*this, &RouteUI::pre_fader_toggle), check));
+       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), PRE_FADER, check));
+       _route.pre_fader_changed.connect(bind (mem_fun (*this, &RouteUI::pre_fader_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
        check = new CheckMenuItem(_("Post Fader"));
        init_mute_menu(POST_FADER, check);
-       check->toggled.connect(bind (slot (*this, &RouteUI::toggle_mute_menu), POST_FADER, check));
-       _route.post_fader_changed.connect(bind (slot (*this, &RouteUI::post_fader_toggle), check));
+       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), POST_FADER, check));
+       _route.post_fader_changed.connect(bind (mem_fun (*this, &RouteUI::post_fader_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
        
        check = new CheckMenuItem(_("Control Outs"));
        init_mute_menu(CONTROL_OUTS, check);
-       check->toggled.connect(bind (slot (*this, &RouteUI::toggle_mute_menu), CONTROL_OUTS, check));
-       _route.control_outs_changed.connect(bind (slot (*this, &RouteUI::control_outs_toggle), check));
+       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), CONTROL_OUTS, check));
+       _route.control_outs_changed.connect(bind (mem_fun (*this, &RouteUI::control_outs_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
        check = new CheckMenuItem(_("Main Outs"));
        init_mute_menu(MAIN_OUTS, check);
-       check->toggled.connect(bind (slot (*this, &RouteUI::toggle_mute_menu), MAIN_OUTS, check));
-       _route.main_outs_changed.connect(bind (slot (*this, &RouteUI::main_outs_toggle), check));
+       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), MAIN_OUTS, check));
+       _route.main_outs_changed.connect(bind (mem_fun (*this, &RouteUI::main_outs_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("MIDI Bind"), slot (*mute_button, &BindableToggleButton::midi_learn)));
+       items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
 }
 
 void
@@ -514,8 +563,8 @@ void
 RouteUI::reversibly_apply_route_boolean (string name, void (Route::*func)(bool, void *), bool yn, void *arg)
 {
        _session.begin_reversible_command (name);
-       _session.add_undo (bind (slot (_route, func), !yn, (void *) arg));
-       _session.add_redo (bind (slot (_route, func), yn, (void *) arg));
+       _session.add_undo (bind (mem_fun (_route, func), !yn, (void *) arg));
+       _session.add_redo (bind (mem_fun (_route, func), yn, (void *) arg));
        _session.commit_reversible_command ();
 }
 
@@ -523,8 +572,8 @@ void
 RouteUI::reversibly_apply_audio_track_boolean (string name, void (AudioTrack::*func)(bool, void *), bool yn, void *arg)
 {
        _session.begin_reversible_command (name);
-       _session.add_undo (bind (slot (*audio_track(), func), !yn, (void *) arg));
-       _session.add_redo (bind (slot (*audio_track(), func), yn, (void *) arg));
+       _session.add_undo (bind (mem_fun (*audio_track(), func), !yn, (void *) arg));
+       _session.add_redo (bind (mem_fun (*audio_track(), func), yn, (void *) arg));
        _session.commit_reversible_command ();
 }
 
@@ -565,15 +614,9 @@ bool
 RouteUI::choose_color()
 {
        bool picked;
-       GdkColor color;
-       gdouble current[4];
-
-       current[0] = _color.get_red()  / 65535.0;
-       current[1] = _color.get_green() / 65535.0;
-       current[2] = _color.get_blue() / 65535.0;
-       current[3] = 1.0;
+       Gdk::Color color;
 
-       color = Gtkmmext::UI::instance()->get_color (_("ardour: color selection"), picked, current);
+       color = Gtkmm2ext::UI::instance()->get_color (_("ardour: color selection"), picked, &_color);
 
        if (picked) {
                set_color (color);
@@ -583,14 +626,14 @@ RouteUI::choose_color()
 }
 
 void
-RouteUI::set_color (Gdk_Color c)
+RouteUI::set_color (const Gdk::Color & c)
 {
        char buf[64];
        
        _color = c;
        
        ensure_xml_node ();
-       snprintf (buf, sizeof (buf), "%d:%d:%d", c.red, c.green, c.blue);
+       snprintf (buf, sizeof (buf), "%d:%d:%d", c.get_red(), c.get_green(), c.get_blue());
        xml_node->add_property ("color", buf);
 
         _route.gui_changed ("color", (void *) 0); /* EMIT_SIGNAL */
@@ -609,7 +652,7 @@ RouteUI::ensure_xml_node ()
 }
 
 XMLNode*
-RouteUI::get_child_xml_node (string childname)
+RouteUI::get_child_xml_node (const string & childname)
 {
        XMLNode* child;
 
@@ -634,9 +677,9 @@ RouteUI::set_color_from_route ()
        if ((prop = xml_node->property ("color")) != 0) {
                int r, g, b;
                sscanf (prop->value().c_str(), "%d:%d:%d", &r, &g, &b);
-               _color.red = r;
-               _color.green = g;
-               _color.blue = b;
+               _color.set_red(r);
+               _color.set_green(g);
+               _color.set_blue(b);
                return 0;
        } 
        return 1;
@@ -649,9 +692,9 @@ RouteUI::remove_this_route ()
        string prompt;
 
        if (is_audio_track()) {
-               prompt  = compose (_("Do you really want to remove track \"%1\" ?\nYou may also lose the playlist used by this track.\n(cannot be undone)"), _route.name());
+               prompt  = string_compose (_("Do you really want to remove track \"%1\" ?\nYou may also lose the playlist used by this track.\n(cannot be undone)"), _route.name());
        } else {
-               prompt  = compose (_("Do you really want to remove bus \"%1\" ?\n(cannot be undone)"), _route.name());
+               prompt  = string_compose (_("Do you really want to remove bus \"%1\" ?\n(cannot be undone)"), _route.name());
        }
 
        choices.push_back (_("Yes, remove it."));
@@ -659,13 +702,8 @@ RouteUI::remove_this_route ()
 
        Choice prompter (prompt, choices);
 
-       prompter.chosen.connect (Gtk::Main::quit.slot());
-       prompter.show_all ();
-
-       Gtk::Main::run ();
-
-       if (prompter.get_choice() == 0) {
-               Main::idle.connect (bind (slot (&RouteUI::idle_remove_this_route), this));
+       if (prompter.run () == 0) {
+               Glib::signal_idle().connect (bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), this));
        }
 }
 
@@ -679,7 +717,7 @@ RouteUI::idle_remove_this_route (RouteUI *rui)
 void
 RouteUI::route_removed ()
 {
-       ENSURE_GUI_THREAD(slot (*this, &RouteUI::route_removed));
+       ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::route_removed));
        
        delete this;
 }
@@ -688,32 +726,29 @@ void
 RouteUI::route_rename ()
 {
        ArdourPrompter name_prompter (true);
+       string result;
        name_prompter.set_prompt (_("new name: "));
        name_prompter.set_initial_text (_route.name());
-       name_prompter.done.connect (Gtk::Main::quit.slot());
        name_prompter.show_all ();
 
-       Gtk::Main::run();
+       switch (name_prompter.run ()) {
 
-       if (name_prompter.status == Gtkmmext::Prompter::cancelled) {
-               return;
+       case Gtk::RESPONSE_ACCEPT:
+        name_prompter.get_result (result);
+        if (result.length()) {
+                       _route.set_name (result, this);
+               }       
+               break;
        }
-       
-       string result;
-       name_prompter.get_result (result);
 
-       if (result.length() == 0) {
-               return;
-       }
-
-       strip_whitespace_edges (result);
-       _route.set_name (result, this);
+       return;
+  
 }
 
 void
 RouteUI::name_changed (void *src)
 {
-       ENSURE_GUI_THREAD(bind (slot (*this, &RouteUI::name_changed), src));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::name_changed), src));
        
        name_label.set_text (_route.name());
 }
@@ -734,7 +769,7 @@ void
 RouteUI::route_active_changed ()
 {
        if (route_active_menu_item) {
-               Gtkmmext::UI::instance()->call_slot (bind (slot (*route_active_menu_item, &CheckMenuItem::set_active), _route.active()));
+               Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun (*route_active_menu_item, &CheckMenuItem::set_active), _route.active()));
        }
 }
 
@@ -750,7 +785,7 @@ RouteUI::solo_safe_toggle(void* src, Gtk::CheckMenuItem* check)
 void
 RouteUI::pre_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 {
-       ENSURE_GUI_THREAD(bind (slot (*this, &RouteUI::pre_fader_toggle), src, check));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::pre_fader_toggle), src, check));
        
        bool yn = _route.get_mute_config(PRE_FADER);
        if (check->get_active() != yn) {
@@ -761,7 +796,7 @@ RouteUI::pre_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 void
 RouteUI::post_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 {
-       ENSURE_GUI_THREAD(bind (slot (*this, &RouteUI::post_fader_toggle), src, check));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::post_fader_toggle), src, check));
        
        bool yn = _route.get_mute_config(POST_FADER);
        if (check->get_active() != yn) {
@@ -772,7 +807,7 @@ RouteUI::post_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 void
 RouteUI::control_outs_toggle(void* src, Gtk::CheckMenuItem* check)
 {
-       ENSURE_GUI_THREAD(bind (slot (*this, &RouteUI::control_outs_toggle), src, check));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::control_outs_toggle), src, check));
        
        bool yn = _route.get_mute_config(CONTROL_OUTS);
        if (check->get_active() != yn) {
@@ -783,7 +818,7 @@ RouteUI::control_outs_toggle(void* src, Gtk::CheckMenuItem* check)
 void
 RouteUI::main_outs_toggle(void* src, Gtk::CheckMenuItem* check)
 {
-       ENSURE_GUI_THREAD(bind (slot (*this, &RouteUI::main_outs_toggle), src, check));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::main_outs_toggle), src, check));
        
        bool yn = _route.get_mute_config(MAIN_OUTS);
        if (check->get_active() != yn) {
@@ -835,7 +870,7 @@ RouteUI::name() const
 void
 RouteUI::map_frozen ()
 {
-       ENSURE_GUI_THREAD (slot (*this, &RouteUI::map_frozen));
+       ENSURE_GUI_THREAD (mem_fun (*this, &RouteUI::map_frozen));
 
        AudioTrack* at = dynamic_cast<AudioTrack*>(&_route);
 
@@ -850,3 +885,4 @@ RouteUI::map_frozen ()
                }
        }
 }
+