Remove debug code.
[ardour.git] / libs / ardour / export_profile_manager.cc
index 4d2b7795a412f93a713605ab528b6b3c1ae1db4d..54779cfa326817e2558dada332bf59fb8a1374a1 100644 (file)
@@ -90,8 +90,6 @@ ExportProfileManager::ExportProfileManager (Session & s, std::string xml_node_na
 
 ExportProfileManager::~ExportProfileManager ()
 {
-       if (single_range_mode) { return; }
-
        XMLNode * instant_xml (new XMLNode (xml_node_name));
        serialize_profile (*instant_xml);
        session.add_instant_xml (*instant_xml, false);
@@ -124,7 +122,7 @@ ExportProfileManager::prepare_for_export ()
                     format_it != formats.end() && filename_it != filenames.end();
                     ++format_it, ++filename_it) {
 
-                       FilenamePtr filename = (*filename_it)->filename;
+                       ExportFilenamePtr filename = (*filename_it)->filename;
 //                     filename->include_timespan = (ts_list->size() > 1); Disabled for now...
 
                        boost::shared_ptr<BroadcastInfo> b;
@@ -143,7 +141,7 @@ ExportProfileManager::prepare_for_export ()
 }
 
 bool
-ExportProfileManager::load_preset (PresetPtr preset)
+ExportProfileManager::load_preset (ExportPresetPtr preset)
 {
        bool ok = true;
 
@@ -181,7 +179,7 @@ ExportProfileManager::preset_filename (std::string const & preset_name)
        return export_config_dir.to_string() + "/" + safe_name + export_preset_suffix;
 }
 
-ExportProfileManager::PresetPtr
+ExportPresetPtr
 ExportProfileManager::new_preset (string const & name)
 {
        // Generate new ID and do regular save
@@ -191,7 +189,7 @@ ExportProfileManager::new_preset (string const & name)
        return save_preset (name);
 }
 
-ExportProfileManager::PresetPtr
+ExportPresetPtr
 ExportProfileManager::save_preset (string const & name)
 {
        string filename = preset_filename (name);
@@ -241,7 +239,7 @@ ExportProfileManager::remove_preset ()
 void
 ExportProfileManager::load_preset_from_disk (PBD::sys::path const & path)
 {
-       PresetPtr preset (new ExportPreset (path.to_string(), session));
+       ExportPresetPtr preset (new ExportPreset (path.to_string(), session));
 
        /* Handle id to filename mapping and don't add duplicates to list */
 
@@ -361,9 +359,9 @@ ExportProfileManager::init_timespans (XMLNodeList nodes)
        if (timespans.empty()) {
                TimespanStatePtr state (new TimespanState (session_range, selection_range, ranges));
                timespans.push_back (state);
-               
+
                // Add session as default selection
-               TimespanPtr timespan = handler->add_timespan();
+               ExportTimespanPtr timespan = handler->add_timespan();
                timespan->set_name (session_range->name());
                timespan->set_range_id ("session");
                timespan->set_range (session_range->start(), session_range->end());
@@ -391,7 +389,7 @@ ExportProfileManager::deserialize_timespan (XMLNode & root)
                        if ((!id.compare ("session") && *it == session_range.get()) ||
                            (!id.compare ("selection") && *it == selection_range.get()) ||
                            (!id.compare ((*it)->id().to_s()))) {
-                               TimespanPtr timespan = handler->add_timespan();
+                               ExportTimespanPtr timespan = handler->add_timespan();
                                timespan->set_name ((*it)->name());
                                timespan->set_range_id (id);
                                timespan->set_range ((*it)->start(), (*it)->end());
@@ -473,15 +471,15 @@ ExportProfileManager::init_channel_configs (XMLNodeList nodes)
        if (nodes.empty()) {
                ChannelConfigStatePtr config (new ChannelConfigState (handler->add_channel_config()));
                channel_configs.push_back (config);
-               
+
                // Add master outs as default
                IO* master_out = session.master_out()->output().get();
                if (!master_out) { return false; }
-               
+
                for (uint32_t n = 0; n < master_out->n_ports().n_audio(); ++n) {
                        PortExportChannel * channel = new PortExportChannel ();
                        channel->add_port (master_out->audio (n));
-                       
+
                        ExportChannelPtr chan_ptr (channel);
                        config->config->register_channel (chan_ptr);
                }
@@ -520,7 +518,7 @@ ExportProfileManager::remove_format_state (FormatStatePtr state)
 }
 
 sys::path
-ExportProfileManager::save_format_to_disk (FormatPtr format)
+ExportProfileManager::save_format_to_disk (ExportFormatSpecPtr format)
 {
        // TODO filename character stripping
 
@@ -577,7 +575,7 @@ ExportProfileManager::save_format_to_disk (FormatPtr format)
 }
 
 void
-ExportProfileManager::remove_format_profile (FormatPtr format)
+ExportProfileManager::remove_format_profile (ExportFormatSpecPtr format)
 {
        for (FormatList::iterator it = format_list->begin(); it != format_list->end(); ++it) {
                if (*it == format) {
@@ -595,10 +593,10 @@ ExportProfileManager::remove_format_profile (FormatPtr format)
        FormatListChanged ();
 }
 
-ExportProfileManager::FormatPtr
-ExportProfileManager::get_new_format (FormatPtr original)
+ExportFormatSpecPtr
+ExportProfileManager::get_new_format (ExportFormatSpecPtr original)
 {
-       FormatPtr format;
+       ExportFormatSpecPtr format;
        if (original) {
                format.reset (new ExportFormatSpecification (*original));
        } else {
@@ -630,7 +628,7 @@ ExportProfileManager::init_formats (XMLNodeList nodes)
        }
 
        if (formats.empty ()) {
-               FormatStatePtr format (new FormatState (format_list, FormatPtr ()));
+               FormatStatePtr format (new FormatState (format_list, ExportFormatSpecPtr ()));
                formats.push_back (format);
                return false;
        }
@@ -682,7 +680,7 @@ void
 ExportProfileManager::load_format_from_disk (PBD::sys::path const & path)
 {
        XMLTree const tree (path.to_string());
-       FormatPtr format = handler->add_format (*tree.root());
+       ExportFormatSpecPtr format = handler->add_format (*tree.root());
 
        /* Handle id to filename mapping and don't add duplicates to list */
 
@@ -713,13 +711,28 @@ ExportProfileManager::remove_filename_state (FilenameStatePtr state)
        }
 }
 
+std::string
+ExportProfileManager::get_sample_filename_for_format (ExportFilenamePtr filename, ExportFormatSpecPtr format)
+{
+       assert (format);
+       
+       if (channel_configs.empty()) { return ""; }
+
+       std::list<string> filenames;
+       build_filenames (filenames, filename, timespans.front()->timespans,
+                        channel_configs.front()->config, format);
+
+       if (filenames.empty()) { return ""; }
+       return filenames.front();
+}
+
 bool
 ExportProfileManager::init_filenames (XMLNodeList nodes)
 {
        filenames.clear ();
 
        for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
-               FilenamePtr filename = handler->add_filename();
+               ExportFilenamePtr filename = handler->add_filename();
                filename->set_state (**it);
                filenames.push_back (FilenameStatePtr (new FilenameState (filename)));
        }
@@ -738,15 +751,21 @@ ExportProfileManager::get_warnings ()
 {
        boost::shared_ptr<Warnings> warnings (new Warnings ());
 
-       assert (!channel_configs.empty ());
-
-       ChannelConfigStatePtr channel_config_state = channel_configs.front();
+       ChannelConfigStatePtr channel_config_state;
+       if (!channel_configs.empty ()) {
+               channel_config_state = channel_configs.front();
+       }
+       
        TimespanStatePtr timespan_state = timespans.front();
 
        /*** Check "global" config ***/
 
        TimespanListPtr timespans = timespan_state->timespans;
-       ChannelConfigPtr channel_config = channel_config_state->config;
+
+       ExportChannelConfigPtr channel_config;
+       if (channel_config_state) {
+               channel_config = channel_config_state->config;
+       }
 
        /* Check Timespans are not empty */
 
@@ -754,22 +773,27 @@ ExportProfileManager::get_warnings ()
                warnings->errors.push_back (_("No timespan has been selected!"));
        }
 
-       /* Check channel config ports */
-
-       if (!channel_config->all_channels_have_ports ()) {
-               warnings->warnings.push_back (_("Some channels are empty"));
+       if (channel_config_state == 0) {
+               warnings->errors.push_back (_("No channels have been selected!"));
+       } else {
+               /* Check channel config ports */
+               if (!channel_config->all_channels_have_ports ()) {
+                       warnings->warnings.push_back (_("Some channels are empty"));
+               }
        }
 
        /*** Check files ***/
 
-       FormatStateList::const_iterator format_it;
-       FilenameStateList::const_iterator filename_it;
-       for (format_it = formats.begin(), filename_it = filenames.begin();
-            format_it != formats.end() && filename_it != filenames.end();
-            ++format_it, ++filename_it) {
+       if (channel_config_state) {
+               FormatStateList::const_iterator format_it;
+               FilenameStateList::const_iterator filename_it;
+               for (format_it = formats.begin(), filename_it = filenames.begin();
+                    format_it != formats.end() && filename_it != filenames.end();
+                    ++format_it, ++filename_it) {
                        check_config (warnings, timespan_state, channel_config_state, *format_it, *filename_it);
+               }
        }
-
+       
        return warnings;
 }
 
@@ -781,9 +805,9 @@ ExportProfileManager::check_config (boost::shared_ptr<Warnings> warnings,
                                    FilenameStatePtr filename_state)
 {
        TimespanListPtr timespans = timespan_state->timespans;
-       ChannelConfigPtr channel_config = channel_config_state->config;
-       FormatPtr format = format_state->format;
-       FilenamePtr filename = filename_state->filename;
+       ExportChannelConfigPtr channel_config = channel_config_state->config;
+       ExportFormatSpecPtr format = format_state->format;
+       ExportFilenamePtr filename = filename_state->filename;
 
        /* Check format and maximum channel count */
        if (!format || !format->type()) {
@@ -806,34 +830,35 @@ ExportProfileManager::check_config (boost::shared_ptr<Warnings> warnings,
 
 //     filename->include_timespan = (timespans->size() > 1); Disabled for now...
 
-       for (std::list<TimespanPtr>::iterator timespan_it = timespans->begin(); timespan_it != timespans->end(); ++timespan_it) {
-               filename->set_timespan (*timespan_it);
+       std::list<string> paths;
+       build_filenames(paths, filename, timespans, channel_config, format);
 
-               if (channel_config->get_split()) {
-                       filename->include_channel = true;
+       for (std::list<string>::const_iterator path_it = paths.begin(); path_it != paths.end(); ++path_it) {
 
-                       for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) {
-                               filename->set_channel (chan);
+               string path = *path_it;
 
-                               string path = filename->get_path (format);
+               if (sys::exists (sys::path (path))) {
+                       warnings->conflicting_filenames.push_back (path);
+               }
 
-                               if (sys::exists (sys::path (path))) {
-                                       warnings->conflicting_filenames.push_back (path);
-                               }
+               if (format->with_toc()) {
+                       string marker_file = handler->get_cd_marker_filename(path, CDMarkerTOC);
+                       if (sys::exists (sys::path (marker_file))) {
+                               warnings->conflicting_filenames.push_back (marker_file);
                        }
+               }
 
-               } else {
-                       string path = filename->get_path (format);
-
-                       if (sys::exists (sys::path (path))) {
-                               warnings->conflicting_filenames.push_back (path);
+               if (format->with_cue()) {
+                       string marker_file = handler->get_cd_marker_filename(path, CDMarkerCUE);
+                       if (sys::exists (sys::path (marker_file))) {
+                               warnings->conflicting_filenames.push_back (marker_file);
                        }
                }
        }
 }
 
 bool
-ExportProfileManager::check_format (FormatPtr format, uint32_t channels)
+ExportProfileManager::check_format (ExportFormatSpecPtr format, uint32_t channels)
 {
        switch (format->type()) {
          case ExportFormatBase::T_Sndfile:
@@ -845,7 +870,7 @@ ExportProfileManager::check_format (FormatPtr format, uint32_t channels)
 }
 
 bool
-ExportProfileManager::check_sndfile_format (FormatPtr format, unsigned int channels)
+ExportProfileManager::check_sndfile_format (ExportFormatSpecPtr format, unsigned int channels)
 {
        SF_INFO sf_info;
        sf_info.channels = channels;
@@ -855,4 +880,28 @@ ExportProfileManager::check_sndfile_format (FormatPtr format, unsigned int chann
        return (sf_format_check (&sf_info) == SF_TRUE ? true : false);
 }
 
+void
+ExportProfileManager::build_filenames(std::list<std::string> & result, ExportFilenamePtr filename,
+                                      TimespanListPtr timespans, ExportChannelConfigPtr channel_config,
+                                      ExportFormatSpecPtr format)
+{
+       for (std::list<ExportTimespanPtr>::iterator timespan_it = timespans->begin();
+            timespan_it != timespans->end(); ++timespan_it) {
+               filename->set_timespan (*timespan_it);
+
+               if (channel_config->get_split()) {
+                       filename->include_channel = true;
+
+                       for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) {
+                               filename->set_channel (chan);
+                               result.push_back(filename->get_path (format));
+                       }
+
+               } else {
+                       filename->include_channel = false;
+                       result.push_back(filename->get_path (format));
+               }
+       }
+}
+
 }; // namespace ARDOUR