X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fexport_channel_configuration.cc;h=4fe8c09cb6a1500f3178b501b8fcbf45aa91bccd;hb=a75e811edb7aa1da6359f5e2a104e582e2848e47;hp=cd29a4e5787e7cd7c2451b982d93e6d6a3c3ae20;hpb=f2b007195cd75b195e38a4cd7757debac73e7792;p=ardour.git diff --git a/libs/ardour/export_channel_configuration.cc b/libs/ardour/export_channel_configuration.cc index cd29a4e578..4fe8c09cb6 100644 --- a/libs/ardour/export_channel_configuration.cc +++ b/libs/ardour/export_channel_configuration.cc @@ -18,69 +18,86 @@ */ -#include +#include "ardour/export_channel_configuration.h" -#include -#include -#include -#include +#include "ardour/export_handler.h" +#include "ardour/export_filename.h" +#include "ardour/export_processor.h" +#include "ardour/export_timespan.h" -#include -#include -#include -#include +#include "ardour/audio_port.h" +#include "ardour/export_failed.h" +#include "ardour/midi_port.h" +#include "ardour/session.h" +#include "ardour/audioengine.h" -namespace ARDOUR -{ +#include "pbd/convert.h" +#include "pbd/pthread_utils.h" -/* ExportChannel */ +using namespace PBD; -ExportChannel::ExportChannel () +namespace ARDOUR { -} +/* ExportChannelConfiguration */ -ExportChannel::~ExportChannel () +ExportChannelConfiguration::ExportChannelConfiguration (Session & session) : + session (session), + writer_thread (*this), + status (session.get_export_status ()), + files_written (false), + split (false) { } -void -ExportChannel::read_ports (float * data, nframes_t frames) const -{ - memset (data, 0, frames * sizeof (float)); - for (iterator it = begin(); it != end(); ++it) { - if (*it != 0) { - Sample* port_buffer = (*it)->get_audio_buffer().data(); - - for (uint32_t i = 0; i < frames; ++i) { - data[i] += (float) port_buffer[i]; - } - } +XMLNode & +ExportChannelConfiguration::get_state () +{ + XMLNode * root = new XMLNode ("ExportChannelConfiguration"); + XMLNode * channel; + + root->add_property ("split", get_split() ? "true" : "false"); + root->add_property ("channels", to_string (get_n_chans(), std::dec)); + + uint32_t i = 1; + for (ExportChannelConfiguration::ChannelList::const_iterator c_it = channels.begin(); c_it != channels.end(); ++c_it) { + channel = root->add_child ("Channel"); + if (!channel) { continue; } + + channel->add_property ("number", to_string (i, std::dec)); + (*c_it)->get_state (channel); + + ++i; } + + return *root; } -/* ExportChannelConfiguration */ - -ExportChannelConfiguration::ExportChannelConfiguration (ExportStatus & status) : - writer_thread (*this), - status (status), - files_written (false), - split (false) +int +ExportChannelConfiguration::set_state (const XMLNode & root) { + XMLProperty const * prop; + + if ((prop = root.property ("split"))) { + set_split (!prop->value().compare ("true")); + } -} - -ExportChannelConfiguration::~ExportChannelConfiguration () -{ + XMLNodeList channels = root.children ("Channel"); + for (XMLNodeList::iterator it = channels.begin(); it != channels.end(); ++it) { + ExportChannelPtr channel (new PortExportChannel ()); + channel->set_state (*it, session); + register_channel (channel); + } + return 0; } bool -ExportChannelConfiguration::all_channels_have_ports () +ExportChannelConfiguration::all_channels_have_ports () const { - for (ChannelList::iterator it = channels.begin(); it != channels.end(); ++it) { + for (ChannelList::const_iterator it = channels.begin(); it != channels.end(); ++it) { if ((*it)->empty ()) { return false; } } @@ -97,7 +114,7 @@ ExportChannelConfiguration::write_files (boost::shared_ptr new_ files_written = true; if (!timespan) { - throw ExportFailed (_("Export failed due to a programming error"), _("No timespan registered to channel configuration when requesting files to be written")); + throw ExportFailed (X_("Programming error: No timespan registered to channel configuration when requesting files to be written")); } /* Take a local copy of the processor to be used in the thread that is created below */ @@ -129,14 +146,14 @@ ExportChannelConfiguration::write_file () uint32_t channel; do { - if (status.aborted()) { break; } + if (status->aborted()) { break; } channel = 0; for (ChannelList::iterator it = channels.begin(); it != channels.end(); ++it) { /* Get channel data */ - frames_read = timespan->get_data (channel_buffer, frames, **it); + frames_read = timespan->get_data (channel_buffer, frames, *it); /* Interleave into file buffer */ @@ -148,7 +165,7 @@ ExportChannelConfiguration::write_file () } progress += frames_read; - status.progress = (float) progress / timespan_length; + status->progress = (float) progress / timespan_length; } while (processor->process (file_buffer, frames_read) > 0); @@ -159,20 +176,23 @@ ExportChannelConfiguration::write_file () void * ExportChannelConfiguration::_write_files (void *arg) { - - PBD::ThreadCreated (pthread_self(), "Export post-processing"); + notify_gui_about_thread_creation (pthread_self(), "Export post-processing"); // cc can be trated like 'this' WriterThread & cc (*((WriterThread *) arg)); - for (FileConfigList::iterator it = cc->file_configs.begin(); it != cc->file_configs.end(); ++it) { - if (cc->status.aborted()) { - break; + try { + for (FileConfigList::iterator it = cc->file_configs.begin(); it != cc->file_configs.end(); ++it) { + if (cc->status->aborted()) { + break; + } + cc->processor->prepare (it->first, it->second, cc->channels.size(), cc->split, cc->timespan->get_start()); + cc->write_file (); // Writes tempfile + cc->processor->prepare_post_processors (); + cc->processor->write_files(); } - cc->processor->prepare (it->first, it->second, cc->channels.size(), cc->split, cc->timespan->get_start()); - cc->write_file (); // Writes tempfile - cc->processor->prepare_post_processors (); - cc->processor->write_files(); + } catch (ExportFailed & e) { + cc->status->abort (true); } cc.running = false; @@ -188,7 +208,7 @@ ExportChannelConfiguration::register_with_timespan (TimespanPtr new_timespan) timespan = new_timespan; for (ChannelList::iterator it = channels.begin(); it != channels.end(); ++it) { - timespan->register_channel (**it); + timespan->register_channel (*it); } }