#include <inttypes.h>
+#include "pbd/basename.h"
#include "pbd/error.h"
#include "ardour/audioregion.h"
#include "ardour/region_factory.h"
#include "ardour/session.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
using namespace ARDOUR;
using namespace PBD;
RegionFactory::CompoundAssociations RegionFactory::_compound_associations;
boost::shared_ptr<Region>
-RegionFactory::create (boost::shared_ptr<const Region> region, bool announce)
+RegionFactory::create (boost::shared_ptr<const Region> region, bool announce, bool fork)
{
boost::shared_ptr<Region> ret;
boost::shared_ptr<const AudioRegion> ar;
if ((ar = boost::dynamic_pointer_cast<const AudioRegion>(region)) != 0) {
- ret = boost::shared_ptr<Region> (new AudioRegion (ar, 0));
+ ret = boost::shared_ptr<Region> (new AudioRegion (ar, MusicFrame (0, 0)));
} else if ((mr = boost::dynamic_pointer_cast<const MidiRegion>(region)) != 0) {
- if (mr->session().config.get_midi_copy_is_fork()) {
- ret = mr->clone ();
+ if (mr->session().config.get_midi_copy_is_fork() || fork) {
+ /* What we really want to do here is what Editor::fork_region()
+ does via Session::create_midi_source_by_stealing_name(), but we
+ don't have a Track. We'll just live with the skipped number,
+ and store the ancestral name of sources so multiple clones
+ generates reasonable names that don't have too many suffixes. */
+ const std::string ancestor_name = mr->sources().front()->ancestor_name();
+ const std::string base = PBD::basename_nosuffix(ancestor_name);
+
+ boost::shared_ptr<MidiSource> source = mr->session().create_midi_source_for_session(base);
+ source->set_ancestor_name(mr->sources().front()->name());
+ ret = mr->clone(source);
} else {
- ret = boost::shared_ptr<Region> (new MidiRegion (mr, 0));
+ ret = boost::shared_ptr<Region> (new MidiRegion (mr, MusicFrame (0, 0)));
}
} else {
fatal << _("programming error: RegionFactory::create() called with unknown Region type")
<< endmsg;
- /*NOTREACHED*/
+ abort(); /*NOTREACHED*/
}
if (ret) {
ret->set_name (new_region_name(ret->name()));
- ret->set_position (region->position());
-
- if (ret->session().config.get_glue_new_regions_to_bars_and_beats ()) {
+
+ if (ret->session().config.get_glue_new_regions_to_bars_and_beats() && ret->position_lock_style() != MusicTime) {
ret->set_position_lock_style (MusicTime);
}
} else {
fatal << _("programming error: RegionFactory::create() called with unknown Region type")
<< endmsg;
- /*NOTREACHED*/
+ abort(); /*NOTREACHED*/
return boost::shared_ptr<Region>();
}
if (ret) {
ret->apply_changes (plist);
- if (ret->session().config.get_glue_new_regions_to_bars_and_beats ()) {
+ if (ret->session().config.get_glue_new_regions_to_bars_and_beats() && ret->position_lock_style() != MusicTime) {
ret->set_position_lock_style (MusicTime);
}
-
+
if (announce) {
map_add (ret);
CheckNewRegion (ret);
}
boost::shared_ptr<Region>
-RegionFactory::create (boost::shared_ptr<Region> region, frameoffset_t offset, const PropertyList& plist, bool announce)
+RegionFactory::create (boost::shared_ptr<Region> region, MusicFrame offset, const PropertyList& plist, bool announce)
{
boost::shared_ptr<Region> ret;
boost::shared_ptr<const AudioRegion> other_a;
} else {
fatal << _("programming error: RegionFactory::create() called with unknown Region type")
<< endmsg;
- /*NOTREACHED*/
+ abort(); /*NOTREACHED*/
return boost::shared_ptr<Region>();
}
if (ret) {
ret->apply_changes (plist);
- if (ret->session().config.get_glue_new_regions_to_bars_and_beats ()) {
+ if (ret->session().config.get_glue_new_regions_to_bars_and_beats() && ret->position_lock_style() != MusicTime) {
ret->set_position_lock_style (MusicTime);
}
} else {
fatal << _("programming error: RegionFactory::create() called with unknown Region type")
<< endmsg;
- /*NOTREACHED*/
+ abort(); /*NOTREACHED*/
}
if (ret) {
ret->apply_changes (plist);
- if (ret->session().config.get_glue_new_regions_to_bars_and_beats ()) {
+ if (ret->session().config.get_glue_new_regions_to_bars_and_beats() && ret->position_lock_style() != MusicTime) {
ret->set_position_lock_style (MusicTime);
}
if (ret) {
ret->apply_changes (plist);
- if (ret->session().config.get_glue_new_regions_to_bars_and_beats ()) {
+ if (ret->session().config.get_glue_new_regions_to_bars_and_beats() && ret->position_lock_style() != MusicTime) {
ret->set_position_lock_style (MusicTime);
}
-
+
if (announce) {
map_add (ret);
CheckNewRegion (ret);
/* Don't fiddle with position_lock_style here as the region
description is coming from XML.
*/
-
+
CheckNewRegion (ret);
}
}
if (!r) {
return;
}
-
+
Glib::Threads::Mutex::Lock lm (region_map_lock);
RegionMap::iterator i = region_map.find (r->id());
update_region_name_number_map (region);
Glib::Threads::Mutex::Lock lm (region_name_maps_mutex);
-
+
map<string, PBD::ID>::iterator i = region_name_map.begin();
while (i != region_name_map.end() && i->second != region->id ()) {
++i;
{
Glib::Threads::Mutex::Lock lm (region_map_lock);
- for (RegionMap::iterator i = region_map.begin(); i != region_map.end(); ++i) {
+ for (RegionMap::const_iterator i = region_map.begin(); i != region_map.end(); ++i) {
if (i->second->uses_source (s)) {
r.insert (i->second);
}
RegionMap::iterator j = i;
++j;
-
+
if (i->second->uses_source (src)) {
remove_from_region_name_map (i->second->name ());
region_map.erase (i);