30#include "../FileFormats.h"
33#include "../SelectFile.h"
34#include "../ShuttleGui.h"
36#include "../WaveTrack.h"
37#include "../widgets/ProgressDialog.h"
48#include <wx/combobox.h>
49#include <wx/filename.h>
53#include <wx/stattext.h>
54#include <wx/textctrl.h>
68 void OnOK(wxCommandEvent & event);
69 void OnCancel(wxCommandEvent & event);
70 void OnPlay(wxCommandEvent & event);
71 void OnDetect(wxCommandEvent & event);
72 void OnChoice(wxCommandEvent & event);
125 if (!dlog.GetReturnCode())
130 double rate = dlog.
mRate;
131 sf_count_t offset = (sf_count_t)dlog.
mOffset;
134 SF_INFO sndInfo = { 0 };
135 sndInfo.samplerate = (int)rate;
136 sndInfo.channels = (int)numChannels;
137 sndInfo.format = encoding | SF_FORMAT_RAW;
142 if (f.Open(fileName)) {
146 sndFile.reset(SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &sndInfo, FALSE));
151 sf_error_str((SNDFILE *)NULL,
str, 1000);
152 wxPrintf(
"%s\n",
str);
159 int result = sf_command(sndFile.get(), SFC_SET_RAW_START_OFFSET, &offset,
sizeof(offset));
162 sf_error_str(sndFile.get(),
str, 1000);
163 wxPrintf(
"%s\n",
str);
168 SFCall<sf_count_t>(sf_seek, sndFile.get(), 0, SEEK_SET);
186 auto &channels = results[0];
187 channels.resize(numChannels);
191 auto iter = channels.begin();
192 for (
decltype(numChannels) c = 0; c < numChannels; ++iter, ++c)
195 const auto firstChannel = channels.begin()->get();
196 auto maxBlockSize = firstChannel->GetMaxBlockSize();
201 decltype(totalFrames) framescompleted = 0;
202 if (totalFrames < 0) {
207 auto msg =
XO(
"Importing %s").Format( wxFileName::FileName(fileName).GetFullName() );
217 sf_count_t sf_result;
219 sf_result = SFCall<sf_count_t>(sf_readf_short, sndFile.get(), (
short *)srcbuffer.
ptr(), block);
221 sf_result = SFCall<sf_count_t>(sf_readf_float, sndFile.get(), (
float *)srcbuffer.
ptr(), block);
223 if (sf_result >= 0) {
233 auto iter = channels.begin();
234 for(
decltype(numChannels) c = 0; c < numChannels; ++iter, ++c) {
236 for(
decltype(block) j=0; j<block; j++)
237 ((
short *)buffer.
ptr())[j] =
238 ((
short *)srcbuffer.
ptr())[numChannels*j+c];
241 for(
decltype(block) j=0; j<block; j++)
242 ((
float *)buffer.
ptr())[j] =
243 ((
float *)srcbuffer.
ptr())[numChannels*j+c];
248 framescompleted += block;
251 updateResult = progress.
Update(
252 framescompleted.as_long_long(),
253 totalFrames.as_long_long()
258 }
while (block > 0 && framescompleted < totalFrames);
264 if (!results.empty() && !results[0].empty()) {
265 for (
const auto &channel : results[0])
267 outTracks.swap(results);
274 switch (sfFormat & SF_FORMAT_ENDMASK)
279 case SF_ENDIAN_LITTLE:
309 wxDefaultPosition, wxDefaultSize,
310 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
313 wxASSERT(0 < mChannels && mChannels <= 16);
318 wxFileName wfn{ fileName };
319 wxString windowTitle =
XO(
"%s: %s").Format(GetTitle(), wfn.GetFullName()).Translation();
320 wxDialog::SetTitle(windowTitle);
328 for (
int i = 0; i < num; i++) {
329 SF_INFO info = { 0 };
332 info.format = SF_FORMAT_RAW + SF_ENDIAN_LITTLE + subtype;
334 info.samplerate = 44100;
336 if (sf_format_check(&info)) {
337 mEncodingSubtype.push_back(subtype);
340 if ((mEncoding & SF_FORMAT_SUBMASK) == subtype)
341 selection = mEncodingSubtype.size() - 1;
348 XO(
"No endianness") ,
351 XO(
"Little-endian") ,
357 XO(
"Default endianness") ,
363 XO(
"1 Channel (Mono)") ,
364 XO(
"2 Channels (Stereo)") ,
366 for (
int i = 2; i < 16; i++) {
367 chans.push_back(
XO(
"%d Channels").
Format( i + 1 ) );
370 S.StartVerticalLay(
false);
375 mEncodingChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Encoding:"),
378 mEndianChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Byte order:"),
381 mChannelChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Channels:"),
388 S.StartMultiColumn(3);
392 mOffsetText =
S.AddTextBox(
XXO(
"Start offset:"),
393 wxString::Format(wxT(
"%d"), mOffset),
395 S.AddUnits(
XO(
"bytes"));
398 mPercentText =
S.AddTextBox(
XXO(
"Amount to import:"),
411 mRateText =
S.AddCombo(
XXO(
"Sample rate:"),
412 wxString::Format(wxT(
"%d"), (
int)mRate),
416 S.AddUnits(
XO(
"Hz"));
430 S.AddStandardButtons();
436 mOK = (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
437 mOK->SetLabel(
_(
"&Import"));
442 SetSizeHints(GetSize());
463 if (mChannels < 1 || mChannels > 16)
474 if (
mRate > 384000.0)
519 memset(&info, 0,
sizeof(SF_INFO));
526 info.samplerate = 44100;
529 if (sf_format_check(&info)) {
536 if (sf_format_check(&info)) {
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
std::vector< std::vector< std::shared_ptr< WaveTrack > > > TrackHolders
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)
an object holding per-project preferred sample rate
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
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.
static sampleFormat ChooseFormat(sampleFormat effectiveFormat)
Choose appropriate format, which will not be narrower than the specified one.
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)
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...
std::shared_ptr< WaveTrack > Create()
Creates an unnamed empty WaveTrack with default sample format and default rate.
Positions or offsets within audio files need a wide type.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.