Chris@297
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@297
|
2
|
Chris@297
|
3 /*
|
Chris@297
|
4 Sonic Visualiser
|
Chris@297
|
5 An audio file viewer and annotation editor.
|
Chris@297
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@297
|
7 This file copyright 2007 QMUL.
|
Chris@297
|
8
|
Chris@297
|
9 This program is free software; you can redistribute it and/or
|
Chris@297
|
10 modify it under the terms of the GNU General Public License as
|
Chris@297
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@297
|
12 License, or (at your option) any later version. See the file
|
Chris@297
|
13 COPYING included with this distribution for more information.
|
Chris@297
|
14 */
|
Chris@297
|
15
|
Chris@297
|
16 #include "AggregateWaveModel.h"
|
Chris@297
|
17
|
Chris@297
|
18 #include <iostream>
|
Chris@297
|
19
|
Chris@314
|
20 #include <QTextStream>
|
Chris@314
|
21
|
Chris@1096
|
22 using namespace std;
|
Chris@1096
|
23
|
Chris@297
|
24 PowerOfSqrtTwoZoomConstraint
|
Chris@297
|
25 AggregateWaveModel::m_zoomConstraint;
|
Chris@297
|
26
|
Chris@297
|
27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
|
Chris@1389
|
28 m_components(channelSpecs),
|
Chris@1389
|
29 m_invalidated(false)
|
Chris@297
|
30 {
|
Chris@297
|
31 for (ChannelSpecList::const_iterator i = channelSpecs.begin();
|
Chris@297
|
32 i != channelSpecs.end(); ++i) {
|
Chris@1389
|
33
|
Chris@1389
|
34 connect(i->model, SIGNAL(aboutToBeDeleted()),
|
Chris@1389
|
35 this, SLOT(componentModelAboutToBeDeleted()));
|
Chris@1389
|
36
|
Chris@297
|
37 if (i->model->getSampleRate() !=
|
Chris@297
|
38 channelSpecs.begin()->model->getSampleRate()) {
|
Chris@690
|
39 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl;
|
Chris@297
|
40 break;
|
Chris@297
|
41 }
|
Chris@297
|
42 }
|
Chris@297
|
43 }
|
Chris@297
|
44
|
Chris@297
|
45 AggregateWaveModel::~AggregateWaveModel()
|
Chris@297
|
46 {
|
Chris@297
|
47 }
|
Chris@297
|
48
|
Chris@1389
|
49 void
|
Chris@1389
|
50 AggregateWaveModel::componentModelAboutToBeDeleted()
|
Chris@1389
|
51 {
|
Chris@1389
|
52 SVDEBUG << "AggregateWaveModel::componentModelAboutToBeDeleted: invalidating"
|
Chris@1389
|
53 << endl;
|
Chris@1389
|
54 m_components.clear();
|
Chris@1389
|
55 m_invalidated = true;
|
Chris@1389
|
56 }
|
Chris@1389
|
57
|
Chris@297
|
58 bool
|
Chris@297
|
59 AggregateWaveModel::isOK() const
|
Chris@297
|
60 {
|
Chris@1389
|
61 if (m_invalidated) {
|
Chris@1389
|
62 return false;
|
Chris@1389
|
63 }
|
Chris@297
|
64 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
65 i != m_components.end(); ++i) {
|
Chris@1389
|
66 if (!i->model->isOK()) {
|
Chris@1389
|
67 return false;
|
Chris@1389
|
68 }
|
Chris@297
|
69 }
|
Chris@297
|
70 return true;
|
Chris@297
|
71 }
|
Chris@297
|
72
|
Chris@297
|
73 bool
|
Chris@297
|
74 AggregateWaveModel::isReady(int *completion) const
|
Chris@297
|
75 {
|
Chris@297
|
76 if (completion) *completion = 100;
|
Chris@1389
|
77
|
Chris@297
|
78 bool ready = true;
|
Chris@297
|
79 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
80 i != m_components.end(); ++i) {
|
Chris@297
|
81 int completionHere = 100;
|
Chris@297
|
82 if (!i->model->isReady(&completionHere)) ready = false;
|
Chris@297
|
83 if (completion && completionHere < *completion) {
|
Chris@297
|
84 *completion = completionHere;
|
Chris@297
|
85 }
|
Chris@297
|
86 }
|
Chris@297
|
87 return ready;
|
Chris@297
|
88 }
|
Chris@297
|
89
|
Chris@1038
|
90 sv_frame_t
|
Chris@297
|
91 AggregateWaveModel::getFrameCount() const
|
Chris@297
|
92 {
|
Chris@1038
|
93 sv_frame_t count = 0;
|
Chris@297
|
94 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
95 i != m_components.end(); ++i) {
|
Chris@1389
|
96 sv_frame_t thisCount =
|
Chris@1389
|
97 i->model->getEndFrame() - i->model->getStartFrame();
|
Chris@297
|
98 if (thisCount > count) count = thisCount;
|
Chris@297
|
99 }
|
Chris@297
|
100 return count;
|
Chris@297
|
101 }
|
Chris@297
|
102
|
Chris@929
|
103 int
|
Chris@297
|
104 AggregateWaveModel::getChannelCount() const
|
Chris@297
|
105 {
|
Chris@1038
|
106 return int(m_components.size());
|
Chris@297
|
107 }
|
Chris@297
|
108
|
Chris@1040
|
109 sv_samplerate_t
|
Chris@297
|
110 AggregateWaveModel::getSampleRate() const
|
Chris@297
|
111 {
|
Chris@297
|
112 if (m_components.empty()) return 0;
|
Chris@297
|
113 return m_components.begin()->model->getSampleRate();
|
Chris@297
|
114 }
|
Chris@297
|
115
|
Chris@1326
|
116 floatvec_t
|
Chris@1096
|
117 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
|
Chris@297
|
118 {
|
Chris@297
|
119 int ch0 = channel, ch1 = channel;
|
Chris@297
|
120 if (channel == -1) {
|
Chris@297
|
121 ch0 = 0;
|
Chris@297
|
122 ch1 = getChannelCount()-1;
|
Chris@297
|
123 }
|
Chris@297
|
124
|
Chris@1326
|
125 floatvec_t result(count, 0.f);
|
Chris@1038
|
126 sv_frame_t longest = 0;
|
Chris@1008
|
127
|
Chris@297
|
128 for (int c = ch0; c <= ch1; ++c) {
|
Chris@1096
|
129
|
Chris@1096
|
130 auto here = m_components[c].model->getData(m_components[c].channel,
|
Chris@1096
|
131 start, count);
|
Chris@1100
|
132 if (sv_frame_t(here.size()) > longest) {
|
Chris@1100
|
133 longest = sv_frame_t(here.size());
|
Chris@1008
|
134 }
|
Chris@1096
|
135 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
|
Chris@1096
|
136 result[i] += here[i];
|
Chris@297
|
137 }
|
Chris@297
|
138 }
|
Chris@297
|
139
|
Chris@1096
|
140 result.resize(longest);
|
Chris@1096
|
141 return result;
|
Chris@297
|
142 }
|
Chris@363
|
143
|
Chris@1326
|
144 vector<floatvec_t>
|
Chris@1086
|
145 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
|
Chris@1096
|
146 sv_frame_t start, sv_frame_t count) const
|
Chris@363
|
147 {
|
Chris@1038
|
148 sv_frame_t min = count;
|
Chris@363
|
149
|
Chris@1326
|
150 vector<floatvec_t> result;
|
Chris@1096
|
151
|
Chris@929
|
152 for (int c = fromchannel; c <= tochannel; ++c) {
|
Chris@1096
|
153 auto here = getData(c, start, count);
|
Chris@1100
|
154 if (sv_frame_t(here.size()) < min) {
|
Chris@1100
|
155 min = sv_frame_t(here.size());
|
Chris@1100
|
156 }
|
Chris@1096
|
157 result.push_back(here);
|
Chris@1096
|
158 }
|
Chris@1096
|
159
|
Chris@1096
|
160 if (min < count) {
|
Chris@1096
|
161 for (auto &v : result) v.resize(min);
|
Chris@363
|
162 }
|
Chris@363
|
163
|
Chris@1096
|
164 return result;
|
Chris@363
|
165 }
|
Chris@377
|
166
|
Chris@929
|
167 int
|
Chris@929
|
168 AggregateWaveModel::getSummaryBlockSize(int desired) const
|
Chris@377
|
169 {
|
Chris@377
|
170 //!!! complete
|
Chris@377
|
171 return desired;
|
Chris@377
|
172 }
|
Chris@297
|
173
|
Chris@297
|
174 void
|
Chris@1038
|
175 AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
|
Chris@929
|
176 RangeBlock &, int &) const
|
Chris@297
|
177 {
|
Chris@297
|
178 //!!! complete
|
Chris@297
|
179 }
|
Chris@297
|
180
|
Chris@297
|
181 AggregateWaveModel::Range
|
Chris@1038
|
182 AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
|
Chris@297
|
183 {
|
Chris@297
|
184 //!!! complete
|
Chris@297
|
185 return Range();
|
Chris@297
|
186 }
|
Chris@297
|
187
|
Chris@929
|
188 int
|
Chris@297
|
189 AggregateWaveModel::getComponentCount() const
|
Chris@297
|
190 {
|
Chris@1038
|
191 return int(m_components.size());
|
Chris@297
|
192 }
|
Chris@297
|
193
|
Chris@297
|
194 AggregateWaveModel::ModelChannelSpec
|
Chris@929
|
195 AggregateWaveModel::getComponent(int c) const
|
Chris@297
|
196 {
|
Chris@297
|
197 return m_components[c];
|
Chris@297
|
198 }
|
Chris@297
|
199
|
Chris@297
|
200 void
|
Chris@297
|
201 AggregateWaveModel::componentModelChanged()
|
Chris@297
|
202 {
|
Chris@297
|
203 emit modelChanged();
|
Chris@297
|
204 }
|
Chris@297
|
205
|
Chris@297
|
206 void
|
Chris@1038
|
207 AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
|
Chris@297
|
208 {
|
Chris@947
|
209 emit modelChangedWithin(start, end);
|
Chris@297
|
210 }
|
Chris@297
|
211
|
Chris@297
|
212 void
|
Chris@297
|
213 AggregateWaveModel::componentModelCompletionChanged()
|
Chris@297
|
214 {
|
Chris@297
|
215 emit completionChanged();
|
Chris@297
|
216 }
|
Chris@297
|
217
|
Chris@297
|
218 void
|
Chris@929
|
219 AggregateWaveModel::toXml(QTextStream &,
|
Chris@929
|
220 QString ,
|
Chris@929
|
221 QString ) const
|
Chris@297
|
222 {
|
Chris@297
|
223 //!!! complete
|
Chris@297
|
224 }
|
Chris@297
|
225
|