Merge branch 'cairocanvas' into windows+cc
[ardour.git] / libs / ardour / export_profile_manager.cc
index 6c4f829bb89fca383e02a54fc106cd93fac7a9ec..7ff4282c74bcdea5ee64ff28ce57313689cda6bc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <cassert>
 #include <stdexcept>
+#include <cerrno>
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -55,17 +56,34 @@ using namespace PBD;
 namespace ARDOUR
 {
 
-ExportProfileManager::ExportProfileManager (Session & s, std::string xml_node_name)
-  : xml_node_name (xml_node_name)
+ExportProfileManager::ExportProfileManager (Session & s, ExportType type)
+  : type(type)
   , handler (s.get_export_handler())
   , session (s)
 
-  , session_range (new Location (s))
   , ranges (new LocationList ())
   , single_range_mode (false)
 
   , format_list (new FormatList ())
 {
+       switch(type) {
+       case RegularExport:
+               xml_node_name = X_("ExportProfile");
+               break;
+       case RangeExport:
+               xml_node_name = X_("RangeExportProfile");
+               break;
+       case SelectionExport:
+               xml_node_name = X_("SelectionExportProfile");
+               break;
+       case RegionExport:
+               xml_node_name = X_("RegionExportProfile");
+               break;
+       case StemExport:
+               xml_node_name = X_("StemExportProfile");
+               break;
+       }
+
        /* Initialize path variables */
 
        export_config_dir = Glib::build_filename (user_config_directory(), export_dir_name);
@@ -138,7 +156,8 @@ ExportProfileManager::prepare_for_export ()
                        }
 
                        // ...and each channel config
-                       filename->include_channel_config = (channel_configs.size() > 1);
+                       filename->include_channel_config = (type == StemExport) ||
+                                                          (channel_configs.size() > 1);
                        for(ChannelConfigStateList::iterator cc_it = channel_configs.begin(); cc_it != channel_configs.end(); ++cc_it) {
                                handler->add_export_config (*ts_it, (*cc_it)->config, (*format_it)->format, filename, b);
                        }
@@ -365,13 +384,16 @@ ExportProfileManager::init_timespans (XMLNodeList nodes)
        }
 
        if (timespans.empty()) {
-               TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges));
+               TimespanStatePtr state (new TimespanState (selection_range, ranges));
                timespans.push_back (state);
 
                // Add session as default selection
+               Location * session_range = session.locations()->session_range_location();
+               if (!session_range) { return false; }
+
                ExportTimespanPtr timespan = handler->add_timespan();
                timespan->set_name (session_range->name());
-               timespan->set_range_id ("session");
+               timespan->set_range_id (session_range->id().to_s());
                timespan->set_range (session_range->start(), session_range->end());
                state->timespans->push_back (timespan);
                return false;
@@ -383,7 +405,7 @@ ExportProfileManager::init_timespans (XMLNodeList nodes)
 ExportProfileManager::TimespanStatePtr
 ExportProfileManager::deserialize_timespan (XMLNode & root)
 {
-       TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges));
+       TimespanStatePtr state (new TimespanState (selection_range, ranges));
        XMLProperty const * prop;
 
        XMLNodeList spans = root.children ("Range");
@@ -393,23 +415,32 @@ ExportProfileManager::deserialize_timespan (XMLNode & root)
                if (!prop) { continue; }
                string id = prop->value();
 
+               Location * location = 0;
                for (LocationList::iterator it = ranges->begin(); it != ranges->end(); ++it) {
-                       if ((!id.compare ("session") && *it == session_range.get()) ||
-                           (!id.compare ("selection") && *it == selection_range.get()) ||
-                           (!id.compare ((*it)->id().to_s()))) {
-                               ExportTimespanPtr timespan = handler->add_timespan();
-                               timespan->set_name ((*it)->name());
-                               timespan->set_range_id (id);
-                               timespan->set_range ((*it)->start(), (*it)->end());
-                               state->timespans->push_back (timespan);
+                       if ((id == "selection" && *it == selection_range.get()) ||
+                           (id == (*it)->id().to_s())) {
+                               location = *it;
+                               break;
                        }
                }
+
+               if (!location) { continue; }
+
+               ExportTimespanPtr timespan = handler->add_timespan();
+               timespan->set_name (location->name());
+               timespan->set_range_id (location->id().to_s());
+               timespan->set_range (location->start(), location->end());
+               state->timespans->push_back (timespan);
        }
 
        if ((prop = root.property ("format"))) {
                state->time_format = (TimeFormat) string_2_enum (prop->value(), TimeFormat);
        }
 
+       if (state->timespans->empty()) {
+               return TimespanStatePtr();
+       }
+
        return state;
 }
 
@@ -420,7 +451,6 @@ ExportProfileManager::serialize_timespan (TimespanStatePtr state)
        XMLNode * span;
 
        update_ranges ();
-
        for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
                if ((span = root.add_child ("Range"))) {
                        span->add_property ("id", (*it)->range_id());
@@ -443,9 +473,10 @@ ExportProfileManager::update_ranges () {
 
        /* Session */
 
-       session_range->set_name (_("Session"));
-       session_range->set (session.current_start_frame(), session.current_end_frame());
-       ranges->push_back (session_range.get());
+       Location * session_range = session.locations()->session_range_location();
+       if (session_range) {
+               ranges->push_back (session_range);
+       }
 
        /* Selection */
 
@@ -481,6 +512,8 @@ ExportProfileManager::init_channel_configs (XMLNodeList nodes)
                channel_configs.push_back (config);
 
                // Add master outs as default
+               if (!session.master_out()) { return false; }
+
                IO* master_out = session.master_out()->output().get();
                if (!master_out) { return false; }
 
@@ -613,7 +646,7 @@ ExportProfileManager::get_new_format (ExportFormatSpecPtr original)
                format.reset (new ExportFormatSpecification (*original));
        } else {
                format = handler->add_format();
-               format->set_name ("empty format");
+               format->set_name (_("empty format"));
        }
 
        std::string path = save_format_to_disk (format);
@@ -652,7 +685,7 @@ ExportProfileManager::FormatStatePtr
 ExportProfileManager::deserialize_format (XMLNode & root)
 {
        XMLProperty * prop;
-       UUID id;
+       PBD::UUID id;
 
        if ((prop = root.property ("id"))) {
                id = prop->value();