initial check in of VBAP implementation (not coupled to any existing ardour objects...
[ardour.git] / libs / ardour / export_handler.cc
index 3ce07cf44d422ee47b529cc2a9cbaca22f6e96c2..9ffb7c17789915170f9b9ae2613b63e260402e2a 100644 (file)
@@ -35,6 +35,8 @@
 #include "ardour/export_filename.h"
 #include "ardour/export_failed.h"
 
+#include "i18n.h"
+
 using namespace std;
 using namespace PBD;
 
@@ -104,7 +106,9 @@ ExportHandler::ExportHandler (Session & session)
   , graph_builder (new ExportGraphBuilder (session))
   , export_status (session.get_export_status ())
   , realtime (false)
-
+  , normalizing (false)
+  , cue_tracknum (0)
+  , cue_indexnum (0)
 {
 }
 
@@ -114,12 +118,12 @@ ExportHandler::~ExportHandler ()
 }
 
 bool
-ExportHandler::add_export_config (TimespanPtr timespan, ChannelConfigPtr channel_config, FormatPtr format, FilenamePtr filename)
+ExportHandler::add_export_config (TimespanPtr timespan, ChannelConfigPtr channel_config, FormatPtr format, FilenamePtr filename, boost::shared_ptr<AudioGrapher::BroadcastInfo> broadcast_info)
 {
-       FileSpec spec (channel_config, format, filename);
+       FileSpec spec (channel_config, format, filename, broadcast_info);
        ConfigPair pair (timespan, spec);
        config_map.insert (pair);
-
+       
        return true;
 }
 
@@ -138,8 +142,6 @@ ExportHandler::do_export (bool rt)
        /* Start export */
 
        realtime = rt;
-
-       session.ExportReadFinished.connect_same_thread (export_read_finished_connection, boost::bind (&ExportHandler::finish_timespan, this));
        start_timespan ();
 }
 
@@ -149,6 +151,7 @@ ExportHandler::start_timespan ()
        export_status->timespan++;
 
        if (config_map.empty()) {
+               // freewheeling has to be stopped from outside the process cycle
                export_status->running = false;
                return;
        }
@@ -160,30 +163,47 @@ ExportHandler::start_timespan ()
        timespan_bounds = config_map.equal_range (current_timespan);
        graph_builder->reset ();
        for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
-               graph_builder->add_config (it->second);
+               // Filenames can be shared across timespans
+               FileSpec & spec = it->second;
+               spec.filename->set_timespan (it->first);
+               graph_builder->add_config (spec);
        }
 
        /* start export */
 
-       session.ProcessExport.connect_same_thread (process_connection, boost::bind (&ExportHandler::process_timespan, this, _1));
+       normalizing = false;
+       session.ProcessExport.connect_same_thread (process_connection, boost::bind (&ExportHandler::process, this, _1));
        process_position = current_timespan->get_start();
        session.start_audio_export (process_position, realtime);
 }
 
+int
+ExportHandler::process (nframes_t frames)
+{
+       if (!export_status->running) {
+               return 0;
+       } else if (normalizing) {
+               return process_normalize ();
+       } else {
+               return process_timespan (frames);
+       }
+}
+
 int
 ExportHandler::process_timespan (nframes_t frames)
 {
        /* update position */
 
        nframes_t frames_to_read = 0;
-       sframes_t const start = current_timespan->get_start();
-       sframes_t const end = current_timespan->get_end();
+       framepos_t const start = current_timespan->get_start();
+       framepos_t const end = current_timespan->get_end();
        
        bool const last_cycle = (process_position + frames >= end);
 
        if (last_cycle) {
                frames_to_read = end - process_position;
                export_status->stop = true;
+               normalizing = true;
        } else {
                frames_to_read = frames;
        }
@@ -196,11 +216,19 @@ ExportHandler::process_timespan (nframes_t frames)
        return graph_builder->process (frames_to_read, last_cycle);
 }
 
+int
+ExportHandler::process_normalize ()
+{
+       if (graph_builder->process_normalize ()) {
+               finish_timespan ();
+       }
+       
+       return 0;
+}
+
 void
 ExportHandler::finish_timespan ()
 {
-       process_connection.disconnect ();
-       
        while (config_map.begin() != timespan_bounds.second) {
                config_map.erase (config_map.begin());
        }
@@ -264,7 +292,7 @@ ExportHandler::export_cd_marker_file (TimespanPtr timespan, FormatPtr file_forma
        Locations::LocationList temp;
 
        for (i = locations.begin(); i != locations.end(); ++i) {
-               if ((*i)->start() >= timespan->get_start() && (*i)->end() <= timespan->get_end() && (*i)->is_cd_marker() && !(*i)->is_end()) {
+               if ((*i)->start() >= timespan->get_start() && (*i)->end() <= timespan->get_end() && (*i)->is_cd_marker() && !(*i)->is_session_range()) {
                        temp.push_back (*i);
                }
        }
@@ -280,7 +308,7 @@ ExportHandler::export_cd_marker_file (TimespanPtr timespan, FormatPtr file_forma
 
        /* Start actual marker stuff */
 
-       sframes_t last_end_time = timespan->get_start(), last_start_time = timespan->get_start();
+       framepos_t last_end_time = timespan->get_start(), last_start_time = timespan->get_start();
        status.track_position = last_start_time - timespan->get_start();
 
        for (i = temp.begin(); i != temp.end(); ++i) {
@@ -336,7 +364,7 @@ ExportHandler::export_cd_marker_file (TimespanPtr timespan, FormatPtr file_forma
 void
 ExportHandler::write_cue_header (CDMarkerStatus & status)
 {
-       Glib::ustring title = status.timespan->name().compare ("Session") ? status.timespan->name() : (Glib::ustring) session.name();
+       string title = status.timespan->name().compare ("Session") ? status.timespan->name() : (string) session.name();
 
        status.out << "REM Cue file generated by Ardour" << endl;
        status.out << "TITLE \"" << title << "\"" << endl;
@@ -360,7 +388,7 @@ ExportHandler::write_cue_header (CDMarkerStatus & status)
        status.out << "FILE \"" << Glib::path_get_basename(status.filename) << "\" ";
        if (!status.format->format_name().compare ("WAV")) {
                status.out  << "WAVE";
-       } else if (status.format->format_name() == ExportFormatBase::F_RAW &&
+       } else if (status.format->format_id() == ExportFormatBase::F_RAW &&
                   status.format->sample_format() == ExportFormatBase::SF_16 &&
                   status.format->sample_rate() == ExportFormatBase::SR_44_1) {
                // Format is RAW 16bit 44.1kHz
@@ -379,7 +407,7 @@ ExportHandler::write_cue_header (CDMarkerStatus & status)
 void
 ExportHandler::write_toc_header (CDMarkerStatus & status)
 {
-       Glib::ustring title = status.timespan->name().compare ("Session") ? status.timespan->name() : (Glib::ustring) session.name();
+       string title = status.timespan->name().compare ("Session") ? status.timespan->name() : (string) session.name();
 
        status.out << "CD_DA" << endl;
        status.out << "CD_TEXT {" << endl << "  LANGUAGE_MAP {" << endl << "    0 : EN" << endl << "  }" << endl;
@@ -507,9 +535,9 @@ ExportHandler::write_index_info_toc (CDMarkerStatus & status)
 }
 
 void
-ExportHandler::frames_to_cd_frames_string (char* buf, sframes_t when)
+ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when)
 {
-       sframes_t remainder;
+       framecnt_t remainder;
        nframes_t fr = session.nominal_frame_rate();
        int mins, secs, frames;