test another fix for solo-press-crashes
[ardour.git] / gtk2_ardour / route_ui.cc
index 4be9fb61a9617a11887a7571416a6cfe81cc6e25..842e06953ece8780731c02d64419cbadb484e1af 100644 (file)
@@ -47,13 +47,24 @@ using namespace Gtkmm2ext;
 using namespace ARDOUR;
 using namespace PBD;
 
-RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, const char* m_name,
-                 const char* s_name, const char* r_name)
-       : AxisView(sess),
-         _route(rt),
-         mute_button(0),
-         solo_button(0),
-         rec_enable_button(0)
+RouteUI::RouteUI (ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+       : AxisView(sess)
+{
+       init ();
+       set_button_names (mute_name, solo_name, rec_name);
+}
+
+RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, 
+                 ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+       : AxisView(sess)
+{
+       init ();
+       set_button_names (mute_name, solo_name, rec_name);
+       set_route (rt);
+}
+
+void
+RouteUI::init ()
 {
        xml_node = 0;
        mute_menu = 0;
@@ -63,50 +74,109 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
        wait_for_release = false;
        route_active_menu_item = 0;
        was_solo_safe = false;
+       polarity_menu_item = 0;
+       denormal_menu_item = 0;
 
-       if (set_color_from_route()) {
-               set_color (unique_random_color());
+       mute_button = manage (new BindableToggleButton (0, ""));
+       mute_button->set_self_managed (true);
+       mute_button->set_name ("MuteButton");
+
+       solo_button = manage (new BindableToggleButton (0, ""));
+       solo_button->set_self_managed (true);
+       solo_button->set_name ("SoloButton");
+
+       rec_enable_button = manage (new BindableToggleButton (0, ""));
+       rec_enable_button->set_name ("RecordEnableButton");
+       rec_enable_button->set_self_managed (true);
+
+       _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
+}
+
+void
+RouteUI::reset ()
+{
+       connections.clear ();
+
+       if (solo_menu) {
+               delete solo_menu;
+               solo_menu = 0;
        }
 
-       new PairedShiva<Route,RouteUI> (*_route, *this);
+       if (mute_menu) {
+               delete mute_menu;
+               mute_menu = 0;
+       }
+       
+       if (remote_control_menu) {
+               delete remote_control_menu;
+               remote_control_menu = 0;
+       }
 
-       _route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
+       if (xml_node) {
+               /* do not delete the node - its owned by the route */
+               xml_node = 0;
+       }
 
-        mute_button = manage (new BindableToggleButton (_route->mute_control(), m_name ));
-       mute_button->set_self_managed (true);
+       route_active_menu_item = 0;
+       polarity_menu_item = 0;
+       denormal_menu_item = 0;
+}
 
-        solo_button = manage (new BindableToggleButton (_route->solo_control(), s_name ));
-       solo_button->set_self_managed (true);
+void
+RouteUI::set_button_names (const char* mute, const char* solo, const char* rec)
+{
+       m_name = mute;
+       s_name = solo;
+       r_name = rec;
+}
 
-       mute_button->set_name ("MuteButton");
-       solo_button->set_name ("SoloButton");
+void
+RouteUI::set_route (boost::shared_ptr<Route> rp)
+{
+       reset ();
 
-       _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
-       _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
-       _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
+       _route = rp;
 
-       /* when solo changes, update mute state too, in case the user wants us to display it */
+       if (set_color_from_route()) {
+               set_color (unique_random_color());
+       }
 
-       _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
+       /* no, there is no memory leak here. This object cleans itself (and other stuff)
+          up when the route is destroyed.
+       */
+
+       new PairedShiva<Route,RouteUI> (*_route, *this);
+
+       mute_button->set_controllable (&_route->mute_control());
+       mute_button->set_label (m_name);
        
+       solo_button->set_controllable (&_route->solo_control());
+       solo_button->set_label (s_name);
+
+       connections.push_back (_route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed)));
+       connections.push_back (_route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed)));
+       connections.push_back (_route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
+       connections.push_back (_route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
+
+       /* when solo changes, update mute state too, in case the user wants us to display it */
+
        update_solo_display ();
        update_mute_display ();
 
        if (is_track()) {
                boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
 
-               t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed));
+               connections.push_back (t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed)));
 
-               _session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed));
+               connections.push_back (_session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed)));
 
-               rec_enable_button = manage (new BindableToggleButton (t->rec_enable_control(), r_name ));
-               rec_enable_button->set_name ("RecordEnableButton");
-               rec_enable_button->set_self_managed (true);
+               rec_enable_button->set_controllable (&t->rec_enable_control());
+               rec_enable_button->set_label (r_name);
 
                update_rec_display ();
        } 
        
-       _route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu));
+       connections.push_back (_route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu)));
 
        /* map the current state */
 
@@ -116,12 +186,26 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
 RouteUI::~RouteUI()
 {
        GoingAway (); /* EMIT SIGNAL */
-       delete mute_menu;
+       if (solo_menu) {
+               delete solo_menu;
+       }
+
+       if (mute_menu) {
+               delete mute_menu;
+       }
+
+       if (remote_control_menu) {
+               delete remote_control_menu;
+       }
 }
 
 bool
 RouteUI::mute_press(GdkEventButton* ev)
 {
+       if (ev->type == GDK_2BUTTON_PRESS) {
+               return true;
+       }
+
        if (!ignore_toggle) {
 
                if (Keyboard::is_context_menu_event (ev)) {
@@ -135,10 +219,10 @@ RouteUI::mute_press(GdkEventButton* ev)
                } else {
 
                        if (ev->button == 2) {
-                               // ctrl-button2 click is the midi binding click
+                               // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
                                
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
+                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
                                        wait_for_release = true;
                                } else {
                                        return false;
@@ -147,9 +231,9 @@ RouteUI::mute_press(GdkEventButton* ev)
 
                        if (ev->button == 1 || ev->button == 2) {
 
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                                       /* ctrl-shift-click applies change to all routes */
+                                       /* Primary-Tertiary-click applies change to all routes */
 
                                        _session.begin_reversible_command (_("mute change"));
                                         Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this);
@@ -158,10 +242,10 @@ RouteUI::mute_press(GdkEventButton* ev)
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                                       /* ctrl-click applies change to the mix group.
-                                          ctrl-button2 is MIDI learn.
+                                       /* Primary-button1 applies change to the mix group.
+                                          NOTE: Primary-button2 is MIDI learn.
                                        */
 
                                        if (ev->button == 1) {
@@ -199,6 +283,12 @@ RouteUI::mute_release(GdkEventButton* ev)
 bool
 RouteUI::solo_press(GdkEventButton* ev)
 {
+       /* ignore double clicks */
+
+       if (ev->type == GDK_2BUTTON_PRESS) {
+               return true;
+       }
+
        if (!ignore_toggle) {
 
                if (Keyboard::is_context_menu_event (ev)) {
@@ -213,10 +303,10 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                        if (ev->button == 2) {
 
-                               // ctrl-button2 click is the midi binding click
+                               // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
                                
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
+                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
                                        wait_for_release = true;
                                } else {
                                        return false;
@@ -225,9 +315,9 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                        if (ev->button == 1 || ev->button == 2) {
 
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                                       /* ctrl-shift-click applies change to all routes */
+                                       /* Primary-Tertiary-click applies change to all routes */
 
                                        _session.begin_reversible_command (_("solo change"));
                                         Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
@@ -236,9 +326,9 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        _session.add_command (cmd);
                                        _session.commit_reversible_command ();
                                        
-                               } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) {
+                               } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
 
-                                       // ctrl-alt-click: exclusively solo this track, not a toggle */
+                                       // Primary-Secondary-click: exclusively solo this track, not a toggle */
 
                                        _session.begin_reversible_command (_("solo change"));
                                         Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this);
@@ -248,17 +338,17 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Shift)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
 
                                        // shift-click: set this route to solo safe
 
                                        _route->set_solo_safe (!_route->solo_safe(), this);
                                        wait_for_release = false;
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                                       /* ctrl-click: solo mix group.
-                                          ctrl-button2 is MIDI learn.
+                                       /* Primary-button1: solo mix group.
+                                          NOTE: Primary-button2 is MIDI learn.
                                        */
 
                                        if (ev->button == 1) {
@@ -268,7 +358,6 @@ RouteUI::solo_press(GdkEventButton* ev)
                                } else {
 
                                        /* click: solo this route */
-
                                        reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
                                }
                        }
@@ -297,6 +386,10 @@ RouteUI::solo_release(GdkEventButton* ev)
 bool
 RouteUI::rec_enable_press(GdkEventButton* ev)
 {
+       if (ev->type == GDK_2BUTTON_PRESS) {
+               return true;
+       }
+
        if (!_session.engine().connected()) {
                MessageDialog msg (_("Not connected to JACK - cannot engage record"));
                msg.run ();
@@ -305,11 +398,12 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 
        if (!ignore_toggle && is_track() && rec_enable_button) {
 
-               if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+               if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
                        // do nothing on midi bind event
+                       return false;
 
-               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
                        _session.begin_reversible_command (_("rec-enable change"));
                         Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
@@ -324,7 +418,11 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                        _session.add_command(cmd);
                        _session.commit_reversible_command ();
 
-               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
+                       /* Primary-button1 applies change to the mix group.
+                          NOTE: Primary-button2 is MIDI learn.
+                       */
 
                        set_mix_group_rec_enable (_route, !_route->record_enabled());
 
@@ -360,7 +458,7 @@ RouteUI::update_solo_display ()
                ignore_toggle = true;
                solo_button->set_active(x);
                ignore_toggle = false;
-       }
+       } 
        
        if (_route->solo_safe()) {
                solo_button->set_visual_state (2);
@@ -386,7 +484,7 @@ RouteUI::mute_changed(void* src)
 void
 RouteUI::update_mute_display ()
 {
-       bool model = _route->record_enabled();
+       bool model = _route->muted();
        bool view = mute_button->get_active();
 
        /* first make sure the button's "depressed" visual
@@ -472,7 +570,7 @@ RouteUI::update_rec_display ()
 void
 RouteUI::build_remote_control_menu ()
 {
-       remote_control_menu = manage (new Menu);
+       remote_control_menu = new Menu;
        refresh_remote_control_menu ();
 }
 
@@ -876,6 +974,28 @@ RouteUI::polarity_changed ()
        /* no signal for this yet */
 }
 
+void
+RouteUI::toggle_denormal_protection ()
+{
+       if (denormal_menu_item) {
+
+               bool x;
+
+               ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_denormal_protection));
+               
+               if ((x = denormal_menu_item->get_active()) != _route->denormal_protection()) {
+                       _route->set_denormal_protection (x, this);
+               }
+       }
+}
+
+void
+RouteUI::denormal_protection_changed ()
+{
+       /* no signal for this yet */
+}
+
+
 void
 RouteUI::solo_safe_toggle(void* src, Gtk::CheckMenuItem* check)
 {
@@ -944,25 +1064,25 @@ RouteUI::disconnect_output ()
 bool
 RouteUI::is_track () const
 {
-       return dynamic_cast<Track*>(_route.get()) != 0;
+       return boost::dynamic_pointer_cast<Track>(_route) != 0;
 }
 
-Track*
+boost::shared_ptr<Track>
 RouteUI::track() const
 {
-       return dynamic_cast<Track*>(_route.get());
+       return boost::dynamic_pointer_cast<Track>(_route);
 }
 
 bool
 RouteUI::is_audio_track () const
 {
-       return dynamic_cast<AudioTrack*>(_route.get()) != 0;
+       return boost::dynamic_pointer_cast<AudioTrack>(_route) != 0;
 }
 
-AudioTrack*
+boost::shared_ptr<AudioTrack>
 RouteUI::audio_track() const
 {
-       return dynamic_cast<AudioTrack*>(_route.get());
+       return boost::dynamic_pointer_cast<AudioTrack>(_route);
 }
 
 boost::shared_ptr<Diskstream>