Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / caimportable.cc
blob149f213222def48b574f0d236ee4dcc072fe7a8f
1 #include "ardour/caimportable.h"
2 #include <sndfile.h>
3 #include "pbd/error.h"
5 #include "i18n.h"
7 using namespace ARDOUR;
8 using namespace std;
9 using namespace PBD;
11 CAImportableSource::CAImportableSource (const string& path)
13 try {
14 af.Open (path.c_str());
16 CAStreamBasicDescription file_format (af.GetFileDataFormat());
17 CAStreamBasicDescription client_format (file_format);
19 /* set canonial form (PCM, native float packed, 32 bit, with the correct number of channels
20 and interleaved (since we plan to deinterleave ourselves)
23 client_format.SetCanonical(client_format.NumberChannels(), true);
24 af.SetClientFormat (client_format);
26 } catch (CAXException& cax) {
27 //Don't report an error here since there is one higher up in import.
28 //Since libsndfile gets tried second, any failures here may show as
29 //invalid errors in the Error log.
30 throw failed_constructor ();
35 CAImportableSource::~CAImportableSource ()
39 framecnt_t
40 CAImportableSource::read (Sample* buffer, framecnt_t nframes)
42 framecnt_t nread = 0;
43 AudioBufferList abl;
44 framecnt_t per_channel;
45 bool at_end = false;
47 abl.mNumberBuffers = 1;
48 abl.mBuffers[0].mNumberChannels = channels();
50 per_channel = nframes / abl.mBuffers[0].mNumberChannels;
52 while (nread < per_channel) {
54 UInt32 new_cnt = per_channel - nread;
56 abl.mBuffers[0].mDataByteSize = new_cnt * abl.mBuffers[0].mNumberChannels * sizeof(Sample);
57 abl.mBuffers[0].mData = buffer + nread;
59 try {
60 af.Read (new_cnt, &abl);
61 } catch (CAXException& cax) {
62 error << string_compose("CAImportable: %1", cax.mOperation);
63 return -1;
66 if (new_cnt == 0) {
67 /* EOF */
68 at_end = true;
69 break;
72 nread += new_cnt;
75 if (!at_end && nread < per_channel) {
76 return 0;
77 } else {
78 return nread * abl.mBuffers[0].mNumberChannels;
82 uint
83 CAImportableSource::channels () const
85 return af.GetFileDataFormat().NumberChannels();
88 framecnt_t
89 CAImportableSource::length () const
91 return af.GetNumberFrames();
94 framecnt_t
95 CAImportableSource::samplerate () const
97 CAStreamBasicDescription client_asbd;
99 try {
100 client_asbd = af.GetClientDataFormat ();
101 } catch (CAXException& cax) {
102 error << string_compose ("CAImportable: %1", cax.mOperation) << endmsg;
103 return 0.0;
106 return client_asbd.mSampleRate;
109 void
110 CAImportableSource::seek (framepos_t pos)
112 try {
113 af.Seek (pos);
114 } catch (CAXException& cax) {
115 error << string_compose ("CAImportable: %1 to %2", cax.mOperation, pos) << endmsg;