Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MP3ExportOptionsEditor Class Referencefinal
Inheritance diagram for MP3ExportOptionsEditor:
[legend]
Collaboration diagram for MP3ExportOptionsEditor:
[legend]

Public Member Functions

 MP3ExportOptionsEditor (Listener *listener)
 
int GetOptionsCount () const override
 
bool GetOption (int index, ExportOption &option) const override
 
bool SetValue (int id, const ExportValue &value) override
 
bool GetValue (int id, ExportValue &value) const override
 
SampleRateList GetSampleRateList () const override
 
void Load (const audacity::BasicSettings &config) override
 
void Store (audacity::BasicSettings &config) const override
 
- Public Member Functions inherited from ExportOptionsEditor
virtual ~ExportOptionsEditor ()
 
virtual int GetOptionsCount () const =0
 
virtual bool GetOption (int index, ExportOption &option) const =0
 
virtual bool GetValue (ExportOptionID id, ExportValue &value) const =0
 
virtual bool SetValue (ExportOptionID id, const ExportValue &value)=0
 
virtual SampleRateList GetSampleRateList () const =0
 
virtual void Store (audacity::BasicSettings &settings) const =0
 
virtual void Load (const audacity::BasicSettings &config)=0
 

Private Member Functions

void OnModeChange (const std::string &mode)
 

Private Attributes

std::vector< ExportOptionmOptions
 
std::unordered_map< int, ExportValuemValues
 
ListenermListener {nullptr}
 

Additional Inherited Members

- Public Types inherited from ExportOptionsEditor
using SampleRateList = std::vector< int >
 

Detailed Description

Definition at line 268 of file ExportMP3.cpp.

Constructor & Destructor Documentation

◆ MP3ExportOptionsEditor()

MP3ExportOptionsEditor::MP3ExportOptionsEditor ( Listener listener)
inlineexplicit

Definition at line 275 of file ExportMP3.cpp.

277 , mListener(listener)
278 {
279 mValues.reserve(mOptions.size());
280 for(auto& option : mOptions)
281 mValues[option.id] = option.defaultValue;
282 }
const std::initializer_list< ExportOption > MP3Options
Definition: ExportMP3.cpp:218
std::unordered_map< int, ExportValue > mValues
Definition: ExportMP3.cpp:271
std::vector< ExportOption > mOptions
Definition: ExportMP3.cpp:270

References mOptions, and mValues.

Member Function Documentation

◆ GetOption()

bool MP3ExportOptionsEditor::GetOption ( int  index,
ExportOption option 
) const
inlineoverridevirtual

Implements ExportOptionsEditor.

Definition at line 289 of file ExportMP3.cpp.

290 {
291 if(index >= 0 && index < static_cast<int>(mOptions.size()))
292 {
293 option = mOptions[index];
294 return true;
295 }
296 return false;
297 }

References mOptions.

◆ GetOptionsCount()

int MP3ExportOptionsEditor::GetOptionsCount ( ) const
inlineoverridevirtual

Implements ExportOptionsEditor.

Definition at line 284 of file ExportMP3.cpp.

285 {
286 return static_cast<int>(mOptions.size());
287 }

References mOptions.

◆ GetSampleRateList()

SampleRateList MP3ExportOptionsEditor::GetSampleRateList ( ) const
inlineoverridevirtual

Implements ExportOptionsEditor.

Definition at line 351 of file ExportMP3.cpp.

352 {
353 // Retrieve preferences
354 int highrate = 48000;
355 int lowrate = 8000;
356
357 const auto rmode = *std::get_if<std::string>(&mValues.find(MP3OptionIDMode)->second);
358
359 if (rmode == "ABR") {
360 auto bitrate = *std::get_if<int>(&mValues.find(MP3OptionIDQualityABR)->second);
361 if (bitrate > 160) {
362 lowrate = 32000;
363 }
364 else if (bitrate < 32 || bitrate == 144) {
365 highrate = 24000;
366 }
367 }
368 else if (rmode == "CBR") {
369 auto bitrate = *std::get_if<int>(&mValues.find(MP3OptionIDQualityCBR)->second);
370
371 if (bitrate > 160) {
372 lowrate = 32000;
373 }
374 else if (bitrate < 32 || bitrate == 144) {
375 highrate = 24000;
376 }
377 }
378
379 SampleRateList result;
380 result.reserve(sampRates.size());
381 for(auto rate : sampRates)
382 if(rate >= lowrate && rate <= highrate)
383 result.push_back(rate);
384
385 return result;
386 }
static const std::vector< int > sampRates
Definition: ExportMP3.cpp:197
@ MP3OptionIDQualityABR
Definition: ExportMP3.cpp:213
@ MP3OptionIDQualityCBR
Definition: ExportMP3.cpp:214
@ MP3OptionIDMode
Definition: ExportMP3.cpp:210
std::vector< int > SampleRateList

References MP3OptionIDMode, MP3OptionIDQualityABR, MP3OptionIDQualityCBR, mValues, and sampRates.

◆ GetValue()

bool MP3ExportOptionsEditor::GetValue ( int  id,
ExportValue value 
) const
inlineoverride

Definition at line 340 of file ExportMP3.cpp.

341 {
342 const auto it = mValues.find(id);
343 if(it != mValues.end())
344 {
345 value = it->second;
346 return true;
347 }
348 return false;
349 }

References mValues.

◆ Load()

void MP3ExportOptionsEditor::Load ( const audacity::BasicSettings config)
inlineoverridevirtual

Implements ExportOptionsEditor.

Definition at line 388 of file ExportMP3.cpp.

389 {
390 wxString mode;
391 if(config.Read(wxT("/FileFormats/MP3RateModeChoice"), &mode))
392 mValues[MP3OptionIDMode] = mode.ToStdString();
393 else
394 {
395 //attempt to recover from old-style preference
396 int index;
397 if(config.Read(wxT("/FileFormats/MP3RateMode"), &index))
399 }
400
401 config.Read(wxT("/FileFormats/MP3SetRate"), std::get_if<int>(&mValues[MP3OptionIDQualitySET]));
402 config.Read(wxT("/FileFormats/MP3AbrRate"), std::get_if<int>(&mValues[MP3OptionIDQualityABR]));
403 config.Read(wxT("/FileFormats/MP3CbrRate"), std::get_if<int>(&mValues[MP3OptionIDQualityCBR]));
404 config.Read(wxT("/FileFormats/MP3VbrRate"), std::get_if<int>(&mValues[MP3OptionIDQualityVBR]));
405
406 OnModeChange(*std::get_if<std::string>(&mValues[MP3OptionIDMode]));
407 }
wxT("CloseDown"))
@ MP3OptionIDQualityVBR
Definition: ExportMP3.cpp:212
@ MP3OptionIDQualitySET
Definition: ExportMP3.cpp:211
void OnModeChange(const std::string &mode)
Definition: ExportMP3.cpp:426
virtual bool Read(const wxString &key, bool *value) const =0

References mOptions, MP3OptionIDMode, MP3OptionIDQualityABR, MP3OptionIDQualityCBR, MP3OptionIDQualitySET, MP3OptionIDQualityVBR, mValues, OnModeChange(), audacity::BasicSettings::Read(), and wxT().

Here is the call graph for this function:

◆ OnModeChange()

void MP3ExportOptionsEditor::OnModeChange ( const std::string &  mode)
inlineprivate

Definition at line 426 of file ExportMP3.cpp.

427 {
432
433 if(mode == "SET")
435 else if(mode == "ABR")
437 else if(mode == "CBR")
439 else if(mode == "VBR")
441 }
A type that provides a description of an exporting option. Isn't allowed to change except non-type re...
Definition: ExportTypes.h:43
@ Hidden
Option is not used and may be hidden from the user.
Definition: ExportTypes.h:51

References ExportOption::Hidden, mOptions, MP3OptionIDQualityABR, MP3OptionIDQualityCBR, MP3OptionIDQualitySET, and MP3OptionIDQualityVBR.

Referenced by Load(), and SetValue().

Here is the caller graph for this function:

◆ SetValue()

bool MP3ExportOptionsEditor::SetValue ( int  id,
const ExportValue value 
)
inlineoverride

Definition at line 299 of file ExportMP3.cpp.

300 {
301 const auto it = mValues.find(id);
302 if(it == mValues.end())
303 return false;
304 if(value.index() != it->second.index())
305 return false;
306
307 it->second = value;
308
309 switch(id)
310 {
311 case MP3OptionIDMode:
312 {
313 const auto mode = *std::get_if<std::string>(&value);
314 OnModeChange(mode);
315 if(mListener)
316 {
323
325 }
326 } break;
331 {
332 if(mListener)
334 } break;
335 default: break;
336 }
337 return true;
338 }
virtual void OnExportOptionChangeEnd()=0
Called after OnExportOptionChange
virtual void OnExportOptionChangeBegin()=0
Called before OnExportOptionChange
virtual void OnExportOptionChange(const ExportOption &option)=0
Called when option change.
virtual void OnSampleRateListChange()=0

References mListener, mOptions, MP3OptionIDMode, MP3OptionIDQualityABR, MP3OptionIDQualityCBR, MP3OptionIDQualitySET, MP3OptionIDQualityVBR, mValues, ExportOptionsEditor::Listener::OnExportOptionChange(), ExportOptionsEditor::Listener::OnExportOptionChangeBegin(), ExportOptionsEditor::Listener::OnExportOptionChangeEnd(), OnModeChange(), and ExportOptionsEditor::Listener::OnSampleRateListChange().

Here is the call graph for this function:

◆ Store()

void MP3ExportOptionsEditor::Store ( audacity::BasicSettings config) const
inlineoverridevirtual

Implements ExportOptionsEditor.

Definition at line 409 of file ExportMP3.cpp.

410 {
411 auto it = mValues.find(MP3OptionIDMode);
412 config.Write(wxT("/FileFormats/MP3RateModeChoice"), wxString(*std::get_if<std::string>(&it->second)));
413
415 config.Write(wxT("/FileFormats/MP3SetRate"), *std::get_if<int>(&it->second));
417 config.Write(wxT("/FileFormats/MP3AbrRate"), *std::get_if<int>(&it->second));
419 config.Write(wxT("/FileFormats/MP3CbrRate"), *std::get_if<int>(&it->second));
421 config.Write(wxT("/FileFormats/MP3VbrRate"), *std::get_if<int>(&it->second));
422 }
virtual bool Write(const wxString &key, bool value)=0

References MP3OptionIDMode, MP3OptionIDQualityABR, MP3OptionIDQualityCBR, MP3OptionIDQualitySET, MP3OptionIDQualityVBR, mValues, audacity::BasicSettings::Write(), and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ mListener

Listener* MP3ExportOptionsEditor::mListener {nullptr}
private

Definition at line 272 of file ExportMP3.cpp.

Referenced by SetValue().

◆ mOptions

std::vector<ExportOption> MP3ExportOptionsEditor::mOptions
private

◆ mValues

std::unordered_map<int, ExportValue> MP3ExportOptionsEditor::mValues
private

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