annotate layer/SliceLayer.cpp @ 1281:fc9d9f1103fa horizontal-scale

Provide linear horizontal scale in spectrum as well as log; fix bin positioning and colour scale property box updating; ensure proper background colour and visibility of peak lines
author Chris Cannam
date Thu, 03 May 2018 15:15:15 +0100
parents a34a2a25907c
children 51e6125627fa
rev   line source
Chris@133 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@133 2
Chris@133 3 /*
Chris@133 4 Sonic Visualiser
Chris@133 5 An audio file viewer and annotation editor.
Chris@133 6 Centre for Digital Music, Queen Mary, University of London.
Chris@195 7 This file copyright 2006-2007 QMUL.
Chris@133 8
Chris@133 9 This program is free software; you can redistribute it and/or
Chris@133 10 modify it under the terms of the GNU General Public License as
Chris@133 11 published by the Free Software Foundation; either version 2 of the
Chris@133 12 License, or (at your option) any later version. See the file
Chris@133 13 COPYING included with this distribution for more information.
Chris@133 14 */
Chris@133 15
Chris@193 16 #include "SliceLayer.h"
Chris@133 17
Chris@133 18 #include "view/View.h"
Chris@153 19 #include "base/AudioLevel.h"
Chris@167 20 #include "base/RangeMapper.h"
Chris@195 21 #include "base/RealTime.h"
Chris@376 22 #include "ColourMapper.h"
Chris@376 23 #include "ColourDatabase.h"
Chris@195 24
Chris@195 25 #include "PaintAssistant.h"
Chris@133 26
Chris@133 27 #include <QPainter>
Chris@133 28 #include <QPainterPath>
Chris@316 29 #include <QTextStream>
Chris@316 30
Chris@133 31
Chris@193 32 SliceLayer::SliceLayer() :
Chris@193 33 m_sliceableModel(0),
Chris@1281 34 m_colourMap(int(ColourMapper::Ice)),
Chris@153 35 m_energyScale(dBScale),
Chris@198 36 m_samplingMode(SampleMean),
Chris@1233 37 m_plotStyle(PlotLines),
Chris@193 38 m_binScale(LinearBins),
Chris@153 39 m_normalize(false),
Chris@284 40 m_threshold(0.0),
Chris@284 41 m_initialThreshold(0.0),
Chris@198 42 m_gain(1.0),
Chris@1238 43 m_minbin(0),
Chris@1238 44 m_maxbin(0),
Chris@198 45 m_currentf0(0),
Chris@198 46 m_currentf1(0)
Chris@133 47 {
Chris@133 48 }
Chris@133 49
Chris@193 50 SliceLayer::~SliceLayer()
Chris@133 51 {
Chris@193 52
Chris@133 53 }
Chris@133 54
Chris@133 55 void
Chris@193 56 SliceLayer::setSliceableModel(const Model *model)
Chris@133 57 {
Chris@193 58 const DenseThreeDimensionalModel *sliceable =
Chris@193 59 dynamic_cast<const DenseThreeDimensionalModel *>(model);
Chris@193 60
Chris@193 61 if (model && !sliceable) {
Chris@682 62 cerr << "WARNING: SliceLayer::setSliceableModel(" << model
Chris@682 63 << "): model is not a DenseThreeDimensionalModel" << endl;
Chris@193 64 }
Chris@193 65
Chris@193 66 if (m_sliceableModel == sliceable) return;
Chris@193 67
Chris@193 68 m_sliceableModel = sliceable;
Chris@193 69
Chris@1255 70 if (!m_sliceableModel) return;
Chris@1255 71
Chris@320 72 connectSignals(m_sliceableModel);
Chris@193 73
Chris@1238 74 m_minbin = 0;
Chris@1238 75 m_maxbin = m_sliceableModel->getHeight();
Chris@1238 76
Chris@193 77 emit modelReplaced();
Chris@1238 78 emit layerParametersChanged();
Chris@153 79 }
Chris@153 80
Chris@153 81 void
Chris@193 82 SliceLayer::sliceableModelReplaced(const Model *orig, const Model *replacement)
Chris@153 83 {
Chris@587 84 SVDEBUG << "SliceLayer::sliceableModelReplaced(" << orig << ", " << replacement << ")" << endl;
Chris@153 85
Chris@193 86 if (orig == m_sliceableModel) {
Chris@193 87 setSliceableModel
Chris@193 88 (dynamic_cast<const DenseThreeDimensionalModel *>(replacement));
Chris@153 89 }
Chris@153 90 }
Chris@153 91
Chris@153 92 void
Chris@193 93 SliceLayer::modelAboutToBeDeleted(Model *m)
Chris@153 94 {
Chris@587 95 SVDEBUG << "SliceLayer::modelAboutToBeDeleted(" << m << ")" << endl;
Chris@153 96
Chris@193 97 if (m == m_sliceableModel) {
Chris@193 98 setSliceableModel(0);
Chris@153 99 }
Chris@133 100 }
Chris@133 101
Chris@198 102 QString
Chris@918 103 SliceLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
Chris@198 104 {
Chris@199 105 int minbin, maxbin, range;
Chris@805 106 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range);
Chris@199 107 }
Chris@199 108
Chris@199 109 QString
Chris@918 110 SliceLayer::getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &p,
Chris@805 111 bool includeBinDescription,
Chris@805 112 int &minbin, int &maxbin, int &range) const
Chris@199 113 {
Chris@199 114 minbin = 0;
Chris@199 115 maxbin = 0;
Chris@198 116 if (!m_sliceableModel) return "";
Chris@198 117
Chris@1256 118 minbin = int(getBinForX(v, p.x()));
Chris@1256 119 maxbin = int(getBinForX(v, p.x() + 1));
Chris@1238 120
Chris@198 121 int mh = m_sliceableModel->getHeight();
Chris@199 122 if (minbin >= mh) minbin = mh - 1;
Chris@199 123 if (maxbin >= mh) maxbin = mh - 1;
Chris@199 124 if (minbin < 0) minbin = 0;
Chris@199 125 if (maxbin < 0) maxbin = 0;
Chris@198 126
Chris@906 127 sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate();
Chris@198 128
Chris@906 129 sv_frame_t f0 = m_currentf0;
Chris@906 130 sv_frame_t f1 = m_currentf1;
Chris@198 131
Chris@198 132 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
Chris@198 133 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
Chris@198 134
Chris@906 135 range = int(f1 - f0 + 1);
Chris@198 136
Chris@280 137 QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str());
Chris@280 138
Chris@199 139 if (includeBinDescription) {
Chris@198 140
Chris@1238 141 int i0 = minbin - m_minbin;
Chris@1238 142 int i1 = maxbin - m_minbin;
Chris@1238 143
Chris@906 144 float minvalue = 0.0;
Chris@1238 145 if (in_range_for(m_values, i0)) minvalue = m_values[i0];
Chris@198 146
Chris@199 147 float maxvalue = minvalue;
Chris@1238 148 if (in_range_for(m_values, i1)) maxvalue = m_values[i1];
Chris@1238 149
Chris@199 150 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
Chris@199 151
Chris@199 152 QString binstr;
Chris@199 153 if (maxbin != minbin) {
Chris@199 154 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
Chris@199 155 } else {
Chris@199 156 binstr = QString("%1").arg(minbin+1);
Chris@199 157 }
Chris@199 158
Chris@199 159 QString valuestr;
Chris@199 160 if (maxvalue != minvalue) {
Chris@199 161 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
Chris@199 162 } else {
Chris@199 163 valuestr = QString("%1").arg(minvalue);
Chris@199 164 }
Chris@199 165
Chris@280 166 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)\nBin:\t%5\n%6 value:\t%7")
Chris@199 167 .arg(QString::fromStdString(rt0.toText(true)))
Chris@199 168 .arg(QString::fromStdString(rt1.toText(true)))
Chris@199 169 .arg(range)
Chris@280 170 .arg(rtrangestr)
Chris@199 171 .arg(binstr)
Chris@199 172 .arg(m_samplingMode == NearestSample ? tr("First") :
Chris@199 173 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
Chris@199 174 .arg(valuestr);
Chris@199 175
Chris@199 176 return description;
Chris@199 177
Chris@199 178 } else {
Chris@199 179
Chris@280 180 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)")
Chris@199 181 .arg(QString::fromStdString(rt0.toText(true)))
Chris@199 182 .arg(QString::fromStdString(rt1.toText(true)))
Chris@280 183 .arg(range)
Chris@280 184 .arg(rtrangestr);
Chris@199 185
Chris@199 186 return description;
Chris@199 187 }
Chris@198 188 }
Chris@198 189
Chris@906 190 double
Chris@1238 191 SliceLayer::getXForBin(const LayerGeometryProvider *v, double bin) const
Chris@198 192 {
Chris@906 193 double x = 0;
Chris@198 194
Chris@1238 195 bin -= m_minbin;
Chris@1238 196 if (bin < 0) bin = 0;
Chris@1238 197
Chris@1238 198 double count = m_maxbin - m_minbin;
Chris@1238 199 if (count < 0) count = 0;
Chris@1238 200
Chris@1238 201 int pw = v->getPaintWidth();
Chris@1238 202 int origin = m_xorigins[v->getId()];
Chris@1238 203 int w = pw - origin;
Chris@1238 204 if (w < 1) w = 1;
Chris@1238 205
Chris@198 206 switch (m_binScale) {
Chris@198 207
Chris@198 208 case LinearBins:
Chris@906 209 x = (w * bin) / count;
Chris@198 210 break;
Chris@198 211
Chris@198 212 case LogBins:
Chris@1281 213 // The 0.8 here is an awkward compromise. Our x-coord is
Chris@1281 214 // proportional to log of bin number, with the x-coord "of a
Chris@1281 215 // bin" being that of the left edge of the bin range. We can't
Chris@1281 216 // start counting bins from 0, as that would give us x = -Inf
Chris@1281 217 // and hide the first bin entirely. But if we start from 1, we
Chris@1281 218 // are giving a lot of space to the first bin, which in most
Chris@1281 219 // display modes won't be used because the "point" location
Chris@1281 220 // for that bin is in the middle of it. Yet in some modes
Chris@1281 221 // we'll still want it. A compromise is to count our first bin
Chris@1281 222 // as "a bit less than 1", so that most of it is visible but a
Chris@1281 223 // bit is tactfully cropped at the left edge so it doesn't
Chris@1281 224 // take up so much space.
Chris@1281 225 x = (w * log10(bin + 0.8)) / log10(count + 0.8);
Chris@198 226 break;
Chris@198 227
Chris@198 228 case InvertedLogBins:
Chris@906 229 x = w - (w * log10(count - bin - 1)) / log10(count);
Chris@198 230 break;
Chris@198 231 }
Chris@1238 232
Chris@1238 233 return x + origin;
Chris@198 234 }
Chris@198 235
Chris@1238 236 double
Chris@1238 237 SliceLayer::getBinForX(const LayerGeometryProvider *v, double x) const
Chris@198 238 {
Chris@1238 239 double bin = 0;
Chris@198 240
Chris@1238 241 double count = m_maxbin - m_minbin;
Chris@1238 242 if (count < 0) count = 0;
Chris@1238 243
Chris@1238 244 int pw = v->getPaintWidth();
Chris@1238 245 int origin = m_xorigins[v->getId()];
Chris@1238 246
Chris@1238 247 int w = pw - origin;
Chris@1238 248 if (w < 1) w = 1;
Chris@1238 249
Chris@1238 250 x = x - origin;
Chris@1238 251 if (x < 0) x = 0;
Chris@1256 252
Chris@1256 253 double eps = 1e-10;
Chris@1238 254
Chris@198 255 switch (m_binScale) {
Chris@198 256
Chris@198 257 case LinearBins:
Chris@1256 258 bin = (x * count) / w + eps;
Chris@198 259 break;
Chris@198 260
Chris@198 261 case LogBins:
Chris@1281 262 // See comment in getXForBin
Chris@1281 263 bin = pow(10.0, (x * log10(count + 0.8)) / w) - 0.8 + eps;
Chris@198 264 break;
Chris@198 265
Chris@198 266 case InvertedLogBins:
Chris@1256 267 bin = count + 1 - pow(10.0, (log10(count) * (w - x)) / double(w)) + eps;
Chris@198 268 break;
Chris@198 269 }
Chris@198 270
Chris@1238 271 return bin + m_minbin;
Chris@198 272 }
Chris@198 273
Chris@906 274 double
Chris@1238 275 SliceLayer::getYForValue(const LayerGeometryProvider *v, double value, double &norm) const
Chris@274 276 {
Chris@906 277 norm = 0.0;
Chris@274 278
Chris@1238 279 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return 0;
Chris@274 280
Chris@274 281 value *= m_gain;
Chris@274 282
Chris@1238 283 int yorigin = m_yorigins[v->getId()];
Chris@1238 284 int h = m_heights[v->getId()];
Chris@906 285 double thresh = getThresholdDb();
Chris@274 286
Chris@906 287 double y = 0.0;
Chris@274 288
Chris@274 289 if (h <= 0) return y;
Chris@274 290
Chris@274 291 switch (m_energyScale) {
Chris@274 292
Chris@274 293 case dBScale:
Chris@274 294 {
Chris@906 295 double db = thresh;
Chris@906 296 if (value > 0.0) db = 10.0 * log10(fabs(value));
Chris@274 297 if (db < thresh) db = thresh;
Chris@274 298 norm = (db - thresh) / -thresh;
Chris@906 299 y = yorigin - (double(h) * norm);
Chris@274 300 break;
Chris@274 301 }
Chris@274 302
Chris@274 303 case MeterScale:
Chris@274 304 y = AudioLevel::multiplier_to_preview(value, h);
Chris@906 305 norm = double(y) / double(h);
Chris@274 306 y = yorigin - y;
Chris@274 307 break;
Chris@274 308
Chris@538 309 case AbsoluteScale:
Chris@906 310 value = fabs(value);
Chris@1264 311 #if (__GNUC__ >= 7)
Chris@1263 312 __attribute__ ((fallthrough));
Chris@1263 313 #endif
Chris@538 314
Chris@805 315 case LinearScale:
Chris@274 316 default:
Chris@538 317 norm = (value - m_threshold);
Chris@284 318 if (norm < 0) norm = 0;
Chris@906 319 y = yorigin - (double(h) * norm);
Chris@274 320 break;
Chris@274 321 }
Chris@274 322
Chris@274 323 return y;
Chris@274 324 }
Chris@274 325
Chris@906 326 double
Chris@1238 327 SliceLayer::getValueForY(const LayerGeometryProvider *v, double y) const
Chris@274 328 {
Chris@906 329 double value = 0.0;
Chris@274 330
Chris@1238 331 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return value;
Chris@274 332
Chris@1238 333 int yorigin = m_yorigins[v->getId()];
Chris@1238 334 int h = m_heights[v->getId()];
Chris@906 335 double thresh = getThresholdDb();
Chris@274 336
Chris@274 337 if (h <= 0) return value;
Chris@274 338
Chris@274 339 y = yorigin - y;
Chris@274 340
Chris@274 341 switch (m_energyScale) {
Chris@274 342
Chris@274 343 case dBScale:
Chris@274 344 {
Chris@906 345 double db = ((y / h) * -thresh) + thresh;
Chris@906 346 value = pow(10.0, db/10.0);
Chris@274 347 break;
Chris@274 348 }
Chris@274 349
Chris@274 350 case MeterScale:
Chris@906 351 value = AudioLevel::preview_to_multiplier(int(lrint(y)), h);
Chris@274 352 break;
Chris@805 353
Chris@805 354 case LinearScale:
Chris@805 355 case AbsoluteScale:
Chris@274 356 default:
Chris@284 357 value = y / h + m_threshold;
Chris@274 358 }
Chris@274 359
Chris@274 360 return value / m_gain;
Chris@274 361 }
Chris@274 362
Chris@133 363 void
Chris@916 364 SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
Chris@133 365 {
Chris@254 366 if (!m_sliceableModel || !m_sliceableModel->isOK() ||
Chris@254 367 !m_sliceableModel->isReady()) return;
Chris@133 368
Chris@195 369 paint.save();
Chris@195 370 paint.setRenderHint(QPainter::Antialiasing, false);
Chris@538 371 paint.setBrush(Qt::NoBrush);
Chris@195 372
Chris@195 373 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) {
Chris@195 374 if (!m_scalePoints.empty()) {
Chris@195 375 paint.setPen(QColor(240, 240, 240)); //!!! and dark background?
Chris@805 376 for (int i = 0; i < (int)m_scalePoints.size(); ++i) {
Chris@195 377 paint.drawLine(0, m_scalePoints[i], rect.width(), m_scalePoints[i]);
Chris@195 378 }
Chris@195 379 }
Chris@195 380 }
Chris@195 381
Chris@1233 382 if (m_plotStyle == PlotBlocks) {
Chris@1233 383 // Must use actual zero-width pen, too slow otherwise
Chris@1233 384 paint.setPen(QPen(getBaseQColor(), 0));
Chris@1233 385 } else {
Chris@1233 386 paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
Chris@1233 387 }
Chris@195 388
Chris@607 389 int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
Chris@1238 390 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription
Chris@133 391
Chris@918 392 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 7;
Chris@195 393 int h = yorigin - paint.fontMetrics().height() - 8;
Chris@133 394
Chris@1238 395 m_yorigins[v->getId()] = yorigin; // for getYForValue etc
Chris@1238 396 m_heights[v->getId()] = h;
Chris@274 397
Chris@274 398 if (h <= 0) return;
Chris@274 399
Chris@133 400 QPainterPath path;
Chris@133 401
Chris@805 402 int mh = m_sliceableModel->getHeight();
Chris@1238 403 int bin0 = 0;
Chris@133 404
Chris@1238 405 if (m_maxbin > m_minbin) {
Chris@1238 406 mh = m_maxbin - m_minbin;
Chris@1238 407 bin0 = m_minbin;
Chris@1238 408 }
Chris@1238 409
Chris@193 410 int divisor = 0;
Chris@193 411
Chris@198 412 m_values.clear();
Chris@805 413 for (int bin = 0; bin < mh; ++bin) {
Chris@906 414 m_values.push_back(0.0);
Chris@193 415 }
Chris@193 416
Chris@906 417 sv_frame_t f0 = v->getCentreFrame();
Chris@193 418 int f0x = v->getXForFrame(f0);
Chris@195 419 f0 = v->getFrameForX(f0x);
Chris@906 420 sv_frame_t f1 = v->getFrameForX(f0x + 1);
Chris@195 421 if (f1 > f0) --f1;
Chris@193 422
Chris@682 423 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
Chris@274 424
Chris@805 425 int res = m_sliceableModel->getResolution();
Chris@906 426 int col0 = int(f0 / res);
Chris@805 427 int col1 = col0;
Chris@906 428 if (m_samplingMode != NearestSample) col1 = int(f1 / res);
Chris@274 429 f0 = col0 * res;
Chris@274 430 f1 = (col1 + 1) * res - 1;
Chris@274 431
Chris@682 432 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl;
Chris@193 433
Chris@198 434 m_currentf0 = f0;
Chris@198 435 m_currentf1 = f1;
Chris@198 436
Chris@254 437 BiasCurve curve;
Chris@254 438 getBiasCurve(curve);
Chris@906 439 int cs = int(curve.size());
Chris@254 440
Chris@805 441 for (int col = col0; col <= col1; ++col) {
Chris@805 442 for (int bin = 0; bin < mh; ++bin) {
Chris@1238 443 float value = m_sliceableModel->getValueAt(col, bin0 + bin);
Chris@254 444 if (bin < cs) value *= curve[bin];
Chris@193 445 if (m_samplingMode == SamplePeak) {
Chris@198 446 if (value > m_values[bin]) m_values[bin] = value;
Chris@193 447 } else {
Chris@198 448 m_values[bin] += value;
Chris@193 449 }
Chris@153 450 }
Chris@193 451 ++divisor;
Chris@193 452 }
Chris@193 453
Chris@906 454 float max = 0.0;
Chris@805 455 for (int bin = 0; bin < mh; ++bin) {
Chris@847 456 if (m_samplingMode == SampleMean && divisor > 0) {
Chris@906 457 m_values[bin] /= float(divisor);
Chris@847 458 }
Chris@198 459 if (m_values[bin] > max) max = m_values[bin];
Chris@193 460 }
Chris@906 461 if (max != 0.0 && m_normalize) {
Chris@805 462 for (int bin = 0; bin < mh; ++bin) {
Chris@198 463 m_values[bin] /= max;
Chris@193 464 }
Chris@193 465 }
Chris@193 466
Chris@1238 467 double nx = getXForBin(v, bin0);
Chris@193 468
Chris@197 469 ColourMapper mapper(m_colourMap, 0, 1);
Chris@197 470
Chris@805 471 for (int bin = 0; bin < mh; ++bin) {
Chris@193 472
Chris@906 473 double x = nx;
Chris@1238 474 nx = getXForBin(v, bin + bin0 + 1);
Chris@193 475
Chris@906 476 double value = m_values[bin];
Chris@906 477 double norm = 0.0;
Chris@1238 478 double y = getYForValue(v, value, norm);
Chris@133 479
Chris@193 480 if (m_plotStyle == PlotLines) {
Chris@193 481
Chris@193 482 if (bin == 0) {
Chris@1233 483 path.moveTo((x + nx) / 2, y);
Chris@193 484 } else {
Chris@1233 485 path.lineTo((x + nx) / 2, y);
Chris@193 486 }
Chris@193 487
Chris@193 488 } else if (m_plotStyle == PlotSteps) {
Chris@193 489
Chris@193 490 if (bin == 0) {
Chris@193 491 path.moveTo(x, y);
Chris@193 492 } else {
Chris@193 493 path.lineTo(x, y);
Chris@193 494 }
Chris@193 495 path.lineTo(nx, y);
Chris@193 496
Chris@193 497 } else if (m_plotStyle == PlotBlocks) {
Chris@193 498
Chris@193 499 path.moveTo(x, yorigin);
Chris@133 500 path.lineTo(x, y);
Chris@193 501 path.lineTo(nx, y);
Chris@193 502 path.lineTo(nx, yorigin);
Chris@193 503 path.lineTo(x, yorigin);
Chris@197 504
Chris@197 505 } else if (m_plotStyle == PlotFilledBlocks) {
Chris@197 506
Chris@197 507 paint.fillRect(QRectF(x, y, nx - x, yorigin - y), mapper.map(norm));
Chris@133 508 }
Chris@193 509
Chris@133 510 }
Chris@133 511
Chris@197 512 if (m_plotStyle != PlotFilledBlocks) {
Chris@197 513 paint.drawPath(path);
Chris@197 514 }
Chris@133 515 paint.restore();
Chris@195 516 }
Chris@195 517
Chris@195 518 int
Chris@918 519 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
Chris@195 520 {
Chris@1238 521 int width;
Chris@538 522 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
Chris@1266 523 width = std::max(paint.fontMetrics().width("0.0") + 13,
Chris@1238 524 paint.fontMetrics().width("x10-10"));
Chris@195 525 } else {
Chris@1238 526 width = std::max(paint.fontMetrics().width(tr("0dB")),
Chris@1238 527 paint.fontMetrics().width(tr("-Inf"))) + 13;
Chris@195 528 }
Chris@1238 529 return width;
Chris@195 530 }
Chris@195 531
Chris@195 532 void
Chris@918 533 SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
Chris@195 534 {
Chris@906 535 double thresh = m_threshold;
Chris@538 536 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
Chris@284 537 thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
Chris@195 538 }
Chris@195 539
Chris@195 540 // int h = (rect.height() * 3) / 4;
Chris@195 541 // int y = (rect.height() / 2) - (h / 2);
Chris@195 542
Chris@918 543 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 6;
Chris@195 544 int h = yorigin - paint.fontMetrics().height() - 8;
Chris@195 545 if (h < 0) return;
Chris@195 546
Chris@195 547 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
Chris@195 548
Chris@220 549 int mult = 1;
Chris@220 550
Chris@195 551 PaintAssistant::paintVerticalLevelScale
Chris@195 552 (paint, actual, thresh, 1.0 / m_gain,
Chris@195 553 PaintAssistant::Scale(m_energyScale),
Chris@220 554 mult,
Chris@195 555 const_cast<std::vector<int> *>(&m_scalePoints));
Chris@220 556
Chris@220 557 if (mult != 1 && mult != 0) {
Chris@906 558 int log = int(lrint(log10(mult)));
Chris@220 559 QString a = tr("x10");
Chris@220 560 QString b = QString("%1").arg(-log);
Chris@220 561 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a);
Chris@220 562 paint.drawText(3 + paint.fontMetrics().width(a),
Chris@220 563 3 + paint.fontMetrics().ascent(), b);
Chris@220 564 }
Chris@133 565 }
Chris@133 566
Chris@1281 567 bool
Chris@1281 568 SliceLayer::hasLightBackground() const
Chris@1281 569 {
Chris@1281 570 if (usesSolidColour()) {
Chris@1281 571 ColourMapper mapper(m_colourMap, 0, 1);
Chris@1281 572 return mapper.hasLightBackground();
Chris@1281 573 } else {
Chris@1281 574 return SingleColourLayer::hasLightBackground();
Chris@1281 575 }
Chris@1281 576 }
Chris@1281 577
Chris@153 578 Layer::PropertyList
Chris@193 579 SliceLayer::getProperties() const
Chris@153 580 {
Chris@287 581 PropertyList list = SingleColourLayer::getProperties();
Chris@538 582 list.push_back("Bin Scale");
Chris@193 583 list.push_back("Plot Type");
Chris@153 584 list.push_back("Scale");
Chris@153 585 list.push_back("Normalize");
Chris@284 586 list.push_back("Threshold");
Chris@153 587 list.push_back("Gain");
Chris@153 588
Chris@153 589 return list;
Chris@153 590 }
Chris@153 591
Chris@153 592 QString
Chris@193 593 SliceLayer::getPropertyLabel(const PropertyName &name) const
Chris@153 594 {
Chris@193 595 if (name == "Plot Type") return tr("Plot Type");
Chris@290 596 if (name == "Scale") return tr("Scale");
Chris@153 597 if (name == "Normalize") return tr("Normalize");
Chris@284 598 if (name == "Threshold") return tr("Threshold");
Chris@153 599 if (name == "Gain") return tr("Gain");
Chris@193 600 if (name == "Sampling Mode") return tr("Sampling Mode");
Chris@538 601 if (name == "Bin Scale") return tr("Bin Scale");
Chris@287 602 return SingleColourLayer::getPropertyLabel(name);
Chris@153 603 }
Chris@153 604
Chris@335 605 QString
Chris@335 606 SliceLayer::getPropertyIconName(const PropertyName &name) const
Chris@335 607 {
Chris@335 608 if (name == "Normalize") return "normalise";
Chris@335 609 return "";
Chris@335 610 }
Chris@335 611
Chris@153 612 Layer::PropertyType
Chris@193 613 SliceLayer::getPropertyType(const PropertyName &name) const
Chris@153 614 {
Chris@153 615 if (name == "Gain") return RangeProperty;
Chris@153 616 if (name == "Normalize") return ToggleProperty;
Chris@284 617 if (name == "Threshold") return RangeProperty;
Chris@287 618 if (name == "Plot Type") return ValueProperty;
Chris@290 619 if (name == "Scale") return ValueProperty;
Chris@287 620 if (name == "Sampling Mode") return ValueProperty;
Chris@287 621 if (name == "Bin Scale") return ValueProperty;
Chris@1281 622 if (name == "Colour" && usesSolidColour()) return ColourMapProperty;
Chris@287 623 return SingleColourLayer::getPropertyType(name);
Chris@153 624 }
Chris@153 625
Chris@153 626 QString
Chris@193 627 SliceLayer::getPropertyGroupName(const PropertyName &name) const
Chris@153 628 {
Chris@153 629 if (name == "Scale" ||
Chris@153 630 name == "Normalize" ||
Chris@193 631 name == "Sampling Mode" ||
Chris@284 632 name == "Threshold" ||
Chris@193 633 name == "Gain") return tr("Scale");
Chris@193 634 if (name == "Plot Type" ||
Chris@538 635 name == "Bin Scale") return tr("Bins");
Chris@287 636 return SingleColourLayer::getPropertyGroupName(name);
Chris@153 637 }
Chris@153 638
Chris@153 639 int
Chris@193 640 SliceLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 641 int *min, int *max, int *deflt) const
Chris@153 642 {
Chris@216 643 int val = 0;
Chris@153 644
Chris@216 645 int garbage0, garbage1, garbage2;
Chris@153 646 if (!min) min = &garbage0;
Chris@153 647 if (!max) max = &garbage1;
Chris@248 648 if (!deflt) deflt = &garbage2;
Chris@153 649
Chris@153 650 if (name == "Gain") {
Chris@153 651
Chris@1266 652 *min = -50;
Chris@1266 653 *max = 50;
Chris@216 654 *deflt = 0;
Chris@153 655
Chris@1238 656 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
Chris@193 657
Chris@1266 658 val = int(lrint(log10(m_gain) * 20.0));
Chris@1266 659 if (val < *min) val = *min;
Chris@1266 660 if (val > *max) val = *max;
Chris@153 661
Chris@284 662 } else if (name == "Threshold") {
Chris@284 663
Chris@1266 664 *min = -80;
Chris@1266 665 *max = 0;
Chris@284 666
Chris@906 667 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
Chris@1266 668 if (*deflt < *min) *deflt = *min;
Chris@1266 669 if (*deflt > *max) *deflt = *max;
Chris@284 670
Chris@1266 671 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
Chris@1266 672 if (val < *min) val = *min;
Chris@1266 673 if (val > *max) val = *max;
Chris@284 674
Chris@153 675 } else if (name == "Normalize") {
Chris@1266 676
Chris@1266 677 val = (m_normalize ? 1 : 0);
Chris@216 678 *deflt = 0;
Chris@153 679
Chris@1281 680 } else if (name == "Colour" && usesSolidColour()) {
Chris@197 681
Chris@287 682 *min = 0;
Chris@287 683 *max = ColourMapper::getColourMapCount() - 1;
Chris@1281 684 *deflt = int(ColourMapper::Ice);
Chris@287 685
Chris@287 686 val = m_colourMap;
Chris@153 687
Chris@153 688 } else if (name == "Scale") {
Chris@153 689
Chris@1266 690 *min = 0;
Chris@1266 691 *max = 3;
Chris@216 692 *deflt = (int)dBScale;
Chris@153 693
Chris@1266 694 val = (int)m_energyScale;
Chris@153 695
Chris@193 696 } else if (name == "Sampling Mode") {
Chris@153 697
Chris@1266 698 *min = 0;
Chris@1266 699 *max = 2;
Chris@216 700 *deflt = (int)SampleMean;
Chris@193 701
Chris@1266 702 val = (int)m_samplingMode;
Chris@153 703
Chris@193 704 } else if (name == "Plot Type") {
Chris@193 705
Chris@193 706 *min = 0;
Chris@197 707 *max = 3;
Chris@216 708 *deflt = (int)PlotSteps;
Chris@193 709
Chris@216 710 val = (int)m_plotStyle;
Chris@193 711
Chris@193 712 } else if (name == "Bin Scale") {
Chris@193 713
Chris@193 714 *min = 0;
Chris@198 715 *max = 2;
Chris@216 716 *deflt = (int)LinearBins;
Chris@198 717 // *max = 1; // I don't think we really do want to offer inverted log
Chris@193 718
Chris@216 719 val = (int)m_binScale;
Chris@193 720
Chris@153 721 } else {
Chris@1266 722 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@153 723 }
Chris@153 724
Chris@216 725 return val;
Chris@153 726 }
Chris@153 727
Chris@153 728 QString
Chris@193 729 SliceLayer::getPropertyValueLabel(const PropertyName &name,
Chris@1281 730 int value) const
Chris@153 731 {
Chris@1281 732 if (name == "Colour" && usesSolidColour()) {
Chris@287 733 return ColourMapper::getColourMapName(value);
Chris@153 734 }
Chris@153 735 if (name == "Scale") {
Chris@1266 736 switch (value) {
Chris@1266 737 default:
Chris@1266 738 case 0: return tr("Linear");
Chris@1266 739 case 1: return tr("Meter");
Chris@1266 740 case 2: return tr("Log");
Chris@1266 741 case 3: return tr("Absolute");
Chris@1266 742 }
Chris@153 743 }
Chris@193 744 if (name == "Sampling Mode") {
Chris@1266 745 switch (value) {
Chris@1266 746 default:
Chris@1266 747 case 0: return tr("Any");
Chris@1266 748 case 1: return tr("Mean");
Chris@1266 749 case 2: return tr("Peak");
Chris@1266 750 }
Chris@193 751 }
Chris@193 752 if (name == "Plot Type") {
Chris@1266 753 switch (value) {
Chris@1266 754 default:
Chris@1266 755 case 0: return tr("Lines");
Chris@1266 756 case 1: return tr("Steps");
Chris@1266 757 case 2: return tr("Blocks");
Chris@1266 758 case 3: return tr("Colours");
Chris@1266 759 }
Chris@193 760 }
Chris@193 761 if (name == "Bin Scale") {
Chris@1266 762 switch (value) {
Chris@1266 763 default:
Chris@1266 764 case 0: return tr("Linear");
Chris@1266 765 case 1: return tr("Log");
Chris@1266 766 case 2: return tr("Rev Log");
Chris@1266 767 }
Chris@153 768 }
Chris@287 769 return SingleColourLayer::getPropertyValueLabel(name, value);
Chris@153 770 }
Chris@153 771
Chris@167 772 RangeMapper *
Chris@193 773 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@167 774 {
Chris@167 775 if (name == "Gain") {
Chris@167 776 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
Chris@167 777 }
Chris@284 778 if (name == "Threshold") {
Chris@284 779 return new LinearRangeMapper(-80, 0, -80, 0, tr("dB"));
Chris@284 780 }
Chris@287 781 return SingleColourLayer::getNewPropertyRangeMapper(name);
Chris@167 782 }
Chris@167 783
Chris@133 784 void
Chris@193 785 SliceLayer::setProperty(const PropertyName &name, int value)
Chris@133 786 {
Chris@153 787 if (name == "Gain") {
Chris@1266 788 setGain(powf(10, float(value)/20.0f));
Chris@284 789 } else if (name == "Threshold") {
Chris@1266 790 if (value == -80) setThreshold(0.0f);
Chris@1266 791 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
Chris@1281 792 } else if (name == "Colour" && usesSolidColour()) {
Chris@287 793 setFillColourMap(value);
Chris@153 794 } else if (name == "Scale") {
Chris@1266 795 switch (value) {
Chris@1266 796 default:
Chris@1266 797 case 0: setEnergyScale(LinearScale); break;
Chris@1266 798 case 1: setEnergyScale(MeterScale); break;
Chris@1266 799 case 2: setEnergyScale(dBScale); break;
Chris@1266 800 case 3: setEnergyScale(AbsoluteScale); break;
Chris@1266 801 }
Chris@193 802 } else if (name == "Plot Type") {
Chris@1266 803 setPlotStyle(PlotStyle(value));
Chris@193 804 } else if (name == "Sampling Mode") {
Chris@1266 805 switch (value) {
Chris@1266 806 default:
Chris@1266 807 case 0: setSamplingMode(NearestSample); break;
Chris@1266 808 case 1: setSamplingMode(SampleMean); break;
Chris@1266 809 case 2: setSamplingMode(SamplePeak); break;
Chris@1266 810 }
Chris@193 811 } else if (name == "Bin Scale") {
Chris@1266 812 switch (value) {
Chris@1266 813 default:
Chris@1266 814 case 0: setBinScale(LinearBins); break;
Chris@1266 815 case 1: setBinScale(LogBins); break;
Chris@1266 816 case 2: setBinScale(InvertedLogBins); break;
Chris@1266 817 }
Chris@153 818 } else if (name == "Normalize") {
Chris@1266 819 setNormalize(value ? true : false);
Chris@287 820 } else {
Chris@287 821 SingleColourLayer::setProperty(name, value);
Chris@153 822 }
Chris@153 823 }
Chris@153 824
Chris@153 825 void
Chris@197 826 SliceLayer::setFillColourMap(int map)
Chris@197 827 {
Chris@197 828 if (m_colourMap == map) return;
Chris@197 829 m_colourMap = map;
Chris@197 830 emit layerParametersChanged();
Chris@197 831 }
Chris@197 832
Chris@197 833 void
Chris@193 834 SliceLayer::setEnergyScale(EnergyScale scale)
Chris@153 835 {
Chris@153 836 if (m_energyScale == scale) return;
Chris@153 837 m_energyScale = scale;
Chris@153 838 emit layerParametersChanged();
Chris@153 839 }
Chris@153 840
Chris@153 841 void
Chris@193 842 SliceLayer::setSamplingMode(SamplingMode mode)
Chris@153 843 {
Chris@193 844 if (m_samplingMode == mode) return;
Chris@193 845 m_samplingMode = mode;
Chris@153 846 emit layerParametersChanged();
Chris@153 847 }
Chris@153 848
Chris@153 849 void
Chris@193 850 SliceLayer::setPlotStyle(PlotStyle style)
Chris@153 851 {
Chris@193 852 if (m_plotStyle == style) return;
Chris@197 853 bool colourTypeChanged = (style == PlotFilledBlocks ||
Chris@197 854 m_plotStyle == PlotFilledBlocks);
Chris@193 855 m_plotStyle = style;
Chris@197 856 if (colourTypeChanged) {
Chris@197 857 emit layerParameterRangesChanged();
Chris@197 858 }
Chris@153 859 emit layerParametersChanged();
Chris@153 860 }
Chris@153 861
Chris@153 862 void
Chris@193 863 SliceLayer::setBinScale(BinScale scale)
Chris@153 864 {
Chris@193 865 if (m_binScale == scale) return;
Chris@193 866 m_binScale = scale;
Chris@153 867 emit layerParametersChanged();
Chris@153 868 }
Chris@153 869
Chris@153 870 void
Chris@193 871 SliceLayer::setNormalize(bool n)
Chris@153 872 {
Chris@153 873 if (m_normalize == n) return;
Chris@153 874 m_normalize = n;
Chris@153 875 emit layerParametersChanged();
Chris@153 876 }
Chris@153 877
Chris@153 878 void
Chris@284 879 SliceLayer::setThreshold(float thresh)
Chris@284 880 {
Chris@284 881 if (m_threshold == thresh) return;
Chris@284 882 m_threshold = thresh;
Chris@284 883 emit layerParametersChanged();
Chris@284 884 }
Chris@284 885
Chris@284 886 void
Chris@193 887 SliceLayer::setGain(float gain)
Chris@153 888 {
Chris@153 889 if (m_gain == gain) return;
Chris@153 890 m_gain = gain;
Chris@153 891 emit layerParametersChanged();
Chris@153 892 }
Chris@153 893
Chris@284 894 float
Chris@284 895 SliceLayer::getThresholdDb() const
Chris@284 896 {
Chris@284 897 if (m_threshold == 0.0) return -80.f;
Chris@906 898 float db = float(AudioLevel::multiplier_to_dB(m_threshold));
Chris@284 899 return db;
Chris@284 900 }
Chris@284 901
Chris@287 902 int
Chris@287 903 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose)
Chris@287 904 {
Chris@287 905 impose = false;
Chris@287 906 return ColourDatabase::getInstance()->getColourIndex
Chris@287 907 (QString(darkbg ? "Bright Blue" : "Blue"));
Chris@287 908 }
Chris@287 909
Chris@316 910 void
Chris@316 911 SliceLayer::toXml(QTextStream &stream,
Chris@316 912 QString indent, QString extraAttributes) const
Chris@153 913 {
Chris@153 914 QString s;
Chris@153 915
Chris@287 916 s += QString("colourScheme=\"%1\" "
Chris@1266 917 "energyScale=\"%2\" "
Chris@287 918 "samplingMode=\"%3\" "
Chris@598 919 "plotStyle=\"%4\" "
Chris@598 920 "binScale=\"%5\" "
Chris@598 921 "gain=\"%6\" "
Chris@598 922 "threshold=\"%7\" "
Chris@1238 923 "normalize=\"%8\" %9")
Chris@197 924 .arg(m_colourMap)
Chris@1266 925 .arg(m_energyScale)
Chris@193 926 .arg(m_samplingMode)
Chris@598 927 .arg(m_plotStyle)
Chris@598 928 .arg(m_binScale)
Chris@153 929 .arg(m_gain)
Chris@598 930 .arg(m_threshold)
Chris@1238 931 .arg(m_normalize ? "true" : "false")
Chris@1238 932 .arg(QString("minbin=\"%1\" "
Chris@1238 933 "maxbin=\"%2\"")
Chris@1238 934 .arg(m_minbin)
Chris@1238 935 .arg(m_maxbin));
Chris@153 936
Chris@316 937 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
Chris@153 938 }
Chris@153 939
Chris@153 940 void
Chris@193 941 SliceLayer::setProperties(const QXmlAttributes &attributes)
Chris@153 942 {
Chris@153 943 bool ok = false;
Chris@153 944
Chris@287 945 SingleColourLayer::setProperties(attributes);
Chris@153 946
Chris@153 947 EnergyScale scale = (EnergyScale)
Chris@1266 948 attributes.value("energyScale").toInt(&ok);
Chris@153 949 if (ok) setEnergyScale(scale);
Chris@153 950
Chris@193 951 SamplingMode mode = (SamplingMode)
Chris@1266 952 attributes.value("samplingMode").toInt(&ok);
Chris@193 953 if (ok) setSamplingMode(mode);
Chris@153 954
Chris@197 955 int colourMap = attributes.value("colourScheme").toInt(&ok);
Chris@197 956 if (ok) setFillColourMap(colourMap);
Chris@197 957
Chris@598 958 PlotStyle s = (PlotStyle)
Chris@1266 959 attributes.value("plotStyle").toInt(&ok);
Chris@598 960 if (ok) setPlotStyle(s);
Chris@598 961
Chris@598 962 BinScale b = (BinScale)
Chris@1266 963 attributes.value("binScale").toInt(&ok);
Chris@598 964 if (ok) setBinScale(b);
Chris@598 965
Chris@153 966 float gain = attributes.value("gain").toFloat(&ok);
Chris@153 967 if (ok) setGain(gain);
Chris@153 968
Chris@598 969 float threshold = attributes.value("threshold").toFloat(&ok);
Chris@598 970 if (ok) setThreshold(threshold);
Chris@598 971
Chris@153 972 bool normalize = (attributes.value("normalize").trimmed() == "true");
Chris@153 973 setNormalize(normalize);
Chris@1238 974
Chris@1238 975 bool alsoOk = false;
Chris@1238 976
Chris@1238 977 float min = attributes.value("minbin").toFloat(&ok);
Chris@1238 978 float max = attributes.value("maxbin").toFloat(&alsoOk);
Chris@1238 979 if (ok && alsoOk) setDisplayExtents(min, max);
Chris@133 980 }
Chris@133 981
Chris@133 982 bool
Chris@1238 983 SliceLayer::getValueExtents(double &min, double &max, bool &logarithmic,
Chris@1238 984 QString &unit) const
Chris@133 985 {
Chris@1238 986 if (!m_sliceableModel) return false;
Chris@1238 987
Chris@1238 988 min = 0;
Chris@1238 989 max = double(m_sliceableModel->getHeight());
Chris@1238 990
Chris@1238 991 logarithmic = (m_binScale == BinScale::LogBins);
Chris@1238 992 unit = "";
Chris@1238 993
Chris@1238 994 return true;
Chris@133 995 }
Chris@133 996
Chris@1238 997 bool
Chris@1238 998 SliceLayer::getDisplayExtents(double &min, double &max) const
Chris@1238 999 {
Chris@1238 1000 if (!m_sliceableModel) return false;
Chris@1238 1001
Chris@1238 1002 double hmax = double(m_sliceableModel->getHeight());
Chris@1238 1003
Chris@1238 1004 min = m_minbin;
Chris@1238 1005 max = m_maxbin;
Chris@1238 1006 if (max <= min) {
Chris@1238 1007 min = 0;
Chris@1238 1008 max = hmax;
Chris@1238 1009 }
Chris@1238 1010 if (min < 0) min = 0;
Chris@1238 1011 if (max > hmax) max = hmax;
Chris@1238 1012
Chris@1238 1013 return true;
Chris@1238 1014 }
Chris@1238 1015
Chris@1238 1016 bool
Chris@1238 1017 SliceLayer::setDisplayExtents(double min, double max)
Chris@1238 1018 {
Chris@1238 1019 if (!m_sliceableModel) return false;
Chris@1238 1020
Chris@1238 1021 m_minbin = int(lrint(min));
Chris@1238 1022 m_maxbin = int(lrint(max));
Chris@1238 1023
Chris@1238 1024 emit layerParametersChanged();
Chris@1238 1025 return true;
Chris@1238 1026 }
Chris@1238 1027
Chris@1238 1028 int
Chris@1238 1029 SliceLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@1238 1030 {
Chris@1238 1031 if (!m_sliceableModel) return 0;
Chris@1238 1032
Chris@1238 1033 defaultStep = 0;
Chris@1238 1034 int h = m_sliceableModel->getHeight();
Chris@1238 1035 return h;
Chris@1238 1036 }
Chris@1238 1037
Chris@1238 1038 int
Chris@1238 1039 SliceLayer::getCurrentVerticalZoomStep() const
Chris@1238 1040 {
Chris@1238 1041 if (!m_sliceableModel) return 0;
Chris@1238 1042
Chris@1238 1043 double min, max;
Chris@1238 1044 getDisplayExtents(min, max);
Chris@1238 1045 return m_sliceableModel->getHeight() - int(lrint(max - min));
Chris@1238 1046 }
Chris@1238 1047
Chris@1238 1048 void
Chris@1238 1049 SliceLayer::setVerticalZoomStep(int step)
Chris@1238 1050 {
Chris@1238 1051 if (!m_sliceableModel) return;
Chris@1238 1052
Chris@1238 1053 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): before: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
Chris@1238 1054
Chris@1238 1055 int dist = m_sliceableModel->getHeight() - step;
Chris@1238 1056 if (dist < 1) dist = 1;
Chris@1238 1057 double centre = m_minbin + (m_maxbin - m_minbin) / 2.0;
Chris@1238 1058 m_minbin = int(lrint(centre - dist/2.0));
Chris@1238 1059 if (m_minbin < 0) m_minbin = 0;
Chris@1238 1060 m_maxbin = m_minbin + dist;
Chris@1238 1061 if (m_maxbin > m_sliceableModel->getHeight()) m_maxbin = m_sliceableModel->getHeight();
Chris@1238 1062
Chris@1238 1063 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): after: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
Chris@1238 1064
Chris@1238 1065 emit layerParametersChanged();
Chris@1238 1066 }
Chris@1238 1067
Chris@1238 1068 RangeMapper *
Chris@1238 1069 SliceLayer::getNewVerticalZoomRangeMapper() const
Chris@1238 1070 {
Chris@1238 1071 if (!m_sliceableModel) return 0;
Chris@1238 1072
Chris@1238 1073 return new LinearRangeMapper(0, m_sliceableModel->getHeight(),
Chris@1238 1074 0, m_sliceableModel->getHeight(), "");
Chris@1238 1075 }