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

ImportRawDialog prompts you with options such as endianness and sample size to help you importing data of an unknown format. More...

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

Public Member Functions

 ImportRawDialog (wxWindow *parent, const wxString &fileName)
 
 ~ImportRawDialog ()
 
void OnOK (wxCommandEvent &event)
 
void OnCancel (wxCommandEvent &event)
 
void OnPlay (wxCommandEvent &event)
 
void OnDetect (wxCommandEvent &event)
 
void OnChoice (wxCommandEvent &event)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Static Public Attributes

static int mEncoding = SF_FORMAT_RAW | SF_ENDIAN_CPU | SF_FORMAT_PCM_16
 
static unsigned mChannels = 1
 
static int mOffset = 0
 
static double mRate = 0
 
static double mPercent = 100.
 

Private Attributes

wxButton * mOK
 
wxChoice * mEncodingChoice
 
wxChoice * mEndianChoice
 
wxChoice * mChannelChoice
 
wxTextCtrl * mOffsetText
 
wxTextCtrl * mPercentText
 
wxComboBox * mRateText
 
std::vector< int > mEncodingSubtype
 
wxString mFileName
 

Detailed Description

ImportRawDialog prompts you with options such as endianness and sample size to help you importing data of an unknown format.

Definition at line 58 of file ImportRaw.cpp.

Constructor & Destructor Documentation

◆ ImportRawDialog()

ImportRawDialog::ImportRawDialog ( wxWindow *  parent,
const wxString &  fileName 
)

Definition at line 296 of file ImportRaw.cpp.

297: wxDialogWrapper(parent, wxID_ANY, XO("Import Raw Data"),
298 wxDefaultPosition, wxDefaultSize,
299 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
300 mFileName(fileName)
301{
302 wxASSERT(0 < mChannels && mChannels <= 16);
303
304 SetName();
305
306 // Append filename at window title
307 wxFileName wfn{ fileName };
308 wxString windowTitle = XO("%s: %s").Format(GetTitle(), wfn.GetFullName()).Translation();
309 wxDialog::SetTitle(windowTitle);
310
311 ShuttleGui S(this, eIsCreating);
312 TranslatableStrings encodings;
313
314 int num = sf_num_encodings();
315
316 int selection = 0;
317 for (int i = 0; i < num; i++) {
318 SF_INFO info = { 0 };
319
320 int subtype = sf_encoding_index_to_subtype(i);
321 info.format = SF_FORMAT_RAW + SF_ENDIAN_LITTLE + subtype;
322 info.channels = 1;
323 info.samplerate = 44100;
324
325 if (sf_format_check(&info)) {
326 mEncodingSubtype.push_back(subtype);
327 encodings.push_back( Verbatim( sf_encoding_index_name(i) ) );
328
329 if ((mEncoding & SF_FORMAT_SUBMASK) == subtype)
330 selection = mEncodingSubtype.size() - 1;
331 }
332 }
333
334 TranslatableStrings endians{
335 /* i18n-hint: Refers to byte-order. Don't translate "endianness" if you don't
336 know the correct technical word. */
337 XO("No endianness") ,
338 /* i18n-hint: Refers to byte-order. Don't translate this if you don't
339 know the correct technical word. */
340 XO("Little-endian") ,
341 /* i18n-hint: Refers to byte-order. Don't translate this if you don't
342 know the correct technical word. */
343 XO("Big-endian") ,
344 /* i18n-hint: Refers to byte-order. Don't translate "endianness" if you don't
345 know the correct technical word. */
346 XO("Default endianness") ,
347 };
348
349 int endian = getEndianChoice(mEncoding);
350
352 XO("1 Channel (Mono)") ,
353 XO("2 Channels (Stereo)") ,
354 };
355 for (int i = 2; i < 16; i++) {
356 chans.push_back( XO("%d Channels").Format( i + 1 ) );
357 }
358
359 S.StartVerticalLay(false);
360 {
361 S.SetBorder(5);
362 S.StartTwoColumn();
363 {
364 mEncodingChoice = S.Id(ChoiceID).AddChoice(XXO("Encoding:"),
365 encodings,
366 selection);
367 mEndianChoice = S.Id(ChoiceID).AddChoice(XXO("Byte order:"),
368 endians,
369 endian);
370 mChannelChoice = S.Id(ChoiceID).AddChoice(XXO("Channels:"),
371 chans,
372 mChannels - 1);
373 }
374 S.EndTwoColumn();
375
376 S.SetBorder(5);
377 S.StartMultiColumn(3);
378 {
379 // Offset text
380 /* i18n-hint: (noun)*/
381 mOffsetText = S.AddTextBox(XXO("Start offset:"),
382 wxString::Format(wxT("%d"), mOffset),
383 12);
384 S.AddUnits(XO("bytes"));
385
386 // Percent text
387 mPercentText = S.AddTextBox(XXO("Amount to import:"),
388 wxT("100"),
389 12);
390 S.AddUnits(XO("%"));
391
392 // Rate text
393 wxArrayStringEx rates;
394 for (int i = 0; i < AudioIOBase::NumStandardRates; i++) {
395 rates.Add(
396 wxString::Format(wxT("%d"), AudioIOBase::StandardRates[i]));
397 }
398
399 /* i18n-hint: (noun)*/
400 mRateText = S.AddCombo(XXO("Sample rate:"),
401 wxString::Format(wxT("%d"), (int)mRate),
402 rates);
403 /* i18n-hint: This is the abbreviation for "Hertz", or
404 cycles per second. */
405 S.AddUnits(XO("Hz"));
406 }
407 S.EndMultiColumn();
408
409 S.SetBorder(5);
410 S.StartTwoColumn();
411 {
412 /* i18n-hint: Guess format of raw file */
413 S.Id(DetectID).AddButton(XXO("Detect"));
414
415 //
416 // Preview Pane goes here
417 //
418
419 S.AddStandardButtons();
420 }
421 S.EndTwoColumn();
422
423 // Find the OK button, and change its text to 'Import'.
424 // We MUST set mOK because it is used later.
425 mOK = (wxButton *)wxWindow::FindWindowById(wxID_OK, this);
426 mOK->SetLabel(_("&Import"));
427 }
428 S.EndVerticalLay();
429
430 Fit();
431 SetSizeHints(GetSize());
432
433 Centre(wxBOTH);
434}
wxT("CloseDown"))
unsigned int sf_encoding_index_to_subtype(int i)
Definition: FileFormats.cpp:90
wxString sf_encoding_index_name(int i)
Get the string name of the data encoding of the requested format.
Definition: FileFormats.cpp:79
int sf_num_encodings()
Get the number of data encodings libsndfile supports (in any container or none.
Definition: FileFormats.cpp:70
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
@ DetectID
Definition: ImportRaw.cpp:285
@ ChoiceID
Definition: ImportRaw.cpp:283
static int getEndianChoice(int sfFormat)
Definition: ImportRaw.cpp:262
#define _(s)
Definition: Internat.h:73
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIOBase.h:189
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIOBase.h:191
Abstract base class used in importing a file.
static int mOffset
Definition: ImportRaw.cpp:74
wxChoice * mChannelChoice
Definition: ImportRaw.cpp:83
wxButton * mOK
Definition: ImportRaw.cpp:80
static double mRate
Definition: ImportRaw.cpp:75
wxChoice * mEndianChoice
Definition: ImportRaw.cpp:82
static int mEncoding
Definition: ImportRaw.cpp:72
static unsigned mChannels
Definition: ImportRaw.cpp:73
wxTextCtrl * mOffsetText
Definition: ImportRaw.cpp:84
std::vector< int > mEncodingSubtype
Definition: ImportRaw.cpp:88
wxComboBox * mRateText
Definition: ImportRaw.cpp:86
wxTextCtrl * mPercentText
Definition: ImportRaw.cpp:85
wxString mFileName
Definition: ImportRaw.cpp:90
wxChoice * mEncodingChoice
Definition: ImportRaw.cpp:81
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References _, ChoiceID, DetectID, eIsCreating, getEndianChoice(), AudioIOBase::NumStandardRates, S, sf_encoding_index_name(), sf_encoding_index_to_subtype(), sf_num_encodings(), AudioIOBase::StandardRates, Verbatim(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ ~ImportRawDialog()

ImportRawDialog::~ImportRawDialog ( )

Definition at line 436 of file ImportRaw.cpp.

437{
438}

Member Function Documentation

◆ OnCancel()

void ImportRawDialog::OnCancel ( wxCommandEvent &  event)

Definition at line 469 of file ImportRaw.cpp.

470{
471 EndModal(false);
472}

◆ OnChoice()

void ImportRawDialog::OnChoice ( wxCommandEvent &  event)

Definition at line 504 of file ImportRaw.cpp.

505{
506 SF_INFO info;
507
508 memset(&info, 0, sizeof(SF_INFO));
509
510 mEncoding = mEncodingSubtype[mEncodingChoice->GetSelection()];
511 mEncoding += (mEndianChoice->GetSelection() * 0x10000000);
512
513 info.format = mEncoding | SF_FORMAT_RAW;
514 info.channels = mChannelChoice->GetSelection() + 1;
515 info.samplerate = 44100;
516
517 //mOK = (wxButton *)wxWindow::FindWindowById(wxID_OK, this);
518 if (sf_format_check(&info)) {
519 mOK->Enable(true);
520 return;
521 }
522
523 // Try it with 1-channel
524 info.channels = 1;
525 if (sf_format_check(&info)) {
526 mChannelChoice->SetSelection(0);
527 mOK->Enable(true);
528 return;
529 }
530
531 // Otherwise, this is an unsupported format
532 mOK->Enable(false);
533}

References mChannelChoice, mEncoding, mEncodingChoice, mEncodingSubtype, mEndianChoice, and mOK.

Referenced by OnDetect().

Here is the caller graph for this function:

◆ OnDetect()

void ImportRawDialog::OnDetect ( wxCommandEvent &  event)

Definition at line 478 of file ImportRaw.cpp.

479{
480 try {
481 // Yes, FormatClassifier currently handles filenames in UTF8 format only, that's a TODO ...
482 FormatClassifier theClassifier(mFileName.utf8_str());
483 mEncoding = theClassifier.GetResultFormatLibSndfile();
484 mChannels = theClassifier.GetResultChannels();
485 } catch (...) {
486 // Something went wrong in FormatClassifier, abort.
487 return;
488 }
489
490 int selection = 0;
491 auto iter = std::find(mEncodingSubtype.begin(), mEncodingSubtype.end(), mEncoding & SF_FORMAT_SUBMASK);
492 if (iter != mEncodingSubtype.end()) // subtype found
493 selection = std::distance(mEncodingSubtype.begin(), iter);
494
495 int endian = getEndianChoice(mEncoding);
496
497 mEncodingChoice->SetSelection(selection);
498 mEndianChoice->SetSelection(endian);
499 mChannelChoice->SetSelection(mChannels - 1);
500
501 OnChoice(event);
502}
FormatClassifier classifies the sample format and endianness of raw audio files.
void OnChoice(wxCommandEvent &event)
Definition: ImportRaw.cpp:504

References getEndianChoice(), FormatClassifier::GetResultChannels(), FormatClassifier::GetResultFormatLibSndfile(), mChannelChoice, mChannels, mEncoding, mEncodingChoice, mEncodingSubtype, mEndianChoice, mFileName, and OnChoice().

Here is the call graph for this function:

◆ OnOK()

void ImportRawDialog::OnOK ( wxCommandEvent &  event)

Definition at line 440 of file ImportRaw.cpp.

441{
442 long l;
443
444 mEncoding = mEncodingSubtype[mEncodingChoice->GetSelection()];
445 mEncoding += (mEndianChoice->GetSelection() * 0x10000000);
446 mChannels = mChannelChoice->GetSelection() + 1;
447 mOffsetText->GetValue().ToLong(&l);
448 mOffset = l;
449 mPercentText->GetValue().ToDouble(&mPercent);
450 mRateText->GetValue().ToDouble(&mRate);
451
452 if (mChannels < 1 || mChannels > 16)
453 mChannels = 1;
454 if (mOffset < 0)
455 mOffset = 0;
456 if (mPercent < 0.0)
457 mPercent = 0.0;
458 if (mPercent > 100.0)
459 mPercent = 100.0;
460 if (mRate < 100.0)
461 mRate = 100.0;
462 // Highest preset sample rate supported in Audacity 2.3.0 is 384 kHz
463 if (mRate > 384000.0)
464 mRate = 384000.0;
465
466 EndModal(true);
467}
static double mPercent
Definition: ImportRaw.cpp:76

References mChannelChoice, mChannels, mEncoding, mEncodingChoice, mEncodingSubtype, mEndianChoice, mOffset, mOffsetText, mPercent, mPercentText, mRate, and mRateText.

◆ OnPlay()

void ImportRawDialog::OnPlay ( wxCommandEvent &  event)

Definition at line 474 of file ImportRaw.cpp.

475{
476}

Member Data Documentation

◆ mChannelChoice

wxChoice* ImportRawDialog::mChannelChoice
private

Definition at line 83 of file ImportRaw.cpp.

Referenced by OnChoice(), OnDetect(), and OnOK().

◆ mChannels

unsigned ImportRawDialog::mChannels = 1
static

Definition at line 73 of file ImportRaw.cpp.

Referenced by ImportRaw(), OnDetect(), and OnOK().

◆ mEncoding

int ImportRawDialog::mEncoding = SF_FORMAT_RAW | SF_ENDIAN_CPU | SF_FORMAT_PCM_16
static

Definition at line 72 of file ImportRaw.cpp.

Referenced by ImportRaw(), OnChoice(), OnDetect(), and OnOK().

◆ mEncodingChoice

wxChoice* ImportRawDialog::mEncodingChoice
private

Definition at line 81 of file ImportRaw.cpp.

Referenced by OnChoice(), OnDetect(), and OnOK().

◆ mEncodingSubtype

std::vector<int> ImportRawDialog::mEncodingSubtype
private

Definition at line 88 of file ImportRaw.cpp.

Referenced by OnChoice(), OnDetect(), and OnOK().

◆ mEndianChoice

wxChoice* ImportRawDialog::mEndianChoice
private

Definition at line 82 of file ImportRaw.cpp.

Referenced by OnChoice(), OnDetect(), and OnOK().

◆ mFileName

wxString ImportRawDialog::mFileName
private

Definition at line 90 of file ImportRaw.cpp.

Referenced by OnDetect().

◆ mOffset

int ImportRawDialog::mOffset = 0
static

Definition at line 74 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mOffsetText

wxTextCtrl* ImportRawDialog::mOffsetText
private

Definition at line 84 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mOK

wxButton* ImportRawDialog::mOK
private

Definition at line 80 of file ImportRaw.cpp.

Referenced by OnChoice().

◆ mPercent

double ImportRawDialog::mPercent = 100.
static

Definition at line 76 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mPercentText

wxTextCtrl* ImportRawDialog::mPercentText
private

Definition at line 85 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mRate

double ImportRawDialog::mRate = 0
static

Definition at line 75 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mRateText

wxComboBox* ImportRawDialog::mRateText
private

Definition at line 86 of file ImportRaw.cpp.

Referenced by OnOK().


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