X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fregion.cc;h=d49ed933c935214ab1afa942137bf4f26aa12940;hb=5a8bc070cd5ca79a53487f536c6df966ffc8df39;hp=6c7e72be4643c20e9296202b332af32b962ede45;hpb=93c7aeba048f19df5abee5e4325ef8b0ef62c279;p=ardour.git diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 6c7e72be46..d49ed933c9 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -64,7 +65,6 @@ Region::Region (nframes_t start, nframes_t length, const string& name, layer_t l _length = length; _position = 0; _layer = layer; - _current_state_id = 0; _read_data_count = 0; _first_edit = EditChangesNothing; _last_layer_op = 0; @@ -90,7 +90,6 @@ Region::Region (boost::shared_ptr other, nframes_t offset, nframes _position = 0; _layer = layer; _flags = Flag (flags & ~(Locked|WholeFile|Hidden)); - _current_state_id = 0; _first_edit = EditChangesNothing; _last_layer_op = 0; } @@ -120,7 +119,6 @@ Region::Region (boost::shared_ptr other) _position = other->_position; _layer = other->_layer; _flags = Flag (other->_flags & ~Locked); - _current_state_id = 0; _last_layer_op = other->_last_layer_op; } @@ -137,7 +135,6 @@ Region::Region (const XMLNode& node) _position = 0; _layer = 0; _flags = Flag (0); - _current_state_id = 0; _first_edit = EditChangesNothing; if (set_state (node)) { @@ -147,9 +144,7 @@ Region::Region (const XMLNode& node) Region::~Region () { - notify_callbacks (); - - /* derived classes must emit GoingAway */ + /* derived classes must call notify_callbacks() and then emit GoingAway */ } void @@ -158,70 +153,8 @@ Region::set_playlist (Playlist* pl) _playlist = pl; } -void -Region::store_state (RegionState& state) const -{ - state._start = _start; - state._length = _length; - state._position = _position; - state._flags = _flags; - state._sync_position = _sync_position; - state._layer = _layer; - state._name = _name; - state._first_edit = _first_edit; -} - -Change -Region::restore_and_return_flags (RegionState& state) -{ - Change what_changed = Change (0); - - { - Glib::Mutex::Lock lm (lock); - - if (_start != state._start) { - what_changed = Change (what_changed|StartChanged); - _start = state._start; - } - if (_length != state._length) { - what_changed = Change (what_changed|LengthChanged); - _length = state._length; - } - if (_position != state._position) { - what_changed = Change (what_changed|PositionChanged); - _position = state._position; - } - if (_sync_position != state._sync_position) { - _sync_position = state._sync_position; - what_changed = Change (what_changed|SyncOffsetChanged); - } - if (_layer != state._layer) { - what_changed = Change (what_changed|LayerChanged); - _layer = state._layer; - } - - uint32_t old_flags = _flags; - _flags = Flag (state._flags); - - if ((old_flags ^ state._flags) & Muted) { - what_changed = Change (what_changed|MuteChanged); - } - if ((old_flags ^ state._flags) & Opaque) { - what_changed = Change (what_changed|OpacityChanged); - } - if ((old_flags ^ state._flags) & Locked) { - what_changed = Change (what_changed|LockChanged); - } - - _first_edit = state._first_edit; - } - - return what_changed; -} - void Region::set_name (string str) - { if (_name != str) { _name = str; @@ -259,10 +192,6 @@ Region::set_length (nframes_t len, void *src) if (!_frozen) { recompute_at_end (); - - char buf[64]; - snprintf (buf, sizeof (buf), "length set to %u", len); - save_state (buf); } send_change (LengthChanged); @@ -293,7 +222,7 @@ Region::move_to_natural_position (void *src) if (!_playlist) { return; } - + boost::shared_ptr whole_file_region = get_parent(); if (whole_file_region) { @@ -330,12 +259,6 @@ Region::set_position (nframes_t pos, void *src) if (max_frames - _length < _position) { _length = max_frames - _position; } - - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "position set to %u", pos); - save_state (buf); - } } /* do this even if the position is the same. this helps out @@ -354,15 +277,9 @@ Region::set_position_on_top (nframes_t pos, void *src) if (_position != pos) { _position = pos; - - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "position set to %u", pos); - save_state (buf); - } } - _playlist->raise_region_to_top (boost::shared_ptr(this)); + _playlist->raise_region_to_top (shared_from_this ()); /* do this even if the position is the same. this helps out a GUI that has moved its representation already. @@ -396,12 +313,6 @@ Region::nudge_position (long n, void *src) } } - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "position set to %u", _position); - save_state (buf); - } - send_change (PositionChanged); } @@ -426,12 +337,6 @@ Region::set_start (nframes_t pos, void *src) _flags = Region::Flag (_flags & ~WholeFile); first_edit (); - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "start set to %u", pos); - save_state (buf); - } - send_change (StartChanged); } } @@ -482,12 +387,6 @@ Region::trim_start (nframes_t new_position, void *src) _flags = Region::Flag (_flags & ~WholeFile); first_edit (); - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "slipped start to %u", _start); - save_state (buf); - } - send_change (StartChanged); } @@ -621,13 +520,6 @@ Region::trim_to_internal (nframes_t position, nframes_t length, void *src) } if (what_changed) { - - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "trimmed to %u-%u", _position, _position+_length-1); - save_state (buf); - } - send_change (what_changed); } } @@ -658,16 +550,6 @@ Region::set_muted (bool yn) _flags = Flag (_flags & ~Muted); } - if (!_frozen) { - char buf[64]; - if (yn) { - snprintf (buf, sizeof (buf), "muted"); - } else { - snprintf (buf, sizeof (buf), "unmuted"); - } - save_state (buf); - } - send_change (MuteChanged); } } @@ -676,16 +558,10 @@ void Region::set_opaque (bool yn) { if (opaque() != yn) { - if (!_frozen) { - char buf[64]; - if (yn) { - snprintf (buf, sizeof (buf), "opaque"); - _flags = Flag (_flags|Opaque); - } else { - snprintf (buf, sizeof (buf), "translucent"); - _flags = Flag (_flags & ~Opaque); - } - save_state (buf); + if (yn) { + _flags = Flag (_flags|Opaque); + } else { + _flags = Flag (_flags & ~Opaque); } send_change (OpacityChanged); } @@ -695,16 +571,10 @@ void Region::set_locked (bool yn) { if (locked() != yn) { - if (!_frozen) { - char buf[64]; - if (yn) { - snprintf (buf, sizeof (buf), "locked"); - _flags = Flag (_flags|Locked); - } else { - snprintf (buf, sizeof (buf), "unlocked"); - _flags = Flag (_flags & ~Locked); - } - save_state (buf); + if (yn) { + _flags = Flag (_flags|Locked); + } else { + _flags = Flag (_flags & ~Locked); } send_change (LockChanged); } @@ -723,10 +593,7 @@ Region::set_sync_position (nframes_t absolute_pos) _flags = Flag (_flags|SyncMarked); if (!_frozen) { - char buf[64]; maybe_uncopy (); - snprintf (buf, sizeof (buf), "sync point set to %u", _sync_position); - save_state (buf); } send_change (SyncOffsetChanged); } @@ -740,7 +607,6 @@ Region::clear_sync_position () if (!_frozen) { maybe_uncopy (); - save_state ("sync point removed"); } send_change (SyncOffsetChanged); } @@ -804,7 +670,7 @@ Region::raise () return; } - _playlist->raise_region (boost::shared_ptr(this)); + _playlist->raise_region (shared_from_this ()); } void @@ -814,7 +680,7 @@ Region::lower () return; } - _playlist->lower_region (boost::shared_ptr(this)); + _playlist->lower_region (shared_from_this ()); } void @@ -825,7 +691,7 @@ Region::raise_to_top () return; } - _playlist->raise_region_to_top (boost::shared_ptr(this)); + _playlist->raise_region_to_top (shared_from_this()); } void @@ -835,7 +701,7 @@ Region::lower_to_bottom () return; } - _playlist->lower_region_to_bottom (boost::shared_ptr(this)); + _playlist->lower_region_to_bottom (shared_from_this()); } void @@ -844,12 +710,6 @@ Region::set_layer (layer_t l) if (_layer != l) { _layer = l; - if (!_frozen) { - char buf[64]; - snprintf (buf, sizeof (buf), "layer set to %" PRIu32, _layer); - save_state (buf); - } - send_change (LayerChanged); } } @@ -859,8 +719,9 @@ Region::state (bool full_state) { XMLNode *node = new XMLNode ("Region"); char buf[64]; - - _id.print (buf); + char* fe; + + _id.print (buf, sizeof (buf)); node->add_property ("id", buf); node->add_property ("name", _name); snprintf (buf, sizeof (buf), "%u", _start); @@ -869,6 +730,20 @@ Region::state (bool full_state) node->add_property ("length", buf); snprintf (buf, sizeof (buf), "%u", _position); node->add_property ("position", buf); + + switch (_first_edit) { + case EditChangesNothing: + fe = X_("nothing"); + break; + case EditChangesName: + fe = X_("name"); + break; + case EditChangesID: + fe = X_("id"); + break; + } + + node->add_property ("first_edit", fe); /* note: flags are stored by derived classes */ @@ -887,54 +762,83 @@ Region::get_state () } int -Region::set_state (const XMLNode& node) +Region::set_live_state (const XMLNode& node, Change& what_changed, bool send) { const XMLNodeList& nlist = node.children(); const XMLProperty *prop; + nframes_t val; - if (_extra_xml) { - delete _extra_xml; - _extra_xml = 0; - } - - if ((prop = node.property ("id")) == 0) { - error << _("Session: XMLNode describing a Region is incomplete (no id)") << endmsg; - return -1; - } - - _id = prop->value(); + /* this is responsible for setting those aspects of Region state + that are mutable after construction. + */ if ((prop = node.property ("name")) == 0) { - error << _("Session: XMLNode describing a Region is incomplete (no name)") << endmsg; + error << _("XMLNode describing a Region is incomplete (no name)") << endmsg; return -1; } _name = prop->value(); if ((prop = node.property ("start")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &_start); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _start) { + what_changed = Change (what_changed|StartChanged); + _start = val; + } + } else { + _start = 0; } if ((prop = node.property ("length")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &_length); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _length) { + what_changed = Change (what_changed|LengthChanged); + _length = val; + } + } else { + _length = 1; } if ((prop = node.property ("position")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &_position); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _position) { + what_changed = Change (what_changed|PositionChanged); + _position = val; + } + } else { + _position = 0; } if ((prop = node.property ("layer")) != 0) { - _layer = (layer_t) atoi (prop->value().c_str()); + layer_t x; + x = (layer_t) atoi (prop->value().c_str()); + if (x != _layer) { + what_changed = Change (what_changed|LayerChanged); + _layer = x; + } + } else { + _layer = 0; } - /* note: derived classes set flags */ - if ((prop = node.property ("sync-position")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &_sync_position); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _sync_position) { + what_changed = Change (what_changed|SyncOffsetChanged); + _sync_position = val; + } } else { _sync_position = _start; } + + /* XXX FIRST EDIT !!! */ + /* note: derived classes set flags */ + + if (_extra_xml) { + delete _extra_xml; + _extra_xml = 0; + } + for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) { XMLNode *child; @@ -947,7 +851,31 @@ Region::set_state (const XMLNode& node) } } + if (send) { + send_change (what_changed); + } + + return 0; +} + +int +Region::set_state (const XMLNode& node) +{ + const XMLProperty *prop; + Change what_changed = Change (0); + + /* ID is not allowed to change, ever */ + + if ((prop = node.property ("id")) == 0) { + error << _("Session: XMLNode describing a Region is incomplete (no id)") << endmsg; + return -1; + } + + _id = prop->value(); + _first_edit = EditChangesNothing; + + set_live_state (node, what_changed, true); return 0; } @@ -987,7 +915,6 @@ Region::thaw (const string& why) recompute_at_end (); } - save_state (why); StateChanged (what_changed); } @@ -1002,7 +929,7 @@ Region::send_change (Change what_changed) } } - StateManager::send_state_changed (what_changed); + StateChanged (what_changed); } void