DecodingWavFileReader.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_DECODING_WAV_FILE_READER_H
17 #define SV_DECODING_WAV_FILE_READER_H
18 
19 #include "CodedAudioFileReader.h"
20 
21 #include "base/Thread.h"
22 
23 #include <set>
24 #include <atomic>
25 
26 class WavFileReader;
27 class ProgressReporter;
28 
30 {
31  Q_OBJECT
32 public:
34  DecodeMode decodeMode, // determines when to resample
35  CacheMode cacheMode,
36  sv_samplerate_t targetRate = 0,
37  bool normalised = false,
38  ProgressReporter *reporter = 0);
39  virtual ~DecodingWavFileReader();
40 
41  QString getTitle() const override { return m_title; }
42  QString getMaker() const override { return m_maker; }
43 
44  QString getError() const override { return m_error; }
45  QString getLocation() const override { return m_source.getLocation(); }
46 
47  static void getSupportedExtensions(std::set<QString> &extensions);
48  static bool supportsExtension(QString ext);
49  static bool supportsContentType(QString type);
50  static bool supports(FileSource &source);
51 
52  int getDecodeCompletion() const override { return m_completion; }
53 
54  bool isUpdating() const override {
55  return m_decodeThread && m_decodeThread->isRunning();
56  }
57 
58 public slots:
59  void cancelled();
60 
61 protected:
63  QString m_title;
64  QString m_maker;
65  QString m_path;
66  QString m_error;
67  std::atomic<bool> m_cancelled;
70 
73 
74  void addBlock(const floatvec_t &frames);
75 
76  class DecodeThread : public Thread
77  {
78  public:
80  void run() override;
81 
82  protected:
84  };
85 
87 };
88 
89 #endif
90 
DecodeThread(DecodingWavFileReader *reader)
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
QString getLocation() const override
Return the location of the audio data in the reader (as passed in to the FileSource constructor...
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
QString getLocation() const
Return the location filename or URL as passed to the constructor.
Definition: FileSource.cpp:616
static bool supportsContentType(QString type)
Reader for audio files using libsndfile.
Definition: WavFileReader.h:41
QString getError() const override
If isOK() is false, return an error string.
static bool supports(FileSource &source)
void addBlock(const floatvec_t &frames)
std::vector< float, breakfastquay::StlAllocator< float > > floatvec_t
Definition: BaseTypes.h:53
int getDecodeCompletion() const override
Return a percentage value indicating how far through decoding the audio file we are.
static void getSupportedExtensions(std::set< QString > &extensions)
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
Definition: FileSource.h:59
Definition: Thread.h:24
DecodingWavFileReader(FileSource source, DecodeMode decodeMode, CacheMode cacheMode, sv_samplerate_t targetRate=0, bool normalised=false, ProgressReporter *reporter=0)
bool isUpdating() const override
Return true if decoding is still in progress and the frame count may change.
std::atomic< bool > m_cancelled
ProgressReporter * m_reporter
QString getMaker() const override
Return the "maker" of the work in the audio file, if known.
QString getTitle() const override
Return the title of the work in the audio file, if known.
static bool supportsExtension(QString ext)