Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
Tags Class Referencefinal

ID3 Tags (for MP3) More...

#include <Tags.h>

Inheritance diagram for Tags:
[legend]
Collaboration diagram for Tags:
[legend]

Public Types

using Iterators = IteratorRange< TagMap::const_iterator >
 

Public Member Functions

 Tags ()
 
 Tags (const Tags &)=default
 
virtual ~Tags ()
 
std::shared_ptr< TagsDuplicate () const
 
void Merge (const Tags &other)
 
Tagsoperator= (const Tags &src)
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXML (XMLWriter &xmlFile) const
 
void LoadDefaultGenres ()
 
void LoadGenres ()
 
void LoadDefaults ()
 
int GetNumUserGenres ()
 
wxString GetUserGenre (int value)
 
wxString GetGenre (int value)
 
int GetGenre (const wxString &name)
 
bool HasTag (const wxString &name) const
 
wxString GetTag (const wxString &name) const
 
Iterators GetRange () const
 
void SetTag (const wxString &name, const wxString &value, const bool bSpecialTag=false)
 
void SetTag (const wxString &name, const int &value)
 
bool IsEmpty ()
 
void Clear ()
 
size_t Count () const
 
void RestoreUndoRedoState (AudacityProject &) override
 Modify the project when undoing or redoing to some state in history. More...
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from UndoStateExtension
virtual ~UndoStateExtension ()
 
virtual void RestoreUndoRedoState (AudacityProject &project)=0
 Modify the project when undoing or redoing to some state in history. More...
 
virtual bool CanUndoOrRedo (const AudacityProject &project)
 Whether undo or redo is now permitted; default returns true. More...
 

Static Public Member Functions

static TagsGet (AudacityProject &project)
 
static const TagsGet (const AudacityProject &project)
 
static TagsSet (AudacityProject &project, const std::shared_ptr< Tags > &tags)
 

Private Attributes

TagMap mXref
 
TagMap mMap
 
wxArrayString mGenres
 

Friends

TAGS_API bool operator== (const Tags &lhs, const Tags &rhs)
 

Detailed Description

ID3 Tags (for MP3)

This class started as an ID3 tag

This class holds a few informational tags, such as Title, Author, etc. that can be associated with a project or other audio file. It is modeled after the ID3 format for MP3 files, and it can both import and export ID3 tags from/to MP2, MP3, and AIFF files.

It can present the user with a dialog for editing this information.

Use of this functionality requires that libid3tag be compiled in with Audacity.

Definition at line 68 of file Tags.h.

Member Typedef Documentation

◆ Iterators

using Tags::Iterators = IteratorRange<TagMap::const_iterator>

Definition at line 112 of file Tags.h.

Constructor & Destructor Documentation

◆ Tags() [1/2]

Tags::Tags ( )

Definition at line 231 of file Tags.cpp.

232{
233 LoadDefaults();
234 LoadGenres();
235}
void LoadGenres()
Definition: Tags.cpp:346
void LoadDefaults()
Definition: Tags.cpp:266

References LoadDefaults(), and LoadGenres().

Here is the call graph for this function:

◆ Tags() [2/2]

Tags::Tags ( const Tags )
default

◆ ~Tags()

Tags::~Tags ( )
virtual

Definition at line 237 of file Tags.cpp.

238{
239}

Member Function Documentation

◆ Clear()

void Tags::Clear ( )

Definition at line 293 of file Tags.cpp.

294{
295 mXref.clear();
296 mMap.clear();
297}
TagMap mXref
Definition: Tags.h:129
TagMap mMap
Definition: Tags.h:130

References mMap, and mXref.

Referenced by FLACImportFileHandle::Import(), OggImportFileHandle::Import(), and WavPackImportFileHandle::Import().

Here is the caller graph for this function:

◆ Count()

size_t Tags::Count ( ) const

Definition at line 299 of file Tags.cpp.

300{
301 return mMap.size();
302}

References mMap.

◆ Duplicate()

std::shared_ptr< Tags > Tags::Duplicate ( ) const

Definition at line 241 of file Tags.cpp.

242{
243 return std::make_shared<Tags>(*this);
244}

◆ Get() [1/2]

Tags & Tags::Get ( AudacityProject project)
static

Definition at line 214 of file Tags.cpp.

215{
216 return project.AttachedObjects::Get< Tags >( key );
217}
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: Tags.cpp:210
const auto project
ID3 Tags (for MP3)
Definition: Tags.h:73

References key, and project.

Referenced by ProjectFileManager::DoImport(), TagsEditorDialog::EditProjectMetadata(), OGGExportProcessor::FillComment(), Get(), anonymous_namespace{ProjectFileManager.cpp}::ImportProject(), FFmpegExporter::Init(), CLExportProcessor::Initialize(), MP2ExportProcessor::Initialize(), MP3ExportProcessor::Initialize(), OpusExportProcessor::Initialize(), PCMExportProcessor::Initialize(), WavPackExportProcessor::Initialize(), FLACExportProcessor::MakeMetadata(), ExportAudioDialog::UpdateLabelExportSettings(), and ExportAudioDialog::UpdateTrackExportSettings().

Here is the caller graph for this function:

◆ Get() [2/2]

const Tags & Tags::Get ( const AudacityProject project)
static

Definition at line 219 of file Tags.cpp.

220{
221 return Get( const_cast< AudacityProject & >( project ) );
222}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static Tags & Get(AudacityProject &project)
Definition: Tags.cpp:214

References Get(), and project.

Here is the call graph for this function:

◆ GetGenre() [1/2]

int Tags::GetGenre ( const wxString &  name)

Definition at line 384 of file Tags.cpp.

385{
386 int cnt = WXSIZEOF(DefaultGenres);
387
388 for (int i = 0; i < cnt; i++) {
389 if (name.CmpNoCase(DefaultGenres[i])) {
390 return i;
391 }
392 }
393
394 return 255;
395}
static const wxChar * DefaultGenres[]
Definition: Tags.cpp:50
wxString name
Definition: TagsEditor.cpp:166

References DefaultGenres, and name.

◆ GetGenre() [2/2]

wxString Tags::GetGenre ( int  value)

Definition at line 373 of file Tags.cpp.

374{
375 int cnt = WXSIZEOF(DefaultGenres);
376
377 if (i >= 0 && i < cnt) {
378 return DefaultGenres[i];
379 }
380
381 return wxT("");
382}
wxT("CloseDown"))

References DefaultGenres, and wxT().

Referenced by anonymous_namespace{ImportMP3_MPG123.cpp}::GetId3v2Genre(), PCMImportFileHandle::Import(), and anonymous_namespace{ImportMP3_MPG123.cpp}::MP3ImportFileHandle::ReadTags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNumUserGenres()

int Tags::GetNumUserGenres ( )

Definition at line 333 of file Tags.cpp.

334{
335 return mGenres.size();
336}
wxArrayString mGenres
Definition: Tags.h:132

References mGenres.

Referenced by GetUserGenre().

Here is the caller graph for this function:

◆ GetRange()

Tags::Iterators Tags::GetRange ( ) const

Definition at line 426 of file Tags.cpp.

427{
428 return { mMap.begin(), mMap.end() };
429}

References mMap.

Referenced by PCMExportProcessor::AddID3Chunk(), MP2ExportProcessor::AddTags(), MP3ExportProcessor::AddTags(), OGGExportProcessor::FillComment(), CLExportProcessor::GetMetaChunk(), and FLACExportProcessor::MakeMetadata().

Here is the caller graph for this function:

◆ GetTag()

wxString Tags::GetTag ( const wxString &  name) const

Definition at line 406 of file Tags.cpp.

407{
408 wxString key = name;
409 key.UpperCase();
410
411 auto iter = mXref.find(key);
412
413 if (iter == mXref.end()) {
414 return wxEmptyString;
415 }
416
417 auto iter2 = mMap.find(iter->second);
418 if (iter2 == mMap.end()) {
419 wxASSERT(false);
420 return wxEmptyString;
421 }
422 else
423 return iter2->second;
424}

References key, mMap, mXref, and name.

Referenced by PCMExportProcessor::AddStrings(), PCMImportFileHandle::Import(), and FFmpegExporter::SetMetadata().

Here is the caller graph for this function:

◆ GetUserGenre()

wxString Tags::GetUserGenre ( int  value)

Definition at line 364 of file Tags.cpp.

365{
366 if (i >= 0 && i < GetNumUserGenres()) {
367 return mGenres[i];
368 }
369
370 return wxT("");
371}
int GetNumUserGenres()
Definition: Tags.cpp:333

References GetNumUserGenres(), mGenres, and wxT().

Here is the call graph for this function:

◆ HandleXMLChild()

XMLTagHandler * Tags::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 526 of file Tags.cpp.

527{
528 if (tag == "tags") {
529 return this;
530 }
531
532 if (tag == "tag") {
533 return this;
534 }
535
536 return NULL;
537}

◆ HandleXMLTag()

bool Tags::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 491 of file Tags.cpp.

492{
493 if (tag == "tags") {
494 return true;
495 }
496
497 if (tag == "tag") {
498 wxString n, v;
499
500 for (auto pair : attrs)
501 {
502 auto attr = pair.first;
503 auto value = pair.second;
504
505 if (attr == "name") {
506 n = value.ToWString();
507 }
508 else if (attr == "value") {
509 v = value.ToWString();
510 }
511 }
512
513 if (n == wxT("id3v2")) {
514 // LLL: This is obsolete, but it must be handled and ignored.
515 }
516 else {
517 SetTag(n, v);
518 }
519
520 return true;
521 }
522
523 return false;
524}
void SetTag(const wxString &name, const wxString &value, const bool bSpecialTag=false)
Definition: Tags.cpp:431

References SetTag(), and wxT().

Here is the call graph for this function:

◆ HasTag()

bool Tags::HasTag ( const wxString &  name) const

Definition at line 397 of file Tags.cpp.

398{
399 wxString key = name;
400 key.UpperCase();
401
402 auto iter = mXref.find(key);
403 return (iter != mXref.end());
404}

References key, mXref, and name.

Referenced by PCMExportProcessor::AddStrings(), FLACImportFileHandle::Import(), OggImportFileHandle::Import(), OpusImportFileHandle::Import(), PCMImportFileHandle::Import(), WavPackImportFileHandle::Import(), IsEmpty(), and FFmpegExporter::SetMetadata().

Here is the caller graph for this function:

◆ IsEmpty()

bool Tags::IsEmpty ( )

Definition at line 282 of file Tags.cpp.

283{
284 // At least one of these should be filled in, otherwise
285 // it's assumed that the tags have not been set...
287 return false;
288 }
289
290 return true;
291}
#define TAG_ALBUM
Definition: Tags.h:60
#define TAG_TITLE
Definition: Tags.h:58
#define TAG_ARTIST
Definition: Tags.h:59
bool HasTag(const wxString &name) const
Definition: Tags.cpp:397

References HasTag(), TAG_ALBUM, TAG_ARTIST, and TAG_TITLE.

Referenced by FFmpegImportFileHandle::WriteMetadata().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadDefaultGenres()

void Tags::LoadDefaultGenres ( )

Definition at line 338 of file Tags.cpp.

339{
340 mGenres.clear();
341 for (size_t i = 0; i < WXSIZEOF(DefaultGenres); i++) {
342 mGenres.push_back(DefaultGenres[i]);
343 }
344}

References DefaultGenres, and mGenres.

Referenced by LoadGenres().

Here is the caller graph for this function:

◆ LoadDefaults()

void Tags::LoadDefaults ( )

Definition at line 266 of file Tags.cpp.

267{
268 wxString value;
269 auto tagsGroup = gPrefs->BeginGroup("/Tags");
270 for(const auto& key : gPrefs->GetChildKeys())
271 {
272 gPrefs->Read(key, &value, {});
273 if(key == wxT("ID3V2")) {
274 // LLL: This is obsolute, but it must be handled and ignored.
275 }
276 else {
277 SetTag(key, value);
278 }
279 }
280}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
virtual wxArrayString GetChildKeys() const =0
Returns all child keys within the current group.
virtual bool Read(const wxString &key, bool *value) const =0

References audacity::BasicSettings::BeginGroup(), audacity::BasicSettings::GetChildKeys(), gPrefs, key, audacity::BasicSettings::Read(), SetTag(), and wxT().

Referenced by Tags(), ExportAudioDialog::UpdateLabelExportSettings(), and ExportAudioDialog::UpdateTrackExportSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadGenres()

void Tags::LoadGenres ( )

Definition at line 346 of file Tags.cpp.

347{
348 wxFileName fn(FileNames::DataDir(), wxT("genres.txt"));
349 wxTextFile tf(fn.GetFullPath());
350
351 if (!tf.Exists() || !tf.Open()) {
353 return;
354 }
355
356 mGenres.clear();
357
358 int cnt = tf.GetLineCount();
359 for (int i = 0; i < cnt; i++) {
360 mGenres.push_back(tf.GetLine(i));
361 }
362}
static const auto fn
void LoadDefaultGenres()
Definition: Tags.cpp:338
FILES_API FilePath DataDir()
Audacity user data directory.

References FileNames::DataDir(), fn, LoadDefaultGenres(), mGenres, and wxT().

Referenced by Tags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Merge()

void Tags::Merge ( const Tags other)

Definition at line 246 of file Tags.cpp.

247{
248 for ( auto &pair : other.mMap ) {
249 SetTag( pair.first, pair.second );
250 }
251}

References mMap, and SetTag().

Referenced by anonymous_namespace{ProjectFileManager.cpp}::ImportProject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

Tags & Tags::operator= ( const Tags src)

Definition at line 253 of file Tags.cpp.

254{
255 mXref.clear();
256 mXref = src.mXref;
257 mMap.clear();
258 mMap = src.mMap;
259
260 mGenres.clear();
261 mGenres = src.mGenres;
262
263 return *this;
264}

References mGenres, mMap, and mXref.

◆ RestoreUndoRedoState()

void Tags::RestoreUndoRedoState ( AudacityProject project)
overridevirtual

Modify the project when undoing or redoing to some state in history.

Implements UndoStateExtension.

Definition at line 569 of file Tags.cpp.

570{
571 // Restore tags
572 Tags::Set( project, shared_from_this() );
573}
static Tags & Set(AudacityProject &project, const std::shared_ptr< Tags > &tags)
Definition: Tags.cpp:224

References project, and Set().

Here is the call graph for this function:

◆ Set()

Tags & Tags::Set ( AudacityProject project,
const std::shared_ptr< Tags > &  tags 
)
static

Definition at line 224 of file Tags.cpp.

225{
226 auto &result = *tags;
227 project.AttachedObjects::Assign( key, tags );
228 return result;
229}

References key, and project.

Referenced by ProjectFileManager::DoImport(), TagsEditorDialog::EditProjectMetadata(), and RestoreUndoRedoState().

Here is the caller graph for this function:

◆ SetTag() [1/2]

void Tags::SetTag ( const wxString &  name,
const int &  value 
)

Definition at line 486 of file Tags.cpp.

487{
488 SetTag(name, wxString::Format(wxT("%d"), value));
489}

References name, SetTag(), and wxT().

Here is the call graph for this function:

◆ SetTag() [2/2]

void Tags::SetTag ( const wxString &  name,
const wxString &  value,
const bool  bSpecialTag = false 
)

Definition at line 431 of file Tags.cpp.

432{
433 // We don't like empty names
434 if (name.empty()) {
435 return;
436 }
437
438 // Tag name must be ascii
439 if (!name.IsAscii()) {
440 wxLogError("Tag rejected (Non-ascii character in name)");
441 return;
442 }
443
444 // All keys are uppercase
445 wxString key = name;
446 key.UpperCase();
447
448 // Look it up
449 TagMap::iterator iter = mXref.find(key);
450
451 // The special tags, if empty, should not exist.
452 // However it is allowable for a custom tag to be empty.
453 // See Bug 440 and Bug 1382
454 if (value.empty() && bSpecialTag) {
455 // Erase the tag
456 if (iter == mXref.end())
457 // nothing to do
458 ;
459 else {
460 mMap.erase(iter->second);
461 mXref.erase(iter);
462 }
463 }
464 else
465 {
466 if (iter == mXref.end()) {
467 // Didn't find the tag
468
469 // Add a NEW tag
470 mXref[key] = name;
471 mMap[name] = value;
472 }
473 else if (iter->second != name) {
474 // Watch out for case differences!
475 mMap[name] = value;
476 mMap.erase(iter->second);
477 iter->second = name;
478 }
479 else {
480 // Update the value
481 mMap[iter->second] = value;
482 }
483 }
484}

References key, mMap, mXref, and name.

Referenced by FFmpegImportFileHandle::GetMetadata(), AUPImportFileHandle::HandleTag(), AUPImportFileHandle::HandleTags(), HandleXMLTag(), FLACImportFileHandle::Import(), OggImportFileHandle::Import(), OpusImportFileHandle::Import(), PCMImportFileHandle::Import(), WavPackImportFileHandle::Import(), LoadDefaults(), Merge(), TagsEditorDialog::OnLoad(), anonymous_namespace{ImportMP3_MPG123.cpp}::MP3ImportFileHandle::ReadTags(), SetTag(), ExportAudioDialog::UpdateLabelExportSettings(), and ExportAudioDialog::UpdateTrackExportSettings().

Here is the caller graph for this function:

◆ WriteXML()

void Tags::WriteXML ( XMLWriter xmlFile) const

Definition at line 539 of file Tags.cpp.

541{
542 xmlFile.StartTag(wxT("tags"));
543
544 for (const auto &pair : GetRange()) {
545 const auto &n = pair.first;
546 const auto &v = pair.second;
547 xmlFile.StartTag(wxT("tag"));
548 xmlFile.WriteAttr(wxT("name"), n);
549 xmlFile.WriteAttr(wxT("value"), v);
550 xmlFile.EndTag(wxT("tag"));
551 }
552
553 xmlFile.EndTag(wxT("tags"));
554}
Iterators GetRange() const
Definition: Tags.cpp:426
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References wxT().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator==

TAGS_API bool operator== ( const Tags lhs,
const Tags rhs 
)
friend

Definition at line 322 of file Tags.cpp.

323{
324 if (!EqualMaps(lhs.mXref, rhs.mXref))
325 return false;
326
327 if (!EqualMaps(lhs.mMap, rhs.mMap))
328 return false;
329
330 return lhs.mGenres == rhs.mGenres;
331}
bool EqualMaps(const TagMap &map1, const TagMap &map2)
Definition: Tags.cpp:305

Member Data Documentation

◆ mGenres

wxArrayString Tags::mGenres
private

Definition at line 132 of file Tags.h.

Referenced by GetNumUserGenres(), GetUserGenre(), LoadDefaultGenres(), LoadGenres(), and operator=().

◆ mMap

TagMap Tags::mMap
private

Definition at line 130 of file Tags.h.

Referenced by Clear(), Count(), GetRange(), GetTag(), Merge(), operator=(), and SetTag().

◆ mXref

TagMap Tags::mXref
private

Definition at line 129 of file Tags.h.

Referenced by Clear(), GetTag(), HasTag(), operator=(), and SetTag().


The documentation for this class was generated from the following files: