remove Glib::ustring from libardour; allow any characters except '/' and '\' in paths...
[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 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 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 overriden
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 overriden, 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 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) { set_name (name); }
96
97                 ExportFormatBase::SampleFormat  format;
98         };
99
100         class DitherTypeState : public ExportFormatBase::SelectableCompatible {
101           public:
102                 DitherTypeState (ExportFormatBase::DitherType type, Glib::ustring name) :
103                   type (type) { set_name (name); }
104
105                 ExportFormatBase::DitherType  type;
106         };
107
108         typedef boost::shared_ptr<SampleFormatState> SampleFormatPtr;
109         typedef boost::weak_ptr<SampleFormatState> WeakSampleFormatPtr;
110         typedef std::list<SampleFormatPtr> SampleFormatList;
111
112         typedef boost::shared_ptr<DitherTypeState> DitherTypePtr;
113         typedef boost::weak_ptr<DitherTypeState> WeakDitherTypePtr;
114         typedef std::list<DitherTypePtr> DitherTypeList;
115
116   public:
117
118         HasSampleFormat (ExportFormatBase::SampleFormatSet & sample_formats);
119         virtual ~HasSampleFormat () {};
120
121         void add_sample_format (ExportFormatBase::SampleFormat format);
122
123         SampleFormatList const & get_sample_formats () const { return sample_format_states; }
124         DitherTypeList const & get_dither_types () const { return dither_type_states; }
125
126         SampleFormatPtr get_selected_sample_format ();
127         DitherTypePtr get_selected_dither_type ();
128
129         /* Proxies for signals from sample formats and dither types */
130
131         PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatSelectChanged;
132         PBD::Signal2<void,bool, WeakSampleFormatPtr> SampleFormatCompatibleChanged;
133
134         PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeSelectChanged;
135         PBD::Signal2<void,bool, WeakDitherTypePtr> DitherTypeCompatibleChanged;
136
137         static std::string get_sample_format_name (ExportFormatBase::SampleFormat format);
138
139   protected:
140         /* State lists */
141
142         DitherTypeList    dither_type_states;
143         SampleFormatList  sample_format_states;
144
145   private:
146         /* Connected to signals */
147
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);
151
152         /* Reference to ExportFormatBase::sample_formats */
153         ExportFormatBase::SampleFormatSet & _sample_formats;
154 };
155
156 class ExportFormatLinear : public ExportFormat, public HasSampleFormat {
157   public:
158
159         ExportFormatLinear (std::string name, FormatId format_id);
160         ~ExportFormatLinear () {};
161
162         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
163         Type get_type () const { return T_Sndfile; }
164
165         void add_endianness (Endianness endianness) { endiannesses.insert (endianness); }
166
167         void set_default_sample_format (SampleFormat sf) { _default_sample_format = sf; }
168         SampleFormat default_sample_format () const { return _default_sample_format; }
169
170   protected:
171         SampleFormat _default_sample_format;
172 };
173
174 class ExportFormatOggVorbis : public ExportFormat {
175   public:
176         ExportFormatOggVorbis ();
177         ~ExportFormatOggVorbis () {};
178
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; }
183 };
184
185 class ExportFormatFLAC : public ExportFormat, public HasSampleFormat {
186   public:
187         ExportFormatFLAC ();
188         ~ExportFormatFLAC () {};
189
190         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
191         Type get_type () const { return T_Sndfile; }
192
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; }
196 };
197
198 class ExportFormatBWF : public ExportFormat, public HasSampleFormat {
199   public:
200         ExportFormatBWF ();
201         ~ExportFormatBWF () {};
202
203         bool set_compatibility_state (ExportFormatCompatibility const & compatibility);
204         Type get_type () const { return T_Sndfile; }
205
206         SampleFormat default_sample_format () const { return SF_16; }
207         virtual bool has_broadcast_info () const { return true; }
208 };
209
210 } // namespace ARDOUR
211
212 #endif /* __ardour_export_formats__ */