26 #include <glib/gstdio.h>
28 #include <glibmm/fileutils.h>
29 #include <glibmm/miscutils.h>
61 , handler (s.get_export_handler())
65 , single_range_mode (false)
144 FormatStateList::const_iterator format_it;
145 FilenameStateList::const_iterator filename_it;
148 for (TimespanList::iterator ts_it = ts_list->begin(); ts_it != ts_list->end(); ++ts_it) {
152 ++format_it, ++filename_it) {
158 if ((*format_it)->format->has_broadcast_info()) {
160 b->set_from_session (
session, (*ts_it)->get_start());
167 handler->add_export_config (*ts_it, (*cc_it)->config, (*format_it)->format, filename, b);
179 if (!preset) {
return false; }
182 if ((state = preset->get_local_state())) {
184 }
else { ok =
false; }
186 if ((state = preset->get_global_state())) {
190 }
else { ok =
false; }
200 for (vector<std::string>::iterator it = found.begin(); it != found.end(); ++it) {
261 if (g_remove (it->second.c_str()) != 0) {
314 for (FormatStateList::iterator it =
formats.begin(); it !=
formats.end(); ++it) {
318 for (FilenameStateList::iterator it =
filenames.begin(); it !=
filenames.end(); ++it) {
326 for (TimespanStateList::iterator it =
timespans.begin(); it !=
timespans.end(); ++it) {
335 std::vector<std::string>
338 vector<std::string> found;
357 for (TimespanStateList::iterator it =
timespans.begin(); it !=
timespans.end(); ++it) {
383 for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
387 }
else { ok =
false; }
396 if (!session_range) {
return false; }
399 timespan->set_name (session_range->
name());
400 timespan->set_range_id (session_range->
id().
to_s());
401 timespan->set_range (session_range->
start(), session_range->
end());
402 state->timespans->push_back (timespan);
416 for (XMLNodeList::iterator node_it = spans.begin(); node_it != spans.end(); ++node_it) {
418 prop = (*node_it)->property (
"id");
419 if (!prop) {
continue; }
420 string id = prop->
value();
423 for (LocationList::iterator it =
ranges->begin(); it !=
ranges->end(); ++it) {
425 (
id == (*it)->id().to_s())) {
431 if (!location) {
continue; }
434 timespan->set_name (location->
name());
435 timespan->set_range_id (location->
id().
to_s());
436 timespan->set_range (location->
start(), location->
end());
437 state->timespans->push_back (timespan);
440 if ((prop = root.
property (
"format"))) {
444 if (state->timespans->empty()) {
458 for (TimespanList::iterator it = state->timespans->begin(); it != state->timespans->end(); ++it) {
482 ranges->push_back (session_range);
494 for (LocationList::const_iterator it = list.begin(); it != list.end(); ++it) {
495 if ((*it)->is_range_marker()) {
522 if (!master_out) {
return false; }
529 config->
config->register_channel (chan_ptr);
534 for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
536 config->
config->set_state (**it);
557 for (FormatStateList::iterator it =
formats.begin(); it !=
formats.end(); ++it) {
572 string new_name = format->name();
582 FileMap::iterator it;
591 tree.
set_root (&format->get_state());
599 tree.
set_root (&format->get_state());
602 if (new_name != Glib::path_get_basename (it->second)) {
603 if (g_rename (it->second.c_str(), new_path.c_str()) != 0) {
604 error <<
string_compose (
_(
"Unable to rename export format %1 to %2: %3"), it->second, new_path, g_strerror(errno)) <<
endmsg;
609 it->second = new_path;
615 tree.
set_root (&format->get_state());
635 if (g_remove (it->second.c_str()) != 0) {
651 std::cerr <<
"After new format created from original, format has id [" << format->id().to_s() <<
']' << std::endl;
653 format =
handler->add_format();
654 format->set_name (
_(
"empty format"));
673 for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
677 }
else { ok =
false; }
695 if ((prop = root.
property (
"id"))) {
700 if ((*it)->id() == id) {
713 string id = state->
format ? state->
format->id().to_s() :
"";
724 for (vector<std::string>::iterator it = found.begin(); it != found.end(); ++it) {
734 if (!tree.
read (path)) {
768 for (FilenameStateList::iterator it =
filenames.begin(); it !=
filenames.end(); ++it) {
787 if (filenames.empty()) {
return ""; }
788 return filenames.front();
796 for (XMLNodeList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
798 filename->set_state (**it);
828 if (channel_config_state) {
829 channel_config = channel_config_state->
config;
834 if (timespans->empty()) {
835 warnings->
errors.push_back (
_(
"No timespan has been selected!"));
838 if (channel_config_state == 0) {
839 warnings->
errors.push_back (
_(
"No channels have been selected!"));
842 if (!channel_config->all_channels_have_ports ()) {
843 warnings->
warnings.push_back (
_(
"Some channels are empty"));
849 if (channel_config_state) {
850 FormatStateList::const_iterator format_it;
851 FilenameStateList::const_iterator filename_it;
854 ++format_it, ++filename_it) {
855 check_config (warnings, timespan_state, channel_config_state, *format_it, *filename_it);
875 if (!format || !format->type()) {
876 warnings->
errors.push_back (
_(
"No format selected!"));
877 }
else if (!channel_config->get_n_chans()) {
878 warnings->
errors.push_back (
_(
"All channels are empty!"));
879 }
else if (!
check_format (format, channel_config->get_n_chans())) {
880 warnings->
errors.push_back (
_(
"One or more of the selected formats is not compatible with this system!"));
881 }
else if (format->channel_limit() < channel_config->get_n_chans()) {
882 warnings->
errors.push_back
883 (
string_compose (
_(
"%1 supports only %2 channels, but you have %3 channels in your channel configuration"),
884 format->format_name(),
885 format->channel_limit(),
886 channel_config->get_n_chans()));
889 if (!warnings->
errors.empty()) {
return; }
895 std::list<string> paths;
898 for (std::list<string>::const_iterator path_it = paths.begin(); path_it != paths.end(); ++path_it) {
900 string path = *path_it;
902 if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
906 if (format->with_toc()) {
908 if (Glib::file_test (marker_file, Glib::FILE_TEST_EXISTS)) {
913 if (format->with_cue()) {
915 if (Glib::file_test (marker_file, Glib::FILE_TEST_EXISTS)) {
925 switch (format->type()) {
930 throw ExportFailed (
X_(
"Invalid format given for ExportFileFactory::check!"));
938 sf_info.channels = channels;
939 sf_info.samplerate = format->sample_rate ();
940 sf_info.format = format->format_id () | format->sample_format ();
942 return (sf_format_check (&sf_info) == SF_TRUE ?
true :
false);
950 for (std::list<ExportTimespanPtr>::iterator timespan_it = timespans->begin();
951 timespan_it != timespans->end(); ++timespan_it) {
952 filename->set_timespan (*timespan_it);
954 if (channel_config->get_split()) {
955 filename->include_channel =
true;
957 for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) {
958 filename->set_channel (chan);
959 result.push_back(filename->get_path (format));
963 filename->include_channel =
false;
964 result.push_back(filename->get_path (format));
XMLNode & serialize_timespan(TimespanStatePtr state)
TimespanStateList timespans
boost::shared_ptr< TimespanState > TimespanStatePtr
ExportFilenamePtr filename
std::string export_config_dir
void build_filenames(std::list< std::string > &result, ExportFilenamePtr filename, TimespanListPtr timespans, ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format)
const std::string & value() const
boost::shared_ptr< FormatList > format_list
std::string get_sample_filename_for_format(ExportFilenamePtr filename, ExportFormatSpecPtr format)
bool check_sndfile_format(ExportFormatSpecPtr format, unsigned int channels)
LIBARDOUR_API std::string legalize_for_path(const std::string &str)
FormatStatePtr deserialize_format(XMLNode &root)
PBD::Searchpath search_path
LIBARDOUR_API const char *const export_dir_name
void remove_format_state(FormatStatePtr state)
XMLNode & serialize_format(FormatStatePtr state)
FilenameStateList filenames
Basic export channel that reads from AudioPorts.
LIBPBD_API Transmitter error
const XMLNodeList & children(const std::string &str=std::string()) const
bool set_local_state(XMLNode const &root)
std::ostream & endmsg(std::ostream &ostr)
FormatStatePtr duplicate_format_state(FormatStatePtr state)
void load_format_from_disk(std::string const &path)
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
ChannelConfigStateList channel_configs
XMLNode * add_child(const char *)
std::string set_single_range(framepos_t start, framepos_t end, std::string name)
std::string xml_node_name
std::list< std::string > warnings
ExportPresetPtr save_preset(std::string const &name)
Location * session_range_location() const
boost::shared_ptr< AudioPort > audio(uint32_t n) const
bool init_channel_configs(XMLNodeList nodes)
std::list< XMLNode * > XMLNodeList
LIBARDOUR_API std::string user_config_directory(int version=-1)
bool check_format(ExportFormatSpecPtr format, uint32_t channels)
void remove_format_profile(ExportFormatSpecPtr format)
const ChanCount & n_ports() const
ExportPresetPtr new_preset(std::string const &name)
void find_files_matching_pattern(vector< string > &result, const Searchpath &paths, const Glib::PatternSpec &pattern)
XMLProperty * property(const char *)
ChannelConfigStatePtr add_channel_config()
#define string_2_enum(str, e)
bool init_timespans(XMLNodeList nodes)
XMLNode * set_root(XMLNode *n)
const LocationList & list()
boost::shared_ptr< Route > master_out() const
const PBD::ID & id() const
void set_selection_range(framepos_t start=0, framepos_t end=0)
void add_port(boost::weak_ptr< AudioPort > port)
ExportFormatSpecPtr get_new_format(ExportFormatSpecPtr original)
LIBPBD_API Transmitter info
LIBARDOUR_API PBD::Searchpath export_formats_search_path()
void remove_filename_state(FilenameStatePtr state)
boost::shared_ptr< FormatState > FormatStatePtr
LIBARDOUR_API const char *const export_format_suffix
XMLProperty * add_property(const char *name, const std::string &value)
std::vector< std::string > find_file(std::string const &pattern)
void serialize_profile(XMLNode &root)
boost::shared_ptr< Warnings > get_warnings()
void add_child_nocopy(XMLNode &)
const std::string & name() const
ExportChannelConfigPtr config
std::pair< PBD::UUID, std::string > FilePair
void serialize_local_profile(XMLNode &root)
XMLNode * instant_xml(const std::string &str)
void prepare_for_export()
LIBPBD_TEMPLATE_MEMBER_API const std::string to_string() const
std::list< ExportFormatSpecPtr > FormatList
TimespanStatePtr deserialize_timespan(XMLNode &root)
XMLNode * extra_xml(const std::string &str, bool add_if_missing=false)
bool init_formats(XMLNodeList nodes)
bool set_global_state(XMLNode const &root)
void load_preset_from_disk(std::string const &path)
bool init_filenames(XMLNodeList nodes)
boost::shared_ptr< Location > single_range
std::string save_format_to_disk(ExportFormatSpecPtr format)
void check_config(boost::shared_ptr< Warnings > warnings, TimespanStatePtr timespan_state, ChannelConfigStatePtr channel_config_state, FormatStatePtr format_state, FilenameStatePtr filename_state)
void serialize_global_profile(XMLNode &root)
LIBARDOUR_API const char *const export_preset_suffix
void add_extra_xml(XMLNode &)
bool load_preset(ExportPresetPtr preset)
std::list< std::string > conflicting_filenames
ExportPresetPtr current_preset
std::list< std::string > errors
std::list< Location * > LocationList
PBD::Signal0< void > FormatListChanged
FilenameStatePtr duplicate_filename_state(FilenameStatePtr state)
boost::shared_ptr< Location > selection_range
std::string preset_filename(std::string const &preset_name)
bool set_state(XMLNode const &root)
std::string string_compose(const std::string &fmt, const T1 &o1)
boost::shared_ptr< LocationList > ranges