2 Copyright (C) 2008 Paul Davis
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.
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.
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.
21 #include "ardour/export_format_base.h"
27 ExportFormatBase::SelectableCompatible::set_selected (bool value)
29 if (_selected != value) {
31 SelectChanged (value);
36 ExportFormatBase::SelectableCompatible::set_compatible (bool value)
38 if (_compatible != value) {
40 CompatibleChanged (value);
47 ExportFormatBase::ExportFormatBase ()
52 ExportFormatBase::ExportFormatBase (ExportFormatBase const & other) :
53 sample_formats (other.sample_formats),
54 endiannesses (other.endiannesses),
55 sample_rates (other.sample_rates),
56 format_ids (other.format_ids),
57 qualities (other.qualities)
62 ExportFormatBase::~ExportFormatBase ()
67 boost::shared_ptr<ExportFormatBase>
68 ExportFormatBase::get_intersection (ExportFormatBase const & other) const
70 return do_set_operation (other, SetIntersection);
73 boost::shared_ptr<ExportFormatBase>
74 ExportFormatBase::get_union (ExportFormatBase const & other) const
76 return do_set_operation (other, SetUnion);
79 boost::shared_ptr<ExportFormatBase>
80 ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation operation) const
82 boost::shared_ptr<ExportFormatBase> result (new ExportFormatBase ());
88 EndianSet::const_iterator start1 = endiannesses.begin();
89 EndianSet::const_iterator end1 = endiannesses.end();
90 EndianSet::const_iterator start2 = other.endiannesses.begin();
91 EndianSet::const_iterator end2 = other.endiannesses.end();
92 std::insert_iterator<EndianSet> insert (result->endiannesses, result->endiannesses.begin());
96 std::set_intersection (start1, end1, start2, end2, insert);
99 std::set_union (start1, end1, start2, end2, insert);
106 SampleFormatSet::const_iterator start1 = sample_formats.begin();
107 SampleFormatSet::const_iterator end1 = sample_formats.end();
108 SampleFormatSet::const_iterator start2 = other.sample_formats.begin();
109 SampleFormatSet::const_iterator end2 = other.sample_formats.end();
110 std::insert_iterator<SampleFormatSet> insert (result->sample_formats, result->sample_formats.begin());
113 case SetIntersection:
114 std::set_intersection (start1, end1, start2, end2, insert);
117 std::set_union (start1, end1, start2, end2, insert);
125 SampleRateSet::const_iterator start1 = sample_rates.begin();
126 SampleRateSet::const_iterator end1 = sample_rates.end();
127 SampleRateSet::const_iterator start2 = other.sample_rates.begin();
128 SampleRateSet::const_iterator end2 = other.sample_rates.end();
129 std::insert_iterator<SampleRateSet> insert (result->sample_rates, result->sample_rates.begin());
132 case SetIntersection:
133 std::set_intersection (start1, end1, start2, end2, insert);
136 std::set_union (start1, end1, start2, end2, insert);
143 FormatSet::const_iterator start1 = format_ids.begin();
144 FormatSet::const_iterator end1 = format_ids.end();
145 FormatSet::const_iterator start2 = other.format_ids.begin();
146 FormatSet::const_iterator end2 = other.format_ids.end();
147 std::insert_iterator<FormatSet> insert (result->format_ids, result->format_ids.begin());
150 case SetIntersection:
151 std::set_intersection (start1, end1, start2, end2, insert);
154 std::set_union (start1, end1, start2, end2, insert);
161 QualitySet::const_iterator start1 = qualities.begin();
162 QualitySet::const_iterator end1 = qualities.end();
163 QualitySet::const_iterator start2 = other.qualities.begin();
164 QualitySet::const_iterator end2 = other.qualities.end();
165 std::insert_iterator<QualitySet> insert (result->qualities, result->qualities.begin());
168 case SetIntersection:
169 std::set_intersection (start1, end1, start2, end2, insert);
172 std::set_union (start1, end1, start2, end2, insert);
180 ExportFormatBase::SampleRate
181 ExportFormatBase::nearest_sample_rate (framecnt_t sample_rate)
184 int smallest_diff = INT_MAX;
185 SampleRate best_match = SR_None;
187 #define DO_SR_COMPARISON(rate) \
188 diff = std::fabs((rate) - sample_rate); \
189 if(diff < smallest_diff) { \
190 smallest_diff = diff; \
191 best_match = (rate); \
194 DO_SR_COMPARISON(SR_8);
195 DO_SR_COMPARISON(SR_22_05);
196 DO_SR_COMPARISON(SR_44_1);
197 DO_SR_COMPARISON(SR_48);
198 DO_SR_COMPARISON(SR_88_2);
199 DO_SR_COMPARISON(SR_96);
200 DO_SR_COMPARISON(SR_192);
203 #undef DO_SR_COMPARISON
206 }; // namespace ARDOUR