558223d75ac676edd4b0a4370ecdb7cb95458a11
[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
30 namespace ARDOUR
31 {
32
33 class HasSampleFormat;
34
35 /// Base class for formats
36 class ExportFormat : public ExportFormatBase, public ExportFormatBase::SelectableCompatible {
37
38   public:
39         ExportFormat () {};
40         ~ExportFormat () {};
41         
42         virtual bool set_compatibility_state (ExportFormatCompatibility const & compatibility) = 0;
43         virtual Type get_type () const = 0;
44         
45         FormatId get_format_id () const { return *format_ids.begin(); }
46         Quality get_quality () const { return *qualities.begin(); }
47         
48         bool has_sample_format ();
49         bool sample_format_is_compatible (SampleFormat format) const;
50         
51         /* If the format has a specific sample format, this function should be overriden
52          * if the format has a selectable sample format, do not override this!
53          */
54         
55         virtual SampleFormat get_explicit_sample_format () const { return SF_None; }
56
57         /* If the above is not overriden, this one should be */
58
59         virtual ExportFormat::SampleFormat default_sample_format () const { return SF_None; }
60         
61         /* If the format has a channel count limit, override this */
62         
63         virtual uint32_t get_channel_limit () const { return 256; }
64         
65         /* If the format can be tagged with metadata override this */
66         
67         virtual bool supports_tagging () const { return false; }
68         
69         /* If the format contains broadcast info override this */
70         
71         virtual bool has_broadcast_info () const { return false; }
72
73   protected:
74         
75         void add_sample_rate (SampleRate rate) { sample_rates.insert (rate); }
76         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
77         
78         void set_format_id (FormatId id) { format_ids.clear (); format_ids.insert (id); }
79         void set_quality (Quality value) { qualities.clear(); qualities.insert (value); }
80 };
81
82 /// Class to be inherited by export formats that have a selectable sample format
83 class HasSampleFormat {
84   public:
85
86         class SampleFormatState : public ExportFormatBase::SelectableCompatible {
87           public:
88                 SampleFormatState (ExportFormatBase::SampleFormat format, Glib::ustring name) :
89                   format (format) { set_name (name); }
90         
91                 ExportFormatBase::SampleFormat  format;
92         };
93
94         class DitherTypeState : public ExportFormatBase::SelectableCompatible {
95           public:
96                 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
97                   type (type) { set_name (name); }
98         
99                 ExportFormatBase::DitherType  type;
100         };
101         
102         typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
103         typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
104         typedef std::list<SampleFormatPtr> SampleFormatList;
105         
106         typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
107         typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
108         typedef std::list<DitherTypePtr> DitherTypeList;
109
110   public:
111
112         HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
113         virtual ~HasSampleFormat () {};
114
115         void add_sample_format (ExportFormatBase::SampleFormat format);
116         
117         SampleFormatList const & get_sample_formats () const { return sample_format_states; }
118         DitherTypeList const & get_dither_types () const { return dither_type_states; }
119         
120         SampleFormatPtr get_selected_sample_format ();
121         DitherTypePtr get_selected_dither_type ();
122         
123         /* Proxies for signals from sample formats and dither types */
124         
125         sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
126         sigc::signal<void, bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
127         
128         sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeSelectChanged;
129         sigc::signal<void, bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
130         
131         static string get_sample_format_name (ExportFormatBase::SampleFormat format);
132
133   protected:
134         /* State lists */
135
136         DitherTypeList    dither_type_states;
137         SampleFormatList  sample_format_states;
138
139   private:
140         /* Connected to signals */
141         
142         void add_dither_type (ExportFormatBase::DitherType type, Glib::ustring name);
143         void update_sample_format_selection (bool);
144         void update_dither_type_selection (bool);
145         
146         /* Reference to ExportFormatBase::sample_formats */
147         ExportFormatBase::SampleFormatSet & _sample_formats;
148 };
149
150 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
151   public:
152
153         ExportFormatLinear (Glib::ustring name, FormatId format_id);
154         ~ExportFormatLinear () {};
155         
156         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
157         Type get_type () const { return T_Sndfile; }
158         
159         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
160         
161         void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
162         SampleFormat default_sample_format () const { return _default_sample_format; }
163         
164   protected:
165         SampleFormat _default_sample_format;
166 };
167
168 class ExportFormatOggVorbis : public ExportFormat {
169   public:
170         ExportFormatOggVorbis ();
171         ~ExportFormatOggVorbis () {};
172         
173         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
174         Type get_type () const { return T_Sndfile; }
175         SampleFormat get_explicit_sample_format () const { return SF_Vorbis; }
176         virtual bool supports_tagging () const { return true; }
177 };
178
179 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
180   public:
181         ExportFormatFLAC ();
182         ~ExportFormatFLAC () {};
183         
184         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
185         Type get_type () const { return T_Sndfile; }
186         
187         uint32_t get_channel_limit () const { return 8; }
188         SampleFormat default_sample_format () const { return SF_16; }
189         virtual bool supports_tagging () const { return true; }
190 };
191
192 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
193   public:
194         ExportFormatBWF ();
195         ~ExportFormatBWF () {};
196         
197         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
198         Type get_type () const { return T_Sndfile; }
199         
200         SampleFormat default_sample_format () const { return SF_16; }
201         virtual bool has_broadcast_info () const { return true; }
202 };
203
204 } // namespace ARDOUR
205
206 #endif /* __ardour_export_formats__ */