X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fexport_channel.cc;h=8f83c0a7fb9c32524d55fcb319363767e484c9f5;hb=bc3e1a212250a67e53e86c972287a275834a967a;hp=c612b1f6684e6af3488138d3b9bdbb1c4347a1cd;hpb=3f30e8093e1c78bb722196ecb48d9c7cbdd279c3;p=ardour.git diff --git a/libs/ardour/export_channel.cc b/libs/ardour/export_channel.cc index c612b1f668..8f83c0a7fb 100644 --- a/libs/ardour/export_channel.cc +++ b/libs/ardour/export_channel.cc @@ -23,14 +23,28 @@ #include "ardour/audio_track.h" #include "ardour/audioengine.h" #include "ardour/audioregion.h" +#include "ardour/capturing_processor.h" #include "ardour/export_channel.h" #include "ardour/export_failed.h" #include "ardour/session.h" #include "pbd/error.h" +#include "i18n.h" + using namespace ARDOUR; +PortExportChannel::PortExportChannel () + : buffer_size(0) +{ +} + +void PortExportChannel::set_max_buffer_size(framecnt_t frames) +{ + buffer_size = frames; + buffer.reset (new Sample[frames]); +} + bool PortExportChannel::operator< (ExportChannel const & other) const { @@ -42,19 +56,31 @@ PortExportChannel::operator< (ExportChannel const & other) const } void -PortExportChannel::read (Sample * data, framecnt_t frames) const +PortExportChannel::read (Sample const *& data, framecnt_t frames) const { - memset (data, 0, frames * sizeof (float)); + assert(buffer); + assert(frames <= buffer_size); + + if (ports.size() == 1) { + boost::shared_ptr p = ports.begin()->lock (); + data = p->get_audio_buffer(frames).data(); + return; + } + + memset (buffer.get(), 0, frames * sizeof (Sample)); for (PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) { - if (*it != 0) { - Sample* port_buffer = (*it)->get_audio_buffer(frames).data(); + boost::shared_ptr p = it->lock (); + if (p) { + Sample* port_buffer = p->get_audio_buffer(frames).data(); for (uint32_t i = 0; i < frames; ++i) { - data[i] += (float) port_buffer[i]; + buffer[i] += (float) port_buffer[i]; } } } + + data = buffer.get(); } void @@ -62,8 +88,9 @@ PortExportChannel::get_state (XMLNode * node) const { XMLNode * port_node; for (PortSet::const_iterator it = ports.begin(); it != ports.end(); ++it) { - if ((port_node = node->add_child ("Port"))) { - port_node->add_property ("name", (*it)->name()); + boost::shared_ptr p = it->lock (); + if (p && (port_node = node->add_child ("Port"))) { + port_node->add_property ("name", p->name()); } } } @@ -76,7 +103,7 @@ PortExportChannel::set_state (XMLNode * node, Session & session) for (XMLNodeList::iterator it = xml_ports.begin(); it != xml_ports.end(); ++it) { if ((prop = (*it)->property ("name"))) { std::string const & name = prop->value(); - AudioPort * port = dynamic_cast (session.engine().get_port_by_name (name)); + boost::shared_ptr port = boost::dynamic_pointer_cast (session.engine().get_port_by_name (name)); if (port) { ports.insert (port); } else { @@ -93,10 +120,7 @@ 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), - - mixdown_buffer (0), - gain_buffer (0) + position (region_start) { switch (type) { case Raw: @@ -105,9 +129,9 @@ RegionExportChannelFactory::RegionExportChannelFactory (Session * session, Audio 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); + mixdown_buffer.reset (new Sample [frames_per_cycle]); + gain_buffer.reset (new Sample [frames_per_cycle]); + memset (gain_buffer.get(), 1.0, sizeof (Sample) * frames_per_cycle); break; case Processed: @@ -125,8 +149,6 @@ RegionExportChannelFactory::RegionExportChannelFactory (Session * session, Audio RegionExportChannelFactory::~RegionExportChannelFactory () { - delete[] mixdown_buffer; - delete[] gain_buffer; } ExportChannelPtr @@ -137,7 +159,7 @@ RegionExportChannelFactory::create (uint32_t channel) } void -RegionExportChannelFactory::read (uint32_t channel, Sample * data, framecnt_t frames_to_read) +RegionExportChannelFactory::read (uint32_t channel, Sample const *& data, framecnt_t frames_to_read) { assert (channel < n_channels); assert (frames_to_read <= frames_per_cycle); @@ -147,7 +169,7 @@ RegionExportChannelFactory::read (uint32_t channel, Sample * data, framecnt_t fr buffers_up_to_date = true; } - memcpy (data, buffers.get_audio (channel).data(), frames_to_read * sizeof (Sample)); + data = buffers.get_audio (channel).data(); } void @@ -164,8 +186,8 @@ RegionExportChannelFactory::update_buffers (framecnt_t frames) 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); + memset (mixdown_buffer.get(), 0, sizeof (Sample) * frames); + region.read_at (buffers.get_audio (channel).data(), mixdown_buffer.get(), gain_buffer.get(), position, frames, channel); } break; case Processed: @@ -177,3 +199,77 @@ RegionExportChannelFactory::update_buffers (framecnt_t frames) position += frames; } + + +RouteExportChannel::RouteExportChannel(boost::shared_ptr processor, size_t channel, + boost::shared_ptr remover) + : processor (processor) + , channel (channel) + , remover (remover) +{ +} + +RouteExportChannel::~RouteExportChannel() +{ +} + +void +RouteExportChannel::create_from_route(std::list & result, Route & route) +{ + boost::shared_ptr processor = route.add_export_point(); + uint32_t channels = processor->input_streams().n_audio(); + + boost::shared_ptr remover (new ProcessorRemover (route, processor)); + result.clear(); + for (uint32_t i = 0; i < channels; ++i) { + result.push_back (ExportChannelPtr (new RouteExportChannel (processor, i, remover))); + } +} + +void +RouteExportChannel::set_max_buffer_size(framecnt_t frames) +{ + if (processor) { + processor->set_block_size (frames); + } +} + +void +RouteExportChannel::read (Sample const *& data, framecnt_t frames) const +{ + assert(processor); + AudioBuffer const & buffer = processor->get_capture_buffers().get_audio (channel); + assert (frames <= (framecnt_t) buffer.size()); + data = buffer.data(); +} + +void +RouteExportChannel::get_state (XMLNode *) const +{ + // TODO +} + +void +RouteExportChannel::set_state (XMLNode *, Session &) +{ + // TODO +} + +bool +RouteExportChannel::operator< (ExportChannel const & other) const +{ + RouteExportChannel const * rec; + if ((rec = dynamic_cast(&other)) == 0) { + return this < &other; + } + + if (processor.get() == rec->processor.get()) { + return channel < rec->channel; + } + return processor.get() < rec->processor.get(); +} + +RouteExportChannel::ProcessorRemover::~ProcessorRemover() +{ + route.remove_processor (processor); +}