From 1e6b6df77321958ce50b4db79e446bd2c1ce9f23 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 24 Sep 2014 19:03:59 -0400 Subject: next (final?) part of handling missing MIDI files. If an external-to-session file is missing, consider it a fatal error in session loading. If an internal-to-session file is missing, just create a new MIDI source with the same path and ID, and use that instead. --- libs/ardour/session_state.cc | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 6c5734db10..79d8ca1c02 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1835,7 +1835,10 @@ Session::load_sources (const XMLNode& node) { XMLNodeList nlist; XMLNodeConstIterator niter; - boost::shared_ptr source; + boost::shared_ptr source; /* don't need this but it stops some + * versions of gcc complaining about + * discarded return values. + */ nlist = node.children(); @@ -1852,9 +1855,15 @@ Session::load_sources (const XMLNode& node) int user_choice; + if (err.type == DataType::MIDI && Glib::path_is_absolute (err.path)) { + error << string_compose (_("A external MIDI file is missing. %1 cannot currently recover from missing external MIDI files"), + PROGRAM_NAME) << endmsg; + return -1; + } + if (!no_questions_about_missing_files) { - user_choice = MissingFile (this, err.path, err.type).get_value_or (-1); - } else { + user_choice = MissingFile (this, err.path, err.type).get_value_or (-1); + } else { user_choice = -2; } @@ -1882,14 +1891,30 @@ Session::load_sources (const XMLNode& node) switch (err.type) { case DataType::AUDIO: - warning << _("A sound file is missing. It will be replaced by silence.") << endmsg; source = SourceFactory::createSilent (*this, **niter, max_framecnt, _current_frame_rate); break; case DataType::MIDI: - warning << string_compose (_("A MIDI file is missing. %1 cannot currently recover from missing MIDI files"), - PROGRAM_NAME) << endmsg; - return -1; + /* The MIDI file is actually missing so + * just create a new one in the same + * location. Do not announce its + */ + string fullpath; + + if (!Glib::path_is_absolute (err.path)) { + fullpath = Glib::build_filename (source_search_path (DataType::MIDI).front(), err.path); + } else { + /* this should be an unrecoverable error: we would be creating a MIDI file outside + the session tree. + */ + return -1; + } + /* Note that we do not announce the source just yet - we need to reset its ID before we do that */ + source = SourceFactory::createWritable (DataType::MIDI, *this, fullpath, false, _current_frame_rate, false, false); + /* reset ID to match the missing one */ + source->set_id (**niter); + /* Now we can announce it */ + SourceFactory::SourceCreated (source); break; } break; -- cgit v1.2.3