region list displays actual playlist use count for each region, rather than a GUI...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 20 Sep 2010 19:18:17 +0000 (19:18 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 20 Sep 2010 19:18:17 +0000 (19:18 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7814 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_regions.cc
gtk2_ardour/editor_regions.h
libs/ardour/ardour/playlist.h
libs/ardour/ardour/session_playlists.h
libs/ardour/playlist.cc
libs/ardour/session.cc
libs/ardour/session_playlists.cc

index 176b5c63459b8e72cdbfb36242e9cddec0a784d7..a66282a7ef9d0bf7969667a04041f726dc540d30 100644 (file)
 
 #include "pbd/basename.h"
 #include "pbd/enumwriter.h"
+#include "pbd/stacktrace.h"
 
 #include "ardour/audioregion.h"
 #include "ardour/audiofilesource.h"
 #include "ardour/region_factory.h"
 #include "ardour/session.h"
+#include "ardour/session_playlists.h"
 #include "ardour/silentfilesource.h"
 #include "ardour/profile.h"
 
@@ -62,6 +64,7 @@ EditorRegions::EditorRegions (Editor* e)
        , _no_redisplay (false) 
        , ignore_region_list_selection_change (false)
        , ignore_selected_region_change (false)
+        , expanded (false)
 {
        _display.set_size_request (100, -1);
        _display.set_name ("RegionListDisplay");
@@ -547,6 +550,9 @@ EditorRegions::redisplay ()
                 insert_into_tmp_regionlist (i->second);
         }
 
+        stacktrace (cerr, 22);
+        cerr << "Redisplay with " << tmp_region_list.size() << " regions\n";
+
        for (list<boost::shared_ptr<Region> >::iterator r = tmp_region_list.begin(); r != tmp_region_list.end(); ++r) {
                add_region (*r);
        }
@@ -709,7 +715,7 @@ void
 EditorRegions::populate_row (boost::shared_ptr<Region> region, TreeModel::Row const &row)
 {
        boost::shared_ptr<AudioRegion> audioregion = boost::dynamic_pointer_cast<AudioRegion>(region);
-        uint32_t used = _editor->get_regionview_count_from_region_list (region);
+        uint32_t used = _session->playlists->region_use_count (region);
 
         populate_row_position (region, row, used);
         populate_row_end (region, row, used);
@@ -941,8 +947,10 @@ EditorRegions::set_full (bool f)
 {
        if (f) {
                _display.expand_all ();
+                expanded = true;
        } else {
                _display.collapse_all ();
+                expanded = false;
        }
 }
 
@@ -1345,6 +1353,8 @@ EditorRegions::get_state () const
 void
 EditorRegions::set_state (const XMLNode & node)
 {
+        bool changed = false;
+
        if (node.name() != X_("RegionList")) {
                return;
        }
@@ -1352,6 +1362,9 @@ EditorRegions::set_state (const XMLNode & node)
        XMLProperty const * p = node.property (X_("sort-type"));
        if (p) {
                Editing::RegionListSortType const t = static_cast<Editing::RegionListSortType> (string_2_enum (p->value(), _sort_type));
+                if (_sort_type != t) {
+                        changed = true;
+                }
                reset_sort_type (t, true);
                RefPtr<RadioAction> ract = sort_type_action (t);
                ract->set_active ();
@@ -1359,10 +1372,17 @@ EditorRegions::set_state (const XMLNode & node)
 
        p = node.property (X_("sort-ascending"));
        if (p) {
-               bool const a = string_is_affirmative (p->value ());
-               reset_sort_direction (a);
+               bool const yn = string_is_affirmative (p->value ());
+                SortType old_sort_type;
+                int old_sort_column;
+
+                _model->get_sort_column_id (old_sort_column, old_sort_type);
+                if (old_sort_type != (yn ? SORT_ASCENDING : SORT_DESCENDING)) {
+                        changed = true;
+                }
+               reset_sort_direction (yn);
                RefPtr<Action> act;
-               if (a) {
+               if (yn) {
                        act = ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
                } else {
                        act = ActionManager::get_action (X_("RegionList"), X_("SortDescending"));
@@ -1373,18 +1393,29 @@ EditorRegions::set_state (const XMLNode & node)
 
        p = node.property (X_("show-all"));
        if (p) {
-               bool const s = string_is_affirmative (p->value ());
-               set_full (s);
-               toggle_full_action()->set_active (s);
+               bool const yn = string_is_affirmative (p->value ());
+                if (expanded != yn) {
+                        changed = true;
+                }
+               set_full (yn);
+               toggle_full_action()->set_active (yn);
        }
 
        p = node.property (X_("show-automatic-regions"));
        if (p) {
-               bool const s = string_is_affirmative (p->value ());
-               _show_automatic_regions = s;
-               redisplay ();
-               toggle_show_auto_regions_action()->set_active (s);
-       }
+               bool const yn = string_is_affirmative (p->value ());
+                if (yn != _show_automatic_regions) {
+                        _show_automatic_regions = yn;
+                        toggle_show_auto_regions_action()->set_active (yn);
+                        /* no need to set changed because the above toggle 
+                           will have triggered a redisplay 
+                        */
+                }
+        }
+        
+        if (changed) {
+                redisplay ();
+        }
 }
 
 RefPtr<RadioAction>
index 43aadaf11b62adfcbbcd614cbd7501b96776ff35..f899b00c550f5d3d52cabf151d4f2acc5bb035ca 100644 (file)
@@ -176,6 +176,7 @@ private:
        PBD::ScopedConnection check_new_region_connection;
        bool ignore_region_list_selection_change;
        bool ignore_selected_region_change;
+        bool expanded;
 };
 
 #endif /* __gtk_ardour_editor_regions_h__ */
index 67638cf15eb9b00d200456240b89fae893448c58..2cc1f570f48b94c572121dd713968fe5328e46c4 100644 (file)
@@ -151,6 +151,7 @@ public:
         uint32_t                   count_regions_at (framepos_t);
        RegionList*                regions_touched (framepos_t start, framepos_t end);
        RegionList*                regions_to_read (framepos_t start, framepos_t end);
+       uint32_t                   region_use_count (boost::shared_ptr<Region>) const;
        boost::shared_ptr<Region>  find_region (const PBD::ID&) const;
        boost::shared_ptr<Region>  top_region_at (framepos_t frame);
        boost::shared_ptr<Region>  top_unmuted_region_at (framepos_t frame);
index 4ca67bdee8b7b478e13982feef1760e4c7843727..0a20c7b9053ebb48d10a0df93a2ab42722a8033e 100644 (file)
@@ -51,6 +51,7 @@ public:
        boost::shared_ptr<Playlist> by_name (std::string name);
        boost::shared_ptr<Playlist> by_id (const PBD::ID&);
        uint32_t source_use_count (boost::shared_ptr<const Source> src) const;
+        uint32_t region_use_count (boost::shared_ptr<Region> region) const;
        template<class T> void foreach (T *obj, void (T::*func)(boost::shared_ptr<Playlist>));
        void get (std::vector<boost::shared_ptr<Playlist> >&);
        void unassigned (std::list<boost::shared_ptr<Playlist> > & list);
index 334b3f163dd40ce0c8957fee79ae2479fe5e5d1b..614c0f5e36848227ce7bf8980f963ac78e324491 100644 (file)
@@ -2712,6 +2712,21 @@ Playlist::find_region (const ID& id) const
        return boost::shared_ptr<Region> ();
 }
 
+uint32_t
+Playlist::region_use_count (boost::shared_ptr<Region> r) const
+{
+       RegionLock rlock (const_cast<Playlist*> (this));
+        uint32_t cnt = 0;
+
+       for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) {
+               if ((*i) == r) {
+                        cnt++;
+               }
+       }
+
+       return cnt;
+}
+
 boost::shared_ptr<Region>
 Playlist::region_by_id (const ID& id) const
 {
index 4f18a300af0c263ca4df72727ad42ca52e846feb..cda93d050f46c4e48d8d485993433ccf9e1baf56 100644 (file)
@@ -4024,3 +4024,4 @@ Session::step_edit_status_change (bool yn)
         }
 }
 
+        
index b54faba97ed2f60721590d2e71efe47bb77dedbc..66b4b53b671d97aa6e7b80f841861a9e784c93f4 100644 (file)
@@ -413,3 +413,20 @@ SessionPlaylists::find_crossfade (const PBD::ID& id)
 
        return boost::shared_ptr<Crossfade> ();
 }
+
+uint32_t
+SessionPlaylists::region_use_count (boost::shared_ptr<Region> region) const
+{
+       Glib::Mutex::Lock lm (lock);
+        uint32_t cnt = 0;
+       
+       for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+                cnt += (*i)->region_use_count (region);
+       }
+
+       for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+                cnt += (*i)->region_use_count (region);
+       }
+
+       return cnt;
+}