#include <ardour/region.h>
#include <ardour/playlist.h>
#include <ardour/session.h>
+#include <ardour/region_factory.h>
#include "i18n.h"
using namespace ARDOUR;
using namespace PBD;
-Change Region::FadeChanged = ARDOUR::new_change ();
+Change Region::FadeChanged = ARDOUR::new_change ();
Change Region::SyncOffsetChanged = ARDOUR::new_change ();
-Change Region::MuteChanged = ARDOUR::new_change ();
-Change Region::OpacityChanged = ARDOUR::new_change ();
-Change Region::LockChanged = ARDOUR::new_change ();
-Change Region::LayerChanged = ARDOUR::new_change ();
-Change Region::HiddenChanged = ARDOUR::new_change ();
+Change Region::MuteChanged = ARDOUR::new_change ();
+Change Region::OpacityChanged = ARDOUR::new_change ();
+Change Region::LockChanged = ARDOUR::new_change ();
+Change Region::LayerChanged = ARDOUR::new_change ();
+Change Region::HiddenChanged = ARDOUR::new_change ();
-sigc::signal<void,Region *> Region::CheckNewRegion;
-
-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 */
_last_layer_op = 0;
}
-Region::Region (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 */
_playlist = 0;
_read_data_count = 0;
- _start = other._start + offset;
- if (other._sync_position < offset) {
- _sync_position = other._sync_position;
+ _start = other->_start + offset;
+ if (other->_sync_position < offset) {
+ _sync_position = other->_sync_position;
} else {
_sync_position = _start;
}
_last_layer_op = 0;
}
-Region::Region (const Region &other)
+Region::Region (boost::shared_ptr<const Region> other)
{
/* Pure copy constructor */
_read_data_count = 0;
_first_edit = EditChangesID;
- other._first_edit = EditChangesName;
+ other->_first_edit = EditChangesName;
- if (other._extra_xml) {
- _extra_xml = new XMLNode (*other._extra_xml);
+ if (other->_extra_xml) {
+ _extra_xml = new XMLNode (*other->_extra_xml);
} else {
_extra_xml = 0;
}
- _start = other._start;
- _sync_position = other._sync_position;
- _length = other._length;
- _name = other._name;
- _position = other._position;
- _layer = other._layer;
- _flags = Flag (other._flags & ~Locked);
+ _start = other->_start;
+ _sync_position = other->_sync_position;
+ _length = other->_length;
+ _name = other->_name;
+ _position = other->_position;
+ _layer = other->_layer;
+ _flags = Flag (other->_flags & ~Locked);
_current_state_id = 0;
- _last_layer_op = other._last_layer_op;
+ _last_layer_op = other->_last_layer_op;
}
Region::Region (const XMLNode& node)
Region::~Region ()
{
+ notify_callbacks ();
+
+ /* derived classes must emit GoingAway */
}
void
}
void
-Region::set_length (jack_nframes_t len, void *src)
+Region::set_length (nframes_t len, void *src)
{
if (_flags & Locked) {
return;
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;
}
_first_edit = EditChangesNothing;
send_change (NameChanged);
- CheckNewRegion (this);
+ RegionFactory::CheckNewRegion (shared_from_this());
}
}
return;
}
- Region* whole_file_region = get_parent();
+ boost::shared_ptr<Region> whole_file_region = get_parent();
if (whole_file_region) {
set_position (whole_file_region->position() + _start, 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.
}
void
-Region::set_position (jack_nframes_t pos, void *src)
+Region::set_position (nframes_t pos, void *src)
{
if (_flags & Locked) {
return;
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);
}
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;
}
}
- _playlist->raise_region_to_top (*this);
+ _playlist->raise_region_to_top (boost::shared_ptr<Region>(this));
/* do this even if the position is the same. this helps out
a GUI that has moved its representation already.
_position += n;
}
} else {
- if (_position < (jack_nframes_t) -n) {
+ if (_position < (nframes_t) -n) {
_position = 0;
} else {
_position += n;
}
void
-Region::set_start (jack_nframes_t pos, void *src)
+Region::set_start (nframes_t pos, void *src)
{
if (_flags & Locked) {
return;
}
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) {
} 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;
}
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;
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 */
}
void
-Region::trim_end (jack_nframes_t new_endpoint, void *src)
+Region::trim_end (nframes_t new_endpoint, void *src)
{
if (_flags & Locked) {
return;
}
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;
}
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;
} 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;
}
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);
}
}
-jack_nframes_t
+nframes_t
Region::sync_offset (int& dir) const
{
/* returns the sync point relative the first frame of the region */
}
}
-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) {
return pos;
}
-jack_nframes_t
+nframes_t
Region::sync_position() const
{
if (_flags & SyncMarked) {
return;
}
- _playlist->raise_region (*this);
+ _playlist->raise_region (boost::shared_ptr<Region>(this));
}
void
return;
}
- _playlist->lower_region (*this);
+ _playlist->lower_region (boost::shared_ptr<Region>(this));
}
void
return;
}
- _playlist->raise_region_to_top (*this);
+ _playlist->raise_region_to_top (boost::shared_ptr<Region>(this));
}
void
return;
}
- _playlist->lower_region_to_bottom (*this);
+ _playlist->lower_region_to_bottom (boost::shared_ptr<Region>(this));
}
void
XMLNode *node = new XMLNode ("Region");
char buf[64];
- _id.print (buf);
+ _id.print (buf, sizeof (buf));
node->add_property ("id", buf);
node->add_property ("name", _name);
snprintf (buf, sizeof (buf), "%u", _start);
_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) {
/* 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;
}
{
_last_layer_op = when;
}
+
+bool
+Region::overlap_equivalent (boost::shared_ptr<const Region> other) const
+{
+ return coverage (other->first_frame(), other->last_frame()) != OverlapNone;
+}
+
+bool
+Region::equivalent (boost::shared_ptr<const Region> other) const
+{
+ return _start == other->_start &&
+ _position == other->_position &&
+ _length == other->_length;
+}
+
+bool
+Region::size_equivalent (boost::shared_ptr<const Region> other) const
+{
+ return _start == other->_start &&
+ _length == other->_length;
+}
+
+bool
+Region::region_list_equivalent (boost::shared_ptr<const Region> other) const
+{
+ return size_equivalent (other) && source_equivalent (other) && _name == other->_name;
+}