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

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

435{
436}

Member Function Documentation

◆ OnCancel()

void ImportRawDialog::OnCancel ( wxCommandEvent &  event)

Definition at line 467 of file ImportRaw.cpp.

468{
469 EndModal(false);
470}

◆ OnChoice()

void ImportRawDialog::OnChoice ( wxCommandEvent &  event)

Definition at line 502 of file ImportRaw.cpp.

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

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

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

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

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

473{
474}

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: