Part 1 of loading 2.X sessions; some things work, some things don't, hacks a-plenty.
[ardour.git] / libs / ardour / midi_playlist.cc
index 27410462d1b85a3ed6778a4c6cabf33f87b99ea1..b0fd5de24eabddbcafefbe8fc73d5734465bade6 100644 (file)
@@ -1,17 +1,17 @@
 /*
-    Copyright (C) 2006 Paul Davis 
-       Written by Dave Robillard, 2006
+    Copyright (C) 2006 Paul Davis
+    Written by Dave Robillard, 2006
 
     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.
 
 #include <sigc++/bind.h>
 
-#include <ardour/types.h>
-#include <ardour/configuration.h>
-#include <ardour/midi_playlist.h>
-#include <ardour/midi_region.h>
-#include <ardour/session.h>
-#include <ardour/midi_ring_buffer.h>
+#include "ardour/types.h"
+#include "ardour/configuration.h"
+#include "ardour/midi_playlist.h"
+#include "ardour/midi_region.h"
+#include "ardour/session.h"
+#include "ardour/midi_ring_buffer.h"
 
-#include <pbd/error.h>
+#include "pbd/error.h"
 
 #include "i18n.h"
 
@@ -42,6 +42,7 @@ using namespace std;
 
 MidiPlaylist::MidiPlaylist (Session& session, const XMLNode& node, bool hidden)
                : Playlist (session, node, DataType::MIDI, hidden)
+               , _note_mode(Sustained)
 {
        const XMLProperty* prop = node.property("type");
        assert(prop && DataType(prop->value()) == DataType::MIDI);
@@ -90,7 +91,7 @@ MidiPlaylist::MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other, string
                                        out_o++;
                                        out_n++;
                                }
-                               //                              cerr << "HUH!? second region in the crossfade not found!" << endl;
+                               // cerr << "HUH!? second region in the crossfade not found!" << endl;
                        }
                }
 
@@ -108,10 +109,10 @@ MidiPlaylist::MidiPlaylist (boost::shared_ptr<const MidiPlaylist> other, nframes
 
 MidiPlaylist::~MidiPlaylist ()
 {
-       GoingAway (); /* EMIT SIGNAL */
-       
+       GoingAway (); /* EMIT SIGNAL */
+
        /* drop connections to signals */
-       
+
        notify_callbacks ();
 }
 
@@ -123,14 +124,13 @@ struct RegionSortByLayer {
 
 /** Returns the number of frames in time duration read (eg could be large when 0 events are read) */
 nframes_t
-MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start,
-                     nframes_t dur, unsigned chan_n)
+MidiPlaylist::read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t dur, unsigned chan_n)
 {
        /* this function is never called from a realtime thread, so
           its OK to block (for short intervals).
        */
 
-       Glib::Mutex::Lock rm (region_lock);
+       Glib::RecMutex::Lock rm (region_lock);
 
        nframes_t end = start + dur - 1;
 
@@ -140,7 +140,6 @@ MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start,
        vector<boost::shared_ptr<Region> > regs;
 
        for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
-
                if ((*i)->coverage (start, end) != OverlapNone) {
                        regs.push_back(*i);
                }
@@ -150,7 +149,6 @@ MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start,
        sort(regs.begin(), regs.end(), layer_cmp);
 
        for (vector<boost::shared_ptr<Region> >::iterator i = regs.begin(); i != regs.end(); ++i) {
-               // FIXME: ensure time is monotonic here?
                boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(*i);
                if (mr) {
                        mr->read_at (dst, start, dur, chan_n, _note_mode);
@@ -163,69 +161,33 @@ MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start,
 
 
 void
-MidiPlaylist::remove_dependents (boost::shared_ptr<Region> region)
+MidiPlaylist::remove_dependents (boost::shared_ptr<Region> /*region*/)
 {
        /* MIDI regions have no dependents (crossfades) */
 }
 
 
 void
-MidiPlaylist::refresh_dependents (boost::shared_ptr<Region> r)
+MidiPlaylist::refresh_dependents (boost::shared_ptr<Region> /*r*/)
 {
        /* MIDI regions have no dependents (crossfades) */
 }
 
 void
-MidiPlaylist::finalize_split_region (boost::shared_ptr<Region> original, boost::shared_ptr<Region> left, boost::shared_ptr<Region> right)
+MidiPlaylist::finalize_split_region (boost::shared_ptr<Region> /*original*/, boost::shared_ptr<Region> /*left*/, boost::shared_ptr<Region> /*right*/)
 {
-       throw; // I don't wanna
-       /*
-       MidiRegion *orig  = dynamic_cast<MidiRegion*>(o);
-       MidiRegion *left  = dynamic_cast<MidiRegion*>(l);
-       MidiRegion *right = dynamic_cast<MidiRegion*>(r);
-
-       for (Crossfades::iterator x = _crossfades.begin(); x != _crossfades.end();) {
-               Crossfades::iterator tmp;
-               tmp = x;
-               ++tmp;
-
-               Crossfade *fade = 0;
-
-               if ((*x)->_in == orig) {
-                       if (! (*x)->covers(right->position())) {
-                               fade = new Crossfade( *(*x), left, (*x)->_out);
-                       } else {
-                               // Overlap, the crossfade is copied on the left side of the right region instead
-                               fade = new Crossfade( *(*x), right, (*x)->_out);
-                       }
-               }
-
-               if ((*x)->_out == orig) {
-                       if (! (*x)->covers(right->position())) {
-                               fade = new Crossfade( *(*x), (*x)->_in, right);
-                       } else {
-                               // Overlap, the crossfade is copied on the right side of the left region instead
-                               fade = new Crossfade( *(*x), (*x)->_in, left);
-                       }
-               }
-
-               if (fade) {
-                       _crossfades.remove( (*x) );
-                       add_crossfade (*fade);
-               }
-               x = tmp;
-       }*/
+       /* No MIDI crossfading (yet?), so nothing to do here */
 }
 
 void
-MidiPlaylist::check_dependents (boost::shared_ptr<Region> r, bool norefresh)
+MidiPlaylist::check_dependents (boost::shared_ptr<Region> /*r*/, bool /*norefresh*/)
 {
        /* MIDI regions have no dependents (crossfades) */
 }
 
 
 int
-MidiPlaylist::set_state (const XMLNode& node)
+MidiPlaylist::set_state (const XMLNode& node, int version)
 {
        in_set_state++;
        freeze ();
@@ -300,6 +262,30 @@ MidiPlaylist::destroy_region (boost::shared_ptr<Region> region)
        return changed;
 }
 
+set<Evoral::Parameter>
+MidiPlaylist::contained_automation()
+{
+       /* this function is never called from a realtime thread, so
+          its OK to block (for short intervals).
+       */
+
+       Glib::RecMutex::Lock rm (region_lock);
+
+       set<Evoral::Parameter> ret;
+
+       for (RegionList::const_iterator r = regions.begin(); r != regions.end(); ++r) {
+               boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(*r);
+
+               for (Automatable::Controls::iterator c = mr->model()->controls().begin();
+                               c != mr->model()->controls().end(); ++c) {
+                       ret.insert(c->first);
+               }
+       }
+
+       return ret;
+}
+
+
 bool
 MidiPlaylist::region_changed (Change what_changed, boost::shared_ptr<Region> region)
 {
@@ -308,7 +294,7 @@ MidiPlaylist::region_changed (Change what_changed, boost::shared_ptr<Region> reg
        }
 
        // Feeling rather uninterested today, but thanks for the heads up anyway!
-       
+
        Change our_interests = Change (/*MidiRegion::FadeInChanged|
                                       MidiRegion::FadeOutChanged|
                                       MidiRegion::FadeInActiveChanged|