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 TAGS_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 size_t Count() const;
122
123 // UndoStateExtension implementation
124 void RestoreUndoRedoState(AudacityProject &) override;
125
126 friend TAGS_API bool operator == (const Tags &lhs, const Tags &rhs);
127
128 private:
131
132 wxArrayString mGenres;
133};
134
135inline bool operator != (const Tags &lhs, const Tags &rhs)
136{ return !(lhs == rhs); }
137
138#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
std::unordered_map< wxString, wxString > TagMap
Definition: Tags.h:56
bool operator!=(const Tags &lhs, const Tags &rhs)
Definition: Tags.h:135
wxString name
Definition: TagsEditor.cpp:166
const auto project
bool operator==(const WaveTrackLocation &a, const WaveTrackLocation &b)
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:90
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:190
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
ID3 Tags (for MP3)
Definition: Tags.h:73
TagMap mXref
Definition: Tags.h:129
TagMap mMap
Definition: Tags.h:130
Tags(const Tags &)=default
wxArrayString mGenres
Definition: Tags.h:132
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:83
virtual void RestoreUndoRedoState(AudacityProject &project)=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:25
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Definition: PackedArray.h:143
std::vector< std::vector< float > > Duplicate(const std::vector< float > &audio, size_t numChannels)
A convenient default parameter for class template Site.
Definition: ClientData.h:29
A convenience for use with range-for.
Definition: IteratorX.h:39