Skip to content

Commit

Permalink
waveform: add track end markers
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 30, 2020
1 parent cdc5d21 commit f456acf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
90 changes: 60 additions & 30 deletions src/waveform/renderers/waveformrendererpreroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,28 @@ void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) {
return;
}

double playMarkerPosition = m_waveformRenderer->getPlayMarkerPosition();
double samplesPerPixel = m_waveformRenderer->getVisualSamplePerPixel();
double numberOfSamples = m_waveformRenderer->getLength() * samplesPerPixel;
double firstDisplayedPosition = m_waveformRenderer->getFirstDisplayedPosition();
double lastDisplayedPosition = m_waveformRenderer->getLastDisplayedPosition();

// Check if the pre- or post-roll is on screen. If so, draw little triangles
// to indicate the respective zones.
bool preRollVisible = firstDisplayedPosition < 0;
bool postRollVisible = lastDisplayedPosition > 1;
if (preRollVisible || postRollVisible) {
double playMarkerPosition = m_waveformRenderer->getPlayMarkerPosition();
double samplesPerPixel = m_waveformRenderer->getVisualSamplePerPixel();
double numberOfSamples = m_waveformRenderer->getLength() * samplesPerPixel;

int currentPosition = m_waveformRenderer->getPlayPosVSample();
int totalSamples = m_waveformRenderer->getTotalVSample();
//qDebug() << "currentPosition" << currentPosition
// << "lastDisplayedPosition" << lastDisplayedPosition
// << "samplesPerPixel" << samplesPerPixel
// << "numberOfSamples" << numberOfSamples
// << "totalSamples" << totalSamples
// << "WaveformRendererPreroll::playMarkerPosition=" << playMarkerPosition;

int currentPosition = m_waveformRenderer->getPlayPosVSample();
//qDebug() << "currentPosition" << currentPosition
// << "samplesPerPixel" << samplesPerPixel
// << "numberOfSamples" << numberOfSamples
// << "WaveformRendererPreroll::playMarkerPosition=" << playMarkerPosition;


// Some of the pre-roll is on screen. Draw little triangles to indicate
// where the pre-roll is located.
if (currentPosition < numberOfSamples * playMarkerPosition) {
int index = static_cast<int>(numberOfSamples * playMarkerPosition - currentPosition);
const int polyLength = static_cast<int>(40.0 / samplesPerPixel);

const float halfBreadth = m_waveformRenderer->getBreadth() / 2.0;
const float halfPolyBreadth = m_waveformRenderer->getBreadth() / 5.0;

Expand All @@ -65,23 +70,48 @@ void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) {
painter->setTransform(QTransform(0, 1, 1, 0, 0, 0));
}

QPolygonF polygon;
polygon << QPointF(0, halfBreadth)
<< QPointF(-polyLength, halfBreadth - halfPolyBreadth)
<< QPointF(-polyLength, halfBreadth + halfPolyBreadth);

// Draw at most one not or halve visible polygon at the widget borders
if (index > (numberOfSamples + ((polyLength + 1) * samplesPerPixel))) {
int rest = index - numberOfSamples;
rest %= (int)((polyLength + 1) * samplesPerPixel);
index = numberOfSamples + rest;
if (preRollVisible) {
// Sample position of the right-most triangle's tip
int index = static_cast<int>(numberOfSamples * playMarkerPosition - currentPosition);

QPolygonF polygon;
polygon << QPointF(0, halfBreadth)
<< QPointF(-polyLength, halfBreadth - halfPolyBreadth)
<< QPointF(-polyLength, halfBreadth + halfPolyBreadth);

// Draw at most one not or halve visible polygon at the widget borders
if (index > (numberOfSamples + ((polyLength + 1) * samplesPerPixel))) {
int rest = index - numberOfSamples;
rest %= (int)((polyLength + 1) * samplesPerPixel);
index = numberOfSamples + rest;
}

polygon.translate(((qreal)index) / samplesPerPixel, 0);
while (index > 0) {
painter->drawPolygon(polygon);
polygon.translate(-(polyLength + 1), 0);
index -= (polyLength + 1) * samplesPerPixel;
}
}

polygon.translate(((qreal)index) / samplesPerPixel, 0);
while (index > 0) {
painter->drawPolygon(polygon);
polygon.translate(-(polyLength + 1), 0);
index -= (polyLength + 1) * samplesPerPixel;
if (postRollVisible) {
int remainingVSamples = totalSamples - currentPosition;
// Sample position of the left-most triangle's tip
int index = (playMarkerPosition * numberOfSamples) + remainingVSamples;
qreal endPos = index / samplesPerPixel;
//painter->drawLine(endPos, 0, endPos, m_waveformRenderer->getBreadth());

QPolygonF polygon;
polygon << QPointF(0, halfBreadth)
<< QPointF(polyLength, halfBreadth - halfPolyBreadth)
<< QPointF(polyLength, halfBreadth + halfPolyBreadth);

polygon.translate(endPos, 0);
while (index < numberOfSamples) {
painter->drawPolygon(polygon);
polygon.translate(+(polyLength + 1), 0);
index += (polyLength + 1) * samplesPerPixel;
}
}
}
}
4 changes: 3 additions & 1 deletion src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group)
m_visualPlayPosition(NULL),
m_playPos(-1),
m_playPosVSample(0),
m_totalVSamples(0),
m_pRateRatioCO(NULL),
m_rateRatio(1.0),
m_pGainControlObject(NULL),
Expand Down Expand Up @@ -133,7 +134,8 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) {
// Avoid pixel jitter in play position by rounding to the nearest track
// pixel.
m_playPos = round(truePlayPos * m_trackPixelCount) / m_trackPixelCount;
m_playPosVSample = m_playPos * m_trackPixelCount * m_visualSamplePerPixel;
m_totalVSamples = m_trackPixelCount * m_visualSamplePerPixel;
m_playPosVSample = m_playPos * m_totalVSamples;

double leftOffset = m_playMarkerPosition;
double rightOffset = 1.0 - m_playMarkerPosition;
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class WaveformWidgetRenderer {

double getPlayPos() const { return m_playPos;}
double getPlayPosVSample() const { return m_playPosVSample;}
double getTotalVSample() const { return m_totalVSamples; }
double getZoomFactor() const { return m_zoomFactor;}
double getGain() const { return m_gain;}
int getTrackSamples() const { return m_trackSamples;}
Expand Down Expand Up @@ -140,6 +141,7 @@ class WaveformWidgetRenderer {
QSharedPointer<VisualPlayPosition> m_visualPlayPosition;
double m_playPos;
int m_playPosVSample;
int m_totalVSamples;
ControlProxy* m_pRateRatioCO;
double m_rateRatio;
ControlProxy* m_pGainControlObject;
Expand Down

0 comments on commit f456acf

Please sign in to comment.