Merged with trunk R846
[ardour.git] / libs / ardour / playlist.cc
index 1c34099c7ef2aaa6b53ab1557c6501ecd2ce960d..61aa5c587aca2ed0bfacad87f418a3442f9fa0ae 100644 (file)
@@ -41,7 +41,7 @@
 
 using namespace std;
 using namespace ARDOUR;
-//using namespace sigc;
+using namespace PBD;
 
 sigc::signal<void,Playlist*> Playlist::PlaylistCreated;
 
@@ -72,21 +72,24 @@ struct RegionSortByLastLayerOp {
     }
 };
 
-Playlist::Playlist (Session& sess, string nom, bool hide)
+Playlist::Playlist (Session& sess, string nom, DataType type, bool hide)
        : _session (sess)
+       , _type(type)
 {
        init (hide);
        _name = nom;
-       _orig_diskstream_id = 0;
        
 }
 
-Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
+Playlist::Playlist (Session& sess, const XMLNode& node, DataType type, bool hide)
        : _session (sess)
+       , _type(type)
 {
+       const XMLProperty* prop = node.property("type");
+       assert(!prop || DataType(prop->value()) == _type);
+
        init (hide);
        _name = "unnamed"; /* reset by set_state */
-       _orig_diskstream_id = 0;
        
        if (set_state (node)) {
                throw failed_constructor();
@@ -94,7 +97,7 @@ Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
 }
 
 Playlist::Playlist (const Playlist& other, string namestr, bool hide)
-       : _name (namestr), _session (other._session), _orig_diskstream_id(other._orig_diskstream_id)
+       : _name (namestr), _session (other._session), _type(other._type), _orig_diskstream_id(other._orig_diskstream_id)
 {
        init (hide);
 
@@ -127,7 +130,7 @@ Playlist::Playlist (const Playlist& other, string namestr, bool hide)
 }
 
 Playlist::Playlist (const Playlist& other, jack_nframes_t start, jack_nframes_t cnt, string str, bool hide)
-       : _name (str), _session (other._session), _orig_diskstream_id(other._orig_diskstream_id)
+       : _name (str), _session (other._session), _type(other._type), _orig_diskstream_id(other._orig_diskstream_id)
 {
        RegionLock rlock2 (&((Playlist&)other));
        
@@ -225,8 +228,8 @@ Playlist::copy_regions (RegionList& newlist) const
 void
 Playlist::init (bool hide)
 {
-       atomic_set (&block_notifications, 0);
-       atomic_set (&ignore_state_changes, 0);
+       g_atomic_int_set (&block_notifications, 0);
+       g_atomic_int_set (&ignore_state_changes, 0);
        pending_modified = false;
        pending_length = false;
        _refcnt = 0;
@@ -249,12 +252,14 @@ Playlist::init (bool hide)
 
 Playlist::Playlist (const Playlist& pl)
        : _session (pl._session)
+       , _type(pl.data_type())
 {
        fatal << _("playlist const copy constructor called") << endmsg;
 }
 
 Playlist::Playlist (Playlist& pl)
        : _session (pl._session)
+       , _type(pl.data_type())
 {
        fatal << _("playlist non-const copy constructor called") << endmsg;
 }
@@ -292,13 +297,13 @@ void
 Playlist::freeze ()
 {
        delay_notifications ();
-       atomic_inc (&ignore_state_changes);
+       g_atomic_int_inc (&ignore_state_changes);
 }
 
 void
 Playlist::thaw ()
 {
-       atomic_dec (&ignore_state_changes);
+       g_atomic_int_dec_and_test (&ignore_state_changes);
        release_notifications ();
 }
 
@@ -306,14 +311,14 @@ Playlist::thaw ()
 void
 Playlist::delay_notifications ()
 {
-       atomic_inc (&block_notifications);
+       g_atomic_int_inc (&block_notifications);
        freeze_length = _get_maximum_extent();
 }
 
 void
 Playlist::release_notifications ()
 {
-       if (atomic_dec_and_test(&block_notifications)) { 
+       if (g_atomic_int_dec_and_test (&block_notifications)) { 
                flush_notifications ();
        } 
 }
@@ -600,6 +605,31 @@ Playlist::remove_region_internal (Region *region, bool delay_sort)
        return -1;
 }
 
+void
+Playlist::get_equivalent_regions (const Region& other, vector<Region*>& results)
+{
+       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
+               if (Config->get_use_overlap_equivalency()) {
+                       if ((*i)->overlap_equivalent (other)) {
+                               results.push_back ((*i));
+                       } else if ((*i)->equivalent (other)) {
+                               results.push_back ((*i));
+                       }
+               }
+       }
+}
+
+void
+Playlist::get_region_list_equivalent_regions (const Region& other, vector<Region*>& results)
+{
+       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
+
+               if ((*i) && (*i)->region_list_equivalent (other)) {
+                       results.push_back (*i);
+               }
+       }
+}
+
 void
 Playlist::partition (jack_nframes_t start, jack_nframes_t end, bool just_top_level)
 {
@@ -998,9 +1028,21 @@ Playlist::split_region (Region& region, jack_nframes_t playlist_position)
 
        _session.region_name (after_name, region.name(), false);
        right = createRegion (region, before, after, after_name, region.layer(), Region::Flag (region.flags()|Region::RightOfSplit));
-       
+
        add_region_internal (left, region.position(), true);
        add_region_internal (right, region.position() + before);
+       
+       uint64_t orig_layer_op = region.last_layer_op();
+       for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
+               if ((*i)->last_layer_op() > orig_layer_op) {
+                       (*i)->set_last_layer_op( (*i)->last_layer_op() + 1 );
+               }
+       }
+       
+       left->set_last_layer_op ( orig_layer_op );
+       right->set_last_layer_op ( orig_layer_op + 1);
+
+       layer_op_counter++;
 
        finalize_split_region (&region, left, right);
        
@@ -1331,7 +1373,7 @@ Playlist::set_state (const XMLNode& node)
                if (prop->name() == X_("name")) {
                        _name = prop->value();
                } else if (prop->name() == X_("orig_diskstream_id")) {
-                       sscanf (prop->value().c_str(), "%" PRIu64, &_orig_diskstream_id);
+                       _orig_diskstream_id = prop->value ();
                } else if (prop->name() == X_("frozen")) {
                        _frozen = (prop->value() == X_("yes"));
                }
@@ -1391,8 +1433,9 @@ Playlist::state (bool full_state)
        char buf[64];
        
        node->add_property (X_("name"), _name);
+       node->add_property (X_("type"), _type.to_string());
 
-       snprintf (buf, sizeof(buf), "%" PRIu64, _orig_diskstream_id);
+       _orig_diskstream_id.print (buf);
        node->add_property (X_("orig_diskstream_id"), buf);
        node->add_property (X_("frozen"), _frozen ? "yes" : "no");
 
@@ -1713,7 +1756,7 @@ Playlist::nudge_after (jack_nframes_t start, jack_nframes_t distance, bool forwa
 }
 
 Region*
-Playlist::find_region (id_t id) const
+Playlist::find_region (const ID& id) const
 {
        RegionLock rlock (const_cast<Playlist*> (this));
        RegionList::const_iterator i;