logic to copy audio region fade in/fade out into compound regions (one-way for now)
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 25 May 2011 18:51:00 +0000 (18:51 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 25 May 2011 18:51:00 +0000 (18:51 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@9588 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioplaylist.h
libs/ardour/ardour/playlist.h
libs/ardour/ardour/region_sorters.h [new file with mode: 0644]
libs/ardour/audio_playlist.cc
libs/ardour/playlist.cc

index b9ed739a791927e2ba329d9a0d51da6b544ca04c..a8426b5f51ec8d4e255e1d651bdf30e71269ff33 100644 (file)
@@ -106,6 +106,9 @@ public:
         void remove_dependents (boost::shared_ptr<Region> region);
        void copy_dependents (const std::vector<TwoRegions>&, boost::shared_ptr<Playlist>);
 
+       void pre_combine (std::vector<boost::shared_ptr<Region> >&, boost::shared_ptr<Region>);
+       void pre_uncombine (std::vector<boost::shared_ptr<Region> >&, boost::shared_ptr<Region>);
+
     private:
        CrossfadeListProperty _crossfades;
        Crossfades      _pending_xfade_adds;
index 5406886faa24bd40a48c6facb7f6d5e14f4fdb5b..dfb16d79bc91eb2c69d796ce87ac486aeb89b728 100644 (file)
@@ -390,6 +390,9 @@ public:
            framecnt_t length;
            framepos_t start;
        };
+
+       virtual void pre_combine (std::vector<boost::shared_ptr<Region> >&, boost::shared_ptr<Region>) {}
+       virtual void pre_uncombine (std::vector<boost::shared_ptr<Region> >&, boost::shared_ptr<Region>) {}
 };
 
 } /* namespace ARDOUR */
diff --git a/libs/ardour/ardour/region_sorters.h b/libs/ardour/ardour/region_sorters.h
new file mode 100644 (file)
index 0000000..ca09f19
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+    Copyright (C) 2000-2011 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __libardour_region_sorters_h__
+#define __libardour_region_sorters_h__
+
+#include "ardour/region.h"
+
+namespace ARDOUR {
+
+struct RegionSortByPosition {
+    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
+           return a->position() < b->position();
+    }
+};
+
+struct RegionSortByLastLayerOp {
+    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
+           return a->last_layer_op() < b->last_layer_op();
+    }
+};
+
+struct RegionSortByLayer {
+    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
+           return a->layer() < b->layer();
+    }
+};
+
+struct RegionSortByLayerWithPending {
+       bool operator () (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
+
+               double p = a->layer ();
+               if (a->pending_explicit_relayer()) {
+                       p += 0.5;
+               }
+
+               double q = b->layer ();
+               if (b->pending_explicit_relayer()) {
+                       q += 0.5;
+               }
+
+               return p < q;
+       }
+};
+
+} // namespace 
+
+#endif /* __libardour_region_sorters_h__ */
index ebff10f49e48cd3a32b65644d54bba130a5d9ca9..f73bbf17e59170e75667dcd79452e3ba731b89bb 100644 (file)
@@ -27,6 +27,7 @@
 #include "ardour/audioplaylist.h"
 #include "ardour/audioregion.h"
 #include "ardour/crossfade.h"
+#include "ardour/region_sorters.h"
 #include "ardour/session.h"
 #include "pbd/enumwriter.h"
 
@@ -1080,3 +1081,45 @@ AudioPlaylist::copy_dependents (const vector<TwoRegions>& old_and_new, boost::sh
                other_audio->add_crossfade (new_xfade);
        }
 }
+
+void
+AudioPlaylist::pre_combine (vector<boost::shared_ptr<Region> >& originals, boost::shared_ptr<Region> compound_region)
+{
+       /* sort the originals into time order */
+
+       RegionSortByPosition cmp;
+       boost::shared_ptr<AudioRegion> ar;
+       boost::shared_ptr<AudioRegion> cr;
+
+       if ((cr = boost::dynamic_pointer_cast<AudioRegion> (compound_region)) == 0) {
+               return;
+       }
+
+       sort (originals.begin(), originals.end(), cmp);
+
+       ar = boost::dynamic_pointer_cast<AudioRegion> (originals.front());
+
+       /* copy the fade in of the first into the compound region */
+
+       if (ar) {
+               cr->set_fade_in (ar->fade_in());
+               
+               /* disable the fade in of the first */
+               
+               ar->set_fade_in_active (false);
+       }
+
+       ar = boost::dynamic_pointer_cast<AudioRegion> (originals.front());
+
+       if (ar) {
+               /* copy the fade out of the last into the compound region */
+               cr->set_fade_out (ar->fade_out());
+               /* disable the fade out of the first */
+               ar->set_fade_out_active (false);
+       }
+}
+
+void
+AudioPlaylist::pre_uncombine (vector<boost::shared_ptr<Region> >& originals, boost::shared_ptr<Region> compound_region)
+{
+}
index 4a5405841ff2dc01fbfb0c72aea93301547ee2f0..3ca4fddfb12a743cab9ac3e8684363db749908e9 100644 (file)
@@ -38,6 +38,7 @@
 #include "ardour/session.h"
 #include "ardour/region.h"
 #include "ardour/region_factory.h"
+#include "ardour/region_sorters.h"
 #include "ardour/playlist_factory.h"
 #include "ardour/playlist_source.h"
 #include "ardour/transient_detector.h"
@@ -65,40 +66,7 @@ struct ShowMeTheList {
     string name;
 };
 
-struct RegionSortByLayer {
-    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
-           return a->layer() < b->layer();
-    }
-};
-
-struct RegionSortByLayerWithPending {
-       bool operator () (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
-
-               double p = a->layer ();
-               if (a->pending_explicit_relayer()) {
-                       p += 0.5;
-               }
-
-               double q = b->layer ();
-               if (b->pending_explicit_relayer()) {
-                       q += 0.5;
-               }
-
-               return p < q;
-       }
-};
-
-struct RegionSortByPosition {
-    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
-           return a->position() < b->position();
-    }
-};
 
-struct RegionSortByLastLayerOp {
-    bool operator() (boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
-           return a->last_layer_op() < b->last_layer_op();
-    }
-};
 
 void
 Playlist::make_property_quarks ()
@@ -3160,6 +3128,7 @@ Playlist::combine (const RegionList& r)
        uint32_t layer = 0;
        framepos_t earliest_position = max_framepos;
        vector<TwoRegions> old_and_new_regions;
+       vector<boost::shared_ptr<Region> > originals;
        string parent_name;
        string child_name;
        uint32_t max_level = 0;
@@ -3193,6 +3162,7 @@ Playlist::combine (const RegionList& r)
                boost::shared_ptr<Region> copied_region = RegionFactory::create (original_region, false);
 
                old_and_new_regions.push_back (TwoRegions (original_region,copied_region));
+               originals.push_back (original_region);
 
                RegionFactory::add_compound_association (original_region, copied_region);
 
@@ -3254,6 +3224,12 @@ Playlist::combine (const RegionList& r)
                remove_region (*i);
        }
 
+       /* do type-specific stuff with the originals and the new compound
+          region 
+       */
+
+       pre_combine (originals, compound_region);
+
        /* add the new region at the right location */
        
        add_region (compound_region, earliest_position);