X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Faudiofile_tagger.cc;h=e2d81176e115dc87e0527efc7d9c538dab2e4039;hb=22a903171347cc8f3776e4c539ca5f1172ec449c;hp=7cd76e43c995f3829413b4674b1c3b9f143a859f;hpb=e0aaed6d65f160c328cb8b56d7c6552ee15d65e2;p=ardour.git diff --git a/libs/ardour/audiofile_tagger.cc b/libs/ardour/audiofile_tagger.cc index 7cd76e43c9..e2d81176e1 100644 --- a/libs/ardour/audiofile_tagger.cc +++ b/libs/ardour/audiofile_tagger.cc @@ -25,11 +25,14 @@ #include "pbd/convert.h" #include -#include #include +#include +#include +#include +#include -/* Convert Glib::ustring to TagLib::String */ -#define TL_STR(ustring) TagLib::String ((ustring).c_str(), TagLib::String::UTF8) +/* Convert string to TagLib::String */ +#define TL_STR(string) TagLib::String ((string).c_str(), TagLib::String::UTF8) using namespace PBD; @@ -37,15 +40,25 @@ namespace ARDOUR { bool -AudiofileTagger::tag_file (string const & filename, SessionMetadata const & metadata) +AudiofileTagger::tag_file (std::string const & filename, SessionMetadata const & metadata) { TagLib::FileRef file (filename.c_str()); + if (file.isNull()) { + std::cerr << "TagLib::FileRef is null for file" << filename << std::endl; + return true; // continue anyway?! + } + + if (!file.tag()) { + std::cerr << "TagLib::Tag is null for file" << filename << std::endl; + return true; // continue anyway?! + } + TagLib::Tag & tag (*file.tag()); - + tag_generic (tag, metadata); - + /* FLAC */ - + TagLib::FLAC::File * flac_file; if ((flac_file = dynamic_cast (file.file()))) { TagLib::Ogg::XiphComment * vorbis_tag; @@ -55,9 +68,9 @@ AudiofileTagger::tag_file (string const & filename, SessionMetadata const & meta std::cerr << "Could not get Xiph comment for FLAC file!" << std::endl; } } - + /* Ogg */ - + TagLib::Ogg::File * ogg_file; if ((ogg_file = dynamic_cast (file.file()))) { TagLib::Ogg::XiphComment * vorbis_tag; @@ -67,7 +80,7 @@ AudiofileTagger::tag_file (string const & filename, SessionMetadata const & meta std::cerr << "Could not get Xiph comment for Ogg file!" << std::endl; } } - + file.save(); return true; } @@ -82,7 +95,7 @@ AudiofileTagger::tag_generic (TagLib::Tag & tag, SessionMetadata const & metadat tag.setGenre (TL_STR(metadata.genre())); tag.setYear (metadata.year()); tag.setTrack (metadata.track_number()); - + return true; } @@ -106,7 +119,7 @@ AudiofileTagger::tag_vorbis_comment (TagLib::Ogg::XiphComment & tag, SessionMeta tag.addField ("COMPILATION", TL_STR(metadata.compilation())); tag.addField ("DISCSUBTITLE", TL_STR(metadata.disc_subtitle())); tag.addField ("DISCNUMBER", to_string (metadata.disc_number(), std::dec)); - + // No field for total discs or tracks return true;