different name for old-session-format copied file, so that 0.99 can always load it
[ardour.git] / libs / ardour / session_state.cc
index fb15de15c4b468bea5acc7fd0457257e7252fbd9..efd2d180f284232d59dced08d0225ff5e802dd5f 100644 (file)
@@ -15,7 +15,6 @@
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     
-  $Id$
 */
 
 #include <algorithm>
@@ -55,6 +54,7 @@
 #include <pbd/pthread_utils.h>
 #include <pbd/strsplit.h>
 #include <pbd/stacktrace.h>
+#include <pbd/copyfile.h>
 
 #include <ardour/audioengine.h>
 #include <ardour/configuration.h>
@@ -63,7 +63,8 @@
 #include <ardour/utils.h>
 #include <ardour/audioplaylist.h>
 #include <ardour/audiofilesource.h>
-#include <ardour/destructive_filesource.h>
+#include <ardour/silentfilesource.h>
+#include <ardour/sndfilesource.h>
 #include <ardour/sndfile_helpers.h>
 #include <ardour/auditioner.h>
 #include <ardour/export.h>
@@ -99,12 +100,14 @@ void
 Session::first_stage_init (string fullpath, string snapshot_name)
 {
        if (fullpath.length() == 0) {
+               destroy ();
                throw failed_constructor();
        }
 
        char buf[PATH_MAX+1];
        if (!realpath (fullpath.c_str(), buf) && (errno != ENOENT)) {
                error << string_compose(_("Could not use path %1 (%s)"), buf, strerror(errno)) << endmsg;
+               destroy ();
                throw failed_constructor();
        }
 
@@ -128,6 +131,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        insert_cnt = 0;
        _transport_speed = 0;
        _last_transport_speed = 0;
+       auto_play_legal = false;
        transport_sub_state = 0;
        _transport_frame = 0;
        last_stop_frame = 0;
@@ -155,7 +159,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        _worst_output_latency = 0;
        _worst_input_latency = 0;
        _worst_track_latency = 0;
-       _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading);
+       _state_of_the_state = StateOfTheState(CannotSave|InitialConnecting|Loading|Deletion);
        _slave = 0;
        butler_mixdown_buffer = 0;
        butler_gain_buffer = 0;
@@ -180,6 +184,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
        current_trans = 0;
        first_file_data_format_reset = true;
        first_file_header_format_reset = true;
+       butler_thread = (pthread_t) 0;
+       midi_thread = (pthread_t) 0;
 
        AudioDiskstream::allocate_working_buffers();
        
@@ -307,7 +313,21 @@ Session::second_stage_init (bool new_session)
        _engine.Halted.connect (mem_fun (*this, &Session::engine_halted));
        _engine.Xrun.connect (mem_fun (*this, &Session::xrun_recovery));
 
-       when_engine_running();
+       try {
+               when_engine_running();
+       }
+
+       /* handle this one in a different way than all others, so that its clear what happened */
+       
+       catch (AudioEngine::PortRegistrationFailure& err) {
+               error << _("Unable to create all required ports")
+                     << endmsg;
+               return -1;
+       }
+
+       catch (...) {
+               return -1;
+       }
 
        send_full_time_code ();
        _engine.transport_locate (0);
@@ -448,11 +468,16 @@ Session::create (bool& new_session, string* mix_template, nframes_t initial_leng
                return -1;
        }
 
-       dir = sound_dir ();
+       /* if this is is an existing session with an old "sounds" directory, just use it. see Session::sound_dir() for more details */
 
-       if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create session sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
-               return -1;
+       if (!Glib::file_test (old_sound_dir(), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_DIR)) {
+
+               dir = sound_dir ();
+               
+               if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
+                       error << string_compose(_("Session: cannot create session sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+                       return -1;
+               }
        }
 
        dir = dead_sound_dir ();
@@ -462,10 +487,10 @@ Session::create (bool& new_session, string* mix_template, nframes_t initial_leng
                return -1;
        }
 
-       dir = automation_dir ();
+       dir = export_dir ();
 
        if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create session automation dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+               error << string_compose(_("Session: cannot create session export dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
                return -1;
        }
 
@@ -549,6 +574,14 @@ Session::load_diskstreams (const XMLNode& node)
        return 0;
 }
 
+void
+Session::maybe_write_autosave()
+{
+        if (dirty() && record_status() != Recording) {
+                save_state("", true);
+        }
+}
+
 void
 Session::remove_pending_capture_state ()
 {
@@ -561,6 +594,48 @@ Session::remove_pending_capture_state ()
        unlink (xml_path.c_str());
 }
 
+/** Rename a state file.
+ * @param snapshot_name Snapshot name.
+ */
+void
+Session::rename_state (string old_name, string new_name)
+{
+       if (old_name == _current_snapshot_name || old_name == _name) {
+               /* refuse to rename the current snapshot or the "main" one */
+               return;
+       }
+       
+       const string old_xml_path = _path + old_name + _statefile_suffix;
+       const string new_xml_path = _path + new_name + _statefile_suffix;
+
+       if (rename (old_xml_path.c_str(), new_xml_path.c_str()) != 0) {
+               error << string_compose(_("could not rename snapshot %1 to %2"), old_name, new_name) << endmsg;
+       }
+}
+
+/** Remove a state file.
+ * @param snapshot_name Snapshot name.
+ */
+void
+Session::remove_state (string snapshot_name)
+{
+       if (snapshot_name == _current_snapshot_name || snapshot_name == _name) {
+               /* refuse to remove the current snapshot or the "main" one */
+               return;
+       }
+       
+       const string xml_path = _path + snapshot_name + _statefile_suffix;
+
+       /* make a backup copy of the state file */
+       const string bak_path = xml_path + ".bak";
+       if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
+               copy_file (xml_path, bak_path);
+       }
+
+       /* and delete it */
+       unlink (xml_path.c_str());
+}
+
 int
 Session::save_state (string snapshot_name, bool pending)
 {
@@ -572,6 +647,12 @@ Session::save_state (string snapshot_name, bool pending)
                return 1;
        }
 
+       if (!_engine.connected ()) {
+               error << _("Ardour's audio engine is not connected and state saving would lose all I/O connections. Session not saved")
+                     << endmsg;
+               return 1;
+       }
+
        tree.set_root (&get_state());
 
        if (snapshot_name.empty()) {
@@ -580,41 +661,22 @@ Session::save_state (string snapshot_name, bool pending)
 
        if (!pending) {
 
+               /* proper save: use _statefile_suffix (.ardour in English) */
                xml_path = _path;
                xml_path += snapshot_name;
                xml_path += _statefile_suffix;
 
+               /* make a backup copy of the old file */
                bak_path = xml_path;
                bak_path += ".bak";
                
                if (g_file_test (xml_path.c_str(), G_FILE_TEST_EXISTS)) {
-
-                       // Make backup of state file
-               
-                       ifstream in (xml_path.c_str());
-                       ofstream out (bak_path.c_str());
-
-                       if (!in) {
-                               error << string_compose (_("Could not open existing session file %1 for backup"), xml_path) << endmsg;
-                               return -1;
-                       }
-
-                       if (!out) {
-                               error << string_compose (_("Could not open backup session file %1"), bak_path) << endmsg;
-                               return -1;
-                       }
-
-                       out << in.rdbuf();
-
-                       if (!in || !out) {
-                               error << string_compose (_("Could not copy existing session file %1 to %2 for backup"), xml_path, bak_path) << endmsg;
-                               unlink (bak_path.c_str());
-                               return -1;
-                       }
+                       copy_file (xml_path, bak_path);
                }
 
        } else {
 
+               /* pending save: use _pending_suffix (.pending in English) */
                xml_path = _path;
                xml_path += snapshot_name;
                xml_path += _pending_suffix;
@@ -627,7 +689,7 @@ Session::save_state (string snapshot_name, bool pending)
        tmp_path += snapshot_name;
        tmp_path += ".tmp";
 
-       cerr << "actually writing state\n";
+       cerr << "actually writing state to " << xml_path << endl;
 
        if (!tree.write (tmp_path)) {
                error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
@@ -689,7 +751,7 @@ Session::load_state (string snapshot_name)
        xmlpath += snapshot_name;
        xmlpath += _pending_suffix;
 
-       if (!access (xmlpath.c_str(), F_OK)) {
+       if (Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
 
                /* there is pending state from a crashed capture attempt */
 
@@ -704,8 +766,8 @@ Session::load_state (string snapshot_name)
                xmlpath += snapshot_name;
                xmlpath += _statefile_suffix;
        }
-
-       if (access (xmlpath.c_str(), F_OK)) {
+       
+       if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
                error << string_compose(_("%1: session state information file \"%2\" doesn't exist!"), _name, xmlpath) << endmsg;
                return 1;
        }
@@ -714,15 +776,54 @@ Session::load_state (string snapshot_name)
 
        set_dirty();
 
-       if (state_tree->read (xmlpath)) {
-               return 0;
-       } else {
+       if (!state_tree->read (xmlpath)) {
                error << string_compose(_("Could not understand ardour file %1"), xmlpath) << endmsg;
+               delete state_tree;
+               state_tree = 0;
+               return -1;
        }
 
-       delete state_tree;
-       state_tree = 0;
-       return -1;
+       XMLNode& root (*state_tree->root());
+       
+       if (root.name() != X_("Session")) {
+               error << string_compose (_("Session file %1 is not an Ardour session"), xmlpath) << endmsg;
+               delete state_tree;
+               state_tree = 0;
+               return -1;
+       }
+
+       const XMLProperty* prop;
+       bool is_old = false;
+
+       if ((prop = root.property ("version")) == 0) {
+               /* no version implies very old version of Ardour */
+               is_old = true;
+       } else {
+               int major_version;
+               major_version = atoi (prop->value()); // grab just the first number before the period
+               if (major_version < 2) {
+                       is_old = true;
+               }
+       }
+
+       if (is_old) {
+               string backup_path;
+
+               backup_path = _path;
+               backup_path += snapshot_name;
+               backup_path += "-1";
+               backup_path += _statefile_suffix;
+
+               info << string_compose (_("Copying old session file %1 to %2\nUse %2 with Ardour versions before 2.0 from now on"),
+                                       xmlpath, backup_path) 
+                    << endmsg;
+
+               copy_file (xmlpath, backup_path);
+
+               /* if it fails, don't worry. right? */
+       }
+
+       return 0;
 }
 
 int
@@ -1008,19 +1109,7 @@ XMLNode&
 Session::get_control_protocol_state ()
 {
        ControlProtocolManager& cpm (ControlProtocolManager::instance());
-       XMLNode* node = new XMLNode (X_("ControlProtocols"));
-
-       cpm.foreach_known_protocol (bind (mem_fun (*this, &Session::add_control_protocol), node));
-       
-       return *node;
-}
-
-void
-Session::add_control_protocol (const ControlProtocolInfo* const cpi, XMLNode* node)
-{
-       if (cpi->protocol) {
-               node->add_child_nocopy (cpi->protocol->get_state());
-       }
+       return cpm.get_state();
 }
 
 int
@@ -1365,6 +1454,19 @@ Session::XMLRegionFactory (const XMLNode& node, bool full)
        
        try {
                boost::shared_ptr<AudioRegion> region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (sources, node)));
+
+               /* a final detail: this is the one and only place that we know how long missing files are */
+
+               if (region->whole_file()) {
+                       for (SourceList::iterator sx = sources.begin(); sx != sources.end(); ++sx) {
+                               boost::shared_ptr<SilentFileSource> sfp = boost::dynamic_pointer_cast<SilentFileSource> (*sx);
+                               if (sfp) {
+                                       sfp->set_length (region->length());
+                               }
+                       }
+               }
+
+
                return region;
                                                       
        }
@@ -1404,11 +1506,16 @@ Session::path_from_region_name (string name, string identifier)
                } else {
                        snprintf (buf, sizeof(buf), "%s/%s-%" PRIu32 ".wav", dir.c_str(), name.c_str(), n);
                }
-               if (access (buf, F_OK) != 0) {
+
+               if (!Glib::file_test (buf, Glib::FILE_TEST_EXISTS)) {
                        return buf;
                }
        }
 
+       error << string_compose (_("cannot create new file from region name \"%1\" with ident = \"%2\": too many existing files with similar names"),
+                                name, identifier)
+             << endmsg;
+
        return "";
 }
        
@@ -1426,10 +1533,16 @@ Session::load_sources (const XMLNode& node)
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
 
-               if ((source = XMLSourceFactory (**niter)) == 0) {
-                       error << _("Session: cannot create Source from XML description.") << endmsg;
+               try {
+                       if ((source = XMLSourceFactory (**niter)) == 0) {
+                               error << _("Session: cannot create Source from XML description.") << endmsg;
+                       }
                }
 
+               catch (non_existent_source& err) {
+                       warning << _("A sound file is missing. It will be replaced by silence.") << endmsg;
+                       source = SourceFactory::createSilent (*this, **niter, max_frames, _current_frame_rate);
+               }
        }
 
        return 0;
@@ -1445,7 +1558,7 @@ Session::XMLSourceFactory (const XMLNode& node)
        try {
                return SourceFactory::create (*this, node);
        }
-       
+
        catch (failed_constructor& err) {
                error << _("Found a sound file that cannot be used by Ardour. Talk to the progammers.") << endmsg;
                return boost::shared_ptr<Source>();
@@ -1794,36 +1907,34 @@ Session::dead_sound_dir () const
 {
        string res = _path;
        res += dead_sound_dir_name;
-       res += '/';
+
        return res;
 }
 
 string
-Session::sound_dir (bool with_path) const
+Session::old_sound_dir (bool with_path) const
 {
-       /* support old session structure */
+       string res;
 
-       struct stat statbuf;
-       string old_nopath;
-       string old_withpath;
+       if (with_path) {
+               res = _path;
+       }
 
-       old_nopath += old_sound_dir_name;
-       old_nopath += '/';
-       
-       old_withpath = _path;
-       old_withpath += old_sound_dir_name;
+       res += old_sound_dir_name;
 
-       if (stat (old_withpath.c_str(), &statbuf) == 0) {
-               if (with_path)
-                       return old_withpath;
-               
-               return old_nopath;
-       }
+       return res;
+}
 
+string
+Session::sound_dir (bool with_path) const
+{
        string res;
+       string full;
 
        if (with_path) {
                res = _path;
+       } else {
+               full = _path;
        }
 
        res += interchange_dir_name;
@@ -1832,6 +1943,38 @@ Session::sound_dir (bool with_path) const
        res += '/';
        res += sound_dir_name;
 
+       if (with_path) {
+               full = res;
+       } else {
+               full += res;
+       }
+       
+       /* if this already exists, don't check for the old session sound directory */
+
+       if (Glib::file_test (full, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
+               return res;
+       }
+               
+       /* possibly support old session structure */
+
+       string old_nopath;
+       string old_withpath;
+
+       old_nopath += old_sound_dir_name;
+       old_nopath += '/';
+       
+       old_withpath = _path;
+       old_withpath += old_sound_dir_name;
+       
+       if (Glib::file_test (old_withpath.c_str(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
+               if (with_path)
+                       return old_withpath;
+               
+               return old_nopath;
+       }
+       
+       /* ok, old "sounds" directory isn't there, return the new path */
+
        return res;
 }
 
@@ -1861,6 +2004,15 @@ Session::template_dir ()
        return path;
 }
 
+string
+Session::export_dir () const
+{
+       string res = _path;
+       res += export_dir_name;
+       res += '/';
+       return res;
+}
+
 string
 Session::suffixed_search_path (string suffix, bool data)
 {
@@ -2425,9 +2577,7 @@ struct RegionCounter {
 int
 Session::cleanup_sources (Session::cleanup_report& rep)
 {
-       typedef map<boost::shared_ptr<Source>, RegionCounter> SourceRegionMap;
-       SourceRegionMap dead_sources;
-
+       vector<boost::shared_ptr<Source> > dead_sources;
        vector<boost::shared_ptr<Playlist> > playlists_tbd;
        PathScanner scanner;
        string sound_path;
@@ -2473,104 +2623,26 @@ Session::cleanup_sources (Session::cleanup_report& rep)
 
        playlists_tbd.clear ();
 
-       /* step 2: find all un-referenced sources */
+       /* step 2: find all un-used sources */
 
        rep.paths.clear ();
        rep.space = 0;
 
-       for (AudioSourceList::iterator i = audio_sources.begin(); i != audio_sources.end(); ++i) {
+       for (AudioSourceList::iterator i = audio_sources.begin(); i != audio_sources.end(); ) {
                
-               /* we expect the use_count() to be at least 2: one for the shared_ptr<> in the sources
-                  list and one for the iterator. if its used by 1 region, we'd expect a value of 3.
-
-                  do not bother with files that are zero size, otherwise we remove the current "nascent"
-                  capture files.
-               */
-
-               if (i->second.use_count() <= 3 && i->second->length() > 0) {
-
-                       pair<boost::shared_ptr<Source>, RegionCounter> newpair;
-
-                       newpair.first = i->second;
-                       newpair.second.iter = i;
-
-                       dead_sources.insert (newpair);
-               } 
-       }
-
-       /* Search the region list to find out the state of the supposedly unreferenced regions 
-        */
-
-       for (SourceRegionMap::iterator i = dead_sources.begin(); i != dead_sources.end();++i) {
-
-               for (AudioRegionList::iterator r = audio_regions.begin(); r != audio_regions.end(); ++r) {
-                       
-                       boost::shared_ptr<AudioRegion> ar = r->second;
-
-                       for (uint32_t n = 0; n < ar->n_channels(); ++n) {
-
-                               if (ar->source (n) == i->first) {
-                                       
-                                       /* this region uses this source */
-
-                                       i->second.region = ar;
-                                       i->second.count++;
-
-                                       if (i->second.count > 1) {
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /* next, get rid of all regions in the region list that use any dead sources
-          in case the sources themselves don't go away (they might be referenced in
-          other snapshots).
-
-          this is also where we remove the apparently unused sources from our source
-          list. this doesn't rename them or delete them, but it means they are
-          potential candidates for renaming after we find all soundfiles
-          and scan for use across all snapshots (including this one).
-       */
-       
-       for (SourceRegionMap::iterator i = dead_sources.begin(); i != dead_sources.end(); ) {
-
-               SourceRegionMap::iterator tmp;
+               AudioSourceList::iterator tmp;
 
                tmp = i;
                ++tmp;
 
-               if (i->second.count == 0) {
-
-                       /* no regions use this source */
-
-                       /* remove this source from our own list to avoid us
-                          adding it to the list of all sources below
-                       */
-
-                       audio_sources.erase (i->second.iter);
-
-               } else if (i->second.count == 1) {
-
-                       /* the use_count for the source was 3. this means that there is only reference to it in addition to the source
-                          list and an iterator used to traverse that list. since there is a single region using the source, that
-                          must be the extra reference. this implies that its a whole-file region
-                          with no children, so remove the region and the source.
-                       */
-
-                       remove_region (i->second.region);
-
-                       /* remove this source from our own list to avoid us
-                          adding it to the list of all sources below
-                       */
-
-                       audio_sources.erase (i->second.iter);
+               /* do not bother with files that are zero size, otherwise we remove the current "nascent"
+                  capture files.
+               */
 
-               } else {
-                       /* more than one region uses this source, do not remove it */
-                       dead_sources.erase (i);
-               }
+               if (!i->second->used() && i->second->length() > 0) {
+                       dead_sources.push_back (i->second);
+                       i->second->GoingAway();
+               } 
 
                i = tmp;
        }
@@ -2620,6 +2692,9 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                } 
        }
 
+       char tmppath1[PATH_MAX+1];
+       char tmppath2[PATH_MAX+1];
+       
        for (vector<string*>::iterator x = soundfiles->begin(); x != soundfiles->end(); ++x) {
 
                used = false;
@@ -2627,11 +2702,13 @@ Session::cleanup_sources (Session::cleanup_report& rep)
 
                for (set<string>::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
 
-                       if (spath == *i) {
+                       realpath(spath.c_str(), tmppath1);
+                       realpath((*i).c_str(),  tmppath2);
+
+                       if (strcmp(tmppath1, tmppath2) == 0) {
                                used = true;
                                break;
                        }
-
                }
 
                if (!used) {
@@ -2656,15 +2733,31 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                   on whichever filesystem it was already on.
                */
 
-               /* XXX this is a hack ... go up 4 levels */
+               if ((*x).find ("/sounds/") != string::npos) {
+
+                       /* old school, go up 1 level */
 
-               newpath = Glib::path_get_dirname (*x);      // "audiofiles" 
-               newpath = Glib::path_get_dirname (newpath); // "session-name"
-               newpath = Glib::path_get_dirname (newpath); // "interchange"
-               newpath = Glib::path_get_dirname (newpath); // "session-dir"
+                       newpath = Glib::path_get_dirname (*x);      // "sounds" 
+                       newpath = Glib::path_get_dirname (newpath); // "session-name"
+
+               } else {
+
+                       /* new school, go up 4 levels */
+                       
+                       newpath = Glib::path_get_dirname (*x);      // "audiofiles" 
+                       newpath = Glib::path_get_dirname (newpath); // "session-name"
+                       newpath = Glib::path_get_dirname (newpath); // "interchange"
+                       newpath = Glib::path_get_dirname (newpath); // "session-dir"
+               }
 
                newpath += '/';
                newpath += dead_sound_dir_name;
+
+               if (g_mkdir_with_parents (newpath.c_str(), 0755) < 0) {
+                       error << string_compose(_("Session: cannot create session peakfile dir \"%1\" (%2)"), newpath, strerror (errno)) << endmsg;
+                       return -1;
+               }
+
                newpath += '/';
                newpath += Glib::path_get_basename ((*x));
                
@@ -2704,7 +2797,6 @@ Session::cleanup_sources (Session::cleanup_report& rep)
                              << endmsg;
                        goto out;
                }
-               
 
                /* see if there an easy to find peakfile for this file, and remove it.
                 */
@@ -2836,6 +2928,12 @@ Session::set_deletion_in_progress ()
 void
 Session::add_controllable (Controllable* c)
 {
+       /* this adds a controllable to the list managed by the Session.
+          this is a subset of those managed by the Controllable class
+          itself, and represents the only ones whose state will be saved
+          as part of the session.
+       */
+
        Glib::Mutex::Lock lm (controllables_lock);
        controllables.insert (c);
 }
@@ -2902,8 +3000,6 @@ Session::save_history (string snapshot_name)
         return -1;
     }
 
-    cerr << "actually writing history\n";
-
     if (!tree.write (xml_path))
     {
         error << string_compose (_("history could not be saved to %1"), xml_path) << endmsg;
@@ -3020,7 +3116,6 @@ Session::config_changed (const char* parameter_name)
                        
                        for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
                                if ((*i)->record_enabled ()) {
-                                       //cerr << "switching to input = " << !auto_input << __FILE__ << __LINE__ << endl << endl;
                                        (*i)->monitor_input (!Config->get_auto_input());
                                }
                        }
@@ -3072,6 +3167,12 @@ Session::config_changed (const char* parameter_name)
 
                poke_midi_thread ();
 
+       } else if (PARAM_IS ("mmc-device-id")) {
+
+               if (mmc) {
+                       mmc->set_device_id (Config->get_mmc_device_id());
+               }
+
        } else if (PARAM_IS ("midi-control")) {
                
                poke_midi_thread ();
@@ -3080,7 +3181,7 @@ Session::config_changed (const char* parameter_name)
 
                setup_raid_path (Config->get_raid_path());
 
-       } else if (PARAM_IS ("smpte-frames-per-second") || PARAM_IS ("smpte-drop-frames")) {
+       } else if (PARAM_IS ("smpte-format")) {
 
                sync_time_vars ();
 
@@ -3130,6 +3231,8 @@ Session::config_changed (const char* parameter_name)
                                /* mark us ready to send */
                                next_quarter_frame_to_send = 0;
                        }
+               } else {
+                       session_send_mtc = false;
                }
 
        } else if (PARAM_IS ("send-mmc")) {
@@ -3140,6 +3243,9 @@ Session::config_changed (const char* parameter_name)
                
                if (_mmc_port != 0) {
                        session_send_mmc = Config->get_send_mmc();
+               } else {
+                       mmc = 0;
+                       session_send_mmc = false; 
                }
 
        } else if (PARAM_IS ("midi-feedback")) {
@@ -3171,8 +3277,13 @@ Session::config_changed (const char* parameter_name)
                }
 
                first_file_data_format_reset = false;
+
+       } else if (PARAM_IS ("slave-source")) {
+               set_slave_source (Config->get_slave_source());
+       } else if (PARAM_IS ("remote-model")) {
+               set_remote_control_ids ();
        }
-               
+
        set_dirty ();
                   
 #undef PARAM_IS