fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / strip_silence.cc
index 2151a3c232ea6257bbd13a606d422121019c360c..3141f422a80e28ccec22e2b25e571c0b3af788ed 100644 (file)
@@ -107,7 +107,7 @@ StripSilence::run (boost::shared_ptr<Region> r, Progress* progress)
        int n = 0;
        int const N = audible.size ();
 
-       for (AudioIntervalResult::const_iterator i = audible.begin(); i != audible.end(); ++i) {
+       for (AudioIntervalResult::const_iterator i = audible.begin(); i != audible.end(); ++i, ++n) {
 
                PBD::PropertyList plist;
                boost::shared_ptr<AudioRegion> copy;
@@ -121,11 +121,17 @@ StripSilence::run (boost::shared_ptr<Region> r, Progress* progress)
 
                copy->set_name (RegionFactory::new_region_name (region->name ()));
 
-               framecnt_t const f = std::min (_fade_length, (i->second - i->first));
+               framecnt_t const f = std::min (_fade_length, (i->second - i->first) / 2);
 
-               copy->set_fade_in_active (true);
-               copy->set_fade_in (FadeLinear, f);
-               copy->set_fade_out (FadeLinear, f);
+               if (f > 0) {
+                       copy->set_fade_in_active (true);
+                       copy->set_fade_out_active (true);
+                       copy->set_fade_in (FadeLinear, f);
+                       copy->set_fade_out (FadeLinear, f);
+               } else {
+                       copy->set_fade_in_active (false);
+                       copy->set_fade_out_active (false);
+               }
                results.push_back (copy);
 
                if (progress && (n <= N)) {