mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-03 06:54:17 +01:00
refact(plotview): Move the time scale into PlotView
This commit is contained in:
@@ -37,7 +37,6 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float
|
||||
zoomLevel = 0;
|
||||
powerMax = 0.0f;
|
||||
powerMin = -50.0f;
|
||||
timeScaleIsEnabled = true;
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
float p = (float)i / 256;
|
||||
@@ -53,59 +52,6 @@ void SpectrogramPlot::paintFront(QPainter &painter, QRect &rect, range_t<off_t>
|
||||
{
|
||||
if (tunerEnabled())
|
||||
tuner.paintFront(painter, rect, sampleRange);
|
||||
|
||||
if (timeScaleIsEnabled)
|
||||
paintTimeScale(painter, rect, sampleRange);
|
||||
}
|
||||
|
||||
void SpectrogramPlot::paintTimeScale(QPainter &painter, QRect &rect, range_t<off_t> sampleRange)
|
||||
{
|
||||
float startTime = (float)sampleRange.minimum / sampleRate;
|
||||
float stopTime = (float)sampleRange.maximum / sampleRate;
|
||||
float duration = stopTime - startTime;
|
||||
|
||||
painter.save();
|
||||
|
||||
QPen pen(Qt::white, 1, Qt::SolidLine);
|
||||
painter.setPen(pen);
|
||||
QFontMetrics fm(painter.font());
|
||||
|
||||
int tickWidth = 80;
|
||||
int maxTicks = rect.width() / tickWidth;
|
||||
|
||||
double durationPerTick = 10 * pow(10, floor(log(duration / maxTicks) / log(10)));
|
||||
|
||||
double firstTick = int(startTime / durationPerTick) * durationPerTick;
|
||||
|
||||
double tick = firstTick;
|
||||
|
||||
while (tick <= stopTime) {
|
||||
|
||||
off_t tickSample = tick * sampleRate;
|
||||
int tickLine = (tickSample - sampleRange.minimum) / getStride();
|
||||
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "%.06f", tick);
|
||||
painter.drawLine(tickLine, 0, tickLine, 30);
|
||||
painter.drawText(tickLine + 2, 25, buf);
|
||||
|
||||
tick += durationPerTick;
|
||||
}
|
||||
|
||||
// Draw small ticks
|
||||
durationPerTick /= 10;
|
||||
firstTick = int(startTime / durationPerTick) * durationPerTick;
|
||||
tick = firstTick;
|
||||
while (tick <= stopTime) {
|
||||
|
||||
off_t tickSample = tick * sampleRate;
|
||||
int tickLine = (tickSample - sampleRange.minimum) / getStride();
|
||||
|
||||
painter.drawLine(tickLine, 0, tickLine, 10);
|
||||
tick += durationPerTick;
|
||||
}
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void SpectrogramPlot::paintMid(QPainter &painter, QRect &rect, range_t<off_t> sampleRange)
|
||||
@@ -293,15 +239,3 @@ uint qHash(const TileCacheKey &key, uint seed)
|
||||
{
|
||||
return key.fftSize ^ key.zoomLevel ^ key.sample ^ seed;
|
||||
}
|
||||
|
||||
void SpectrogramPlot::setSampleRate(off_t rate)
|
||||
{
|
||||
sampleRate = rate;
|
||||
emit repaint();
|
||||
}
|
||||
|
||||
void SpectrogramPlot::setTimeScaleEnable(bool enabled)
|
||||
{
|
||||
timeScaleIsEnabled = enabled;
|
||||
emit repaint();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user