Use macro from pbd/enum_convert.h to define to_string/_to for Track enum
[ardour.git] / libs / ardour / presentation_info.cc
index 64d2a35828ca3a2b9d2d6fc634689ff58bb36c33..e3e7700d403409c7ff436e63114b949681505f0c 100644 (file)
@@ -43,6 +43,7 @@ PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
 Glib::Threads::Mutex PresentationInfo::static_signal_lock;
 int PresentationInfo::_change_signal_suspended = 0;
 PBD::PropertyChange PresentationInfo::_pending_static_changes;
+int PresentationInfo::selection_counter = 0;
 
 namespace ARDOUR {
        namespace Properties {
@@ -61,37 +62,31 @@ PresentationInfo::suspend_change_signal ()
 void
 PresentationInfo::unsuspend_change_signal ()
 {
+       Glib::Threads::Mutex::Lock lm (static_signal_lock);
+
        if (g_atomic_int_get (const_cast<gint*> (&_change_signal_suspended)) == 1) {
 
                /* atomically grab currently pending flags */
 
-               PropertyChange pc;
-
-               {
-                       Glib::Threads::Mutex::Lock lm (static_signal_lock);
-                       pc = _pending_static_changes;
-                       _pending_static_changes.clear ();
-               }
+               PropertyChange pc = _pending_static_changes;
+               _pending_static_changes.clear ();
 
                if (!pc.empty()) {
 
-                       std::cerr << "PI change (unsuspended): ";
-                       for (PropertyChange::const_iterator x = pc.begin(); x != pc.end(); ++x) {
-                               std::cerr << g_quark_to_string (*x) << ',';
-                       }
-                       std::cerr << '\n';
-
-                       /* emit the signal with further emissions still
-                        * blocked, so that if the handlers modify other PI
-                        * states, the signal for that won't be sent while
-                        * they are handling this one.
+                       /* emit the signal with further emissions still blocked
+                        * by _change_signal_suspended, but not by the lock.
+                        *
+                        * This means that if the handlers modify other PI
+                        * states, the signal for that won't be sent while they
+                        * are handling the current signal.
                         */
-
+                       lm.release ();
                        Change (pc); /* EMIT SIGNAL */
+                       lm.acquire ();
                }
-
-               g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
        }
+
+       g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
 }
 
 void
@@ -108,12 +103,6 @@ PresentationInfo::send_static_change (const PropertyChange& what_changed)
                return;
        }
 
-       std::cerr << "PI change (direct): ";
-       for (PropertyChange::const_iterator x = what_changed.begin(); x != what_changed.end(); ++x) {
-               std::cerr << g_quark_to_string (*x) << ',';
-       }
-       std::cerr << '\n';
-
        Change (what_changed);
 }
 
@@ -255,8 +244,10 @@ PresentationInfo::set_selected (bool yn)
        if (yn != selected()) {
                if (yn) {
                        _flags = Flag (_flags | Selected);
+                       _selection_cnt = g_atomic_int_add (&selection_counter, 1);
                } else {
                        _flags = Flag (_flags & ~Selected);
+                       _selection_cnt = 0;
                }
                send_change (PropertyChange (Properties::selected));
                send_static_change (PropertyChange (Properties::selected));