make session/Config now responsible for adding/removing a monitor section
[ardour.git] / libs / ardour / session_state.cc
index b27a292642a21db84a42b62b7461bb1ac959f2b0..8809ab388c12a7debdb3f61236d67db4202b61ec 100644 (file)
 #include "ardour/template_utils.h"
 #include "ardour/tempo.h"
 #include "ardour/ticker.h"
+#include "ardour/transport_master_manager.h"
 #include "ardour/types_convert.h"
 #include "ardour/user_bundle.h"
 #include "ardour/vca.h"
@@ -749,6 +750,8 @@ Session::remove_state (string snapshot_name)
                error << string_compose(_("Could not remove session file at path \"%1\" (%2)"),
                                xml_path, g_strerror (errno)) << endmsg;
        }
+
+       StateSaved (snapshot_name); /* EMIT SIGNAL */
 }
 
 /** @param snapshot_name Name to save under, without .ardour / .pending prefix */
@@ -873,6 +876,32 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot
                }
        }
 
+       //Mixbus auto-backup mechanism
+       if(Profile->get_mixbus()) {
+               if (pending) {  //"pending" save means it's a backup, or some other non-user-initiated save;  a good time to make a backup
+                       // make a serialized safety backup
+                       // (will make one periodically but only one per hour is left on disk)
+                       // these backup files go into a separated folder
+                       char timebuf[128];
+                       time_t n;
+                       struct tm local_time;
+                       time (&n);
+                       localtime_r (&n, &local_time);
+                       strftime (timebuf, sizeof(timebuf), "%y-%m-%d.%H", &local_time);
+                       std::string save_path(session_directory().backup_path());
+                       save_path += G_DIR_SEPARATOR;
+                       save_path += legalize_for_path(_current_snapshot_name);
+                       save_path += "-";
+                       save_path += timebuf;
+                       save_path += statefile_suffix;
+                       if ( !tree.write (save_path) )
+                                       error << string_compose(_("Could not save backup file at path \"%1\" (%2)"),
+                                                       save_path, g_strerror (errno)) << endmsg;
+               }
+
+               StateSaved (snapshot_name); /* EMIT SIGNAL */
+       }
+
        if (!pending && !for_archive) {
 
                save_history (snapshot_name);
@@ -1451,12 +1480,7 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool only_used_ass
                gain_child->add_child_nocopy (_click_gain->get_state ());
        }
 
-       if (_ltc_input) {
-               XMLNode* ltc_input_child = node->add_child ("LTC-In");
-               ltc_input_child->add_child_nocopy (_ltc_input->get_state ());
-       }
-
-       if (_ltc_input) {
+       if (_ltc_output) {
                XMLNode* ltc_output_child = node->add_child ("LTC-Out");
                ltc_output_child->add_child_nocopy (_ltc_output->get_state ());
        }
@@ -1495,8 +1519,7 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool only_used_ass
 XMLNode&
 Session::get_control_protocol_state ()
 {
-       ControlProtocolManager& cpm (ControlProtocolManager::instance());
-       return cpm.get_state();
+       return ControlProtocolManager::instance().get_state ();
 }
 
 int
@@ -1706,7 +1729,7 @@ Session::set_state (const XMLNode& node, int version)
        }
 
        if ((child = find_named_node (node, ControlProtocolManager::state_node_name)) != 0) {
-               ControlProtocolManager::instance().set_state (*child, version);
+               ControlProtocolManager::instance().set_state (*child, 1 /* here: session-specific state */);
        }
 
        if ((child = find_named_node (node, "Script"))) {
@@ -3646,7 +3669,7 @@ Session::set_dirty ()
        }
 
        /* never mark session dirty during loading */
-       if (_state_of_the_state & Loading) {
+       if (_state_of_the_state & (Loading | Deletion)) {
                return;
        }
 
@@ -4075,11 +4098,7 @@ Session::config_changed (std::string p, bool ours)
                first_file_data_format_reset = false;
 
        } else if (p == "external-sync") {
-               if (!config.get_external_sync()) {
-                       drop_sync_source ();
-               } else {
-                       switch_to_sync_source (Config->get_sync_source());
-               }
+               request_sync_source (TransportMasterManager::instance().current());
        }  else if (p == "denormal-model") {
                setup_fpu ();
        } else if (p == "history-depth") {
@@ -4110,14 +4129,19 @@ Session::config_changed (std::string p, bool ours)
                last_timecode_valid = false;
        } else if (p == "playback-buffer-seconds") {
                AudioSource::allocate_working_buffers (sample_rate());
-       } else if (p == "ltc-source-port") {
-               reconnect_ltc_input ();
        } else if (p == "ltc-sink-port") {
                reconnect_ltc_output ();
        } else if (p == "timecode-generator-offset") {
                ltc_tx_parse_offset();
        } else if (p == "auto-return-target-list") {
                follow_playhead_priority ();
+       } else if (p == "use-monitor-bus") {
+               bool yn = Config->get_use_monitor_bus();
+               if (yn && !_monitor_out) {
+                       add_monitor_section ();
+               } else if (!yn && _monitor_out) {
+                       remove_monitor_section ();
+               }
        }
 
        set_dirty ();
@@ -4193,9 +4217,9 @@ Session::save_snapshot_name (const std::string & n)
         */
        instant_xml ("LastUsedSnapshot");
 
-       XMLNode* last_used_snapshot = new XMLNode ("LastUsedSnapshot");
-       last_used_snapshot->set_property ("name", n);
-       add_instant_xml (*last_used_snapshot, false);
+       XMLNode last_used_snapshot ("LastUsedSnapshot");
+       last_used_snapshot.set_property ("name", n);
+       add_instant_xml (last_used_snapshot, false);
 }
 
 void
@@ -5242,6 +5266,9 @@ Session::archive_session (const std::string& dest,
                /* build a list of used names */
                std::set<std::string> audio_file_names;
                for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
+                       if (boost::dynamic_pointer_cast<SilentFileSource> (i->second)) {
+                               continue;
+                       }
                        boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
                        if (!afs || afs->readable_length () == 0) {
                                continue;
@@ -5258,6 +5285,9 @@ Session::archive_session (const std::string& dest,
                }
 
                for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
+                       if (boost::dynamic_pointer_cast<SilentFileSource> (i->second)) {
+                               continue;
+                       }
                        boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
                        if (!afs || afs->readable_length () == 0) {
                                continue;
@@ -5319,6 +5349,9 @@ Session::archive_session (const std::string& dest,
 
                Glib::Threads::Mutex::Lock lm (source_lock);
                for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) {
+                       if (boost::dynamic_pointer_cast<SilentFileSource> (i->second)) {
+                               continue;
+                       }
                        boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (i->second);
                        if (!afs || afs->readable_length () == 0) {
                                continue;