#include <ardour/playlist_factory.h>
#include <ardour/transient_detector.h>
+#include <boost/lexical_cast.hpp>
+
#include "i18n.h"
using namespace std;
init (hide);
first_set_state = false;
_name = nom;
-
+ _set_sort_id();
}
Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
{
init (hide);
_name = "unnamed"; /* reset by set_state */
+ _set_sort_id();
/* set state called by derived class */
}
/* GoingAway must be emitted by derived classes */
}
+void
+Playlist::_set_sort_id ()
+{
+ /*
+ Playlists are given names like <track name>.<id>
+ or <track name>.<edit group name>.<id> where id
+ is an integer. We extract the id and sort by that.
+ */
+
+ size_t dot_position = _name.find_last_of(".");
+ if (dot_position == string::npos)
+ {
+ _sort_id = 0;
+ }
+ else
+ {
+ string t = _name.substr(dot_position + 1);
+
+ try
+ {
+ _sort_id = boost::lexical_cast<int>(t);
+ }
+ catch (boost::bad_lexical_cast e)
+ {
+ _sort_id = 0;
+ }
+ }
+}
+
void
Playlist::set_name (string str)
{
return;
}
- _name = str;
+ if (str == _name) {
+ return;
+ }
+
+ string name = str;
+
+ while (_session.playlist_by_name(name) != 0) {
+ name = bump_name_once(name);
+ }
+
+ _name = name;
+ _set_sort_id();
+
NameChanged(); /* EMIT SIGNAL */
}
}
}
-
void
Playlist::notify_modified ()
{
void
Playlist::partition_internal (nframes_t start, nframes_t end, bool cutting, RegionList& thawlist)
{
- RegionLock rlock (this);
- boost::shared_ptr<Region> region;
- boost::shared_ptr<Region> current;
- string new_name;
- RegionList::iterator tmp;
- OverlapType overlap;
- nframes_t pos1, pos2, pos3, pos4;
RegionList new_regions;
- in_partition = true;
-
- /* need to work from a copy, because otherwise the regions we add during the process
- get operated on as well.
- */
-
- RegionList copy = regions;
-
- for (RegionList::iterator i = copy.begin(); i != copy.end(); i = tmp) {
+ {
+ RegionLock rlock (this);
+ boost::shared_ptr<Region> region;
+ boost::shared_ptr<Region> current;
+ string new_name;
+ RegionList::iterator tmp;
+ OverlapType overlap;
+ nframes_t pos1, pos2, pos3, pos4;
- tmp = i;
- ++tmp;
-
- current = *i;
+ in_partition = true;
- if (current->first_frame() == start && current->last_frame() == end) {
- if (cutting) {
- remove_region_internal (current);
- }
- continue;
- }
+ /* need to work from a copy, because otherwise the regions we add during the process
+ get operated on as well.
+ */
- if ((overlap = current->coverage (start, end)) == OverlapNone) {
- continue;
- }
+ RegionList copy = regions;
- pos1 = current->position();
- pos2 = start;
- pos3 = end;
- pos4 = current->last_frame();
+ for (RegionList::iterator i = copy.begin(); i != copy.end(); i = tmp) {
+
+ tmp = i;
+ ++tmp;
+
+ current = *i;
- if (overlap == OverlapInternal) {
+ if (current->first_frame() >= start && current->last_frame() < end) {
+ if (cutting) {
+ remove_region_internal (current);
+ }
+ continue;
+ }
- /* split: we need 3 new regions, the front, middle and end.
- cut: we need 2 regions, the front and end.
+ /* coverage will return OverlapStart if the start coincides
+ with the end point. we do not partition such a region,
+ so catch this special case.
*/
+
+ if (current->first_frame() >= end) {
+ continue;
+ }
+
+ if ((overlap = current->coverage (start, end)) == OverlapNone) {
+ continue;
+ }
+
+ pos1 = current->position();
+ pos2 = start;
+ pos3 = end;
+ pos4 = current->last_frame();
- /*
+ if (overlap == OverlapInternal) {
+
+ /* split: we need 3 new regions, the front, middle and end.
+ cut: we need 2 regions, the front and end.
+ */
+
+ /*
start end
---------------*************************------------
P1 P2 P3 P4
CUT
---------------*****----------------====------------
- */
+ */
- if (!cutting) {
+ if (!cutting) {
- /* "middle" ++++++ */
+ /* "middle" ++++++ */
+
+ _session.region_name (new_name, current->name(), false);
+ region = RegionFactory::create (current, pos2 - pos1, pos3 - pos2, new_name,
+ regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit|Region::RightOfSplit));
+ add_region_internal (region, start);
+ new_regions.push_back (region);
+ }
+ /* "end" ====== */
+
_session.region_name (new_name, current->name(), false);
- region = RegionFactory::create (current, pos2 - pos1, pos3 - pos2, new_name,
- regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit|Region::RightOfSplit));
- add_region_internal (region, start);
+ region = RegionFactory::create (current, pos3 - pos1, pos4 - pos3, new_name,
+ regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit));
+
+ add_region_internal (region, end);
new_regions.push_back (region);
- }
-
- /* "end" ====== */
+
+ /* "front" ***** */
- _session.region_name (new_name, current->name(), false);
- region = RegionFactory::create (current, pos3 - pos1, pos4 - pos3, new_name,
- regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit));
+ current->freeze ();
+ thawlist.push_back (current);
+ current->cut_end (pos2, this);
- add_region_internal (region, end);
- new_regions.push_back (region);
-
- /* "front" ***** */
+ } else if (overlap == OverlapEnd) {
- current->freeze ();
- thawlist.push_back (current);
- current->trim_end (pos2, this);
-
- } else if (overlap == OverlapEnd) {
-
- /*
+ /*
start end
---------------*************************------------
P1 P2 P4 P3
---------------**************+++++++++++------------
CUT:
---------------**************-----------------------
-
- */
-
- if (!cutting) {
+ */
- /* end +++++ */
+ if (!cutting) {
+
+ /* end +++++ */
+
+ _session.region_name (new_name, current->name(), false);
+ region = RegionFactory::create (current, pos2 - pos1, pos4 - pos2, new_name, (layer_t) regions.size(),
+ Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit));
+ add_region_internal (region, start);
+ new_regions.push_back (region);
+ }
- _session.region_name (new_name, current->name(), false);
- region = RegionFactory::create (current, pos2 - pos1, pos4 - pos2, new_name, (layer_t) regions.size(),
- Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit));
- add_region_internal (region, start);
- new_regions.push_back (region);
- }
-
- /* front ****** */
-
- current->freeze ();
- thawlist.push_back (current);
- current->trim_end (pos2, this);
-
- } else if (overlap == OverlapStart) {
-
- /* split: we need 2 regions: the front and the end.
- cut: just trim current to skip the cut area
- */
+ /* front ****** */
+
+ current->freeze ();
+ thawlist.push_back (current);
+ current->cut_end (pos2, this);
+
+ } else if (overlap == OverlapStart) {
- /*
+ /* split: we need 2 regions: the front and the end.
+ cut: just trim current to skip the cut area
+ */
+
+ /*
start end
---------------*************************------------
P2 P1 P3 P4
CUT:
-------------------*********************------------
- */
+ */
- if (!cutting) {
+ if (!cutting) {
- /* front **** */
- _session.region_name (new_name, current->name(), false);
- region = RegionFactory::create (current, 0, pos3 - pos1, new_name,
- regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit));
- add_region_internal (region, pos1);
- new_regions.push_back (region);
- }
-
- /* end */
-
- current->freeze ();
- thawlist.push_back (current);
- current->trim_front (pos3, this);
-
- } else if (overlap == OverlapExternal) {
-
- /* split: no split required.
- cut: remove the region.
- */
+ /* front **** */
+ _session.region_name (new_name, current->name(), false);
+ region = RegionFactory::create (current, 0, pos3 - pos1, new_name,
+ regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit));
+ add_region_internal (region, pos1);
+ new_regions.push_back (region);
+ }
- /*
+ /* end */
+
+ current->freeze ();
+ thawlist.push_back (current);
+ current->trim_front (pos3, this);
+
+ } else if (overlap == OverlapExternal) {
+
+ /* split: no split required.
+ cut: remove the region.
+ */
+
+ /*
start end
---------------*************************------------
P2 P1 P3 P4
CUT:
----------------------------------------------------
- */
-
- if (cutting) {
- remove_region_internal (current);
+ */
+
+ if (cutting) {
+ remove_region_internal (current);
+ }
+ new_regions.push_back (current);
}
- new_regions.push_back (current);
}
+
+ in_partition = false;
}
- in_partition = false;
-
for (RegionList::iterator i = new_regions.begin(); i != new_regions.end(); ++i) {
check_dependents (*i, false);
}
}
}
+void
+Playlist::shift (nframes64_t at, nframes64_t distance, bool move_intersected, bool ignore_music_glue)
+{
+ RegionLock rlock (this);
+ RegionList copy (regions);
+ 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)->positional_lock_style() != Region::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 (nframes64_t at)
+{
+ RegionLock rlock (this);
+ RegionList copy (regions);
+
+ /* 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, nframes_t playlist_position)
{
RegionLock rl (this);
+ _split_region (region, playlist_position);
+}
+void
+Playlist::_split_region (boost::shared_ptr<Region> region, nframes_t playlist_position)
+{
if (!region->covers (playlist_position)) {
return;
}
pos = r->last_frame ();
break;
case SyncPoint:
- pos = r->adjust_to_sync (r->first_frame());
+ pos = r->sync_position ();
+ // r->adjust_to_sync (r->first_frame());
break;
}
if (prop->name() == X_("name")) {
_name = prop->value();
+ _set_sort_id();
} else if (prop->name() == X_("orig_diskstream_id")) {
_orig_diskstream_id = prop->value ();
} else if (prop->name() == X_("frozen")) {
- _frozen = (prop->value() == X_("yes"));
+ _frozen = string_is_affirmative (prop->value());
}
}
Playlist::raise_region_to_top (boost::shared_ptr<Region> region)
{
/* does nothing useful if layering mode is later=higher */
- if ((Config->get_layer_model() == MoveAddHigher) ||
- (Config->get_layer_model() == AddHigher)) {
- timestamp_layer_op (region);
- relayer ();
+ switch (Config->get_layer_model()) {
+ case LaterHigher:
+ return;
}
+
+ RegionList::size_type sz = regions.size();
+
+ if (region->layer() >= (sz - 1)) {
+ /* already on the top */
+ return;
+ }
+
+ move_region_to_layer (sz, region, 1);
+ /* mark the region's last_layer_op as now, so that it remains on top when
+ doing future relayers (until something else takes over)
+ */
+ timestamp_layer_op (region);
}
void
Playlist::lower_region_to_bottom (boost::shared_ptr<Region> region)
{
/* does nothing useful if layering mode is later=higher */
- if ((Config->get_layer_model() == MoveAddHigher) ||
- (Config->get_layer_model() == AddHigher)) {
- region->set_last_layer_op (0);
- relayer ();
+ switch (Config->get_layer_model()) {
+ case LaterHigher:
+ return;
}
+
+ if (region->layer() == 0) {
+ /* already on the bottom */
+ return;
+ }
+
+ move_region_to_layer (0, region, -1);
+ /* force region's last layer op to zero so that it stays at the bottom
+ when doing future relayers
+ */
+ region->set_last_layer_op (0);
}
int
void
Playlist::timestamp_layer_op (boost::shared_ptr<Region> region)
{
-// struct timeval tv;
-// gettimeofday (&tv, 0);
region->set_last_layer_op (++layer_op_counter);
}