Desperate hack to align master-bus on export.
authorRobin Gareus <robin@gareus.org>
Tue, 25 Oct 2016 20:33:37 +0000 (22:33 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 25 Oct 2016 20:33:37 +0000 (22:33 +0200)
Another 90% solution which hopefully gives us another year :(
see comments Session::start_audio_export() for explanation.

libs/ardour/ardour/session.h
libs/ardour/export_handler.cc
libs/ardour/session_export.cc

index f37746d6b2027c2a9049aa77792014e7646985fe..7ae2fb4bd825b88246a8d90858ef4548f524d974 100644 (file)
@@ -725,7 +725,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        boost::shared_ptr<ExportHandler> get_export_handler ();
        boost::shared_ptr<ExportStatus> get_export_status ();
 
-       int start_audio_export (framepos_t position, bool realtime = false, bool region_export = false);
+       int start_audio_export (framepos_t position, bool realtime = false, bool region_export = false, bool comensate_master_latency = false);
 
        PBD::Signal1<int, framecnt_t> ProcessExport;
        static PBD::Signal2<void,std::string, std::string> Exported;
index 3bdfdc90901179c4b774eb76f9e409c7743523c2..34333b488b9c13af5772a8ed3993fac9391d67b5 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ardour/audioengine.h"
 #include "ardour/audiofile_tagger.h"
+#include "ardour/audio_port.h"
 #include "ardour/debug.h"
 #include "ardour/export_graph_builder.h"
 #include "ardour/export_timespan.h"
@@ -192,6 +193,7 @@ ExportHandler::start_timespan ()
        handle_duplicate_format_extensions();
        bool realtime = current_timespan->realtime ();
        bool region_export = true;
+       bool incl_master_bus = false;
        for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) {
                // Filenames can be shared across timespans
                FileSpec & spec = it->second;
@@ -204,6 +206,33 @@ ExportHandler::start_timespan ()
                        default:
                                break;
                }
+#if 1 // hack alert -- align master bus, compensate master latency
+
+               /* there's no easier way to get this information here.
+                * Ports are configured in the PortExportChannelSelector GUI,
+                * This ExportHandler has no context of routes.
+                */
+               boost::shared_ptr<Route> master_bus = session.master_out ();
+               if (master_bus) {
+                       const PortSet& ps = master_bus->output ()->ports();
+
+                       const ExportChannelConfiguration::ChannelList& channels = spec.channel_config->get_channels ();
+                       for (ExportChannelConfiguration::ChannelList::const_iterator it = channels.begin(); it != channels.end(); ++it) {
+
+                               boost::shared_ptr <PortExportChannel> pep = boost::dynamic_pointer_cast<PortExportChannel> (*it);
+                               if (!pep) {
+                                       continue;
+                               }
+                               PortExportChannel::PortSet const& ports = pep->get_ports ();
+                               for (PortExportChannel::PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) {
+                                       boost::shared_ptr<AudioPort> ap = (*it).lock();
+                                       if (ps.contains (ap)) {
+                                               incl_master_bus = true;
+                                       }
+                               }
+                       }
+               }
+#endif
                graph_builder->add_config (spec, realtime);
        }
 
@@ -216,7 +245,7 @@ ExportHandler::start_timespan ()
        session.ProcessExport.connect_same_thread (process_connection, boost::bind (&ExportHandler::process, this, _1));
        process_position = current_timespan->get_start();
        // TODO check if it's a RegionExport.. set flag to skip  process_without_events()
-       session.start_audio_export (process_position, realtime, region_export);
+       session.start_audio_export (process_position, realtime, region_export, incl_master_bus);
 }
 
 void
index 23172838d075c7726dcfd8d02f413c5c2927a1db..7276d631ddd4d53f4cccf59b0ed1d6b4f23dbb61 100644 (file)
@@ -104,7 +104,7 @@ Session::pre_export ()
 
 /** Called for each range that is being exported */
 int
-Session::start_audio_export (framepos_t position, bool realtime, bool region_export)
+Session::start_audio_export (framepos_t position, bool realtime, bool region_export, bool comensate_master_latency)
 {
        if (!_exporting) {
                pre_export ();
@@ -130,14 +130,24 @@ Session::start_audio_export (framepos_t position, bool realtime, bool region_exp
        /* "worst_track_latency" is the correct value for stem-exports
         * see to Route::add_export_point(),
         *
-        * for master-bus export, we'd need to add the master's latency.
-        * or actually longest-total-session-latency.
+        * For master-bus export, we also need to add the master's latency.
+        * (or actually longest-total-session-latency - worst-track-latency)
+        * to align the export to 00:00:00:00.
         *
-        * We can't use worst_playback_latency because that includes
-        * includes external latencies and would overcompensate.
+        * We must not use worst_playback_latency because that
+        * includes external (hardware) latencies and would overcompensate
+        * during file-export.
+        *
+        * (this is all still very [w]hacky. Individual Bus and Track outputs
+        * are not aligned but one can select them in the PortExportChannelSelector)
         */
        _export_latency = worst_track_latency ();
 
+       boost::shared_ptr<Route> master = master_out ();
+       if (master && comensate_master_latency) {
+               _export_latency += master->signal_latency ();
+       }
+
        if (region_export) {
                _export_latency = 0;
        }