allow to load/save default session-properties
authorRobin Gareus <robin@gareus.org>
Sun, 29 Jun 2014 13:45:08 +0000 (15:45 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 29 Jun 2014 14:11:46 +0000 (16:11 +0200)
libs/ardour/ardour/session.h
libs/ardour/ardour/session_configuration.h
libs/ardour/session.cc
libs/ardour/session_configuration.cc
libs/ardour/session_state.cc

index 788d4d9fcb25f8d7b70f4127c67ed9dd7634b51f..a7ca2d00eec719a0384869e7ae9cfc504749e18e 100644 (file)
@@ -401,6 +401,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        int rename (const std::string&);
        bool get_nsm_state () const { return _under_nsm_control; }
        void set_nsm_state (bool state) { _under_nsm_control = state; }
+       bool save_default_options ();
 
        PBD::Signal1<void,std::string> StateSaved;
        PBD::Signal0<void> StateReady;
index e72d19f32208708179e349ef31397f08543d8eb7..c0af2239439c04ffdb8afc2547a688e4f6d0880e 100644 (file)
@@ -35,6 +35,9 @@ public:
        XMLNode& get_variables ();
        void set_variables (XMLNode const &);
 
+       bool load_state ();
+       bool save_state ();
+
        /* define accessor methods */
 
 #undef  CONFIG_VARIABLE
index 3123b59c2c9750e11b7e5399a34217fd5112301e..121df3130cb60f2cf08755d6318ad28e9013b61e 100644 (file)
@@ -300,6 +300,9 @@ Session::Session (AudioEngine &eng,
                        throw failed_constructor ();
                }
 
+               /* load default session properties - if any */
+               config.load_state();
+
        } else {
 
                if (load_state (_current_snapshot_name)) {
index 0cfdb52872ed37946d975fd3682d1120e8972c2a..f9f43ba4b2b0b5fadaaf0af3cd2c9f95e1dbcb5c 100644 (file)
 
 */
 
+#include <glib.h>
+#include <glib/gstdio.h> /* for g_stat() */
+#include <glibmm/miscutils.h> /* for build_filename() */
+
+#include "pbd/file_utils.h"
 #include "pbd/pathexpand.h"
 
 #include "ardour/types.h"
+#include "ardour/filesystem_paths.h"
 #include "ardour/session_configuration.h"
 #include "i18n.h"
 
@@ -122,3 +128,67 @@ SessionConfiguration::map_parameters (boost::function<void (std::string)>& funct
 #undef  CONFIG_VARIABLE
 #undef  CONFIG_VARIABLE_SPECIAL
 }
+
+
+bool
+SessionConfiguration::load_state ()
+{
+       std::string rcfile;
+       GStatBuf statbuf;
+       if (find_file (ardour_config_search_path(), "session.rc", rcfile)) {
+               if (g_stat (rcfile.c_str(), &statbuf)) {
+                       return false;
+               }
+               if (statbuf.st_size == 0) {
+                       return false;
+               }
+               XMLTree tree;
+               if (!tree.read (rcfile.c_str())) {
+                       error << string_compose(_("%1: cannot part default session options \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
+                       return false;
+               }
+
+               XMLNode& root (*tree.root());
+               if (root.name() != X_("SessionDefaults")) {
+                       warning << _("Invalid session default XML Root.") << endmsg;
+                       return false;
+               }
+
+               XMLNode* node;
+               if (((node = find_named_node (root, X_("Config"))) != 0)) {
+                       LocaleGuard lg (X_("POSIX"));
+                       set_variables(*node);
+                       info << _("Loaded custom session defaults.") << endmsg;
+               } else {
+                       warning << _("Found no session defaults in XML file.") << endmsg;
+                       return false;
+               }
+
+               /* CUSTOM OVERRIDES */
+               set_audio_search_path("");
+               set_midi_search_path("");
+               set_raid_path("");
+       }
+       return true;
+}
+
+bool
+SessionConfiguration::save_state ()
+{
+       const std::string rcfile = Glib::build_filename (user_config_directory(), "session.rc");
+       if (rcfile.empty()) {
+               return false;
+       }
+
+       XMLTree tree;
+       XMLNode* root = new XMLNode(X_("SessionDefaults"));
+       root->add_child_nocopy (get_variables ());
+       tree.set_root (root);
+
+       if (!tree.write (rcfile.c_str())) {
+               error << _("Could not save session options") << endmsg;
+               return false;
+       }
+
+       return true;
+}
index 6979f88dcb3389a48d4ffa896b5ba9fd8caa0300..cf0852f5a31b8be681126dd77f0ad31815c102e7 100644 (file)
@@ -879,6 +879,12 @@ Session::load_options (const XMLNode& node)
        return 0;
 }
 
+bool
+Session::save_default_options ()
+{
+       return config.save_state();
+}
+
 XMLNode&
 Session::get_state()
 {