4cf68edaa8a984d8cd8ee562b94d2381540ddce7
[ardour.git] / libs / ardour / ardour / export_format_manager.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_format_manager_h__
22 #define __ardour_export_format_manager_h__
23
24 #include <list>
25 #include <string>
26
27 #include <boost/shared_ptr.hpp>
28 #include <boost/weak_ptr.hpp>
29 #include <sigc++/signal.h>
30 #include <sigc++/trackable.h>
31
32 #include "ardour/export_formats.h"
33
34 using std::string;
35
36 namespace ARDOUR
37 {
38
39 class ExportFormat;
40 class ExportFormatCompatibility;
41 class ExportFormatSpecification;
42 class AnyTime;
43
44 class ExportFormatManager : public sigc::trackable
45 {
46   public:
47
48         typedef boost::shared_ptr<ExportFormatCompatibility> CompatPtr;
49         typedef boost::weak_ptr<ExportFormatCompatibility> WeakCompatPtr;
50         typedef std::list<CompatPtr> CompatList;
51         
52         typedef boost::shared_ptr<ExportFormat> FormatPtr;
53         typedef boost::weak_ptr<ExportFormat> WeakFormatPtr;
54         typedef std::list<FormatPtr> FormatList;
55         
56         typedef HasSampleFormat::SampleFormatPtr SampleFormatPtr;
57         typedef HasSampleFormat::SampleFormatList SampleFormatList;
58         typedef HasSampleFormat::WeakSampleFormatPtr WeakSampleFormatPtr;
59         
60         typedef HasSampleFormat::DitherTypePtr DitherTypePtr;
61         typedef HasSampleFormat::WeakDitherTypePtr WeakDitherTypePtr;
62         
63         typedef boost::shared_ptr<ExportFormatSpecification> SpecPtr;
64         typedef boost::shared_ptr<ExportFormatBase> FormatBasePtr;
65         
66         /* Quality states */
67         
68         class QualityState : public ExportFormatBase::SelectableCompatible {
69           public:
70                 QualityState (ExportFormatBase::Quality quality, Glib::ustring name) :
71                   quality (quality) { set_name (name); }
72                 ExportFormatBase::Quality  quality;
73         };
74         typedef boost::shared_ptr<QualityState> QualityPtr;
75         typedef boost::weak_ptr<QualityState> WeakQualityPtr;
76         typedef std::list<QualityPtr> QualityList;
77         
78         /* Sample rate states */
79         
80         class SampleRateState : public ExportFormatBase::SelectableCompatible {
81           public:
82                 SampleRateState (ExportFormatBase::SampleRate rate, Glib::ustring name) :
83                   rate (rate) { set_name (name); }
84                 ExportFormatBase::SampleRate  rate;
85         };
86         typedef boost::shared_ptr<SampleRateState> SampleRatePtr;
87         typedef boost::weak_ptr<SampleRateState> WeakSampleRatePtr;
88         typedef std::list<SampleRatePtr> SampleRateList;
89
90   public:
91
92         explicit ExportFormatManager (SpecPtr specification);
93         ~ExportFormatManager ();
94
95         /* Signals */
96
97         sigc::signal<void, bool> CompleteChanged;
98
99         /* Access to lists */
100
101         CompatList const & get_compatibilities () { return compatibilities; }
102         QualityList const & get_qualities () { return qualities; }
103         FormatList const & get_formats () { return formats; }
104         SampleRateList const & get_sample_rates () { return sample_rates; }
105         
106         /* Non interactive selections */
107         
108         void set_name (Glib::ustring name);
109         
110         void select_src_quality (ExportFormatBase::SRCQuality value);
111         void select_trim_beginning (bool value);
112         void select_silence_beginning (AnyTime const & time);
113         void select_trim_end (bool value);
114         void select_silence_end (AnyTime const & time);
115         void select_normalize (bool value);
116         void select_normalize_target (float value);
117         void select_tagging (bool tag);
118
119   private:
120
121         void init_compatibilities ();
122         void init_qualities ();
123         void init_formats ();
124         void init_sample_rates ();
125
126         void add_compatibility (CompatPtr ptr);
127         void add_quality (QualityPtr ptr);
128         void add_format (FormatPtr ptr);
129         void add_sample_rate (SampleRatePtr ptr);
130
131         /* Connected to signals */
132         
133         void change_compatibility_selection (bool select, WeakCompatPtr const & compat);
134         void change_quality_selection (bool select, WeakQualityPtr const & quality);
135         void change_format_selection (bool select, WeakFormatPtr const & format);
136         void change_sample_rate_selection (bool select, WeakSampleRatePtr const & rate);
137         
138         void change_sample_format_selection (bool select, WeakSampleFormatPtr const & format);
139         void change_dither_type_selection (bool select, WeakDitherTypePtr const & type);
140         
141         /* Do actual selection */
142         
143         void select_compatibility (WeakCompatPtr const & compat);
144         void select_quality (QualityPtr const & quality);
145         void select_format (FormatPtr const & format);
146         void select_sample_rate (SampleRatePtr const & rate);
147         
148         void select_sample_format (SampleFormatPtr const & format);
149         void select_dither_type (DitherTypePtr const & type);
150         
151         bool pending_selection_change;
152         void selection_changed ();
153         
154         /* Formats and compatibilities */
155         
156         QualityPtr    get_selected_quality ();
157         FormatPtr     get_selected_format ();
158         SampleRatePtr get_selected_sample_rate ();
159         
160         SampleFormatPtr get_selected_sample_format ();
161         
162         FormatBasePtr get_compatibility_intersection ();
163         
164         FormatBasePtr   universal_set;
165         SpecPtr         current_selection;
166         
167         CompatList      compatibilities;
168         QualityList     qualities;
169         FormatList      formats;
170         SampleRateList  sample_rates;
171
172 };
173
174 } // namespace ARDOUR
175
176 #endif /* __ardour_export_format_manager_h__ */