libs/ardour/wscript: unit tests get a target name, inorder to be able to build them...
[ardour.git] / libs / ardour / region.cc
index cae564832dc53f22a46f7178eb54289fcaadcd95..1f90a0761b04838b9bfbcb93bc6126fca79c18da 100644 (file)
 #include <sigc++/class_slot.h>
 
 #include <glibmm/thread.h>
-#include <pbd/xml++.h>
-#include <pbd/stacktrace.h>
-#include <pbd/enumwriter.h>
-
-#include <ardour/region.h>
-#include <ardour/playlist.h>
-#include <ardour/session.h>
-#include <ardour/source.h>
-#include <ardour/tempo.h>
-#include <ardour/region_factory.h>
-#include <ardour/filter.h>
-#include <ardour/profile.h>
+#include "pbd/xml++.h"
+#include "pbd/stacktrace.h"
+#include "pbd/enumwriter.h"
+
+#include "ardour/region.h"
+#include "ardour/playlist.h"
+#include "ardour/session.h"
+#include "ardour/source.h"
+#include "ardour/tempo.h"
+#include "ardour/region_factory.h"
+#include "ardour/filter.h"
+#include "ardour/profile.h"
+#include "ardour/utils.h"
 
 #include "i18n.h"
 
@@ -60,7 +61,7 @@ sigc::signal<void,boost::shared_ptr<ARDOUR::Region> > Region::RegionPropertyChan
 Region::Region (Session& s, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(s, name)
        , _type(type)
-       , _flags(flags)
+       , _flags(Flag (flags|DoNotSendPropertyChanges))
        , _start(start) 
        , _length(length) 
        , _position(0) 
@@ -70,6 +71,8 @@ Region::Region (Session& s, nframes_t start, nframes_t length, const string& nam
        , _layer(layer)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
+       , _ancestral_start (0)
+       , _ancestral_length (0)
        , _stretch(1.0)
        , _shift(1.0)
        , _read_data_count(0)
@@ -83,7 +86,7 @@ Region::Region (Session& s, nframes_t start, nframes_t length, const string& nam
 Region::Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(src->session(), name)
        , _type(type)
-       , _flags(flags)
+       , _flags(Flag (flags|DoNotSendPropertyChanges))
        , _start(start) 
        , _length(length) 
        , _position(0) 
@@ -116,7 +119,7 @@ Region::Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length
 Region::Region (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(srcs.front()->session(), name)
        , _type(type)
-       , _flags(flags)
+       , _flags(Flag (flags|DoNotSendPropertyChanges))
        , _start(start) 
        , _length(length) 
        , _position(0) 
@@ -126,28 +129,15 @@ Region::Region (const SourceList& srcs, nframes_t start, nframes_t length, const
        , _layer(layer)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
+       , _ancestral_start (0)
+       , _ancestral_length (0)
        , _stretch(1.0)
        , _shift(1.0)
        , _read_data_count(0)
        , _pending_changed(Change (0))
        , _last_layer_op(0)
 {
-       
-       set<boost::shared_ptr<Source> > unique_srcs;
-
-       for (SourceList::const_iterator i=srcs.begin(); i != srcs.end(); ++i) {
-               _sources.push_back (*i);
-               (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               unique_srcs.insert (*i);
-       }
-
-       for (SourceList::const_iterator i = srcs.begin(); i != srcs.end(); ++i) {
-               _master_sources.push_back (*i);
-               if (unique_srcs.find (*i) == unique_srcs.end()) {
-                       (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               }
-       }
-       
+       use_sources (srcs);
        assert(_sources.size() > 0);
 }
 
@@ -160,6 +150,8 @@ Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes
        _start = other->_start + offset;
        copy_stuff (other, offset, length, name, layer, flags);
 
+       _flags = Flag (_flags | DoNotSendPropertyChanges);
+
        /* if the other region had a distinct sync point
           set, then continue to use it as best we can.
           otherwise, reset sync point back to start.
@@ -198,6 +190,8 @@ Region::Region (boost::shared_ptr<const Region> other, nframes_t length, const s
        _start = 0;
        copy_stuff (other, 0, length, name, layer, flags);
 
+       _flags = Flag (_flags | DoNotSendPropertyChanges);
+
        /* sync pos is relative to start of file. our start-in-file is now zero,
           so set our sync position to whatever the the difference between
           _start and _sync_pos was in the other region. 
@@ -263,6 +257,8 @@ Region::Region (boost::shared_ptr<const Region> other)
        , _pending_changed(Change(0))
        , _last_layer_op(other->_last_layer_op)
 {
+       _flags = Flag (_flags | DoNotSendPropertyChanges);
+
        other->_first_edit = EditChangesName;
 
        if (other->_extra_xml) {
@@ -271,28 +267,14 @@ Region::Region (boost::shared_ptr<const Region> other)
                _extra_xml = 0;
        }
 
-       set<boost::shared_ptr<Source> > unique_srcs;
-
-       for (SourceList::const_iterator i = other->_sources.begin(); i != other->_sources.end(); ++i) {
-               _sources.push_back (*i);
-               (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               unique_srcs.insert (*i);
-       }
-
-       for (SourceList::const_iterator i = other->_master_sources.begin(); i != other->_master_sources.end(); ++i) {
-               _master_sources.push_back (*i);
-               if (unique_srcs.find (*i) == unique_srcs.end()) {
-                       (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               }
-       }
-       
+       use_sources (other->_sources);
        assert(_sources.size() > 0);
 }
 
 Region::Region (const SourceList& srcs, const XMLNode& node)
        : SessionObject(srcs.front()->session(), X_("error: XML did not reset this"))
        , _type(DataType::NIL) // to be loaded from XML
-       , _flags(Flag(0))
+       , _flags(DoNotSendPropertyChanges)
        , _start(0) 
        , _length(0) 
        , _position(0) 
@@ -308,20 +290,7 @@ Region::Region (const SourceList& srcs, const XMLNode& node)
        , _pending_changed(Change(0))
        , _last_layer_op(0)
 {
-       set<boost::shared_ptr<Source> > unique_srcs;
-
-       for (SourceList::const_iterator i=srcs.begin(); i != srcs.end(); ++i) {
-               _sources.push_back (*i);
-               (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               unique_srcs.insert (*i);
-       }
-
-       for (SourceList::const_iterator i = srcs.begin(); i != srcs.end(); ++i) {
-               _master_sources.push_back (*i);
-               if (unique_srcs.find (*i) == unique_srcs.end()) {
-                       (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i)));
-               }
-       }
+       use_sources (srcs);
 
        if (set_state (node)) {
                throw failed_constructor();
@@ -334,7 +303,7 @@ Region::Region (const SourceList& srcs, const XMLNode& node)
 Region::Region (boost::shared_ptr<Source> src, const XMLNode& node)
        : SessionObject(src->session(), X_("error: XML did not reset this"))
        , _type(DataType::NIL)
-       , _flags(Flag(0))
+       , _flags(DoNotSendPropertyChanges)
        , _start(0) 
        , _length(0) 
        , _position(0) 
@@ -378,7 +347,7 @@ Region::~Region ()
 }
 
 void
-Region::copy_stuff (boost::shared_ptr<const Region> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags)
+Region::copy_stuff (boost::shared_ptr<const Region> other, nframes_t /*offset*/, nframes_t length, const string& name, layer_t layer, Flag flags)
 {
        _frozen = 0;
        _pending_changed = Change (0);
@@ -400,6 +369,8 @@ Region::copy_stuff (boost::shared_ptr<const Region> other, nframes_t offset, nfr
        _first_edit = EditChangesNothing;
        _last_layer_op = 0;
        _positional_lock_style = AudioTime;
+
+       use_sources (other->_sources);
 }
 
 void
@@ -458,7 +429,7 @@ Region::set_name (const std::string& str)
 }
 
 void
-Region::set_length (nframes_t len, void *src)
+Region::set_length (nframes_t len, void */*src*/)
 {
        //cerr << "Region::set_length() len = " << len << endl;
        if (_flags & Locked) {
@@ -596,7 +567,7 @@ Region::update_position_after_tempo_map_change ()
 }
 
 void
-Region::set_position (nframes_t pos, void *src)
+Region::set_position (nframes_t pos, void */*src*/)
 {
        if (!can_move()) {
                return;
@@ -638,7 +609,7 @@ Region::set_position_internal (nframes_t pos, bool allow_bbt_recompute)
 }
 
 void
-Region::set_position_on_top (nframes_t pos, void *src)
+Region::set_position_on_top (nframes_t pos, void */*src*/)
 {
        if (_flags & Locked) {
                return;
@@ -674,7 +645,7 @@ Region::recompute_position_from_lock_style ()
 }
                
 void
-Region::nudge_position (nframes64_t n, void *src)
+Region::nudge_position (nframes64_t n, void */*src*/)
 {
        if (_flags & Locked) {
                return;
@@ -713,7 +684,7 @@ Region::set_ancestral_data (nframes64_t s, nframes64_t l, float st, float sh)
 }
 
 void
-Region::set_start (nframes_t pos, void *src)
+Region::set_start (nframes_t pos, void */*src*/)
 {
        if (_flags & (Locked|PositionLocked)) {
                return;
@@ -739,7 +710,7 @@ Region::set_start (nframes_t pos, void *src)
 }
 
 void
-Region::trim_start (nframes_t new_position, void *src)
+Region::trim_start (nframes_t new_position, void */*src*/)
 {
        if (_flags & (Locked|PositionLocked)) {
                return;
@@ -826,7 +797,7 @@ Region::trim_front (nframes_t new_position, void *src)
 }
 
 void
-Region::trim_end (nframes_t new_endpoint, void *src)
+Region::trim_end (nframes_t new_endpoint, void */*src*/)
 {
        if (_flags & Locked) {
                return;
@@ -856,7 +827,7 @@ Region::trim_to (nframes_t position, nframes_t length, void *src)
 }
 
 void
-Region::trim_to_internal (nframes_t position, nframes_t length, void *src)
+Region::trim_to_internal (nframes_t position, nframes_t length, void */*src*/)
 {
        int32_t start_shift;
        nframes_t new_start;
@@ -1128,7 +1099,7 @@ Region::set_layer (layer_t l)
 }
 
 XMLNode&
-Region::state (bool full_state)
+Region::state (bool /*full_state*/)
 {
        XMLNode *node = new XMLNode ("Region");
        char buf[64];
@@ -1298,13 +1269,13 @@ Region::set_live_state (const XMLNode& node, Change& what_changed, bool send)
        /* these 3 properties never change as a result of any editing */
 
        if ((prop = node.property ("ancestral-start")) != 0) {
-               _ancestral_start = atoi (prop->value());
+               _ancestral_start = strtoll (prop->value().c_str(), 0, 10);
        } else {
                _ancestral_start = _start;
        }
 
        if ((prop = node.property ("ancestral-length")) != 0) {
-               _ancestral_length = atoi (prop->value());
+               _ancestral_length = strtoll (prop->value().c_str(), 0, 10);
        } else {
                _ancestral_length = _length;
        }
@@ -1391,7 +1362,7 @@ Region::freeze ()
 }
 
 void
-Region::thaw (const string& why)
+Region::thaw (const string& /*why*/)
 {
        Change what_changed = Change (0);
 
@@ -1435,7 +1406,7 @@ Region::send_change (Change what_changed)
 
        StateChanged (what_changed);
        
-       if (!(_flags & DoNotSaveState)) {
+       if (!(_flags & DoNotSendPropertyChanges)) {
                
                /* Try and send a shared_pointer unless this is part of the constructor.
                   If so, do nothing.
@@ -1508,6 +1479,7 @@ void
 Region::set_master_sources (const SourceList& srcs)
 {
        _master_sources = srcs;
+       assert (_sources.size() == _master_sources.size());
 }
 
 bool
@@ -1637,3 +1609,23 @@ Region::invalidate_transients ()
        _transients.clear ();
 }
 
+
+void
+Region::use_sources (SourceList const & s)
+{
+       set<boost::shared_ptr<Source> > unique_srcs;
+       
+       for (SourceList::const_iterator i = s.begin (); i != s.end(); ++i) {
+               _sources.push_back (*i);
+               (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), *i));
+               unique_srcs.insert (*i);
+       }
+
+       for (SourceList::const_iterator i = s.begin (); i != s.end(); ++i) {
+               _master_sources.push_back (*i);
+               if (unique_srcs.find (*i) == unique_srcs.end()) {
+                       (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), *i));
+               }
+       }
+}
+