- while (itimes--) {
- boost::shared_ptr<Region> copy = RegionFactory::create (region);
- add_region_internal (copy, pos);
- pos += region->length();
- }
-
- if (floor (times) != times) {
- framecnt_t length = (framecnt_t) floor (region->length() * (times - floor (times)));
- string name;
- RegionFactory::region_name (name, region->name(), false);
-
- {
- PropertyList plist;
-
- plist.add (Properties::start, region->start());
- plist.add (Properties::length, length);
- plist.add (Properties::name, name);
-
- boost::shared_ptr<Region> sub = RegionFactory::create (region, plist);
- add_region_internal (sub, pos);
- }
- }
-}
-
-void
-Playlist::shift (framepos_t at, frameoffset_t distance, bool move_intersected, bool ignore_music_glue)
-{
- RegionLock rlock (this);
- RegionList copy (regions.rlist());
- RegionList fixup;
-
- for (RegionList::iterator r = copy.begin(); r != copy.end(); ++r) {
-
- if ((*r)->last_frame() < at) {
- /* too early */
- continue;
- }
-
- if (at > (*r)->first_frame() && at < (*r)->last_frame()) {
- /* intersected region */
- if (!move_intersected) {
- continue;
- }
- }
-
- /* do not move regions glued to music time - that
- has to be done separately.
- */
-
- if (!ignore_music_glue && (*r)->position_lock_style() != AudioTime) {
- fixup.push_back (*r);
- continue;
- }
-
- (*r)->set_position ((*r)->position() + distance, this);
- }
-
- for (RegionList::iterator r = fixup.begin(); r != fixup.end(); ++r) {
- (*r)->recompute_position_from_lock_style ();
- }
-}
-
-void
-Playlist::split (framepos_t at)
-{
- RegionLock rlock (this);
- RegionList copy (regions.rlist());
-
- /* use a copy since this operation can modify the region list
- */
-
- for (RegionList::iterator r = copy.begin(); r != copy.end(); ++r) {
- _split_region (*r, at);
- }
-}
-
-void
-Playlist::split_region (boost::shared_ptr<Region> region, framepos_t playlist_position)
-{
- RegionLock rl (this);
- _split_region (region, playlist_position);
-}
-
-void
-Playlist::_split_region (boost::shared_ptr<Region> region, framepos_t playlist_position)
-{
- if (!region->covers (playlist_position)) {
- return;
- }
-
- if (region->position() == playlist_position ||
- region->last_frame() == playlist_position) {
- return;
- }
-
- boost::shared_ptr<Region> left;
- boost::shared_ptr<Region> right;
- frameoffset_t before;
- frameoffset_t after;
- string before_name;
- string after_name;
-
- /* split doesn't change anything about length, so don't try to splice */
-
- bool old_sp = _splicing;
- _splicing = true;
-
- before = playlist_position - region->position();
- after = region->length() - before;
-
- RegionFactory::region_name (before_name, region->name(), false);
-
- {
- PropertyList plist;
-
- plist.add (Properties::length, before);
- plist.add (Properties::name, before_name);
- plist.add (Properties::left_of_split, true);
-
- /* note: we must use the version of ::create with an offset here,
- since it supplies that offset to the Region constructor, which
- is necessary to get audio region gain envelopes right.
- */
- left = RegionFactory::create (region, 0, plist);
- }
-
- RegionFactory::region_name (after_name, region->name(), false);
-
- {
- PropertyList plist;
-
- plist.add (Properties::length, after);
- plist.add (Properties::name, after_name);
- plist.add (Properties::right_of_split, true);
-
- /* same note as above */
- right = RegionFactory::create (region, before, plist);
- }
-
- add_region_internal (left, region->position());
- add_region_internal (right, region->position() + before);
-
- uint64_t orig_layer_op = region->last_layer_op();
- for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
- if ((*i)->last_layer_op() > orig_layer_op) {
- (*i)->set_last_layer_op( (*i)->last_layer_op() + 1 );
- }
- }
-
- left->set_last_layer_op ( orig_layer_op );
- right->set_last_layer_op ( orig_layer_op + 1);
-
- layer_op_counter++;
-
- finalize_split_region (region, left, right);
-
- remove_region_internal (region);
-
- _splicing = old_sp;
-}
-
-void
-Playlist::possibly_splice (framepos_t at, framecnt_t distance, boost::shared_ptr<Region> exclude)
-{
- if (_splicing || in_set_state) {
- /* don't respond to splicing moves or state setting */
- return;
- }
-
- if (_edit_mode == Splice) {
- splice_locked (at, distance, exclude);
- }
-}
-
-void
-Playlist::possibly_splice_unlocked (framepos_t at, framecnt_t distance, boost::shared_ptr<Region> exclude)
-{
- if (_splicing || in_set_state) {
- /* don't respond to splicing moves or state setting */
- return;
- }
-
- if (_edit_mode == Splice) {
- splice_unlocked (at, distance, exclude);
- }
-}
-
-void
-Playlist::splice_locked (framepos_t at, framecnt_t distance, boost::shared_ptr<Region> exclude)
-{
- {
- RegionLock rl (this);
- core_splice (at, distance, exclude);
- }
-}
-
-void
-Playlist::splice_unlocked (framepos_t at, framecnt_t distance, boost::shared_ptr<Region> exclude)
-{
- core_splice (at, distance, exclude);
-}
-
-void
-Playlist::core_splice (framepos_t at, framecnt_t distance, boost::shared_ptr<Region> exclude)
-{
- _splicing = true;
-
- for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-
- if (exclude && (*i) == exclude) {
- continue;
- }
-
- if ((*i)->position() >= at) {
- framepos_t new_pos = (*i)->position() + distance;
- if (new_pos < 0) {
- new_pos = 0;
- } else if (new_pos >= max_frames - (*i)->length()) {
- new_pos = max_frames - (*i)->length();
- }
-
- (*i)->set_position (new_pos, this);
- }
- }
-
- _splicing = false;
-
- notify_length_changed ();
-}
-
-void
-Playlist::region_bounds_changed (const PropertyChange& what_changed, boost::shared_ptr<Region> region)
-{
- if (in_set_state || _splicing || _nudging || _shuffling) {
- return;
- }
-
- if (what_changed.contains (Properties::position)) {
-
- /* remove it from the list then add it back in
- the right place again.
- */
-
- RegionSortByPosition cmp;
-
- RegionList::iterator i = find (regions.begin(), regions.end(), region);
-
- if (i == regions.end()) {
- /* the region bounds are being modified but its not currently
- in the region list. we will use its bounds correctly when/if
- it is added
- */
- return;
- }
-
- regions.erase (i);
- regions.insert (upper_bound (regions.begin(), regions.end(), region, cmp), region);
- }
-
- if (what_changed.contains (Properties::position) || what_changed.contains (Properties::length)) {
-
- frameoffset_t delta = 0;
-
- if (what_changed.contains (Properties::position)) {
- delta = region->position() - region->last_position();
- }
-
- if (what_changed.contains (Properties::length)) {
- delta += region->length() - region->last_length();
- }
-
- if (delta) {
- possibly_splice (region->last_position() + region->last_length(), delta, region);
- }
-
- if (holding_state ()) {
- pending_bounds.push_back (region);
- } else {
- if (_session.config.get_layer_model() == MoveAddHigher) {
- /* it moved or changed length, so change the timestamp */
- timestamp_layer_op (region);
- }
-
- notify_length_changed ();
- relayer ();
- check_dependents (region, false);
- }
- }
-}
-
-void
-Playlist::region_changed_proxy (const PropertyChange& what_changed, boost::weak_ptr<Region> weak_region)
-{
- boost::shared_ptr<Region> region (weak_region.lock());
-
- if (!region) {
- return;
- }
-
- /* this makes a virtual call to the right kind of playlist ... */
-
- region_changed (what_changed, region);
-}
-
-bool
-Playlist::region_changed (const PropertyChange& what_changed, boost::shared_ptr<Region> region)
-{
- PropertyChange our_interests;
- PropertyChange bounds;
- PropertyChange pos_and_length;
- bool save = false;
-
- if (in_set_state || in_flush) {
- return false;
- }
-
- our_interests.add (Properties::muted);
- our_interests.add (Properties::layer);
- our_interests.add (Properties::opaque);
-
- bounds.add (Properties::start);
- bounds.add (Properties::position);
- bounds.add (Properties::length);
-
- pos_and_length.add (Properties::position);
- pos_and_length.add (Properties::length);
-
- if (what_changed.contains (bounds)) {
- region_bounds_changed (what_changed, region);
- save = !(_splicing || _nudging);
- }
-
- if (what_changed.contains (our_interests) && !what_changed.contains (pos_and_length)) {
- check_dependents (region, false);
- }
-
- if (what_changed.contains (Properties::position) && !what_changed.contains (Properties::length)) {
- notify_region_moved (region);
- }
-
-
- /* don't notify about layer changes, since we are the only object that can initiate
- them, and we notify in ::relayer()
- */
-
- if (what_changed.contains (our_interests)) {
- save = true;
- }
-
- return save;
-}
-
-void
-Playlist::drop_regions ()
-{
- RegionLock rl (this);
- regions.clear ();
- all_regions.clear ();
-}
-
-void
-Playlist::clear (bool with_signals)
-{
- {
- RegionLock rl (this);
-
- region_state_changed_connections.drop_connections ();
-
- for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
- pending_removes.insert (*i);
- }
-
- regions.clear ();
-
- for (set<boost::shared_ptr<Region> >::iterator s = pending_removes.begin(); s != pending_removes.end(); ++s) {
- remove_dependents (*s);
- }
- }
-
- if (with_signals) {
-
- for (set<boost::shared_ptr<Region> >::iterator s = pending_removes.begin(); s != pending_removes.end(); ++s) {
- RegionRemoved (boost::weak_ptr<Region> (*s)); /* EMIT SIGNAL */
- }
-
- pending_removes.clear ();
- pending_length = false;
- LengthChanged ();
- pending_contents_change = false;
- ContentsChanged ();
- }
-
-}
-
-/***********************************************************************
- FINDING THINGS
- **********************************************************************/
-
-Playlist::RegionList *
-Playlist::regions_at (framepos_t frame)
-
-{
- RegionLock rlock (this);
- return find_regions_at (frame);
-}
-
-boost::shared_ptr<Region>
-Playlist::top_region_at (framepos_t frame)
-
-{
- RegionLock rlock (this);
- RegionList *rlist = find_regions_at (frame);
- boost::shared_ptr<Region> region;
-
- if (rlist->size()) {
- RegionSortByLayer cmp;
- rlist->sort (cmp);
- region = rlist->back();
- }
-
- delete rlist;
- return region;
-}
-
-boost::shared_ptr<Region>
-Playlist::top_unmuted_region_at (framepos_t frame)
-
-{
- RegionLock rlock (this);
- RegionList *rlist = find_regions_at (frame);
-
- for (RegionList::iterator i = rlist->begin(); i != rlist->end(); ) {
-
- RegionList::iterator tmp = i;
- ++tmp;
-
- if ((*i)->muted()) {
- rlist->erase (i);
- }
-
- i = tmp;
- }
-
- boost::shared_ptr<Region> region;
-
- if (rlist->size()) {
- RegionSortByLayer cmp;
- rlist->sort (cmp);
- region = rlist->back();
- }
-
- delete rlist;
- return region;
-}
-
-Playlist::RegionList*
-Playlist::regions_to_read (framepos_t start, framepos_t end)
-{
- /* Caller must hold lock */
-
- RegionList covering;
- set<framepos_t> to_check;
- set<boost::shared_ptr<Region> > unique;
-
- to_check.insert (start);
- to_check.insert (end);
-
- DEBUG_TRACE (DEBUG::AudioPlayback, ">>>>> REGIONS TO READ\n");
-
- for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-
- /* find all/any regions that span start+end */
-
- switch ((*i)->coverage (start, end)) {
- case OverlapNone:
- break;
-
- case OverlapInternal:
- covering.push_back (*i);
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("toread: will cover %1 (OInternal)\n", (*i)->name()));
- break;
-
- case OverlapStart:
- to_check.insert ((*i)->position());
- if ((*i)->position() != 0) {
- to_check.insert ((*i)->position()-1);
- }
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("toread: will check %1 for %2\n", (*i)->position(), (*i)->name()));
- covering.push_back (*i);
- break;
-
- case OverlapEnd:
- to_check.insert ((*i)->last_frame());
- to_check.insert ((*i)->last_frame()+1);
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("toread: will cover %1 (OEnd)\n", (*i)->name()));
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("\ttoread: will check %1 for %2\n", (*i)->last_frame(), (*i)->name()));
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("\ttoread: will check %1 for %2\n", (*i)->last_frame(), (*i)->name()));
- covering.push_back (*i);
- break;
-
- case OverlapExternal:
- covering.push_back (*i);
- to_check.insert ((*i)->position());
- if ((*i)->position() != 0) {
- to_check.insert ((*i)->position()-1);
- }
- to_check.insert ((*i)->last_frame());
- to_check.insert ((*i)->last_frame()+1);
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("toread: will cover %1 (OExt)\n", (*i)->name()));
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("\ttoread: will check %1 for %2\n", (*i)->position(), (*i)->name()));
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("\ttoread: will check %1 for %2\n", (*i)->last_frame(), (*i)->name()));
- break;
- }
-
- /* don't go too far */
-
- if ((*i)->position() > end) {
- break;
- }
- }
-
- RegionList* rlist = new RegionList;
-
- /* find all the regions that cover each position .... */
-
- if (covering.size() == 1) {
-
- rlist->push_back (covering.front());
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("Just one covering region (%1)\n", covering.front()->name()));
-
- } else {
-
- RegionList here;
- for (set<framepos_t>::iterator t = to_check.begin(); t != to_check.end(); ++t) {
-
- here.clear ();
-
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("++++ Considering %1\n", *t));
-
- for (RegionList::iterator x = covering.begin(); x != covering.end(); ++x) {
-
- if ((*x)->covers (*t)) {
- here.push_back (*x);
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("region %1 covers %2\n",
- (*x)->name(),
- (*t)));
- } else {
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("region %1 does NOT covers %2\n",
- (*x)->name(),
- (*t)));
- }
-
- }
-
- RegionSortByLayer cmp;
- here.sort (cmp);
-
- /* ... and get the top/transparent regions at "here" */
-
- for (RegionList::reverse_iterator c = here.rbegin(); c != here.rend(); ++c) {
-
- unique.insert (*c);
-
- if ((*c)->opaque()) {
-
- /* the other regions at this position are hidden by this one */
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("%1 is opaque, ignore all others\n",
- (*c)->name()));
- break;
- }
- }
- }
-
- for (set<boost::shared_ptr<Region> >::iterator s = unique.begin(); s != unique.end(); ++s) {
- rlist->push_back (*s);
- }
-
- if (rlist->size() > 1) {
- /* now sort by time order */
-
- RegionSortByPosition cmp;
- rlist->sort (cmp);
- }
- }
-
- DEBUG_TRACE (DEBUG::AudioPlayback, string_compose ("<<<<< REGIONS TO READ returns %1\n", rlist->size()));
-
- return rlist;
-}
-
-Playlist::RegionList *
-Playlist::find_regions_at (framepos_t frame)
-{
- /* Caller must hold lock */
-
- RegionList *rlist = new RegionList;
-
- for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
- if ((*i)->covers (frame)) {
- rlist->push_back (*i);
- }