annotate layer/SpectrogramLayer.cpp @ 1112:d578b685d912 spectrogram-minor-refactor

Colourmap rotation (inelegantly)
author Chris Cannam
date Tue, 19 Jul 2016 10:12:30 +0100
parents 8abdefce36a6
children 261a00010918
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@484 7 This file copyright 2006-2009 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 "SpectrogramLayer.h"
Chris@0 17
Chris@128 18 #include "view/View.h"
Chris@0 19 #include "base/Profiler.h"
Chris@0 20 #include "base/AudioLevel.h"
Chris@0 21 #include "base/Window.h"
Chris@24 22 #include "base/Pitch.h"
Chris@118 23 #include "base/Preferences.h"
Chris@167 24 #include "base/RangeMapper.h"
Chris@253 25 #include "base/LogRange.h"
Chris@1063 26 #include "base/ColumnOp.h"
Chris@376 27 #include "widgets/CommandHistory.h"
Chris@1078 28 #include "data/model/Dense3DModelPeakCache.h"
Chris@1078 29
Chris@376 30 #include "ColourMapper.h"
Chris@283 31 #include "ImageRegionFinder.h"
Chris@690 32 #include "PianoScale.h"
Chris@1078 33 #include "PaintAssistant.h"
Chris@1089 34 #include "Colour3DPlotRenderer.h"
Chris@0 35
Chris@0 36 #include <QPainter>
Chris@0 37 #include <QImage>
Chris@0 38 #include <QPixmap>
Chris@0 39 #include <QRect>
Chris@92 40 #include <QApplication>
Chris@178 41 #include <QMessageBox>
Chris@283 42 #include <QMouseEvent>
Chris@316 43 #include <QTextStream>
Chris@1017 44 #include <QSettings>
Chris@0 45
Chris@0 46 #include <iostream>
Chris@0 47
Chris@0 48 #include <cassert>
Chris@0 49 #include <cmath>
Chris@0 50
Chris@545 51 #ifndef __GNUC__
Chris@545 52 #include <alloca.h>
Chris@545 53 #endif
Chris@545 54
Chris@1090 55 #define DEBUG_SPECTROGRAM 1
Chris@1044 56 #define DEBUG_SPECTROGRAM_REPAINT 1
Chris@1025 57
Chris@1025 58 using namespace std;
Chris@907 59
Chris@44 60 SpectrogramLayer::SpectrogramLayer(Configuration config) :
Chris@0 61 m_model(0),
Chris@0 62 m_channel(0),
Chris@0 63 m_windowSize(1024),
Chris@0 64 m_windowType(HanningWindow),
Chris@97 65 m_windowHopLevel(2),
Chris@0 66 m_gain(1.0),
Chris@215 67 m_initialGain(1.0),
Chris@37 68 m_threshold(0.0),
Chris@215 69 m_initialThreshold(0.0),
Chris@9 70 m_colourRotation(0),
Chris@215 71 m_initialRotation(0),
Chris@119 72 m_minFrequency(10),
Chris@0 73 m_maxFrequency(8000),
Chris@135 74 m_initialMaxFrequency(8000),
Chris@1105 75 m_colourScale(ColourScaleType::Log),
Chris@197 76 m_colourMap(0),
Chris@1103 77 m_binScale(BinScale::Linear),
Chris@1103 78 m_binDisplay(BinDisplay::AllBins),
Chris@1104 79 m_normalization(ColumnNormalization::None),
Chris@1104 80 m_normalizeVisibleArea(false),
Chris@133 81 m_lastEmittedZoomStep(-1),
Chris@390 82 m_synchronous(false),
Chris@608 83 m_haveDetailedScale(false),
Chris@193 84 m_exiting(false),
Chris@1088 85 m_fftModel(0),
Chris@1088 86 m_peakCache(0),
Chris@1088 87 m_peakCacheDivisor(8)
Chris@0 88 {
Chris@1017 89 QString colourConfigName = "spectrogram-colour";
Chris@1017 90 int colourConfigDefault = int(ColourMapper::Green);
Chris@1017 91
Chris@215 92 if (config == FullRangeDb) {
Chris@215 93 m_initialMaxFrequency = 0;
Chris@215 94 setMaxFrequency(0);
Chris@215 95 } else if (config == MelodicRange) {
Chris@0 96 setWindowSize(8192);
Chris@97 97 setWindowHopLevel(4);
Chris@215 98 m_initialMaxFrequency = 1500;
Chris@215 99 setMaxFrequency(1500);
Chris@215 100 setMinFrequency(40);
Chris@1105 101 setColourScale(ColourScaleType::Linear);
Chris@215 102 setColourMap(ColourMapper::Sunset);
Chris@1103 103 setBinScale(BinScale::Log);
Chris@1017 104 colourConfigName = "spectrogram-melodic-colour";
Chris@1017 105 colourConfigDefault = int(ColourMapper::Sunset);
Chris@224 106 // setGain(20);
Chris@37 107 } else if (config == MelodicPeaks) {
Chris@37 108 setWindowSize(4096);
Chris@97 109 setWindowHopLevel(5);
Chris@135 110 m_initialMaxFrequency = 2000;
Chris@40 111 setMaxFrequency(2000);
Chris@37 112 setMinFrequency(40);
Chris@1103 113 setBinScale(BinScale::Log);
Chris@1105 114 setColourScale(ColourScaleType::Linear);
Chris@1103 115 setBinDisplay(BinDisplay::PeakFrequencies);
Chris@1104 116 setNormalization(ColumnNormalization::Max1);
Chris@1017 117 colourConfigName = "spectrogram-melodic-colour";
Chris@1017 118 colourConfigDefault = int(ColourMapper::Sunset);
Chris@0 119 }
Chris@110 120
Chris@1017 121 QSettings settings;
Chris@1017 122 settings.beginGroup("Preferences");
Chris@1017 123 setColourMap(settings.value(colourConfigName, colourConfigDefault).toInt());
Chris@1017 124 settings.endGroup();
Chris@1017 125
Chris@122 126 Preferences *prefs = Preferences::getInstance();
Chris@122 127 connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
Chris@122 128 this, SLOT(preferenceChanged(PropertyContainer::PropertyName)));
Chris@122 129 setWindowType(prefs->getWindowType());
Chris@0 130 }
Chris@0 131
Chris@0 132 SpectrogramLayer::~SpectrogramLayer()
Chris@0 133 {
Chris@1106 134 invalidateRenderers();
Chris@1088 135 invalidateFFTModel();
Chris@0 136 }
Chris@0 137
Chris@1105 138 ColourScaleType
Chris@1104 139 SpectrogramLayer::convertToColourScale(int value)
Chris@1104 140 {
Chris@1104 141 switch (value) {
Chris@1105 142 case 0: return ColourScaleType::Linear;
Chris@1105 143 case 1: return ColourScaleType::Meter;
Chris@1105 144 case 2: return ColourScaleType::Log; //!!! db^2
Chris@1105 145 case 3: return ColourScaleType::Log;
Chris@1105 146 case 4: return ColourScaleType::Phase;
Chris@1105 147 default: return ColourScaleType::Linear;
Chris@1104 148 }
Chris@1104 149 }
Chris@1104 150
Chris@1104 151 int
Chris@1105 152 SpectrogramLayer::convertFromColourScale(ColourScaleType scale)
Chris@1104 153 {
Chris@1104 154 switch (scale) {
Chris@1105 155 case ColourScaleType::Linear: return 0;
Chris@1105 156 case ColourScaleType::Meter: return 1;
Chris@1105 157 case ColourScaleType::Log: return 3; //!!! + db^2
Chris@1105 158 case ColourScaleType::Phase: return 4;
Chris@1105 159
Chris@1105 160 case ColourScaleType::PlusMinusOne:
Chris@1105 161 case ColourScaleType::Absolute:
Chris@1104 162 default: return 0;
Chris@1104 163 }
Chris@1104 164 }
Chris@1104 165
Chris@1104 166 std::pair<ColumnNormalization, bool>
Chris@1104 167 SpectrogramLayer::convertToColumnNorm(int value)
Chris@1104 168 {
Chris@1104 169 switch (value) {
Chris@1104 170 default:
Chris@1104 171 case 0: return { ColumnNormalization::None, false };
Chris@1104 172 case 1: return { ColumnNormalization::Max1, false };
Chris@1104 173 case 2: return { ColumnNormalization::None, true }; // visible area
Chris@1104 174 case 3: return { ColumnNormalization::Hybrid, false };
Chris@1104 175 }
Chris@1104 176 }
Chris@1104 177
Chris@1104 178 int
Chris@1104 179 SpectrogramLayer::convertFromColumnNorm(ColumnNormalization norm, bool visible)
Chris@1104 180 {
Chris@1104 181 if (visible) return 2;
Chris@1104 182 switch (norm) {
Chris@1104 183 case ColumnNormalization::None: return 0;
Chris@1104 184 case ColumnNormalization::Max1: return 1;
Chris@1104 185 case ColumnNormalization::Hybrid: return 3;
Chris@1104 186
Chris@1104 187 case ColumnNormalization::Sum1:
Chris@1104 188 default: return 0;
Chris@1104 189 }
Chris@1104 190 }
Chris@1104 191
Chris@0 192 void
Chris@0 193 SpectrogramLayer::setModel(const DenseTimeValueModel *model)
Chris@0 194 {
Chris@682 195 // cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << endl;
Chris@34 196
Chris@110 197 if (model == m_model) return;
Chris@110 198
Chris@0 199 m_model = model;
Chris@1088 200 invalidateFFTModel();
Chris@0 201
Chris@0 202 if (!m_model || !m_model->isOK()) return;
Chris@0 203
Chris@320 204 connectSignals(m_model);
Chris@0 205
Chris@0 206 connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid()));
Chris@906 207 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
Chris@906 208 this, SLOT(cacheInvalid(sv_frame_t, sv_frame_t)));
Chris@0 209
Chris@0 210 emit modelReplaced();
Chris@110 211 }
Chris@115 212
Chris@0 213 Layer::PropertyList
Chris@0 214 SpectrogramLayer::getProperties() const
Chris@0 215 {
Chris@0 216 PropertyList list;
Chris@87 217 list.push_back("Colour");
Chris@87 218 list.push_back("Colour Scale");
Chris@87 219 list.push_back("Window Size");
Chris@97 220 list.push_back("Window Increment");
Chris@862 221 list.push_back("Normalization");
Chris@87 222 list.push_back("Bin Display");
Chris@87 223 list.push_back("Threshold");
Chris@87 224 list.push_back("Gain");
Chris@87 225 list.push_back("Colour Rotation");
Chris@153 226 // list.push_back("Min Frequency");
Chris@153 227 // list.push_back("Max Frequency");
Chris@87 228 list.push_back("Frequency Scale");
Chris@0 229 return list;
Chris@0 230 }
Chris@0 231
Chris@87 232 QString
Chris@87 233 SpectrogramLayer::getPropertyLabel(const PropertyName &name) const
Chris@87 234 {
Chris@87 235 if (name == "Colour") return tr("Colour");
Chris@87 236 if (name == "Colour Scale") return tr("Colour Scale");
Chris@87 237 if (name == "Window Size") return tr("Window Size");
Chris@112 238 if (name == "Window Increment") return tr("Window Overlap");
Chris@862 239 if (name == "Normalization") return tr("Normalization");
Chris@87 240 if (name == "Bin Display") return tr("Bin Display");
Chris@87 241 if (name == "Threshold") return tr("Threshold");
Chris@87 242 if (name == "Gain") return tr("Gain");
Chris@87 243 if (name == "Colour Rotation") return tr("Colour Rotation");
Chris@87 244 if (name == "Min Frequency") return tr("Min Frequency");
Chris@87 245 if (name == "Max Frequency") return tr("Max Frequency");
Chris@87 246 if (name == "Frequency Scale") return tr("Frequency Scale");
Chris@87 247 return "";
Chris@87 248 }
Chris@87 249
Chris@335 250 QString
Chris@862 251 SpectrogramLayer::getPropertyIconName(const PropertyName &) const
Chris@335 252 {
Chris@335 253 return "";
Chris@335 254 }
Chris@335 255
Chris@0 256 Layer::PropertyType
Chris@0 257 SpectrogramLayer::getPropertyType(const PropertyName &name) const
Chris@0 258 {
Chris@87 259 if (name == "Gain") return RangeProperty;
Chris@87 260 if (name == "Colour Rotation") return RangeProperty;
Chris@87 261 if (name == "Threshold") return RangeProperty;
Chris@0 262 return ValueProperty;
Chris@0 263 }
Chris@0 264
Chris@0 265 QString
Chris@0 266 SpectrogramLayer::getPropertyGroupName(const PropertyName &name) const
Chris@0 267 {
Chris@153 268 if (name == "Bin Display" ||
Chris@153 269 name == "Frequency Scale") return tr("Bins");
Chris@87 270 if (name == "Window Size" ||
Chris@1086 271 name == "Window Increment") return tr("Window");
Chris@87 272 if (name == "Colour" ||
Chris@87 273 name == "Threshold" ||
Chris@87 274 name == "Colour Rotation") return tr("Colour");
Chris@862 275 if (name == "Normalization" ||
Chris@153 276 name == "Gain" ||
Chris@87 277 name == "Colour Scale") return tr("Scale");
Chris@0 278 return QString();
Chris@0 279 }
Chris@0 280
Chris@0 281 int
Chris@0 282 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 283 int *min, int *max, int *deflt) const
Chris@0 284 {
Chris@216 285 int val = 0;
Chris@216 286
Chris@216 287 int garbage0, garbage1, garbage2;
Chris@55 288 if (!min) min = &garbage0;
Chris@55 289 if (!max) max = &garbage1;
Chris@216 290 if (!deflt) deflt = &garbage2;
Chris@10 291
Chris@87 292 if (name == "Gain") {
Chris@0 293
Chris@0 294 *min = -50;
Chris@0 295 *max = 50;
Chris@0 296
Chris@906 297 *deflt = int(lrint(log10(m_initialGain) * 20.0));
Chris@216 298 if (*deflt < *min) *deflt = *min;
Chris@216 299 if (*deflt > *max) *deflt = *max;
Chris@216 300
Chris@906 301 val = int(lrint(log10(m_gain) * 20.0));
Chris@216 302 if (val < *min) val = *min;
Chris@216 303 if (val > *max) val = *max;
Chris@0 304
Chris@87 305 } else if (name == "Threshold") {
Chris@37 306
Chris@37 307 *min = -50;
Chris@37 308 *max = 0;
Chris@37 309
Chris@906 310 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
Chris@216 311 if (*deflt < *min) *deflt = *min;
Chris@216 312 if (*deflt > *max) *deflt = *max;
Chris@216 313
Chris@906 314 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
Chris@216 315 if (val < *min) val = *min;
Chris@216 316 if (val > *max) val = *max;
Chris@37 317
Chris@87 318 } else if (name == "Colour Rotation") {
Chris@9 319
Chris@9 320 *min = 0;
Chris@9 321 *max = 256;
Chris@216 322 *deflt = m_initialRotation;
Chris@216 323
Chris@216 324 val = m_colourRotation;
Chris@9 325
Chris@87 326 } else if (name == "Colour Scale") {
Chris@0 327
Chris@1099 328 // linear, meter, db^2, db, phase
Chris@0 329 *min = 0;
Chris@176 330 *max = 4;
Chris@1092 331 *deflt = 2;
Chris@216 332
Chris@1104 333 val = convertFromColourScale(m_colourScale);
Chris@0 334
Chris@87 335 } else if (name == "Colour") {
Chris@0 336
Chris@0 337 *min = 0;
Chris@196 338 *max = ColourMapper::getColourMapCount() - 1;
Chris@216 339 *deflt = 0;
Chris@216 340
Chris@216 341 val = m_colourMap;
Chris@0 342
Chris@87 343 } else if (name == "Window Size") {
Chris@0 344
Chris@0 345 *min = 0;
Chris@0 346 *max = 10;
Chris@216 347 *deflt = 5;
Chris@0 348
Chris@216 349 val = 0;
Chris@0 350 int ws = m_windowSize;
Chris@216 351 while (ws > 32) { ws >>= 1; val ++; }
Chris@0 352
Chris@97 353 } else if (name == "Window Increment") {
Chris@0 354
Chris@0 355 *min = 0;
Chris@97 356 *max = 5;
Chris@216 357 *deflt = 2;
Chris@216 358
Chris@216 359 val = m_windowHopLevel;
Chris@0 360
Chris@87 361 } else if (name == "Min Frequency") {
Chris@37 362
Chris@37 363 *min = 0;
Chris@37 364 *max = 9;
Chris@216 365 *deflt = 1;
Chris@37 366
Chris@37 367 switch (m_minFrequency) {
Chris@216 368 case 0: default: val = 0; break;
Chris@216 369 case 10: val = 1; break;
Chris@216 370 case 20: val = 2; break;
Chris@216 371 case 40: val = 3; break;
Chris@216 372 case 100: val = 4; break;
Chris@216 373 case 250: val = 5; break;
Chris@216 374 case 500: val = 6; break;
Chris@216 375 case 1000: val = 7; break;
Chris@216 376 case 4000: val = 8; break;
Chris@216 377 case 10000: val = 9; break;
Chris@37 378 }
Chris@37 379
Chris@87 380 } else if (name == "Max Frequency") {
Chris@0 381
Chris@0 382 *min = 0;
Chris@0 383 *max = 9;
Chris@216 384 *deflt = 6;
Chris@0 385
Chris@0 386 switch (m_maxFrequency) {
Chris@216 387 case 500: val = 0; break;
Chris@216 388 case 1000: val = 1; break;
Chris@216 389 case 1500: val = 2; break;
Chris@216 390 case 2000: val = 3; break;
Chris@216 391 case 4000: val = 4; break;
Chris@216 392 case 6000: val = 5; break;
Chris@216 393 case 8000: val = 6; break;
Chris@216 394 case 12000: val = 7; break;
Chris@216 395 case 16000: val = 8; break;
Chris@216 396 default: val = 9; break;
Chris@0 397 }
Chris@0 398
Chris@87 399 } else if (name == "Frequency Scale") {
Chris@0 400
Chris@0 401 *min = 0;
Chris@0 402 *max = 1;
Chris@1103 403 *deflt = int(BinScale::Linear);
Chris@1093 404 val = (int)m_binScale;
Chris@0 405
Chris@87 406 } else if (name == "Bin Display") {
Chris@35 407
Chris@35 408 *min = 0;
Chris@35 409 *max = 2;
Chris@1103 410 *deflt = int(BinDisplay::AllBins);
Chris@216 411 val = (int)m_binDisplay;
Chris@35 412
Chris@862 413 } else if (name == "Normalization") {
Chris@36 414
Chris@862 415 *min = 0;
Chris@862 416 *max = 3;
Chris@1104 417 *deflt = 0;
Chris@1104 418
Chris@1104 419 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea);
Chris@120 420
Chris@0 421 } else {
Chris@216 422 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@0 423 }
Chris@0 424
Chris@216 425 return val;
Chris@0 426 }
Chris@0 427
Chris@0 428 QString
Chris@0 429 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name,
Chris@9 430 int value) const
Chris@0 431 {
Chris@87 432 if (name == "Colour") {
Chris@196 433 return ColourMapper::getColourMapName(value);
Chris@0 434 }
Chris@87 435 if (name == "Colour Scale") {
Chris@0 436 switch (value) {
Chris@0 437 default:
Chris@37 438 case 0: return tr("Linear");
Chris@37 439 case 1: return tr("Meter");
Chris@215 440 case 2: return tr("dBV^2");
Chris@215 441 case 3: return tr("dBV");
Chris@119 442 case 4: return tr("Phase");
Chris@0 443 }
Chris@0 444 }
Chris@862 445 if (name == "Normalization") {
Chris@862 446 return ""; // icon only
Chris@862 447 }
Chris@87 448 if (name == "Window Size") {
Chris@0 449 return QString("%1").arg(32 << value);
Chris@0 450 }
Chris@97 451 if (name == "Window Increment") {
Chris@0 452 switch (value) {
Chris@0 453 default:
Chris@112 454 case 0: return tr("None");
Chris@112 455 case 1: return tr("25 %");
Chris@112 456 case 2: return tr("50 %");
Chris@112 457 case 3: return tr("75 %");
Chris@112 458 case 4: return tr("87.5 %");
Chris@112 459 case 5: return tr("93.75 %");
Chris@0 460 }
Chris@0 461 }
Chris@87 462 if (name == "Min Frequency") {
Chris@37 463 switch (value) {
Chris@37 464 default:
Chris@38 465 case 0: return tr("No min");
Chris@37 466 case 1: return tr("10 Hz");
Chris@37 467 case 2: return tr("20 Hz");
Chris@37 468 case 3: return tr("40 Hz");
Chris@37 469 case 4: return tr("100 Hz");
Chris@37 470 case 5: return tr("250 Hz");
Chris@37 471 case 6: return tr("500 Hz");
Chris@37 472 case 7: return tr("1 KHz");
Chris@37 473 case 8: return tr("4 KHz");
Chris@37 474 case 9: return tr("10 KHz");
Chris@37 475 }
Chris@37 476 }
Chris@87 477 if (name == "Max Frequency") {
Chris@0 478 switch (value) {
Chris@0 479 default:
Chris@0 480 case 0: return tr("500 Hz");
Chris@0 481 case 1: return tr("1 KHz");
Chris@0 482 case 2: return tr("1.5 KHz");
Chris@0 483 case 3: return tr("2 KHz");
Chris@0 484 case 4: return tr("4 KHz");
Chris@0 485 case 5: return tr("6 KHz");
Chris@0 486 case 6: return tr("8 KHz");
Chris@0 487 case 7: return tr("12 KHz");
Chris@0 488 case 8: return tr("16 KHz");
Chris@38 489 case 9: return tr("No max");
Chris@0 490 }
Chris@0 491 }
Chris@87 492 if (name == "Frequency Scale") {
Chris@0 493 switch (value) {
Chris@0 494 default:
Chris@0 495 case 0: return tr("Linear");
Chris@0 496 case 1: return tr("Log");
Chris@0 497 }
Chris@0 498 }
Chris@87 499 if (name == "Bin Display") {
Chris@35 500 switch (value) {
Chris@35 501 default:
Chris@37 502 case 0: return tr("All Bins");
Chris@37 503 case 1: return tr("Peak Bins");
Chris@37 504 case 2: return tr("Frequencies");
Chris@35 505 }
Chris@35 506 }
Chris@0 507 return tr("<unknown>");
Chris@0 508 }
Chris@0 509
Chris@862 510 QString
Chris@862 511 SpectrogramLayer::getPropertyValueIconName(const PropertyName &name,
Chris@862 512 int value) const
Chris@862 513 {
Chris@862 514 if (name == "Normalization") {
Chris@862 515 switch(value) {
Chris@862 516 default:
Chris@862 517 case 0: return "normalise-none";
Chris@862 518 case 1: return "normalise-columns";
Chris@862 519 case 2: return "normalise";
Chris@862 520 case 3: return "normalise-hybrid";
Chris@862 521 }
Chris@862 522 }
Chris@862 523 return "";
Chris@862 524 }
Chris@862 525
Chris@167 526 RangeMapper *
Chris@167 527 SpectrogramLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@167 528 {
Chris@167 529 if (name == "Gain") {
Chris@167 530 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
Chris@167 531 }
Chris@167 532 if (name == "Threshold") {
Chris@167 533 return new LinearRangeMapper(-50, 0, -50, 0, tr("dB"));
Chris@167 534 }
Chris@167 535 return 0;
Chris@167 536 }
Chris@167 537
Chris@0 538 void
Chris@0 539 SpectrogramLayer::setProperty(const PropertyName &name, int value)
Chris@0 540 {
Chris@87 541 if (name == "Gain") {
Chris@906 542 setGain(float(pow(10, float(value)/20.0)));
Chris@87 543 } else if (name == "Threshold") {
Chris@37 544 if (value == -50) setThreshold(0.0);
Chris@906 545 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
Chris@87 546 } else if (name == "Colour Rotation") {
Chris@9 547 setColourRotation(value);
Chris@87 548 } else if (name == "Colour") {
Chris@197 549 setColourMap(value);
Chris@87 550 } else if (name == "Window Size") {
Chris@0 551 setWindowSize(32 << value);
Chris@97 552 } else if (name == "Window Increment") {
Chris@97 553 setWindowHopLevel(value);
Chris@87 554 } else if (name == "Min Frequency") {
Chris@37 555 switch (value) {
Chris@37 556 default:
Chris@37 557 case 0: setMinFrequency(0); break;
Chris@37 558 case 1: setMinFrequency(10); break;
Chris@37 559 case 2: setMinFrequency(20); break;
Chris@37 560 case 3: setMinFrequency(40); break;
Chris@37 561 case 4: setMinFrequency(100); break;
Chris@37 562 case 5: setMinFrequency(250); break;
Chris@37 563 case 6: setMinFrequency(500); break;
Chris@37 564 case 7: setMinFrequency(1000); break;
Chris@37 565 case 8: setMinFrequency(4000); break;
Chris@37 566 case 9: setMinFrequency(10000); break;
Chris@37 567 }
Chris@133 568 int vs = getCurrentVerticalZoomStep();
Chris@133 569 if (vs != m_lastEmittedZoomStep) {
Chris@133 570 emit verticalZoomChanged();
Chris@133 571 m_lastEmittedZoomStep = vs;
Chris@133 572 }
Chris@87 573 } else if (name == "Max Frequency") {
Chris@0 574 switch (value) {
Chris@0 575 case 0: setMaxFrequency(500); break;
Chris@0 576 case 1: setMaxFrequency(1000); break;
Chris@0 577 case 2: setMaxFrequency(1500); break;
Chris@0 578 case 3: setMaxFrequency(2000); break;
Chris@0 579 case 4: setMaxFrequency(4000); break;
Chris@0 580 case 5: setMaxFrequency(6000); break;
Chris@0 581 case 6: setMaxFrequency(8000); break;
Chris@0 582 case 7: setMaxFrequency(12000); break;
Chris@0 583 case 8: setMaxFrequency(16000); break;
Chris@0 584 default:
Chris@0 585 case 9: setMaxFrequency(0); break;
Chris@0 586 }
Chris@133 587 int vs = getCurrentVerticalZoomStep();
Chris@133 588 if (vs != m_lastEmittedZoomStep) {
Chris@133 589 emit verticalZoomChanged();
Chris@133 590 m_lastEmittedZoomStep = vs;
Chris@133 591 }
Chris@87 592 } else if (name == "Colour Scale") {
Chris@0 593 switch (value) {
Chris@0 594 default:
Chris@1105 595 case 0: setColourScale(ColourScaleType::Linear); break;
Chris@1105 596 case 1: setColourScale(ColourScaleType::Meter); break;
Chris@1105 597 case 2: setColourScale(ColourScaleType::Log); break; //!!! dB^2
Chris@1105 598 case 3: setColourScale(ColourScaleType::Log); break;
Chris@1105 599 case 4: setColourScale(ColourScaleType::Phase); break;
Chris@0 600 }
Chris@87 601 } else if (name == "Frequency Scale") {
Chris@0 602 switch (value) {
Chris@0 603 default:
Chris@1103 604 case 0: setBinScale(BinScale::Linear); break;
Chris@1103 605 case 1: setBinScale(BinScale::Log); break;
Chris@0 606 }
Chris@87 607 } else if (name == "Bin Display") {
Chris@35 608 switch (value) {
Chris@35 609 default:
Chris@1103 610 case 0: setBinDisplay(BinDisplay::AllBins); break;
Chris@1103 611 case 1: setBinDisplay(BinDisplay::PeakBins); break;
Chris@1103 612 case 2: setBinDisplay(BinDisplay::PeakFrequencies); break;
Chris@35 613 }
Chris@862 614 } else if (name == "Normalization") {
Chris@1104 615 auto n = convertToColumnNorm(value);
Chris@1104 616 setNormalization(n.first);
Chris@1104 617 setNormalizeVisibleArea(n.second);
Chris@0 618 }
Chris@0 619 }
Chris@0 620
Chris@0 621 void
Chris@1106 622 SpectrogramLayer::invalidateRenderers()
Chris@95 623 {
Chris@1044 624 #ifdef DEBUG_SPECTROGRAM
Chris@1106 625 cerr << "SpectrogramLayer::invalidateRenderers called" << endl;
Chris@1044 626 #endif
Chris@1106 627
Chris@1089 628 for (ViewRendererMap::iterator i = m_renderers.begin();
Chris@1089 629 i != m_renderers.end(); ++i) {
Chris@1089 630 delete i->second;
Chris@1089 631 }
Chris@1089 632 m_renderers.clear();
Chris@95 633 }
Chris@95 634
Chris@95 635 void
Chris@122 636 SpectrogramLayer::preferenceChanged(PropertyContainer::PropertyName name)
Chris@122 637 {
Chris@587 638 SVDEBUG << "SpectrogramLayer::preferenceChanged(" << name << ")" << endl;
Chris@122 639
Chris@122 640 if (name == "Window Type") {
Chris@122 641 setWindowType(Preferences::getInstance()->getWindowType());
Chris@122 642 return;
Chris@122 643 }
Chris@490 644 if (name == "Spectrogram Y Smoothing") {
Chris@1086 645 setWindowSize(m_windowSize);
Chris@1106 646 invalidateRenderers();
Chris@490 647 invalidateMagnitudes();
Chris@490 648 emit layerParametersChanged();
Chris@490 649 }
Chris@490 650 if (name == "Spectrogram X Smoothing") {
Chris@1106 651 invalidateRenderers();
Chris@122 652 invalidateMagnitudes();
Chris@122 653 emit layerParametersChanged();
Chris@122 654 }
Chris@122 655 if (name == "Tuning Frequency") {
Chris@122 656 emit layerParametersChanged();
Chris@122 657 }
Chris@122 658 }
Chris@122 659
Chris@122 660 void
Chris@0 661 SpectrogramLayer::setChannel(int ch)
Chris@0 662 {
Chris@0 663 if (m_channel == ch) return;
Chris@0 664
Chris@1106 665 invalidateRenderers();
Chris@0 666 m_channel = ch;
Chris@1088 667 invalidateFFTModel();
Chris@9 668
Chris@0 669 emit layerParametersChanged();
Chris@0 670 }
Chris@0 671
Chris@0 672 int
Chris@0 673 SpectrogramLayer::getChannel() const
Chris@0 674 {
Chris@0 675 return m_channel;
Chris@0 676 }
Chris@0 677
Chris@1086 678 int
Chris@1086 679 SpectrogramLayer::getFFTOversampling() const
Chris@1086 680 {
Chris@1103 681 if (m_binDisplay != BinDisplay::AllBins) {
Chris@1086 682 return 1;
Chris@1086 683 }
Chris@1086 684
Chris@1086 685 Preferences::SpectrogramSmoothing smoothing =
Chris@1086 686 Preferences::getInstance()->getSpectrogramSmoothing();
Chris@1086 687
Chris@1086 688 if (smoothing == Preferences::NoSpectrogramSmoothing ||
Chris@1086 689 smoothing == Preferences::SpectrogramInterpolated) {
Chris@1086 690 return 1;
Chris@1086 691 }
Chris@1086 692
Chris@1086 693 return 4;
Chris@1086 694 }
Chris@1086 695
Chris@1087 696 int
Chris@1087 697 SpectrogramLayer::getFFTSize() const
Chris@1087 698 {
Chris@1087 699 return m_windowSize * getFFTOversampling();
Chris@1087 700 }
Chris@1087 701
Chris@0 702 void
Chris@805 703 SpectrogramLayer::setWindowSize(int ws)
Chris@0 704 {
Chris@1087 705 if (m_windowSize == ws) return;
Chris@0 706
Chris@1106 707 invalidateRenderers();
Chris@0 708
Chris@0 709 m_windowSize = ws;
Chris@0 710
Chris@1088 711 invalidateFFTModel();
Chris@9 712
Chris@9 713 emit layerParametersChanged();
Chris@0 714 }
Chris@0 715
Chris@805 716 int
Chris@0 717 SpectrogramLayer::getWindowSize() const
Chris@0 718 {
Chris@0 719 return m_windowSize;
Chris@0 720 }
Chris@0 721
Chris@0 722 void
Chris@805 723 SpectrogramLayer::setWindowHopLevel(int v)
Chris@0 724 {
Chris@97 725 if (m_windowHopLevel == v) return;
Chris@0 726
Chris@1106 727 invalidateRenderers();
Chris@0 728
Chris@97 729 m_windowHopLevel = v;
Chris@0 730
Chris@1088 731 invalidateFFTModel();
Chris@9 732
Chris@9 733 emit layerParametersChanged();
Chris@9 734
Chris@110 735 // fillCache();
Chris@0 736 }
Chris@0 737
Chris@805 738 int
Chris@97 739 SpectrogramLayer::getWindowHopLevel() const
Chris@0 740 {
Chris@97 741 return m_windowHopLevel;
Chris@0 742 }
Chris@0 743
Chris@0 744 void
Chris@0 745 SpectrogramLayer::setWindowType(WindowType w)
Chris@0 746 {
Chris@0 747 if (m_windowType == w) return;
Chris@0 748
Chris@1106 749 invalidateRenderers();
Chris@0 750
Chris@0 751 m_windowType = w;
Chris@110 752
Chris@1088 753 invalidateFFTModel();
Chris@9 754
Chris@9 755 emit layerParametersChanged();
Chris@0 756 }
Chris@0 757
Chris@0 758 WindowType
Chris@0 759 SpectrogramLayer::getWindowType() const
Chris@0 760 {
Chris@0 761 return m_windowType;
Chris@0 762 }
Chris@0 763
Chris@0 764 void
Chris@0 765 SpectrogramLayer::setGain(float gain)
Chris@0 766 {
Chris@587 767 // SVDEBUG << "SpectrogramLayer::setGain(" << gain << ") (my gain is now "
Chris@585 768 // << m_gain << ")" << endl;
Chris@55 769
Chris@40 770 if (m_gain == gain) return;
Chris@0 771
Chris@1106 772 invalidateRenderers();
Chris@0 773
Chris@0 774 m_gain = gain;
Chris@0 775
Chris@9 776 emit layerParametersChanged();
Chris@0 777 }
Chris@0 778
Chris@0 779 float
Chris@0 780 SpectrogramLayer::getGain() const
Chris@0 781 {
Chris@0 782 return m_gain;
Chris@0 783 }
Chris@0 784
Chris@0 785 void
Chris@37 786 SpectrogramLayer::setThreshold(float threshold)
Chris@37 787 {
Chris@40 788 if (m_threshold == threshold) return;
Chris@37 789
Chris@1106 790 invalidateRenderers();
Chris@37 791
Chris@37 792 m_threshold = threshold;
Chris@37 793
Chris@37 794 emit layerParametersChanged();
Chris@37 795 }
Chris@37 796
Chris@37 797 float
Chris@37 798 SpectrogramLayer::getThreshold() const
Chris@37 799 {
Chris@37 800 return m_threshold;
Chris@37 801 }
Chris@37 802
Chris@37 803 void
Chris@805 804 SpectrogramLayer::setMinFrequency(int mf)
Chris@37 805 {
Chris@37 806 if (m_minFrequency == mf) return;
Chris@37 807
Chris@587 808 // SVDEBUG << "SpectrogramLayer::setMinFrequency: " << mf << endl;
Chris@187 809
Chris@1106 810 invalidateRenderers();
Chris@119 811 invalidateMagnitudes();
Chris@37 812
Chris@37 813 m_minFrequency = mf;
Chris@37 814
Chris@37 815 emit layerParametersChanged();
Chris@37 816 }
Chris@37 817
Chris@805 818 int
Chris@37 819 SpectrogramLayer::getMinFrequency() const
Chris@37 820 {
Chris@37 821 return m_minFrequency;
Chris@37 822 }
Chris@37 823
Chris@37 824 void
Chris@805 825 SpectrogramLayer::setMaxFrequency(int mf)
Chris@0 826 {
Chris@0 827 if (m_maxFrequency == mf) return;
Chris@0 828
Chris@587 829 // SVDEBUG << "SpectrogramLayer::setMaxFrequency: " << mf << endl;
Chris@187 830
Chris@1106 831 invalidateRenderers();
Chris@119 832 invalidateMagnitudes();
Chris@0 833
Chris@0 834 m_maxFrequency = mf;
Chris@0 835
Chris@9 836 emit layerParametersChanged();
Chris@0 837 }
Chris@0 838
Chris@805 839 int
Chris@0 840 SpectrogramLayer::getMaxFrequency() const
Chris@0 841 {
Chris@0 842 return m_maxFrequency;
Chris@0 843 }
Chris@0 844
Chris@0 845 void
Chris@9 846 SpectrogramLayer::setColourRotation(int r)
Chris@9 847 {
Chris@9 848 if (r < 0) r = 0;
Chris@9 849 if (r > 256) r = 256;
Chris@9 850 int distance = r - m_colourRotation;
Chris@9 851
Chris@9 852 if (distance != 0) {
Chris@1106 853 //!!! rotatePalette(-distance);
Chris@9 854 m_colourRotation = r;
Chris@9 855 }
Chris@9 856
Chris@1112 857 invalidateRenderers(); //!!! in theory we shouldn't have to do this... but...
Chris@1112 858
Chris@9 859 emit layerParametersChanged();
Chris@9 860 }
Chris@9 861
Chris@9 862 void
Chris@1105 863 SpectrogramLayer::setColourScale(ColourScaleType colourScale)
Chris@0 864 {
Chris@0 865 if (m_colourScale == colourScale) return;
Chris@0 866
Chris@1106 867 invalidateRenderers();
Chris@0 868
Chris@0 869 m_colourScale = colourScale;
Chris@0 870
Chris@9 871 emit layerParametersChanged();
Chris@0 872 }
Chris@0 873
Chris@1105 874 ColourScaleType
Chris@0 875 SpectrogramLayer::getColourScale() const
Chris@0 876 {
Chris@0 877 return m_colourScale;
Chris@0 878 }
Chris@0 879
Chris@0 880 void
Chris@197 881 SpectrogramLayer::setColourMap(int map)
Chris@0 882 {
Chris@197 883 if (m_colourMap == map) return;
Chris@0 884
Chris@1106 885 invalidateRenderers();
Chris@0 886
Chris@197 887 m_colourMap = map;
Chris@9 888
Chris@0 889 emit layerParametersChanged();
Chris@0 890 }
Chris@0 891
Chris@196 892 int
Chris@197 893 SpectrogramLayer::getColourMap() const
Chris@0 894 {
Chris@197 895 return m_colourMap;
Chris@0 896 }
Chris@0 897
Chris@0 898 void
Chris@1103 899 SpectrogramLayer::setBinScale(BinScale binScale)
Chris@0 900 {
Chris@1093 901 if (m_binScale == binScale) return;
Chris@0 902
Chris@1106 903 invalidateRenderers();
Chris@1093 904 m_binScale = binScale;
Chris@9 905
Chris@9 906 emit layerParametersChanged();
Chris@0 907 }
Chris@0 908
Chris@1103 909 BinScale
Chris@1093 910 SpectrogramLayer::getBinScale() const
Chris@0 911 {
Chris@1093 912 return m_binScale;
Chris@0 913 }
Chris@0 914
Chris@0 915 void
Chris@1103 916 SpectrogramLayer::setBinDisplay(BinDisplay binDisplay)
Chris@35 917 {
Chris@37 918 if (m_binDisplay == binDisplay) return;
Chris@35 919
Chris@1106 920 invalidateRenderers();
Chris@37 921 m_binDisplay = binDisplay;
Chris@35 922
Chris@35 923 emit layerParametersChanged();
Chris@35 924 }
Chris@35 925
Chris@1103 926 BinDisplay
Chris@37 927 SpectrogramLayer::getBinDisplay() const
Chris@35 928 {
Chris@37 929 return m_binDisplay;
Chris@35 930 }
Chris@35 931
Chris@35 932 void
Chris@1104 933 SpectrogramLayer::setNormalization(ColumnNormalization n)
Chris@36 934 {
Chris@862 935 if (m_normalization == n) return;
Chris@36 936
Chris@1106 937 invalidateRenderers();
Chris@119 938 invalidateMagnitudes();
Chris@862 939 m_normalization = n;
Chris@36 940
Chris@36 941 emit layerParametersChanged();
Chris@36 942 }
Chris@36 943
Chris@1104 944 ColumnNormalization
Chris@862 945 SpectrogramLayer::getNormalization() const
Chris@36 946 {
Chris@862 947 return m_normalization;
Chris@36 948 }
Chris@36 949
Chris@36 950 void
Chris@1104 951 SpectrogramLayer::setNormalizeVisibleArea(bool n)
Chris@1104 952 {
Chris@1104 953 if (m_normalizeVisibleArea == n) return;
Chris@1104 954
Chris@1106 955 invalidateRenderers();
Chris@1104 956 invalidateMagnitudes();
Chris@1104 957 m_normalizeVisibleArea = n;
Chris@1104 958
Chris@1104 959 emit layerParametersChanged();
Chris@1104 960 }
Chris@1104 961
Chris@1104 962 bool
Chris@1104 963 SpectrogramLayer::getNormalizeVisibleArea() const
Chris@1104 964 {
Chris@1104 965 return m_normalizeVisibleArea;
Chris@1104 966 }
Chris@1104 967
Chris@1104 968 void
Chris@918 969 SpectrogramLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
Chris@29 970 {
Chris@33 971 if (dormant) {
Chris@33 972
Chris@331 973 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@985 974 cerr << "SpectrogramLayer::setLayerDormant(" << dormant << ")"
Chris@585 975 << endl;
Chris@331 976 #endif
Chris@331 977
Chris@131 978 if (isLayerDormant(v)) {
Chris@131 979 return;
Chris@131 980 }
Chris@131 981
Chris@131 982 Layer::setLayerDormant(v, true);
Chris@33 983
Chris@1106 984 invalidateRenderers();
Chris@1030 985
Chris@1088 986 //!!! in theory we should call invalidateFFTModel() if and
Chris@1088 987 //!!! only if there are no remaining views in which we are not
Chris@1088 988 //!!! dormant
Chris@33 989
Chris@33 990 } else {
Chris@33 991
Chris@131 992 Layer::setLayerDormant(v, false);
Chris@33 993 }
Chris@29 994 }
Chris@29 995
Chris@29 996 void
Chris@0 997 SpectrogramLayer::cacheInvalid()
Chris@0 998 {
Chris@391 999 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@985 1000 cerr << "SpectrogramLayer::cacheInvalid()" << endl;
Chris@391 1001 #endif
Chris@391 1002
Chris@1106 1003 invalidateRenderers();
Chris@119 1004 invalidateMagnitudes();
Chris@0 1005 }
Chris@0 1006
Chris@0 1007 void
Chris@1037 1008 SpectrogramLayer::cacheInvalid(
Chris@1037 1009 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@1037 1010 sv_frame_t from, sv_frame_t to
Chris@1037 1011 #else
Chris@1037 1012 sv_frame_t , sv_frame_t
Chris@1037 1013 #endif
Chris@1037 1014 )
Chris@0 1015 {
Chris@391 1016 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@985 1017 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl;
Chris@391 1018 #endif
Chris@391 1019
Chris@1030 1020 // We used to call invalidateMagnitudes(from, to) to invalidate
Chris@1030 1021 // only those caches whose views contained some of the (from, to)
Chris@1030 1022 // range. That's the right thing to do; it has been lost in
Chris@1030 1023 // pulling out the image cache code, but it might not matter very
Chris@1030 1024 // much, since the underlying models for spectrogram layers don't
Chris@1030 1025 // change very often. Let's see.
Chris@1106 1026 invalidateRenderers();
Chris@391 1027 invalidateMagnitudes();
Chris@0 1028 }
Chris@0 1029
Chris@224 1030 bool
Chris@224 1031 SpectrogramLayer::hasLightBackground() const
Chris@224 1032 {
Chris@287 1033 return ColourMapper(m_colourMap, 1.f, 255.f).hasLightBackground();
Chris@224 1034 }
Chris@224 1035
Chris@905 1036 double
Chris@40 1037 SpectrogramLayer::getEffectiveMinFrequency() const
Chris@40 1038 {
Chris@907 1039 sv_samplerate_t sr = m_model->getSampleRate();
Chris@1087 1040 double minf = double(sr) / getFFTSize();
Chris@40 1041
Chris@40 1042 if (m_minFrequency > 0.0) {
Chris@1087 1043 int minbin = int((double(m_minFrequency) * getFFTSize()) / sr + 0.01);
Chris@40 1044 if (minbin < 1) minbin = 1;
Chris@1087 1045 minf = minbin * sr / getFFTSize();
Chris@40 1046 }
Chris@40 1047
Chris@40 1048 return minf;
Chris@40 1049 }
Chris@40 1050
Chris@905 1051 double
Chris@40 1052 SpectrogramLayer::getEffectiveMaxFrequency() const
Chris@40 1053 {
Chris@907 1054 sv_samplerate_t sr = m_model->getSampleRate();
Chris@905 1055 double maxf = double(sr) / 2;
Chris@40 1056
Chris@40 1057 if (m_maxFrequency > 0.0) {
Chris@1087 1058 int maxbin = int((double(m_maxFrequency) * getFFTSize()) / sr + 0.1);
Chris@1087 1059 if (maxbin > getFFTSize() / 2) maxbin = getFFTSize() / 2;
Chris@1087 1060 maxf = maxbin * sr / getFFTSize();
Chris@40 1061 }
Chris@40 1062
Chris@40 1063 return maxf;
Chris@40 1064 }
Chris@40 1065
Chris@0 1066 bool
Chris@918 1067 SpectrogramLayer::getYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const
Chris@0 1068 {
Chris@382 1069 Profiler profiler("SpectrogramLayer::getYBinRange");
Chris@382 1070
Chris@918 1071 int h = v->getPaintHeight();
Chris@0 1072 if (y < 0 || y >= h) return false;
Chris@0 1073
Chris@907 1074 sv_samplerate_t sr = m_model->getSampleRate();
Chris@905 1075 double minf = getEffectiveMinFrequency();
Chris@905 1076 double maxf = getEffectiveMaxFrequency();
Chris@0 1077
Chris@1103 1078 bool logarithmic = (m_binScale == BinScale::Log);
Chris@38 1079
Chris@44 1080 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic);
Chris@44 1081 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic);
Chris@38 1082
Chris@1086 1083 // Now map these on to ("proportions of") actual bins
Chris@490 1084
Chris@1087 1085 q0 = (q0 * getFFTSize()) / sr;
Chris@1087 1086 q1 = (q1 * getFFTSize()) / sr;
Chris@0 1087
Chris@0 1088 return true;
Chris@0 1089 }
Chris@486 1090
Chris@1085 1091 double
Chris@1090 1092 SpectrogramLayer::getYForBin(LayerGeometryProvider *, double) const {
Chris@1085 1093 //!!! not implemented
Chris@1085 1094 throw std::logic_error("not implemented");
Chris@1085 1095 }
Chris@1085 1096
Chris@1085 1097 double
Chris@1085 1098 SpectrogramLayer::getBinForY(LayerGeometryProvider *v, double y) const
Chris@1085 1099 {
Chris@1085 1100 //!!! overlap with range methods above (but using double arg)
Chris@1085 1101 //!!! tidy this
Chris@38 1102
Chris@1085 1103 int h = v->getPaintHeight();
Chris@1085 1104 if (y < 0 || y >= h) return false;
Chris@1085 1105
Chris@1085 1106 sv_samplerate_t sr = m_model->getSampleRate();
Chris@1085 1107 double minf = getEffectiveMinFrequency();
Chris@1085 1108 double maxf = getEffectiveMaxFrequency();
Chris@1085 1109
Chris@1103 1110 bool logarithmic = (m_binScale == BinScale::Log);
Chris@1085 1111
Chris@1085 1112 double q = v->getFrequencyForY(y, minf, maxf, logarithmic);
Chris@1085 1113
Chris@1086 1114 // Now map on to ("proportions of") actual bins
Chris@1085 1115
Chris@1087 1116 q = (q * getFFTSize()) / sr;
Chris@1085 1117
Chris@1085 1118 return q;
Chris@1085 1119 }
Chris@1085 1120
Chris@0 1121 bool
Chris@918 1122 SpectrogramLayer::getXBinRange(LayerGeometryProvider *v, int x, double &s0, double &s1) const
Chris@0 1123 {
Chris@907 1124 sv_frame_t modelStart = m_model->getStartFrame();
Chris@907 1125 sv_frame_t modelEnd = m_model->getEndFrame();
Chris@0 1126
Chris@0 1127 // Each pixel column covers an exact range of sample frames:
Chris@907 1128 sv_frame_t f0 = v->getFrameForX(x) - modelStart;
Chris@907 1129 sv_frame_t f1 = v->getFrameForX(x + 1) - modelStart - 1;
Chris@20 1130
Chris@41 1131 if (f1 < int(modelStart) || f0 > int(modelEnd)) {
Chris@41 1132 return false;
Chris@41 1133 }
Chris@20 1134
Chris@0 1135 // And that range may be drawn from a possibly non-integral
Chris@0 1136 // range of spectrogram windows:
Chris@0 1137
Chris@805 1138 int windowIncrement = getWindowIncrement();
Chris@905 1139 s0 = double(f0) / windowIncrement;
Chris@905 1140 s1 = double(f1) / windowIncrement;
Chris@0 1141
Chris@0 1142 return true;
Chris@0 1143 }
Chris@0 1144
Chris@0 1145 bool
Chris@918 1146 SpectrogramLayer::getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &min, RealTime &max) const
Chris@0 1147 {
Chris@905 1148 double s0 = 0, s1 = 0;
Chris@44 1149 if (!getXBinRange(v, x, s0, s1)) return false;
Chris@0 1150
Chris@0 1151 int s0i = int(s0 + 0.001);
Chris@0 1152 int s1i = int(s1);
Chris@0 1153
Chris@0 1154 int windowIncrement = getWindowIncrement();
Chris@0 1155 int w0 = s0i * windowIncrement - (m_windowSize - windowIncrement)/2;
Chris@0 1156 int w1 = s1i * windowIncrement + windowIncrement +
Chris@0 1157 (m_windowSize - windowIncrement)/2 - 1;
Chris@0 1158
Chris@0 1159 min = RealTime::frame2RealTime(w0, m_model->getSampleRate());
Chris@0 1160 max = RealTime::frame2RealTime(w1, m_model->getSampleRate());
Chris@0 1161 return true;
Chris@0 1162 }
Chris@0 1163
Chris@0 1164 bool
Chris@918 1165 SpectrogramLayer::getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax)
Chris@0 1166 const
Chris@0 1167 {
Chris@905 1168 double q0 = 0, q1 = 0;
Chris@44 1169 if (!getYBinRange(v, y, q0, q1)) return false;
Chris@0 1170
Chris@0 1171 int q0i = int(q0 + 0.001);
Chris@0 1172 int q1i = int(q1);
Chris@0 1173
Chris@907 1174 sv_samplerate_t sr = m_model->getSampleRate();
Chris@0 1175
Chris@0 1176 for (int q = q0i; q <= q1i; ++q) {
Chris@1087 1177 if (q == q0i) freqMin = (sr * q) / getFFTSize();
Chris@1087 1178 if (q == q1i) freqMax = (sr * (q+1)) / getFFTSize();
Chris@0 1179 }
Chris@0 1180 return true;
Chris@0 1181 }
Chris@35 1182
Chris@35 1183 bool
Chris@918 1184 SpectrogramLayer::getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y,
Chris@905 1185 double &freqMin, double &freqMax,
Chris@905 1186 double &adjFreqMin, double &adjFreqMax)
Chris@35 1187 const
Chris@35 1188 {
Chris@277 1189 if (!m_model || !m_model->isOK() || !m_model->isReady()) {
Chris@277 1190 return false;
Chris@277 1191 }
Chris@277 1192
Chris@1088 1193 FFTModel *fft = getFFTModel();
Chris@114 1194 if (!fft) return false;
Chris@110 1195
Chris@905 1196 double s0 = 0, s1 = 0;
Chris@44 1197 if (!getXBinRange(v, x, s0, s1)) return false;
Chris@35 1198
Chris@905 1199 double q0 = 0, q1 = 0;
Chris@44 1200 if (!getYBinRange(v, y, q0, q1)) return false;
Chris@35 1201
Chris@35 1202 int s0i = int(s0 + 0.001);
Chris@35 1203 int s1i = int(s1);
Chris@35 1204
Chris@35 1205 int q0i = int(q0 + 0.001);
Chris@35 1206 int q1i = int(q1);
Chris@35 1207
Chris@907 1208 sv_samplerate_t sr = m_model->getSampleRate();
Chris@35 1209
Chris@35 1210 bool haveAdj = false;
Chris@35 1211
Chris@1103 1212 bool peaksOnly = (m_binDisplay == BinDisplay::PeakBins ||
Chris@1103 1213 m_binDisplay == BinDisplay::PeakFrequencies);
Chris@37 1214
Chris@35 1215 for (int q = q0i; q <= q1i; ++q) {
Chris@35 1216
Chris@35 1217 for (int s = s0i; s <= s1i; ++s) {
Chris@35 1218
Chris@905 1219 double binfreq = (double(sr) * q) / m_windowSize;
Chris@35 1220 if (q == q0i) freqMin = binfreq;
Chris@35 1221 if (q == q1i) freqMax = binfreq;
Chris@37 1222
Chris@114 1223 if (peaksOnly && !fft->isLocalPeak(s, q)) continue;
Chris@38 1224
Chris@1086 1225 if (!fft->isOverThreshold
Chris@1087 1226 (s, q, float(m_threshold * double(getFFTSize())/2.0))) {
Chris@1086 1227 continue;
Chris@1086 1228 }
Chris@907 1229
Chris@907 1230 double freq = binfreq;
Chris@40 1231
Chris@114 1232 if (s < int(fft->getWidth()) - 1) {
Chris@38 1233
Chris@277 1234 fft->estimateStableFrequency(s, q, freq);
Chris@35 1235
Chris@38 1236 if (!haveAdj || freq < adjFreqMin) adjFreqMin = freq;
Chris@38 1237 if (!haveAdj || freq > adjFreqMax) adjFreqMax = freq;
Chris@35 1238
Chris@35 1239 haveAdj = true;
Chris@35 1240 }
Chris@35 1241 }
Chris@35 1242 }
Chris@35 1243
Chris@35 1244 if (!haveAdj) {
Chris@40 1245 adjFreqMin = adjFreqMax = 0.0;
Chris@35 1246 }
Chris@35 1247
Chris@35 1248 return haveAdj;
Chris@35 1249 }
Chris@0 1250
Chris@0 1251 bool
Chris@918 1252 SpectrogramLayer::getXYBinSourceRange(LayerGeometryProvider *v, int x, int y,
Chris@905 1253 double &min, double &max,
Chris@905 1254 double &phaseMin, double &phaseMax) const
Chris@0 1255 {
Chris@277 1256 if (!m_model || !m_model->isOK() || !m_model->isReady()) {
Chris@277 1257 return false;
Chris@277 1258 }
Chris@277 1259
Chris@905 1260 double q0 = 0, q1 = 0;
Chris@44 1261 if (!getYBinRange(v, y, q0, q1)) return false;
Chris@0 1262
Chris@905 1263 double s0 = 0, s1 = 0;
Chris@44 1264 if (!getXBinRange(v, x, s0, s1)) return false;
Chris@0 1265
Chris@0 1266 int q0i = int(q0 + 0.001);
Chris@0 1267 int q1i = int(q1);
Chris@0 1268
Chris@0 1269 int s0i = int(s0 + 0.001);
Chris@0 1270 int s1i = int(s1);
Chris@0 1271
Chris@37 1272 bool rv = false;
Chris@37 1273
Chris@1088 1274 FFTModel *fft = getFFTModel();
Chris@0 1275
Chris@114 1276 if (fft) {
Chris@114 1277
Chris@114 1278 int cw = fft->getWidth();
Chris@114 1279 int ch = fft->getHeight();
Chris@0 1280
Chris@110 1281 min = 0.0;
Chris@110 1282 max = 0.0;
Chris@110 1283 phaseMin = 0.0;
Chris@110 1284 phaseMax = 0.0;
Chris@110 1285 bool have = false;
Chris@0 1286
Chris@110 1287 for (int q = q0i; q <= q1i; ++q) {
Chris@110 1288 for (int s = s0i; s <= s1i; ++s) {
Chris@110 1289 if (s >= 0 && q >= 0 && s < cw && q < ch) {
Chris@117 1290
Chris@905 1291 double value;
Chris@38 1292
Chris@114 1293 value = fft->getPhaseAt(s, q);
Chris@110 1294 if (!have || value < phaseMin) { phaseMin = value; }
Chris@110 1295 if (!have || value > phaseMax) { phaseMax = value; }
Chris@91 1296
Chris@1087 1297 value = fft->getMagnitudeAt(s, q) / (getFFTSize()/2.0);
Chris@110 1298 if (!have || value < min) { min = value; }
Chris@110 1299 if (!have || value > max) { max = value; }
Chris@110 1300
Chris@110 1301 have = true;
Chris@110 1302 }
Chris@110 1303 }
Chris@110 1304 }
Chris@110 1305
Chris@110 1306 if (have) {
Chris@110 1307 rv = true;
Chris@110 1308 }
Chris@0 1309 }
Chris@0 1310
Chris@37 1311 return rv;
Chris@0 1312 }
Chris@114 1313
Chris@130 1314 FFTModel *
Chris@1088 1315 SpectrogramLayer::getFFTModel() const
Chris@114 1316 {
Chris@114 1317 if (!m_model) return 0;
Chris@114 1318
Chris@1087 1319 int fftSize = getFFTSize();
Chris@114 1320
Chris@1088 1321 //!!! it is now surely slower to do this on every getFFTModel()
Chris@1088 1322 //!!! request than it would be to recreate the model immediately
Chris@1088 1323 //!!! when something changes instead of just invalidating it
Chris@920 1324
Chris@1088 1325 if (m_fftModel &&
Chris@1088 1326 m_fftModel->getHeight() == fftSize / 2 + 1 &&
Chris@1088 1327 m_fftModel->getWindowIncrement() == getWindowIncrement()) {
Chris@1088 1328 return m_fftModel;
Chris@114 1329 }
Chris@1088 1330
Chris@1088 1331 delete m_peakCache;
Chris@1088 1332 m_peakCache = 0;
Chris@1088 1333
Chris@1088 1334 delete m_fftModel;
Chris@1088 1335 m_fftModel = new FFTModel(m_model,
Chris@1088 1336 m_channel,
Chris@1088 1337 m_windowType,
Chris@1088 1338 m_windowSize,
Chris@1088 1339 getWindowIncrement(),
Chris@1088 1340 fftSize);
Chris@1088 1341
Chris@1088 1342 if (!m_fftModel->isOK()) {
Chris@1088 1343 QMessageBox::critical
Chris@1088 1344 (0, tr("FFT cache failed"),
Chris@1088 1345 tr("Failed to create the FFT model for this spectrogram.\n"
Chris@1088 1346 "There may be insufficient memory or disc space to continue."));
Chris@1088 1347 delete m_fftModel;
Chris@1088 1348 m_fftModel = 0;
Chris@1088 1349 return 0;
Chris@114 1350 }
Chris@114 1351
Chris@1088 1352 ((SpectrogramLayer *)this)->sliceableModelReplaced(0, m_fftModel);
Chris@1088 1353
Chris@1088 1354 return m_fftModel;
Chris@114 1355 }
Chris@114 1356
Chris@484 1357 Dense3DModelPeakCache *
Chris@1088 1358 SpectrogramLayer::getPeakCache() const
Chris@484 1359 {
Chris@1088 1360 //!!! see comment in getFFTModel
Chris@1088 1361
Chris@1088 1362 if (!m_peakCache) {
Chris@1088 1363 FFTModel *f = getFFTModel();
Chris@484 1364 if (!f) return 0;
Chris@1088 1365 m_peakCache = new Dense3DModelPeakCache(f, m_peakCacheDivisor);
Chris@484 1366 }
Chris@1088 1367 return m_peakCache;
Chris@484 1368 }
Chris@484 1369
Chris@193 1370 const Model *
Chris@193 1371 SpectrogramLayer::getSliceableModel() const
Chris@193 1372 {
Chris@1088 1373 return m_fftModel;
Chris@193 1374 }
Chris@193 1375
Chris@114 1376 void
Chris@1088 1377 SpectrogramLayer::invalidateFFTModel()
Chris@114 1378 {
Chris@1044 1379 #ifdef DEBUG_SPECTROGRAM
Chris@1088 1380 cerr << "SpectrogramLayer::invalidateFFTModel called" << endl;
Chris@1044 1381 #endif
Chris@1088 1382
Chris@1088 1383 emit sliceableModelReplaced(m_fftModel, 0);
Chris@1088 1384
Chris@1088 1385 delete m_fftModel;
Chris@1088 1386 delete m_peakCache;
Chris@1088 1387
Chris@1088 1388 m_fftModel = 0;
Chris@1088 1389 m_peakCache = 0;
Chris@114 1390 }
Chris@114 1391
Chris@0 1392 void
Chris@119 1393 SpectrogramLayer::invalidateMagnitudes()
Chris@119 1394 {
Chris@1044 1395 #ifdef DEBUG_SPECTROGRAM
Chris@1044 1396 cerr << "SpectrogramLayer::invalidateMagnitudes called" << endl;
Chris@1044 1397 #endif
Chris@119 1398 m_viewMags.clear();
Chris@1025 1399 for (vector<MagnitudeRange>::iterator i = m_columnMags.begin();
Chris@119 1400 i != m_columnMags.end(); ++i) {
Chris@119 1401 *i = MagnitudeRange();
Chris@119 1402 }
Chris@119 1403 }
Chris@119 1404
Chris@119 1405 bool
Chris@918 1406 SpectrogramLayer::updateViewMagnitudes(LayerGeometryProvider *v) const
Chris@119 1407 {
Chris@119 1408 MagnitudeRange mag;
Chris@119 1409
Chris@918 1410 int x0 = 0, x1 = v->getPaintWidth();
Chris@905 1411 double s00 = 0, s01 = 0, s10 = 0, s11 = 0;
Chris@119 1412
Chris@203 1413 if (!getXBinRange(v, x0, s00, s01)) {
Chris@907 1414 s00 = s01 = double(m_model->getStartFrame()) / getWindowIncrement();
Chris@203 1415 }
Chris@203 1416
Chris@203 1417 if (!getXBinRange(v, x1, s10, s11)) {
Chris@907 1418 s10 = s11 = double(m_model->getEndFrame()) / getWindowIncrement();
Chris@203 1419 }
Chris@119 1420
Chris@1025 1421 int s0 = int(min(s00, s10) + 0.0001);
Chris@1025 1422 int s1 = int(max(s01, s11) + 0.0001);
Chris@203 1423
Chris@587 1424 // SVDEBUG << "SpectrogramLayer::updateViewMagnitudes: x0 = " << x0 << ", x1 = " << x1 << ", s00 = " << s00 << ", s11 = " << s11 << " s0 = " << s0 << ", s1 = " << s1 << endl;
Chris@119 1425
Chris@248 1426 if (int(m_columnMags.size()) <= s1) {
Chris@119 1427 m_columnMags.resize(s1 + 1);
Chris@119 1428 }
Chris@119 1429
Chris@119 1430 for (int s = s0; s <= s1; ++s) {
Chris@119 1431 if (m_columnMags[s].isSet()) {
Chris@119 1432 mag.sample(m_columnMags[s]);
Chris@119 1433 }
Chris@119 1434 }
Chris@119 1435
Chris@184 1436 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@985 1437 cerr << "SpectrogramLayer::updateViewMagnitudes returning from cols "
Chris@1044 1438 << s0 << " -> " << s1 << " inclusive" << endl;
Chris@1044 1439 cerr << "SpectrogramLayer::updateViewMagnitudes: for view id " << v->getId()
Chris@1044 1440 << ": min is " << mag.getMin() << ", max is " << mag.getMax() << endl;
Chris@184 1441 #endif
Chris@119 1442
Chris@119 1443 if (!mag.isSet()) return false;
Chris@1030 1444 if (mag == m_viewMags[v->getId()]) return false;
Chris@1030 1445 m_viewMags[v->getId()] = mag;
Chris@119 1446 return true;
Chris@119 1447 }
Chris@119 1448
Chris@119 1449 void
Chris@389 1450 SpectrogramLayer::setSynchronousPainting(bool synchronous)
Chris@389 1451 {
Chris@389 1452 m_synchronous = synchronous;
Chris@389 1453 }
Chris@389 1454
Chris@1089 1455 Colour3DPlotRenderer *
Chris@1089 1456 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const
Chris@1089 1457 {
Chris@1089 1458 if (m_renderers.find(v->getId()) == m_renderers.end()) {
Chris@1089 1459
Chris@1089 1460 Colour3DPlotRenderer::Sources sources;
Chris@1089 1461 sources.verticalBinLayer = this;
Chris@1090 1462 sources.fft = getFFTModel();
Chris@1090 1463 sources.source = sources.fft;
Chris@1090 1464 sources.peaks = getPeakCache();
Chris@1089 1465
Chris@1092 1466 ColourScale::Parameters cparams;
Chris@1092 1467 cparams.colourMap = m_colourMap;
Chris@1092 1468 cparams.scale = m_colourScale;
Chris@1093 1469 cparams.threshold = m_threshold;
Chris@1093 1470 cparams.gain = m_gain;
Chris@1093 1471
Chris@1105 1472 if (m_colourScale != ColourScaleType::Phase &&
Chris@1104 1473 m_normalization == ColumnNormalization::None) {
Chris@1093 1474 cparams.gain *= 2.f / float(getFFTSize());
Chris@1093 1475 }
Chris@1089 1476
Chris@1089 1477 Colour3DPlotRenderer::Parameters params;
Chris@1092 1478 params.colourScale = ColourScale(cparams);
Chris@1089 1479 params.normalization = m_normalization;
Chris@1093 1480 params.binDisplay = m_binDisplay;
Chris@1093 1481 params.binScale = m_binScale;
Chris@1093 1482 params.alwaysOpaque = true;
Chris@1093 1483 params.invertVertical = false;
Chris@1112 1484 params.colourRotation = m_colourRotation;
Chris@1093 1485
Chris@1093 1486 Preferences::SpectrogramSmoothing smoothing =
Chris@1093 1487 Preferences::getInstance()->getSpectrogramSmoothing();
Chris@1093 1488 params.interpolate =
Chris@1093 1489 (smoothing == Preferences::SpectrogramInterpolated ||
Chris@1093 1490 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated);
Chris@1089 1491
Chris@1089 1492 m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params);
Chris@1089 1493 }
Chris@1089 1494
Chris@1089 1495 return m_renderers[v->getId()];
Chris@1089 1496 }
Chris@1089 1497
Chris@1089 1498 void
Chris@1106 1499 SpectrogramLayer::paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
Chris@1106 1500 {
Chris@1106 1501 static int depth = 0;
Chris@1106 1502
Chris@1106 1503 Colour3DPlotRenderer *renderer = getRenderer(v);
Chris@1106 1504
Chris@1106 1505 if (m_synchronous) {
Chris@1106 1506 (void)renderer->render(v, paint, rect);
Chris@1106 1507 return;
Chris@1106 1508 }
Chris@1106 1509
Chris@1106 1510 ++depth;
Chris@1106 1511 cerr << "paint depth " << depth << endl;
Chris@1106 1512
Chris@1106 1513 (void)renderer->renderTimeConstrained(v, paint, rect);
Chris@1106 1514
Chris@1106 1515 //!!! + mag range
Chris@1106 1516
Chris@1106 1517 QRect uncached = renderer->getLargestUncachedRect();
Chris@1106 1518 if (uncached.width() > 0) {
Chris@1106 1519 cerr << "updating rect at " << uncached.x() << " width "
Chris@1106 1520 << uncached.width() << endl;
Chris@1106 1521 v->updatePaintRect(uncached);
Chris@1106 1522 }
Chris@1106 1523
Chris@1106 1524 cerr << "exiting paint depth " << depth << endl;
Chris@1106 1525 --depth;
Chris@1106 1526 }
Chris@1106 1527
Chris@1106 1528 void
Chris@916 1529 SpectrogramLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
Chris@0 1530 {
Chris@334 1531 Profiler profiler("SpectrogramLayer::paint", false);
Chris@334 1532
Chris@0 1533 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@1026 1534 cerr << "SpectrogramLayer::paint() entering: m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << endl;
Chris@95 1535
Chris@1026 1536 cerr << "SpectrogramLayer::paint(): rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
Chris@0 1537 #endif
Chris@95 1538
Chris@0 1539 if (!m_model || !m_model->isOK() || !m_model->isReady()) {
Chris@0 1540 return;
Chris@0 1541 }
Chris@0 1542
Chris@47 1543 if (isLayerDormant(v)) {
Chris@587 1544 SVDEBUG << "SpectrogramLayer::paint(): Layer is dormant, making it undormant again" << endl;
Chris@29 1545 }
Chris@29 1546
Chris@1106 1547 paintWithRenderer(v, paint, rect);
Chris@480 1548 }
Chris@477 1549
Chris@121 1550 void
Chris@918 1551 SpectrogramLayer::illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &paint) const
Chris@121 1552 {
Chris@382 1553 Profiler profiler("SpectrogramLayer::illuminateLocalFeatures");
Chris@382 1554
Chris@121 1555 QPoint localPos;
Chris@121 1556 if (!v->shouldIlluminateLocalFeatures(this, localPos) || !m_model) {
Chris@121 1557 return;
Chris@121 1558 }
Chris@121 1559
Chris@682 1560 // cerr << "SpectrogramLayer: illuminateLocalFeatures("
Chris@682 1561 // << localPos.x() << "," << localPos.y() << ")" << endl;
Chris@121 1562
Chris@905 1563 double s0, s1;
Chris@905 1564 double f0, f1;
Chris@121 1565
Chris@121 1566 if (getXBinRange(v, localPos.x(), s0, s1) &&
Chris@121 1567 getYBinSourceRange(v, localPos.y(), f0, f1)) {
Chris@121 1568
Chris@121 1569 int s0i = int(s0 + 0.001);
Chris@121 1570 int s1i = int(s1);
Chris@121 1571
Chris@121 1572 int x0 = v->getXForFrame(s0i * getWindowIncrement());
Chris@121 1573 int x1 = v->getXForFrame((s1i + 1) * getWindowIncrement());
Chris@121 1574
Chris@248 1575 int y1 = int(getYForFrequency(v, f1));
Chris@248 1576 int y0 = int(getYForFrequency(v, f0));
Chris@121 1577
Chris@682 1578 // cerr << "SpectrogramLayer: illuminate "
Chris@682 1579 // << x0 << "," << y1 << " -> " << x1 << "," << y0 << endl;
Chris@121 1580
Chris@287 1581 paint.setPen(v->getForeground());
Chris@133 1582
Chris@133 1583 //!!! should we be using paintCrosshairs for this?
Chris@133 1584
Chris@121 1585 paint.drawRect(x0, y1, x1 - x0 + 1, y0 - y1 + 1);
Chris@121 1586 }
Chris@121 1587 }
Chris@121 1588
Chris@905 1589 double
Chris@918 1590 SpectrogramLayer::getYForFrequency(const LayerGeometryProvider *v, double frequency) const
Chris@42 1591 {
Chris@44 1592 return v->getYForFrequency(frequency,
Chris@44 1593 getEffectiveMinFrequency(),
Chris@44 1594 getEffectiveMaxFrequency(),
Chris@1103 1595 m_binScale == BinScale::Log);
Chris@42 1596 }
Chris@42 1597
Chris@905 1598 double
Chris@918 1599 SpectrogramLayer::getFrequencyForY(const LayerGeometryProvider *v, int y) const
Chris@42 1600 {
Chris@44 1601 return v->getFrequencyForY(y,
Chris@44 1602 getEffectiveMinFrequency(),
Chris@44 1603 getEffectiveMaxFrequency(),
Chris@1103 1604 m_binScale == BinScale::Log);
Chris@42 1605 }
Chris@42 1606
Chris@0 1607 int
Chris@1090 1608 SpectrogramLayer::getCompletion(LayerGeometryProvider *) const
Chris@0 1609 {
Chris@1088 1610 if (!m_fftModel) return 100;
Chris@1088 1611 int completion = m_fftModel->getCompletion();
Chris@224 1612 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@985 1613 cerr << "SpectrogramLayer::getCompletion: completion = " << completion << endl;
Chris@224 1614 #endif
Chris@0 1615 return completion;
Chris@0 1616 }
Chris@0 1617
Chris@583 1618 QString
Chris@1090 1619 SpectrogramLayer::getError(LayerGeometryProvider *) const
Chris@583 1620 {
Chris@1088 1621 if (!m_fftModel) return "";
Chris@1088 1622 return m_fftModel->getError();
Chris@583 1623 }
Chris@583 1624
Chris@28 1625 bool
Chris@905 1626 SpectrogramLayer::getValueExtents(double &min, double &max,
Chris@101 1627 bool &logarithmic, QString &unit) const
Chris@79 1628 {
Chris@133 1629 if (!m_model) return false;
Chris@133 1630
Chris@907 1631 sv_samplerate_t sr = m_model->getSampleRate();
Chris@1087 1632 min = double(sr) / getFFTSize();
Chris@905 1633 max = double(sr) / 2;
Chris@133 1634
Chris@1103 1635 logarithmic = (m_binScale == BinScale::Log);
Chris@79 1636 unit = "Hz";
Chris@79 1637 return true;
Chris@79 1638 }
Chris@79 1639
Chris@79 1640 bool
Chris@905 1641 SpectrogramLayer::getDisplayExtents(double &min, double &max) const
Chris@101 1642 {
Chris@101 1643 min = getEffectiveMinFrequency();
Chris@101 1644 max = getEffectiveMaxFrequency();
Chris@253 1645
Chris@587 1646 // SVDEBUG << "SpectrogramLayer::getDisplayExtents: " << min << "->" << max << endl;
Chris@101 1647 return true;
Chris@101 1648 }
Chris@101 1649
Chris@101 1650 bool
Chris@905 1651 SpectrogramLayer::setDisplayExtents(double min, double max)
Chris@120 1652 {
Chris@120 1653 if (!m_model) return false;
Chris@187 1654
Chris@587 1655 // SVDEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl;
Chris@187 1656
Chris@120 1657 if (min < 0) min = 0;
Chris@907 1658 if (max > m_model->getSampleRate()/2.0) max = m_model->getSampleRate()/2.0;
Chris@120 1659
Chris@907 1660 int minf = int(lrint(min));
Chris@907 1661 int maxf = int(lrint(max));
Chris@120 1662
Chris@120 1663 if (m_minFrequency == minf && m_maxFrequency == maxf) return true;
Chris@120 1664
Chris@1106 1665 invalidateRenderers();
Chris@120 1666 invalidateMagnitudes();
Chris@120 1667
Chris@120 1668 m_minFrequency = minf;
Chris@120 1669 m_maxFrequency = maxf;
Chris@120 1670
Chris@120 1671 emit layerParametersChanged();
Chris@120 1672
Chris@133 1673 int vs = getCurrentVerticalZoomStep();
Chris@133 1674 if (vs != m_lastEmittedZoomStep) {
Chris@133 1675 emit verticalZoomChanged();
Chris@133 1676 m_lastEmittedZoomStep = vs;
Chris@133 1677 }
Chris@133 1678
Chris@120 1679 return true;
Chris@120 1680 }
Chris@120 1681
Chris@120 1682 bool
Chris@918 1683 SpectrogramLayer::getYScaleValue(const LayerGeometryProvider *v, int y,
Chris@905 1684 double &value, QString &unit) const
Chris@261 1685 {
Chris@261 1686 value = getFrequencyForY(v, y);
Chris@261 1687 unit = "Hz";
Chris@261 1688 return true;
Chris@261 1689 }
Chris@261 1690
Chris@261 1691 bool
Chris@918 1692 SpectrogramLayer::snapToFeatureFrame(LayerGeometryProvider *,
Chris@907 1693 sv_frame_t &frame,
Chris@805 1694 int &resolution,
Chris@28 1695 SnapType snap) const
Chris@13 1696 {
Chris@13 1697 resolution = getWindowIncrement();
Chris@907 1698 sv_frame_t left = (frame / resolution) * resolution;
Chris@907 1699 sv_frame_t right = left + resolution;
Chris@28 1700
Chris@28 1701 switch (snap) {
Chris@28 1702 case SnapLeft: frame = left; break;
Chris@28 1703 case SnapRight: frame = right; break;
Chris@28 1704 case SnapNearest:
Chris@28 1705 case SnapNeighbouring:
Chris@28 1706 if (frame - left > right - frame) frame = right;
Chris@28 1707 else frame = left;
Chris@28 1708 break;
Chris@28 1709 }
Chris@28 1710
Chris@28 1711 return true;
Chris@28 1712 }
Chris@13 1713
Chris@283 1714 void
Chris@1106 1715 SpectrogramLayer::measureDoubleClick(LayerGeometryProvider *, QMouseEvent *)
Chris@283 1716 {
Chris@1106 1717 /*!!! replace this
Chris@920 1718 const View *view = v->getView();
Chris@1106 1719
Chris@1030 1720 ScrollableImageCache &cache = getImageCacheReference(view);
Chris@1030 1721
Chris@1030 1722 cerr << "cache width: " << cache.getSize().width() << ", height: "
Chris@1030 1723 << cache.getSize().height() << endl;
Chris@1030 1724
Chris@1030 1725 QImage image = cache.getImage();
Chris@283 1726
Chris@283 1727 ImageRegionFinder finder;
Chris@283 1728 QRect rect = finder.findRegionExtents(&image, e->pos());
Chris@283 1729 if (rect.isValid()) {
Chris@283 1730 MeasureRect mr;
Chris@283 1731 setMeasureRectFromPixrect(v, mr, rect);
Chris@283 1732 CommandHistory::getInstance()->addCommand
Chris@283 1733 (new AddMeasurementRectCommand(this, mr));
Chris@283 1734 }
Chris@1106 1735 */
Chris@283 1736 }
Chris@283 1737
Chris@77 1738 bool
Chris@918 1739 SpectrogramLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint,
Chris@77 1740 QPoint cursorPos,
Chris@1025 1741 vector<QRect> &extents) const
Chris@77 1742 {
Chris@918 1743 QRect vertical(cursorPos.x() - 12, 0, 12, v->getPaintHeight());
Chris@77 1744 extents.push_back(vertical);
Chris@77 1745
Chris@77 1746 QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1);
Chris@77 1747 extents.push_back(horizontal);
Chris@77 1748
Chris@608 1749 int sw = getVerticalScaleWidth(v, m_haveDetailedScale, paint);
Chris@264 1750
Chris@280 1751 QRect freq(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2,
Chris@280 1752 paint.fontMetrics().width("123456 Hz") + 2,
Chris@280 1753 paint.fontMetrics().height());
Chris@280 1754 extents.push_back(freq);
Chris@264 1755
Chris@279 1756 QRect pitch(sw, cursorPos.y() + 2,
Chris@279 1757 paint.fontMetrics().width("C#10+50c") + 2,
Chris@279 1758 paint.fontMetrics().height());
Chris@279 1759 extents.push_back(pitch);
Chris@279 1760
Chris@280 1761 QRect rt(cursorPos.x(),
Chris@918 1762 v->getPaintHeight() - paint.fontMetrics().height() - 2,
Chris@280 1763 paint.fontMetrics().width("1234.567 s"),
Chris@280 1764 paint.fontMetrics().height());
Chris@280 1765 extents.push_back(rt);
Chris@280 1766
Chris@280 1767 int w(paint.fontMetrics().width("1234567890") + 2);
Chris@280 1768 QRect frame(cursorPos.x() - w - 2,
Chris@918 1769 v->getPaintHeight() - paint.fontMetrics().height() - 2,
Chris@280 1770 w,
Chris@280 1771 paint.fontMetrics().height());
Chris@280 1772 extents.push_back(frame);
Chris@280 1773
Chris@77 1774 return true;
Chris@77 1775 }
Chris@77 1776
Chris@77 1777 void
Chris@918 1778 SpectrogramLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint,
Chris@77 1779 QPoint cursorPos) const
Chris@77 1780 {
Chris@77 1781 paint.save();
Chris@283 1782
Chris@608 1783 int sw = getVerticalScaleWidth(v, m_haveDetailedScale, paint);
Chris@283 1784
Chris@282 1785 QFont fn = paint.font();
Chris@282 1786 if (fn.pointSize() > 8) {
Chris@282 1787 fn.setPointSize(fn.pointSize() - 1);
Chris@282 1788 paint.setFont(fn);
Chris@282 1789 }
Chris@77 1790 paint.setPen(m_crosshairColour);
Chris@77 1791
Chris@77 1792 paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y());
Chris@918 1793 paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->getPaintHeight());
Chris@77 1794
Chris@905 1795 double fundamental = getFrequencyForY(v, cursorPos.y());
Chris@77 1796
Chris@1078 1797 PaintAssistant::drawVisibleText(v, paint,
Chris@278 1798 sw + 2,
Chris@278 1799 cursorPos.y() - 2,
Chris@278 1800 QString("%1 Hz").arg(fundamental),
Chris@1078 1801 PaintAssistant::OutlinedText);
Chris@278 1802
Chris@279 1803 if (Pitch::isFrequencyInMidiRange(fundamental)) {
Chris@279 1804 QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental);
Chris@1078 1805 PaintAssistant::drawVisibleText(v, paint,
Chris@279 1806 sw + 2,
Chris@279 1807 cursorPos.y() + paint.fontMetrics().ascent() + 2,
Chris@279 1808 pitchLabel,
Chris@1078 1809 PaintAssistant::OutlinedText);
Chris@279 1810 }
Chris@279 1811
Chris@907 1812 sv_frame_t frame = v->getFrameForX(cursorPos.x());
Chris@279 1813 RealTime rt = RealTime::frame2RealTime(frame, m_model->getSampleRate());
Chris@280 1814 QString rtLabel = QString("%1 s").arg(rt.toText(true).c_str());
Chris@280 1815 QString frameLabel = QString("%1").arg(frame);
Chris@1078 1816 PaintAssistant::drawVisibleText(v, paint,
Chris@280 1817 cursorPos.x() - paint.fontMetrics().width(frameLabel) - 2,
Chris@918 1818 v->getPaintHeight() - 2,
Chris@280 1819 frameLabel,
Chris@1078 1820 PaintAssistant::OutlinedText);
Chris@1078 1821 PaintAssistant::drawVisibleText(v, paint,
Chris@280 1822 cursorPos.x() + 2,
Chris@918 1823 v->getPaintHeight() - 2,
Chris@280 1824 rtLabel,
Chris@1078 1825 PaintAssistant::OutlinedText);
Chris@264 1826
Chris@77 1827 int harmonic = 2;
Chris@77 1828
Chris@77 1829 while (harmonic < 100) {
Chris@77 1830
Chris@907 1831 int hy = int(lrint(getYForFrequency(v, fundamental * harmonic)));
Chris@918 1832 if (hy < 0 || hy > v->getPaintHeight()) break;
Chris@77 1833
Chris@77 1834 int len = 7;
Chris@77 1835
Chris@77 1836 if (harmonic % 2 == 0) {
Chris@77 1837 if (harmonic % 4 == 0) {
Chris@77 1838 len = 12;
Chris@77 1839 } else {
Chris@77 1840 len = 10;
Chris@77 1841 }
Chris@77 1842 }
Chris@77 1843
Chris@77 1844 paint.drawLine(cursorPos.x() - len,
Chris@907 1845 hy,
Chris@77 1846 cursorPos.x(),
Chris@907 1847 hy);
Chris@77 1848
Chris@77 1849 ++harmonic;
Chris@77 1850 }
Chris@77 1851
Chris@77 1852 paint.restore();
Chris@77 1853 }
Chris@77 1854
Chris@25 1855 QString
Chris@918 1856 SpectrogramLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
Chris@25 1857 {
Chris@25 1858 int x = pos.x();
Chris@25 1859 int y = pos.y();
Chris@0 1860
Chris@25 1861 if (!m_model || !m_model->isOK()) return "";
Chris@0 1862
Chris@905 1863 double magMin = 0, magMax = 0;
Chris@905 1864 double phaseMin = 0, phaseMax = 0;
Chris@905 1865 double freqMin = 0, freqMax = 0;
Chris@905 1866 double adjFreqMin = 0, adjFreqMax = 0;
Chris@25 1867 QString pitchMin, pitchMax;
Chris@0 1868 RealTime rtMin, rtMax;
Chris@0 1869
Chris@38 1870 bool haveValues = false;
Chris@0 1871
Chris@44 1872 if (!getXBinSourceRange(v, x, rtMin, rtMax)) {
Chris@38 1873 return "";
Chris@38 1874 }
Chris@44 1875 if (getXYBinSourceRange(v, x, y, magMin, magMax, phaseMin, phaseMax)) {
Chris@38 1876 haveValues = true;
Chris@38 1877 }
Chris@0 1878
Chris@35 1879 QString adjFreqText = "", adjPitchText = "";
Chris@35 1880
Chris@1103 1881 if (m_binDisplay == BinDisplay::PeakFrequencies) {
Chris@35 1882
Chris@44 1883 if (!getAdjustedYBinSourceRange(v, x, y, freqMin, freqMax,
Chris@38 1884 adjFreqMin, adjFreqMax)) {
Chris@38 1885 return "";
Chris@38 1886 }
Chris@35 1887
Chris@35 1888 if (adjFreqMin != adjFreqMax) {
Chris@65 1889 adjFreqText = tr("Peak Frequency:\t%1 - %2 Hz\n")
Chris@35 1890 .arg(adjFreqMin).arg(adjFreqMax);
Chris@35 1891 } else {
Chris@65 1892 adjFreqText = tr("Peak Frequency:\t%1 Hz\n")
Chris@35 1893 .arg(adjFreqMin);
Chris@38 1894 }
Chris@38 1895
Chris@38 1896 QString pmin = Pitch::getPitchLabelForFrequency(adjFreqMin);
Chris@38 1897 QString pmax = Pitch::getPitchLabelForFrequency(adjFreqMax);
Chris@38 1898
Chris@38 1899 if (pmin != pmax) {
Chris@65 1900 adjPitchText = tr("Peak Pitch:\t%3 - %4\n").arg(pmin).arg(pmax);
Chris@38 1901 } else {
Chris@65 1902 adjPitchText = tr("Peak Pitch:\t%2\n").arg(pmin);
Chris@35 1903 }
Chris@35 1904
Chris@35 1905 } else {
Chris@35 1906
Chris@44 1907 if (!getYBinSourceRange(v, y, freqMin, freqMax)) return "";
Chris@35 1908 }
Chris@35 1909
Chris@25 1910 QString text;
Chris@25 1911
Chris@25 1912 if (rtMin != rtMax) {
Chris@25 1913 text += tr("Time:\t%1 - %2\n")
Chris@25 1914 .arg(rtMin.toText(true).c_str())
Chris@25 1915 .arg(rtMax.toText(true).c_str());
Chris@25 1916 } else {
Chris@25 1917 text += tr("Time:\t%1\n")
Chris@25 1918 .arg(rtMin.toText(true).c_str());
Chris@0 1919 }
Chris@0 1920
Chris@25 1921 if (freqMin != freqMax) {
Chris@65 1922 text += tr("%1Bin Frequency:\t%2 - %3 Hz\n%4Bin Pitch:\t%5 - %6\n")
Chris@65 1923 .arg(adjFreqText)
Chris@25 1924 .arg(freqMin)
Chris@25 1925 .arg(freqMax)
Chris@65 1926 .arg(adjPitchText)
Chris@65 1927 .arg(Pitch::getPitchLabelForFrequency(freqMin))
Chris@65 1928 .arg(Pitch::getPitchLabelForFrequency(freqMax));
Chris@65 1929 } else {
Chris@65 1930 text += tr("%1Bin Frequency:\t%2 Hz\n%3Bin Pitch:\t%4\n")
Chris@35 1931 .arg(adjFreqText)
Chris@25 1932 .arg(freqMin)
Chris@65 1933 .arg(adjPitchText)
Chris@65 1934 .arg(Pitch::getPitchLabelForFrequency(freqMin));
Chris@25 1935 }
Chris@25 1936
Chris@38 1937 if (haveValues) {
Chris@905 1938 double dbMin = AudioLevel::multiplier_to_dB(magMin);
Chris@905 1939 double dbMax = AudioLevel::multiplier_to_dB(magMax);
Chris@43 1940 QString dbMinString;
Chris@43 1941 QString dbMaxString;
Chris@43 1942 if (dbMin == AudioLevel::DB_FLOOR) {
Chris@43 1943 dbMinString = tr("-Inf");
Chris@43 1944 } else {
Chris@907 1945 dbMinString = QString("%1").arg(lrint(dbMin));
Chris@43 1946 }
Chris@43 1947 if (dbMax == AudioLevel::DB_FLOOR) {
Chris@43 1948 dbMaxString = tr("-Inf");
Chris@43 1949 } else {
Chris@907 1950 dbMaxString = QString("%1").arg(lrint(dbMax));
Chris@43 1951 }
Chris@907 1952 if (lrint(dbMin) != lrint(dbMax)) {
Chris@199 1953 text += tr("dB:\t%1 - %2").arg(dbMinString).arg(dbMaxString);
Chris@25 1954 } else {
Chris@199 1955 text += tr("dB:\t%1").arg(dbMinString);
Chris@25 1956 }
Chris@38 1957 if (phaseMin != phaseMax) {
Chris@38 1958 text += tr("\nPhase:\t%1 - %2").arg(phaseMin).arg(phaseMax);
Chris@38 1959 } else {
Chris@38 1960 text += tr("\nPhase:\t%1").arg(phaseMin);
Chris@38 1961 }
Chris@25 1962 }
Chris@25 1963
Chris@25 1964 return text;
Chris@0 1965 }
Chris@25 1966
Chris@0 1967 int
Chris@40 1968 SpectrogramLayer::getColourScaleWidth(QPainter &paint) const
Chris@40 1969 {
Chris@40 1970 int cw;
Chris@40 1971
Chris@119 1972 cw = paint.fontMetrics().width("-80dB");
Chris@119 1973
Chris@40 1974 return cw;
Chris@40 1975 }
Chris@40 1976
Chris@40 1977 int
Chris@918 1978 SpectrogramLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool detailed, QPainter &paint) const
Chris@0 1979 {
Chris@0 1980 if (!m_model || !m_model->isOK()) return 0;
Chris@0 1981
Chris@607 1982 int cw = 0;
Chris@607 1983 if (detailed) cw = getColourScaleWidth(paint);
Chris@40 1984
Chris@0 1985 int tw = paint.fontMetrics().width(QString("%1")
Chris@0 1986 .arg(m_maxFrequency > 0 ?
Chris@0 1987 m_maxFrequency - 1 :
Chris@0 1988 m_model->getSampleRate() / 2));
Chris@0 1989
Chris@234 1990 int fw = paint.fontMetrics().width(tr("43Hz"));
Chris@0 1991 if (tw < fw) tw = fw;
Chris@40 1992
Chris@1103 1993 int tickw = (m_binScale == BinScale::Log ? 10 : 4);
Chris@0 1994
Chris@40 1995 return cw + tickw + tw + 13;
Chris@0 1996 }
Chris@0 1997
Chris@0 1998 void
Chris@918 1999 SpectrogramLayer::paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const
Chris@0 2000 {
Chris@0 2001 if (!m_model || !m_model->isOK()) {
Chris@0 2002 return;
Chris@0 2003 }
Chris@0 2004
Chris@382 2005 Profiler profiler("SpectrogramLayer::paintVerticalScale");
Chris@122 2006
Chris@120 2007 //!!! cache this?
Chris@120 2008
Chris@0 2009 int h = rect.height(), w = rect.width();
Chris@0 2010
Chris@1103 2011 int tickw = (m_binScale == BinScale::Log ? 10 : 4);
Chris@1103 2012 int pkw = (m_binScale == BinScale::Log ? 10 : 0);
Chris@40 2013
Chris@1087 2014 int bins = getFFTSize() / 2;
Chris@907 2015 sv_samplerate_t sr = m_model->getSampleRate();
Chris@0 2016
Chris@0 2017 if (m_maxFrequency > 0) {
Chris@1087 2018 bins = int((double(m_maxFrequency) * getFFTSize()) / sr + 0.1);
Chris@1087 2019 if (bins > getFFTSize() / 2) bins = getFFTSize() / 2;
Chris@0 2020 }
Chris@0 2021
Chris@607 2022 int cw = 0;
Chris@607 2023
Chris@607 2024 if (detailed) cw = getColourScaleWidth(paint);
Chris@119 2025 int cbw = paint.fontMetrics().width("dB");
Chris@40 2026
Chris@0 2027 int py = -1;
Chris@0 2028 int textHeight = paint.fontMetrics().height();
Chris@0 2029 int toff = -textHeight + paint.fontMetrics().ascent() + 2;
Chris@0 2030
Chris@607 2031 if (detailed && (h > textHeight * 3 + 10)) {
Chris@119 2032
Chris@119 2033 int topLines = 2;
Chris@1105 2034 if (m_colourScale == ColourScaleType::Phase) topLines = 1;
Chris@119 2035
Chris@119 2036 int ch = h - textHeight * (topLines + 1) - 8;
Chris@119 2037 // paint.drawRect(4, textHeight + 4, cw - 1, ch + 1);
Chris@119 2038 paint.drawRect(4 + cw - cbw, textHeight * topLines + 4, cbw - 1, ch + 1);
Chris@40 2039
Chris@40 2040 QString top, bottom;
Chris@1030 2041 double min = m_viewMags[v->getId()].getMin();
Chris@1030 2042 double max = m_viewMags[v->getId()].getMax();
Chris@905 2043
Chris@905 2044 double dBmin = AudioLevel::multiplier_to_dB(min);
Chris@905 2045 double dBmax = AudioLevel::multiplier_to_dB(max);
Chris@119 2046
Chris@1044 2047 #ifdef DEBUG_SPECTROGRAM_REPAINT
Chris@1044 2048 cerr << "paintVerticalScale: for view id " << v->getId()
Chris@1044 2049 << ": min = " << min << ", max = " << max
Chris@1044 2050 << ", dBmin = " << dBmin << ", dBmax = " << dBmax << endl;
Chris@1044 2051 #endif
Chris@1044 2052
Chris@120 2053 if (dBmax < -60.f) dBmax = -60.f;
Chris@907 2054 else top = QString("%1").arg(lrint(dBmax));
Chris@120 2055
Chris@120 2056 if (dBmin < dBmax - 60.f) dBmin = dBmax - 60.f;
Chris@907 2057 bottom = QString("%1").arg(lrint(dBmin));
Chris@119 2058
Chris@119 2059 //!!! & phase etc
Chris@119 2060
Chris@1105 2061 if (m_colourScale != ColourScaleType::Phase) {
Chris@119 2062 paint.drawText((cw + 6 - paint.fontMetrics().width("dBFS")) / 2,
Chris@119 2063 2 + textHeight + toff, "dBFS");
Chris@119 2064 }
Chris@119 2065
Chris@119 2066 // paint.drawText((cw + 6 - paint.fontMetrics().width(top)) / 2,
Chris@119 2067 paint.drawText(3 + cw - cbw - paint.fontMetrics().width(top),
Chris@119 2068 2 + textHeight * topLines + toff + textHeight/2, top);
Chris@119 2069
Chris@119 2070 paint.drawText(3 + cw - cbw - paint.fontMetrics().width(bottom),
Chris@119 2071 h + toff - 3 - textHeight/2, bottom);
Chris@40 2072
Chris@40 2073 paint.save();
Chris@40 2074 paint.setBrush(Qt::NoBrush);
Chris@119 2075
Chris@119 2076 int lasty = 0;
Chris@119 2077 int lastdb = 0;
Chris@119 2078
Chris@40 2079 for (int i = 0; i < ch; ++i) {
Chris@119 2080
Chris@905 2081 double dBval = dBmin + (((dBmax - dBmin) * i) / (ch - 1));
Chris@119 2082 int idb = int(dBval);
Chris@119 2083
Chris@1106 2084 //!!! replace this
Chris@1106 2085 // double value = AudioLevel::dB_to_multiplier(dBval);
Chris@1106 2086 // int colour = getDisplayValue(v, value * m_gain);
Chris@1106 2087 // paint.setPen(m_palette.getColour((unsigned char)colour));
Chris@119 2088
Chris@119 2089 int y = textHeight * topLines + 4 + ch - i;
Chris@119 2090
Chris@119 2091 paint.drawLine(5 + cw - cbw, y, cw + 2, y);
Chris@119 2092
Chris@119 2093 if (i == 0) {
Chris@119 2094 lasty = y;
Chris@119 2095 lastdb = idb;
Chris@119 2096 } else if (i < ch - paint.fontMetrics().ascent() &&
Chris@120 2097 idb != lastdb &&
Chris@119 2098 ((abs(y - lasty) > textHeight &&
Chris@119 2099 idb % 10 == 0) ||
Chris@119 2100 (abs(y - lasty) > paint.fontMetrics().ascent() &&
Chris@119 2101 idb % 5 == 0))) {
Chris@287 2102 paint.setPen(v->getBackground());
Chris@119 2103 QString text = QString("%1").arg(idb);
Chris@119 2104 paint.drawText(3 + cw - cbw - paint.fontMetrics().width(text),
Chris@119 2105 y + toff + textHeight/2, text);
Chris@287 2106 paint.setPen(v->getForeground());
Chris@119 2107 paint.drawLine(5 + cw - cbw, y, 8 + cw - cbw, y);
Chris@119 2108 lasty = y;
Chris@119 2109 lastdb = idb;
Chris@119 2110 }
Chris@40 2111 }
Chris@40 2112 paint.restore();
Chris@40 2113 }
Chris@40 2114
Chris@40 2115 paint.drawLine(cw + 7, 0, cw + 7, h);
Chris@40 2116
Chris@0 2117 int bin = -1;
Chris@0 2118
Chris@918 2119 for (int y = 0; y < v->getPaintHeight(); ++y) {
Chris@0 2120
Chris@905 2121 double q0, q1;
Chris@918 2122 if (!getYBinRange(v, v->getPaintHeight() - y, q0, q1)) continue;
Chris@0 2123
Chris@0 2124 int vy;
Chris@0 2125
Chris@0 2126 if (int(q0) > bin) {
Chris@0 2127 vy = y;
Chris@0 2128 bin = int(q0);
Chris@0 2129 } else {
Chris@0 2130 continue;
Chris@0 2131 }
Chris@0 2132
Chris@1087 2133 int freq = int((sr * bin) / getFFTSize());
Chris@0 2134
Chris@0 2135 if (py >= 0 && (vy - py) < textHeight - 1) {
Chris@1103 2136 if (m_binScale == BinScale::Linear) {
Chris@40 2137 paint.drawLine(w - tickw, h - vy, w, h - vy);
Chris@40 2138 }
Chris@0 2139 continue;
Chris@0 2140 }
Chris@0 2141
Chris@0 2142 QString text = QString("%1").arg(freq);
Chris@234 2143 if (bin == 1) text = tr("%1Hz").arg(freq); // bin 0 is DC
Chris@40 2144 paint.drawLine(cw + 7, h - vy, w - pkw - 1, h - vy);
Chris@0 2145
Chris@0 2146 if (h - vy - textHeight >= -2) {
Chris@1025 2147 int tx = w - 3 - paint.fontMetrics().width(text) - max(tickw, pkw);
Chris@0 2148 paint.drawText(tx, h - vy + toff, text);
Chris@0 2149 }
Chris@0 2150
Chris@0 2151 py = vy;
Chris@0 2152 }
Chris@40 2153
Chris@1103 2154 if (m_binScale == BinScale::Log) {
Chris@40 2155
Chris@277 2156 // piano keyboard
Chris@277 2157
Chris@690 2158 PianoScale().paintPianoVertical
Chris@690 2159 (v, paint, QRect(w - pkw - 1, 0, pkw, h),
Chris@690 2160 getEffectiveMinFrequency(), getEffectiveMaxFrequency());
Chris@40 2161 }
Chris@608 2162
Chris@608 2163 m_haveDetailedScale = detailed;
Chris@0 2164 }
Chris@0 2165
Chris@187 2166 class SpectrogramRangeMapper : public RangeMapper
Chris@187 2167 {
Chris@187 2168 public:
Chris@901 2169 SpectrogramRangeMapper(sv_samplerate_t sr, int /* fftsize */) :
Chris@901 2170 m_dist(sr / 2),
Chris@901 2171 m_s2(sqrt(sqrt(2))) { }
Chris@187 2172 ~SpectrogramRangeMapper() { }
Chris@187 2173
Chris@901 2174 virtual int getPositionForValue(double value) const {
Chris@901 2175
Chris@901 2176 double dist = m_dist;
Chris@187 2177
Chris@187 2178 int n = 0;
Chris@187 2179
Chris@901 2180 while (dist > (value + 0.00001) && dist > 0.1) {
Chris@187 2181 dist /= m_s2;
Chris@187 2182 ++n;
Chris@187 2183 }
Chris@187 2184
Chris@187 2185 return n;
Chris@187 2186 }
Chris@724 2187
Chris@901 2188 virtual int getPositionForValueUnclamped(double value) const {
Chris@724 2189 // We don't really support this
Chris@724 2190 return getPositionForValue(value);
Chris@724 2191 }
Chris@187 2192
Chris@901 2193 virtual double getValueForPosition(int position) const {
Chris@187 2194
Chris@187 2195 // Vertical zoom step 0 shows the entire range from DC ->
Chris@187 2196 // Nyquist frequency. Step 1 shows 2^(1/4) of the range of
Chris@187 2197 // step 0, and so on until the visible range is smaller than
Chris@187 2198 // the frequency step between bins at the current fft size.
Chris@187 2199
Chris@901 2200 double dist = m_dist;
Chris@187 2201
Chris@187 2202 int n = 0;
Chris@187 2203 while (n < position) {
Chris@187 2204 dist /= m_s2;
Chris@187 2205 ++n;
Chris@187 2206 }
Chris@187 2207
Chris@187 2208 return dist;
Chris@187 2209 }
Chris@187 2210
Chris@901 2211 virtual double getValueForPositionUnclamped(int position) const {
Chris@724 2212 // We don't really support this
Chris@724 2213 return getValueForPosition(position);
Chris@724 2214 }
Chris@724 2215
Chris@187 2216 virtual QString getUnit() const { return "Hz"; }
Chris@187 2217
Chris@187 2218 protected:
Chris@901 2219 double m_dist;
Chris@901 2220 double m_s2;
Chris@187 2221 };
Chris@187 2222
Chris@133 2223 int
Chris@133 2224 SpectrogramLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@133 2225 {
Chris@135 2226 if (!m_model) return 0;
Chris@187 2227
Chris@907 2228 sv_samplerate_t sr = m_model->getSampleRate();
Chris@187 2229
Chris@1087 2230 SpectrogramRangeMapper mapper(sr, getFFTSize());
Chris@1087 2231
Chris@1087 2232 // int maxStep = mapper.getPositionForValue((double(sr) / getFFTSize()) + 0.001);
Chris@187 2233 int maxStep = mapper.getPositionForValue(0);
Chris@905 2234 int minStep = mapper.getPositionForValue(double(sr) / 2);
Chris@250 2235
Chris@805 2236 int initialMax = m_initialMaxFrequency;
Chris@907 2237 if (initialMax == 0) initialMax = int(sr / 2);
Chris@250 2238
Chris@250 2239 defaultStep = mapper.getPositionForValue(initialMax) - minStep;
Chris@250 2240
Chris@587 2241 // SVDEBUG << "SpectrogramLayer::getVerticalZoomSteps: " << maxStep - minStep << " (" << maxStep <<"-" << minStep << "), default is " << defaultStep << " (from initial max freq " << initialMax << ")" << endl;
Chris@187 2242
Chris@187 2243 return maxStep - minStep;
Chris@133 2244 }
Chris@133 2245
Chris@133 2246 int
Chris@133 2247 SpectrogramLayer::getCurrentVerticalZoomStep() const
Chris@133 2248 {
Chris@133 2249 if (!m_model) return 0;
Chris@133 2250
Chris@905 2251 double dmin, dmax;
Chris@133 2252 getDisplayExtents(dmin, dmax);
Chris@133 2253
Chris@1087 2254 SpectrogramRangeMapper mapper(m_model->getSampleRate(), getFFTSize());
Chris@187 2255 int n = mapper.getPositionForValue(dmax - dmin);
Chris@587 2256 // SVDEBUG << "SpectrogramLayer::getCurrentVerticalZoomStep: " << n << endl;
Chris@133 2257 return n;
Chris@133 2258 }
Chris@133 2259
Chris@133 2260 void
Chris@133 2261 SpectrogramLayer::setVerticalZoomStep(int step)
Chris@133 2262 {
Chris@187 2263 if (!m_model) return;
Chris@187 2264
Chris@905 2265 double dmin = m_minFrequency, dmax = m_maxFrequency;
Chris@253 2266 // getDisplayExtents(dmin, dmax);
Chris@253 2267
Chris@682 2268 // cerr << "current range " << dmin << " -> " << dmax << ", range " << dmax-dmin << ", mid " << (dmax + dmin)/2 << endl;
Chris@133 2269
Chris@907 2270 sv_samplerate_t sr = m_model->getSampleRate();
Chris@1087 2271 SpectrogramRangeMapper mapper(sr, getFFTSize());
Chris@905 2272 double newdist = mapper.getValueForPosition(step);
Chris@905 2273
Chris@905 2274 double newmin, newmax;
Chris@253 2275
Chris@1103 2276 if (m_binScale == BinScale::Log) {
Chris@253 2277
Chris@253 2278 // need to pick newmin and newmax such that
Chris@253 2279 //
Chris@253 2280 // (log(newmin) + log(newmax)) / 2 == logmid
Chris@253 2281 // and
Chris@253 2282 // newmax - newmin = newdist
Chris@253 2283 //
Chris@253 2284 // so log(newmax - newdist) + log(newmax) == 2logmid
Chris@253 2285 // log(newmax(newmax - newdist)) == 2logmid
Chris@253 2286 // newmax.newmax - newmax.newdist == exp(2logmid)
Chris@253 2287 // newmax^2 + (-newdist)newmax + -exp(2logmid) == 0
Chris@253 2288 // quadratic with a = 1, b = -newdist, c = -exp(2logmid), all known
Chris@253 2289 //
Chris@253 2290 // positive root
Chris@253 2291 // newmax = (newdist + sqrt(newdist^2 + 4exp(2logmid))) / 2
Chris@253 2292 //
Chris@253 2293 // but logmid = (log(dmin) + log(dmax)) / 2
Chris@253 2294 // so exp(2logmid) = exp(log(dmin) + log(dmax))
Chris@253 2295 // = exp(log(dmin.dmax))
Chris@253 2296 // = dmin.dmax
Chris@253 2297 // so newmax = (newdist + sqrtf(newdist^2 + 4dmin.dmax)) / 2
Chris@253 2298
Chris@907 2299 newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2;
Chris@253 2300 newmin = newmax - newdist;
Chris@253 2301
Chris@682 2302 // cerr << "newmin = " << newmin << ", newmax = " << newmax << endl;
Chris@253 2303
Chris@253 2304 } else {
Chris@905 2305 double dmid = (dmax + dmin) / 2;
Chris@253 2306 newmin = dmid - newdist / 2;
Chris@253 2307 newmax = dmid + newdist / 2;
Chris@253 2308 }
Chris@187 2309
Chris@905 2310 double mmin, mmax;
Chris@187 2311 mmin = 0;
Chris@905 2312 mmax = double(sr) / 2;
Chris@133 2313
Chris@187 2314 if (newmin < mmin) {
Chris@187 2315 newmax += (mmin - newmin);
Chris@187 2316 newmin = mmin;
Chris@187 2317 }
Chris@187 2318 if (newmax > mmax) {
Chris@187 2319 newmax = mmax;
Chris@187 2320 }
Chris@133 2321
Chris@587 2322 // SVDEBUG << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl;
Chris@253 2323
Chris@907 2324 setMinFrequency(int(lrint(newmin)));
Chris@907 2325 setMaxFrequency(int(lrint(newmax)));
Chris@187 2326 }
Chris@187 2327
Chris@187 2328 RangeMapper *
Chris@187 2329 SpectrogramLayer::getNewVerticalZoomRangeMapper() const
Chris@187 2330 {
Chris@187 2331 if (!m_model) return 0;
Chris@1087 2332 return new SpectrogramRangeMapper(m_model->getSampleRate(), getFFTSize());
Chris@133 2333 }
Chris@133 2334
Chris@273 2335 void
Chris@918 2336 SpectrogramLayer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const
Chris@273 2337 {
Chris@273 2338 int y0 = 0;
Chris@907 2339 if (r.startY > 0.0) y0 = int(getYForFrequency(v, r.startY));
Chris@273 2340
Chris@273 2341 int y1 = y0;
Chris@907 2342 if (r.endY > 0.0) y1 = int(getYForFrequency(v, r.endY));
Chris@273 2343
Chris@587 2344 // SVDEBUG << "SpectrogramLayer::updateMeasureRectYCoords: start " << r.startY << " -> " << y0 << ", end " << r.endY << " -> " << y1 << endl;
Chris@273 2345
Chris@273 2346 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0);
Chris@273 2347 }
Chris@273 2348
Chris@273 2349 void
Chris@918 2350 SpectrogramLayer::setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const
Chris@273 2351 {
Chris@273 2352 if (start) {
Chris@273 2353 r.startY = getFrequencyForY(v, y);
Chris@273 2354 r.endY = r.startY;
Chris@273 2355 } else {
Chris@273 2356 r.endY = getFrequencyForY(v, y);
Chris@273 2357 }
Chris@587 2358 // SVDEBUG << "SpectrogramLayer::setMeasureRectYCoord: start " << r.startY << " <- " << y << ", end " << r.endY << " <- " << y << endl;
Chris@273 2359
Chris@273 2360 }
Chris@273 2361
Chris@316 2362 void
Chris@316 2363 SpectrogramLayer::toXml(QTextStream &stream,
Chris@316 2364 QString indent, QString extraAttributes) const
Chris@6 2365 {
Chris@6 2366 QString s;
Chris@6 2367
Chris@6 2368 s += QString("channel=\"%1\" "
Chris@6 2369 "windowSize=\"%2\" "
Chris@153 2370 "windowHopLevel=\"%3\" "
Chris@153 2371 "gain=\"%4\" "
Chris@153 2372 "threshold=\"%5\" ")
Chris@6 2373 .arg(m_channel)
Chris@6 2374 .arg(m_windowSize)
Chris@97 2375 .arg(m_windowHopLevel)
Chris@37 2376 .arg(m_gain)
Chris@37 2377 .arg(m_threshold);
Chris@37 2378
Chris@37 2379 s += QString("minFrequency=\"%1\" "
Chris@37 2380 "maxFrequency=\"%2\" "
Chris@37 2381 "colourScale=\"%3\" "
Chris@37 2382 "colourScheme=\"%4\" "
Chris@37 2383 "colourRotation=\"%5\" "
Chris@37 2384 "frequencyScale=\"%6\" "
Chris@761 2385 "binDisplay=\"%7\" ")
Chris@37 2386 .arg(m_minFrequency)
Chris@6 2387 .arg(m_maxFrequency)
Chris@1104 2388 .arg(convertFromColourScale(m_colourScale))
Chris@197 2389 .arg(m_colourMap)
Chris@37 2390 .arg(m_colourRotation)
Chris@1103 2391 .arg(int(m_binScale))
Chris@1103 2392 .arg(int(m_binDisplay));
Chris@761 2393
Chris@1009 2394 // New-style normalization attributes, allowing for more types of
Chris@1009 2395 // normalization in future: write out the column normalization
Chris@1009 2396 // type separately, and then whether we are normalizing visible
Chris@1009 2397 // area as well afterwards
Chris@1009 2398
Chris@1009 2399 s += QString("columnNormalization=\"%1\" ")
Chris@1104 2400 .arg(m_normalization == ColumnNormalization::Max1 ? "peak" :
Chris@1104 2401 m_normalization == ColumnNormalization::Hybrid ? "hybrid" : "none");
Chris@1009 2402
Chris@1009 2403 // Old-style normalization attribute. We *don't* write out
Chris@1009 2404 // normalizeHybrid here because the only release that would accept
Chris@1009 2405 // it (Tony v1.0) has a totally different scale factor for
Chris@1009 2406 // it. We'll just have to accept that session files from Tony
Chris@1009 2407 // v2.0+ will look odd in Tony v1.0
Chris@1009 2408
Chris@1009 2409 s += QString("normalizeColumns=\"%1\" ")
Chris@1104 2410 .arg(m_normalization == ColumnNormalization::Max1 ? "true" : "false");
Chris@1009 2411
Chris@1009 2412 // And this applies to both old- and new-style attributes
Chris@1009 2413
Chris@1009 2414 s += QString("normalizeVisibleArea=\"%1\" ")
Chris@1104 2415 .arg(m_normalizeVisibleArea ? "true" : "false");
Chris@1009 2416
Chris@316 2417 Layer::toXml(stream, indent, extraAttributes + " " + s);
Chris@6 2418 }
Chris@6 2419
Chris@11 2420 void
Chris@11 2421 SpectrogramLayer::setProperties(const QXmlAttributes &attributes)
Chris@11 2422 {
Chris@11 2423 bool ok = false;
Chris@11 2424
Chris@11 2425 int channel = attributes.value("channel").toInt(&ok);
Chris@11 2426 if (ok) setChannel(channel);
Chris@11 2427
Chris@805 2428 int windowSize = attributes.value("windowSize").toUInt(&ok);
Chris@11 2429 if (ok) setWindowSize(windowSize);
Chris@11 2430
Chris@805 2431 int windowHopLevel = attributes.value("windowHopLevel").toUInt(&ok);
Chris@97 2432 if (ok) setWindowHopLevel(windowHopLevel);
Chris@97 2433 else {
Chris@805 2434 int windowOverlap = attributes.value("windowOverlap").toUInt(&ok);
Chris@97 2435 // a percentage value
Chris@97 2436 if (ok) {
Chris@97 2437 if (windowOverlap == 0) setWindowHopLevel(0);
Chris@97 2438 else if (windowOverlap == 25) setWindowHopLevel(1);
Chris@97 2439 else if (windowOverlap == 50) setWindowHopLevel(2);
Chris@97 2440 else if (windowOverlap == 75) setWindowHopLevel(3);
Chris@97 2441 else if (windowOverlap == 90) setWindowHopLevel(4);
Chris@97 2442 }
Chris@97 2443 }
Chris@11 2444
Chris@11 2445 float gain = attributes.value("gain").toFloat(&ok);
Chris@11 2446 if (ok) setGain(gain);
Chris@11 2447
Chris@37 2448 float threshold = attributes.value("threshold").toFloat(&ok);
Chris@37 2449 if (ok) setThreshold(threshold);
Chris@37 2450
Chris@805 2451 int minFrequency = attributes.value("minFrequency").toUInt(&ok);
Chris@187 2452 if (ok) {
Chris@587 2453 SVDEBUG << "SpectrogramLayer::setProperties: setting min freq to " << minFrequency << endl;
Chris@187 2454 setMinFrequency(minFrequency);
Chris@187 2455 }
Chris@37 2456
Chris@805 2457 int maxFrequency = attributes.value("maxFrequency").toUInt(&ok);
Chris@187 2458 if (ok) {
Chris@587 2459 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl;
Chris@187 2460 setMaxFrequency(maxFrequency);
Chris@187 2461 }
Chris@11 2462
Chris@1105 2463 ColourScaleType colourScale = convertToColourScale
Chris@1092 2464 (attributes.value("colourScale").toInt(&ok));
Chris@11 2465 if (ok) setColourScale(colourScale);
Chris@11 2466
Chris@197 2467 int colourMap = attributes.value("colourScheme").toInt(&ok);
Chris@197 2468 if (ok) setColourMap(colourMap);
Chris@11 2469
Chris@37 2470 int colourRotation = attributes.value("colourRotation").toInt(&ok);
Chris@37 2471 if (ok) setColourRotation(colourRotation);
Chris@37 2472
Chris@1103 2473 BinScale binScale = (BinScale)
Chris@11 2474 attributes.value("frequencyScale").toInt(&ok);
Chris@1093 2475 if (ok) setBinScale(binScale);
Chris@1093 2476
Chris@1103 2477 BinDisplay binDisplay = (BinDisplay)
Chris@37 2478 attributes.value("binDisplay").toInt(&ok);
Chris@37 2479 if (ok) setBinDisplay(binDisplay);
Chris@36 2480
Chris@1009 2481 bool haveNewStyleNormalization = false;
Chris@1009 2482
Chris@1009 2483 QString columnNormalization = attributes.value("columnNormalization");
Chris@1009 2484
Chris@1009 2485 if (columnNormalization != "") {
Chris@1009 2486
Chris@1009 2487 haveNewStyleNormalization = true;
Chris@1009 2488
Chris@1009 2489 if (columnNormalization == "peak") {
Chris@1104 2490 setNormalization(ColumnNormalization::Max1);
Chris@1009 2491 } else if (columnNormalization == "hybrid") {
Chris@1104 2492 setNormalization(ColumnNormalization::Hybrid);
Chris@1009 2493 } else if (columnNormalization == "none") {
Chris@1104 2494 setNormalization(ColumnNormalization::None);
Chris@1009 2495 } else {
Chris@1009 2496 cerr << "NOTE: Unknown or unsupported columnNormalization attribute \""
Chris@1009 2497 << columnNormalization << "\"" << endl;
Chris@1009 2498 }
Chris@1009 2499 }
Chris@1009 2500
Chris@1009 2501 if (!haveNewStyleNormalization) {
Chris@1009 2502
Chris@1009 2503 bool normalizeColumns =
Chris@1009 2504 (attributes.value("normalizeColumns").trimmed() == "true");
Chris@1009 2505 if (normalizeColumns) {
Chris@1104 2506 setNormalization(ColumnNormalization::Max1);
Chris@1009 2507 }
Chris@1009 2508
Chris@1009 2509 bool normalizeHybrid =
Chris@1009 2510 (attributes.value("normalizeHybrid").trimmed() == "true");
Chris@1009 2511 if (normalizeHybrid) {
Chris@1104 2512 setNormalization(ColumnNormalization::Hybrid);
Chris@1009 2513 }
Chris@862 2514 }
Chris@153 2515
Chris@153 2516 bool normalizeVisibleArea =
Chris@1099 2517 (attributes.value("normalizeVisibleArea").trimmed() == "true");
Chris@1104 2518 setNormalizeVisibleArea(normalizeVisibleArea);
Chris@1104 2519
Chris@1104 2520 if (!haveNewStyleNormalization && m_normalization == ColumnNormalization::Hybrid) {
Chris@1009 2521 // Tony v1.0 is (and hopefully will remain!) the only released
Chris@1009 2522 // SV-a-like to use old-style attributes when saving sessions
Chris@1009 2523 // that ask for hybrid normalization. It saves them with the
Chris@1009 2524 // wrong gain factor, so hack in a fix for that here -- this
Chris@1009 2525 // gives us backward but not forward compatibility.
Chris@1087 2526 setGain(m_gain / float(getFFTSize() / 2));
Chris@862 2527 }
Chris@11 2528 }
Chris@11 2529