* radically cleaned up / refactored midi_clock_slave.cc
[ardour.git] / libs / ardour / export_profile_manager.cc
index 1d1c66665f6aa5581884918c00a7ee4dceee298b..2576620ec2eeb4bf261ef07d6ad426bd27a2cdab 100644 (file)
@@ -60,19 +60,12 @@ ExportProfileManager::ExportProfileManager (Session & s) :
 
        /* Initialize path variables */
 
-       sys::path path;
-
        export_config_dir = user_config_directory();
        export_config_dir /= "export";
        search_path += export_config_dir;
        
-       path = ardour_search_path().to_string();
-       path /= "export";
-       search_path += path;
-       
-       path = system_config_search_path().to_string();
-       path /= "export";
-       search_path += path;
+       search_path += ardour_search_path().add_subdirectory_to_paths("export");
+       search_path += system_config_search_path().add_subdirectory_to_paths("export");;
        
        /* create export config directory if necessary */
 
@@ -168,8 +161,9 @@ ExportProfileManager::load_presets ()
 ExportProfileManager::PresetPtr
 ExportProfileManager::save_preset (string const & name)
 {
+       string filename = export_config_dir.to_string() + "/" + name + export_preset_suffix;
+
        if (!current_preset) {
-               string filename = export_config_dir.to_string() + "/" + name + export_preset_suffix;
                current_preset.reset (new ExportPreset (filename, session));
                preset_list.push_back (current_preset);
        }
@@ -184,7 +178,7 @@ ExportProfileManager::save_preset (string const & name)
        current_preset->set_global_state (*global_preset);
        current_preset->set_local_state (*local_preset);
        
-       current_preset->save();
+       current_preset->save (filename);
        
        return current_preset;
 }
@@ -215,12 +209,13 @@ void
 ExportProfileManager::load_preset_from_disk (PBD::sys::path const & path)
 {
        PresetPtr preset (new ExportPreset (path.to_string(), session));
-       preset_list.push_back (preset);
        
-       /* Handle id to filename mapping */
+       /* Handle id to filename mapping and don't add duplicates to list */
        
        FilePair pair (preset->id(), path);
-       preset_file_map.insert (pair);
+       if (preset_file_map.insert (pair).second) {
+               preset_list.push_back (preset);
+       }
 }
 
 bool
@@ -480,19 +475,31 @@ ExportProfileManager::save_format_to_disk (FormatPtr format)
        /* Check if format is on disk already */
        FileMap::iterator it;
        if ((it = format_file_map.find (format->id())) != format_file_map.end()) {
-               /* Update data */
-               {
-                       XMLTree tree (it->second.to_string());
+               
+               /* Check if config is not in user config dir */
+               if (it->second.branch_path().to_string().compare (export_config_dir.to_string())) {
+               
+                       /* Write new file */
+               
+                       XMLTree tree (new_path.to_string());
                        tree.set_root (&format->get_state());
                        tree.write();
-               }
                
-               /* Rename if necessary */
+               } else {
+               
+                       /* Update file and rename if necessary */
                
-               if (new_name.compare (it->second.leaf())) {
-                       sys::rename (it->second, new_path);
+                       XMLTree tree (it->second.to_string());
+                       tree.set_root (&format->get_state());
+                       tree.write();
+                       
+                       if (new_name.compare (it->second.leaf())) {
+                               sys::rename (it->second, new_path);
+                       }
                }
                
+               it->second = new_path;
+               
        } else {
                /* Write new file */
                
@@ -612,12 +619,13 @@ ExportProfileManager::load_format_from_disk (PBD::sys::path const & path)
 {
        XMLTree const tree (path.to_string());
        FormatPtr format = handler->add_format (*tree.root());
-       format_list->push_back (format);
        
-       /* Handle id to filename mapping */
+       /* Handle id to filename mapping and don't add duplicates to list */
        
        FilePair pair (format->id(), path);
-       format_file_map.insert (pair);
+       if (format_file_map.insert (pair).second) {
+               format_list->push_back (format);
+       }
        
        FormatListChanged ();
 }
@@ -714,6 +722,8 @@ ExportProfileManager::check_config (boost::shared_ptr<Warnings> warnings,
        /* Check format and maximum channel count */
        if (!format || !format->type()) {
                warnings->errors.push_back (_("No format selected!"));
+       } else if (!channel_config->get_n_chans()) {
+               warnings->errors.push_back (_("All channels are empty!"));
        } else if (!ExportFileFactory::check (format, channel_config->get_n_chans())) {
                warnings->errors.push_back (_("One or more of the selected formats is not compatible with this system!"));
        } else if (format->channel_limit() < channel_config->get_n_chans()) {