comparison layer/SliceLayer.cpp @ 199:45e995ed84d9

* Flesh out feature descriptions for spectrum
author Chris Cannam
date Mon, 05 Feb 2007 16:11:49 +0000
parents c2ed5014d4ff
children 34bbbcb3c01f
comparison
equal deleted inserted replaced
198:c2ed5014d4ff 199:45e995ed84d9
97 } 97 }
98 98
99 QString 99 QString
100 SliceLayer::getFeatureDescription(View *v, QPoint &p) const 100 SliceLayer::getFeatureDescription(View *v, QPoint &p) const
101 { 101 {
102 int minbin, maxbin, range;
103 return getFeatureDescription(v, p, true, minbin, maxbin, range);
104 }
105
106 QString
107 SliceLayer::getFeatureDescription(View *v, QPoint &p,
108 bool includeBinDescription,
109 int &minbin, int &maxbin, int &range) const
110 {
111 minbin = 0;
112 maxbin = 0;
102 if (!m_sliceableModel) return ""; 113 if (!m_sliceableModel) return "";
103 114
104 int xorigin = m_xorigins[v]; 115 int xorigin = m_xorigins[v];
105 int w = v->width() - xorigin - 1; 116 int w = v->width() - xorigin - 1;
106 117
107 int mh = m_sliceableModel->getHeight(); 118 int mh = m_sliceableModel->getHeight();
108 int bin = getBinForX(p.x() - xorigin, mh, w); 119 minbin = getBinForX(p.x() - xorigin, mh, w);
109 if (bin >= mh) bin = mh - 1; 120 maxbin = getBinForX(p.x() - xorigin + 1, mh, w);
110 if (bin < 0) bin = 0; 121
122 if (minbin >= mh) minbin = mh - 1;
123 if (maxbin >= mh) maxbin = mh - 1;
124 if (minbin < 0) minbin = 0;
125 if (maxbin < 0) maxbin = 0;
111 126
112 int sampleRate = m_sliceableModel->getSampleRate(); 127 int sampleRate = m_sliceableModel->getSampleRate();
113 128
114 size_t f0 = m_currentf0; 129 size_t f0 = m_currentf0;
115 size_t f1 = m_currentf1; 130 size_t f1 = m_currentf1;
116 131
117 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate); 132 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
118 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate); 133 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
119 134
120 size_t range = f1 - f0 + 1; 135 range = f1 - f0 + 1;
121 136
122 float value = 0.f; 137 if (includeBinDescription) {
123 if (bin < m_values.size()) value = m_values[bin]; 138
124 139 float minvalue = 0.f;
125 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples\nBin:\t%4\n%5 value:\t%6") 140 if (minbin < m_values.size()) minvalue = m_values[minbin];
126 .arg(QString::fromStdString(rt0.toText(true))) 141
127 .arg(QString::fromStdString(rt1.toText(true))) 142 float maxvalue = minvalue;
128 .arg(range) 143 if (maxbin < m_values.size()) maxvalue = m_values[maxbin];
129 .arg(bin + 1) 144
130 .arg(m_samplingMode == NearestSample ? tr("First") : 145 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
131 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak")) 146
132 .arg(value); 147 QString binstr;
133 148 if (maxbin != minbin) {
134 return description; 149 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
150 } else {
151 binstr = QString("%1").arg(minbin+1);
152 }
153
154 QString valuestr;
155 if (maxvalue != minvalue) {
156 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
157 } else {
158 valuestr = QString("%1").arg(minvalue);
159 }
160
161 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples\nBin:\t%4\n%5 value:\t%6")
162 .arg(QString::fromStdString(rt0.toText(true)))
163 .arg(QString::fromStdString(rt1.toText(true)))
164 .arg(range)
165 .arg(binstr)
166 .arg(m_samplingMode == NearestSample ? tr("First") :
167 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
168 .arg(valuestr);
169
170 return description;
171
172 } else {
173
174 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples")
175 .arg(QString::fromStdString(rt0.toText(true)))
176 .arg(QString::fromStdString(rt1.toText(true)))
177 .arg(range);
178
179 return description;
180 }
135 } 181 }
136 182
137 float 183 float
138 SliceLayer::getXForBin(int bin, int count, float w) const 184 SliceLayer::getXForBin(int bin, int count, float w) const
139 { 185 {