mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 17:18:41 +02:00
Don't use an internal iterator in Tags
This commit is contained in:
parent
a1c7b396b3
commit
ffe9989f7c
41
src/Tags.cpp
41
src/Tags.cpp
@ -394,30 +394,9 @@ wxString Tags::GetTag(const wxString & name)
|
|||||||
return mMap[iter->second];
|
return mMap[iter->second];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tags::GetFirst(wxString & name, wxString & value)
|
Tags::Iterators Tags::GetRange() const
|
||||||
{
|
{
|
||||||
mIter = mMap.begin();
|
return std::make_pair(mMap.begin(), mMap.end());
|
||||||
if (mIter == mMap.end()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = mIter->first;
|
|
||||||
value = mIter->second;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Tags::GetNext(wxString & name, wxString & value)
|
|
||||||
{
|
|
||||||
++mIter;
|
|
||||||
if (mIter == mMap.end()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = mIter->first;
|
|
||||||
value = mIter->second;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tags::SetTag(const wxString & name, const wxString & value)
|
void Tags::SetTag(const wxString & name, const wxString & value)
|
||||||
@ -510,8 +489,9 @@ void Tags::WriteXML(XMLWriter &xmlFile)
|
|||||||
{
|
{
|
||||||
xmlFile.StartTag(wxT("tags"));
|
xmlFile.StartTag(wxT("tags"));
|
||||||
|
|
||||||
wxString n, v;
|
for (const auto &pair : GetRange()) {
|
||||||
for (bool cont = GetFirst(n, v); cont; cont = GetNext(n, v)) {
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
xmlFile.StartTag(wxT("tag"));
|
xmlFile.StartTag(wxT("tag"));
|
||||||
xmlFile.WriteAttr(wxT("name"), n);
|
xmlFile.WriteAttr(wxT("name"), n);
|
||||||
xmlFile.WriteAttr(wxT("value"), v);
|
xmlFile.WriteAttr(wxT("value"), v);
|
||||||
@ -863,8 +843,6 @@ bool TagsEditor::TransferDataFromWindow()
|
|||||||
bool TagsEditor::TransferDataToWindow()
|
bool TagsEditor::TransferDataToWindow()
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
wxString n;
|
|
||||||
wxString v;
|
|
||||||
TagMap popTagMap;
|
TagMap popTagMap;
|
||||||
|
|
||||||
// Disable redrawing until we're done
|
// Disable redrawing until we're done
|
||||||
@ -895,7 +873,9 @@ bool TagsEditor::TransferDataToWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate the rest
|
// Populate the rest
|
||||||
for (bool cont = mLocal.GetFirst(n, v); cont; cont = mLocal.GetNext(n, v)) {
|
for (const auto &pair : mLocal.GetRange()) {
|
||||||
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
if (popTagMap.find(n) == popTagMap.end()) {
|
if (popTagMap.find(n) == popTagMap.end()) {
|
||||||
mGrid->AppendRows();
|
mGrid->AppendRows();
|
||||||
mGrid->SetCellValue(i, 0, n);
|
mGrid->SetCellValue(i, 0, n);
|
||||||
@ -1186,8 +1166,9 @@ void TagsEditor::OnSaveDefaults(wxCommandEvent & WXUNUSED(event))
|
|||||||
gPrefs->DeleteGroup(wxT("/Tags"));
|
gPrefs->DeleteGroup(wxT("/Tags"));
|
||||||
|
|
||||||
// Write out each tag
|
// Write out each tag
|
||||||
wxString n, v;
|
for (const auto &pair : mLocal.GetRange()) {
|
||||||
for (bool cont = mLocal.GetFirst(n, v); cont; cont = mLocal.GetNext(n, v)) {
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
gPrefs->Write(wxT("/Tags/") + n, v);
|
gPrefs->Write(wxT("/Tags/") + n, v);
|
||||||
}
|
}
|
||||||
gPrefs->Flush();
|
gPrefs->Flush();
|
||||||
|
12
src/Tags.h
12
src/Tags.h
@ -33,6 +33,7 @@
|
|||||||
#include "widgets/Grid.h"
|
#include "widgets/Grid.h"
|
||||||
#include "xml/XMLTagHandler.h"
|
#include "xml/XMLTagHandler.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
#include <wx/hashmap.h>
|
#include <wx/hashmap.h>
|
||||||
#include <wx/notebook.h>
|
#include <wx/notebook.h>
|
||||||
@ -99,8 +100,14 @@ class AUDACITY_DLL_API Tags: public XMLTagHandler {
|
|||||||
bool HasTag(const wxString & name);
|
bool HasTag(const wxString & name);
|
||||||
wxString GetTag(const wxString & name);
|
wxString GetTag(const wxString & name);
|
||||||
|
|
||||||
bool GetFirst(wxString & name, wxString & value);
|
using IterPair = std::pair<TagMap::const_iterator, TagMap::const_iterator>;
|
||||||
bool GetNext(wxString & name, wxString & value);
|
struct Iterators : public IterPair {
|
||||||
|
Iterators(IterPair p) : IterPair(p) {}
|
||||||
|
// Define begin() and end() for convenience in range-for
|
||||||
|
auto begin() -> decltype(first) const { return first; }
|
||||||
|
auto end() -> decltype(second) const { return second; }
|
||||||
|
};
|
||||||
|
Iterators GetRange() const;
|
||||||
|
|
||||||
void SetTag(const wxString & name, const wxString & value);
|
void SetTag(const wxString & name, const wxString & value);
|
||||||
void SetTag(const wxString & name, const int & value);
|
void SetTag(const wxString & name, const int & value);
|
||||||
@ -111,7 +118,6 @@ class AUDACITY_DLL_API Tags: public XMLTagHandler {
|
|||||||
private:
|
private:
|
||||||
void LoadDefaults();
|
void LoadDefaults();
|
||||||
|
|
||||||
TagMap::iterator mIter;
|
|
||||||
TagMap mXref;
|
TagMap mXref;
|
||||||
TagMap mMap;
|
TagMap mMap;
|
||||||
|
|
||||||
|
@ -388,8 +388,10 @@ bool ExportFLAC::GetMetadata(AudacityProject *project, Tags *tags)
|
|||||||
|
|
||||||
mMetadata = ::FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
mMetadata = ::FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
||||||
|
|
||||||
wxString n, v;
|
wxString n;
|
||||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
for (const auto &pair : tags->GetRange()) {
|
||||||
|
n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
if (n == TAG_YEAR) {
|
if (n == TAG_YEAR) {
|
||||||
n = wxT("DATE");
|
n = wxT("DATE");
|
||||||
}
|
}
|
||||||
|
@ -344,8 +344,9 @@ int ExportMP2::AddTags(AudacityProject * WXUNUSED(project), char **buffer, bool
|
|||||||
#ifdef USE_LIBID3TAG
|
#ifdef USE_LIBID3TAG
|
||||||
struct id3_tag *tp = id3_tag_new();
|
struct id3_tag *tp = id3_tag_new();
|
||||||
|
|
||||||
wxString n, v;
|
for (const auto &pair : tags->GetRange()) {
|
||||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
const char *name = "TXXX";
|
const char *name = "TXXX";
|
||||||
|
|
||||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||||
|
@ -1970,8 +1970,9 @@ int ExportMP3::AddTags(AudacityProject *WXUNUSED(project), char **buffer, bool *
|
|||||||
#ifdef USE_LIBID3TAG
|
#ifdef USE_LIBID3TAG
|
||||||
struct id3_tag *tp = id3_tag_new();
|
struct id3_tag *tp = id3_tag_new();
|
||||||
|
|
||||||
wxString n, v;
|
for (const auto &pair : tags->GetRange()) {
|
||||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
const char *name = "TXXX";
|
const char *name = "TXXX";
|
||||||
|
|
||||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||||
|
@ -349,8 +349,10 @@ bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, T
|
|||||||
|
|
||||||
vorbis_comment_init(comment);
|
vorbis_comment_init(comment);
|
||||||
|
|
||||||
wxString n, v;
|
wxString n;
|
||||||
for (bool cont = metadata->GetFirst(n, v); cont; cont = metadata->GetNext(n, v)) {
|
for (const auto &pair : metadata->GetRange()) {
|
||||||
|
n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
if (n == TAG_YEAR) {
|
if (n == TAG_YEAR) {
|
||||||
n = wxT("DATE");
|
n = wxT("DATE");
|
||||||
}
|
}
|
||||||
|
@ -746,8 +746,9 @@ void ExportPCM::AddID3Chunk(wxString fName, Tags *tags, int sf_format)
|
|||||||
#ifdef USE_LIBID3TAG
|
#ifdef USE_LIBID3TAG
|
||||||
struct id3_tag *tp = id3_tag_new();
|
struct id3_tag *tp = id3_tag_new();
|
||||||
|
|
||||||
wxString n, v;
|
for (const auto &pair : tags->GetRange()) {
|
||||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
const auto &n = pair.first;
|
||||||
|
const auto &v = pair.second;
|
||||||
const char *name = "TXXX";
|
const char *name = "TXXX";
|
||||||
|
|
||||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user