30#include "../FileFormats.h"
47#include <wx/combobox.h>
49#include <wx/stattext.h>
50#include <wx/textctrl.h>
63 void OnOK(wxCommandEvent & event);
64 void OnCancel(wxCommandEvent & event);
65 void OnPlay(wxCommandEvent & event);
66 void OnDetect(wxCommandEvent & event);
67 void OnChoice(wxCommandEvent & event);
120 if (!dlog.GetReturnCode())
125 double rate = dlog.
mRate;
126 sf_count_t offset = (sf_count_t)dlog.
mOffset;
129 SF_INFO sndInfo = { 0 };
130 sndInfo.samplerate = (int)rate;
131 sndInfo.channels = (int)numChannels;
132 sndInfo.format = encoding | SF_FORMAT_RAW;
137 if (f.Open(fileName)) {
141 sndFile.reset(SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &sndInfo, FALSE));
146 sf_error_str((SNDFILE *)NULL,
str, 1000);
147 wxPrintf(
"%s\n",
str);
154 int result = sf_command(sndFile.get(), SFC_SET_RAW_START_OFFSET, &offset,
sizeof(offset));
157 sf_error_str(sndFile.get(),
str, 1000);
158 wxPrintf(
"%s\n",
str);
163 SFCall<sf_count_t>(sf_seek, sndFile.get(), 0, SEEK_SET);
181 auto &channels = results[0];
182 channels.resize(numChannels);
186 auto iter = channels.begin();
187 for (
decltype(numChannels) c = 0; c < numChannels; ++iter, ++c)
190 const auto firstChannel = channels.begin()->get();
191 auto maxBlockSize = firstChannel->GetMaxBlockSize();
196 decltype(totalFrames) framescompleted = 0;
197 if (totalFrames < 0) {
202 auto msg =
XO(
"Importing %s").Format( wxFileName::FileName(fileName).GetFullName() );
212 sf_count_t sf_result;
214 sf_result = SFCall<sf_count_t>(sf_readf_short, sndFile.get(), (
short *)srcbuffer.
ptr(), block);
216 sf_result = SFCall<sf_count_t>(sf_readf_float, sndFile.get(), (
float *)srcbuffer.
ptr(), block);
218 if (sf_result >= 0) {
228 auto iter = channels.begin();
229 for(
decltype(numChannels) c = 0; c < numChannels; ++iter, ++c) {
231 for(
decltype(block) j=0; j<block; j++)
232 ((
short *)buffer.
ptr())[j] =
233 ((
short *)srcbuffer.
ptr())[numChannels*j+c];
236 for(
decltype(block) j=0; j<block; j++)
237 ((
float *)buffer.
ptr())[j] =
238 ((
float *)srcbuffer.
ptr())[numChannels*j+c];
244 framescompleted += block;
247 updateResult = progress.
Update(
248 framescompleted.as_long_long(),
249 totalFrames.as_long_long()
254 }
while (block > 0 && framescompleted < totalFrames);
260 if (!results.empty() && !results[0].empty()) {
261 for (
const auto &channel : results[0])
263 outTracks.swap(results);
270 switch (sfFormat & SF_FORMAT_ENDMASK)
275 case SF_ENDIAN_LITTLE:
305 wxDefaultPosition, wxDefaultSize,
306 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
309 wxASSERT(0 < mChannels && mChannels <= 16);
314 wxFileName wfn{ fileName };
315 wxString windowTitle =
XO(
"%s: %s").Format(GetTitle(), wfn.GetFullName()).Translation();
316 wxDialog::SetTitle(windowTitle);
324 for (
int i = 0; i < num; i++) {
325 SF_INFO info = { 0 };
328 info.format = SF_FORMAT_RAW + SF_ENDIAN_LITTLE + subtype;
330 info.samplerate = 44100;
332 if (sf_format_check(&info)) {
333 mEncodingSubtype.push_back(subtype);
336 if ((mEncoding & SF_FORMAT_SUBMASK) == subtype)
337 selection = mEncodingSubtype.size() - 1;
344 XO(
"No endianness") ,
347 XO(
"Little-endian") ,
353 XO(
"Default endianness") ,
359 XO(
"1 Channel (Mono)") ,
360 XO(
"2 Channels (Stereo)") ,
362 for (
int i = 2; i < 16; i++) {
363 chans.push_back(
XO(
"%d Channels").
Format( i + 1 ) );
366 S.StartVerticalLay(
false);
371 mEncodingChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Encoding:"),
374 mEndianChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Byte order:"),
377 mChannelChoice =
S.Id(
ChoiceID).AddChoice(
XXO(
"Channels:"),
384 S.StartMultiColumn(3);
388 mOffsetText =
S.AddTextBox(
XXO(
"Start offset:"),
389 wxString::Format(
wxT(
"%d"), mOffset),
391 S.AddUnits(
XO(
"bytes"));
394 mPercentText =
S.AddTextBox(
XXO(
"Amount to import:"),
407 mRateText =
S.AddCombo(
XXO(
"Sample rate:"),
408 wxString::Format(
wxT(
"%d"), (
int)mRate),
412 S.AddUnits(
XO(
"Hz"));
426 S.AddStandardButtons();
432 mOK = (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
433 mOK->SetLabel(
_(
"&Import"));
438 SetSizeHints(GetSize());
459 if (mChannels < 1 || mChannels > 16)
470 if (
mRate > 384000.0)
515 memset(&info, 0,
sizeof(SF_INFO));
522 info.samplerate = 44100;
525 if (sf_format_check(&info)) {
532 if (sf_format_check(&info)) {
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XXO("&Cut/Copy/Paste Toolbar")
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.