Decreased region opacity, smoothed out canvas/tempo line colours.
[ardour.git] / gtk2_ardour / route_ui.cc
index 8a1fb1c21aecf813f53fa073e2cd07401de36aed..08b6c657a519a57880747d13dd8aaf6b42716217 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <ardour/route_group.h>
 #include <pbd/memento_command.h>
+#include <pbd/stacktrace.h>
+#include <pbd/shiva.h>
 
 #include "route_ui.h"
 #include "keyboard.h"
@@ -34,6 +36,8 @@
 #include "gui_thread.h"
 
 #include <ardour/route.h>
+#include <ardour/session.h>
+#include <ardour/audioengine.h>
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
 
@@ -44,7 +48,6 @@ 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),
@@ -65,29 +68,36 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
                set_color (unique_random_color());
        }
 
-       _route->GoingAway.connect (mem_fun (*this, &RouteUI::route_removed));
+       new PairedShiva<Route,RouteUI> (*_route, *this);
+
        _route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
 
         mute_button = manage (new BindableToggleButton (_route->mute_control(), m_name ));
         solo_button = manage (new BindableToggleButton (_route->solo_control(), s_name ));
+
+       // mute_button->unset_flags (Gtk::CAN_FOCUS);
+       // solo_button->unset_flags (Gtk::CAN_FOCUS);
+
+       _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));
        
+       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));
+               t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed));
 
                _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->unset_flags (Gtk::CAN_FOCUS);
                
                update_rec_display ();
        } 
        
-       mute_button->unset_flags (Gtk::CAN_FOCUS);
-       solo_button->unset_flags (Gtk::CAN_FOCUS);
-
        /* map the current state */
 
        map_frozen ();
@@ -95,10 +105,11 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
 
 RouteUI::~RouteUI()
 {
+       GoingAway (); /* EMIT SIGNAL */
        delete mute_menu;
 }
 
-gint
+bool
 RouteUI::mute_press(GdkEventButton* ev)
 {
        if (!ignore_toggle) {
@@ -109,7 +120,7 @@ RouteUI::mute_press(GdkEventButton* ev)
                                build_mute_menu();
                        }
 
-                       mute_menu->popup(0,0);
+                       mute_menu->popup(0,ev->time);
 
                } else {
 
@@ -119,6 +130,8 @@ RouteUI::mute_press(GdkEventButton* ev)
                                
                                if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
                                        wait_for_release = true;
+                               } else {
+                                       return false;
                                }
                        }
 
@@ -130,7 +143,7 @@ RouteUI::mute_press(GdkEventButton* ev)
 
                                        _session.begin_reversible_command (_("mute change"));
                                         Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this);
-                                       _session.set_all_mute (!_route.muted());
+                                       _session.set_all_mute (!_route->muted());
                                         cmd->mark();
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
@@ -159,7 +172,7 @@ RouteUI::mute_press(GdkEventButton* ev)
        return true;
 }
 
-gint
+bool
 RouteUI::mute_release(GdkEventButton* ev)
 {
        if (!ignore_toggle) {
@@ -173,7 +186,7 @@ RouteUI::mute_release(GdkEventButton* ev)
        return true;
 }
 
-gint
+bool
 RouteUI::solo_press(GdkEventButton* ev)
 {
        if (!ignore_toggle) {
@@ -184,7 +197,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                build_solo_menu ();
                        }
 
-                       solo_menu->popup (1, 0);
+                       solo_menu->popup (1, ev->time);
 
                } else {
 
@@ -195,6 +208,8 @@ RouteUI::solo_press(GdkEventButton* ev)
                                
                                if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
                                        wait_for_release = true;
+                               } else {
+                                       return false;
                                }
                        }
 
@@ -206,7 +221,7 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                                        _session.begin_reversible_command (_("solo change"));
                                         Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
-                                       _session.set_all_solo (!_route.soloed());
+                                       _session.set_all_solo (!_route->soloed());
                                         cmd->mark();
                                        _session.add_command (cmd);
                                        _session.commit_reversible_command ();
@@ -218,7 +233,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        _session.begin_reversible_command (_("solo change"));
                                         Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this);
                                        _session.set_all_solo (false);
-                                       _route.set_solo (true, this);
+                                       _route->set_solo (true, this);
                                         cmd->mark();
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
@@ -253,7 +268,7 @@ RouteUI::solo_press(GdkEventButton* ev)
        return true;
 }
 
-gint
+bool
 RouteUI::solo_release(GdkEventButton* ev)
 {
        if (!ignore_toggle) {
@@ -269,9 +284,15 @@ RouteUI::solo_release(GdkEventButton* ev)
        return true;
 }
 
-gint
+bool
 RouteUI::rec_enable_press(GdkEventButton* ev)
 {
+       if (!_session.engine().connected()) {
+               MessageDialog msg (_("Not connected to JACK - cannot engage record"));
+               msg.run ();
+               return true;
+       }
+
        if (!ignore_toggle && is_track() && rec_enable_button) {
 
                if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
@@ -423,7 +444,7 @@ RouteUI::refresh_remote_control_menu ()
 
        RadioMenuItem::Group rc_group;
        CheckMenuItem* rc_active;
-       uint32_t limit = _session.ntracks();
+       uint32_t limit = _session.ntracks() + _session.nbusses();
        char buf[32];
 
        MenuList& rc_items = remote_control_menu->items();
@@ -484,7 +505,7 @@ RouteUI::build_solo_menu (void)
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
-       items.push_back (SeparatorElem());
+       //items.push_back (SeparatorElem());
        // items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
        
 }
@@ -527,7 +548,7 @@ RouteUI::build_mute_menu(void)
        items.push_back (CheckMenuElem(*check));
        check->show_all();
 
-       items.push_back (SeparatorElem());
+       //items.push_back (SeparatorElem());
        // items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
 }
 
@@ -572,10 +593,10 @@ void
 RouteUI::reversibly_apply_route_boolean (string name, void (Route::*func)(bool, void *), bool yn, void *arg)
 {
        _session.begin_reversible_command (name);
-        XMLNode &before = _route.get_state();
-        bind(mem_fun(_route, func), yn, arg)();
-        XMLNode &after = _route.get_state();
-        _session.add_command (new MementoCommand<Route>(_route, before, after));
+        XMLNode &before = _route->get_state();
+        bind(mem_fun(*_route, func), yn, arg)();
+        XMLNode &after = _route->get_state();
+        _session.add_command (new MementoCommand<Route>(*_route, &before, &after));
        _session.commit_reversible_command ();
 }
 
@@ -586,7 +607,7 @@ RouteUI::reversibly_apply_audio_track_boolean (string name, void (AudioTrack::*f
         XMLNode &before = audio_track()->get_state();
        bind (mem_fun (*audio_track(), func), yn, arg)();
         XMLNode &after = audio_track()->get_state();
-       _session.add_command (new MementoCommand<AudioTrack>(*audio_track(), before, after));
+       _session.add_command (new MementoCommand<AudioTrack>(*audio_track(), &before, &after));
        _session.commit_reversible_command ();
 }
 
@@ -651,7 +672,7 @@ RouteUI::set_color (const Gdk::Color & c)
        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 */
+       _route->gui_changed ("color", (void *) 0); /* EMIT_SIGNAL */
 }
 
 
@@ -729,14 +750,6 @@ RouteUI::idle_remove_this_route (RouteUI *rui)
        return FALSE;
 }
 
-void
-RouteUI::route_removed ()
-{
-       ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::route_removed));
-       
-       delete this;
-}
-
 void
 RouteUI::route_rename ()
 {
@@ -905,15 +918,15 @@ RouteUI::audio_track() const
        return dynamic_cast<AudioTrack*>(_route.get());
 }
 
-Diskstream*
+boost::shared_ptr<Diskstream>
 RouteUI::get_diskstream () const
 {
        boost::shared_ptr<Track> t;
 
        if ((t = boost::dynamic_pointer_cast<Track>(_route)) != 0) {
-               return &t->diskstream();
+               return t->diskstream();
        } else {
-               return 0;
+               return boost::shared_ptr<Diskstream> ((Diskstream*) 0);
        }
 }