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