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__
24 #include <ardour/export_format_base.h>
25 #include <ardour/export_format_compatibility.h>
28 #include <boost/weak_ptr.hpp>
29 #include <pbd/failed_constructor.h>
34 class ExportFormatIncompatible : public failed_constructor {
36 virtual const char *what() const throw() { return "Export format constructor failed: Format incompatible with system"; }
39 /// Base class for formats
40 class ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
46 virtual bool set_compatibility_state (ExportFormatCompatibility const & compatibility) = 0;
47 virtual Type get_type () const = 0;
49 FormatId get_format_id () const { return *format_ids.begin(); }
50 Quality get_quality () const { return *qualities.begin(); }
52 bool has_sample_format ();
53 bool sample_format_is_compatible (SampleFormat format) const;
55 /* If the format has a specific sample format, this function should be overriden
56 * if the format has a selectable sample format, do not override this!
59 virtual SampleFormat get_explicit_sample_format () const { return SF_None; }
61 /* If the above is not overriden, this one should be */
63 virtual ExportFormat::SampleFormat default_sample_format () const { return SF_None; }
65 /* If the format has a channel count limit, override this */
67 virtual uint32_t get_channel_limit () const { return 256; }
69 /* If the format can be tagged with metadata override this */
71 virtual bool supports_tagging () const { return false; }
73 /* If the format contains broadcast info override this */
75 virtual bool has_broadcast_info () const { return false; }
79 void add_sample_rate (SampleRate rate) { sample_rates.insert (rate); }
80 void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
82 void set_format_id (FormatId id) { format_ids.clear (); format_ids.insert (id); }
83 void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
86 /// Class to be inherited by export formats that have a selectable sample format
87 class HasSampleFormat {
90 class SampleFormatState : public ExportFormatBase::SelectableCompatible {
92 SampleFormatState (ExportFormatBase::SampleFormat format, Glib::ustring name) :
93 format (format) { set_name (name); }
95 ExportFormatBase::SampleFormat format;
98 class DitherTypeState : public ExportFormatBase::SelectableCompatible {
100 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
101 type (type) { set_name (name); }
103 ExportFormatBase::DitherType type;
106 typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
107 typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
108 typedef std::list<SampleFormatPtr> SampleFormatList;
110 typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
111 typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
112 typedef std::list<DitherTypePtr> DitherTypeList;
116 HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
117 virtual ~HasSampleFormat () {};
119 void add_sample_format (ExportFormatBase::SampleFormat format);
121 SampleFormatList const & get_sample_formats () const { return sample_format_states; }
122 DitherTypeList const & get_dither_types () const { return dither_type_states; }
124 SampleFormatPtr get_selected_sample_format ();
125 DitherTypePtr get_selected_dither_type ();
127 /* Proxies for signals from sample formats and dither types */
129 sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
130 sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
132 sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeSelectChanged;
133 sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
135 static string get_sample_format_name (ExportFormatBase::SampleFormat format);
140 DitherTypeList dither_type_states;
141 SampleFormatList sample_format_states;
144 /* Connected to signals */
146 void add_dither_type (ExportFormatBase::DitherType type, Glib::ustring name);
147 void update_sample_format_selection (bool);
148 void update_dither_type_selection (bool);
150 /* Reference to ExportFormatBase::sample_formats */
151 ExportFormatBase::SampleFormatSet & _sample_formats;
154 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
157 ExportFormatLinear (Glib::ustring name, FormatId format_id);
158 ~ExportFormatLinear () {};
160 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
161 Type get_type () const { return T_Sndfile; }
163 void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
165 void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
166 SampleFormat default_sample_format () const { return _default_sample_format; }
169 SampleFormat _default_sample_format;
172 class ExportFormatOggVorbis : public ExportFormat {
174 ExportFormatOggVorbis ();
175 ~ExportFormatOggVorbis () {};
177 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
178 Type get_type () const { return T_Sndfile; }
179 SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
180 virtual bool supports_tagging () const { return true; }
183 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
186 ~ExportFormatFLAC () {};
188 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
189 Type get_type () const { return T_Sndfile; }
191 uint32_t get_channel_limit () const { return 8; }
192 SampleFormat default_sample_format () const { return SF_16; }
193 virtual bool supports_tagging () const { return true; }
196 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
199 ~ExportFormatBWF () {};
201 bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
202 Type get_type () const { return T_Sndfile; }
204 SampleFormat default_sample_format () const { return SF_16; }
205 virtual bool has_broadcast_info () const { return true; }
208 } // namespace ARDOUR
210 #endif /* __ardour_export_formats__ */