Add support for RIFF and ID3v2 tags (wav, aiff)

This commit is contained in:
Robin Gareus
2020-11-14 16:00:16 +01:00
parent a95d87ef6e
commit f149a82688
4 changed files with 60 additions and 3 deletions

View File

@@ -22,6 +22,8 @@
#include <string>
#include <taglib/id3v2tag.h>
#include <taglib/infotag.h>
#include <taglib/tag.h>
#include <taglib/taglib.h>
#include <taglib/xiphcomment.h>
@@ -43,6 +45,8 @@ public:
private:
static bool tag_generic (TagLib::Tag& tag, SessionMetadata const& metadata);
static bool tag_vorbis_comment (TagLib::Ogg::XiphComment& tag, SessionMetadata const& metadata);
static bool tag_riff_info (TagLib::RIFF::Info::Tag& tag, SessionMetadata const& metadata);
static bool tag_id3v2 (TagLib::ID3v2::Tag& tag, SessionMetadata const& metadata);
};
} // namespace ARDOUR

View File

@@ -269,6 +269,20 @@ protected:
SampleFormat _default_sample_format;
};
class LIBARDOUR_API ExportFormatTaggedLinear : public ExportFormatLinear
{
public:
ExportFormatTaggedLinear (std::string name, FormatId format_id)
: ExportFormatLinear (name, format_id)
{
}
virtual bool supports_tagging () const
{
return true;
}
};
class LIBARDOUR_API ExportFormatOggVorbis : public ExportFormat, public HasCodecQuality
{
public:

View File

@@ -27,6 +27,9 @@
#include <taglib/fileref.h>
#include <taglib/flacfile.h>
#include <taglib/oggfile.h>
#include <taglib/rifffile.h>
#include <taglib/wavfile.h>
#include <taglib/aifffile.h>
#include <taglib/tag.h>
#include <taglib/taglib.h>
#include <taglib/xiphcomment.h>
@@ -80,6 +83,25 @@ AudiofileTagger::tag_file (std::string const& filename, SessionMetadata const& m
}
}
TagLib::RIFF::WAV::File* wav_file;
if ((wav_file = dynamic_cast<TagLib::RIFF::WAV::File*> (file.file ()))) {
TagLib::RIFF::Info::Tag* info_tag = dynamic_cast<TagLib::RIFF::Info::Tag*> (wav_file->InfoTag ());
assert (info_tag);
tag_riff_info (*info_tag, metadata);
#if 1 // Also add id3v2 header to .wav
TagLib::ID3v2::Tag* id3v2_tag = dynamic_cast<TagLib::ID3v2::Tag*> (wav_file->tag ());
assert (id3v2_tag);
tag_id3v2 (*id3v2_tag, metadata);
#endif
}
TagLib::RIFF::AIFF::File* aiff_file;
if ((aiff_file = dynamic_cast<TagLib::RIFF::AIFF::File*> (file.file ()))) {
TagLib::ID3v2::Tag* id3v2_tag = dynamic_cast<TagLib::ID3v2::Tag*> (aiff_file->tag ());
assert (id3v2_tag);
tag_id3v2 (*id3v2_tag, metadata);
}
file.save ();
return true;
}
@@ -124,5 +146,22 @@ AudiofileTagger::tag_vorbis_comment (TagLib::Ogg::XiphComment& tag, SessionMetad
return true;
}
bool
AudiofileTagger::tag_riff_info (TagLib::RIFF::Info::Tag& tag, SessionMetadata const& metadata)
{
/* tag_generic() already takes care of all relevant fields:
* https://taglib.org/api/classTagLib_1_1RIFF_1_1Info_1_1Tag.html#pub-methods
*/
return tag_generic (tag, metadata);
}
bool
AudiofileTagger::tag_id3v2 (TagLib::ID3v2::Tag& tag, SessionMetadata const& metadata)
{
/* TODO: consider adding custom frames
* https://taglib.org/api/classTagLib_1_1ID3v2_1_1Frame.html
*/
return tag_generic (tag, metadata);
}
} // namespace ARDOUR

View File

@@ -122,7 +122,7 @@ ExportFormatManager::init_formats ()
ExportFormatPtr f_ptr;
ExportFormatLinear * fl_ptr;
f_ptr.reset (fl_ptr = new ExportFormatLinear ("AIFF", ExportFormatBase::F_AIFF));
f_ptr.reset (fl_ptr = new ExportFormatTaggedLinear ("AIFF", ExportFormatBase::F_AIFF));
fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
fl_ptr->add_sample_format (ExportFormatBase::SF_8);
fl_ptr->add_sample_format (ExportFormatBase::SF_16);
@@ -158,7 +158,7 @@ ExportFormatManager::init_formats ()
fl_ptr->set_extension ("sf");
add_format (f_ptr);
f_ptr.reset (fl_ptr = new ExportFormatLinear ("WAV", ExportFormatBase::F_WAV));
f_ptr.reset (fl_ptr = new ExportFormatTaggedLinear ("WAV", ExportFormatBase::F_WAV));
fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
fl_ptr->add_sample_format (ExportFormatBase::SF_16);
fl_ptr->add_sample_format (ExportFormatBase::SF_24);
@@ -170,7 +170,7 @@ ExportFormatManager::init_formats ()
fl_ptr->set_extension ("wav");
add_format (f_ptr);
f_ptr.reset (fl_ptr = new ExportFormatLinear ("W64", ExportFormatBase::F_W64));
f_ptr.reset (fl_ptr = new ExportFormatTaggedLinear ("W64", ExportFormatBase::F_W64));
fl_ptr->add_sample_format (ExportFormatBase::SF_U8);
fl_ptr->add_sample_format (ExportFormatBase::SF_16);
fl_ptr->add_sample_format (ExportFormatBase::SF_24);