Audacity 3.2.0
PlainExportOptionsEditor.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 PlainExportOptionsEditor.cpp
6
7 Vitaly Sverchinsky
8
9**********************************************************************/
10
12#include <wx/config.h>
13
14#include "BasicSettings.h"
15
16PlainExportOptionsEditor::PlainExportOptionsEditor(std::initializer_list<OptionDesc> options,
17 Listener* listener)
18 : mOptionsListener(listener)
19{
20 InitOptions(options);
21}
22
23PlainExportOptionsEditor::PlainExportOptionsEditor(std::initializer_list<OptionDesc> options,
24 SampleRateList sampleRates,
25 Listener* listener)
26 : mRates(std::move(sampleRates))
27 , mOptionsListener(listener)
28{
29 InitOptions(options);
30}
31
33{
34 return static_cast<int>(mOptions.size());
35}
36
38{
39 if(index >= 0 && index < static_cast<int>(mOptions.size()))
40 {
41 option = mOptions[index];
42 return true;
43 }
44 return false;
45}
46
48{
49 const auto it = mValues.find(id);
50 if(it != mValues.end())
51 {
52 value = it->second;
53 return true;
54 }
55 return false;
56}
57
59{
60 const auto it = mValues.find(id);
61 if(it != mValues.end() && it->second.index() == value.index())
62 {
63 it->second = value;
64 return true;
65 }
66 return false;
67}
68
70{
71 auto index = 0;
72 for(const auto& option : mOptions)
73 {
74 auto it = mValues.find(option.id);
75 assert(it != mValues.end());
76 if(auto val = std::get_if<bool>(&it->second))
77 config.Read(mConfigKeys[index], val);
78 else if(auto val = std::get_if<int>(&it->second))
79 config.Read(mConfigKeys[index], val);
80 else if(auto val = std::get_if<double>(&it->second))
81 config.Read(mConfigKeys[index], val);
82 else if(auto val = std::get_if<std::string>(&it->second))
83 {
84 wxString wxstr;
85 if(config.Read(mConfigKeys[index], &wxstr))
86 *val = wxstr.ToStdString();
87 }
88 ++index;
89 }
90}
91
93{
94 auto index = 0;
95 for(const auto& option : mOptions)
96 {
97 auto it = mValues.find(option.id);
98 assert(it != mValues.end());
99 if(auto val = std::get_if<bool>(&it->second))
100 config.Write(mConfigKeys[index], *val);
101 else if(auto val = std::get_if<int>(&it->second))
102 config.Write(mConfigKeys[index], *val);
103 else if(auto val = std::get_if<double>(&it->second))
104 config.Write(mConfigKeys[index], *val);
105 else if(auto val = std::get_if<std::string>(&it->second))
106 config.Write(mConfigKeys[index], wxString(*val));
107
108 ++index;
109 }
110}
111
113{
114 return mRates;
115}
116
118{
119 mRates = std::move(rates);
122}
123
124void PlainExportOptionsEditor::InitOptions(std::initializer_list<OptionDesc> options)
125{
126 assert(mOptions.empty());
127
128 mOptions.reserve(options.size());
129 mValues.reserve(options.size());
130 for(auto& desc : options)
131 {
132 mValues[desc.option.id] = desc.option.defaultValue;
133 mOptions.emplace_back(desc.option);
134 mConfigKeys.push_back(desc.configKey);
135 }
136}
137
std::variant< bool, int, double, std::string > ExportValue
A type of option values (parameters) used by exporting plugins.
Definition: ExportTypes.h:38
Listener object that is used to report on option changes.
virtual void OnSampleRateListChange()=0
std::vector< int > SampleRateList
std::vector< ExportOption > mOptions
std::unordered_map< int, ExportValue > mValues
void InitOptions(std::initializer_list< OptionDesc > options)
PlainExportOptionsEditor(std::initializer_list< OptionDesc > options, Listener *listener=nullptr)
void Load(const audacity::BasicSettings &config) override
void SetSampleRateList(SampleRateList rates)
bool GetValue(int id, ExportValue &value) const override
void Store(audacity::BasicSettings &) const override
SampleRateList GetSampleRateList() const override
bool GetOption(int index, ExportOption &option) const override
int GetOptionsCount() const override
bool SetValue(int id, const ExportValue &value) override
Base class for objects that provide facility to store data persistently, and access it with string ke...
Definition: BasicSettings.h:31
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
const TranslatableString desc
Definition: ExportPCM.cpp:51
STL namespace.
A type that provides a description of an exporting option. Isn't allowed to change except non-type re...
Definition: ExportTypes.h:43