X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fregion_factory.cc;h=16a9e02e378cf0f6835fe81bb973e4b5e8892c34;hb=c8c6bca6587450ff64303dbc994a4cd28d6ce7aa;hp=44f8c34ddd3be482fd5377805f83bce3371ae571;hpb=23e7cf10191270d70357ccf0ed9294f020c7b7ab;p=ardour.git diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc index 44f8c34ddd..16a9e02e37 100644 --- a/libs/ardour/region_factory.cc +++ b/libs/ardour/region_factory.cc @@ -19,6 +19,7 @@ #include +#include "pbd/basename.h" #include "pbd/error.h" #include "ardour/audioregion.h" @@ -29,7 +30,7 @@ #include "ardour/region_factory.h" #include "ardour/session.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; using namespace PBD; @@ -45,7 +46,7 @@ std::map RegionFactory::region_name_map; RegionFactory::CompoundAssociations RegionFactory::_compound_associations; boost::shared_ptr -RegionFactory::create (boost::shared_ptr region, bool announce) +RegionFactory::create (boost::shared_ptr region, bool announce, const int32_t sub_num) { boost::shared_ptr ret; boost::shared_ptr ar; @@ -53,30 +54,41 @@ RegionFactory::create (boost::shared_ptr region, bool announce) if ((ar = boost::dynamic_pointer_cast(region)) != 0) { - ret = boost::shared_ptr (new AudioRegion (ar, 0)); + ret = boost::shared_ptr (new AudioRegion (ar, 0, sub_num)); } else if ((mr = boost::dynamic_pointer_cast(region)) != 0) { if (mr->session().config.get_midi_copy_is_fork()) { - ret = mr->clone (); + /* 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 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 (new MidiRegion (mr, 0)); + ret = boost::shared_ptr (new MidiRegion (mr, 0, sub_num)); } } 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); } + ret->set_position (region->position(), sub_num); + /* pure copy constructor - no property list */ if (announce) { map_add (ret); @@ -108,17 +120,17 @@ RegionFactory::create (boost::shared_ptr region, const PropertyList& pli } else { fatal << _("programming error: RegionFactory::create() called with unknown Region type") << endmsg; - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ return boost::shared_ptr(); } 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); @@ -132,7 +144,7 @@ RegionFactory::create (boost::shared_ptr region, const PropertyList& pli } boost::shared_ptr -RegionFactory::create (boost::shared_ptr region, frameoffset_t offset, const PropertyList& plist, bool announce) +RegionFactory::create (boost::shared_ptr region, frameoffset_t offset, const PropertyList& plist, bool announce, const int32_t sub_num) { boost::shared_ptr ret; boost::shared_ptr other_a; @@ -140,23 +152,23 @@ RegionFactory::create (boost::shared_ptr region, frameoffset_t offset, c if ((other_a = boost::dynamic_pointer_cast(region)) != 0) { - ret = boost::shared_ptr (new AudioRegion (other_a, offset)); + ret = boost::shared_ptr (new AudioRegion (other_a, offset, sub_num)); } else if ((other_m = boost::dynamic_pointer_cast(region)) != 0) { - ret = boost::shared_ptr (new MidiRegion (other_m, offset)); + ret = boost::shared_ptr (new MidiRegion (other_m, offset, sub_num)); } else { fatal << _("programming error: RegionFactory::create() called with unknown Region type") << endmsg; - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ return boost::shared_ptr(); } 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); } @@ -191,13 +203,13 @@ RegionFactory::create (boost::shared_ptr region, const SourceList& srcs, } 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); } @@ -241,10 +253,10 @@ RegionFactory::create (const SourceList& srcs, const PropertyList& plist, bool a 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); @@ -291,7 +303,7 @@ RegionFactory::create (SourceList& srcs, const XMLNode& node) /* Don't fiddle with position_lock_style here as the region description is coming from XML. */ - + CheckNewRegion (ret); } } @@ -331,7 +343,7 @@ RegionFactory::map_remove (boost::weak_ptr w) if (!r) { return; } - + Glib::Threads::Mutex::Lock lm (region_map_lock); RegionMap::iterator i = region_map.find (r->id()); @@ -438,7 +450,7 @@ RegionFactory::rename_in_region_name_maps (boost::shared_ptr region) update_region_name_number_map (region); Glib::Threads::Mutex::Lock lm (region_name_maps_mutex); - + map::iterator i = region_name_map.begin(); while (i != region_name_map.end() && i->second != region->id ()) { ++i; @@ -624,7 +636,7 @@ RegionFactory::get_regions_using_source (boost::shared_ptr s, std::setsecond->uses_source (s)) { r.insert (i->second); } @@ -641,7 +653,7 @@ RegionFactory::remove_regions_using_source (boost::shared_ptr src) RegionMap::iterator j = i; ++j; - + if (i->second->uses_source (src)) { remove_from_region_name_map (i->second->name ()); region_map.erase (i);