tag editor: performer, composer and disc tags support for ogg and flac files
This commit is contained in:
@@ -25,9 +25,12 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
// taglib includes
|
||||||
#include "id3v2tag.h"
|
#include "id3v2tag.h"
|
||||||
#include "textidentificationframe.h"
|
#include "textidentificationframe.h"
|
||||||
#include "mpegfile.h"
|
#include "mpegfile.h"
|
||||||
|
#include "vorbisfile.h"
|
||||||
|
#include "flacfile.h"
|
||||||
|
|
||||||
#include "charset.h"
|
#include "charset.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
@@ -920,6 +923,23 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TagEditor::WriteXiphComments(const MPD::Song &s, TagLib::Ogg::XiphComment *tag)
|
||||||
|
{
|
||||||
|
TagLib::StringList list;
|
||||||
|
|
||||||
|
tag->addField("DISCNUMBER", ToWString(s.GetDisc())); // disc
|
||||||
|
|
||||||
|
tag->removeField("COMPOSER"); // composer
|
||||||
|
GetTagList(list, s.GetComposer());
|
||||||
|
for (TagLib::StringList::ConstIterator it = list.begin(); it != list.end(); ++it)
|
||||||
|
tag->addField("COMPOSER", *it, 0);
|
||||||
|
|
||||||
|
tag->removeField("PERFORMER"); // performer
|
||||||
|
GetTagList(list, s.GetPerformer());
|
||||||
|
for (TagLib::StringList::ConstIterator it = list.begin(); it != list.end(); ++it)
|
||||||
|
tag->addField("PERFORMER", *it, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool TagEditor::WriteTags(MPD::Song &s)
|
bool TagEditor::WriteTags(MPD::Song &s)
|
||||||
{
|
{
|
||||||
std::string path_to_file;
|
std::string path_to_file;
|
||||||
@@ -938,9 +958,9 @@ bool TagEditor::WriteTags(MPD::Song &s)
|
|||||||
f.tag()->setTrack(StrToInt(s.GetTrack()));
|
f.tag()->setTrack(StrToInt(s.GetTrack()));
|
||||||
f.tag()->setGenre(ToWString(s.GetGenre()));
|
f.tag()->setGenre(ToWString(s.GetGenre()));
|
||||||
f.tag()->setComment(ToWString(s.GetComment()));
|
f.tag()->setComment(ToWString(s.GetComment()));
|
||||||
if (TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File *>(f.file()))
|
if (TagLib::MPEG::File *mp3_file = dynamic_cast<TagLib::MPEG::File *>(f.file()))
|
||||||
{
|
{
|
||||||
TagLib::ID3v2::Tag *tag = file->ID3v2Tag();
|
TagLib::ID3v2::Tag *tag = mp3_file->ID3v2Tag(1);
|
||||||
TagLib::StringList list;
|
TagLib::StringList list;
|
||||||
|
|
||||||
WriteID3v2("TIT2", tag, ToWString(s.GetTitle())); // title
|
WriteID3v2("TIT2", tag, ToWString(s.GetTitle())); // title
|
||||||
@@ -957,6 +977,14 @@ bool TagEditor::WriteTags(MPD::Song &s)
|
|||||||
GetTagList(list, s.GetPerformer());
|
GetTagList(list, s.GetPerformer());
|
||||||
WriteID3v2("TOPE", tag, list); // performer
|
WriteID3v2("TOPE", tag, list); // performer
|
||||||
}
|
}
|
||||||
|
else if (TagLib::Ogg::Vorbis::File *ogg_file = dynamic_cast<TagLib::Ogg::Vorbis::File *>(f.file()))
|
||||||
|
{
|
||||||
|
WriteXiphComments(s, ogg_file->tag());
|
||||||
|
}
|
||||||
|
else if (TagLib::FLAC::File *flac_file = dynamic_cast<TagLib::FLAC::File *>(f.file()))
|
||||||
|
{
|
||||||
|
WriteXiphComments(s, flac_file->xiphComment(1));
|
||||||
|
}
|
||||||
if (!f.save())
|
if (!f.save())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1062,7 +1090,9 @@ void TagEditor::GetTagList(TagLib::StringList &list, const std::string &s)
|
|||||||
for (size_t i = 0; i != std::string::npos; i = s.find(",", i))
|
for (size_t i = 0; i != std::string::npos; i = s.find(",", i))
|
||||||
{
|
{
|
||||||
if (i)
|
if (i)
|
||||||
i++;
|
++i;
|
||||||
|
while (s[i] == ' ')
|
||||||
|
++i;
|
||||||
size_t j = s.find(",", i);
|
size_t j = s.find(",", i);
|
||||||
list.append(TagLib::String(s.substr(i, j-i), TagLib::String::UTF8));
|
list.append(TagLib::String(s.substr(i, j-i), TagLib::String::UTF8));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
// taglib headers
|
// taglib headers
|
||||||
|
#include "xiphcomment.h"
|
||||||
#include "fileref.h"
|
#include "fileref.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
|
||||||
@@ -96,6 +97,7 @@ class TagEditor : public Screen<Window>
|
|||||||
static void CapitalizeFirstLetters(MPD::Song &);
|
static void CapitalizeFirstLetters(MPD::Song &);
|
||||||
static void LowerAllLetters(MPD::Song &);
|
static void LowerAllLetters(MPD::Song &);
|
||||||
static void GetTagList(TagLib::StringList &, const std::string &);
|
static void GetTagList(TagLib::StringList &, const std::string &);
|
||||||
|
static void WriteXiphComments(const MPD::Song &, TagLib::Ogg::XiphComment *);
|
||||||
|
|
||||||
static void GetPatternList();
|
static void GetPatternList();
|
||||||
static void SavePatternList();
|
static void SavePatternList();
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
#ifdef HAVE_TAGLIB_H
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
|
||||||
|
// taglib includes
|
||||||
|
#include "mpegfile.h"
|
||||||
|
#include "vorbisfile.h"
|
||||||
|
#include "flacfile.h"
|
||||||
|
|
||||||
#include "browser.h"
|
#include "browser.h"
|
||||||
#include "charset.h"
|
#include "charset.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
@@ -281,7 +286,7 @@ bool TinyTagEditor::GetTags()
|
|||||||
w->IntoSeparator(18);
|
w->IntoSeparator(18);
|
||||||
w->IntoSeparator(20);
|
w->IntoSeparator(20);
|
||||||
|
|
||||||
if (ext != "mp3")
|
if (!extendedTagsSupported(f.file()))
|
||||||
for (size_t i = 14; i <= 16; ++i)
|
for (size_t i = 14; i <= 16; ++i)
|
||||||
w->Static(i, 1);
|
w->Static(i, 1);
|
||||||
|
|
||||||
@@ -324,5 +329,12 @@ bool TinyTagEditor::GetTags()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TinyTagEditor::extendedTagsSupported(TagLib::File *f)
|
||||||
|
{
|
||||||
|
return dynamic_cast<TagLib::MPEG::File *>(f)
|
||||||
|
|| dynamic_cast<TagLib::Ogg::Vorbis::File *>(f)
|
||||||
|
|| dynamic_cast<TagLib::FLAC::File *>(f);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAVE_TAGLIB_H
|
#endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
|
|
||||||
#ifdef HAVE_TAGLIB_H
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
|
||||||
|
// taglib includes
|
||||||
|
#include "tfile.h"
|
||||||
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
class TinyTagEditor : public Screen< Menu<Buffer> >
|
class TinyTagEditor : public Screen< Menu<Buffer> >
|
||||||
@@ -53,6 +56,8 @@ class TinyTagEditor : public Screen< Menu<Buffer> >
|
|||||||
private:
|
private:
|
||||||
bool GetTags();
|
bool GetTags();
|
||||||
MPD::Song itsEdited;
|
MPD::Song itsEdited;
|
||||||
|
|
||||||
|
static bool extendedTagsSupported(TagLib::File *);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TinyTagEditor *myTinyTagEditor;
|
extern TinyTagEditor *myTinyTagEditor;
|
||||||
|
|||||||
Reference in New Issue
Block a user