Re-enable export file tagging. No idea why this code has dropped out at some stage...
[ardour.git] / libs / ardour / export_handler.cc
index d93ec7779af5941d9a2d7358f6fdb3872609f218..93f43f33a63ac65269566f0bbf1945285e0d95d3 100644 (file)
 
 #include "pbd/convert.h"
 
+#include "ardour/audiofile_tagger.h"
 #include "ardour/export_graph_builder.h"
 #include "ardour/export_timespan.h"
 #include "ardour/export_channel_configuration.h"
 #include "ardour/export_status.h"
 #include "ardour/export_format_specification.h"
 #include "ardour/export_filename.h"
+#include "ardour/session_metadata.h"
 
 #include "i18n.h"
 
@@ -171,6 +173,7 @@ ExportHandler::start_timespan ()
        timespan_bounds = config_map.equal_range (current_timespan);
        graph_builder->reset ();
        graph_builder->set_current_timespan (current_timespan);
+       handle_duplicate_format_extensions();
        for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
                // Filenames can be shared across timespans
                FileSpec & spec = it->second;
@@ -186,6 +189,27 @@ ExportHandler::start_timespan ()
        session.start_audio_export (process_position);
 }
 
+void
+ExportHandler::handle_duplicate_format_extensions()
+{
+       typedef std::map<std::string, int> ExtCountMap;
+
+       ExtCountMap counts;
+       for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
+               counts[it->second.format->extension()]++;
+       }
+
+       bool duplicates_found = false;
+       for (ExtCountMap::iterator it = counts.begin(); it != counts.end(); ++it) {
+               if (it->second > 1) { duplicates_found = true; }
+       }
+
+       // Set this always, as the filenames are shared...
+       for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
+               it->second.filename->include_format_name = duplicates_found;
+       }
+}
+
 int
 ExportHandler::process (framecnt_t frames)
 {
@@ -258,13 +282,18 @@ ExportHandler::finish_timespan ()
        while (config_map.begin() != timespan_bounds.second) {
 
                ExportFormatSpecPtr fmt = config_map.begin()->second.format;
+               std::string filename = config_map.begin()->second.filename->get_path(fmt);
 
                if (fmt->with_cue()) {
-                       export_cd_marker_file (current_timespan, fmt, config_map.begin()->second.filename->get_path(fmt), CDMarkerCUE);
-               } 
+                       export_cd_marker_file (current_timespan, fmt, filename, CDMarkerCUE);
+               }
 
                if (fmt->with_toc()) {
-                       export_cd_marker_file (current_timespan, fmt, config_map.begin()->second.filename->get_path(fmt), CDMarkerTOC);
+                       export_cd_marker_file (current_timespan, fmt, filename, CDMarkerTOC);
+               }
+
+               if (fmt->tag()) {
+                       AudiofileTagger::tag_file(filename, *SessionMetadata::Metadata());
                }
 
                config_map.erase (config_map.begin());