(1) remove most uses of MementoCommand for Playlist and Region (2) move frozen state...
[ardour.git] / libs / ardour / midi_track.cc
index 6f036f803c4076b8df4c5183c5000c4fe76dc6be..9409e9f1439b14b0fb2c5e73c9947f82cf0da8fa 100644 (file)
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 #include "pbd/error.h"
-#include <sigc++/retype.h>
-#include <sigc++/retype_return.h>
-#include <sigc++/bind.h>
 
 #include "pbd/enumwriter.h"
+#include "pbd/convert.h"
 #include "midi++/events.h"
 #include "evoral/midi_util.h"
 
@@ -41,6 +39,7 @@
 #include "ardour/processor.h"
 #include "ardour/route_group_specialized.h"
 #include "ardour/session.h"
+#include "ardour/session_playlists.h"
 #include "ardour/utils.h"
 
 #include "i18n.h"
@@ -66,8 +65,8 @@ MidiTrack::MidiTrack (Session& sess, string name, Route::Flag flag, TrackMode mo
        _mode = mode;
 }
 
-MidiTrack::MidiTrack (Session& sess, const XMLNode& node, int version)
-       : Track (sess, node, version, DataType::MIDI)
+MidiTrack::MidiTrack (Session& sess, const XMLNode& node, int /*version*/)
+       : Track (sess, node, DataType::MIDI)
        , _immediate_events(1024) // FIXME: size?
        , _step_edit_ring_buffer(64) // FIXME: size?
        , _note_mode(Sustained)
@@ -75,7 +74,7 @@ MidiTrack::MidiTrack (Session& sess, const XMLNode& node, int version)
        , _default_channel (0)
        , _midi_thru (true)
 {
-       _set_state (node, version, false);
+       _set_state (node, Stateful::loading_state_version, false);
 }
 
 MidiTrack::~MidiTrack ()
@@ -111,9 +110,6 @@ MidiTrack::set_diskstream (boost::shared_ptr<MidiDiskstream> ds)
        _diskstream->set_record_enabled (false);
        //_diskstream->monitor_input (false);
 
-       ic_connection.disconnect();
-       ic_connection = _input->changed.connect (mem_fun (*_diskstream, &MidiDiskstream::handle_input_change));
-
        DiskstreamChanged (); /* EMIT SIGNAL */
 
        return 0;
@@ -124,14 +120,11 @@ MidiTrack::use_diskstream (string name)
 {
        boost::shared_ptr<MidiDiskstream> dstream;
 
-       cerr << "\n\n\nMIDI use diskstream\n";
-
        if ((dstream = boost::dynamic_pointer_cast<MidiDiskstream>(_session.diskstream_by_name (name))) == 0) {
                error << string_compose(_("MidiTrack: midi diskstream \"%1\" not known by session"), name) << endmsg;
                return -1;
        }
 
-       cerr << "\n\n\nMIDI found DS\n";
        return set_diskstream (dstream);
 }
 
@@ -214,8 +207,6 @@ MidiTrack::_set_state (const XMLNode& node, int version, bool call_base)
                   an old one.
                */
 
-               cerr << "\n\n\n\n MIDI track " << name() << " found DS id " << id << endl;
-
                if (id == zero) {
                        use_new_diskstream ();
                } else if (use_diskstream (id)) {
@@ -232,7 +223,7 @@ MidiTrack::_set_state (const XMLNode& node, int version, bool call_base)
                child = *niter;
 
                if (child->name() == X_("recenable")) {
-                       _rec_enable_control->set_state (*child);
+                       _rec_enable_control->set_state (*child, version);
                        _session.add_controllable (_rec_enable_control);
                }
        }
@@ -240,7 +231,7 @@ MidiTrack::_set_state (const XMLNode& node, int version, bool call_base)
        pending_state = const_cast<XMLNode*> (&node);
 
        if (_session.state_of_the_state() & Session::Loading) {
-               _session.StateReady.connect (mem_fun (*this, &MidiTrack::set_state_part_two));
+               _session.StateReady.connect_same_thread (*this, boost::bind (&MidiTrack::set_state_part_two, this));
        } else {
                set_state_part_two ();
        }
@@ -328,7 +319,7 @@ MidiTrack::set_state_part_two ()
                _freeze_record.processor_info.clear ();
 
                if ((prop = fnode->property (X_("playlist"))) != 0) {
-                       boost::shared_ptr<Playlist> pl = _session.playlist_by_name (prop->value());
+                       boost::shared_ptr<Playlist> pl = _session.playlists->by_name (prop->value());
                        if (pl) {
                                _freeze_record.playlist = boost::dynamic_pointer_cast<MidiPlaylist> (pl);
                        } else {
@@ -523,17 +514,15 @@ void
 MidiTrack::write_out_of_band_data (BufferSet& bufs, sframes_t /*start*/, sframes_t /*end*/, nframes_t nframes)
 {
        // Append immediate events
-
        MidiBuffer& buf (bufs.get_midi (0));
        _immediate_events.read (buf, 0, 0, nframes - 1); // all stamps = 0
 
-       /* MIDI thru: send incoming data "through" output */
-       if (_midi_thru && _input->n_ports().n_midi()) {
+       // MIDI thru: send incoming data "through" output
+       if (_midi_thru && _session.transport_speed() != 0.0f && _input->n_ports().n_midi()) {
                buf.merge_in_place (_input->midi(0)->get_midi_buffer(nframes));
        }
 }
 
-
 int
 MidiTrack::export_stuff (BufferSet& /*bufs*/, nframes_t /*nframes*/, sframes_t /*end_frame*/)
 {
@@ -567,7 +556,7 @@ MidiTrack::bounce_range (nframes_t /*start*/, nframes_t /*end*/, InterThreadInfo
 }
 
 void
-MidiTrack::freeze (InterThreadInfo& /*itt*/)
+MidiTrack::freeze_me (InterThreadInfo& /*itt*/)
 {
 }
 
@@ -632,9 +621,8 @@ MidiTrack::MidiControl::set_value(float val)
        }
 
        assert(val <= _list->parameter().max());
-       size_t size = 3;
-
        if ( ! automation_playback()) {
+               size_t size = 3;
                uint8_t ev[3] = { _list->parameter().channel(), int(val), 0 };
                switch(_list->parameter().type()) {
                case MidiCCAutomation: