48#include <wx/combobox.h>
50#include <wx/stattext.h>
51#include <wx/textctrl.h>
64 void OnOK(wxCommandEvent & event);
65 void OnCancel(wxCommandEvent & event);
66 void OnPlay(wxCommandEvent & event);
67 void OnDetect(wxCommandEvent & event);
68 void OnChoice(wxCommandEvent & event);
121 if (!dlog.GetReturnCode())
126 double rate = dlog.
mRate;
127 sf_count_t offset = (sf_count_t)dlog.
mOffset;
130 SF_INFO sndInfo = { 0 };
131 sndInfo.samplerate = (int)rate;
132 sndInfo.channels = (int)numChannels;
133 sndInfo.format = encoding | SF_FORMAT_RAW;
138 if (f.Open(fileName)) {
142 sndFile.reset(SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &sndInfo, FALSE));
147 sf_error_str((SNDFILE *)NULL,
str, 1000);
148 wxPrintf(
"%s\n",
str);
155 int result = sf_command(sndFile.get(), SFC_SET_RAW_START_OFFSET, &offset,
sizeof(offset));
158 sf_error_str(sndFile.get(),
str, 1000);
159 wxPrintf(
"%s\n",
str);
164 SFCall<sf_count_t>(sf_seek, sndFile.get(), 0, SEEK_SET);
188 decltype(totalFrames) framescompleted = 0;
189 if (totalFrames < 0) {
194 auto msg =
XO(
"Importing %s").Format( wxFileName::FileName(fileName).GetFullName() );
204 sf_count_t sf_result;
206 sf_result = SFCall<sf_count_t>(sf_readf_short, sndFile.get(), (
short *)srcbuffer.
ptr(), block);
208 sf_result = SFCall<sf_count_t>(sf_readf_float, sndFile.get(), (
float *)srcbuffer.
ptr(), block);
210 if (sf_result >= 0) {
224 for (
size_t j = 0; j < block; ++j)
225 ((
short *)buffer.
ptr())[j] =
226 ((
short *)srcbuffer.
ptr())[numChannels * j + c];
229 for (
size_t j = 0; j < block; ++j)
230 ((
float *)buffer.
ptr())[j] =
231 ((
float *)srcbuffer.
ptr())[numChannels * j + c];
234 channel.AppendBuffer(buffer.
ptr(),
239 framescompleted += block;
242 updateResult = progress.
Update(
243 framescompleted.as_long_long(),
244 totalFrames.as_long_long()
249 }
while (block > 0 && framescompleted < totalFrames);
261 switch (sfFormat & SF_FORMAT_ENDMASK)
266 case SF_ENDIAN_LITTLE:
296 wxDefaultPosition, wxDefaultSize,
297 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
300 wxASSERT(0 < mChannels && mChannels <= 16);
305 wxFileName wfn{ fileName };
306 wxString windowTitle =
XO(
"%s: %s").Format(GetTitle(), wfn.GetFullName()).Translation();
307 wxDialog::SetTitle(windowTitle);
315 for (
int i = 0; i < num; i++) {
316 SF_INFO info = { 0 };
319 info.format = SF_FORMAT_RAW + SF_ENDIAN_LITTLE + subtype;
321 info.samplerate = 44100;
323 if (sf_format_check(&info)) {
324 mEncodingSubtype.push_back(subtype);
327 if ((mEncoding & SF_FORMAT_SUBMASK) == subtype)
328 selection = mEncodingSubtype.size() - 1;
335 XO(
"No endianness") ,
338 XO(
"Little-endian") ,
344 XO(
"Default endianness") ,
350 XO(
"1 Channel (Mono)") ,
351 XO(
"2 Channels (Stereo)") ,
353 for (
int i = 2; i < 16; i++) {
354 chans.push_back(
XO(
"%d Channels").
Format( i + 1 ) );
357 S.StartVerticalLay(
false);
362 mEncodingChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Encoding:"),
365 mEndianChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Byte order:"),
368 mChannelChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Channels:"),
375 S.StartMultiColumn(3);
379 mOffsetText =
S.AddTextBox(
XXO(
"Start offset:"),
380 wxString::Format(
wxT(
"%d"), mOffset),
382 S.AddUnits(
XO(
"bytes"));
385 mPercentText =
S.AddTextBox(
XXO(
"Amount to import:"),
398 mRateText =
S.AddCombo(
XXO(
"Sample rate:"),
399 wxString::Format(
wxT(
"%d"), (
int)mRate),
403 S.AddUnits(
XO(
"Hz"));
417 S.AddStandardButtons();
423 mOK = (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
424 mOK->SetLabel(
_(
"&Import"));
429 SetSizeHints(GetSize());
450 if (mChannels < 1 || mChannels > 16)
461 if (
mRate > 384000.0)
506 memset(&info, 0,
sizeof(SF_INFO));
513 info.samplerate = 44100;
516 if (sf_format_check(&info)) {
523 if (sf_format_check(&info)) {
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XXO("&Cut/Copy/Paste Toolbar")
The interface that all file import "plugins" (if you want to call them that) must implement....
static int getEndianChoice(int sfFormat)
void ImportRaw(const AudacityProject &project, wxWindow *parent, const wxString &fileName, WaveTrackFactory *trackFactory, TrackHolders &outTracks)
std::vector< std::shared_ptr< Track > > TrackHolders
an object holding per-project preferred sample rate
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
std::shared_ptr< TrackList > TrackListHolder
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
An AudacityException with no visible message.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static const int StandardRates[]
Array of common audio sample rates.
static const int NumStandardRates
How many standard sample rates there are.
Thrown for failure of file or database operations in deeply nested places.
ImportRawDialog prompts you with options such as endianness and sample size to help you importing dat...
void OnCancel(wxCommandEvent &event)
wxChoice * mChannelChoice
void OnOK(wxCommandEvent &event)
void OnDetect(wxCommandEvent &event)
static unsigned mChannels
std::vector< int > mEncodingSubtype
void OnPlay(wxCommandEvent &event)
ImportRawDialog(wxWindow *parent, const wxString &fileName)
wxTextCtrl * mPercentText
wxChoice * mEncodingChoice
void OnChoice(wxCommandEvent &event)
static sampleFormat ChooseFormat(sampleFormat effectiveFormat)
Choose appropriate format, which will not be narrower than the specified one.
static void ForEachChannel(TrackList &trackList, const std::function< void(WaveChannel &)> &op)
Iterates over channels in each wave track from the list.
static void FinalizeImport(TrackHolders &outTracks, const std::vector< std::shared_ptr< WaveTrack > > &importedStreams)
Flushes the given channels and moves them to outTracks.
ProgressResult Update(int value, const TranslatableString &message={})
static ProjectRate & Get(AudacityProject &project)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing.
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
TrackListHolder CreateMany(size_t nChannels)
Creates tracks with project's default rate and format and the given number of channels.
A Track that contains audio waveform data.
Positions or offsets within audio files need a wide type.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
constexpr auto maxBlockSize
const char * begin(const char *str) noexcept