summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-08-28 14:01:52 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2014-09-15 18:23:02 -0400
commit499e9a5ec6db2f0d9b4a7dc23e9c99b6858328d0 (patch)
treee4566953494ba96374716456afcf907ccfc1d08b
parentab22a06ec7cc0027caffe521e7a53fc12379570c (diff)
tentative fix for losing (empty) MIDI files. Incomplete because testing shows issues with some workflows
-rw-r--r--libs/ardour/ardour/source.h3
-rw-r--r--libs/ardour/enums.cc1
-rw-r--r--libs/ardour/session.cc6
-rw-r--r--libs/ardour/smf_source.cc28
4 files changed, 29 insertions, 9 deletions
diff --git a/libs/ardour/ardour/source.h b/libs/ardour/ardour/source.h
index 5e851702d4..4427d65cc1 100644
--- a/libs/ardour/ardour/source.h
+++ b/libs/ardour/ardour/source.h
@@ -47,7 +47,8 @@ class Source : public SessionObject
RemovableIfEmpty = 0x10,
RemoveAtDestroy = 0x20,
NoPeakFile = 0x40,
- Destructive = 0x80
+ Destructive = 0x80,
+ Empty = 0x100, /* used for MIDI only */
};
Source (Session&, DataType type, const std::string& name, Flag flags=Flag(0));
diff --git a/libs/ardour/enums.cc b/libs/ardour/enums.cc
index e32fe329af..142ce2cc5f 100644
--- a/libs/ardour/enums.cc
+++ b/libs/ardour/enums.cc
@@ -447,6 +447,7 @@ setup_enum_writer ()
REGISTER_CLASS_ENUM (Source, RemoveAtDestroy);
REGISTER_CLASS_ENUM (Source, NoPeakFile);
REGISTER_CLASS_ENUM (Source, Destructive);
+ REGISTER_CLASS_ENUM (Source, Empty);
REGISTER_BITS (_Source_Flag);
REGISTER_ENUM (FadeLinear);
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 0e4a10f76b..2d26cb73b4 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -3603,7 +3603,11 @@ Session::create_midi_source_by_stealing_name (boost::shared_ptr<Track> track)
return boost::shared_ptr<MidiSource>();
}
- const string path = new_midi_source_path (name);
+ /* MIDI files are small, just put them in the first location of the
+ session source search path.
+ */
+
+ const string path = Glib::build_filename (source_search_path (DataType::MIDI).front(), name);
return boost::dynamic_pointer_cast<SMFSource> (
SourceFactory::createWritable (
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc
index 1cd456ee58..be141ef192 100644
--- a/libs/ardour/smf_source.cc
+++ b/libs/ardour/smf_source.cc
@@ -71,6 +71,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) {
@@ -131,12 +133,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 ();
@@ -379,6 +392,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) */
@@ -425,6 +439,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&
@@ -667,10 +682,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 ();
@@ -702,9 +719,6 @@ SMFSource::ensure_disk_file ()
if (!_open) {
open_for_write ();
}
-
- /* Flush, which will definitely put something on disk */
- flush_midi ();
}
}