diff options
Diffstat (limited to 'libs/ardour/region.cc')
-rw-r--r-- | libs/ardour/region.cc | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index e8353ac529..6c7e72be46 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -48,7 +48,7 @@ Change Region::LockChanged = ARDOUR::new_change (); Change Region::LayerChanged = ARDOUR::new_change (); Change Region::HiddenChanged = ARDOUR::new_change (); -Region::Region (jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Region::Flag flags) +Region::Region (nframes_t start, nframes_t length, const string& name, layer_t layer, Region::Flag flags) { /* basic Region constructor */ @@ -70,7 +70,7 @@ Region::Region (jack_nframes_t start, jack_nframes_t length, const string& name, _last_layer_op = 0; } -Region::Region (boost::shared_ptr<const Region> other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags) +Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags) { /* create a new Region from part of an existing one */ @@ -230,7 +230,7 @@ Region::set_name (string str) } void -Region::set_length (jack_nframes_t len, void *src) +Region::set_length (nframes_t len, void *src) { if (_flags & Locked) { return; @@ -238,6 +238,14 @@ Region::set_length (jack_nframes_t len, void *src) if (_length != len && len != 0) { + /* check that the current _position wouldn't make the new + length impossible. + */ + + if (max_frames - len < _position) { + return; + } + if (!verify_length (len)) { return; } @@ -294,7 +302,7 @@ Region::move_to_natural_position (void *src) } void -Region::special_set_position (jack_nframes_t pos) +Region::special_set_position (nframes_t pos) { /* this is used when creating a whole file region as a way to store its "natural" or "captured" position. @@ -304,7 +312,7 @@ Region::special_set_position (jack_nframes_t pos) } void -Region::set_position (jack_nframes_t pos, void *src) +Region::set_position (nframes_t pos, void *src) { if (_flags & Locked) { return; @@ -313,6 +321,16 @@ Region::set_position (jack_nframes_t pos, void *src) if (_position != pos) { _position = pos; + /* check that the new _position wouldn't make the current + length impossible - if so, change the length. + + XXX is this the right thing to do? + */ + + if (max_frames - _length < _position) { + _length = max_frames - _position; + } + if (!_frozen) { char buf[64]; snprintf (buf, sizeof (buf), "position set to %u", pos); @@ -328,7 +346,7 @@ Region::set_position (jack_nframes_t pos, void *src) } void -Region::set_position_on_top (jack_nframes_t pos, void *src) +Region::set_position_on_top (nframes_t pos, void *src) { if (_flags & Locked) { return; @@ -371,7 +389,7 @@ Region::nudge_position (long n, void *src) _position += n; } } else { - if (_position < (jack_nframes_t) -n) { + if (_position < (nframes_t) -n) { _position = 0; } else { _position += n; @@ -388,7 +406,7 @@ Region::nudge_position (long n, void *src) } void -Region::set_start (jack_nframes_t pos, void *src) +Region::set_start (nframes_t pos, void *src) { if (_flags & Locked) { return; @@ -419,12 +437,12 @@ Region::set_start (jack_nframes_t pos, void *src) } void -Region::trim_start (jack_nframes_t new_position, void *src) +Region::trim_start (nframes_t new_position, void *src) { if (_flags & Locked) { return; } - jack_nframes_t new_start; + nframes_t new_start; int32_t start_shift; if (new_position > _position) { @@ -447,7 +465,7 @@ Region::trim_start (jack_nframes_t new_position, void *src) } else if (start_shift < 0) { - if (_start < (jack_nframes_t) -start_shift) { + if (_start < (nframes_t) -start_shift) { new_start = 0; } else { new_start = _start + start_shift; @@ -474,14 +492,14 @@ Region::trim_start (jack_nframes_t new_position, void *src) } void -Region::trim_front (jack_nframes_t new_position, void *src) +Region::trim_front (nframes_t new_position, void *src) { if (_flags & Locked) { return; } - jack_nframes_t end = _position + _length - 1; - jack_nframes_t source_zero; + nframes_t end = last_frame(); + nframes_t source_zero; if (_position > _start) { source_zero = _position - _start; @@ -491,7 +509,7 @@ Region::trim_front (jack_nframes_t new_position, void *src) if (new_position < end) { /* can't trim it zero or negative length */ - jack_nframes_t newlen; + nframes_t newlen; /* can't trim it back passed where source position zero is located */ @@ -512,7 +530,7 @@ Region::trim_front (jack_nframes_t new_position, void *src) } void -Region::trim_end (jack_nframes_t new_endpoint, void *src) +Region::trim_end (nframes_t new_endpoint, void *src) { if (_flags & Locked) { return; @@ -527,7 +545,7 @@ Region::trim_end (jack_nframes_t new_endpoint, void *src) } void -Region::trim_to (jack_nframes_t position, jack_nframes_t length, void *src) +Region::trim_to (nframes_t position, nframes_t length, void *src) { if (_flags & Locked) { return; @@ -542,10 +560,10 @@ Region::trim_to (jack_nframes_t position, jack_nframes_t length, void *src) } void -Region::trim_to_internal (jack_nframes_t position, jack_nframes_t length, void *src) +Region::trim_to_internal (nframes_t position, nframes_t length, void *src) { int32_t start_shift; - jack_nframes_t new_start; + nframes_t new_start; if (_flags & Locked) { return; @@ -568,7 +586,7 @@ Region::trim_to_internal (jack_nframes_t position, jack_nframes_t length, void * } else if (start_shift < 0) { - if (_start < (jack_nframes_t) -start_shift) { + if (_start < (nframes_t) -start_shift) { new_start = 0; } else { new_start = _start + start_shift; @@ -693,9 +711,9 @@ Region::set_locked (bool yn) } void -Region::set_sync_position (jack_nframes_t absolute_pos) +Region::set_sync_position (nframes_t absolute_pos) { - jack_nframes_t file_pos; + nframes_t file_pos; file_pos = _start + (absolute_pos - _position); @@ -728,7 +746,7 @@ Region::clear_sync_position () } } -jack_nframes_t +nframes_t Region::sync_offset (int& dir) const { /* returns the sync point relative the first frame of the region */ @@ -747,11 +765,11 @@ Region::sync_offset (int& dir) const } } -jack_nframes_t -Region::adjust_to_sync (jack_nframes_t pos) +nframes_t +Region::adjust_to_sync (nframes_t pos) { int sync_dir; - jack_nframes_t offset = sync_offset (sync_dir); + nframes_t offset = sync_offset (sync_dir); if (sync_dir > 0) { if (max_frames - pos > offset) { @@ -768,7 +786,7 @@ Region::adjust_to_sync (jack_nframes_t pos) return pos; } -jack_nframes_t +nframes_t Region::sync_position() const { if (_flags & SyncMarked) { @@ -894,15 +912,15 @@ Region::set_state (const XMLNode& node) _name = prop->value(); if ((prop = node.property ("start")) != 0) { - _start = (jack_nframes_t) atoi (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &_start); } if ((prop = node.property ("length")) != 0) { - _length = (jack_nframes_t) atoi (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &_length); } if ((prop = node.property ("position")) != 0) { - _position = (jack_nframes_t) atoi (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &_position); } if ((prop = node.property ("layer")) != 0) { @@ -912,7 +930,7 @@ Region::set_state (const XMLNode& node) /* note: derived classes set flags */ if ((prop = node.property ("sync-position")) != 0) { - _sync_position = (jack_nframes_t) atoi (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &_sync_position); } else { _sync_position = _start; } |