13
0

fix up condition where a MIDI filesource is marked empty, not found, and its _path member is not set correctly

This commit is contained in:
Paul Davis 2014-09-15 12:38:54 -04:00
parent 596a9247bd
commit 9a3cf7a10b

View File

@ -100,16 +100,15 @@ SMFSource::SMFSource (Session& s, const string& path)
{
/* note that origin remains empty */
if (init (_path, false)) {
if (init (_path, true)) {
throw failed_constructor ();
}
assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS));
existence_check ();
/* file is not opened until write */
if (_flags & Writable) {
/* file is not opened until write */
return;
}
@ -139,8 +138,30 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
require it to exist if it was marked Empty.
*/
if (init (_path, !(_flags & Source::Empty))) {
throw failed_constructor ();
try {
if (init (_path, true)) {
throw failed_constructor ();
}
} catch (MissingSource& err) {
if (_flags & Source::Empty) {
/* we don't care that the file was not found, because
it was empty. But FileSource::init() will have
failed to set our _path correctly, so we have to do
this ourselves. Use the first entry in the search
path for MIDI files, which is assumed to be the
correct "main" location.
*/
std::vector<string> sdirs = s.source_search_path (DataType::MIDI);
_path = Glib::build_filename (sdirs.front(), _path);
/* This might be important, too */
_file_is_new = true;
} else {
/* pass it on */
throw;
}
}
if (!(_flags & Source::Empty)) {
@ -705,6 +726,10 @@ SMFSource::set_path (const string& p)
void
SMFSource::ensure_disk_file ()
{
if (!writable()) {
return;
}
if (_model) {
/* We have a model, so write it to disk; see MidiSource::session_saved
for an explanation of what we are doing here.