Fix broken whitespace. I'd apologize for the compile times if it was my fault :D
[ardour.git] / libs / ardour / midi_diskstream.cc
index 6b400a02d0d3b0bf75d6872532ccd6512769efb4..0539e3b62f744e5d0e4f4f4f579d2f3edf5cc70e 100644 (file)
@@ -36,6 +36,7 @@
 #include "pbd/memento_command.h"
 #include "pbd/enumwriter.h"
 #include "pbd/stateful_diff_command.h"
+#include "pbd/stacktrace.h"
 
 #include "ardour/ardour.h"
 #include "ardour/audioengine.h"
@@ -78,8 +79,6 @@ MidiDiskstream::MidiDiskstream (Session &sess, const string &name, Diskstream::F
        , _frames_written_to_ringbuffer(0)
        , _frames_read_from_ringbuffer(0)
 {
-       /* prevent any write sources from being created */
-
        in_set_state = true;
 
        init ();
@@ -147,7 +146,7 @@ MidiDiskstream::non_realtime_locate (framepos_t position)
        if (_write_source) {
                _write_source->set_timeline_position (position);
        }
-       seek(position, false);
+       seek (position, false);
 }
 
 
@@ -162,17 +161,24 @@ MidiDiskstream::non_realtime_input_change ()
                }
 
                if (input_change_pending.type & IOChange::ConfigurationChanged) {
-                       if (_io->n_ports().n_midi() != _n_channels.n_midi()) {
+                       uint32_t ni = _io->n_ports().n_midi();
+
+                       if (ni != _n_channels.n_midi()) {
                                error << string_compose (_("%1: I/O configuration change %4 requested to use %2, but channel setup is %3"),
                                                         name(),
                                                         _io->n_ports(),
                                                         _n_channels, input_change_pending.type)
                                      << endmsg;
                        }
+
+                       if (ni == 0) {
+                               _source_port = 0;
+                       } else {
+                               _source_port = _io->midi(0);
+                       }
                }
 
                if (input_change_pending.type & IOChange::ConnectionsChanged) {
-                       get_input_sources ();
                        set_capture_offset ();
                        set_align_style_from_io ();
                }
@@ -199,23 +205,6 @@ MidiDiskstream::non_realtime_input_change ()
        _last_flush_frame = _session.transport_frame();
 }
 
-void
-MidiDiskstream::get_input_sources ()
-{
-       uint32_t ni = _io->n_ports().n_midi();
-
-       if (ni == 0) {
-               return;
-       }
-
-       // This is all we do for now at least
-       assert(ni == 1);
-
-       _source_port = _io->midi(0);
-
-       // do... stuff?
-}
-
 int
 MidiDiskstream::find_and_use_playlist (const string& name)
 {
@@ -504,6 +493,10 @@ MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, bool can
                return 0;
        }
 
+       if (_source_port == 0) {
+               return 1;
+       }
+
        Glib::Mutex::Lock sm (state_lock, Glib::TRY_LOCK);
 
        if (!sm.locked()) {
@@ -524,7 +517,6 @@ MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, bool can
                }
        }
 
-
        if (can_record && !_last_capture_sources.empty()) {
                _last_capture_sources.clear ();
        }
@@ -828,7 +820,7 @@ MidiDiskstream::do_refill ()
        //      << frames_written - frames_read << endl;
 
        to_read = (framecnt_t) min ((framecnt_t) to_read, (framecnt_t) (max_framepos - file_frame));
+
        if (read (file_frame, to_read, reversed)) {
                ret = -1;
        }
@@ -1078,7 +1070,7 @@ MidiDiskstream::transport_stopped_wallclock (struct tm& /*when*/, time_t /*twhen
                                _write_source.reset();
                        }
                }
-               
+
 
                mark_write_completed = true;
        }
@@ -1322,13 +1314,8 @@ MidiDiskstream::steal_write_sources()
 {
        list<boost::shared_ptr<Source> > ret;
 
-       /* put some data on the disk, even if its just a header for an empty file.
-          XXX should we not have a more direct method for doing this? Maybe not
-          since we don't want to mess around with the model/disk relationship
-          that the Source has to pay attention to.
-       */
-
-       boost::dynamic_pointer_cast<MidiSource>(_write_source)->session_saved ();
+       /* put some data on the disk, even if its just a header for an empty file */
+       boost::dynamic_pointer_cast<SMFSource> (_write_source)->ensure_disk_file ();
 
        /* never let it go away */
        _write_source->mark_nonremovable ();
@@ -1375,27 +1362,15 @@ MidiDiskstream::monitor_input (bool yn)
 void
 MidiDiskstream::set_align_style_from_io ()
 {
-       bool have_physical = false;
-
        if (_alignment_choice != Automatic) {
                return;
        }
 
-       if (_io == 0) {
-               return;
-       }
-
-       get_input_sources ();
-
-       if (_source_port && _source_port->flags() & JackPortIsPhysical) {
-               have_physical = true;
-       }
+       /* XXX Not sure what, if anything we can do with MIDI
+          as far as capture alignment etc.
+       */
 
-       if (have_physical) {
-               set_align_style (ExistingMaterial);
-       } else {
-               set_align_style (CaptureTime);
-       }
+       set_align_style (ExistingMaterial);
 }
 
 
@@ -1438,7 +1413,7 @@ MidiDiskstream::get_playback (MidiBuffer& dst, framepos_t start, framepos_t end)
 
 #ifndef NDEBUG
        DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose (
-                            "%1 MDS pre-read read from %2 write to %3\n", _name, 
+                            "%1 MDS pre-read read from %2 write to %3\n", _name,
                             _playback_buf->get_read_ptr(), _playback_buf->get_write_ptr()));
 //        cerr << "================\n";
 //        _playback_buf->dump (cerr);
@@ -1458,3 +1433,14 @@ MidiDiskstream::get_playback (MidiBuffer& dst, framepos_t start, framepos_t end)
        g_atomic_int_add(&_frames_read_from_ringbuffer, frames_read);
 }
 
+bool
+MidiDiskstream::set_name (string const & name)
+{
+       Diskstream::set_name (name);
+
+       /* get a new write source so that its name reflects the new diskstream name */
+       use_new_write_source (0);
+
+       return true;
+}
+