Mercurial > hg > svgui
changeset 709:def489f5ce92 tonioni
Adjustable middle-line height for waveform. Not 100% supported (only really for basic waveform rendering)
author | Chris Cannam |
---|---|
date | Wed, 08 Jan 2014 17:47:34 +0000 |
parents | 1c4bbf8952bc |
children | c65826b5e980 |
files | layer/WaveformLayer.cpp layer/WaveformLayer.h |
diffstat | 2 files changed, 45 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/WaveformLayer.cpp Tue Jan 07 13:04:16 2014 +0000 +++ b/layer/WaveformLayer.cpp Wed Jan 08 17:47:34 2014 +0000 @@ -43,6 +43,7 @@ m_channelMode(SeparateChannels), m_channel(-1), m_scale(LinearScale), + m_middleLineHeight(0.5), m_aggressive(false), m_cache(0), m_cacheValid(false) @@ -306,6 +307,15 @@ } void +WaveformLayer::setMiddleLineHeight(float height) +{ + if (m_middleLineHeight == height) return; + m_middleLineHeight = height; + m_cacheValid = false; + emit layerParametersChanged(); +} + +void WaveformLayer::setAggressiveCacheing(bool aggressive) { if (m_aggressive == aggressive) return; @@ -532,6 +542,15 @@ paint->setRenderHint(QPainter::Antialiasing, false); + if (m_middleLineHeight != 0.5) { + paint->save(); + float space = m_middleLineHeight * 2; + if (space > 1.0) space = 2.0 - space; + float yt = h * (m_middleLineHeight - space/2); + paint->translate(QPointF(0, yt)); + paint->scale(1.0, space); + } + int x0 = 0, x1 = w - 1; int y0 = 0, y1 = h - 1; @@ -915,6 +934,10 @@ } } + if (m_middleLineHeight != 0.5) { + paint->restore(); + } + if (m_aggressive) { if (ready && rect == v->rect()) { @@ -1314,14 +1337,16 @@ "channelMode=\"%4\" " "channel=\"%5\" " "scale=\"%6\" " - "aggressive=\"%7\" " - "autoNormalize=\"%8\"") + "middleLineHeight=\"%7\" " + "aggressive=\"%8\" " + "autoNormalize=\"%9\"") .arg(m_gain) .arg(m_showMeans) .arg(m_greyscale) .arg(m_channelMode) .arg(m_channel) .arg(m_scale) + .arg(m_middleLineHeight) .arg(m_aggressive) .arg(m_autoNormalize); @@ -1353,10 +1378,12 @@ int channel = attributes.value("channel").toInt(&ok); if (ok) setChannel(channel); - Scale scale = (Scale) - attributes.value("scale").toInt(&ok); + Scale scale = (Scale)attributes.value("scale").toInt(&ok); if (ok) setScale(scale); + float middleLineHeight = attributes.value("middleLineHeight").toFloat(&ok); + if (ok) setMiddleLineHeight(middleLineHeight); + bool aggressive = (attributes.value("aggressive") == "1" || attributes.value("aggressive") == "true"); setUseGreyscale(aggressive);
--- a/layer/WaveformLayer.h Tue Jan 07 13:04:16 2014 +0000 +++ b/layer/WaveformLayer.h Wed Jan 08 17:47:34 2014 +0000 @@ -147,6 +147,19 @@ Scale getScale() const { return m_scale; } /** + * Specify the height of the middle of the waveform track or + * tracks within the layer, from 0.0 to 1.0. + * + * A value of 0.0 would indicate that the waveform occupies + * effectively no space at the very top of the layer; 1.0 would + * indicate that the waveform occupies no space at the very + * bottom; the default value of 0.5 indicates that it occupies the + * whole layer, centred at the middle. + */ + void setMiddleLineHeight(float height); + float getMiddleLineHeight() const { return m_middleLineHeight; } + + /** * Enable or disable aggressive pixmap cacheing. If enabled, * waveforms will be rendered to an off-screen pixmap and * refreshed from there instead of being redrawn from the peak @@ -216,6 +229,7 @@ ChannelMode m_channelMode; int m_channel; Scale m_scale; + float m_middleLineHeight; bool m_aggressive; mutable std::vector<float> m_effectiveGains;