Audacity 3.2.0
Tags.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Tags.h
6
7 Dominic Mazzoni
8
9 This class holds a few informational tags, such as Title, Author,
10 etc. that can be associated with a project or other audio file.
11 It is modeled after the ID3 format for MP3 files, and it can
12 both import ID3 tags from MP3 files, and export them as well.
13
14 It can present the user with a dialog for editing this information.
15
16 It only keeps track of the fields that are standard in ID3v1
17 (title, author, artist, track num, year, genre, and comments),
18 but it can export both ID3v1 or the newer ID3v2 format. The primary
19 reason you would want to export ID3v2 tags instead of ID3v1,
20 since we're not supporting any v2 fields, is that ID3v2 tags are
21 inserted at the BEGINNING of an mp3 file, which is far more
22 useful for streaming.
23
24 Use of this functionality requires that libid3tag be compiled in
25 with Audacity.
26
27**********************************************************************/
28
29#ifndef __AUDACITY_TAGS__
30#define __AUDACITY_TAGS__
31
32
33
34#include "XMLTagHandler.h"
35
36#include "ClientData.h"
37#include "UndoManager.h" // To inherit UndoStateExtension
38#include <utility>
39
40#include <memory>
41#include <unordered_map>
42#include "Identifier.h"
43
44class wxArrayString;
45class wxComboBox;
46class wxGridCellChoiceEditor;
47class wxGridCellStringRenderer;
48class wxGridEvent;
49class wxTextCtrl;
50
51class AudacityProject;
52class Grid;
53class ShuttleGui;
54class ComboEditor;
55
56using TagMap = std::unordered_map< wxString, wxString >;
57
58#define TAG_TITLE wxT("TITLE")
59#define TAG_ARTIST wxT("ARTIST")
60#define TAG_ALBUM wxT("ALBUM")
61#define TAG_TRACK wxT("TRACKNUMBER")
62#define TAG_YEAR wxT("YEAR")
63#define TAG_GENRE wxT("GENRE")
64#define TAG_COMMENTS wxT("COMMENTS")
65#define TAG_SOFTWARE wxT("Software")
66#define TAG_COPYRIGHT wxT("Copyright")
67
68class AUDACITY_DLL_API Tags final
69 : public XMLTagHandler
70 , public std::enable_shared_from_this< Tags >
71 , public ClientData::Base
72 , public UndoStateExtension
73{
74
75 public:
76
77 static Tags &Get( AudacityProject &project );
78 static const Tags &Get( const AudacityProject &project );
79 // Returns reference to *tags
80 static Tags &Set(
81 AudacityProject &project, const std::shared_ptr<Tags> &tags );
82
83 Tags(); // constructor
84 Tags( const Tags& ) = default;
85 //Tags( Tags && ) = default;
86 virtual ~Tags();
87
88 std::shared_ptr<Tags> Duplicate() const;
89
90 void Merge( const Tags &other );
91
92 Tags & operator= (const Tags & src );
93
94 bool HandleXMLTag(const std::string_view& tag, const AttributesList &attrs) override;
95 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
96 void WriteXML(XMLWriter &xmlFile) const /* not override */;
97
98 void LoadDefaultGenres();
99 void LoadGenres();
100
101 void LoadDefaults();
102
103 int GetNumUserGenres();
104 wxString GetUserGenre(int value);
105
106 wxString GetGenre(int value);
107 int GetGenre(const wxString & name);
108
109 bool HasTag(const wxString & name) const;
110 wxString GetTag(const wxString & name) const;
111
113 Iterators GetRange() const;
114
115 void SetTag(const wxString & name, const wxString & value, const bool bSpecialTag=false);
116 void SetTag(const wxString & name, const int & value);
117
118 bool IsEmpty();
119 void Clear();
120
121 // UndoStateExtension implementation
122 void RestoreUndoRedoState(AudacityProject &) override;
123
124 friend bool operator == (const Tags &lhs, const Tags &rhs);
125
126 private:
129
130 wxArrayString mGenres;
131};
132
133inline bool operator != (const Tags &lhs, const Tags &rhs)
134{ return !(lhs == rhs); }
135
136#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
const TranslatableString name
Definition: Distortion.cpp:82
bool operator==(const Tags &lhs, const Tags &rhs)
Definition: Tags.cpp:332
std::unordered_map< wxString, wxString > TagMap
Definition: Tags.h:56
bool operator!=(const Tags &lhs, const Tags &rhs)
Definition: Tags.h:133
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:185
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
ID3 Tags (for MP3)
Definition: Tags.h:73
TagMap mXref
Definition: Tags.h:127
TagMap mMap
Definition: Tags.h:128
Tags(const Tags &)=default
wxArrayString mGenres
Definition: Tags.h:130
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:91
virtual void RestoreUndoRedoState(AudacityProject &)=0
Modify the project when undoing or redoing to some state in history.
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
virtual XMLTagHandler * HandleXMLChild(const std::string_view &tag)=0
virtual bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs)=0
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
A convenient default parameter for class template Site.
Definition: ClientData.h:28
A convenience for use with range-for.
Definition: MemoryX.h:252