Mackie Control, Fix sends after monitor not showing.
[ardour.git] / libs / surfaces / mackie / device_profile.cc
index fbf7d89361a31b04984c2c501f1daab74b587942..2b9cbd5edb2d462a933fd5d2d61cfabdd7d5db39 100644 (file)
@@ -24,9 +24,9 @@
 
 #include "pbd/xml++.h"
 #include "pbd/error.h"
-#include "pbd/pathscanner.h"
+#include "pbd/file_utils.h"
+#include "pbd/stl_delete.h"
 #include "pbd/replace_all.h"
-#include "pbd/filesystem.h"
 
 #include "ardour/filesystem_paths.h"
 
 
 #include "i18n.h"
 
-using namespace Mackie;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace ArdourSurface;
+using namespace Mackie;
+
 using std::string;
 using std::vector;
 
@@ -56,7 +58,7 @@ static const char * const devprofile_env_variable_name = "ARDOUR_MCP_PATH";
 static const char* const devprofile_dir_name = "mcp";
 static const char* const devprofile_suffix = ".profile";
 
-static SearchPath
+static Searchpath
 devprofile_search_path ()
 {
        bool devprofile_path_defined = false;
@@ -66,23 +68,20 @@ devprofile_search_path ()
                return spath_env;
        }
 
-       SearchPath spath (ardour_data_search_path());
+       Searchpath spath (ardour_data_search_path());
        spath.add_subdirectory_to_paths(devprofile_dir_name);
 
        return spath;
 }
 
-static sys::path
+static std::string
 user_devprofile_directory ()
 {
-       sys::path p(user_config_directory());
-       p /= devprofile_dir_name;
-
-       return p;
+       return Glib::build_filename (user_config_directory(), devprofile_dir_name);
 }
 
 static bool
-devprofile_filter (const string &str, void */*arg*/)
+devprofile_filter (const string &str, void/*arg*/)
 {
        return (str.length() > strlen(devprofile_suffix) &&
                str.find (devprofile_suffix) == (str.length() - strlen (devprofile_suffix)));
@@ -91,27 +90,21 @@ devprofile_filter (const string &str, void */*arg*/)
 void
 DeviceProfile::reload_device_profiles ()
 {
-       DeviceProfile dp;
        vector<string> s;
-       vector<string *> *devprofiles;
-       PathScanner scanner;
-       SearchPath spath (devprofile_search_path());
+       vector<string> devprofiles;
+       Searchpath spath (devprofile_search_path());
 
-       devprofiles = scanner (spath.to_string(), devprofile_filter, 0, false, true);
+       find_files_matching_filter (devprofiles, spath, devprofile_filter, 0, false, true);
        device_profiles.clear ();
 
-       if (!devprofiles) {
+       if (devprofiles.empty()) {
                error << "No MCP device info files found using " << spath.to_string() << endmsg;
                return;
        }
 
-       if (devprofiles->empty()) {
-               error << "No MCP device info files found using " << spath.to_string() << endmsg;
-               return;
-       }
-
-       for (vector<string*>::iterator i = devprofiles->begin(); i != devprofiles->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = devprofiles.begin(); i != devprofiles.end(); ++i) {
+               string fullpath = *i;
+               DeviceProfile dp; // has to be initial every loop or info from last added.
 
                XMLTree tree;
 
@@ -129,8 +122,6 @@ DeviceProfile::reload_device_profiles ()
                        device_profiles[dp.name()] = dp;
                }
        }
-
-       delete devprofiles;
 }
 
 int
@@ -144,7 +135,7 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
        }
 
        /* name is mandatory */
+
        if ((child = node.child ("Name")) == 0 || (prop = child->property ("value")) == 0) {
                return -1;
        } else {
@@ -166,7 +157,7 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
 
                                int id = Button::name_to_id (prop->value());
                                if (id < 0) {
-                                       error << string_compose ("Unknow button ID \"%1\"", prop->value()) << endmsg;
+                                       error << string_compose ("Unknown button ID \"%1\"", prop->value()) << endmsg;
                                        continue;
                                }
 
@@ -340,20 +331,20 @@ legalize_for_path (const string& str)
 void
 DeviceProfile::save ()
 {
-       sys::path fullpath = user_devprofile_directory();
+       std::string fullpath = user_devprofile_directory();
 
-       if (g_mkdir_with_parents (fullpath.to_string().c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create user MCP profile folder \"%1\" (%2)"), fullpath.to_string(), strerror (errno)) << endmsg;
+       if (g_mkdir_with_parents (fullpath.c_str(), 0755) < 0) {
+               error << string_compose(_("Session: cannot create user MCP profile folder \"%1\" (%2)"), fullpath, strerror (errno)) << endmsg;
                return;
        }
 
-       fullpath /= legalize_for_path (_name) + ".profile";
-       
+       fullpath = Glib::build_filename (fullpath, legalize_for_path (_name) + ".profile");
+
        XMLTree tree;
        tree.set_root (&get_state());
 
-       if (!tree.write (fullpath.to_string())) {
-               error << string_compose ("MCP profile not saved to %1", fullpath.to_string()) << endmsg;
+       if (!tree.write (fullpath)) {
+               error << string_compose ("MCP profile not saved to %1", fullpath) << endmsg;
        }
 }