19 #include "base/AudioLevel.h" 20 #include "base/RangeMapper.h" 21 #include "base/RealTime.h" 28 #include <QPainterPath> 29 #include <QTextStream> 35 m_energyScale(dBScale),
36 m_samplingMode(SampleMean),
37 m_plotStyle(PlotSteps),
38 m_binScale(LinearBins),
41 m_initialThreshold(0.0),
56 const DenseThreeDimensionalModel *sliceable =
57 dynamic_cast<const DenseThreeDimensionalModel *>(model);
59 if (model && !sliceable) {
60 cerr <<
"WARNING: SliceLayer::setSliceableModel(" << model
61 <<
"): model is not a DenseThreeDimensionalModel" << endl;
76 SVDEBUG <<
"SliceLayer::sliceableModelReplaced(" << orig <<
", " << replacement <<
")" << endl;
80 (dynamic_cast<const DenseThreeDimensionalModel *>(replacement));
87 SVDEBUG <<
"SliceLayer::modelAboutToBeDeleted(" << m <<
")" << endl;
97 int minbin, maxbin, range;
103 bool includeBinDescription,
104 int &minbin,
int &maxbin,
int &range)
const 111 int w = v->width() - xorigin - 1;
115 maxbin =
getBinForX(p.x() - xorigin + 1, mh, w);
117 if (minbin >= mh) minbin = mh - 1;
118 if (maxbin >= mh) maxbin = mh - 1;
119 if (minbin < 0) minbin = 0;
120 if (maxbin < 0) maxbin = 0;
127 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
128 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
132 QString rtrangestr = QString(
"%1 s").arg((rt1 - rt0).toText().c_str());
134 if (includeBinDescription) {
136 float minvalue = 0.f;
139 float maxvalue = minvalue;
142 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
145 if (maxbin != minbin) {
146 binstr = tr(
"%1 - %2").arg(minbin+1).arg(maxbin+1);
148 binstr = QString(
"%1").arg(minbin+1);
152 if (maxvalue != minvalue) {
153 valuestr = tr(
"%1 - %2").arg(minvalue).arg(maxvalue);
155 valuestr = QString(
"%1").arg(minvalue);
158 QString description = tr(
"Time:\t%1 - %2\nRange:\t%3 samples (%4)\nBin:\t%5\n%6 value:\t%7")
159 .arg(QString::fromStdString(rt0.toText(
true)))
160 .arg(QString::fromStdString(rt1.toText(
true)))
172 QString description = tr(
"Time:\t%1 - %2\nRange:\t%3 samples (%4)")
173 .arg(QString::fromStdString(rt0.toText(
true)))
174 .arg(QString::fromStdString(rt1.toText(
true)))
190 x = (float(w) * bin) / count;
194 x = (float(w) * log10f(bin + 1)) / log10f(count + 1);
198 x = w - (float(w) * log10f(count - bin - 1)) / log10f(count);
213 bin = int((x * count) / w + 0.0001);
217 bin = int(powf(10.f, (x * log10f(count + 1)) / w) - 1 + 0.0001);
221 bin = count + 1 - int(powf(10.f, (log10f(count) * (w - x)) /
float(w)) + 0.0001);
243 if (h <= 0)
return y;
250 if (value > 0.f) db = 10.f * log10f(fabsf(value));
251 if (db < thresh) db = thresh;
252 norm = (db - thresh) / -thresh;
253 y = yorigin - (float(h) * norm);
258 y = AudioLevel::multiplier_to_preview(value, h);
259 norm = float(y) / float(h);
264 value = fabsf(value);
270 if (norm < 0) norm = 0;
271 y = yorigin - (float(h) * norm);
289 if (h <= 0)
return value;
297 float db = ((y / h) * -thresh) + thresh;
298 value = powf(10.f, db/10.f);
303 value = AudioLevel::preview_to_multiplier(lrintf(y), h);
322 paint.setRenderHint(QPainter::Antialiasing,
false);
323 paint.setBrush(Qt::NoBrush);
327 paint.setPen(QColor(240, 240, 240));
337 int w = v->width() - xorigin - 1;
341 int yorigin = v->height() - 20 -
paint.fontMetrics().height() - 7;
342 int h = yorigin -
paint.fontMetrics().height() - 8;
356 for (
int bin = 0; bin < mh; ++bin) {
373 f1 = (col1 + 1) * res - 1;
382 int cs = curve.size();
384 for (
int col = col0; col <= col1; ++col) {
385 for (
int bin = 0; bin < mh; ++bin) {
387 if (bin < cs) value *= curve[bin];
398 for (
int bin = 0; bin < mh; ++bin) {
405 for (
int bin = 0; bin < mh; ++bin) {
414 for (
int bin = 0; bin < mh; ++bin) {
442 path.moveTo(x, yorigin);
445 path.lineTo(nx, yorigin);
446 path.lineTo(x, yorigin);
450 paint.fillRect(QRectF(x, y, nx - x, yorigin - y), mapper.
map(norm));
456 paint.drawPath(path);
507 return std::max(
paint.fontMetrics().width(
"0.0") + 13,
508 paint.fontMetrics().width(
"x10-10"));
510 return std::max(
paint.fontMetrics().width(tr(
"0dB")),
511 paint.fontMetrics().width(tr(
"-Inf"))) + 13;
526 int yorigin = v->height() - 20 -
paint.fontMetrics().height() - 6;
527 int h = yorigin -
paint.fontMetrics().height() - 8;
530 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
540 if (mult != 1 && mult != 0) {
541 int log = lrintf(log10f(mult));
542 QString a = tr(
"x10");
543 QString b = QString(
"%1").arg(-log);
544 paint.drawText(3, 8 +
paint.fontMetrics().ascent(), a);
545 paint.drawText(3 +
paint.fontMetrics().width(a),
546 3 +
paint.fontMetrics().ascent(), b);
554 list.push_back(
"Bin Scale");
555 list.push_back(
"Plot Type");
556 list.push_back(
"Scale");
557 list.push_back(
"Normalize");
558 list.push_back(
"Threshold");
559 list.push_back(
"Gain");
567 if (name ==
"Plot Type")
return tr(
"Plot Type");
568 if (name ==
"Scale")
return tr(
"Scale");
569 if (name ==
"Normalize")
return tr(
"Normalize");
570 if (name ==
"Threshold")
return tr(
"Threshold");
571 if (name ==
"Gain")
return tr(
"Gain");
572 if (name ==
"Sampling Mode")
return tr(
"Sampling Mode");
573 if (name ==
"Bin Scale")
return tr(
"Bin Scale");
580 if (name ==
"Normalize")
return "normalise";
587 if (name ==
"Gain")
return RangeProperty;
588 if (name ==
"Normalize")
return ToggleProperty;
589 if (name ==
"Threshold")
return RangeProperty;
590 if (name ==
"Plot Type")
return ValueProperty;
591 if (name ==
"Scale")
return ValueProperty;
592 if (name ==
"Sampling Mode")
return ValueProperty;
593 if (name ==
"Bin Scale")
return ValueProperty;
601 if (name ==
"Scale" ||
602 name ==
"Normalize" ||
603 name ==
"Sampling Mode" ||
604 name ==
"Threshold" ||
605 name ==
"Gain")
return tr(
"Scale");
606 if (name ==
"Plot Type" ||
607 name ==
"Bin Scale")
return tr(
"Bins");
613 int *min,
int *max,
int *deflt)
const 617 int garbage0, garbage1, garbage2;
618 if (!min) min = &garbage0;
619 if (!max) max = &garbage1;
620 if (!deflt) deflt = &garbage2;
622 if (name ==
"Gain") {
630 val = lrint(log10(
m_gain) * 20.0);
631 if (val < *min) val = *min;
632 if (val > *max) val = *max;
634 }
else if (name ==
"Threshold") {
640 if (*deflt < *min) *deflt = *min;
641 if (*deflt > *max) *deflt = *max;
643 val = lrintf(AudioLevel::multiplier_to_dB(
m_threshold));
644 if (val < *min) val = *min;
645 if (val > *max) val = *max;
647 }
else if (name ==
"Normalize") {
660 }
else if (name ==
"Scale") {
668 }
else if (name ==
"Sampling Mode") {
676 }
else if (name ==
"Plot Type") {
684 }
else if (name ==
"Bin Scale") {
707 if (name ==
"Scale") {
710 case 0:
return tr(
"Linear");
711 case 1:
return tr(
"Meter");
712 case 2:
return tr(
"Log");
713 case 3:
return tr(
"Absolute");
716 if (name ==
"Sampling Mode") {
719 case 0:
return tr(
"Any");
720 case 1:
return tr(
"Mean");
721 case 2:
return tr(
"Peak");
724 if (name ==
"Plot Type") {
727 case 0:
return tr(
"Lines");
728 case 1:
return tr(
"Steps");
729 case 2:
return tr(
"Blocks");
730 case 3:
return tr(
"Colours");
733 if (name ==
"Bin Scale") {
736 case 0:
return tr(
"Linear");
737 case 1:
return tr(
"Log");
738 case 2:
return tr(
"Rev Log");
747 if (name ==
"Gain") {
748 return new LinearRangeMapper(-50, 50, -25, 25, tr(
"dB"));
750 if (name ==
"Threshold") {
751 return new LinearRangeMapper(-80, 0, -80, 0, tr(
"dB"));
759 if (name ==
"Gain") {
760 setGain(pow(10,
float(value)/20.0));
761 }
else if (name ==
"Threshold") {
766 }
else if (name ==
"Scale") {
774 }
else if (name ==
"Plot Type") {
776 }
else if (name ==
"Sampling Mode") {
783 }
else if (name ==
"Bin Scale") {
790 }
else if (name ==
"Normalize") {
828 if (colourTypeChanged) {
861 if (
m_gain == gain)
return;
870 float db = AudioLevel::multiplier_to_dB(
m_threshold);
879 (QString(darkbg ?
"Bright Blue" :
"Blue"));
884 QString indent, QString extraAttributes)
const 888 s += QString(
"colourScheme=\"%1\" " 889 "energyScale=\"%2\" " 890 "samplingMode=\"%3\" " 916 attributes.value(
"energyScale").toInt(&ok);
920 attributes.value(
"samplingMode").toInt(&ok);
923 int colourMap = attributes.value(
"colourScheme").toInt(&ok);
927 attributes.value(
"plotStyle").toInt(&ok);
931 attributes.value(
"binScale").toInt(&ok);
934 float gain = attributes.value(
"gain").toFloat(&ok);
937 float threshold = attributes.value(
"threshold").toFloat(&ok);
940 bool normalize = (attributes.value(
"normalize").trimmed() ==
"true");
int getFrameForX(int x) const
Return the closest frame to the given pixel x-coordinate.
EnergyScale m_energyScale
virtual QString getPropertyLabel(const PropertyName &) const
virtual QString getPropertyIconName(const PropertyName &) const
virtual QString getFeatureDescriptionAux(View *v, QPoint &, bool includeBinDescription, int &minbin, int &maxbin, int &range) const
virtual float getXForBin(int bin, int totalBins, float w) const
void setFillColourMap(int)
void connectSignals(const Model *)
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual PropertyType getPropertyType(const PropertyName &) const
virtual float getYForValue(float value, const View *v, float &norm) const
std::map< const View *, int > m_heights
virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const
void setSamplingMode(SamplingMode)
std::map< const View *, int > m_xorigins
const DenseThreeDimensionalModel * m_sliceableModel
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
virtual ViewManager * getViewManager() const
virtual QString getPropertyGroupName(const PropertyName &) const
virtual void setProperties(const QXmlAttributes &)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
static int getColourMapCount()
void sliceableModelReplaced(const Model *, const Model *)
virtual void setProperty(const PropertyName &, int value)
std::vector< int > m_scalePoints
void layerParameterRangesChanged()
virtual QColor getBaseQColor() const
bool shouldShowScaleGuides() const
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
int getColourIndex(QString name) const
virtual int getDefaultColourHint(bool dark, bool &impose)
virtual QString getPropertyLabel(const PropertyName &) const
virtual QString getFeatureDescription(View *v, QPoint &) const
void setNormalize(bool n)
virtual int getBinForX(float x, int totalBins, float w) const
virtual PropertyList getProperties() const
void setSliceableModel(const Model *model)
void layerParametersChanged()
virtual float getValueForY(float y, const View *v) const
virtual QString getPropertyGroupName(const PropertyName &) const
std::vector< float > m_values
virtual float getThresholdDb() const
virtual void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual void getBiasCurve(BiasCurve &) const
A class for mapping intensity values onto various colour maps.
QColor map(float value) const
void setPlotStyle(PlotStyle style)
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
virtual RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const
void setBinScale(BinScale scale)
std::vector< float > BiasCurve
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
void setEnergyScale(EnergyScale)
std::map< const View *, int > m_yorigins
static void paintVerticalLevelScale(QPainter &p, QRect rect, float minVal, float maxVal, Scale scale, int &multRtn, std::vector< int > *markCoordRtns=0)
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
SamplingMode m_samplingMode
int getCentreFrame() const
Return the centre frame of the visible widget.
virtual bool getValueExtents(float &min, float &max, bool &logarithmic, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
virtual PropertyList getProperties() const
virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const
void modelAboutToBeDeleted(Model *)
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
virtual PropertyType getPropertyType(const PropertyName &) const
int getXForFrame(int frame) const
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative).
static ColourDatabase * getInstance()
virtual void setProperty(const PropertyName &, int value)
static QString getColourMapName(int n)