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) :
95 format (format) { set_name (name); }
97 ExportFormatBase::SampleFormat format;
100 class DitherTypeState : public ExportFormatBase::SelectableCompatible {
102 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
103 type (type) { set_name (name); }
105 ExportFormatBase::DitherType type;
108 typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
109 typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
110 typedef std::list<SampleFormatPtr> SampleFormatList;
112 typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
113 typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
114 typedef std::list<DitherTypePtr> DitherTypeList;
118 HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
119 virtual ~HasSampleFormat () {};
121 void add_sample_format (ExportFormatBase::SampleFormat format);
123 SampleFormatList const & get_sample_formats () const { return sample_format_states; }
124 DitherTypeList const & get_dither_types () const { return dither_type_states; }
126 SampleFormatPtr get_selected_sample_format ();
127 DitherTypePtr get_selected_dither_type ();
129 /* Proxies for signals from sample formats and dither types */
131 PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
132 PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
134 PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeSelectChanged;
135 PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
137 static std::string get_sample_format_name (ExportFormatBase::SampleFormat format);
142 DitherTypeList dither_type_states;
143 SampleFormatList sample_format_states;
146 /* Connected to signals */
148 void add_dither_type (ExportFormatBase::DitherType type, std::string name);
149 void update_sample_format_selection (bool);
150 void update_dither_type_selection (bool);
152 /* Reference to ExportFormatBase::sample_formats */
153 ExportFormatBase::SampleFormatSet & _sample_formats;
156 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
159 ExportFormatLinear (std::string name, FormatId format_id);
160 ~ExportFormatLinear () {};
162 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
163 Type get_type () const { return T_Sndfile; }
165 void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
167 void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
168 SampleFormat default_sample_format () const { return _default_sample_format; }
171 SampleFormat _default_sample_format;
174 class ExportFormatOggVorbis : public ExportFormat {
176 ExportFormatOggVorbis ();
177 ~ExportFormatOggVorbis () {};
179 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
180 Type get_type () const { return T_Sndfile; }
181 SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
182 virtual bool supports_tagging () const { return true; }
185 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
188 ~ExportFormatFLAC () {};
190 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
191 Type get_type () const { return T_Sndfile; }
193 uint32_t get_channel_limit () const { return 8; }
194 SampleFormat default_sample_format () const { return SF_16; }
195 virtual bool supports_tagging () const { return true; }
198 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
201 ~ExportFormatBWF () {};
203 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
204 Type get_type () const { return T_Sndfile; }
206 SampleFormat default_sample_format () const { return SF_16; }
207 virtual bool has_broadcast_info () const { return true; }
210 } // namespace ARDOUR
212 #endif /* __ardour_export_formats__ */