MuseScore  3.4
Music composition and notation
audiofile.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2007-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __AUDIOFILE_H__
14 #define __AUDIOFILE_H__
15 
16 #include <sndfile.h>
17 
18 //---------------------------------------------------------
19 // AudioFile
20 //---------------------------------------------------------
21 
22 class AudioFile {
24  {
27  };
28  SF_INFO info;
29  SNDFILE* sf;
30  SF_INSTRUMENT inst;
32  QByteArray buf; // used during read of Sample
33  int idx;
35 
36  public:
37  AudioFile();
38  ~AudioFile();
39 
40  bool open(const QByteArray&);
41  const char* error() const { return sf_strerror(sf); }
42  sf_count_t readData(short* data, sf_count_t frames);
43 
44  int channels() const { return info.channels; }
45  sf_count_t frames() const { return info.frames; }
46  int samplerate() const { return info.samplerate; }
47 
48  sf_count_t getFileLen() const { return buf.size(); }
49  sf_count_t tell() const { return idx; }
50  sf_count_t read(void* ptr, sf_count_t count);
51  sf_count_t write(const void* ptr, sf_count_t count);
52  sf_count_t seek(sf_count_t offset, int whence);
53  unsigned int loopStart(int v = 0) { return hasInstrument ? inst.loops[v].start : -1; }
54  unsigned int loopEnd(int v = 0) { return hasInstrument ? inst.loops[v].end : -1; }
55  int loopMode(int v = 0) { return hasInstrument ? inst.loops[v].mode : -1; }
56  };
57 
58 #endif
59 
QByteArray buf
Definition: audiofile.h:32
Definition: audiofile.h:26
Definition: audiofile.h:22
int idx
Definition: audiofile.h:33
Definition: audiofile.h:25
SNDFILE * sf
Definition: audiofile.h:29
SF_INSTRUMENT inst
Definition: audiofile.h:30
int loopMode(int v=0)
Definition: audiofile.h:55
FormatType
Definition: audiofile.h:23
unsigned int loopEnd(int v=0)
Definition: audiofile.h:54
sf_count_t tell() const
Definition: audiofile.h:49
SF_INFO info
Definition: audiofile.h:28
sf_count_t getFileLen() const
Definition: audiofile.h:48
sf_count_t readData(short *data, sf_count_t frames)
Definition: audiofile.cpp:74
FormatType _type
Definition: audiofile.h:34
~AudioFile()
Definition: audiofile.cpp:50
int channels() const
Definition: audiofile.h:44
sf_count_t seek(sf_count_t offset, int whence)
Definition: audiofile.cpp:110
const char * error() const
Definition: audiofile.h:41
int samplerate() const
Definition: audiofile.h:46
sf_count_t write(const void *ptr, sf_count_t count)
Definition: audiofile.cpp:142
bool open(const QByteArray &)
Definition: audiofile.cpp:60
sf_count_t frames() const
Definition: audiofile.h:45
unsigned int loopStart(int v=0)
Definition: audiofile.h:53
AudioFile()
Definition: audiofile.cpp:43
bool hasInstrument
Definition: audiofile.h:31
sf_count_t read(void *ptr, sf_count_t count)
Definition: audiofile.cpp:130