[go: up one dir, main page]

File: qtractorAudioFile.h

package info (click to toggle)
qtractor 0.9.31-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,712 kB
  • sloc: cpp: 117,217; ansic: 2,215; xml: 71; sh: 5; makefile: 3
file content (155 lines) | stat: -rw-r--r-- 4,225 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// qtractorAudioFile.h
//
/****************************************************************************
   Copyright (C) 2005-2020, rncbc aka Rui Nuno Capela. All rights reserved.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

*****************************************************************************/

#ifndef __qtractorAudioFile_h
#define __qtractorAudioFile_h

#include <QStringList>
#include <QHash>


//----------------------------------------------------------------------
// class qtractorAudioFile -- Abstract audio file mockup.
//

class qtractorAudioFile
{
public:

	// Virtual destructor.
	virtual ~qtractorAudioFile() {}

	// Basic file open mode.
	enum { None = 0, Read = 1, Write = 2 };

	// Pure virtual method mockups.
	virtual bool open  (const QString& sFilename, int iMode = Read) = 0;
	virtual int  read  (float **ppFrames, unsigned int iFrames) = 0;
	virtual int  write (float **ppFrames, unsigned int iFrames) = 0;
	virtual bool seek  (unsigned long iOffset) = 0;
	virtual void close () = 0;

	// Pure virtual accessor mockups.
	virtual int mode() const = 0;

	// These shall give us a clue on the size
	// of the ring buffer size (in frames).
	virtual unsigned short channels() const = 0;
	virtual unsigned long frames() const = 0;

	// Other special informational methods.
	virtual unsigned int sampleRate() const = 0;
};


//----------------------------------------------------------------------
// class qtractorAudioFileFactory -- Audio file factory (singleton).
//

class qtractorAudioFileFactory
{
public:

	// Constructor.
	qtractorAudioFileFactory();

	// Destructor.
	~qtractorAudioFileFactory();

	// Singleton instance accessor.
	static qtractorAudioFileFactory *getInstance();

	// Supported file types.
	enum FileType { SndFile, VorbisFile, MadFile };

	// Audio file format descriptor.
	struct FileFormat
	{
		FileType type;
		QString  name;
		QString  ext;
		int      data;
	};

	// The supported file types/format global map.
	typedef QList<FileFormat *> FileFormats;

	static const FileFormats& formats();

	// The supported file types/extension map.
	typedef QHash<QString, FileFormat *> FileTypes;

	static const FileTypes& types();

	// The supported file types/names format lists.
	static const QStringList& filters();
	static const QStringList& exts();

	// Default audio file format accessors
	// (specific to capture/recording)
	static void setDefaultType(
		const QString& sExt, int iType,
		int iFormat = 0, int iQuality = 4);

	static QString defaultExt();

	// Check whether given file type/format is valid. (static)
	static bool isValidFormat(const FileFormat *pFormat, int iFormat);

	// Factory method. (static)
	static qtractorAudioFile *createAudioFile (const QString& sFilename,
		unsigned short iChannels = 0, unsigned int iSampleRate = 0,
		unsigned int iBufferSize = 0, int iFormat = -1);

protected:

	// Instance factory method.
	qtractorAudioFile *newAudioFile (const QString& sFilename,
		unsigned short iChannels, unsigned int iSampleRate,
		unsigned int iBufferSize, int iFormat);

	static int defaultFormat();
	static int defaultQuality();

private:

	// Instance members.
	FileFormats m_formats;
	FileTypes   m_types;

	// Supported filter strings.
	QStringList m_filters;
	QStringList m_exts;

	// Default file format/type (for capture/record)
	FileFormat *m_pDefaultFormat;
	int         m_iDefaultFormat;
	int         m_iDefaultQuality;

	// The singleton instance.
	static qtractorAudioFileFactory *g_pInstance;
};


#endif  // __qtractorAudioFile_h


// end of qtractorAudioFile.h