X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudio_playlist_importer.cc;h=34d46915f188e6f21feaa9417b804fc709051b82;hb=5b4c3aa226dc95f33dc3ffae6669a24f5e8b8fe0;hp=50aa6f222580c3e175e3738a5ac889d9e1ef777d;hpb=a8cc30be5fe817d120d23ba72e6d75839085f81b;p=ardour.git diff --git a/libs/ardour/audio_playlist_importer.cc b/libs/ardour/audio_playlist_importer.cc index 50aa6f2225..34d46915f1 100644 --- a/libs/ardour/audio_playlist_importer.cc +++ b/libs/ardour/audio_playlist_importer.cc @@ -18,19 +18,22 @@ */ -#include +#include "ardour/audio_playlist_importer.h" #include -#include -#include -#include +#include "pbd/failed_constructor.h" +#include "pbd/compose.h" +#include "pbd/error.h" -#include -#include -#include -#include +#include "ardour/audio_region_importer.h" +#include "ardour/session.h" +#include "ardour/playlist_factory.h" +#include "ardour/session_playlists.h" +#include "i18n.h" + +using namespace std; using namespace PBD; using namespace ARDOUR; @@ -41,11 +44,11 @@ AudioPlaylistImportHandler::AudioPlaylistImportHandler (XMLTree const & source, { XMLNode const * root = source.root(); XMLNode const * playlists; - + if (!(playlists = root->child (nodename))) { throw failed_constructor(); } - + XMLNodeList const & pl_children = playlists->children(); for (XMLNodeList::const_iterator it = pl_children.begin(); it != pl_children.end(); ++it) { const XMLProperty* type = (*it)->property("type"); @@ -91,7 +94,7 @@ AudioPlaylistImportHandler::playlists_by_diskstream (PBD::ID const & id, Playlis } /*** AudioPlaylistImporter ***/ -AudioPlaylistImporter::AudioPlaylistImporter (XMLTree const & source, Session & session, AudioPlaylistImportHandler & handler, XMLNode const & node) : +AudioPlaylistImporter::AudioPlaylistImporter (XMLTree const & source, Session & session, AudioPlaylistImportHandler & handler, XMLNode const & node) : ElementImporter (source, session), handler (handler), orig_node (node), @@ -99,9 +102,9 @@ AudioPlaylistImporter::AudioPlaylistImporter (XMLTree const & source, Session & diskstream_id ("0") { bool ds_ok = false; - + populate_region_list (); - + // Parse XML XMLPropertyList const & props = xml_playlist.properties(); for (XMLPropertyList::const_iterator it = props.begin(); it != props.end(); ++it) { @@ -117,7 +120,7 @@ AudioPlaylistImporter::AudioPlaylistImporter (XMLTree const & source, Session & std::cerr << string_compose (X_("AudioPlaylistImporter did not recognise XML-property \"%1\""), prop) << endmsg; } } - + if (!ds_ok) { error << string_compose (X_("AudioPlaylistImporter (%1): did not find XML-property \"orig_diskstream_id\" which is mandatory"), name) << endmsg; throw failed_constructor(); @@ -136,7 +139,7 @@ AudioPlaylistImporter::AudioPlaylistImporter (AudioPlaylistImporter const & othe AudioPlaylistImporter::~AudioPlaylistImporter () { - + } string @@ -145,21 +148,21 @@ AudioPlaylistImporter::get_info () const XMLNodeList children = xml_playlist.children(); unsigned int regions = 0; std::ostringstream oss; - + for (XMLNodeIterator it = children.begin(); it != children.end(); it++) { if ((*it)->name() == "Region") { ++regions; } } - + oss << regions << " "; - + if (regions == 1) { oss << _("region"); } else { oss << _("regions"); } - + return oss.str(); } @@ -167,16 +170,22 @@ bool AudioPlaylistImporter::_prepare_move () { // Rename - while (session.playlist_by_name (name) || !handler.check_name (name)) { - std::pair rename_pair = Rename (_("A playlist with this name already exists, please rename it."), name); + while (session.playlists->by_name (name) || !handler.check_name (name)) { + std::pair rename_pair = *Rename (_("A playlist with this name already exists, please rename it."), name); if (!rename_pair.first) { return false; } name = rename_pair.second; } - xml_playlist.property ("name")->set_value (name); - handler.add_name (name); + XMLProperty* p = xml_playlist.property ("name"); + if (!p) { + error << _("badly-formed XML in imported playlist") << endmsg; + } + + p->set_value (name); + handler.add_name (name); + return true; } @@ -190,10 +199,10 @@ void AudioPlaylistImporter::_move () { boost::shared_ptr playlist; - + // Update diskstream id xml_playlist.property ("orig-diskstream-id")->set_value (diskstream_id.to_s()); - + // Update region XML in playlist and prepare sources xml_playlist.remove_nodes("Region"); for (RegionList::iterator it = regions.begin(); it != regions.end(); ++it) { @@ -205,7 +214,7 @@ AudioPlaylistImporter::_move () return; // TODO clean up? } } - + // Update region ids in crossfades XMLNodeList crossfades = xml_playlist.children("Crossfade"); for (XMLNodeIterator it = crossfades.begin(); it != crossfades.end(); ++it) { @@ -214,22 +223,22 @@ AudioPlaylistImporter::_move () if (!in || !out) { error << string_compose (X_("AudioPlaylistImporter (%1): did not find the \"in\" or \"out\" property from a crossfade"), name) << endmsg; } - + handler.update_region_id (in); handler.update_region_id (out); - + // rate convert length and position XMLProperty* length = (*it)->property("length"); if (length) { length->set_value (rate_convert_samples (length->value())); } - + XMLProperty* position = (*it)->property("position"); if (position) { position->set_value (rate_convert_samples (position->value())); } } - + // Create playlist playlist = PlaylistFactory::create (session, xml_playlist, false, true); } @@ -250,3 +259,8 @@ AudioPlaylistImporter::populate_region_list () } } +string +UnusedAudioPlaylistImportHandler::get_info () const +{ + return _("Audio Playlists (unused)"); +}