*** NEW CODING POLICY ***
[ardour.git] / libs / ardour / ardour / export_formats.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_export_formats_h__
22 #define __ardour_export_formats_h__
23
24 #include "ardour/export_format_base.h"
25 #include "ardour/export_format_compatibility.h"
26
27 #include <list>
28 #include <boost/weak_ptr.hpp>
29 #include "pbd/failed_constructor.h"
30
31 namespace ARDOUR
32 {
33
34 class ExportFormatIncompatible : public failed_constructor {
35   public:
36         virtual const char *what() const throw() { return "Export format constructor failed: Format incompatible with system"; }
37 };
38
39 /// Base class for formats
40 class ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
41
42   public:
43         ExportFormat () {};
44         ~ExportFormat () {};
45         
46         virtual bool set_compatibility_state (ExportFormatCompatibility const & compatibility) = 0;
47         virtual Type get_type () const = 0;
48         
49         FormatId get_format_id () const { return *format_ids.begin(); }
50         Quality get_quality () const { return *qualities.begin(); }
51         
52         bool has_sample_format ();
53         bool sample_format_is_compatible (SampleFormat format) const;
54         
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!
57          */
58         
59         virtual SampleFormat get_explicit_sample_format () const { return SF_None; }
60
61         /* If the above is not overriden, this one should be */
62
63         virtual ExportFormat::SampleFormat default_sample_format () const { return SF_None; }
64         
65         /* If the format has a channel count limit, override this */
66         
67         virtual uint32_t get_channel_limit () const { return 256; }
68         
69         /* If the format can be tagged with metadata override this */
70         
71         virtual bool supports_tagging () const { return false; }
72         
73         /* If the format contains broadcast info override this */
74         
75         virtual bool has_broadcast_info () const { return false; }
76
77   protected:
78         
79         void add_sample_rate (SampleRate rate) { sample_rates.insert (rate); }
80         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
81         
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); }
84 };
85
86 /// Class to be inherited by export formats that have a selectable sample format
87 class HasSampleFormat {
88   public:
89
90         class SampleFormatState : public ExportFormatBase::SelectableCompatible {
91           public:
92                 SampleFormatState (ExportFormatBase::SampleFormat format, Glib::ustring name) :
93                   format (format) { set_name (name); }
94         
95                 ExportFormatBase::SampleFormat  format;
96         };
97
98         class DitherTypeState : public ExportFormatBase::SelectableCompatible {
99           public:
100                 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
101                   type (type) { set_name (name); }
102         
103                 ExportFormatBase::DitherType  type;
104         };
105         
106         typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
107         typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
108         typedef std::list<SampleFormatPtr> SampleFormatList;
109         
110         typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
111         typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
112         typedef std::list<DitherTypePtr> DitherTypeList;
113
114   public:
115
116         HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
117         virtual ~HasSampleFormat () {};
118
119         void add_sample_format (ExportFormatBase::SampleFormat format);
120         
121         SampleFormatList const & get_sample_formats () const { return sample_format_states; }
122         DitherTypeList const & get_dither_types () const { return dither_type_states; }
123         
124         SampleFormatPtr get_selected_sample_format ();
125         DitherTypePtr get_selected_dither_type ();
126         
127         /* Proxies for signals from sample formats and dither types */
128         
129         sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
130         sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
131         
132         sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeSelectChanged;
133         sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
134         
135         static string get_sample_format_name (ExportFormatBase::SampleFormat format);
136
137   protected:
138         /* State lists */
139
140         DitherTypeList    dither_type_states;
141         SampleFormatList  sample_format_states;
142
143   private:
144         /* Connected to signals */
145         
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);
149         
150         /* Reference to ExportFormatBase::sample_formats */
151         ExportFormatBase::SampleFormatSet & _sample_formats;
152 };
153
154 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
155   public:
156
157         ExportFormatLinear (Glib::ustring name, FormatId format_id);
158         ~ExportFormatLinear () {};
159         
160         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
161         Type get_type () const { return T_Sndfile; }
162         
163         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
164         
165         void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
166         SampleFormat default_sample_format () const { return _default_sample_format; }
167         
168   protected:
169         SampleFormat _default_sample_format;
170 };
171
172 class ExportFormatOggVorbis : public ExportFormat {
173   public:
174         ExportFormatOggVorbis ();
175         ~ExportFormatOggVorbis () {};
176         
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; }
181 };
182
183 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
184   public:
185         ExportFormatFLAC ();
186         ~ExportFormatFLAC () {};
187         
188         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
189         Type get_type () const { return T_Sndfile; }
190         
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; }
194 };
195
196 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
197   public:
198         ExportFormatBWF ();
199         ~ExportFormatBWF () {};
200         
201         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
202         Type get_type () const { return T_Sndfile; }
203         
204         SampleFormat default_sample_format () const { return SF_16; }
205         virtual bool has_broadcast_info () const { return true; }
206 };
207
208 } // namespace ARDOUR
209
210 #endif /* __ardour_export_formats__ */