Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ExportOptionsHandler Class Referencefinal

#include <ExportOptionsHandler.h>

Inheritance diagram for ExportOptionsHandler:
[legend]
Collaboration diagram for ExportOptionsHandler:
[legend]

Public Member Functions

 ExportOptionsHandler (ShuttleGui &S, const ExportPlugin &plugin, int format)
 
 ~ExportOptionsHandler ()
 
bool TransferDataFromEditor ()
 
ExportProcessor::Parameters GetParameters () const
 
void SetParameters (const ExportProcessor::Parameters &parameters)
 
ExportOptionsEditor::SampleRateList GetSampleRateList () const
 
void OnExportOptionChangeBegin () override
 Called before OnExportOptionChange More...
 
void OnExportOptionChangeEnd () override
 Called after OnExportOptionChange More...
 
void OnExportOptionChange (const ExportOption &option) override
 Called when option change. More...
 
void OnFormatInfoChange () override
 Called when format extension change (usually in response parameter change) More...
 
void OnSampleRateListChange () override
 
- Public Member Functions inherited from ExportOptionsEditor::Listener
virtual ~Listener ()
 
virtual void OnExportOptionChangeBegin ()=0
 Called before OnExportOptionChange More...
 
virtual void OnExportOptionChangeEnd ()=0
 Called after OnExportOptionChange More...
 
virtual void OnExportOptionChange (const ExportOption &option)=0
 Called when option change. More...
 
virtual void OnFormatInfoChange ()=0
 Called when format extension change (usually in response parameter change) More...
 
virtual void OnSampleRateListChange ()=0
 
- Public Member Functions inherited from Observer::Publisher< ExportOptionsHandlerEvent >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Private Member Functions

void PopulateEmpty (ShuttleGui &S)
 
void PopulateOptions (ShuttleGui &S)
 
void UpdateSampleRateList ()
 

Private Attributes

wxWindow * mParent { nullptr }
 
std::unique_ptr< wxWindowUpdateLocker > mUpdateLocker
 
std::unique_ptr< ExportOptionsEditormEditor
 
std::vector< std::tuple< wxStaticText *, wxControl * > > mRows
 
std::unordered_map< int, int > mIDRowIndexMap
 

Additional Inherited Members

- Public Types inherited from Observer::Publisher< ExportOptionsHandlerEvent >
using message_type = ExportOptionsHandlerEvent
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const ExportOptionsHandlerEvent &) >
 Type of functions that can be connected to the Publisher. More...
 
- Static Public Attributes inherited from Observer::Publisher< ExportOptionsHandlerEvent >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from Observer::Publisher< ExportOptionsHandlerEvent >
CallbackReturn Publish (const ExportOptionsHandlerEvent &message)
 Send a message to connected callbacks. More...
 

Detailed Description

Definition at line 38 of file ExportOptionsHandler.h.

Constructor & Destructor Documentation

◆ ExportOptionsHandler()

ExportOptionsHandler::ExportOptionsHandler ( ShuttleGui S,
const ExportPlugin plugin,
int  format 
)

Definition at line 33 of file ExportOptionsHandler.cpp.

34{
35 mParent = S.GetParent();
36
37 mEditor = plugin.CreateOptionsEditor(format, this);
38 if(mEditor)
39 {
40 mEditor->Load(*gPrefs);
41 if(auto uiServices = dynamic_cast<ExportOptionsUIServices*>(mEditor.get()))
42 uiServices->PopulateUI(S);
43 else
45 }
46 else
48}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
#define S(N)
Definition: ToChars.cpp:64
void PopulateOptions(ShuttleGui &S)
void PopulateEmpty(ShuttleGui &S)
std::unique_ptr< ExportOptionsEditor > mEditor
virtual std::unique_ptr< ExportOptionsEditor > CreateOptionsEditor(int formatIndex, ExportOptionsEditor::Listener *listener) const =0
Creates format-dependent options editor, that is used to create a valid set of parameters to be used ...

References ExportPlugin::CreateOptionsEditor(), anonymous_namespace{ExportPCM.cpp}::format, gPrefs, mEditor, mParent, PopulateEmpty(), PopulateOptions(), and S.

Here is the call graph for this function:

◆ ~ExportOptionsHandler()

ExportOptionsHandler::~ExportOptionsHandler ( )
default

Member Function Documentation

◆ GetParameters()

ExportProcessor::Parameters ExportOptionsHandler::GetParameters ( ) const

Definition at line 64 of file ExportOptionsHandler.cpp.

65{
66 if(mEditor)
68 return {};
69}
static ExportProcessor::Parameters ParametersFromEditor(const ExportOptionsEditor &editor)
Definition: ExportUtils.cpp:32

References mEditor, and ExportUtils::ParametersFromEditor().

Here is the call graph for this function:

◆ GetSampleRateList()

ExportOptionsEditor::SampleRateList ExportOptionsHandler::GetSampleRateList ( ) const

Definition at line 80 of file ExportOptionsHandler.cpp.

81{
82 if(mEditor)
83 return mEditor->GetSampleRateList();
84 return {};
85}

References mEditor.

◆ OnExportOptionChange()

void ExportOptionsHandler::OnExportOptionChange ( const ExportOption option)
overridevirtual

Called when option change.

Implements ExportOptionsEditor::Listener.

Definition at line 227 of file ExportOptionsHandler.cpp.

228{
229 const auto it = mIDRowIndexMap.find(option.id);
230 if(it == mIDRowIndexMap.end())
231 return;
232
233 const auto index = it->second;
234 const auto [prompt, control] = mRows[index];
235
236 const auto visible = (option.flags & ExportOption::Hidden) == 0;
237
238 prompt->Show(visible);
239 control->Show(visible);
240
241 const auto enabled = (option.flags & ExportOption::ReadOnly) == 0;
242 control->Enable(enabled);
243}
std::unordered_map< int, int > mIDRowIndexMap
std::vector< std::tuple< wxStaticText *, wxControl * > > mRows
ExportOptionID id
Internal option id.
Definition: ExportTypes.h:56
@ ReadOnly
Parameter is read-only, client should not attempt to change it's value.
Definition: ExportTypes.h:50
@ Hidden
Option is not used and may be hidden from the user.
Definition: ExportTypes.h:51
int flags
A set of flag that desc.
Definition: ExportTypes.h:59

References ExportOption::flags, ExportOption::Hidden, ExportOption::id, mIDRowIndexMap, mRows, and ExportOption::ReadOnly.

◆ OnExportOptionChangeBegin()

void ExportOptionsHandler::OnExportOptionChangeBegin ( )
overridevirtual

Called before OnExportOptionChange

Implements ExportOptionsEditor::Listener.

Definition at line 216 of file ExportOptionsHandler.cpp.

217{
218 mUpdateLocker = std::make_unique<wxWindowUpdateLocker>(mParent);
219}
std::unique_ptr< wxWindowUpdateLocker > mUpdateLocker

References mParent, and mUpdateLocker.

◆ OnExportOptionChangeEnd()

void ExportOptionsHandler::OnExportOptionChangeEnd ( )
overridevirtual

Called after OnExportOptionChange

Implements ExportOptionsEditor::Listener.

Definition at line 221 of file ExportOptionsHandler.cpp.

222{
223 mParent->Layout();
224 mUpdateLocker.reset();
225}

References mParent, and mUpdateLocker.

◆ OnFormatInfoChange()

void ExportOptionsHandler::OnFormatInfoChange ( )
overridevirtual

Called when format extension change (usually in response parameter change)

Implements ExportOptionsEditor::Listener.

Definition at line 245 of file ExportOptionsHandler.cpp.

246{
248}
CallbackReturn Publish(const ExportOptionsHandlerEvent &message)
Send a message to connected callbacks.
Definition: Observer.h:207

References ExportOptionsHandlerEvent::FormatInfoChange, and Observer::Publisher< ExportOptionsHandlerEvent >::Publish().

Here is the call graph for this function:

◆ OnSampleRateListChange()

void ExportOptionsHandler::OnSampleRateListChange ( )
overridevirtual

Implements ExportOptionsEditor::Listener.

Definition at line 250 of file ExportOptionsHandler.cpp.

References Observer::Publisher< ExportOptionsHandlerEvent >::Publish(), and ExportOptionsHandlerEvent::SampleRateListChange.

Here is the call graph for this function:

◆ PopulateEmpty()

void ExportOptionsHandler::PopulateEmpty ( ShuttleGui S)
private

Definition at line 87 of file ExportOptionsHandler.cpp.

88{
89 S.StartHorizontalLay(wxCENTER);
90 {
91 S.StartHorizontalLay(wxCENTER, 0);
92 {
93 S.Prop(1).AddTitle(XO("No format specific options"));
94 }
95 S.EndHorizontalLay();
96 }
97 S.EndHorizontalLay();
98}
XO("Cut/Copy/Paste")

References S, and XO().

Referenced by ExportOptionsHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopulateOptions()

void ExportOptionsHandler::PopulateOptions ( ShuttleGui S)
private

Definition at line 100 of file ExportOptionsHandler.cpp.

101{
102 {
103 S.StartMultiColumn(2, wxALIGN_LEFT);
104 {
105 for(int i = 0; i < mEditor->GetOptionsCount(); ++i)
106 {
107 ExportOption option;
108 if(!mEditor->GetOption(i, option))
109 continue;
110
111 ExportValue value;
112 if(!mEditor->GetValue(option.id, value))
113 continue;
114
115 wxControl* control { nullptr };
116
117 auto prompt = S.AddPrompt(option.title);
118 prompt->SetMinSize({140, -1});
119
121 {
122 int selected = -1;
124
125 int index { 0 };
126 std::unordered_map<int, ExportValue> indexValueMap;
127 indexValueMap.reserve(option.values.size());
128 for(auto& e : option.values)
129 {
130 list.push_back(option.names[index]);
131 if(value == e)
132 selected = index;
133 indexValueMap[index] = e;
134 ++index;
135 }
136 control = S.AddChoice({}, list, selected);
137 control->Bind(wxEVT_CHOICE, [this, id = option.id, indexValueMap](const wxCommandEvent& evt)
138 {
139 const auto it = indexValueMap.find(evt.GetInt());
140 if(it != indexValueMap.end())
141 mEditor->SetValue(id, it->second);
142 });
143 }
144 else if(auto selected = std::get_if<bool>(&value))
145 {
146 control = S.Name(option.title).
147 AddCheckBox({}, *selected);
148#if wxUSE_ACCESSIBILITY
149 safenew WindowAccessible(control);
150#endif
151 control->Bind(wxEVT_CHECKBOX, [this, id = option.id](const wxCommandEvent& evt)
152 {
153 const auto checked = evt.GetInt() != 0;
154 mEditor->SetValue(id, checked);
155 });
156 }
157 else if(auto num = std::get_if<int>(&value))
158 {
160 {
161 const int min = *std::get_if<int>(&option.values[0]);
162 const int max = *std::get_if<int>(&option.values[1]);
163 if(max - min < 20)
164 {
165 control = S.Name(option.title)
166 .AddSlider({}, *num, max, min);
167 control->Bind(wxEVT_SLIDER, [this, id = option.id](const wxCommandEvent& evt)
168 {
169 mEditor->SetValue(id, evt.GetInt());
170 });
171 }
172 else
173 {
174 control = S.AddSpinCtrl({}, *num, max, min);
175 control->Bind(wxEVT_SPINCTRL, [this, id = option.id](const wxSpinEvent& evt)
176 {
177 mEditor->SetValue(id, evt.GetInt());
178 });
179 }
180 }
181 else
182 {
183 control = S.AddNumericTextBox({}, wxString::Format("%d", *num), 0);
184 control->Bind(wxEVT_TEXT, [this, id = option.id](const wxCommandEvent& evt)
185 {
186 long num;
187 if(evt.GetString().ToLong(&num))
188 mEditor->SetValue(id, static_cast<int>(num));
189 });
190 }
191 }
192 else if(auto str = std::get_if<std::string>(&value))
193 {
194 control = S.AddTextBox({}, wxString::FromUTF8(*str), 0);
195 control->Bind(wxEVT_TEXT, [this, id = option.id](const wxCommandEvent& evt)
196 {
197 mEditor->SetValue(id, evt.GetString().ToStdString());
198 });
199 }
200 mIDRowIndexMap[option.id] = static_cast<int>(mRows.size());
201 mRows.emplace_back(prompt, control);
202
203 if(option.flags & ExportOption::ReadOnly)
204 control->Disable();
205 if(option.flags & ExportOption::Hidden)
206 {
207 prompt->Hide();
208 control->Hide();
209 }
210 }
211 }
212 S.EndMultiColumn();
213 }
214}
int min(int a, int b)
#define str(a)
std::variant< bool, int, double, std::string > ExportValue
A type of option values (parameters) used by exporting plugins.
Definition: ExportTypes.h:38
#define safenew
Definition: MemoryX.h:10
std::vector< TranslatableString > TranslatableStrings
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
A type that provides a description of an exporting option. Isn't allowed to change except non-type re...
Definition: ExportTypes.h:43
@ TypeMask
Mask for bits that hold option type.
Definition: ExportTypes.h:46
@ TypeEnum
List/enum option. values holds items, and names text to be displayed.
Definition: ExportTypes.h:48
@ TypeRange
Range option. values holds [min, max].
Definition: ExportTypes.h:47
std::vector< ExportValue > values
Interpretation depends on type.
Definition: ExportTypes.h:60
TranslatableString title
Name of an option in a human-readable form.
Definition: ExportTypes.h:57
TranslatableStrings names
Interpretation depends on type.
Definition: ExportTypes.h:61

References ExportOption::flags, ExportOption::Hidden, ExportOption::id, mEditor, mIDRowIndexMap, min(), mRows, ExportOption::names, ExportOption::ReadOnly, S, safenew, str, ExportOption::title, ExportOption::TypeEnum, ExportOption::TypeMask, ExportOption::TypeRange, and ExportOption::values.

Referenced by ExportOptionsHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetParameters()

void ExportOptionsHandler::SetParameters ( const ExportProcessor::Parameters parameters)

Definition at line 71 of file ExportOptionsHandler.cpp.

72{
73 if(mEditor)
74 {
75 for(const auto& p : parameters)
76 mEditor->SetValue(std::get<0>(p), std::get<1>(p));
77 }
78}

References mEditor.

◆ TransferDataFromEditor()

bool ExportOptionsHandler::TransferDataFromEditor ( )

Definition at line 50 of file ExportOptionsHandler.cpp.

51{
52 if(mEditor)
53 {
54 if(auto uiServices = dynamic_cast<ExportOptionsUIServices*>(mEditor.get()))
55 {
56 if(!uiServices->TransferDataFromWindow())
57 return false;
58 }
59 mEditor->Store(*gPrefs);
60 }
61 return true;
62}

References gPrefs, and mEditor.

◆ UpdateSampleRateList()

void ExportOptionsHandler::UpdateSampleRateList ( )
private

Member Data Documentation

◆ mEditor

std::unique_ptr<ExportOptionsEditor> ExportOptionsHandler::mEditor
private

◆ mIDRowIndexMap

std::unordered_map<int, int> ExportOptionsHandler::mIDRowIndexMap
private

Definition at line 70 of file ExportOptionsHandler.h.

Referenced by OnExportOptionChange(), and PopulateOptions().

◆ mParent

wxWindow* ExportOptionsHandler::mParent { nullptr }
private

◆ mRows

std::vector<std::tuple<wxStaticText*, wxControl*> > ExportOptionsHandler::mRows
private

Definition at line 69 of file ExportOptionsHandler.h.

Referenced by OnExportOptionChange(), and PopulateOptions().

◆ mUpdateLocker

std::unique_ptr<wxWindowUpdateLocker> ExportOptionsHandler::mUpdateLocker
private

Definition at line 67 of file ExportOptionsHandler.h.

Referenced by OnExportOptionChangeBegin(), and OnExportOptionChangeEnd().


The documentation for this class was generated from the following files: