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 57 of file ImportRaw.cpp.

Constructor & Destructor Documentation

◆ ImportRawDialog()

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

Definition at line 303 of file ImportRaw.cpp.

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

444{
445}

Member Function Documentation

◆ OnCancel()

void ImportRawDialog::OnCancel ( wxCommandEvent &  event)

Definition at line 476 of file ImportRaw.cpp.

477{
478 EndModal(false);
479}

◆ OnChoice()

void ImportRawDialog::OnChoice ( wxCommandEvent &  event)

Definition at line 511 of file ImportRaw.cpp.

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

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 485 of file ImportRaw.cpp.

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

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 447 of file ImportRaw.cpp.

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

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

◆ OnPlay()

void ImportRawDialog::OnPlay ( wxCommandEvent &  event)

Definition at line 481 of file ImportRaw.cpp.

482{
483}

Member Data Documentation

◆ mChannelChoice

wxChoice* ImportRawDialog::mChannelChoice
private

Definition at line 82 of file ImportRaw.cpp.

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

◆ mChannels

unsigned ImportRawDialog::mChannels = 1
static

Definition at line 72 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 71 of file ImportRaw.cpp.

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

◆ mEncodingChoice

wxChoice* ImportRawDialog::mEncodingChoice
private

Definition at line 80 of file ImportRaw.cpp.

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

◆ mEncodingSubtype

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

Definition at line 87 of file ImportRaw.cpp.

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

◆ mEndianChoice

wxChoice* ImportRawDialog::mEndianChoice
private

Definition at line 81 of file ImportRaw.cpp.

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

◆ mFileName

wxString ImportRawDialog::mFileName
private

Definition at line 89 of file ImportRaw.cpp.

Referenced by OnDetect().

◆ mOffset

int ImportRawDialog::mOffset = 0
static

Definition at line 73 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mOffsetText

wxTextCtrl* ImportRawDialog::mOffsetText
private

Definition at line 83 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mOK

wxButton* ImportRawDialog::mOK
private

Definition at line 79 of file ImportRaw.cpp.

Referenced by OnChoice().

◆ mPercent

double ImportRawDialog::mPercent = 100.
static

Definition at line 75 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mPercentText

wxTextCtrl* ImportRawDialog::mPercentText
private

Definition at line 84 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mRate

double ImportRawDialog::mRate = 0
static

Definition at line 74 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mRateText

wxComboBox* ImportRawDialog::mRateText
private

Definition at line 85 of file ImportRaw.cpp.

Referenced by OnOK().


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