Ardour  9.0-pre0-386-g96ef4d20f2
sndfile_reader.h
Go to the documentation of this file.
1 #ifndef AUDIOGRAPHER_SNDFILE_READER_H
2 #define AUDIOGRAPHER_SNDFILE_READER_H
3 
4 #include "pbd/compose.h"
5 
9 
10 namespace AudioGrapher
11 {
12 
16 template<typename T = DefaultSampleType>
18  : public virtual SndfileBase
19  , public ListedSource<T>
20  , public Throwing<>
21 {
22  public:
23 
24  SndfileReader (std::string const & path) : SndfileHandle (path) {}
25  virtual ~SndfileReader () {}
26 
27  SndfileReader (SndfileReader const & other) : SndfileHandle (other) {}
28  using SndfileHandle::operator=;
29 
35  {
36  if (throw_level (ThrowStrict) && context.channels() != channels() ) {
37  throw Exception (*this, string_compose
38  ("Wrong number of channels given to process(), %1 instead of %2",
39  context.channels(), channels()));
40  }
41 
42  samplecnt_t const samples_read = SndfileHandle::read (context.data(), context.samples());
43  ProcessContext<T> c_out = context.beginning (samples_read);
44 
45  if (samples_read < context.samples()) {
47  }
48  this->output (c_out);
49  return samples_read;
50  }
51 
52  protected:
55 };
56 
57 } // namespace
58 
59 #endif // AUDIOGRAPHER_SNDFILE_READER_H
An generic Source that uses a std::list for managing outputs.
Definition: listed_source.h:17
void output(ProcessContext< DefaultSampleType > const &c)
Helper for derived classes.
Definition: listed_source.h:28
ChannelCount const & channels() const
T const * data() const
data points to the array of data to process
ProcessContext beginning(samplecnt_t samples)
Make new Context out of the beginning of this context.
samplecnt_t const & samples() const
samples tells how many samples the array pointed by data contains
void set_flag(Flag flag) const
Base class for all classes using libsndfile.
Definition: sndfile_base.h:13
sf_count_t read(short *ptr, sf_count_t items)
int channels(void) const
Definition: sndfile.hh:102
SndfileReader(std::string const &path)
samplecnt_t read(ProcessContext< T > &context)
SndfileReader()
SndfileHandle has to be constructed directly by deriving classes.
SndfileReader(SndfileReader const &other)
bool throw_level(ThrowLevel level)
Definition: throwing.h:47
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:246
@ ThrowStrict
Stricter checks than ThrowProcess, less than ThrowSample.
Definition: throwing.h:24