comparison layer/Colour3DPlotLayer.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents b3603483228d
children d79e21855aef
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
146 146
147 connectSignals(m_model); 147 connectSignals(m_model);
148 148
149 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); 149 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
150 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), 150 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
151 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); 151 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
152 152
153 m_peakResolution = 256; 153 m_peakResolution = 256;
154 if (model->getResolution() > 512) { 154 if (model->getResolution() > 512) {
155 m_peakResolution = 16; 155 m_peakResolution = 16;
156 } else if (model->getResolution() > 128) { 156 } else if (model->getResolution() > 128) {
322 if (!max) max = &garbage1; 322 if (!max) max = &garbage1;
323 if (!deflt) deflt = &garbage2; 323 if (!deflt) deflt = &garbage2;
324 324
325 if (name == "Gain") { 325 if (name == "Gain") {
326 326
327 *min = -50; 327 *min = -50;
328 *max = 50; 328 *max = 50;
329 329
330 *deflt = int(lrint(log10(1.0) * 20.0)); 330 *deflt = int(lrint(log10(1.0) * 20.0));
331 if (*deflt < *min) *deflt = *min; 331 if (*deflt < *min) *deflt = *min;
332 if (*deflt > *max) *deflt = *max; 332 if (*deflt > *max) *deflt = *max;
333 333
334 val = int(lrint(log10(m_gain) * 20.0)); 334 val = int(lrint(log10(m_gain) * 20.0));
335 if (val < *min) val = *min; 335 if (val < *min) val = *min;
336 if (val > *max) val = *max; 336 if (val > *max) val = *max;
337 337
338 } else if (name == "Colour Scale") { 338 } else if (name == "Colour Scale") {
339 339
340 // linear, log, +/-1, abs 340 // linear, log, +/-1, abs
341 *min = 0;
342 *max = 3;
343 *deflt = 0;
344
345 val = convertFromColourScale(m_colourScale);
346
347 } else if (name == "Colour") {
348
349 *min = 0;
350 *max = ColourMapper::getColourMapCount() - 1;
351 *deflt = 0;
352
353 val = m_colourMap;
354
355 } else if (name == "Normalization") {
356
357 *min = 0; 341 *min = 0;
358 *max = 3; 342 *max = 3;
359 *deflt = 0; 343 *deflt = 0;
360 344
345 val = convertFromColourScale(m_colourScale);
346
347 } else if (name == "Colour") {
348
349 *min = 0;
350 *max = ColourMapper::getColourMapCount() - 1;
351 *deflt = 0;
352
353 val = m_colourMap;
354
355 } else if (name == "Normalization") {
356
357 *min = 0;
358 *max = 3;
359 *deflt = 0;
360
361 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea); 361 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea);
362 362
363 } else if (name == "Invert Vertical Scale") { 363 } else if (name == "Invert Vertical Scale") {
364 364
365 *deflt = 0; 365 *deflt = 0;
366 val = (m_invertVertical ? 1 : 0); 366 val = (m_invertVertical ? 1 : 0);
367 367
368 } else if (name == "Bin Scale") { 368 } else if (name == "Bin Scale") {
369 369
370 *min = 0; 370 *min = 0;
371 *max = 1; 371 *max = 1;
372 *deflt = int(BinScale::Linear); 372 *deflt = int(BinScale::Linear);
373 val = (int)m_binScale; 373 val = (int)m_binScale;
374 374
375 } else if (name == "Opaque") { 375 } else if (name == "Opaque") {
376 376
377 *deflt = 0; 377 *deflt = 0;
378 val = (m_opaque ? 1 : 0); 378 val = (m_opaque ? 1 : 0);
379 379
380 } else if (name == "Smooth") { 380 } else if (name == "Smooth") {
381 381
382 *deflt = 0; 382 *deflt = 0;
383 val = (m_smooth ? 1 : 0); 383 val = (m_smooth ? 1 : 0);
384 384
385 } else { 385 } else {
386 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); 386 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
387 } 387 }
388 388
389 return val; 389 return val;
390 } 390 }
391 391
392 QString 392 QString
393 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name, 393 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
394 int value) const 394 int value) const
395 { 395 {
396 if (name == "Colour") { 396 if (name == "Colour") {
397 return ColourMapper::getColourMapName(value); 397 return ColourMapper::getColourMapName(value);
398 } 398 }
399 if (name == "Colour Scale") { 399 if (name == "Colour Scale") {
400 switch (value) { 400 switch (value) {
401 default: 401 default:
402 case 0: return tr("Linear"); 402 case 0: return tr("Linear");
403 case 1: return tr("Log"); 403 case 1: return tr("Log");
404 case 2: return tr("+/-1"); 404 case 2: return tr("+/-1");
405 case 3: return tr("Absolute"); 405 case 3: return tr("Absolute");
406 } 406 }
407 } 407 }
408 if (name == "Normalization") { 408 if (name == "Normalization") {
409 switch(value) { 409 switch(value) {
410 default: 410 default:
411 case 0: return tr("None"); 411 case 0: return tr("None");
414 case 3: return tr("Hybrid"); 414 case 3: return tr("Hybrid");
415 } 415 }
416 // return ""; // icon only 416 // return ""; // icon only
417 } 417 }
418 if (name == "Bin Scale") { 418 if (name == "Bin Scale") {
419 switch (value) { 419 switch (value) {
420 default: 420 default:
421 case 0: return tr("Linear"); 421 case 0: return tr("Linear");
422 case 1: return tr("Log"); 422 case 1: return tr("Log");
423 } 423 }
424 } 424 }
425 return tr("<unknown>"); 425 return tr("<unknown>");
426 } 426 }
427 427
428 QString 428 QString
452 452
453 void 453 void
454 Colour3DPlotLayer::setProperty(const PropertyName &name, int value) 454 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
455 { 455 {
456 if (name == "Gain") { 456 if (name == "Gain") {
457 setGain(float(pow(10, value/20.0))); 457 setGain(float(pow(10, value/20.0)));
458 } else if (name == "Colour Scale") { 458 } else if (name == "Colour Scale") {
459 setColourScale(convertToColourScale(value)); 459 setColourScale(convertToColourScale(value));
460 } else if (name == "Colour") { 460 } else if (name == "Colour") {
461 setColourMap(value); 461 setColourMap(value);
462 } else if (name == "Invert Vertical Scale") { 462 } else if (name == "Invert Vertical Scale") {
463 setInvertVertical(value ? true : false); 463 setInvertVertical(value ? true : false);
464 } else if (name == "Opaque") { 464 } else if (name == "Opaque") {
465 setOpaque(value ? true : false); 465 setOpaque(value ? true : false);
466 } else if (name == "Smooth") { 466 } else if (name == "Smooth") {
467 setSmooth(value ? true : false); 467 setSmooth(value ? true : false);
468 } else if (name == "Bin Scale") { 468 } else if (name == "Bin Scale") {
469 switch (value) { 469 switch (value) {
470 default: 470 default:
471 case 0: setBinScale(BinScale::Linear); break; 471 case 0: setBinScale(BinScale::Linear); break;
472 case 1: setBinScale(BinScale::Log); break; 472 case 1: setBinScale(BinScale::Log); break;
473 } 473 }
474 } else if (name == "Normalization") { 474 } else if (name == "Normalization") {
475 auto n = convertToColumnNorm(value); 475 auto n = convertToColumnNorm(value);
476 setNormalization(n.first); 476 setNormalization(n.first);
477 setNormalizeVisibleArea(n.second); 477 setNormalizeVisibleArea(n.second);
478 } 478 }
622 } 622 }
623 623
624 Layer::setLayerDormant(v, true); 624 Layer::setLayerDormant(v, true);
625 625
626 cacheInvalid(); 626 cacheInvalid();
627 627
628 } else { 628 } else {
629 629
630 Layer::setLayerDormant(v, false); 630 Layer::setLayerDormant(v, false);
631 } 631 }
632 } 632 }
833 QString binName = m_model->getBinName(sy); 833 QString binName = m_model->getBinName(sy);
834 if (binName == "") binName = QString("[%1]").arg(sy + 1); 834 if (binName == "") binName = QString("[%1]").arg(sy + 1);
835 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1); 835 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
836 836
837 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4") 837 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
838 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate()) 838 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
839 .toText(true).c_str()) 839 .toText(true).c_str())
840 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate()) 840 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
841 .toText(true).c_str()) 841 .toText(true).c_str())
842 .arg(binName) 842 .arg(binName)
843 .arg(value); 843 .arg(value);
844 844
845 return text; 845 return text;
846 } 846 }
847 847
848 int 848 int
861 QString sampleText = QString("[%1]").arg(m_model->getHeight()); 861 QString sampleText = QString("[%1]").arg(m_model->getHeight());
862 int tw = paint.fontMetrics().width(sampleText); 862 int tw = paint.fontMetrics().width(sampleText);
863 bool another = false; 863 bool another = false;
864 864
865 for (int i = 0; i < m_model->getHeight(); ++i) { 865 for (int i = 0; i < m_model->getHeight(); ++i) {
866 if (m_model->getBinName(i).length() > sampleText.length()) { 866 if (m_model->getBinName(i).length() > sampleText.length()) {
867 sampleText = m_model->getBinName(i); 867 sampleText = m_model->getBinName(i);
868 another = true; 868 another = true;
869 } 869 }
870 } 870 }
871 if (another) { 871 if (another) {
872 tw = std::max(tw, paint.fontMetrics().width(sampleText)); 872 tw = std::max(tw, paint.fontMetrics().width(sampleText));
873 } 873 }
874 874
875 return tw + 13 + getColourScaleWidth(paint); 875 return tw + 13 + getColourScaleWidth(paint);
876 } 876 }
877 877
967 } else { 967 } else {
968 continue; 968 continue;
969 } 969 }
970 } 970 }
971 } 971 }
972 972
973 py = y0; 973 py = y0;
974 974
975 if (i < symax) { 975 if (i < symax) {
976 paint.drawLine(cw, y0, w, y0); 976 paint.drawLine(cw, y0, w, y0);
977 } 977 }
1121 cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl; 1121 cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl;
1122 #endif 1122 #endif
1123 1123
1124 int completion = 0; 1124 int completion = 0;
1125 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { 1125 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
1126 if (completion > 0) { 1126 if (completion > 0) {
1127 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100, 1127 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
1128 10, QColor(120, 120, 120)); 1128 10, QColor(120, 120, 120));
1129 } 1129 }
1130 return; 1130 return;
1131 } 1131 }
1132 1132
1133 if (m_model->getWidth() == 0) { 1133 if (m_model->getWidth() == 0) {
1134 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1134 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1135 cerr << "Colour3DPlotLayer::paint(): model width == 0, " 1135 cerr << "Colour3DPlotLayer::paint(): model width == 0, "
1141 paintWithRenderer(v, paint, rect); 1141 paintWithRenderer(v, paint, rect);
1142 } 1142 }
1143 1143
1144 bool 1144 bool
1145 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 1145 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
1146 int &resolution, 1146 int &resolution,
1147 SnapType snap) const 1147 SnapType snap) const
1148 { 1148 {
1149 if (!m_model) { 1149 if (!m_model) {
1150 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 1150 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
1151 } 1151 }
1152 1152
1153 resolution = m_model->getResolution(); 1153 resolution = m_model->getResolution();
1154 sv_frame_t left = (frame / resolution) * resolution; 1154 sv_frame_t left = (frame / resolution) * resolution;
1155 sv_frame_t right = left + resolution; 1155 sv_frame_t right = left + resolution;
1157 switch (snap) { 1157 switch (snap) {
1158 case SnapLeft: frame = left; break; 1158 case SnapLeft: frame = left; break;
1159 case SnapRight: frame = right; break; 1159 case SnapRight: frame = right; break;
1160 case SnapNearest: 1160 case SnapNearest:
1161 case SnapNeighbouring: 1161 case SnapNeighbouring:
1162 if (frame - left > right - frame) frame = right; 1162 if (frame - left > right - frame) frame = right;
1163 else frame = left; 1163 else frame = left;
1164 break; 1164 break;
1165 } 1165 }
1166 1166
1167 return true; 1167 return true;
1168 } 1168 }
1169 1169
1175 "colourScheme=\"%2\" " 1175 "colourScheme=\"%2\" "
1176 "minY=\"%3\" " 1176 "minY=\"%3\" "
1177 "maxY=\"%4\" " 1177 "maxY=\"%4\" "
1178 "invertVertical=\"%5\" " 1178 "invertVertical=\"%5\" "
1179 "opaque=\"%6\" %7") 1179 "opaque=\"%6\" %7")
1180 .arg(convertFromColourScale(m_colourScale)) 1180 .arg(convertFromColourScale(m_colourScale))
1181 .arg(m_colourMap) 1181 .arg(m_colourMap)
1182 .arg(m_miny) 1182 .arg(m_miny)
1183 .arg(m_maxy) 1183 .arg(m_maxy)
1184 .arg(m_invertVertical ? "true" : "false") 1184 .arg(m_invertVertical ? "true" : "false")
1185 .arg(m_opaque ? "true" : "false") 1185 .arg(m_opaque ? "true" : "false")
1198 m_normalization == ColumnNormalization::Hybrid ? "hybrid" : "none"); 1198 m_normalization == ColumnNormalization::Hybrid ? "hybrid" : "none");
1199 1199
1200 // Old-style normalization attribute, for backward compatibility 1200 // Old-style normalization attribute, for backward compatibility
1201 1201
1202 s += QString("normalizeColumns=\"%1\" ") 1202 s += QString("normalizeColumns=\"%1\" ")
1203 .arg(m_normalization == ColumnNormalization::Range01 ? "true" : "false"); 1203 .arg(m_normalization == ColumnNormalization::Range01 ? "true" : "false");
1204 1204
1205 // And this applies to both old- and new-style attributes 1205 // And this applies to both old- and new-style attributes
1206 1206
1207 s += QString("normalizeVisibleArea=\"%1\" ") 1207 s += QString("normalizeVisibleArea=\"%1\" ")
1208 .arg(m_normalizeVisibleArea ? "true" : "false"); 1208 .arg(m_normalizeVisibleArea ? "true" : "false");
1221 1221
1222 int colourMap = attributes.value("colourScheme").toInt(&ok); 1222 int colourMap = attributes.value("colourScheme").toInt(&ok);
1223 if (ok) setColourMap(colourMap); 1223 if (ok) setColourMap(colourMap);
1224 1224
1225 BinScale binScale = (BinScale) 1225 BinScale binScale = (BinScale)
1226 attributes.value("binScale").toInt(&ok); 1226 attributes.value("binScale").toInt(&ok);
1227 if (ok) setBinScale(binScale); 1227 if (ok) setBinScale(binScale);
1228 1228
1229 bool invertVertical = 1229 bool invertVertical =
1230 (attributes.value("invertVertical").trimmed() == "true"); 1230 (attributes.value("invertVertical").trimmed() == "true");
1231 setInvertVertical(invertVertical); 1231 setInvertVertical(invertVertical);