more MTC debugging
[ardour.git] / libs / ardour / export_channel.cc
index e0242a9f527eb1b337fecf7bdde7d6a0b652c911..a09e6e21b6c2a6cfd388b011bc7256d3d2deeb86 100644 (file)
 
 */
 
-#include <ardour/export_channel.h>
-
-#include <ardour/export_failed.h>
-#include <ardour/audioengine.h>
+#include "ardour/audio_buffer.h"
+#include "ardour/audio_port.h"
+#include "ardour/audio_track.h"
+#include "ardour/audioengine.h"
+#include "ardour/export_channel.h"
+#include "ardour/export_failed.h"
+#include "ardour/session.h"
 
 using namespace ARDOUR;
 
@@ -43,7 +46,7 @@ PortExportChannel::read (Sample * data, nframes_t frames) const
        for (PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) {
                if (*it != 0) {
                        Sample* port_buffer = (*it)->get_audio_buffer(frames, 0).data();
-                       
+
                        for (uint32_t i = 0; i < frames; ++i) {
                                data[i] += (float) port_buffer[i];
                        }
@@ -81,11 +84,22 @@ RegionExportChannelFactory::RegionExportChannelFactory (Session * session, Audio
   frames_per_cycle (session->engine().frames_per_cycle ()),
   buffers_up_to_date (false),
   region_start (region.position()),
-  position (region_start)
+  position (region_start),
+
+  mixdown_buffer (0),
+  gain_buffer (0)
 {
        switch (type) {
          case Raw:
                n_channels = region.n_channels();
+               break;
+         case Fades:
+               n_channels = region.n_channels();
+
+               mixdown_buffer = new Sample [frames_per_cycle];
+               gain_buffer = new Sample [frames_per_cycle];
+               memset (gain_buffer, 1.0, sizeof (Sample) * frames_per_cycle);
+
                break;
          case Processed:
                n_channels = track.n_outputs().n_audio();
@@ -93,11 +107,17 @@ RegionExportChannelFactory::RegionExportChannelFactory (Session * session, Audio
          default:
                throw ExportFailed ("Unhandled type in ExportChannelFactory constructor");
        }
-       
-       session->ProcessExport.connect (sigc::hide (sigc::mem_fun (*this, &RegionExportChannelFactory::new_cycle_started)));
-       
-       buffers.set_count (ChanCount (DataType::AUDIO, n_channels));
+
+       session->ProcessExport.connect_same_thread (export_connection, boost::bind (&RegionExportChannelFactory::new_cycle_started, this, _1));
+
        buffers.ensure_buffers (DataType::AUDIO, n_channels, frames_per_cycle);
+       buffers.set_count (ChanCount (DataType::AUDIO, n_channels));
+}
+
+RegionExportChannelFactory::~RegionExportChannelFactory ()
+{
+       delete[] mixdown_buffer;
+       delete[] gain_buffer;
 }
 
 ExportChannelPtr
@@ -112,31 +132,39 @@ RegionExportChannelFactory::read (uint32_t channel, Sample * data, nframes_t fra
 {
        assert (channel < n_channels);
        assert (frames_to_read <= frames_per_cycle);
-       
+
        if (!buffers_up_to_date) {
                update_buffers(frames_to_read);
                buffers_up_to_date = true;
        }
-       
+
        memcpy (data, buffers.get_audio (channel).data(), frames_to_read * sizeof (Sample));
 }
 
 void
 RegionExportChannelFactory::update_buffers (nframes_t frames)
 {
+       assert (frames <= frames_per_cycle);
+
        switch (type) {
          case Raw:
                for (size_t channel = 0; channel < n_channels; ++channel) {
                        region.read (buffers.get_audio (channel).data(), position - region_start, frames, channel);
                }
                break;
+         case Fades:
+               assert (mixdown_buffer && gain_buffer);
+               for (size_t channel = 0; channel < n_channels; ++channel) {
+                       memset (mixdown_buffer, 0, sizeof (Sample) * frames);
+                       region.read_at (buffers.get_audio (channel).data(), mixdown_buffer, gain_buffer, position, frames, channel);
+               }
+               break;
          case Processed:
-               std::cout << "exporting " << frames << " frames from position " << position << std::endl;
                track.export_stuff (buffers, position, frames);
                break;
          default:
                throw ExportFailed ("Unhandled type in ExportChannelFactory::update_buffers");
        }
-       
+
        position += frames;
 }