annotate layer/WaveformLayer.cpp @ 1337:4f9a3c84be60 zoom

Fix accidental always-auto-normalise
author Chris Cannam
date Tue, 25 Sep 2018 12:52:08 +0100
parents 43296804c473
children 6d091348e4e9
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "WaveformLayer.h"
Chris@0 17
Chris@0 18 #include "base/AudioLevel.h"
Chris@128 19 #include "view/View.h"
Chris@0 20 #include "base/Profiler.h"
Chris@167 21 #include "base/RangeMapper.h"
Chris@1147 22 #include "base/Strings.h"
Chris@1078 23
Chris@376 24 #include "ColourDatabase.h"
Chris@1078 25 #include "PaintAssistant.h"
Chris@0 26
Chris@0 27 #include <QPainter>
Chris@0 28 #include <QPixmap>
Chris@316 29 #include <QTextStream>
Chris@0 30
Chris@0 31 #include <iostream>
Chris@0 32 #include <cmath>
Chris@0 33
Chris@1336 34 #include <bqresample/Resampler.h>
Chris@1336 35
Chris@4 36 //#define DEBUG_WAVEFORM_PAINT 1
Chris@4 37
Chris@1333 38 using std::vector;
Chris@682 39
Chris@0 40
Chris@44 41 WaveformLayer::WaveformLayer() :
Chris@287 42 SingleColourLayer(),
Chris@0 43 m_model(0),
Chris@0 44 m_gain(1.0f),
Chris@67 45 m_autoNormalize(false),
Chris@0 46 m_showMeans(true),
Chris@0 47 m_greyscale(true),
Chris@0 48 m_channelMode(SeparateChannels),
Chris@0 49 m_channel(-1),
Chris@0 50 m_scale(LinearScale),
Chris@709 51 m_middleLineHeight(0.5),
Chris@0 52 m_aggressive(false),
Chris@1336 53 m_oversampleRate(8),
Chris@1336 54 m_oversampleTail(200),
Chris@1336 55 m_oversampler(0),
Chris@0 56 m_cache(0),
Chris@1325 57 m_cacheValid(false)
Chris@0 58 {
Chris@0 59 }
Chris@0 60
Chris@0 61 WaveformLayer::~WaveformLayer()
Chris@0 62 {
Chris@0 63 delete m_cache;
Chris@1336 64 delete m_oversampler;
Chris@0 65 }
Chris@0 66
Chris@0 67 void
Chris@0 68 WaveformLayer::setModel(const RangeSummarisableTimeValueModel *model)
Chris@0 69 {
Chris@69 70 bool channelsChanged = false;
Chris@69 71 if (m_channel == -1) {
Chris@69 72 if (!m_model) {
Chris@69 73 if (model) {
Chris@69 74 channelsChanged = true;
Chris@69 75 }
Chris@69 76 } else {
Chris@69 77 if (model &&
Chris@69 78 m_model->getChannelCount() != model->getChannelCount()) {
Chris@69 79 channelsChanged = true;
Chris@69 80 }
Chris@69 81 }
Chris@69 82 }
Chris@69 83
Chris@0 84 m_model = model;
Chris@0 85 m_cacheValid = false;
Chris@0 86 if (!m_model || !m_model->isOK()) return;
Chris@0 87
Chris@1336 88 delete m_oversampler;
Chris@1336 89 breakfastquay::Resampler::Parameters params;
Chris@1336 90 params.initialSampleRate = m_model->getSampleRate();
Chris@1336 91 m_oversampler = new breakfastquay::Resampler
Chris@1336 92 (params, m_model->getChannelCount());
Chris@1336 93
Chris@320 94 connectSignals(m_model);
Chris@301 95
Chris@0 96 emit modelReplaced();
Chris@69 97
Chris@69 98 if (channelsChanged) emit layerParametersChanged();
Chris@0 99 }
Chris@0 100
Chris@0 101 Layer::PropertyList
Chris@0 102 WaveformLayer::getProperties() const
Chris@0 103 {
Chris@287 104 PropertyList list = SingleColourLayer::getProperties();
Chris@87 105 list.push_back("Scale");
Chris@87 106 list.push_back("Gain");
Chris@87 107 list.push_back("Normalize Visible Area");
Chris@68 108
Chris@68 109 if (m_model && m_model->getChannelCount() > 1 && m_channel == -1) {
Chris@87 110 list.push_back("Channels");
Chris@68 111 }
Chris@68 112
Chris@0 113 return list;
Chris@0 114 }
Chris@0 115
Chris@87 116 QString
Chris@87 117 WaveformLayer::getPropertyLabel(const PropertyName &name) const
Chris@87 118 {
Chris@87 119 if (name == "Scale") return tr("Scale");
Chris@87 120 if (name == "Gain") return tr("Gain");
Chris@87 121 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
Chris@87 122 if (name == "Channels") return tr("Channels");
Chris@287 123 return SingleColourLayer::getPropertyLabel(name);
Chris@87 124 }
Chris@87 125
Chris@335 126 QString
Chris@335 127 WaveformLayer::getPropertyIconName(const PropertyName &name) const
Chris@335 128 {
Chris@335 129 if (name == "Normalize Visible Area") return "normalise";
Chris@335 130 return "";
Chris@335 131 }
Chris@335 132
Chris@0 133 Layer::PropertyType
Chris@0 134 WaveformLayer::getPropertyType(const PropertyName &name) const
Chris@0 135 {
Chris@87 136 if (name == "Gain") return RangeProperty;
Chris@87 137 if (name == "Normalize Visible Area") return ToggleProperty;
Chris@87 138 if (name == "Channels") return ValueProperty;
Chris@87 139 if (name == "Scale") return ValueProperty;
Chris@287 140 return SingleColourLayer::getPropertyType(name);
Chris@0 141 }
Chris@0 142
Chris@0 143 QString
Chris@0 144 WaveformLayer::getPropertyGroupName(const PropertyName &name) const
Chris@0 145 {
Chris@87 146 if (name == "Gain" ||
Chris@87 147 name == "Normalize Visible Area" ||
Chris@1266 148 name == "Scale") return tr("Scale");
Chris@0 149 return QString();
Chris@0 150 }
Chris@0 151
Chris@0 152 int
Chris@0 153 WaveformLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 154 int *min, int *max, int *deflt) const
Chris@0 155 {
Chris@216 156 int val = 0;
Chris@0 157
Chris@216 158 int garbage0, garbage1, garbage2;
Chris@56 159 if (!min) min = &garbage0;
Chris@56 160 if (!max) max = &garbage1;
Chris@216 161 if (!deflt) deflt = &garbage2;
Chris@10 162
Chris@87 163 if (name == "Gain") {
Chris@0 164
Chris@1266 165 *min = -50;
Chris@1266 166 *max = 50;
Chris@216 167 *deflt = 0;
Chris@0 168
Chris@1266 169 val = int(lrint(log10(m_gain) * 20.0));
Chris@1266 170 if (val < *min) val = *min;
Chris@1266 171 if (val > *max) val = *max;
Chris@0 172
Chris@87 173 } else if (name == "Normalize Visible Area") {
Chris@67 174
Chris@216 175 val = (m_autoNormalize ? 1 : 0);
Chris@216 176 *deflt = 0;
Chris@67 177
Chris@87 178 } else if (name == "Channels") {
Chris@0 179
Chris@67 180 *min = 0;
Chris@67 181 *max = 2;
Chris@216 182 *deflt = 0;
Chris@216 183 if (m_channelMode == MixChannels) val = 1;
Chris@216 184 else if (m_channelMode == MergeChannels) val = 2;
Chris@216 185 else val = 0;
Chris@0 186
Chris@87 187 } else if (name == "Scale") {
Chris@0 188
Chris@1266 189 *min = 0;
Chris@1266 190 *max = 2;
Chris@216 191 *deflt = 0;
Chris@0 192
Chris@1266 193 val = (int)m_scale;
Chris@0 194
Chris@0 195 } else {
Chris@1266 196 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@0 197 }
Chris@0 198
Chris@216 199 return val;
Chris@0 200 }
Chris@0 201
Chris@0 202 QString
Chris@0 203 WaveformLayer::getPropertyValueLabel(const PropertyName &name,
Chris@1266 204 int value) const
Chris@0 205 {
Chris@87 206 if (name == "Scale") {
Chris@1266 207 switch (value) {
Chris@1266 208 default:
Chris@1266 209 case 0: return tr("Linear");
Chris@1266 210 case 1: return tr("Meter");
Chris@1266 211 case 2: return tr("dB");
Chris@1266 212 }
Chris@0 213 }
Chris@87 214 if (name == "Channels") {
Chris@67 215 switch (value) {
Chris@67 216 default:
Chris@67 217 case 0: return tr("Separate");
Chris@67 218 case 1: return tr("Mean");
Chris@67 219 case 2: return tr("Butterfly");
Chris@67 220 }
Chris@67 221 }
Chris@287 222 return SingleColourLayer::getPropertyValueLabel(name, value);
Chris@0 223 }
Chris@0 224
Chris@167 225 RangeMapper *
Chris@167 226 WaveformLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@167 227 {
Chris@167 228 if (name == "Gain") {
Chris@167 229 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
Chris@167 230 }
Chris@167 231 return 0;
Chris@167 232 }
Chris@167 233
Chris@0 234 void
Chris@0 235 WaveformLayer::setProperty(const PropertyName &name, int value)
Chris@0 236 {
Chris@87 237 if (name == "Gain") {
Chris@1266 238 setGain(float(pow(10, float(value)/20.0)));
Chris@87 239 } else if (name == "Normalize Visible Area") {
Chris@67 240 setAutoNormalize(value ? true : false);
Chris@87 241 } else if (name == "Channels") {
Chris@67 242 if (value == 1) setChannelMode(MixChannels);
Chris@67 243 else if (value == 2) setChannelMode(MergeChannels);
Chris@67 244 else setChannelMode(SeparateChannels);
Chris@87 245 } else if (name == "Scale") {
Chris@1266 246 switch (value) {
Chris@1266 247 default:
Chris@1266 248 case 0: setScale(LinearScale); break;
Chris@1266 249 case 1: setScale(MeterScale); break;
Chris@1266 250 case 2: setScale(dBScale); break;
Chris@1266 251 }
Chris@287 252 } else {
Chris@287 253 SingleColourLayer::setProperty(name, value);
Chris@0 254 }
Chris@0 255 }
Chris@0 256
Chris@0 257 void
Chris@67 258 WaveformLayer::setGain(float gain)
Chris@0 259 {
Chris@0 260 if (m_gain == gain) return;
Chris@0 261 m_gain = gain;
Chris@0 262 m_cacheValid = false;
Chris@0 263 emit layerParametersChanged();
Chris@133 264 emit verticalZoomChanged();
Chris@0 265 }
Chris@0 266
Chris@0 267 void
Chris@67 268 WaveformLayer::setAutoNormalize(bool autoNormalize)
Chris@67 269 {
Chris@67 270 if (m_autoNormalize == autoNormalize) return;
Chris@67 271 m_autoNormalize = autoNormalize;
Chris@67 272 m_cacheValid = false;
Chris@67 273 emit layerParametersChanged();
Chris@67 274 }
Chris@67 275
Chris@67 276 void
Chris@0 277 WaveformLayer::setShowMeans(bool showMeans)
Chris@0 278 {
Chris@0 279 if (m_showMeans == showMeans) return;
Chris@0 280 m_showMeans = showMeans;
Chris@0 281 m_cacheValid = false;
Chris@0 282 emit layerParametersChanged();
Chris@0 283 }
Chris@0 284
Chris@0 285 void
Chris@0 286 WaveformLayer::setUseGreyscale(bool useGreyscale)
Chris@0 287 {
Chris@0 288 if (m_greyscale == useGreyscale) return;
Chris@0 289 m_greyscale = useGreyscale;
Chris@0 290 m_cacheValid = false;
Chris@0 291 emit layerParametersChanged();
Chris@0 292 }
Chris@0 293
Chris@0 294 void
Chris@0 295 WaveformLayer::setChannelMode(ChannelMode channelMode)
Chris@0 296 {
Chris@0 297 if (m_channelMode == channelMode) return;
Chris@0 298 m_channelMode = channelMode;
Chris@0 299 m_cacheValid = false;
Chris@0 300 emit layerParametersChanged();
Chris@0 301 }
Chris@0 302
Chris@0 303 void
Chris@0 304 WaveformLayer::setChannel(int channel)
Chris@0 305 {
Chris@587 306 // SVDEBUG << "WaveformLayer::setChannel(" << channel << ")" << endl;
Chris@0 307
Chris@0 308 if (m_channel == channel) return;
Chris@0 309 m_channel = channel;
Chris@0 310 m_cacheValid = false;
Chris@0 311 emit layerParametersChanged();
Chris@0 312 }
Chris@0 313
Chris@0 314 void
Chris@0 315 WaveformLayer::setScale(Scale scale)
Chris@0 316 {
Chris@0 317 if (m_scale == scale) return;
Chris@0 318 m_scale = scale;
Chris@0 319 m_cacheValid = false;
Chris@0 320 emit layerParametersChanged();
Chris@0 321 }
Chris@0 322
Chris@0 323 void
Chris@908 324 WaveformLayer::setMiddleLineHeight(double height)
Chris@709 325 {
Chris@709 326 if (m_middleLineHeight == height) return;
Chris@709 327 m_middleLineHeight = height;
Chris@709 328 m_cacheValid = false;
Chris@709 329 emit layerParametersChanged();
Chris@709 330 }
Chris@709 331
Chris@709 332 void
Chris@0 333 WaveformLayer::setAggressiveCacheing(bool aggressive)
Chris@0 334 {
Chris@0 335 if (m_aggressive == aggressive) return;
Chris@0 336 m_aggressive = aggressive;
Chris@0 337 m_cacheValid = false;
Chris@0 338 emit layerParametersChanged();
Chris@0 339 }
Chris@0 340
Chris@0 341 int
Chris@918 342 WaveformLayer::getCompletion(LayerGeometryProvider *) const
Chris@0 343 {
Chris@0 344 int completion = 100;
Chris@0 345 if (!m_model || !m_model->isOK()) return completion;
Chris@0 346 if (m_model->isReady(&completion)) return 100;
Chris@0 347 return completion;
Chris@0 348 }
Chris@0 349
Chris@79 350 bool
Chris@908 351 WaveformLayer::getValueExtents(double &min, double &max,
Chris@248 352 bool &, QString &unit) const
Chris@79 353 {
Chris@79 354 if (m_scale == LinearScale) {
Chris@79 355 min = 0.0;
Chris@79 356 max = 1.0;
Chris@79 357 unit = "V";
Chris@79 358 } else if (m_scale == MeterScale) {
Chris@79 359 return false; //!!!
Chris@79 360 } else {
Chris@79 361 min = AudioLevel::multiplier_to_dB(0.0);
Chris@79 362 max = AudioLevel::multiplier_to_dB(1.0);
Chris@79 363 unit = "dB";
Chris@79 364 }
Chris@79 365 return true;
Chris@79 366 }
Chris@79 367
Chris@0 368 int
Chris@908 369 WaveformLayer::dBscale(double sample, int m) const
Chris@0 370 {
Chris@67 371 if (sample < 0.0) return dBscale(-sample, m);
Chris@908 372 double dB = AudioLevel::multiplier_to_dB(sample);
Chris@0 373 if (dB < -50.0) return 0;
Chris@0 374 if (dB > 0.0) return m;
Chris@0 375 return int(((dB + 50.0) * m) / 50.0 + 0.1);
Chris@0 376 }
Chris@0 377
Chris@805 378 int
Chris@805 379 WaveformLayer::getChannelArrangement(int &min, int &max,
Chris@67 380 bool &merging, bool &mixing)
Chris@0 381 const
Chris@0 382 {
Chris@0 383 if (!m_model || !m_model->isOK()) return 0;
Chris@0 384
Chris@805 385 int channels = m_model->getChannelCount();
Chris@0 386 if (channels == 0) return 0;
Chris@0 387
Chris@805 388 int rawChannels = channels;
Chris@0 389
Chris@0 390 if (m_channel == -1) {
Chris@1266 391 min = 0;
Chris@1266 392 if (m_channelMode == MergeChannels ||
Chris@67 393 m_channelMode == MixChannels) {
Chris@1266 394 max = 0;
Chris@1266 395 channels = 1;
Chris@1266 396 } else {
Chris@1266 397 max = channels - 1;
Chris@1266 398 }
Chris@0 399 } else {
Chris@1266 400 min = m_channel;
Chris@1266 401 max = m_channel;
Chris@1266 402 rawChannels = 1;
Chris@1266 403 channels = 1;
Chris@0 404 }
Chris@0 405
Chris@0 406 merging = (m_channelMode == MergeChannels && rawChannels > 1);
Chris@67 407 mixing = (m_channelMode == MixChannels && rawChannels > 1);
Chris@0 408
Chris@587 409 // SVDEBUG << "WaveformLayer::getChannelArrangement: min " << min << ", max " << max << ", merging " << merging << ", channels " << channels << endl;
Chris@0 410
Chris@0 411 return channels;
Chris@0 412 }
Chris@0 413
Chris@67 414 bool
Chris@918 415 WaveformLayer::isLayerScrollable(const LayerGeometryProvider *) const
Chris@67 416 {
Chris@67 417 return !m_autoNormalize;
Chris@67 418 }
Chris@67 419
Chris@68 420 static float meterdbs[] = { -40, -30, -20, -15, -10,
Chris@68 421 -5, -3, -2, -1, -0.5, 0 };
Chris@68 422
Chris@365 423 bool
Chris@1336 424 WaveformLayer::getSourceFramesForX(LayerGeometryProvider *v,
Chris@1336 425 int x, int modelZoomLevel,
Chris@908 426 sv_frame_t &f0, sv_frame_t &f1) const
Chris@365 427 {
Chris@908 428 sv_frame_t viewFrame = v->getFrameForX(x);
Chris@365 429 if (viewFrame < 0) {
Chris@365 430 f0 = 0;
Chris@365 431 f1 = 0;
Chris@365 432 return false;
Chris@365 433 }
Chris@365 434
Chris@365 435 f0 = viewFrame;
Chris@365 436
Chris@365 437 f0 = f0 / modelZoomLevel;
Chris@365 438 f0 = f0 * modelZoomLevel;
Chris@365 439
Chris@365 440 viewFrame = v->getFrameForX(x + 1);
Chris@365 441
Chris@365 442 f1 = viewFrame;
Chris@365 443 f1 = f1 / modelZoomLevel;
Chris@365 444 f1 = f1 * modelZoomLevel;
Chris@365 445
Chris@365 446 return (f0 < m_model->getEndFrame());
Chris@365 447 }
Chris@365 448
Chris@365 449 float
Chris@918 450 WaveformLayer::getNormalizeGain(LayerGeometryProvider *v, int channel) const
Chris@365 451 {
Chris@908 452 sv_frame_t startFrame = v->getStartFrame();
Chris@908 453 sv_frame_t endFrame = v->getEndFrame();
Chris@365 454
Chris@908 455 sv_frame_t modelStart = m_model->getStartFrame();
Chris@908 456 sv_frame_t modelEnd = m_model->getEndFrame();
Chris@365 457
Chris@908 458 sv_frame_t rangeStart, rangeEnd;
Chris@365 459
Chris@365 460 if (startFrame < modelStart) rangeStart = modelStart;
Chris@365 461 else rangeStart = startFrame;
Chris@365 462
Chris@365 463 if (endFrame < 0) rangeEnd = 0;
Chris@365 464 else if (endFrame > modelEnd) rangeEnd = modelEnd;
Chris@365 465 else rangeEnd = endFrame;
Chris@365 466
Chris@365 467 if (rangeEnd < rangeStart) rangeEnd = rangeStart;
Chris@365 468
Chris@365 469 RangeSummarisableTimeValueModel::Range range =
Chris@365 470 m_model->getSummary(channel, rangeStart, rangeEnd - rangeStart);
Chris@365 471
Chris@805 472 int minChannel = 0, maxChannel = 0;
Chris@365 473 bool mergingChannels = false, mixingChannels = false;
Chris@365 474
Chris@859 475 (void)getChannelArrangement(minChannel, maxChannel,
Chris@859 476 mergingChannels, mixingChannels);
Chris@365 477
Chris@365 478 if (mergingChannels || mixingChannels) {
Chris@365 479 RangeSummarisableTimeValueModel::Range otherRange =
Chris@365 480 m_model->getSummary(1, rangeStart, rangeEnd - rangeStart);
Chris@386 481 range.setMax(std::max(range.max(), otherRange.max()));
Chris@386 482 range.setMin(std::min(range.min(), otherRange.min()));
Chris@386 483 range.setAbsmean(std::min(range.absmean(), otherRange.absmean()));
Chris@365 484 }
Chris@365 485
Chris@908 486 return float(1.0 / std::max(fabs(range.max()), fabs(range.min())));
Chris@365 487 }
Chris@365 488
Chris@0 489 void
Chris@916 490 WaveformLayer::paint(LayerGeometryProvider *v, QPainter &viewPainter, QRect rect) const
Chris@0 491 {
Chris@0 492 if (!m_model || !m_model->isOK()) {
Chris@1266 493 return;
Chris@0 494 }
Chris@0 495
Chris@1325 496 ZoomLevel zoomLevel = v->getZoomLevel();
Chris@0 497
Chris@2 498 #ifdef DEBUG_WAVEFORM_PAINT
Chris@0 499 Profiler profiler("WaveformLayer::paint", true);
Chris@682 500 cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y()
Chris@1266 501 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << endl;
Chris@2 502 #endif
Chris@0 503
Chris@805 504 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@67 505 bool mergingChannels = false, mixingChannels = false;
Chris@0 506
Chris@67 507 channels = getChannelArrangement(minChannel, maxChannel,
Chris@67 508 mergingChannels, mixingChannels);
Chris@0 509 if (channels == 0) return;
Chris@0 510
Chris@915 511 int w = v->getPaintWidth();
Chris@915 512 int h = v->getPaintHeight();
Chris@0 513
Chris@0 514 QPainter *paint;
Chris@0 515
Chris@0 516 if (m_aggressive) {
Chris@0 517
Chris@214 518 #ifdef DEBUG_WAVEFORM_PAINT
Chris@682 519 cerr << "WaveformLayer::paint: aggressive is true" << endl;
Chris@214 520 #endif
Chris@214 521
Chris@1325 522 using namespace std::rel_ops;
Chris@1325 523
Chris@1266 524 if (m_cacheValid && (zoomLevel != m_cacheZoomLevel)) {
Chris@1266 525 m_cacheValid = false;
Chris@1266 526 }
Chris@0 527
Chris@1266 528 if (!m_cache || m_cache->width() != w || m_cache->height() != h) {
Chris@214 529 #ifdef DEBUG_WAVEFORM_PAINT
Chris@214 530 if (m_cache) {
Chris@682 531 cerr << "WaveformLayer::paint: cache size " << m_cache->width() << "x" << m_cache->height() << " differs from view size " << w << "x" << h << ": regenerating aggressive cache" << endl;
Chris@214 532 }
Chris@214 533 #endif
Chris@1266 534 delete m_cache;
Chris@1266 535 m_cache = new QPixmap(w, h);
Chris@214 536 m_cacheValid = false;
Chris@1266 537 }
Chris@214 538
Chris@1266 539 if (m_cacheValid) {
Chris@1266 540 viewPainter.drawPixmap(rect, *m_cache, rect);
Chris@1266 541 return;
Chris@1266 542 }
Chris@0 543
Chris@1266 544 paint = new QPainter(m_cache);
Chris@0 545
Chris@1266 546 paint->setPen(Qt::NoPen);
Chris@1266 547 paint->setBrush(getBackgroundQColor(v));
Chris@1266 548 paint->drawRect(rect);
Chris@0 549
Chris@1266 550 paint->setPen(getForegroundQColor(v));
Chris@1266 551 paint->setBrush(Qt::NoBrush);
Chris@0 552
Chris@0 553 } else {
Chris@1266 554 paint = &viewPainter;
Chris@0 555 }
Chris@0 556
Chris@28 557 paint->setRenderHint(QPainter::Antialiasing, false);
Chris@28 558
Chris@709 559 if (m_middleLineHeight != 0.5) {
Chris@709 560 paint->save();
Chris@908 561 double space = m_middleLineHeight * 2;
Chris@709 562 if (space > 1.0) space = 2.0 - space;
Chris@908 563 double yt = h * (m_middleLineHeight - space/2);
Chris@709 564 paint->translate(QPointF(0, yt));
Chris@709 565 paint->scale(1.0, space);
Chris@709 566 }
Chris@709 567
Chris@0 568 int x0 = 0, x1 = w - 1;
Chris@0 569
Chris@0 570 x0 = rect.left();
Chris@0 571 x1 = rect.right();
Chris@0 572
Chris@1334 573 if (x0 > 0) {
Chris@1334 574 rect.adjust(-1, 0, 0, 0);
Chris@1334 575 x0 = rect.left();
Chris@1334 576 }
Chris@1334 577
Chris@1334 578 if (x1 < w) {
Chris@1334 579 rect.adjust(0, 0, 1, 0);
Chris@1334 580 x1 = rect.right();
Chris@1334 581 }
Chris@28 582
Chris@365 583 // Our zoom level may differ from that at which the underlying
Chris@365 584 // model has its blocks.
Chris@302 585
Chris@365 586 // Each pixel within our visible range must always draw from
Chris@365 587 // exactly the same set of underlying audio frames, no matter what
Chris@365 588 // the range being drawn is. And that set of underlying frames
Chris@365 589 // must remain the same when we scroll one or more pixels left or
Chris@365 590 // right.
Chris@1325 591
Chris@1325 592 int desiredBlockSize = 1;
Chris@1325 593 if (zoomLevel.zone == ZoomLevel::FramesPerPixel) {
Chris@1325 594 desiredBlockSize = zoomLevel.level;
Chris@1325 595 }
Chris@1325 596 int blockSize = m_model->getSummaryBlockSize(desiredBlockSize);
Chris@365 597
Chris@908 598 sv_frame_t frame0;
Chris@908 599 sv_frame_t frame1;
Chris@908 600 sv_frame_t spare;
Chris@365 601
Chris@1325 602 getSourceFramesForX(v, x0, blockSize, frame0, spare);
Chris@1325 603 getSourceFramesForX(v, x1, blockSize, spare, frame1);
Chris@365 604
Chris@4 605 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1325 606 cerr << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << " and model zoom " << blockSize << ")" << endl;
Chris@4 607 #endif
Chris@0 608
Chris@805 609 while ((int)m_effectiveGains.size() <= maxChannel) {
Chris@67 610 m_effectiveGains.push_back(m_gain);
Chris@67 611 }
Chris@1337 612 if (m_autoNormalize) {
Chris@1337 613 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@1337 614 m_effectiveGains[ch] = getNormalizeGain(v, ch);
Chris@1337 615 }
Chris@1336 616 }
Chris@67 617
Chris@1336 618 if (v->getZoomLevel().zone == ZoomLevel::FramesPerPixel) {
Chris@1336 619
Chris@1336 620 vector<RangeSummarisableTimeValueModel::RangeBlock> ranges;
Chris@1333 621
Chris@1336 622 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@1336 623 ranges.push_back({});
Chris@1336 624 m_model->getSummaries(ch, frame0, frame1 - frame0,
Chris@1336 625 ranges[ch - minChannel], blockSize);
Chris@365 626 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1336 627 cerr << "channel " << ch << ": " << ranges[ch - minChannel].size() << " ranges from " << frame0 << " to " << frame1 << " at zoom level " << blockSize << endl;
Chris@365 628 #endif
Chris@1336 629 }
Chris@1333 630
Chris@1336 631 if (mergingChannels || mixingChannels) {
Chris@1336 632 if (minChannel != 0 || maxChannel != 0) {
Chris@1336 633 SVCERR << "Internal error: min & max channels should be 0 when merging or mixing all channels" << endl;
Chris@1336 634 } else if (m_model->getChannelCount() > 1) {
Chris@1336 635 ranges.push_back({});
Chris@1336 636 m_model->getSummaries
Chris@1336 637 (1, frame0, frame1 - frame0, ranges[1], blockSize);
Chris@1336 638 }
Chris@1336 639 }
Chris@1336 640
Chris@1336 641 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@1336 642 paintChannelSummarised(v, paint, rect, ch,
Chris@1336 643 ranges, blockSize, frame0, frame1);
Chris@1336 644 }
Chris@1336 645 } else {
Chris@1336 646
Chris@1336 647 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@1336 648 paintChannelOversampled(v, paint, rect, ch, frame0, frame1);
Chris@1266 649 }
Chris@1333 650 }
Chris@1333 651
Chris@709 652 if (m_middleLineHeight != 0.5) {
Chris@709 653 paint->restore();
Chris@709 654 }
Chris@709 655
Chris@0 656 if (m_aggressive) {
Chris@1332 657 if (m_model->isReady() && rect == v->getPaintRect()) {
Chris@1266 658 m_cacheValid = true;
Chris@1266 659 m_cacheZoomLevel = zoomLevel;
Chris@1266 660 }
Chris@1266 661 paint->end();
Chris@1266 662 delete paint;
Chris@1266 663 viewPainter.drawPixmap(rect, *m_cache, rect);
Chris@0 664 }
Chris@0 665 }
Chris@0 666
Chris@1332 667 void
Chris@1336 668 WaveformLayer::paintChannelSummarised(LayerGeometryProvider *v,
Chris@1336 669 QPainter *paint,
Chris@1336 670 QRect rect, int ch,
Chris@1336 671 const vector<RangeSummarisableTimeValueModel::RangeBlock> &ranges,
Chris@1336 672 int blockSize,
Chris@1336 673 sv_frame_t frame0, sv_frame_t frame1)
Chris@1332 674 const
Chris@1332 675 {
Chris@1334 676 int x0 = rect.left();
Chris@1334 677 int y0 = rect.top();
Chris@1334 678
Chris@1334 679 int x1 = rect.right();
Chris@1334 680 int y1 = rect.bottom();
Chris@1334 681
Chris@1332 682 int h = v->getPaintHeight();
Chris@1332 683
Chris@1332 684 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@1332 685 bool mergingChannels = false, mixingChannels = false;
Chris@1332 686
Chris@1332 687 channels = getChannelArrangement(minChannel, maxChannel,
Chris@1332 688 mergingChannels, mixingChannels);
Chris@1332 689 if (channels == 0) return;
Chris@1332 690
Chris@1332 691 QColor baseColour = getBaseQColor();
Chris@1333 692 vector<QColor> greys = getPartialShades(v);
Chris@1332 693
Chris@1332 694 QColor midColour = baseColour;
Chris@1332 695 if (midColour == Qt::black) {
Chris@1332 696 midColour = Qt::gray;
Chris@1332 697 } else if (v->hasLightBackground()) {
Chris@1332 698 midColour = midColour.light(150);
Chris@1332 699 } else {
Chris@1332 700 midColour = midColour.light(50);
Chris@1332 701 }
Chris@1332 702
Chris@1332 703 int prevRangeBottom = -1, prevRangeTop = -1;
Chris@1332 704 QColor prevRangeBottomColour = baseColour, prevRangeTopColour = baseColour;
Chris@1332 705
Chris@1332 706 double gain = m_effectiveGains[ch];
Chris@1332 707
Chris@1332 708 int m = (h / channels) / 2;
Chris@1332 709 int my = m + (((ch - minChannel) * h) / channels);
Chris@1332 710
Chris@1332 711 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1332 712 cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << endl;
Chris@1332 713 #endif
Chris@1332 714
Chris@1332 715 if (my - m > y1 || my + m < y0) return;
Chris@1332 716
Chris@1332 717 if ((m_scale == dBScale || m_scale == MeterScale) &&
Chris@1332 718 m_channelMode != MergeChannels) {
Chris@1332 719 m = (h / channels);
Chris@1332 720 my = m + (((ch - minChannel) * h) / channels);
Chris@1332 721 }
Chris@1332 722
Chris@1332 723 paint->setPen(greys[1]);
Chris@1332 724 paint->drawLine(x0, my, x1, my);
Chris@1332 725
Chris@1335 726 paintChannelScaleGuides(v, paint, rect, ch);
Chris@1332 727
Chris@1333 728 int rangeix = ch - minChannel;
Chris@1333 729
Chris@1332 730 for (int x = x0; x <= x1; ++x) {
Chris@1332 731
Chris@1332 732 sv_frame_t f0, f1;
Chris@1332 733 if (!getSourceFramesForX(v, x, blockSize, f0, f1)) continue;
Chris@1332 734 f1 = f1 - 1;
Chris@1332 735
Chris@1332 736 if (f0 < frame0) {
Chris@1332 737 cerr << "ERROR: WaveformLayer::paint: pixel " << x << " has f0 = " << f0 << " which is less than range frame0 " << frame0 << " for x0 = " << x0 << endl;
Chris@1332 738 continue;
Chris@1332 739 }
Chris@1332 740
Chris@1332 741 sv_frame_t i0 = (f0 - frame0) / blockSize;
Chris@1332 742 sv_frame_t i1 = (f1 - frame0) / blockSize;
Chris@1332 743
Chris@1332 744 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1332 745 cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl;
Chris@1332 746 #endif
Chris@1332 747
Chris@1332 748 if (i1 > i0 + 1) {
Chris@1332 749 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << v->getZoomLevel() << ", model zoom = " << blockSize << ")" << endl;
Chris@1332 750 }
Chris@1332 751
Chris@1333 752 const auto &r = ranges[rangeix];
Chris@1333 753 RangeSummarisableTimeValueModel::Range range;
Chris@1333 754
Chris@1333 755 if (in_range_for(r, i0)) {
Chris@1332 756
Chris@1333 757 range = r[i0];
Chris@1332 758
Chris@1333 759 if (i1 > i0 && in_range_for(r, i1)) {
Chris@1333 760 range.setMax(std::max(range.max(), r[i1].max()));
Chris@1333 761 range.setMin(std::min(range.min(), r[i1].min()));
Chris@1333 762 range.setAbsmean((range.absmean() + r[i1].absmean()) / 2);
Chris@1332 763 }
Chris@1332 764
Chris@1332 765 } else {
Chris@1332 766 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1332 767 cerr << "No (or not enough) ranges for i0 = " << i0 << endl;
Chris@1332 768 #endif
Chris@1332 769 continue;
Chris@1332 770 }
Chris@1332 771
Chris@1332 772 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0;
Chris@1332 773
Chris@1333 774 if (mergingChannels && ranges.size() > 1) {
Chris@1332 775
Chris@1333 776 const auto &other = ranges[1];
Chris@1333 777
Chris@1333 778 if (in_range_for(other, i0)) {
Chris@1332 779
Chris@1332 780 range.setMax(fabsf(range.max()));
Chris@1333 781 range.setMin(-fabsf(other[i0].max()));
Chris@1332 782 range.setAbsmean
Chris@1333 783 ((range.absmean() + other[i0].absmean()) / 2);
Chris@1332 784
Chris@1333 785 if (i1 > i0 && in_range_for(other, i1)) {
Chris@1332 786 // let's not concern ourselves about the mean
Chris@1333 787 range.setMin(std::min(range.min(),
Chris@1333 788 -fabsf(other[i1].max())));
Chris@1332 789 }
Chris@1332 790 }
Chris@1332 791
Chris@1333 792 } else if (mixingChannels && ranges.size() > 1) {
Chris@1332 793
Chris@1333 794 const auto &other = ranges[1];
Chris@1333 795
Chris@1333 796 if (in_range_for(other, i0)) {
Chris@1332 797
Chris@1333 798 range.setMax((range.max() + other[i0].max()) / 2);
Chris@1333 799 range.setMin((range.min() + other[i0].min()) / 2);
Chris@1333 800 range.setAbsmean((range.absmean() + other[i0].absmean()) / 2);
Chris@1332 801 }
Chris@1332 802 }
Chris@1332 803
Chris@1332 804 int greyLevels = 1;
Chris@1332 805 if (m_greyscale && (m_scale == LinearScale)) greyLevels = 4;
Chris@1332 806
Chris@1332 807 switch (m_scale) {
Chris@1332 808
Chris@1332 809 case LinearScale:
Chris@1332 810 rangeBottom = int(double(m * greyLevels) * range.min() * gain);
Chris@1332 811 rangeTop = int(double(m * greyLevels) * range.max() * gain);
Chris@1332 812 meanBottom = int(double(-m) * range.absmean() * gain);
Chris@1332 813 meanTop = int(double(m) * range.absmean() * gain);
Chris@1332 814 break;
Chris@1332 815
Chris@1332 816 case dBScale:
Chris@1332 817 if (!mergingChannels) {
Chris@1332 818 int db0 = dBscale(range.min() * gain, m);
Chris@1332 819 int db1 = dBscale(range.max() * gain, m);
Chris@1332 820 rangeTop = std::max(db0, db1);
Chris@1332 821 meanTop = std::min(db0, db1);
Chris@1332 822 if (mixingChannels) rangeBottom = meanTop;
Chris@1332 823 else rangeBottom = dBscale(range.absmean() * gain, m);
Chris@1332 824 meanBottom = rangeBottom;
Chris@1332 825 } else {
Chris@1332 826 rangeBottom = -dBscale(range.min() * gain, m * greyLevels);
Chris@1332 827 rangeTop = dBscale(range.max() * gain, m * greyLevels);
Chris@1332 828 meanBottom = -dBscale(range.absmean() * gain, m);
Chris@1332 829 meanTop = dBscale(range.absmean() * gain, m);
Chris@1332 830 }
Chris@1332 831 break;
Chris@1332 832
Chris@1332 833 case MeterScale:
Chris@1332 834 if (!mergingChannels) {
Chris@1332 835 int r0 = abs(AudioLevel::multiplier_to_preview(range.min() * gain, m));
Chris@1332 836 int r1 = abs(AudioLevel::multiplier_to_preview(range.max() * gain, m));
Chris@1332 837 rangeTop = std::max(r0, r1);
Chris@1332 838 meanTop = std::min(r0, r1);
Chris@1332 839 if (mixingChannels) rangeBottom = meanTop;
Chris@1332 840 else rangeBottom = AudioLevel::multiplier_to_preview(range.absmean() * gain, m);
Chris@1332 841 meanBottom = rangeBottom;
Chris@1332 842 } else {
Chris@1332 843 rangeBottom = -AudioLevel::multiplier_to_preview(range.min() * gain, m * greyLevels);
Chris@1332 844 rangeTop = AudioLevel::multiplier_to_preview(range.max() * gain, m * greyLevels);
Chris@1332 845 meanBottom = -AudioLevel::multiplier_to_preview(range.absmean() * gain, m);
Chris@1332 846 meanTop = AudioLevel::multiplier_to_preview(range.absmean() * gain, m);
Chris@1332 847 }
Chris@1332 848 break;
Chris@1332 849 }
Chris@1332 850
Chris@1332 851 rangeBottom = my * greyLevels - rangeBottom;
Chris@1332 852 rangeTop = my * greyLevels - rangeTop;
Chris@1332 853 meanBottom = my - meanBottom;
Chris@1332 854 meanTop = my - meanTop;
Chris@1332 855
Chris@1332 856 int topFill = (rangeTop % greyLevels);
Chris@1332 857 if (topFill > 0) topFill = greyLevels - topFill;
Chris@1332 858
Chris@1332 859 int bottomFill = (rangeBottom % greyLevels);
Chris@1332 860
Chris@1332 861 rangeTop = rangeTop / greyLevels;
Chris@1332 862 rangeBottom = rangeBottom / greyLevels;
Chris@1332 863
Chris@1332 864 bool clipped = false;
Chris@1332 865
Chris@1332 866 if (rangeTop < my - m) { rangeTop = my - m; }
Chris@1332 867 if (rangeTop > my + m) { rangeTop = my + m; }
Chris@1332 868 if (rangeBottom < my - m) { rangeBottom = my - m; }
Chris@1332 869 if (rangeBottom > my + m) { rangeBottom = my + m; }
Chris@1332 870
Chris@1332 871 if (range.max() <= -1.0 ||
Chris@1332 872 range.max() >= 1.0) clipped = true;
Chris@1332 873
Chris@1332 874 if (meanBottom > rangeBottom) meanBottom = rangeBottom;
Chris@1332 875 if (meanTop < rangeTop) meanTop = rangeTop;
Chris@1332 876
Chris@1332 877 bool drawMean = m_showMeans;
Chris@1332 878 if (meanTop == rangeTop) {
Chris@1332 879 if (meanTop < meanBottom) ++meanTop;
Chris@1332 880 else drawMean = false;
Chris@1332 881 }
Chris@1332 882 if (meanBottom == rangeBottom && m_scale == LinearScale) {
Chris@1332 883 if (meanBottom > meanTop) --meanBottom;
Chris@1332 884 else drawMean = false;
Chris@1332 885 }
Chris@1332 886
Chris@1332 887 if (x != x0 && prevRangeBottom != -1) {
Chris@1332 888 if (prevRangeBottom > rangeBottom + 1 &&
Chris@1332 889 prevRangeTop > rangeBottom + 1) {
Chris@1332 890 // paint->setPen(midColour);
Chris@1332 891 paint->setPen(baseColour);
Chris@1332 892 paint->drawLine(x-1, prevRangeTop, x, rangeBottom + 1);
Chris@1332 893 paint->setPen(prevRangeTopColour);
Chris@1332 894 paint->drawPoint(x-1, prevRangeTop);
Chris@1332 895 } else if (prevRangeBottom < rangeTop - 1 &&
Chris@1332 896 prevRangeTop < rangeTop - 1) {
Chris@1332 897 // paint->setPen(midColour);
Chris@1332 898 paint->setPen(baseColour);
Chris@1332 899 paint->drawLine(x-1, prevRangeBottom, x, rangeTop - 1);
Chris@1332 900 paint->setPen(prevRangeBottomColour);
Chris@1332 901 paint->drawPoint(x-1, prevRangeBottom);
Chris@1332 902 }
Chris@1332 903 }
Chris@1332 904
Chris@1332 905 if (m_model->isReady()) {
Chris@1332 906 if (clipped /*!!! ||
Chris@1332 907 range.min() * gain <= -1.0 ||
Chris@1332 908 range.max() * gain >= 1.0 */) {
Chris@1332 909 paint->setPen(Qt::red); //!!! getContrastingColour
Chris@1332 910 } else {
Chris@1332 911 paint->setPen(baseColour);
Chris@1332 912 }
Chris@1332 913 } else {
Chris@1332 914 paint->setPen(midColour);
Chris@1332 915 }
Chris@1332 916
Chris@1332 917 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1332 918 cerr << "range " << rangeBottom << " -> " << rangeTop << ", means " << meanBottom << " -> " << meanTop << ", raw range " << range.min() << " -> " << range.max() << endl;
Chris@1332 919 #endif
Chris@1332 920
Chris@1332 921 if (rangeTop == rangeBottom) {
Chris@1332 922 paint->drawPoint(x, rangeTop);
Chris@1332 923 } else {
Chris@1332 924 paint->drawLine(x, rangeBottom, x, rangeTop);
Chris@1332 925 }
Chris@1332 926
Chris@1332 927 prevRangeTopColour = baseColour;
Chris@1332 928 prevRangeBottomColour = baseColour;
Chris@1332 929
Chris@1332 930 if (m_greyscale && (m_scale == LinearScale) && m_model->isReady()) {
Chris@1332 931 if (!clipped) {
Chris@1332 932 if (rangeTop < rangeBottom) {
Chris@1332 933 if (topFill > 0 &&
Chris@1332 934 (!drawMean || (rangeTop < meanTop - 1))) {
Chris@1332 935 paint->setPen(greys[topFill - 1]);
Chris@1332 936 paint->drawPoint(x, rangeTop);
Chris@1332 937 prevRangeTopColour = greys[topFill - 1];
Chris@1332 938 }
Chris@1332 939 if (bottomFill > 0 &&
Chris@1332 940 (!drawMean || (rangeBottom > meanBottom + 1))) {
Chris@1332 941 paint->setPen(greys[bottomFill - 1]);
Chris@1332 942 paint->drawPoint(x, rangeBottom);
Chris@1332 943 prevRangeBottomColour = greys[bottomFill - 1];
Chris@1332 944 }
Chris@1332 945 }
Chris@1332 946 }
Chris@1332 947 }
Chris@1332 948
Chris@1332 949 if (drawMean) {
Chris@1332 950 paint->setPen(midColour);
Chris@1332 951 paint->drawLine(x, meanBottom, x, meanTop);
Chris@1332 952 }
Chris@1332 953
Chris@1332 954 prevRangeBottom = rangeBottom;
Chris@1332 955 prevRangeTop = rangeTop;
Chris@1332 956 }
Chris@1332 957 }
Chris@1332 958
Chris@1335 959 void
Chris@1336 960 WaveformLayer::paintChannelOversampled(LayerGeometryProvider *v,
Chris@1336 961 QPainter *paint,
Chris@1336 962 QRect rect,
Chris@1336 963 int ch,
Chris@1336 964 sv_frame_t frame0, sv_frame_t frame1)
Chris@1336 965 const
Chris@1336 966 {
Chris@1336 967 int x0 = rect.left();
Chris@1336 968 int y0 = rect.top();
Chris@1336 969
Chris@1336 970 int x1 = rect.right();
Chris@1336 971 int y1 = rect.bottom();
Chris@1336 972
Chris@1336 973 int h = v->getPaintHeight();
Chris@1336 974
Chris@1336 975 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@1336 976 bool mergingChannels = false, mixingChannels = false;
Chris@1336 977
Chris@1336 978 channels = getChannelArrangement(minChannel, maxChannel,
Chris@1336 979 mergingChannels, mixingChannels);
Chris@1336 980 if (channels == 0) return;
Chris@1336 981
Chris@1336 982 QColor baseColour = getBaseQColor();
Chris@1336 983 vector<QColor> greys = getPartialShades(v);
Chris@1336 984
Chris@1336 985 QColor midColour = baseColour;
Chris@1336 986 if (midColour == Qt::black) {
Chris@1336 987 midColour = Qt::gray;
Chris@1336 988 } else if (v->hasLightBackground()) {
Chris@1336 989 midColour = midColour.light(150);
Chris@1336 990 } else {
Chris@1336 991 midColour = midColour.light(50);
Chris@1336 992 }
Chris@1336 993
Chris@1336 994 double gain = m_effectiveGains[ch];
Chris@1336 995
Chris@1336 996 int m = (h / channels) / 2;
Chris@1336 997 int my = m + (((ch - minChannel) * h) / channels);
Chris@1336 998
Chris@1336 999 #ifdef DEBUG_WAVEFORM_PAINT
Chris@1336 1000 cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << endl;
Chris@1336 1001 #endif
Chris@1336 1002
Chris@1336 1003 if (my - m > y1 || my + m < y0) return;
Chris@1336 1004
Chris@1336 1005 if ((m_scale == dBScale || m_scale == MeterScale) &&
Chris@1336 1006 m_channelMode != MergeChannels) {
Chris@1336 1007 m = (h / channels);
Chris@1336 1008 my = m + (((ch - minChannel) * h) / channels);
Chris@1336 1009 }
Chris@1336 1010
Chris@1336 1011 paint->setPen(greys[1]);
Chris@1336 1012 paint->drawLine(x0, my, x1, my);
Chris@1336 1013
Chris@1336 1014 paintChannelScaleGuides(v, paint, rect, ch);
Chris@1336 1015
Chris@1336 1016 for (sv_frame_t f = frame0; f <= frame1; ++f) {
Chris@1336 1017
Chris@1336 1018 }
Chris@1336 1019 }
Chris@1336 1020
Chris@1336 1021 void
Chris@1335 1022 WaveformLayer::paintChannelScaleGuides(LayerGeometryProvider *v,
Chris@1335 1023 QPainter *paint,
Chris@1335 1024 QRect rect,
Chris@1335 1025 int ch) const
Chris@1335 1026 {
Chris@1335 1027 int x0 = rect.left();
Chris@1335 1028 int y0 = rect.top();
Chris@1335 1029
Chris@1335 1030 int x1 = rect.right();
Chris@1335 1031 int y1 = rect.bottom();
Chris@1335 1032
Chris@1335 1033 int n = 10;
Chris@1335 1034 int py = -1;
Chris@1335 1035
Chris@1335 1036 double gain = m_effectiveGains[ch];
Chris@1335 1037
Chris@1335 1038 if (v->hasLightBackground() &&
Chris@1335 1039 v->getViewManager() &&
Chris@1335 1040 v->getViewManager()->shouldShowScaleGuides()) {
Chris@1335 1041
Chris@1335 1042 paint->setPen(QColor(240, 240, 240));
Chris@1335 1043
Chris@1335 1044 for (int i = 1; i < n; ++i) {
Chris@1335 1045
Chris@1335 1046 double val = 0.0, nval = 0.0;
Chris@1335 1047
Chris@1335 1048 switch (m_scale) {
Chris@1335 1049
Chris@1335 1050 case LinearScale:
Chris@1335 1051 val = (i * gain) / n;
Chris@1335 1052 if (i > 0) nval = -val;
Chris@1335 1053 break;
Chris@1335 1054
Chris@1335 1055 case MeterScale:
Chris@1335 1056 val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain;
Chris@1335 1057 break;
Chris@1335 1058
Chris@1335 1059 case dBScale:
Chris@1335 1060 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain;
Chris@1335 1061 break;
Chris@1335 1062 }
Chris@1335 1063
Chris@1335 1064 if (val < -1.0 || val > 1.0) continue;
Chris@1335 1065
Chris@1335 1066 int y = getYForValue(v, val, ch);
Chris@1335 1067
Chris@1335 1068 if (py >= 0 && abs(y - py) < 10) continue;
Chris@1335 1069 else py = y;
Chris@1335 1070
Chris@1335 1071 int ny = y;
Chris@1335 1072 if (nval != 0.0) {
Chris@1335 1073 ny = getYForValue(v, nval, ch);
Chris@1335 1074 }
Chris@1335 1075
Chris@1335 1076 paint->drawLine(x0, y, x1, y);
Chris@1335 1077 if (ny != y) {
Chris@1335 1078 paint->drawLine(x0, ny, x1, ny);
Chris@1335 1079 }
Chris@1335 1080 }
Chris@1335 1081 }
Chris@1335 1082 }
Chris@1335 1083
Chris@25 1084 QString
Chris@918 1085 WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
Chris@25 1086 {
Chris@25 1087 int x = pos.x();
Chris@25 1088
Chris@25 1089 if (!m_model || !m_model->isOK()) return "";
Chris@25 1090
Chris@1325 1091 ZoomLevel zoomLevel = v->getZoomLevel();
Chris@25 1092
Chris@1325 1093 int desiredBlockSize = 1;
Chris@1325 1094 if (zoomLevel.zone == ZoomLevel::FramesPerPixel) {
Chris@1325 1095 desiredBlockSize = zoomLevel.level;
Chris@1325 1096 }
Chris@1325 1097
Chris@1325 1098 int blockSize = m_model->getSummaryBlockSize(desiredBlockSize);
Chris@365 1099
Chris@908 1100 sv_frame_t f0, f1;
Chris@1325 1101 if (!getSourceFramesForX(v, x, blockSize, f0, f1)) return "";
Chris@25 1102
Chris@25 1103 QString text;
Chris@25 1104
Chris@25 1105 RealTime rt0 = RealTime::frame2RealTime(f0, m_model->getSampleRate());
Chris@25 1106 RealTime rt1 = RealTime::frame2RealTime(f1, m_model->getSampleRate());
Chris@25 1107
Chris@25 1108 if (f1 != f0 + 1 && (rt0.sec != rt1.sec || rt0.msec() != rt1.msec())) {
Chris@1266 1109 text += tr("Time:\t%1 - %2")
Chris@1266 1110 .arg(rt0.toText(true).c_str())
Chris@1266 1111 .arg(rt1.toText(true).c_str());
Chris@25 1112 } else {
Chris@1266 1113 text += tr("Time:\t%1")
Chris@1266 1114 .arg(rt0.toText(true).c_str());
Chris@25 1115 }
Chris@25 1116
Chris@805 1117 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@67 1118 bool mergingChannels = false, mixingChannels = false;
Chris@25 1119
Chris@67 1120 channels = getChannelArrangement(minChannel, maxChannel,
Chris@67 1121 mergingChannels, mixingChannels);
Chris@25 1122 if (channels == 0) return "";
Chris@25 1123
Chris@805 1124 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@25 1125
Chris@1266 1126 RangeSummarisableTimeValueModel::RangeBlock ranges;
Chris@302 1127 m_model->getSummaries(ch, f0, f1 - f0, ranges, blockSize);
Chris@25 1128
Chris@1266 1129 if (ranges.empty()) continue;
Chris@1266 1130
Chris@1266 1131 RangeSummarisableTimeValueModel::Range range = ranges[0];
Chris@1266 1132
Chris@1266 1133 QString label = tr("Level:");
Chris@1266 1134 if (minChannel != maxChannel) {
Chris@1266 1135 if (ch == 0) label = tr("Left:");
Chris@1266 1136 else if (ch == 1) label = tr("Right:");
Chris@1266 1137 else label = tr("Channel %1").arg(ch + 1);
Chris@1266 1138 }
Chris@25 1139
Chris@76 1140 bool singleValue = false;
Chris@908 1141 double min, max;
Chris@76 1142
Chris@386 1143 if (fabs(range.min()) < 0.01) {
Chris@386 1144 min = range.min();
Chris@386 1145 max = range.max();
Chris@76 1146 singleValue = (min == max);
Chris@76 1147 } else {
Chris@908 1148 int imin = int(lrint(range.min() * 10000));
Chris@908 1149 int imax = int(lrint(range.max() * 10000));
Chris@76 1150 singleValue = (imin == imax);
Chris@908 1151 min = double(imin)/10000;
Chris@908 1152 max = double(imax)/10000;
Chris@76 1153 }
Chris@76 1154
Chris@1266 1155 int db = int(AudioLevel::multiplier_to_dB(std::max(fabsf(range.min()),
Chris@1266 1156 fabsf(range.max())))
Chris@1266 1157 * 100);
Chris@25 1158
Chris@1266 1159 if (!singleValue) {
Chris@1266 1160 text += tr("\n%1\t%2 - %3 (%4 dB peak)")
Chris@1266 1161 .arg(label).arg(min).arg(max).arg(double(db)/100);
Chris@1266 1162 } else {
Chris@1266 1163 text += tr("\n%1\t%2 (%3 dB peak)")
Chris@1266 1164 .arg(label).arg(min).arg(double(db)/100);
Chris@1266 1165 }
Chris@25 1166 }
Chris@25 1167
Chris@25 1168 return text;
Chris@25 1169 }
Chris@25 1170
Chris@0 1171 int
Chris@918 1172 WaveformLayer::getYForValue(const LayerGeometryProvider *v, double value, int channel) const
Chris@68 1173 {
Chris@805 1174 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@274 1175 bool mergingChannels = false, mixingChannels = false;
Chris@274 1176
Chris@274 1177 channels = getChannelArrangement(minChannel, maxChannel,
Chris@274 1178 mergingChannels, mixingChannels);
Chris@853 1179 if (channels == 0) return 0;
Chris@68 1180 if (maxChannel < minChannel || channel < minChannel) return 0;
Chris@68 1181
Chris@918 1182 int h = v->getPaintHeight();
Chris@68 1183 int m = (h / channels) / 2;
Chris@1266 1184
Chris@68 1185 if ((m_scale == dBScale || m_scale == MeterScale) &&
Chris@68 1186 m_channelMode != MergeChannels) {
Chris@68 1187 m = (h / channels);
Chris@68 1188 }
Chris@68 1189
Chris@274 1190 int my = m + (((channel - minChannel) * h) / channels);
Chris@274 1191
Chris@68 1192 int vy = 0;
Chris@68 1193
Chris@274 1194 switch (m_scale) {
Chris@68 1195
Chris@68 1196 case LinearScale:
Chris@68 1197 vy = int(m * value);
Chris@68 1198 break;
Chris@68 1199
Chris@68 1200 case MeterScale:
Chris@68 1201 vy = AudioLevel::multiplier_to_preview(value, m);
Chris@68 1202 break;
Chris@68 1203
Chris@68 1204 case dBScale:
Chris@68 1205 vy = dBscale(value, m);
Chris@68 1206 break;
Chris@68 1207 }
Chris@68 1208
Chris@682 1209 // cerr << "mergingChannels= " << mergingChannels << ", channel = " << channel << ", value = " << value << ", vy = " << vy << endl;
Chris@324 1210
Chris@68 1211 return my - vy;
Chris@68 1212 }
Chris@68 1213
Chris@908 1214 double
Chris@918 1215 WaveformLayer::getValueForY(const LayerGeometryProvider *v, int y, int &channel) const
Chris@261 1216 {
Chris@805 1217 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@274 1218 bool mergingChannels = false, mixingChannels = false;
Chris@274 1219
Chris@274 1220 channels = getChannelArrangement(minChannel, maxChannel,
Chris@274 1221 mergingChannels, mixingChannels);
Chris@853 1222 if (channels == 0) return 0;
Chris@261 1223 if (maxChannel < minChannel) return 0;
Chris@261 1224
Chris@918 1225 int h = v->getPaintHeight();
Chris@261 1226 int m = (h / channels) / 2;
Chris@261 1227
Chris@261 1228 if ((m_scale == dBScale || m_scale == MeterScale) &&
Chris@261 1229 m_channelMode != MergeChannels) {
Chris@261 1230 m = (h / channels);
Chris@261 1231 }
Chris@274 1232
Chris@274 1233 channel = (y * channels) / h + minChannel;
Chris@261 1234
Chris@261 1235 int my = m + (((channel - minChannel) * h) / channels);
Chris@261 1236
Chris@262 1237 int vy = my - y;
Chris@908 1238 double value = 0;
Chris@908 1239 double thresh = -50.f;
Chris@261 1240
Chris@274 1241 switch (m_scale) {
Chris@261 1242
Chris@261 1243 case LinearScale:
Chris@908 1244 value = double(vy) / m;
Chris@261 1245 break;
Chris@261 1246
Chris@261 1247 case MeterScale:
Chris@261 1248 value = AudioLevel::preview_to_multiplier(vy, m);
Chris@261 1249 break;
Chris@261 1250
Chris@261 1251 case dBScale:
Chris@908 1252 value = (-thresh * double(vy)) / m + thresh;
Chris@274 1253 value = AudioLevel::dB_to_multiplier(value);
Chris@261 1254 break;
Chris@261 1255 }
Chris@261 1256
Chris@274 1257 return value / m_gain;
Chris@261 1258 }
Chris@261 1259
Chris@261 1260 bool
Chris@918 1261 WaveformLayer::getYScaleValue(const LayerGeometryProvider *v, int y,
Chris@908 1262 double &value, QString &unit) const
Chris@261 1263 {
Chris@805 1264 int channel;
Chris@261 1265
Chris@274 1266 value = getValueForY(v, y, channel);
Chris@261 1267
Chris@274 1268 if (m_scale == dBScale || m_scale == MeterScale) {
Chris@261 1269
Chris@908 1270 double thresh = -50.f;
Chris@274 1271
Chris@908 1272 if (value > 0.0) {
Chris@908 1273 value = 10.0 * log10(value);
Chris@274 1274 if (value < thresh) value = thresh;
Chris@274 1275 } else value = thresh;
Chris@274 1276
Chris@274 1277 unit = "dBV";
Chris@274 1278
Chris@274 1279 } else {
Chris@274 1280 unit = "V";
Chris@274 1281 }
Chris@274 1282
Chris@274 1283 return true;
Chris@274 1284 }
Chris@274 1285
Chris@274 1286 bool
Chris@918 1287 WaveformLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
Chris@908 1288 double &diff, QString &unit) const
Chris@274 1289 {
Chris@805 1290 int c0, c1;
Chris@908 1291 double v0 = getValueForY(v, y0, c0);
Chris@908 1292 double v1 = getValueForY(v, y1, c1);
Chris@274 1293
Chris@274 1294 if (c0 != c1) {
Chris@274 1295 // different channels, not comparable
Chris@908 1296 diff = 0.0;
Chris@274 1297 unit = "";
Chris@274 1298 return false;
Chris@274 1299 }
Chris@274 1300
Chris@274 1301 if (m_scale == dBScale || m_scale == MeterScale) {
Chris@274 1302
Chris@908 1303 double thresh = -50.0;
Chris@274 1304
Chris@274 1305 if (v1 == v0) diff = thresh;
Chris@274 1306 else {
Chris@274 1307 if (v1 > v0) diff = v0 / v1;
Chris@274 1308 else diff = v1 / v0;
Chris@274 1309
Chris@908 1310 diff = 10.0 * log10(diff);
Chris@274 1311 if (diff < thresh) diff = thresh;
Chris@274 1312 }
Chris@274 1313
Chris@274 1314 unit = "dBV";
Chris@274 1315
Chris@274 1316 } else {
Chris@908 1317 diff = fabs(v1 - v0);
Chris@274 1318 unit = "V";
Chris@274 1319 }
Chris@274 1320
Chris@261 1321 return true;
Chris@261 1322 }
Chris@261 1323
Chris@68 1324 int
Chris@918 1325 WaveformLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
Chris@0 1326 {
Chris@0 1327 if (m_scale == LinearScale) {
Chris@1266 1328 return paint.fontMetrics().width("0.0") + 13;
Chris@0 1329 } else {
Chris@1266 1330 return std::max(paint.fontMetrics().width(tr("0dB")),
Chris@1266 1331 paint.fontMetrics().width(Strings::minus_infinity)) + 13;
Chris@0 1332 }
Chris@0 1333 }
Chris@0 1334
Chris@0 1335 void
Chris@918 1336 WaveformLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
Chris@0 1337 {
Chris@0 1338 if (!m_model || !m_model->isOK()) {
Chris@1266 1339 return;
Chris@0 1340 }
Chris@0 1341
Chris@805 1342 int channels = 0, minChannel = 0, maxChannel = 0;
Chris@67 1343 bool mergingChannels = false, mixingChannels = false;
Chris@0 1344
Chris@67 1345 channels = getChannelArrangement(minChannel, maxChannel,
Chris@67 1346 mergingChannels, mixingChannels);
Chris@0 1347 if (channels == 0) return;
Chris@0 1348
Chris@0 1349 int h = rect.height(), w = rect.width();
Chris@0 1350 int textHeight = paint.fontMetrics().height();
Chris@0 1351 int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1;
Chris@0 1352
Chris@908 1353 double gain = m_gain;
Chris@67 1354
Chris@805 1355 for (int ch = minChannel; ch <= maxChannel; ++ch) {
Chris@0 1356
Chris@1266 1357 int lastLabelledY = -1;
Chris@0 1358
Chris@805 1359 if (ch < (int)m_effectiveGains.size()) gain = m_effectiveGains[ch];
Chris@67 1360
Chris@68 1361 int n = 10;
Chris@0 1362
Chris@1266 1363 for (int i = 0; i <= n; ++i) {
Chris@68 1364
Chris@908 1365 double val = 0.0, nval = 0.0;
Chris@1266 1366 QString text = "";
Chris@0 1367
Chris@68 1368 switch (m_scale) {
Chris@68 1369
Chris@68 1370 case LinearScale:
Chris@68 1371 val = (i * gain) / n;
Chris@1266 1372 text = QString("%1").arg(double(i) / n);
Chris@1266 1373 if (i == 0) text = "0.0";
Chris@68 1374 else {
Chris@68 1375 nval = -val;
Chris@68 1376 if (i == n) text = "1.0";
Chris@68 1377 }
Chris@68 1378 break;
Chris@0 1379
Chris@68 1380 case MeterScale:
Chris@68 1381 val = AudioLevel::dB_to_multiplier(meterdbs[i]) * gain;
Chris@1266 1382 text = QString("%1").arg(meterdbs[i]);
Chris@1266 1383 if (i == n) text = tr("0dB");
Chris@1266 1384 if (i == 0) {
Chris@1147 1385 text = Strings::minus_infinity;
Chris@68 1386 val = 0.0;
Chris@1266 1387 }
Chris@68 1388 break;
Chris@0 1389
Chris@68 1390 case dBScale:
Chris@68 1391 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10) * gain;
Chris@1266 1392 text = QString("%1").arg(-(10*n) + i * 10);
Chris@1266 1393 if (i == n) text = tr("0dB");
Chris@1266 1394 if (i == 0) {
Chris@1147 1395 text = Strings::minus_infinity;
Chris@68 1396 val = 0.0;
Chris@1266 1397 }
Chris@68 1398 break;
Chris@68 1399 }
Chris@0 1400
Chris@68 1401 if (val < -1.0 || val > 1.0) continue;
Chris@0 1402
Chris@274 1403 int y = getYForValue(v, val, ch);
Chris@0 1404
Chris@68 1405 int ny = y;
Chris@68 1406 if (nval != 0.0) {
Chris@274 1407 ny = getYForValue(v, nval, ch);
Chris@68 1408 }
Chris@0 1409
Chris@68 1410 bool spaceForLabel = (i == 0 ||
Chris@68 1411 abs(y - lastLabelledY) >= textHeight - 1);
Chris@0 1412
Chris@68 1413 if (spaceForLabel) {
Chris@0 1414
Chris@68 1415 int tx = 3;
Chris@68 1416 if (m_scale != LinearScale) {
Chris@68 1417 tx = w - 10 - paint.fontMetrics().width(text);
Chris@68 1418 }
Chris@68 1419
Chris@68 1420 int ty = y;
Chris@68 1421 if (ty < paint.fontMetrics().ascent()) {
Chris@68 1422 ty = paint.fontMetrics().ascent();
Chris@68 1423 } else if (ty > h - paint.fontMetrics().descent()) {
Chris@68 1424 ty = h - paint.fontMetrics().descent();
Chris@68 1425 } else {
Chris@68 1426 ty += toff;
Chris@68 1427 }
Chris@68 1428 paint.drawText(tx, ty, text);
Chris@0 1429
Chris@68 1430 lastLabelledY = ty - toff;
Chris@67 1431
Chris@68 1432 if (ny != y) {
Chris@68 1433 ty = ny;
Chris@68 1434 if (ty < paint.fontMetrics().ascent()) {
Chris@68 1435 ty = paint.fontMetrics().ascent();
Chris@68 1436 } else if (ty > h - paint.fontMetrics().descent()) {
Chris@68 1437 ty = h - paint.fontMetrics().descent();
Chris@68 1438 } else {
Chris@68 1439 ty += toff;
Chris@68 1440 }
Chris@68 1441 paint.drawText(tx, ty, text);
Chris@68 1442 }
Chris@68 1443
Chris@68 1444 paint.drawLine(w - 7, y, w, y);
Chris@68 1445 if (ny != y) paint.drawLine(w - 7, ny, w, ny);
Chris@68 1446
Chris@68 1447 } else {
Chris@68 1448
Chris@68 1449 paint.drawLine(w - 4, y, w, y);
Chris@68 1450 if (ny != y) paint.drawLine(w - 4, ny, w, ny);
Chris@68 1451 }
Chris@1266 1452 }
Chris@0 1453 }
Chris@0 1454 }
Chris@0 1455
Chris@316 1456 void
Chris@316 1457 WaveformLayer::toXml(QTextStream &stream,
Chris@316 1458 QString indent, QString extraAttributes) const
Chris@6 1459 {
Chris@6 1460 QString s;
Chris@6 1461
Chris@285 1462 QString colourName, colourSpec, darkbg;
Chris@285 1463 ColourDatabase::getInstance()->getStringValues
Chris@285 1464 (m_colour, colourName, colourSpec, darkbg);
Chris@285 1465
Chris@6 1466 s += QString("gain=\"%1\" "
Chris@1266 1467 "showMeans=\"%2\" "
Chris@1266 1468 "greyscale=\"%3\" "
Chris@1266 1469 "channelMode=\"%4\" "
Chris@1266 1470 "channel=\"%5\" "
Chris@287 1471 "scale=\"%6\" "
Chris@709 1472 "middleLineHeight=\"%7\" "
Chris@1266 1473 "aggressive=\"%8\" "
Chris@709 1474 "autoNormalize=\"%9\"")
Chris@1266 1475 .arg(m_gain)
Chris@1266 1476 .arg(m_showMeans)
Chris@1266 1477 .arg(m_greyscale)
Chris@1266 1478 .arg(m_channelMode)
Chris@1266 1479 .arg(m_channel)
Chris@1266 1480 .arg(m_scale)
Chris@709 1481 .arg(m_middleLineHeight)
Chris@1266 1482 .arg(m_aggressive)
Chris@67 1483 .arg(m_autoNormalize);
Chris@6 1484
Chris@316 1485 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
Chris@6 1486 }
Chris@6 1487
Chris@11 1488 void
Chris@11 1489 WaveformLayer::setProperties(const QXmlAttributes &attributes)
Chris@11 1490 {
Chris@11 1491 bool ok = false;
Chris@11 1492
Chris@287 1493 SingleColourLayer::setProperties(attributes);
Chris@287 1494
Chris@11 1495 float gain = attributes.value("gain").toFloat(&ok);
Chris@11 1496 if (ok) setGain(gain);
Chris@11 1497
Chris@11 1498 bool showMeans = (attributes.value("showMeans") == "1" ||
Chris@1266 1499 attributes.value("showMeans") == "true");
Chris@11 1500 setShowMeans(showMeans);
Chris@11 1501
Chris@11 1502 bool greyscale = (attributes.value("greyscale") == "1" ||
Chris@1266 1503 attributes.value("greyscale") == "true");
Chris@11 1504 setUseGreyscale(greyscale);
Chris@11 1505
Chris@11 1506 ChannelMode channelMode = (ChannelMode)
Chris@1266 1507 attributes.value("channelMode").toInt(&ok);
Chris@11 1508 if (ok) setChannelMode(channelMode);
Chris@11 1509
Chris@11 1510 int channel = attributes.value("channel").toInt(&ok);
Chris@11 1511 if (ok) setChannel(channel);
Chris@11 1512
Chris@709 1513 Scale scale = (Scale)attributes.value("scale").toInt(&ok);
Chris@11 1514 if (ok) setScale(scale);
Chris@11 1515
Chris@709 1516 float middleLineHeight = attributes.value("middleLineHeight").toFloat(&ok);
Chris@709 1517 if (ok) setMiddleLineHeight(middleLineHeight);
Chris@709 1518
Chris@11 1519 bool aggressive = (attributes.value("aggressive") == "1" ||
Chris@1266 1520 attributes.value("aggressive") == "true");
Chris@11 1521 setUseGreyscale(aggressive);
Chris@67 1522
Chris@67 1523 bool autoNormalize = (attributes.value("autoNormalize") == "1" ||
Chris@67 1524 attributes.value("autoNormalize") == "true");
Chris@67 1525 setAutoNormalize(autoNormalize);
Chris@11 1526 }
Chris@11 1527
Chris@133 1528 int
Chris@133 1529 WaveformLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@133 1530 {
Chris@133 1531 defaultStep = 50;
Chris@133 1532 return 100;
Chris@133 1533 }
Chris@0 1534
Chris@133 1535 int
Chris@133 1536 WaveformLayer::getCurrentVerticalZoomStep() const
Chris@133 1537 {
Chris@908 1538 int val = int(lrint(log10(m_gain) * 20.0) + 50);
Chris@133 1539 if (val < 0) val = 0;
Chris@133 1540 if (val > 100) val = 100;
Chris@133 1541 return val;
Chris@133 1542 }
Chris@133 1543
Chris@133 1544 void
Chris@133 1545 WaveformLayer::setVerticalZoomStep(int step)
Chris@133 1546 {
Chris@908 1547 setGain(powf(10, float(step - 50) / 20.f));
Chris@133 1548 }
Chris@133 1549