Skip to content
Snippets Groups Projects
Commit 7d3cc657 authored by Igor Korsukov's avatar Igor Korsukov
Browse files

[AU4] made params refactor of wave draw

parent 793b44e5
No related branches found
No related tags found
No related merge requests found
...@@ -8,15 +8,11 @@ ...@@ -8,15 +8,11 @@
#include <wx/utils.h> #include <wx/utils.h>
#include "ClipInterface.h" #include "ClipInterface.h"
#include "CodeConversions.h"
#include "SelectedRegion.h"
#include "WaveClip.h" #include "WaveClip.h"
#include "WaveTrack.h" #include "WaveTrack.h"
#include "ZoomInfo.h" #include "ZoomInfo.h"
#include "Envelope.h" #include "Envelope.h"
#include "FrameStatistics.h" #include "FrameStatistics.h"
#include "SyncLock.h"
#include "ViewInfo.h"
#include "WaveformScale.h" #include "WaveformScale.h"
#include "graphics/Color.h" #include "graphics/Color.h"
...@@ -25,11 +21,7 @@ ...@@ -25,11 +21,7 @@
#include "domaccessor.h" #include "domaccessor.h"
constexpr int kClipDetailedViewMinimumWidth{ 3 }; constexpr double CLIPVIEW_WIDTH_MIN = 4; // px
constexpr int FrameRadius { 4 };
constexpr int HeaderHeight { 0 };
constexpr int HeaderVMargin { 2 };
using Style = au::au3::Au3WavePainter::Style; using Style = au::au3::Au3WavePainter::Style;
...@@ -120,19 +112,24 @@ public: ...@@ -120,19 +112,24 @@ public:
clip, dataCache, clip, dataCache,
[] { return std::make_unique<WaveBitmapCacheElementQt>(); }); [] { return std::make_unique<WaveBitmapCacheElementQt>(); });
mChannelCaches.push_back( mChannelCaches.push_back({ std::move(dataCache), std::move(bitmapCache) });
{ std::move(dataCache), std::move(bitmapCache) });
} }
return *this; return *this;
} }
struct Geometry
{
double top = 0.0;
double left = 0.0;
double height = 0.0;
};
void Draw(int channelIndex, void Draw(int channelIndex,
QPainter& painter, const QPainter& painter, const
WavePaintParameters& params, WavePaintParameters& params,
const ZoomInfo& zoomInfo, const Geometry& geometry,
const QRect& targetRect, double zoom,
int leftOffset,
double from, double from,
double to) double to)
{ {
...@@ -144,33 +141,32 @@ public: ...@@ -144,33 +141,32 @@ public:
auto& bitmapCache = mChannelCaches[channelIndex].BitmapCache; auto& bitmapCache = mChannelCaches[channelIndex].BitmapCache;
bitmapCache->SetPaintParameters(params); bitmapCache->SetPaintParameters(params);
const ZoomInfo zoomInfo(0.0, zoom);
auto range = bitmapCache->PerformLookup(zoomInfo, from, to); auto range = bitmapCache->PerformLookup(zoomInfo, from, to);
auto left = targetRect.x() + leftOffset; int left = geometry.left;
auto height = targetRect.height(); int height = geometry.height;
LOGDA() << "zoom: " << zoomInfo.GetZoom() LOGDA() << " top: " << geometry.top
<< " leftOffset: " << leftOffset << " left: " << geometry.left
<< " targetRect.x() : " << targetRect.x() << " height: " << geometry.height
<< " left: " << left << " zoom: " << zoom
<< " from: " << from << " from: " << from
<< " to: " << to; << " to: " << to
;
const auto top = targetRect.y();
for (auto it = range.begin(); it != range.end(); ++it) { for (auto it = range.begin(); it != range.end(); ++it) {
const auto elementLeftOffset = it.GetLeftOffset(); const auto elementLeftOffset = it.GetLeftOffset();
const auto elementRightOffset = it.GetRightOffset(); const auto elementRightOffset = it.GetRightOffset();
const auto width = WaveBitmapCache::CacheElementWidth const auto width = WaveBitmapCache::CacheElementWidth - elementLeftOffset - elementRightOffset;
- elementLeftOffset - elementRightOffset;
const auto drawableWidth = std::min<int32_t>( const auto drawableWidth = std::min<int32_t>(width, it->Width() - elementLeftOffset);
width, it->Width() - elementLeftOffset);
const auto image = static_cast<const WaveBitmapCacheElementQt&>(*it).GetImage(); const auto image = static_cast<const WaveBitmapCacheElementQt&>(*it).GetImage();
painter.drawImage( painter.drawImage(
QRectF(left, targetRect.y(), drawableWidth, height), QRectF(left, geometry.top, drawableWidth, height),
image, image,
QRectF( QRectF(
elementLeftOffset, elementLeftOffset,
...@@ -372,170 +368,38 @@ int GetWaveYPos(float value, float min, float max, ...@@ -372,170 +368,38 @@ int GetWaveYPos(float value, float min, float max,
return (int)(value * (height - 1) + 0.5); return (int)(value * (height - 1) + 0.5);
} }
struct ClipGeometry
{
double top = 0.0; // wave channel view top
double height = 0.0; // wave view height
double width = 0.0; // wave view width
double left = 0.0; // on track line
double frameLeft = 0.0; // track line shift
double frameWidth = 0.0; // track line visible width
};
struct ClipParameters struct ClipParameters
{ {
// Do a bunch of calculations common to waveform and spectrum drawing. // Do a bunch of calculations common to waveform and spectrum drawing.
ClipParameters(const ClipTimes& clip, const QRect& rect, const ZoomInfo& zoomInfo); ClipParameters(const ClipGeometry& geometry, double zoom);
const double trackRectT0; // absolute time of left edge of track ClipGeometry geometry;
// Lower and upper visible time boundaries (relative to clip). If completely // Lower and upper visible time boundaries (relative to clip). If completely
// off-screen, `t0 == t1`. // off-screen, `t0 == t1`.
double t0; double t0 = 0.0;
double t1; double t1 = 0.0;
const double averagePixelsPerSecond;
const bool showIndividualSamples;
QRect hiddenMid;
int hiddenLeftOffset;
QRect mid; QRect mid;
int leftOffset;
// returns a clip rectangle restricted by viewRect,
// and with clipOffsetX - clip horizontal origin offset within view rect
static QRect GetClipRect(
const ClipTimes& clip, const ZoomInfo& zoomInfo, const QRect& viewRect, bool* outShowSamples = nullptr);
}; };
ClipParameters::ClipParameters( ClipParameters::ClipParameters(const ClipGeometry& geomet, double zoom)
const ClipTimes& clip, const QRect& rect, const ZoomInfo& zoomInfo) : geometry(geomet)
: trackRectT0{zoomInfo.PositionToTime(0, 0, true)}
, averagePixelsPerSecond{GetPixelsPerSecond(rect, zoomInfo)}
, showIndividualSamples{ShowIndividualSamples(
clip.GetRate(), clip.GetStretchRatio(), averagePixelsPerSecond)}
{ {
const auto trackRectT1 = zoomInfo.PositionToTime(rect.width(), 0, true); geometry.left = 0.0;
const auto playStartTime = clip.GetPlayStartTime();
const double clipLength = clip.GetPlayEndTime() - clip.GetPlayStartTime();
// Hidden duration because too far left.
const auto tpre = trackRectT0 - playStartTime;
const auto tpost = trackRectT1 - playStartTime;
const auto blank = GetBlankSpaceBeforePlayEndTime(clip);
// Calculate actual selection bounds so that t0 > 0 and t1 < the
// end of the track
t0 = std::max(tpre, .0);
t1 = std::min(tpost, clipLength - blank)
+ CalculateAdjustmentForZoomLevel(
averagePixelsPerSecond, showIndividualSamples);
// Make sure t1 (the right bound) is greater than 0
if (t1 < 0.0) {
t1 = 0.0;
}
// Make sure t1 is greater than t0
if (t0 > t1) {
t0 = t1;
}
// The variable "hiddenMid" will be the rectangle containing the
// actual waveform, as opposed to any blank area before
// or after the track, as it would appear without the fisheye.
hiddenMid = rect;
// If the left edge of the track is to the right of the left
// edge of the display, then there's some unused area to the
// left of the track. Reduce the "hiddenMid"
hiddenLeftOffset = 0;
if (tpre < 0) {
// Fix Bug #1296 caused by premature conversion to (int).
wxInt64 time64 = zoomInfo.TimeToPosition(playStartTime, 0, true);
if (time64 < 0) {
time64 = 0;
}
hiddenLeftOffset = (time64 < rect.width()) ? (int)time64 : rect.width();
hiddenMid.setLeft(hiddenMid.left() + hiddenLeftOffset);
}
// If the right edge of the track is to the left of the right
// edge of the display, then there's some unused area to the right
// of the track. Reduce the "hiddenMid" rect by the
// size of the blank area.
if (tpost > t1) {
wxInt64 time64 = zoomInfo.TimeToPosition(playStartTime + t1, 0, true);
if (time64 < 0) {
time64 = 0;
}
const int hiddenRightOffset = (time64 < rect.width()) ? (int)time64 : rect.width();
hiddenMid.setWidth(std::max(0, hiddenRightOffset - hiddenLeftOffset));
}
// The variable "mid" will be the rectangle containing the
// actual waveform, as distorted by the fisheye,
// as opposed to any blank area before or after the track.
mid = rect;
// If the left edge of the track is to the right of the left
// edge of the display, then there's some unused area to the
// left of the track. Reduce the "mid"
leftOffset = 0;
if (tpre < 0) {
wxInt64 time64 = 0;//zoomInfo.TimeToPosition(playStartTime, 0, false);
if (time64 < 0) {
time64 = 0;
}
leftOffset = (time64 < rect.width()) ? (int)time64 : rect.width();
mid.setLeft(mid.left() + leftOffset);
}
// If the right edge of the track is to the left of the right t0 = 0;//geomet.left / zoom;
// edge of the display, then there's some unused area to the right t1 = t0 + (geomet.width / zoom);
// of the track. Reduce the "mid" rect by the
// size of the blank area.
if (tpost > t1) {
wxInt64 time64 = zoomInfo.TimeToPosition(playStartTime + t1, 0, false);
if (time64 < 0) {
time64 = 0;
}
const int distortedRightOffset = (time64 < rect.width()) ? (int)time64 : rect.width();
mid.setWidth(std::max(0, distortedRightOffset - leftOffset));
}
}
QRect ClipParameters::GetClipRect(const ClipTimes& clip,
const ZoomInfo& zoomInfo, const QRect& viewRect, bool* outShowSamples)
{
const auto pixelsPerSecond = GetPixelsPerSecond(viewRect, zoomInfo);
const auto showIndividualSamples = ShowIndividualSamples(
clip.GetRate(), clip.GetStretchRatio(), pixelsPerSecond);
const auto clipEndingAdjustment
=CalculateAdjustmentForZoomLevel(pixelsPerSecond, showIndividualSamples);
if (outShowSamples != nullptr) {
*outShowSamples = showIndividualSamples;
}
constexpr auto edgeLeft
=static_cast<ZoomInfo::int64>(std::numeric_limits<int>::min());
constexpr auto edgeRight
=static_cast<ZoomInfo::int64>(std::numeric_limits<int>::max());
const auto left = std::clamp(
zoomInfo.TimeToPosition(clip.GetPlayStartTime(), viewRect.x(), true),
edgeLeft, edgeRight);
const auto right = std::clamp(
zoomInfo.TimeToPosition(
clip.GetPlayEndTime() - GetBlankSpaceBeforePlayEndTime(clip)
+ clipEndingAdjustment,
viewRect.x(), true),
edgeLeft, edgeRight);
if (right >= left) {
// after clamping we can expect that left and right
// are small enough to be put into int
return {
static_cast<int>(left),
viewRect.y(),
std::max(1, static_cast<int>(right - left)),
viewRect.height()
};
}
return {};
} }
void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rect, void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rect,
...@@ -545,10 +409,8 @@ void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rec ...@@ -545,10 +409,8 @@ void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rec
int leftOffset, int leftOffset,
float zoomMin, float zoomMax, float zoomMin, float zoomMax,
bool dB, float dBRange, bool dB, float dBRange,
bool showPoints, bool muted, bool highlight) bool showPoints, bool highlight)
{ {
UNUSED(muted);
const double toffset = clip.GetPlayStartTime(); const double toffset = clip.GetPlayStartTime();
double rate = clip.GetRate(); double rate = clip.GetRate();
const double t0 = std::max(0.0, zoomInfo.PositionToTime(0, -leftOffset) - toffset); const double t0 = std::max(0.0, zoomInfo.PositionToTime(0, -leftOffset) - toffset);
...@@ -664,167 +526,27 @@ void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rec ...@@ -664,167 +526,27 @@ void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rec
} }
} }
void DrawWaveformBackground(QPainter& painter, const QRect& rect,
const Style& style,
const ZoomInfo& zoomInfo,
const double* env, int leftOffset,
float zoomMin, float zoomMax,
double t0, double t1,
bool dB, float dBRange,
int zeroLevelYCoordinate,
bool bIsSyncLockSelected,
bool highlightEnvelope)
{
// Visually (one vertical slice of the waveform background, on its side;
// the "*" is the actual waveform background we're drawing
//
//1.0 0.0 -1.0
// |--------------------------------|--------------------------------|
// *************** ***************
// | | | |
// maxtop maxbot mintop minbot
int h = rect.height();
int halfHeight = wxMax(h / 2, 1);
int maxtop, lmaxtop = 0;
int mintop, lmintop = 0;
int maxbot, lmaxbot = 0;
int minbot, lminbot = 0;
bool sel, lsel = false;
int xx, lx = 0;
int l, w;
painter.setPen(Qt::NoPen);
painter.setBrush(style.blankBrush);
painter.drawRect(rect);
// Bug 2389 - always draw at least one pixel of selection.
int selectedX = zoomInfo.TimeToPosition(t0, -leftOffset);
double time = zoomInfo.PositionToTime(0, -leftOffset), nextTime;
for (xx = 0; xx < rect.width(); ++xx, time = nextTime) {
nextTime = zoomInfo.PositionToTime(xx + 1, -leftOffset);
// First we compute the truncated shape of the waveform background.
// If drawEnvelope is true, then we compute the lower border of the
// envelope.
maxtop = GetWaveYPos(env[xx], zoomMin, zoomMax,
h, dB, true, dBRange, true);
maxbot = GetWaveYPos(env[xx], zoomMin, zoomMax,
h, dB, false, dBRange, true);
mintop = GetWaveYPos(-env[xx], zoomMin, zoomMax,
h, dB, false, dBRange, true);
minbot = GetWaveYPos(-env[xx], zoomMin, zoomMax,
h, dB, true, dBRange, true);
// Make sure it's odd so that a that max and min mirror each other
mintop +=1;
minbot +=1;
//TODO: uncomment and fix
//const auto drawEnvelope = artist->drawEnvelope;
const auto drawEnvelope = false;
if (!drawEnvelope || maxbot > mintop) {
maxbot = halfHeight;
mintop = halfHeight;
}
sel = (t0 <= time && nextTime < t1);
sel = sel || (xx == selectedX);
// We don't draw selection color for sync-lock selected tracks.
sel = sel && !bIsSyncLockSelected;
if (lmaxtop == maxtop
&& lmintop == mintop
&& lmaxbot == maxbot
&& lminbot == minbot
&& lsel == sel) {
continue;
}
painter.setBrush(style.blankBrush);
l = rect.x() + lx;
w = xx - lx;
if (lmaxbot < lmintop - 1) {
painter.drawRect(l, rect.y() + lmaxtop, w, lmaxbot - lmaxtop);
painter.drawRect(l, rect.y() + lmintop, w, lminbot - lmintop);
} else {
painter.drawRect(l, rect.y() + lmaxtop, w, lminbot - lmaxtop);
}
if (highlightEnvelope && lmaxbot < lmintop - 1) {
painter.setBrush(style.highlight);
painter.drawRect(l, rect.y() + lmaxbot, w, lmintop - lmaxbot);
}
lmaxtop = maxtop;
lmintop = mintop;
lmaxbot = maxbot;
lminbot = minbot;
lsel = sel;
lx = xx;
}
painter.setBrush(style.blankBrush);
l = rect.x() + lx;
w = xx - lx;
if (lmaxbot < lmintop - 1) {
painter.drawRect(l, rect.y() + lmaxtop, w, lmaxbot - lmaxtop);
painter.drawRect(l, rect.y() + lmintop, w, lminbot - lmintop);
} else {
painter.drawRect(l, rect.y() + lmaxtop, w, lminbot - lmaxtop);
}
if (highlightEnvelope && lmaxbot < lmintop - 1) {
painter.setBrush(style.highlight);
painter.drawRect(l, rect.y() + lmaxbot, w, lmintop - lmaxbot);
}
//TODO: uncomment and fix
// If sync-lock selected, draw in linked graphics.
/*if (bIsSyncLockSelected && t0 < t1) {
const int begin = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t0, -leftOffset))));
const int end = std::max(0, std::min(rect.width, (int)(zoomInfo.TimeToPosition(t1, -leftOffset))));
TrackArt::DrawSyncLockTiles( context,
{ rect.x + begin, rect.y, end - 1 - begin, rect.height } );
}*/
//OK, the display bounds are between min and max, which
//is spread across rect.height. Draw the line at the proper place.
if (zeroLevelYCoordinate >= rect.top()
&& zeroLevelYCoordinate <= rect.bottom()) {
painter.setPen(Qt::black);
painter.drawLine(rect.x(), zeroLevelYCoordinate,
rect.x() + rect.width() - 1, zeroLevelYCoordinate);
}
}
void DrawMinMaxRMS(int channelIndex, QPainter& painter, void DrawMinMaxRMS(int channelIndex, QPainter& painter,
const QRect& rect, const ClipParameters& params,
double zoom,
const Style& style, const Style& style,
const ZoomInfo& zoomInfo,
const WaveClip& clip, const WaveClip& clip,
double t0, double t1, int leftOffset,
double zoomMin, double zoomMax, double zoomMin, double zoomMax,
bool dB, double dbRange, bool dB, double dbRange)
bool muted)
{ {
UNUSED(muted);
const ZoomInfo localZoomInfo(0.0, zoomInfo.GetZoom());
auto& waveformPainter = WaveformPainter::Get(clip); auto& waveformPainter = WaveformPainter::Get(clip);
const auto trimLeft = clip.GetTrimLeft(); WaveformPainter::Geometry g;
g.top = params.geometry.top;
g.left = params.geometry.left;
g.height = params.geometry.height;
WavePaintParameters paintParameters; WavePaintParameters paintParameters;
paintParameters paintParameters
.SetDisplayParameters( .SetDisplayParameters(
//TODO: uncomment and fix //TODO: uncomment and fix
rect.height(), zoomMin, zoomMax, false /*artist->mShowClipping*/) g.height, zoomMin, zoomMax, false /*artist->mShowClipping*/)
.SetDBParameters(dbRange, dB) .SetDBParameters(dbRange, dB)
.SetBlankColor(ColorFromQColor(style.blankBrush)) .SetBlankColor(ColorFromQColor(style.blankBrush))
.SetSampleColors( .SetSampleColors(
...@@ -841,37 +563,35 @@ void DrawMinMaxRMS(int channelIndex, QPainter& painter, ...@@ -841,37 +563,35 @@ void DrawMinMaxRMS(int channelIndex, QPainter& painter,
ColorFromQColor(style.clippedPen)) ColorFromQColor(style.clippedPen))
.SetEnvelope(clip.GetEnvelope()); .SetEnvelope(clip.GetEnvelope());
//TODO: uncomment and fix const auto trimLeft = clip.GetTrimLeft();
//clipPainter.SetSelection(
// zoomInfo, artist->pSelectedRegion->t0() - sequenceStartTime,
// artist->pSelectedRegion->t1() - sequenceStartTime);
waveformPainter.Draw(channelIndex, painter, paintParameters, localZoomInfo, rect, leftOffset, t0 + trimLeft, t1 + trimLeft); waveformPainter.Draw(channelIndex, painter, paintParameters, g, zoom, params.t0 + trimLeft, params.t1 + trimLeft);
} }
static bool ClipDetailsVisible(const ClipTimes& clip, const ZoomInfo& zoomInfo, const QRect& viewRect) static bool showIndividualSamples(const WaveClip& clip, bool zoom)
{ {
//Do not fold clips to line at sample zoom level, as const double sampleRate = clip.GetRate();
//it may become impossible to 'unfold' it when clip is trimmed const double stretchRatio = clip.GetStretchRatio();
//to a single sample
bool showSamples{ false }; // Require at least 1/2 pixel per sample for drawing individual samples.
auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, viewRect, &showSamples); const double threshold1 = 0.5 * sampleRate / stretchRatio;
return showSamples || clipRect.width() >= kClipDetailedViewMinimumWidth;
bool showIndividualSamples = zoom > threshold1;
return showIndividualSamples;
} }
void DrawWaveform(int channelIndex, static void DrawWaveform(int channelIndex,
QPainter& painter, QPainter& painter,
WaveTrack& track, WaveTrack& track,
const WaveClip& clip, const WaveClip& clip,
const ZoomInfo& zoomInfo, const ClipGeometry& geometry,
const SelectedRegion& selectedRegion, double zoom,
const QRect& rect,
const Style& style, const Style& style,
bool dB, bool muted, bool selected) bool dB)
{ {
//If clip is "too small" draw a placeholder instead of //If clip is "too small" draw a placeholder instead of
//attempting to fit the contents into a few pixels //attempting to fit the contents into a few pixels
if (!ClipDetailsVisible(clip, zoomInfo, rect)) { if (geometry.width < CLIPVIEW_WIDTH_MIN) {
//TODO: uncomment and fix me //TODO: uncomment and fix me
/* /*
auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect); auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect);
...@@ -880,29 +600,10 @@ void DrawWaveform(int channelIndex, ...@@ -880,29 +600,10 @@ void DrawWaveform(int channelIndex,
return; return;
} }
bool highlightEnvelope = false; const ClipParameters params(geometry, zoom);
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING // if (params.mid.width() <= 0) {
auto target = dynamic_cast<EnvelopeHandle*>(context.target.get()); // return;
highlightEnvelope = target && target->GetEnvelope() == clip.GetEnvelope(); // }
#endif
const ClipParameters params(clip, rect, zoomInfo);
const auto& hiddenMid = params.hiddenMid;
// The "hiddenMid" rect contains the part of the display actually
// containing the waveform, as it appears without the fisheye. If it's empty, we're done.
if (hiddenMid.width() <= 0) {
return;
}
const double t0 = params.t0;
LOGDA() << "t0: " << t0;
const double sampleRate = clip.GetRate();
const double playStartTime = clip.GetPlayStartTime();
const double trackRectT0 = params.trackRectT0;
const double stretchRatio = clip.GetStretchRatio();
const double t1 = params.t1;
const int leftOffset = params.leftOffset;
const QRect mid = params.mid;
auto& settings = WaveformSettings::Get(track); auto& settings = WaveformSettings::Get(track);
const float dBRange = settings.dBRange; const float dBRange = settings.dBRange;
...@@ -915,99 +616,28 @@ void DrawWaveform(int channelIndex, ...@@ -915,99 +616,28 @@ void DrawWaveform(int channelIndex,
auto& cache = WaveformScale::Get(track); auto& cache = WaveformScale::Get(track);
cache.GetDisplayBounds(zoomMin, zoomMax); cache.GetDisplayBounds(zoomMin, zoomMax);
std::vector<double> vEnv(mid.width()); if (!showIndividualSamples(clip, zoom)) {
double* const env = &vEnv[0]; DrawMinMaxRMS(channelIndex, painter,
GetEnvelopeValues( params, zoom,
clip.GetEnvelope(),
playStartTime,
// PRL: change back to make envelope evaluate only at sample times
// and then interpolate the display
0, // 1.0 / sampleRate,
env, mid.width(), leftOffset, zoomInfo
);
// Draw the background of the track, outlining the shape of
// the envelope and using a colored pen for the selected
// part of the waveform
{
double tt0, tt1;
if (SyncLock::IsSelectedOrSyncLockSelected(track)) {
tt0 = track.LongSamplesToTime(track.TimeToLongSamples(selectedRegion.t0())),
tt1 = track.LongSamplesToTime(track.TimeToLongSamples(selectedRegion.t1()));
} else {
tt0 = tt1 = 0.0;
}
DrawWaveformBackground(
painter, mid,
style,
zoomInfo,
env, leftOffset,
zoomMin, zoomMax,
tt0, tt1,
dB, dBRange,
cache.ZeroLevelYCoordinate({ mid.x(), mid.y(), mid.width(), mid.height() }),
!track.GetSelected(), highlightEnvelope);
}
//const double pps =
// averagePixelsPerSample * rate;
// Require at least 1/2 pixel per sample for drawing individual samples.
const double threshold1 = 0.5 * sampleRate / stretchRatio;
// Require at least 3 pixels per sample for drawing the draggable points.
const double threshold2 = 3 * sampleRate / stretchRatio;
const bool showIndividualSamples = zoomInfo.GetZoom() > threshold1;
const bool showPoints = zoomInfo.GetZoom() > threshold2;
if (!showIndividualSamples) {
DrawMinMaxRMS(channelIndex,
painter, rect,
style, style,
zoomInfo,
clip, clip,
t0, t1, leftOffset,
zoomMin, zoomMax, zoomMin, zoomMax,
dB, dBRange, muted); dB, dBRange);
} else { } else {
bool highlight = false; // Require at least 3 pixels per sample for drawing the draggable points.
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING // const double threshold2 = 3 * sampleRate / stretchRatio;
auto target = dynamic_cast<SampleHandle*>(context.target.get()); // const bool showPoints =zoom > threshold2;
highlight = target && target->GetTrack().get() == track; // bool highlight = false;
#endif // DrawIndividualSamples(
DrawIndividualSamples( // channelIndex,
channelIndex, // painter, rect,
painter, rect, // style,
style, // zoomInfo,
zoomInfo, // clip, leftOffset,
clip, leftOffset, // zoomMin, zoomMax,
zoomMin, zoomMax, // dB, dBRange,
dB, dBRange, // showPoints, highlight);
showPoints, muted, highlight);
}
//TODO: uncomment and fix me
/*const auto drawEnvelope = artist->drawEnvelope;
if (drawEnvelope) {
DrawEnvelope(
context, mid, env, zoomMin, zoomMax, dB, dBRange, highlightEnvelope );
EnvelopeEditor::DrawPoints( *clip->GetEnvelope(),
context, mid, dB, dBRange, zoomMin, zoomMax, true, rect.x - mid.x );
}*/
// Draw arrows on the left side if the track extends to the left of the
// beginning of time. :)
//TODO: uncomment and fix me
/*if (trackRectT0 == 0.0 && playStartTime < 0.0) {
TrackArt::DrawNegativeOffsetTrackArrows( context, rect );
} }
{
auto clipRect = ClipParameters::GetClipRect(*clip, zoomInfo, rect);
TrackArt::DrawClipEdges(context.painter, clipRect, selected);
}*/
} }
using namespace au::au3; using namespace au::au3;
...@@ -1036,44 +666,26 @@ void Au3WavePainter::paint(QPainter& painter, const processing::ClipKey& clipKey ...@@ -1036,44 +666,26 @@ void Au3WavePainter::paint(QPainter& painter, const processing::ClipKey& clipKey
void Au3WavePainter::doPaint(QPainter& painter, const WaveTrack* _track, const WaveClip* clip, const Params& params) void Au3WavePainter::doPaint(QPainter& painter, const WaveTrack* _track, const WaveClip* clip, const Params& params)
{ {
// debug
// const auto& vr = params.viewRect;
// LOGDA() << "viewRect: w: " << vr.width() << ", h: " << vr.height() << ", x: " << vr.x() << ", y: " << vr.y();
auto sw = FrameStatistics::CreateStopwatch(FrameStatistics::SectionID::WaveformView); auto sw = FrameStatistics::CreateStopwatch(FrameStatistics::SectionID::WaveformView);
WaveTrack* track = const_cast<WaveTrack*>(_track); WaveTrack* track = const_cast<WaveTrack*>(_track);
bool highlightEnvelope = false;
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
highlightEnvelope = target && target->GetEnvelope() == clip->GetEnvelope();
#endif
const bool dB = !WaveformSettings::Get(*track).isLinear(); const bool dB = !WaveformSettings::Get(*track).isLinear();
const auto channelHeight = (params.geometry.height) / static_cast<int>(clip->NChannels()); const auto channelHeight = (params.geometry.height) / static_cast<int>(clip->NChannels());
const Geometry& g = params.geometry; const Geometry& g = params.geometry;
double width = std::min(g.left + g.width, g.frameLeft + g.frameWidth) - g.left; ClipGeometry cg;
double left = std::min(g.left - g.frameLeft, 0.0); cg.height = channelHeight;
double clipStartTime = clip->GetPlayStartTime();// + (left / params.zoom); cg.width = g.width;
LOGDA() << "g.width: " << g.width cg.left = g.left;
<< " g.left: " << g.left cg.frameLeft = g.frameLeft;
<< " g.frameWidth: " << g.frameWidth cg.frameWidth = g.frameWidth;
<< " g.frameLeft: " << g.frameLeft
<< " (g.left + g.width): " << (g.left + g.width) cg.top = 0.0;
<< " (g.frameLeft + g.frameWidth): " << (g.frameLeft + g.frameWidth)
<< " width: " << width
<< " left: " << left;
ZoomInfo zoomInfo(clipStartTime, params.zoom);
SelectedRegion selectedRegion{};
double top = 0.0;
for (unsigned i = 0; i < clip->NChannels(); ++i) { for (unsigned i = 0; i < clip->NChannels(); ++i) {
QRect rect(0, top, width, channelHeight); DrawWaveform(i, painter, *track, *clip, cg, params.zoom, params.style, dB);
DrawWaveform(i, painter, *track, *clip, zoomInfo, selectedRegion, rect, params.style, dB, track->GetMute(), false); cg.top += channelHeight;
top += channelHeight;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment