initial check in of VBAP implementation (not coupled to any existing ardour objects...
[ardour.git] / libs / ardour / region.cc
index 9d8e4e8ca01613d96cea0a3ebacae7acbd8277bc..33338e52ea8fa2597e8c7d51cf362b36c78635b3 100644 (file)
@@ -182,29 +182,29 @@ Region::register_properties ()
        , _position_lock_style (Properties::position_lock_style, _type == DataType::AUDIO ? AudioTime : MusicTime)
 
 #define REGION_COPY_STATE(other) \
-         _muted (other->_muted) \
-       , _opaque (other->_opaque) \
-       , _locked (other->_locked) \
-       , _automatic (other->_automatic) \
-       , _whole_file (other->_whole_file) \
-       , _import (other->_import) \
-       , _external (other->_external) \
-       , _sync_marked (other->_sync_marked) \
-       , _left_of_split (other->_left_of_split) \
-       , _right_of_split (other->_right_of_split) \
-       , _hidden (other->_hidden) \
-       , _position_locked (other->_position_locked) \
-       , _valid_transients (other->_valid_transients) \
-       , _start(other->_start) \
-       , _length(other->_length) \
-       , _position(other->_position) \
-       , _sync_position(other->_sync_position) \
-        , _layer (other->_layer) \
-       , _ancestral_start (other->_ancestral_start) \
-       , _ancestral_length (other->_ancestral_length) \
-       , _stretch (other->_stretch) \
-       , _shift (other->_shift) \
-       , _position_lock_style (other->_position_lock_style)
+         _muted (Properties::muted, other->_muted)                     \
+       , _opaque (Properties::opaque, other->_opaque)          \
+       , _locked (Properties::locked, other->_locked)          \
+       , _automatic (Properties::automatic, other->_automatic) \
+       , _whole_file (Properties::whole_file, other->_whole_file) \
+       , _import (Properties::import, other->_import)          \
+       , _external (Properties::external, other->_external)    \
+       , _sync_marked (Properties::sync_marked, other->_sync_marked) \
+       , _left_of_split (Properties::left_of_split, other->_left_of_split) \
+       , _right_of_split (Properties::right_of_split, other->_right_of_split) \
+       , _hidden (Properties::hidden, other->_hidden)          \
+       , _position_locked (Properties::position_locked, other->_position_locked) \
+       , _valid_transients (Properties::valid_transients, other->_valid_transients) \
+       , _start(Properties::start, other->_start)              \
+       , _length(Properties::length, other->_length)           \
+       , _position(Properties::position, other->_position)     \
+       , _sync_position(Properties::sync_position, other->_sync_position) \
+       , _layer (Properties::layer, other->_layer)             \
+       , _ancestral_start (Properties::ancestral_start, other->_ancestral_start) \
+       , _ancestral_length (Properties::ancestral_length, other->_ancestral_length) \
+       , _stretch (Properties::stretch, other->_stretch)       \
+       , _shift (Properties::shift, other->_shift)             \
+       , _position_lock_style (Properties::position_lock_style, other->_position_lock_style)
 
 /* derived-from-derived constructor (no sources in constructor) */
 Region::Region (Session& s, framepos_t start, framecnt_t length, const string& name, DataType type)
@@ -247,10 +247,10 @@ Region::Region (const SourceList& srcs)
 
 /** Create a new Region from part of an existing one, starting at one of two places:
 
-    if @param offset_relative is true, then the start within @param other is given by @param offset
-    (i.e. relative to the start of @param other's sources, the start is @param offset + @param other.start()
+    if \a offset_relative is true, then the start within \a other is given by \a offset
+    (i.e. relative to the start of \a other's sources, the start is \a offset + \a other.start()
 
-    if @param offset_relative is false, then the start within the source is given @param offset.
+    if @param offset_relative is false, then the start within the source is given \a offset.
 */
 Region::Region (boost::shared_ptr<const Region> other, frameoffset_t offset, bool offset_relative)
        : SessionObject(other->session(), other->name())
@@ -452,7 +452,7 @@ Region::set_length (framecnt_t len, void */*src*/)
                   length impossible.
                */
 
-               if (max_frames - len < _position) {
+               if (max_framepos - len < _position) {
                        return;
                }
 
@@ -602,9 +602,9 @@ Region::set_position_internal (framepos_t pos, bool allow_bbt_recompute)
                   XXX is this the right thing to do?
                */
 
-               if (max_frames - _length < _position) {
+               if (max_framepos - _length < _position) {
                        _last_length = _length;
-                       _length = max_frames - _position;
+                       _length = max_framepos - _position;
                }
 
                if (allow_bbt_recompute) {
@@ -667,8 +667,8 @@ Region::nudge_position (frameoffset_t n, void* /*src*/)
        _last_position = _position;
 
        if (n > 0) {
-               if (_position > max_frames - n) {
-                       _position = max_frames;
+               if (_position > max_framepos - n) {
+                       _position = max_framepos;
                } else {
                        _position += n;
                }
@@ -735,8 +735,8 @@ Region::trim_start (framepos_t new_position, void */*src*/)
 
        if (start_shift > 0) {
 
-               if (_start > max_frames - start_shift) {
-                       new_start = max_frames;
+               if (_start > max_framepos - start_shift) {
+                       new_start = max_framepos;
                } else {
                        new_start = _start + start_shift;
                }
@@ -804,7 +804,7 @@ Region::modify_front (nframes_t new_position, bool reset_fade, void *src)
        if (new_position < end) { /* can't trim it zero or negative length */
                
                nframes_t newlen = 0;
-               nframes64_t delta = 0;
+               framepos_t delta = 0;
 
                /* can't trim it back passed where source position zero is located */
                
@@ -835,7 +835,7 @@ Region::modify_front (nframes_t new_position, bool reset_fade, void *src)
 }
 
 void
-Region::modify_end (nframes_t new_endpoint, bool reset_fade, void *src)
+Region::modify_end (nframes_t new_endpoint, bool reset_fade, void* /*src*/)
 {
        if (locked()) {
                return;
@@ -895,8 +895,8 @@ Region::trim_to_internal (framepos_t position, framecnt_t length, void */*src*/)
 
        if (start_shift > 0) {
 
-               if (_start > max_frames - start_shift) {
-                       new_start = max_frames;
+               if (_start > max_framepos - start_shift) {
+                       new_start = max_framepos;
                } else {
                        new_start = _start + start_shift;
                }
@@ -1013,9 +1013,13 @@ Region::set_position_locked (bool yn)
        }
 }
 
+/** Set the region's sync point.
+ *  @param absolute_pos Session time.
+ */
 void
 Region::set_sync_position (framepos_t absolute_pos)
 {
+       /* position within our file */
        framepos_t const file_pos = _start + (absolute_pos - _position);
 
        if (file_pos != _sync_position) {
@@ -1040,11 +1044,10 @@ Region::clear_sync_position ()
        }
 }
 
+/* @return the sync point relative the first frame of the region */
 framepos_t
 Region::sync_offset (int& dir) const
 {
-       /* returns the sync point relative the first frame of the region */
-
        if (sync_marked()) {
                if (_sync_position > _start) {
                        dir = 1;
@@ -1074,7 +1077,7 @@ Region::adjust_to_sync (framepos_t pos) const
                        pos = 0;
                }
        } else {
-               if (max_frames - pos > offset) {
+               if (max_framepos - pos > offset) {
                        pos += offset;
                }
        }
@@ -1082,13 +1085,15 @@ Region::adjust_to_sync (framepos_t pos) const
        return pos;
 }
 
+/** @return Sync position in session time */
 framepos_t
 Region::sync_position() const
 {
        if (sync_marked()) {
-               return _sync_position;
+               return _position - _start + _sync_position;
        } else {
-               return _start;
+               /* if sync has not been marked, use the start of the region */
+               return _position;
        }
 }
 
@@ -1140,7 +1145,7 @@ Region::set_layer (layer_t l)
 }
 
 XMLNode&
-Region::state (bool full)
+Region::state ()
 {
        XMLNode *node = new XMLNode ("Region");
        char buf[64];
@@ -1191,7 +1196,7 @@ Region::state (bool full)
                node->add_property (buf2, buf);
        }
 
-       if (full && _extra_xml) {
+       if (_extra_xml) {
                node->add_child_copy (*_extra_xml);
        }
 
@@ -1201,7 +1206,7 @@ Region::state (bool full)
 XMLNode&
 Region::get_state ()
 {
-       return state (true);
+       return state ();
 }
 
 int
@@ -1212,11 +1217,11 @@ Region::set_state (const XMLNode& node, int version)
 }
 
 int
-Region::_set_state (const XMLNode& node, int version, PropertyChange& what_changed, bool send)
+Region::_set_state (const XMLNode& node, int /*version*/, PropertyChange& what_changed, bool send)
 {
        const XMLProperty* prop;
 
-       what_changed = set_properties (node);
+       what_changed = set_values (node);
 
        if ((prop = node.property (X_("id")))) {
                _id = prop->value();
@@ -1305,7 +1310,7 @@ Region::send_change (const PropertyChange& what_changed)
 
         Stateful::send_change (what_changed);
 
-       if (!_no_property_changes) {
+       if (!Stateful::frozen()) {
                
                /* Try and send a shared_pointer unless this is part of the constructor.
                   If so, do nothing.
@@ -1388,7 +1393,6 @@ void
 Region::set_master_sources (const SourceList& srcs)
 {
         for (SourceList::const_iterator i = _master_sources.begin (); i != _master_sources.end(); ++i) {
-                cerr << name() << " " << id() << " DEC M SMS\n";
                 (*i)->dec_use_count ();
         }
 
@@ -1405,6 +1409,11 @@ Region::source_equivalent (boost::shared_ptr<const Region> other) const
 {
        if (!other)
                return false;
+        
+        if ((_sources.size() != other->_sources.size()) ||
+            (_master_sources.size() != other->_master_sources.size())) {
+                return false;
+        }
 
        SourceList::const_iterator i;
        SourceList::const_iterator io;
@@ -1435,11 +1444,11 @@ Region::uses_source (boost::shared_ptr<const Source> source) const
        return false;
 }
 
-sframes_t
+framecnt_t
 Region::source_length(uint32_t n) const
 {
         assert (n < _sources.size());
-       return _sources[n]->length(_position - _start);
+       return _sources[n]->length (_position - _start);
 }
 
 bool
@@ -1526,9 +1535,9 @@ Region::get_parent() const
 }
 
 int
-Region::apply (Filter& filter)
+Region::apply (Filter& filter, Progress* progress)
 {
-       return filter.run (shared_from_this());
+       return filter.run (shared_from_this(), progress);
 }
 
 
@@ -1579,18 +1588,30 @@ Region::use_sources (SourceList const & s)
        }
 }
 
-PropertyList*
-Region::property_factory (const XMLNode& history_node) const
+Trimmable::CanTrim
+Region::can_trim () const
 {
-        PropertyList* prop_list = new PropertyList;
+        CanTrim ct = CanTrim (0);
+
+        if (locked()) {
+                return ct;
+        }
+
+        /* if not locked, we can always move the front later, and the end earlier 
+         */
 
-        for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
-                PropertyBase* prop = i->second->maybe_clone_self_if_found_in_history_node (history_node);
+        ct = CanTrim (ct | FrontTrimLater | EndTrimEarlier);
+
+        if (start() != 0) {
+                ct = CanTrim (ct | FrontTrimEarlier);
+        }
 
-                if (prop) {
-                        prop_list->add (prop);
+        if (!_sources.empty()) {
+                if ((start() + length()) < _sources.front()->length (0)) {
+                        ct = CanTrim (ct | EndTrimLater);
                 }
         }
 
-        return prop_list;
+        return ct;
 }
+