Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waveform: add track end markers #3137

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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