forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTags.h
206 lines (145 loc) · 5.17 KB
/
Tags.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**********************************************************************
Sneedacity: A Digital Audio Editor
Tags.h
Dominic Mazzoni
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 ID3 tags from MP3 files, and export them as well.
It can present the user with a dialog for editing this information.
It only keeps track of the fields that are standard in ID3v1
(title, author, artist, track num, year, genre, and comments),
but it can export both ID3v1 or the newer ID3v2 format. The primary
reason you would want to export ID3v2 tags instead of ID3v1,
since we're not supporting any v2 fields, is that ID3v2 tags are
inserted at the BEGINNING of an mp3 file, which is far more
useful for streaming.
Use of this functionality requires that libid3tag be compiled in
with Sneedacity.
**********************************************************************/
#ifndef __SNEEDACITY_TAGS__
#define __SNEEDACITY_TAGS__
#include "xml/XMLTagHandler.h"
#include "ClientData.h"
#include <utility>
#include "widgets/wxPanelWrapper.h" // to inherit
#include <memory>
#include <unordered_map>
#include "Identifier.h"
class wxArrayString;
class wxComboBox;
class wxGridCellChoiceEditor;
class wxGridCellStringRenderer;
class wxGridEvent;
class wxTextCtrl;
class SneedacityProject;
class Grid;
class ShuttleGui;
class TagsEditorDialog;
class ComboEditor;
using TagMap = std::unordered_map< wxString, wxString >;
#define TAG_TITLE wxT("TITLE")
#define TAG_ARTIST wxT("ARTIST")
#define TAG_ALBUM wxT("ALBUM")
#define TAG_TRACK wxT("TRACKNUMBER")
#define TAG_YEAR wxT("YEAR")
#define TAG_GENRE wxT("GENRE")
#define TAG_COMMENTS wxT("COMMENTS")
#define TAG_SOFTWARE wxT("Software")
#define TAG_COPYRIGHT wxT("Copyright")
class SNEEDACITY_DLL_API Tags final
: public XMLTagHandler
, public std::enable_shared_from_this< Tags >
, public ClientData::Base
{
public:
static Tags &Get( SneedacityProject &project );
static const Tags &Get( const SneedacityProject &project );
// Returns reference to *tags
static Tags &Set(
SneedacityProject &project, const std::shared_ptr<Tags> &tags );
Tags(); // constructor
Tags( const Tags& ) = default;
//Tags( Tags && ) = default;
virtual ~Tags();
std::shared_ptr<Tags> Duplicate() const;
void Merge( const Tags &other );
Tags & operator= (const Tags & src );
bool ShowEditDialog(
wxWindow *parent, const TranslatableString &title, bool force = false);
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
void WriteXML(XMLWriter &xmlFile) const /* not override */;
void AllowEditTitle(bool editTitle);
void AllowEditTrackNumber(bool editTrackNumber);
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;
using Iterators = IteratorRange<TagMap::const_iterator>;
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();
friend bool operator == (const Tags &lhs, const Tags &rhs);
private:
TagMap mXref;
TagMap mMap;
wxArrayString mGenres;
bool mEditTitle;
bool mEditTrackNumber;
};
inline bool operator != (const Tags &lhs, const Tags &rhs)
{ return !(lhs == rhs); }
class TagsEditorDialog final : public wxDialogWrapper
{
public:
// constructors and destructors
TagsEditorDialog(wxWindow * parent,
const TranslatableString &title,
Tags * tags,
bool editTitle,
bool editTrack);
virtual ~TagsEditorDialog();
#if !defined(__WXMSW__)
bool IsEscapeKey(const wxKeyEvent& /*event*/) override { return false; }
#endif
void PopulateOrExchange(ShuttleGui & S);
void OnDontShow( wxCommandEvent & Evt);
void OnHelp(wxCommandEvent & Evt);
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private:
void PopulateGenres();
void SetEditors();
void OnChange(wxGridEvent & event);
void OnEdit(wxCommandEvent & event);
void OnReset(wxCommandEvent & event);
void OnClear(wxCommandEvent & event);
void OnLoad(wxCommandEvent & event);
void OnSave(wxCommandEvent & event);
void OnSaveDefaults(wxCommandEvent & event);
void OnAdd(wxCommandEvent & event);
void OnRemove(wxCommandEvent & event);
void OnOk(wxCommandEvent & event);
void DoCancel(bool escKey);
void OnCancel(wxCommandEvent & event);
void OnKeyDown(wxKeyEvent &event);
bool IsWindowRectValid(const wxRect *windowRect) const;
private:
Tags *mTags;
bool mEditTitle;
bool mEditTrack;
Tags mLocal;
Grid *mGrid;
ComboEditor *mComboEditor;
wxGridCellStringRenderer *mStringRenderer;
DECLARE_EVENT_TABLE()
};
#endif