Modified version of Hans' patch for mantis 1985. Also remove unused port_connections...
[ardour.git] / libs / ardour / midi_track.cc
index 6697e3b70476980a8505de996f1f5c9042eb10bd..4c575e8cc4e146162f07fe0dba060500ce5bb857 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "ardour/amp.h"
 #include "ardour/buffer_set.h"
+#include "ardour/delivery.h"
 #include "ardour/io_processor.h"
 #include "ardour/meter.h"
 #include "ardour/midi_diskstream.h"
@@ -57,9 +58,6 @@ MidiTrack::MidiTrack (Session& sess, string name, Route::Flag flag, TrackMode mo
        _freeze_record.state = NoFreeze;
        _saved_meter_point = _meter_point;
        _mode = mode;
-
-       set_input_minimum(ChanCount(DataType::MIDI, 1));
-       set_input_maximum(ChanCount(DataType::MIDI, 1));
 }
 
 MidiTrack::MidiTrack (Session& sess, const XMLNode& node)
@@ -68,9 +66,6 @@ MidiTrack::MidiTrack (Session& sess, const XMLNode& node)
        , _note_mode(Sustained)
 {
        _set_state(node, false);
-       
-       set_input_minimum(ChanCount(DataType::MIDI, 1));
-       set_input_maximum(ChanCount(DataType::MIDI, 1));
 }
 
 MidiTrack::~MidiTrack ()
@@ -100,14 +95,14 @@ int
 MidiTrack::set_diskstream (boost::shared_ptr<MidiDiskstream> ds)
 {
        _diskstream = ds;
-       _diskstream->set_io (*this);
+       _diskstream->set_route (*this);
        _diskstream->set_destructive (_mode == Destructive);
 
        _diskstream->set_record_enabled (false);
        //_diskstream->monitor_input (false);
 
        ic_connection.disconnect();
-       ic_connection = input_changed.connect (mem_fun (*_diskstream, &MidiDiskstream::handle_input_change));
+       ic_connection = _input->changed.connect (mem_fun (*_diskstream, &MidiDiskstream::handle_input_change));
 
        DiskstreamChanged (); /* EMIT SIGNAL */
 
@@ -119,11 +114,14 @@ 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);
 }
 
@@ -197,6 +195,8 @@ MidiTrack::_set_state (const XMLNode& node, bool call_base)
                   that means "you should create a new diskstream here, not look for
                   an old one.
                */
+
+               cerr << "\n\n\n\n MIDI track " << name() << " found DS id " << id << endl;
                
                if (id == zero) {
                        use_new_diskstream ();
@@ -369,8 +369,6 @@ MidiTrack::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
        int dret;
        boost::shared_ptr<MidiDiskstream> diskstream = midi_diskstream();
        
-       prepare_inputs (nframes);
-
        {
                Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
                if (lm.locked()) {
@@ -403,7 +401,6 @@ MidiTrack::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
        _silent = false;
 
        if ((dret = diskstream->process (transport_frame, nframes, can_record, rec_monitors_input)) != 0) {
-
                silence (nframes);
                return dret;
        }
@@ -411,17 +408,17 @@ MidiTrack::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
        /* special condition applies */
 
        if (_meter_point == MeterInput) {
-               just_meter_input (start_frame, end_frame, nframes);
+               _input->process_input (_meter, start_frame, end_frame, nframes);
        }
 
-       if (diskstream->record_enabled() && !can_record && !Config->get_auto_input()) {
+       if (diskstream->record_enabled() && !can_record && !_session.config.get_auto_input()) {
 
                /* not actually recording, but we want to hear the input material anyway,
                   at least potentially (depending on monitoring options)
-                  */
+               */
 
                passthru (start_frame, end_frame, nframes, 0);
-
+               
        } else {
                /*
                   XXX is it true that the earlier test on n_outputs()
@@ -436,31 +433,33 @@ MidiTrack::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
 
                //const size_t limit = n_process_buffers().n_audio();
                BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
+               
+               diskstream->get_playback (bufs.get_midi(0), start_frame, end_frame);
 
-               diskstream->get_playback(bufs.get_midi(0), start_frame, end_frame);
+               /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
+
+               write_out_of_band_data (bufs, start_frame, end_frame, nframes); 
 
                process_output_buffers (bufs, start_frame, end_frame, nframes,
                                (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick);
-       
        }
 
-       flush_outputs (nframes);
+       _main_outs->flush (nframes);
 
        return 0;
 }
 
 void
-MidiTrack::write_controller_messages(MidiBuffer& output_buf, sframes_t start, sframes_t end, nframes_t nframes)
+MidiTrack::write_out_of_band_data (BufferSet& bufs, sframes_t /*start*/, sframes_t /*end*/, nframes_t nframes)
 {
-       // Append immediate events (UI controls)
-
-       // XXX TAKE _port_offset in Port into account???
+       // Append immediate events
 
-       _immediate_events.read (output_buf, 0, 0, nframes - 1); // all stamps = 0
+       MidiBuffer& buf (bufs.get_midi (0));
+       _immediate_events.read (buf, 0, 0, nframes - 1); // all stamps = 0
 }
 
 int
-MidiTrack::export_stuff (BufferSet& bufs, nframes_t nframes, sframes_t end_frame)
+MidiTrack::export_stuff (BufferSet& /*bufs*/, nframes_t /*nframes*/, sframes_t /*end_frame*/)
 {
        return -1;
 }
@@ -473,7 +472,7 @@ MidiTrack::set_latency_delay (nframes_t longest_session_latency)
 }
 
 boost::shared_ptr<Region>
-MidiTrack::bounce (InterThreadInfo& itt)
+MidiTrack::bounce (InterThreadInfo& /*itt*/)
 {
        throw;
        // vector<MidiSource*> srcs;
@@ -483,7 +482,7 @@ MidiTrack::bounce (InterThreadInfo& itt)
 
 
 boost::shared_ptr<Region>
-MidiTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt, bool enable_processing)
+MidiTrack::bounce_range (nframes_t /*start*/, nframes_t /*end*/, InterThreadInfo& /*itt*/, bool /*enable_processing*/)
 {
        throw;
        //vector<MidiSource*> srcs;
@@ -492,7 +491,7 @@ MidiTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt, b
 }
 
 void
-MidiTrack::freeze (InterThreadInfo& itt)
+MidiTrack::freeze (InterThreadInfo& /*itt*/)
 {
 }