2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_export_formats_h__
22 #define __ardour_export_formats_h__
25 #include <boost/weak_ptr.hpp>
27 #include "pbd/failed_constructor.h"
28 #include "pbd/signals.h"
30 #include "ardour/export_format_base.h"
31 #include "ardour/export_format_compatibility.h"
36 class ExportFormatIncompatible : public failed_constructor {
38 virtual const char *what() const throw() { return "Export format constructor failed: Format incompatible with system"; }
41 /// Base class for formats
42 class ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
48 virtual bool set_compatibility_state (ExportFormatCompatibility const & compatibility) = 0;
49 virtual Type get_type () const = 0;
51 FormatId get_format_id () const { return *format_ids.begin(); }
52 Quality get_quality () const { return *qualities.begin(); }
54 bool has_sample_format ();
55 bool sample_format_is_compatible (SampleFormat format) const;
57 /* If the format has a specific sample format, this function should be overriden
58 * if the format has a selectable sample format, do not override this!
61 virtual SampleFormat get_explicit_sample_format () const { return SF_None; }
63 /* If the above is not overriden, this one should be */
65 virtual ExportFormat::SampleFormat default_sample_format () const { return SF_None; }
67 /* If the format has a channel count limit, override this */
69 virtual uint32_t get_channel_limit () const { return 256; }
71 /* If the format can be tagged with metadata override this */
73 virtual bool supports_tagging () const { return false; }
75 /* If the format contains broadcast info override this */
77 virtual bool has_broadcast_info () const { return false; }
81 void add_sample_rate (SampleRate rate) { sample_rates.insert (rate); }
82 void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
84 void set_format_id (FormatId id) { format_ids.clear (); format_ids.insert (id); }
85 void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
88 /// Class to be inherited by export formats that have a selectable sample format
89 class HasSampleFormat : public PBD::ScopedConnectionList {
92 class SampleFormatState : public ExportFormatBase::SelectableCompatible {
94 SampleFormatState (ExportFormatBase::SampleFormat format, std::string name)
100 ExportFormatBase::SampleFormat format;
103 class DitherTypeState : public ExportFormatBase::SelectableCompatible {
105 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
106 type (type) { set_name (name); }
108 ExportFormatBase::DitherType type;
111 typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
112 typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
113 typedef std::list<SampleFormatPtr> SampleFormatList;
115 typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
116 typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
117 typedef std::list<DitherTypePtr> DitherTypeList;
121 HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
122 virtual ~HasSampleFormat () {};
124 void add_sample_format (ExportFormatBase::SampleFormat format);
126 SampleFormatList const & get_sample_formats () const { return sample_format_states; }
127 DitherTypeList const & get_dither_types () const { return dither_type_states; }
129 SampleFormatPtr get_selected_sample_format ();
130 DitherTypePtr get_selected_dither_type ();
132 /* Proxies for signals from sample formats and dither types */
134 PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
135 PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
137 PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeSelectChanged;
138 PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
140 static std::string get_sample_format_name (ExportFormatBase::SampleFormat format);
145 DitherTypeList dither_type_states;
146 SampleFormatList sample_format_states;
149 /* Connected to signals */
151 void add_dither_type (ExportFormatBase::DitherType type, std::string name);
152 void update_sample_format_selection (bool);
153 void update_dither_type_selection (bool);
155 /* Reference to ExportFormatBase::sample_formats */
156 ExportFormatBase::SampleFormatSet & _sample_formats;
159 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
162 ExportFormatLinear (std::string name, FormatId format_id);
163 ~ExportFormatLinear () {};
165 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
166 Type get_type () const { return T_Sndfile; }
168 void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
170 void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
171 SampleFormat default_sample_format () const { return _default_sample_format; }
174 SampleFormat _default_sample_format;
177 class ExportFormatOggVorbis : public ExportFormat {
179 ExportFormatOggVorbis ();
180 ~ExportFormatOggVorbis () {};
182 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
183 Type get_type () const { return T_Sndfile; }
184 SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
185 virtual bool supports_tagging () const { return true; }
188 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
191 ~ExportFormatFLAC () {};
193 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
194 Type get_type () const { return T_Sndfile; }
196 uint32_t get_channel_limit () const { return 8; }
197 SampleFormat default_sample_format () const { return SF_16; }
198 virtual bool supports_tagging () const { return true; }
201 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
204 ~ExportFormatBWF () {};
206 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
207 Type get_type () const { return T_Sndfile; }
209 SampleFormat default_sample_format () const { return SF_16; }
210 virtual bool has_broadcast_info () const { return true; }
213 } // namespace ARDOUR
215 #endif /* __ardour_export_formats__ */