summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/export_format_base.h
blob: ee2739eee1f576ab8c33115e9eb970596691a619 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
    Copyright (C) 2008 Paul Davis
    Author: Sakari Bergen

    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., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __ardour_export_format_base_h__
#define __ardour_export_format_base_h__

#include <set>
#include <string>

#include <boost/shared_ptr.hpp>

#include <sndfile.h>
#include <samplerate.h>

#include "pbd/signals.h"
#include "ardour/libardour_visibility.h"
#include "ardour/types.h"

#include "audiographer/general/sample_format_converter.h"

namespace ARDOUR
{

class LIBARDOUR_API ExportFormatBase {
  public:

	enum Type {
		T_None = 0,
		T_Sndfile
	};

	enum FormatId {
		F_None = 0,
		F_WAV = SF_FORMAT_WAV,
		F_W64 = SF_FORMAT_W64,
		F_CAF = SF_FORMAT_CAF,
		F_AIFF = SF_FORMAT_AIFF,
		F_AU = SF_FORMAT_AU,
		F_IRCAM = SF_FORMAT_IRCAM,
		F_RAW = SF_FORMAT_RAW,
		F_FLAC = SF_FORMAT_FLAC,
		F_Ogg = SF_FORMAT_OGG
	};

	enum Endianness {
		E_FileDefault = SF_ENDIAN_FILE, /* Default file endian-ness. */
		E_Little = SF_ENDIAN_LITTLE,    /* Force little endian-ness. */
		E_Big = SF_ENDIAN_BIG,          /* Force big endian-ness. */
		E_Cpu = SF_ENDIAN_CPU           /* Force CPU endian-ness. */
	};

	enum SampleFormat {
		SF_None = 0,
		SF_8 = SF_FORMAT_PCM_S8,
		SF_16 = SF_FORMAT_PCM_16,
		SF_24 = SF_FORMAT_PCM_24,
		SF_32 = SF_FORMAT_PCM_32,
		SF_U8 = SF_FORMAT_PCM_U8,
		SF_Float = SF_FORMAT_FLOAT,
		SF_Double = SF_FORMAT_DOUBLE,
		SF_Vorbis = SF_FORMAT_VORBIS
	};

	enum DitherType {
		D_None = AudioGrapher::D_None,
		D_Rect = AudioGrapher::D_Rect,
		D_Tri = AudioGrapher::D_Tri,
		D_Shaped = AudioGrapher::D_Shaped
	};

	enum Quality {
		Q_None = 0,
		Q_Any,
		Q_LosslessLinear,
		Q_LosslessCompression,
		Q_LossyCompression
	};

	enum SampleRate {
		SR_None = 0,
		SR_Session = 1,
		SR_8 = 8000,
		SR_22_05 = 22050,
		SR_44_1 = 44100,
		SR_48 = 48000,
		SR_88_2 = 88200,
		SR_96 = 96000,
		SR_176_4 = 176400,
		SR_192 = 192000
	};

	enum SRCQuality {
		SRC_SincBest = SRC_SINC_BEST_QUALITY,
		SRC_SincMedium = SRC_SINC_MEDIUM_QUALITY,
		SRC_SincFast = SRC_SINC_FASTEST,
		SRC_ZeroOrderHold = SRC_ZERO_ORDER_HOLD,
		SRC_Linear = SRC_LINEAR
	};

	/// Class for managing selection and compatibility states
	class LIBARDOUR_API SelectableCompatible {
	  public:
		SelectableCompatible ()
			: _selected (false), _compatible (true) { }
		~SelectableCompatible () {}

		PBD::Signal1<void,bool> SelectChanged;
		PBD::Signal1<void,bool> CompatibleChanged;

		bool selected () const { return _selected; }
		bool compatible () const { return _compatible; }
		std::string name () const { return _name; }

		void set_selected (bool value);
		void set_compatible (bool value);

	  protected:
		void set_name (std::string name) { _name = name; }

	  private:
		bool _selected;
		bool _compatible;

		std::string _name;
	};

  public:

	ExportFormatBase ();
	ExportFormatBase (ExportFormatBase const & other);

	virtual ~ExportFormatBase ();

	boost::shared_ptr<ExportFormatBase> get_intersection (ExportFormatBase const & other) const;
	boost::shared_ptr<ExportFormatBase> get_union (ExportFormatBase const & other) const;

	bool endiannesses_empty () const { return endiannesses.empty (); }
	bool sample_formats_empty () const { return sample_formats.empty (); }
	bool sample_rates_empty () const { return sample_rates.empty (); }
	bool formats_empty () const { return format_ids.empty (); }
	bool qualities_empty () const { return qualities.empty (); }

	bool has_endianness (Endianness endianness) const { return endiannesses.find (endianness) != endiannesses.end() ; }
	bool has_sample_format (SampleFormat format) const { return sample_formats.find (format) != sample_formats.end(); }
	bool has_sample_rate (SampleRate rate) const { return sample_rates.find (rate) != sample_rates.end(); }
	bool has_format (FormatId format) const { return format_ids.find (format) != format_ids.end(); }
	bool has_quality (Quality quality) const { return qualities.find (quality) != qualities.end(); }

	void set_extension (std::string const & extension) { _extension = extension; }
	std::string const & extension () const { return _extension; }

	static SampleRate nearest_sample_rate (samplecnt_t sample_rate);

  protected:

	friend class HasSampleFormat;
	typedef std::set<SampleFormat> SampleFormatSet;
	SampleFormatSet sample_formats;

  protected:
	typedef std::set<Endianness> EndianSet;
	typedef std::set<SampleRate> SampleRateSet;
	typedef std::set<FormatId> FormatSet;
	typedef std::set<Quality> QualitySet;

	EndianSet       endiannesses;
	SampleRateSet   sample_rates;
	FormatSet       format_ids;
	QualitySet      qualities;

  private:

	std::string  _extension;

	enum SetOperation {
		SetUnion,
		SetIntersection
	};

	boost::shared_ptr<ExportFormatBase> do_set_operation (ExportFormatBase const & other, SetOperation operation) const;
};

} // namespace ARDOUR

#endif /* __ardour_export_format_base_h__ */