fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / region_factory.cc
index 7c9f4fd228200ebb4d7f3e6dc169f4b180872f0c..16a9e02e378cf0f6835fe81bb973e4b5e8892c34 100644 (file)
@@ -30,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;
@@ -46,7 +46,7 @@ std::map<std::string, PBD::ID>                RegionFactory::region_name_map;
 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, const int32_t sub_num)
 {
        boost::shared_ptr<Region> ret;
        boost::shared_ptr<const AudioRegion> ar;
@@ -54,7 +54,7 @@ RegionFactory::create (boost::shared_ptr<const Region> region, bool announce)
 
        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, 0, sub_num));
 
        } else if ((mr = boost::dynamic_pointer_cast<const MidiRegion>(region)) != 0) {
 
@@ -71,7 +71,7 @@ RegionFactory::create (boost::shared_ptr<const Region> region, bool announce)
                        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, 0, sub_num));
                }
 
        } else {
@@ -82,12 +82,13 @@ RegionFactory::create (boost::shared_ptr<const Region> region, bool announce)
 
        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);
@@ -126,10 +127,10 @@ RegionFactory::create (boost::shared_ptr<Region> region, const PropertyList& pli
        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);
@@ -143,7 +144,7 @@ RegionFactory::create (boost::shared_ptr<Region> region, const PropertyList& pli
 }
 
 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, frameoffset_t offset, const PropertyList& plist, bool announce, const int32_t sub_num)
 {
        boost::shared_ptr<Region> ret;
        boost::shared_ptr<const AudioRegion> other_a;
@@ -151,11 +152,11 @@ RegionFactory::create (boost::shared_ptr<Region> region, frameoffset_t offset, c
 
        if ((other_a = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {
 
-               ret = boost::shared_ptr<Region> (new AudioRegion (other_a, offset));
+               ret = boost::shared_ptr<Region> (new AudioRegion (other_a, offset, sub_num));
 
        } else if ((other_m = boost::dynamic_pointer_cast<MidiRegion>(region)) != 0) {
 
-               ret = boost::shared_ptr<Region> (new MidiRegion (other_m, offset));
+               ret = boost::shared_ptr<Region> (new MidiRegion (other_m, offset, sub_num));
 
        } else {
                fatal << _("programming error: RegionFactory::create() called with unknown Region type")
@@ -167,7 +168,7 @@ RegionFactory::create (boost::shared_ptr<Region> region, frameoffset_t offset, c
        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);
                }
 
@@ -208,7 +209,7 @@ RegionFactory::create (boost::shared_ptr<Region> region, const SourceList& srcs,
        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);
                }
 
@@ -252,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);
@@ -302,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);
                }
        }
@@ -342,7 +343,7 @@ RegionFactory::map_remove (boost::weak_ptr<Region> w)
        if (!r) {
                return;
        }
-       
+
        Glib::Threads::Mutex::Lock lm (region_map_lock);
        RegionMap::iterator i = region_map.find (r->id());
 
@@ -449,7 +450,7 @@ RegionFactory::rename_in_region_name_maps (boost::shared_ptr<Region> region)
        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;
@@ -635,7 +636,7 @@ RegionFactory::get_regions_using_source (boost::shared_ptr<Source> s, std::set<b
 {
        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);
                }
@@ -652,7 +653,7 @@ RegionFactory::remove_regions_using_source (boost::shared_ptr<Source> src)
 
                RegionMap::iterator j = i;
                ++j;
-               
+
                if (i->second->uses_source (src)) {
                        remove_from_region_name_map (i->second->name ());
                        region_map.erase (i);