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

Constructor & Destructor Documentation

◆ ImportRawDialog()

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

Definition at line 307 of file ImportRaw.cpp.

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

Here is the call graph for this function:

◆ ~ImportRawDialog()

ImportRawDialog::~ImportRawDialog ( )

Definition at line 447 of file ImportRaw.cpp.

448{
449}

Member Function Documentation

◆ OnCancel()

void ImportRawDialog::OnCancel ( wxCommandEvent &  event)

Definition at line 480 of file ImportRaw.cpp.

481{
482 EndModal(false);
483}

◆ OnChoice()

void ImportRawDialog::OnChoice ( wxCommandEvent &  event)

Definition at line 515 of file ImportRaw.cpp.

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

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

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

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

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

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

◆ OnPlay()

void ImportRawDialog::OnPlay ( wxCommandEvent &  event)

Definition at line 485 of file ImportRaw.cpp.

486{
487}

Member Data Documentation

◆ mChannelChoice

wxChoice* ImportRawDialog::mChannelChoice
private

Definition at line 87 of file ImportRaw.cpp.

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

◆ mChannels

unsigned ImportRawDialog::mChannels = 1
static

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

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

◆ mEncodingChoice

wxChoice* ImportRawDialog::mEncodingChoice
private

Definition at line 85 of file ImportRaw.cpp.

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

◆ mEncodingSubtype

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

Definition at line 92 of file ImportRaw.cpp.

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

◆ mEndianChoice

wxChoice* ImportRawDialog::mEndianChoice
private

Definition at line 86 of file ImportRaw.cpp.

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

◆ mFileName

wxString ImportRawDialog::mFileName
private

Definition at line 94 of file ImportRaw.cpp.

Referenced by OnDetect().

◆ mOffset

int ImportRawDialog::mOffset = 0
static

Definition at line 78 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mOffsetText

wxTextCtrl* ImportRawDialog::mOffsetText
private

Definition at line 88 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mOK

wxButton* ImportRawDialog::mOK
private

Definition at line 84 of file ImportRaw.cpp.

Referenced by OnChoice().

◆ mPercent

double ImportRawDialog::mPercent = 100.
static

Definition at line 80 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mPercentText

wxTextCtrl* ImportRawDialog::mPercentText
private

Definition at line 89 of file ImportRaw.cpp.

Referenced by OnOK().

◆ mRate

double ImportRawDialog::mRate = 0
static

Definition at line 79 of file ImportRaw.cpp.

Referenced by ImportRaw(), and OnOK().

◆ mRateText

wxComboBox* ImportRawDialog::mRateText
private

Definition at line 90 of file ImportRaw.cpp.

Referenced by OnOK().


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