23#define EQCURVES_VERSION 1
24#define EQCURVES_REVISION 0
29 wxString base =
wxT(
"/Effects/Equalization/");
31 base =
wxT(
"/Effects/GraphicEq/");
33 base =
wxT(
"/Effects/FilterCurve/");
59 if(fileName.empty()) {
62 wxString eqCurvesInstalledVersion;
65 bool needUpdate = (eqCurvesCurrentVersion != eqCurvesInstalledVersion);
95 const wxString fullPath{
fn.GetFullPath() };
96 if( !reader.
Parse(
this, fullPath ) )
99 auto msg =
XO(
"Error Loading EQ Curves from file:\n%s\nError message says:\n%s")
109 int numCurves =
mCurves.size();
112 for( curve = 0; curve < numCurves-1; curve++ )
114 if(
mCurves[curve].Name ==
_(
"unnamed") )
123 if(
mCurves.back().Name !=
_(
"unnamed") )
141 wxString unnamed =
wxT(
"unnamed");
152 wxLogDebug(
wxT(
"Attempting to load EQDefaultCurves.xml from %s"),
fn.GetFullPath());
155 if(!reader.
Parse(
this,
fn.GetFullPath())) {
156 wxLogError(
wxT(
"EQDefaultCurves.xml could not be read."));
160 wxLogDebug(
wxT(
"Loading EQDefaultCurves.xml successful."));
167 if (defaultCurves.back().Name == unnamed) {
168 defaultCurves.pop_back();
171 wxLogError(
wxT(
"Error in EQDefaultCurves.xml"));
174 int numUserCurves = userCurves.size();
175 int numDefaultCurves = defaultCurves.size();
184 for (
int curveCount = 0; curveCount < numUserCurves; curveCount++) {
185 bool isCustom =
true;
186 tempCurve = userCurves[curveCount];
188 for (
int defCurveCount = 0; defCurveCount < numDefaultCurves; defCurveCount++) {
189 if (tempCurve.
Name ==
mCurves[defCurveCount].Name) {
202 for (
int defCurveCount = 0; defCurveCount < numDefaultCurves; defCurveCount++) {
203 bool isUserCurve =
false;
205 for (
int userCurveCount = 0; userCurveCount < numUserCurves; userCurveCount++) {
206 if (userCurves[userCurveCount].Name == defaultCurves[defCurveCount].Name) {
208 mCurves.push_back(userCurves[userCurveCount]);
213 mCurves.push_back(defaultCurves[defCurveCount]);
218 for (
int userCurveCount = 0; userCurveCount < numUserCurves; userCurveCount++) {
219 bool isDefaultCurve =
false;
220 tempCurve = userCurves[userCurveCount];
221 for (
int defCurveCount = 0; defCurveCount < numDefaultCurves; defCurveCount++) {
222 if (tempCurve.
Name == defaultCurves[defCurveCount].Name) {
223 isDefaultCurve =
true;
227 if (!isDefaultCurve) {
232 defaultCurves.clear();
236 if(userUnnamed.
Name == unnamed) {
237 mCurves.push_back( userUnnamed );
258 if( !fileName.FileExists() )
263 if( !fileName.FileExists() )
275 return (fileName.FileExists());
285 if( fileName.empty() )
296 if( !
fn.DirExists() )
299 if( !
fn.Mkdir(
fn.GetPath(), 511, wxPATH_MKDIR_FULL ) )
311 const wxString fullPath{
fn.GetFullPath() };
312 XMLFileWriter eqFile{ fullPath,
XO(
"Error Saving Equalization Curves") };
328 if (tag ==
"equalizationeffect")
337 for (
auto pair : attrs)
339 auto attr = pair.first;
340 auto value = pair.second;
345 const wxString strValue = value.ToWString();
348 wxString strValueTemp = strValue;
353 for(
size_t i = 0; i <
mCurves.size(); i++)
356 strValueTemp.Printf(
wxT(
"%s (%d)"),strValue,n);
357 if(
mCurves[i].Name == strValueTemp)
365 while(exists ==
true);
384 for (
auto pair : attrs)
386 auto attr = pair.first;
387 auto value = pair.second;
392 if (!value.TryGet(dblValue))
397 else if( attr ==
"d" )
399 if (!value.TryGet(dblValue))
421 if (tag ==
"equalizationeffect")
446 xmlFile.StartTag(
wxT(
"equalizationeffect" ) );
449 int numCurves = mCurves.size();
451 for( curve = 0; curve < numCurves; curve++ )
454 xmlFile.StartTag(
wxT(
"curve" ) );
455 xmlFile.WriteAttr(
wxT(
"name" ), mCurves[ curve ].Name );
458 int numPoints = mCurves[ curve ].points.size();
460 for( point = 0; point < numPoints; point++ )
463 xmlFile.StartTag(
wxT(
"point" ) );
464 xmlFile.WriteAttr(
wxT(
"f" ), mCurves[ curve ].points[ point ].Freq, 12 );
465 xmlFile.WriteAttr(
wxT(
"d" ), mCurves[ curve ].points[ point ].dB, 12 );
466 xmlFile.EndTag(
wxT(
"point" ) );
470 xmlFile.EndTag(
wxT(
"curve" ) );
474 xmlFile.EndTag(
wxT(
"equalizationeffect" ) );
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), F3 delayedHandler=DefaultDelayedHandlerAction) noexcept(noexcept(handler(std::declval< AudacityException * >())) &&noexcept(handler(nullptr)) &&noexcept(std::function< void(AudacityException *)>{std::move(delayedHandler)}))
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
#define EQCURVES_REVISION
std::vector< EQCurve > EQCurveArray
const int kEqOptionGraphic
audacity::BasicSettings * gPrefs
std::vector< Attribute > AttributesList
std::vector< EQPoint > points
wxString GetPrefsPrefix()
bool GetDefaultFileName(wxFileName &fileName)
void UpdateDefaultCurves(bool updateAll=false)
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
void LoadCurves(const wxString &fileName={}, bool append=false)
Serializer of curves into XML files.
void SaveCurves(const wxString &fileName={})
void WriteXML(XMLWriter &xmlFile) const
Reads a file and passes the results through an XMLTagHandler.
const TranslatableString & GetErrorStr() const
bool Parse(XMLTagHandler *baseHandler, const FilePath &fname)
Wrapper to output XML data to files.
This class is an interface which should be implemented by classes which wish to be able to load and s...
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
FILES_API FilePath ResourcesDir()
FILES_API FilePath DataDir()
Audacity user data directory.
void append(std::basic_string< Elem > &dest, First &&first, Others &&...others)
MessageBoxOptions && IconStyle(Icon style) &&