diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-08-28 14:01:52 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-09-15 14:09:12 -0400 |
commit | c96ec968c7bb4b1d7c358f522a49b0685c022920 (patch) | |
tree | 9c2dcba77150c2a0281f6a9a62625c9696a8fb18 /libs/ardour/smf_source.cc | |
parent | dbc34ab4dac07a17aa5181e5a1bf6271b68f3660 (diff) |
tentative fix for losing (empty) MIDI files. Incomplete because testing shows issues with some workflows
Diffstat (limited to 'libs/ardour/smf_source.cc')
-rw-r--r-- | libs/ardour/smf_source.cc | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 6ec7c5a78c..59f4c240d9 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -72,6 +72,8 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags) assert (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); existence_check (); + _flags = Source::Flag (_flags | Empty); + /* file is not opened until write */ if (flags & Writable) { @@ -132,12 +134,23 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist) throw failed_constructor (); } - if (init (_path, true)) { + /* we expect the file to exist, but if no MIDI data was ever added + it will have been removed at last session close. so, we don't + require it to exist if it was marked Empty. + */ + + if (init (_path, !(_flags & Source::Empty))) { throw failed_constructor (); } - assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); - existence_check (); + if (!(_flags & Source::Empty)) { + assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); + existence_check (); + } else { + assert (_flags & Source::Writable); + /* file will be opened on write */ + return; + } if (open(_path)) { throw failed_constructor (); @@ -380,6 +393,7 @@ SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev) Evoral::SMF::append_event_delta(delta_time_ticks, ev.size(), ev.buffer(), event_id); _last_ev_time_beats = ev.time(); + _flags = Source::Flag (_flags & ~Empty); } /** Append an event with a timestamp in frames (framepos_t) */ @@ -426,6 +440,7 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<framepos_t>& ev, fr Evoral::SMF::append_event_delta(delta_time_ticks, ev.size(), ev.buffer(), event_id); _last_ev_time_frames = ev.time(); + _flags = Source::Flag (_flags & ~Empty); } XMLNode& @@ -668,10 +683,12 @@ SMFSource::destroy_model () void SMFSource::flush_midi () { - if (!writable() || (writable() && !_open)) { + if (!writable() || _length_beats == 0.0) { return; } + ensure_disk_file (); + Evoral::SMF::end_write (); /* data in the file means its no longer removable */ mark_nonremovable (); @@ -703,9 +720,6 @@ SMFSource::ensure_disk_file () if (!_open) { open_for_write (); } - - /* Flush, which will definitely put something on disk */ - flush_midi (); } } |