Another small optimization for audio thumbs drawing

parent 7735dede
...@@ -18,7 +18,7 @@ Row { ...@@ -18,7 +18,7 @@ Row {
Timer { Timer {
id: waveTimer id: waveTimer
interval: 30; running: false; repeat: false interval: 5; running: false; repeat: false
onTriggered: processReload() onTriggered: processReload()
} }
......
#include "kdenlivesettings.h" #include "kdenlivesettings.h"
#include <QLinearGradient>
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include <QPalette> #include <QPalette>
...@@ -115,15 +114,13 @@ public: ...@@ -115,15 +114,13 @@ public:
font.setPixelSize(channelHeight - 1); font.setPixelSize(channelHeight - 1);
painter->setFont(font); painter->setFont(font);
// Draw separate channels // Draw separate channels
QMap<int, QPainterPath> positiveChannelPaths;
QMap<int, QPainterPath> negativeChannelPaths;
double i = 0; double i = 0;
double increment = qMax(1., 1 / indicesPrPixel); double increment = qMax(1., 1 / indicesPrPixel);
QRectF bgRect(0, 0, width(), 2 * channelHeight); QRectF bgRect(0, 0, width(), 2 * channelHeight);
QVector<QPainterPath> channelPaths(m_channels);
for (int channel = 0; channel < m_channels; channel++) { for (int channel = 0; channel < m_channels; channel++) {
double y = height() - (2 * channel * channelHeight) - channelHeight; double y = height() - (2 * channel * channelHeight) - channelHeight;
positiveChannelPaths[channel].moveTo(-1, y); channelPaths[channel].moveTo(-1, y);
negativeChannelPaths[channel].moveTo(-1, y);
painter->setOpacity(0.2); painter->setOpacity(0.2);
if (channel % 2 == 0) { if (channel % 2 == 0) {
// Add dark background on odd channels // Add dark background on odd channels
...@@ -143,17 +140,18 @@ public: ...@@ -143,17 +140,18 @@ public:
lastIdx = idx; lastIdx = idx;
if (idx + channel >= m_audioLevels.length()) break; if (idx + channel >= m_audioLevels.length()) break;
qreal level = m_audioLevels.at(idx + channel).toReal() * channelHeight / 256; qreal level = m_audioLevels.at(idx + channel).toReal() * channelHeight / 256;
positiveChannelPaths[channel].lineTo(i, y - level); channelPaths[channel].lineTo(i, y - level);
negativeChannelPaths[channel].lineTo(i, y + level);
} }
if (m_firstChunk && m_channels > 1 && m_channels < 7) { if (m_firstChunk && m_channels > 1 && m_channels < 7) {
painter->drawText(2, y + channelHeight, chanelNames[channel]); painter->drawText(2, y + channelHeight, chanelNames[channel]);
} }
positiveChannelPaths[channel].lineTo(i, y); channelPaths[channel].lineTo(i, y);
negativeChannelPaths[channel].lineTo(i, y);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
painter->drawPath(positiveChannelPaths.value(channel)); painter->drawPath(channelPaths.value(channel));
painter->drawPath(negativeChannelPaths.value(channel)); QTransform tr;
tr.scale(1, -1);
tr.translate(0, -2 * y);
painter->drawPath(tr.map(channelPaths.value(channel)));
} }
} }
} }
...@@ -170,7 +168,6 @@ private: ...@@ -170,7 +168,6 @@ private:
int m_outPoint; int m_outPoint;
QColor m_color; QColor m_color;
bool m_format; bool m_format;
QLinearGradient m_gradient;
bool m_showItem; bool m_showItem;
int m_channels; int m_channels;
bool m_firstChunk; bool m_firstChunk;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment