annotate data/model/AggregateWaveModel.cpp @ 1765:2e2497cba59e by-id

Remove comment - these are now connected
author Chris Cannam
date Wed, 17 Jul 2019 12:59:57 +0100
parents 87b4c596c0ef
children dffc70996f54
rev   line source
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@1556 24 //#define DEBUG_AGGREGATE_WAVE_FILE_MODEL 1
Chris@1556 25
Chris@297 26 PowerOfSqrtTwoZoomConstraint
Chris@297 27 AggregateWaveModel::m_zoomConstraint;
Chris@297 28
Chris@297 29 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
Chris@1732 30 m_components(channelSpecs)
Chris@297 31 {
Chris@1732 32 sv_samplerate_t overallRate = 0;
Chris@1389 33
Chris@1732 34 for (int channel = 0; in_range_for(m_components, channel); ++channel) {
Chris@1732 35
Chris@1732 36 auto model = ModelById::getAs<RangeSummarisableTimeValueModel>
Chris@1732 37 (m_components[channel].model);
Chris@1732 38
Chris@1732 39 if (!model) {
Chris@1732 40 SVCERR << "AggregateWaveModel: WARNING: component for channel "
Chris@1732 41 << channel << " is not found or is of wrong model type"
Chris@1732 42 << endl;
Chris@1732 43 continue;
Chris@1732 44 }
Chris@1732 45
Chris@1732 46 sv_samplerate_t rate = model->getSampleRate();
Chris@1732 47
Chris@1732 48 if (!rate) {
Chris@1732 49 SVCERR << "AggregateWaveModel: WARNING: component for channel "
Chris@1732 50 << channel << " reports zero sample rate" << endl;
Chris@1732 51
Chris@1732 52 } else if (!overallRate) {
Chris@1732 53
Chris@1732 54 overallRate = rate;
Chris@1732 55
Chris@1732 56 } else if (rate != overallRate) {
Chris@1732 57 SVCERR << "AggregateWaveModel: WARNING: component for channel "
Chris@1732 58 << channel << " has different sample rate from earlier "
Chris@1732 59 << "channels (has " << rate << ", expected " << overallRate
Chris@1732 60 << ")" << endl;
Chris@297 61 }
Chris@297 62 }
Chris@297 63 }
Chris@297 64
Chris@297 65 AggregateWaveModel::~AggregateWaveModel()
Chris@297 66 {
Chris@1688 67 SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl;
Chris@297 68 }
Chris@297 69
Chris@297 70 bool
Chris@297 71 AggregateWaveModel::isOK() const
Chris@297 72 {
Chris@1732 73 if (m_components.empty()) {
Chris@1389 74 return false;
Chris@1389 75 }
Chris@1732 76 for (const auto &c: m_components) {
Chris@1732 77 auto model = ModelById::get(c.model);
Chris@1732 78 if (!model || !model->isOK()) {
Chris@1389 79 return false;
Chris@1389 80 }
Chris@297 81 }
Chris@297 82 return true;
Chris@297 83 }
Chris@297 84
Chris@297 85 bool
Chris@297 86 AggregateWaveModel::isReady(int *completion) const
Chris@297 87 {
Chris@297 88 if (completion) *completion = 100;
Chris@1389 89
Chris@297 90 bool ready = true;
Chris@1732 91 for (auto c: m_components) {
Chris@297 92 int completionHere = 100;
Chris@1732 93 auto model = ModelById::get(c.model);
Chris@1732 94 if (!model) continue;
Chris@1732 95 if (!model->isReady(&completionHere)) {
Chris@1556 96 ready = false;
Chris@1556 97 }
Chris@297 98 if (completion && completionHere < *completion) {
Chris@297 99 *completion = completionHere;
Chris@297 100 }
Chris@297 101 }
Chris@1556 102
Chris@1556 103 #ifdef DEBUG_AGGREGATE_WAVE_FILE_MODEL
Chris@1556 104 SVDEBUG << "AggregateWaveModel(" << objectName()
Chris@1556 105 << ")::isReady: returning " << ready << endl;
Chris@1556 106 #endif
Chris@1556 107
Chris@297 108 return ready;
Chris@297 109 }
Chris@297 110
Chris@1038 111 sv_frame_t
Chris@297 112 AggregateWaveModel::getFrameCount() const
Chris@297 113 {
Chris@1038 114 sv_frame_t count = 0;
Chris@1732 115 for (auto c: m_components) {
Chris@1732 116 auto model = ModelById::get(c.model);
Chris@1732 117 if (!model) continue;
Chris@1732 118 sv_frame_t thisCount = model->getEndFrame() - model->getStartFrame();
Chris@297 119 if (thisCount > count) count = thisCount;
Chris@297 120 }
Chris@297 121 return count;
Chris@297 122 }
Chris@297 123
Chris@929 124 int
Chris@297 125 AggregateWaveModel::getChannelCount() const
Chris@297 126 {
Chris@1038 127 return int(m_components.size());
Chris@297 128 }
Chris@297 129
Chris@1040 130 sv_samplerate_t
Chris@297 131 AggregateWaveModel::getSampleRate() const
Chris@297 132 {
Chris@1732 133 if (m_components.empty()) return 0;
Chris@1732 134 auto model = ModelById::get(m_components.begin()->model);
Chris@1732 135 if (!model) return 0;
Chris@1732 136 return model->getSampleRate();
Chris@297 137 }
Chris@297 138
Chris@1326 139 floatvec_t
Chris@1096 140 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
Chris@297 141 {
Chris@1732 142 if (m_components.empty()) return {};
Chris@1732 143
Chris@297 144 int ch0 = channel, ch1 = channel;
Chris@297 145 if (channel == -1) {
Chris@297 146 ch0 = 0;
Chris@297 147 ch1 = getChannelCount()-1;
Chris@1732 148 } else if (!in_range_for(m_components, channel)) {
Chris@1732 149 return {};
Chris@297 150 }
Chris@297 151
Chris@1326 152 floatvec_t result(count, 0.f);
Chris@1038 153 sv_frame_t longest = 0;
Chris@1008 154
Chris@297 155 for (int c = ch0; c <= ch1; ++c) {
Chris@1096 156
Chris@1732 157 auto model = ModelById::getAs<RangeSummarisableTimeValueModel>
Chris@1732 158 (m_components[c].model);
Chris@1732 159 if (!model) continue;
Chris@1732 160
Chris@1732 161 auto here = model->getData(m_components[c].channel, start, count);
Chris@1100 162 if (sv_frame_t(here.size()) > longest) {
Chris@1100 163 longest = sv_frame_t(here.size());
Chris@1008 164 }
Chris@1096 165 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
Chris@1096 166 result[i] += here[i];
Chris@297 167 }
Chris@297 168 }
Chris@297 169
Chris@1096 170 result.resize(longest);
Chris@1096 171 return result;
Chris@297 172 }
Chris@363 173
Chris@1326 174 vector<floatvec_t>
Chris@1086 175 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
Chris@1096 176 sv_frame_t start, sv_frame_t count) const
Chris@363 177 {
Chris@1038 178 sv_frame_t min = count;
Chris@363 179
Chris@1326 180 vector<floatvec_t> result;
Chris@1096 181
Chris@929 182 for (int c = fromchannel; c <= tochannel; ++c) {
Chris@1096 183 auto here = getData(c, start, count);
Chris@1100 184 if (sv_frame_t(here.size()) < min) {
Chris@1100 185 min = sv_frame_t(here.size());
Chris@1100 186 }
Chris@1096 187 result.push_back(here);
Chris@1096 188 }
Chris@1096 189
Chris@1096 190 if (min < count) {
Chris@1096 191 for (auto &v : result) v.resize(min);
Chris@363 192 }
Chris@363 193
Chris@1096 194 return result;
Chris@363 195 }
Chris@377 196
Chris@929 197 int
Chris@929 198 AggregateWaveModel::getSummaryBlockSize(int desired) const
Chris@377 199 {
Chris@377 200 //!!! complete
Chris@377 201 return desired;
Chris@377 202 }
Chris@297 203
Chris@297 204 void
Chris@1038 205 AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
Chris@929 206 RangeBlock &, int &) const
Chris@297 207 {
Chris@297 208 //!!! complete
Chris@297 209 }
Chris@297 210
Chris@297 211 AggregateWaveModel::Range
Chris@1038 212 AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
Chris@297 213 {
Chris@297 214 //!!! complete
Chris@297 215 return Range();
Chris@297 216 }
Chris@297 217
Chris@929 218 int
Chris@297 219 AggregateWaveModel::getComponentCount() const
Chris@297 220 {
Chris@1038 221 return int(m_components.size());
Chris@297 222 }
Chris@297 223
Chris@297 224 AggregateWaveModel::ModelChannelSpec
Chris@929 225 AggregateWaveModel::getComponent(int c) const
Chris@297 226 {
Chris@297 227 return m_components[c];
Chris@297 228 }
Chris@297 229
Chris@297 230 void
Chris@297 231 AggregateWaveModel::componentModelChanged()
Chris@297 232 {
Chris@297 233 emit modelChanged();
Chris@297 234 }
Chris@297 235
Chris@297 236 void
Chris@1038 237 AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
Chris@297 238 {
Chris@947 239 emit modelChangedWithin(start, end);
Chris@297 240 }
Chris@297 241
Chris@297 242 void
Chris@297 243 AggregateWaveModel::componentModelCompletionChanged()
Chris@297 244 {
Chris@297 245 emit completionChanged();
Chris@297 246 }
Chris@297 247
Chris@297 248 void
Chris@1391 249 AggregateWaveModel::toXml(QTextStream &out,
Chris@1391 250 QString indent,
Chris@1391 251 QString extraAttributes) const
Chris@297 252 {
Chris@1391 253 QStringList componentStrings;
Chris@1391 254 for (const auto &c: m_components) {
Chris@1732 255 auto model = ModelById::get(c.model);
Chris@1732 256 if (!model) continue;
Chris@1732 257 componentStrings.push_back(QString("%1").arg(model->getExportId()));
Chris@1391 258 }
Chris@1391 259 Model::toXml(out, indent,
Chris@1391 260 QString("type=\"aggregatewave\" components=\"%1\" %2")
Chris@1391 261 .arg(componentStrings.join(","))
Chris@1391 262 .arg(extraAttributes));
Chris@297 263 }
Chris@297 264