diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index e2f36b07ec..5e54c1580a 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -64,6 +64,7 @@ public: void destroy_model (); void flush_midi (); + void ensure_disk_file (); static void set_header_position_offset (framecnt_t offset, bool negative); diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index 3659a2ac60..6c51958caa 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -1314,13 +1314,8 @@ MidiDiskstream::steal_write_sources() { list > 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(_write_source)->session_saved (); + /* put some data on the disk, even if its just a header for an empty file */ + boost::dynamic_pointer_cast (_write_source)->ensure_disk_file (); /* never let it go away */ _write_source->mark_nonremovable (); diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 90ee20ab66..2a02e50da7 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -578,3 +578,29 @@ SMFSource::set_path (const string& p) FileSource::set_path (p); SMF::set_path (_path); } + +/** Ensure that this source has some file on disk, even if it's just a SMF header */ +void +SMFSource::ensure_disk_file () +{ + if (_model) { + /* We have a model, so write it to disk; see MidiSource::session_saved + for an explanation of what we are doing here. + */ + boost::shared_ptr mm = _model; + _model.reset (); + mm->sync_to_source (); + _model = mm; + } else { + /* No model; if it's not already open, it's an empty source, so create + and open it for writing. + */ + if (!_open) { + open_for_write (); + } + + /* Flush, which will definitely put something on disk */ + flush_midi (); + } +} +