ardour
export_format_base.cc
Go to the documentation of this file.
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 
22 
23 namespace ARDOUR
24 {
25 
26 void
28 {
29  if (_selected != value) {
30  _selected = value;
31  SelectChanged (value);
32  }
33 }
34 
35 void
37 {
38  if (_compatible != value) {
39  _compatible = value;
40  CompatibleChanged (value);
41  }
42  if (!value) {
43  set_selected (false);
44  }
45 }
46 
48 {
49 
50 }
51 
54  endiannesses (other.endiannesses),
55  sample_rates (other.sample_rates),
56  format_ids (other.format_ids),
57  qualities (other.qualities)
58 {
59 
60 }
61 
63 {
64 
65 }
66 
69 {
70  return do_set_operation (other, SetIntersection);
71 }
72 
75 {
76  return do_set_operation (other, SetUnion);
77 }
78 
81 {
83 
84  /* Sets */
85 
86  // Endiannesses
87  {
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());
93 
94  switch (operation) {
95  case SetIntersection:
96  std::set_intersection (start1, end1, start2, end2, insert);
97  break;
98  case SetUnion:
99  std::set_union (start1, end1, start2, end2, insert);
100  break;
101  }
102  }
103 
104  // Sample formats
105  {
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());
111 
112  switch (operation) {
113  case SetIntersection:
114  std::set_intersection (start1, end1, start2, end2, insert);
115  break;
116  case SetUnion:
117  std::set_union (start1, end1, start2, end2, insert);
118  break;
119  }
120  }
121 
122 
123  // Sample rates
124  {
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());
130 
131  switch (operation) {
132  case SetIntersection:
133  std::set_intersection (start1, end1, start2, end2, insert);
134  break;
135  case SetUnion:
136  std::set_union (start1, end1, start2, end2, insert);
137  break;
138  }
139  }
140 
141  // Format ids
142  {
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());
148 
149  switch (operation) {
150  case SetIntersection:
151  std::set_intersection (start1, end1, start2, end2, insert);
152  break;
153  case SetUnion:
154  std::set_union (start1, end1, start2, end2, insert);
155  break;
156  }
157  }
158 
159  // Qualities
160  {
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());
166 
167  switch (operation) {
168  case SetIntersection:
169  std::set_intersection (start1, end1, start2, end2, insert);
170  break;
171  case SetUnion:
172  std::set_union (start1, end1, start2, end2, insert);
173  break;
174  }
175  }
176 
177  return result;
178 }
179 
182 {
183  int diff = 0;
184  int smallest_diff = INT_MAX;
185  SampleRate best_match = SR_None;
186 
187  #define DO_SR_COMPARISON(rate) \
188  diff = std::fabs((double)((rate) - sample_rate)); \
189  if(diff < smallest_diff) { \
190  smallest_diff = diff; \
191  best_match = (rate); \
192  }
193 
201 
202  return best_match;
203  #undef DO_SR_COMPARISON
204 }
205 
206 }; // namespace ARDOUR
static SampleRate nearest_sample_rate(framecnt_t sample_rate)
boost::shared_ptr< ExportFormatBase > get_intersection(ExportFormatBase const &other) const
int64_t framecnt_t
Definition: types.h:76
#define DO_SR_COMPARISON(rate)
Definition: amp.h:29
boost::shared_ptr< ExportFormatBase > do_set_operation(ExportFormatBase const &other, SetOperation operation) const
boost::shared_ptr< ExportFormatBase > get_union(ExportFormatBase const &other) const