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

[WIP] Paint in different color normal beats, bar beats, and phrase beats. #1918

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions res/skins/Deere/deck_visual_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<SignalRGBLowColor></SignalRGBLowColor>
<SignalColor><Variable name="DeckSignalColor"/></SignalColor>
<BeatColor>#ffffff</BeatColor>
<BarColor>#00ff00</BarColor>
<PhraseColor>#ccffff</PhraseColor>
<PlayPosColor>#00FF00</PlayPosColor>
<EndOfTrackColor>#EA0000</EndOfTrackColor>
<AxesColor></AxesColor>
Expand Down
12 changes: 7 additions & 5 deletions res/skins/LateNight/waveform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
<Channel><Variable name="channum"/></Channel>
<BgColor><Variable name="SignalBgColor"/></BgColor>
<SignalColor><Variable name="signal_color"/></SignalColor>
<SignalRGBLowColor><Variable name="SignalRGBLowColor"/></SignalRGBLowColor>
<SignalRGBMidColor><Variable name="SignalRGBMidColor"/></SignalRGBMidColor>
<SignalRGBHighColor><Variable name="SignalRGBHighColor"/></SignalRGBHighColor>
<BeatColor>#ffffff</BeatColor>
<BeatHighlightColor></BeatHighlightColor>
<SignalRGBLowColor><Variable name="SignalRGBLowColor"/></SignalRGBLowColor>
<SignalRGBMidColor><Variable name="SignalRGBMidColor"/></SignalRGBMidColor>
<SignalRGBHighColor><Variable name="SignalRGBHighColor"/></SignalRGBHighColor>
<BeatColor>#ffffff</BeatColor>
<BarColor>#00ff00</BarColor>
<PhraseColor>#ccffff</PhraseColor>
<BeatHighlightColor></BeatHighlightColor>
<PlayPosColor>#00FF00</PlayPosColor>
<EndOfTrackColor>#EA0000</EndOfTrackColor>
<DefaultMark>
Expand Down
6 changes: 4 additions & 2 deletions res/skins/Shade/deck.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@
<SignalMidColor></SignalMidColor>
<SignalLowColor></SignalLowColor>
<SignalColor>#191F24</SignalColor>
<BeatColor>#FFFFFF</BeatColor>
<PlayPosColor>#00FF00</PlayPosColor>
<BeatColor>#FFFFFF</BeatColor>
<BarColor>#00ff00</BarColor>
<PhraseColor>#ccffff</PhraseColor>
<PlayPosColor>#00FF00</PlayPosColor>
<EndOfTrackColor>#EA0000</EndOfTrackColor>
<AxesColor>#00FF00</AxesColor>
<Align></Align>
Expand Down
2 changes: 2 additions & 0 deletions res/skins/Tango/waveform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Variables:
<SignalRGBMidColor><Variable name="SignalRGBMidColor"/></SignalRGBMidColor>
<SignalRGBHighColor><Variable name="SignalRGBHighColor"/></SignalRGBHighColor>
<BeatColor>#ffffff</BeatColor>
<BarColor>#00ff00</BarColor>
<PhraseColor>#ccffff</PhraseColor>
<PlayPosColor>#FF4300</PlayPosColor>
<EndOfTrackColor>#EA0085</EndOfTrackColor>
<DefaultMark>
Expand Down
93 changes: 81 additions & 12 deletions src/waveform/renderers/waveformrenderbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,38 @@ WaveformRenderBeat::~WaveformRenderBeat() {
void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) {
m_beatColor.setNamedColor(context.selectString(node, "BeatColor"));
m_beatColor = WSkinColor::getCorrectColor(m_beatColor).toRgb();
m_barColor.setNamedColor(context.selectString(node, "BarColor"));
m_barColor = WSkinColor::getCorrectColor(m_barColor).toRgb();
m_phraseColor.setNamedColor(context.selectString(node, "PhraseColor"));
m_phraseColor = WSkinColor::getCorrectColor(m_phraseColor).toRgb();
}

void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) {
TrackPointer trackInfo = m_waveformRenderer->getTrackInfo();

// No track, nothing to do
if (!trackInfo)
return;

// Gets beats from the track
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
BeatsPointer trackBeats = trackInfo->getBeats();
// No beats, nothing to do
if (!trackBeats)
return;

// Set up Alpha values according to the renderer
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
int alpha = m_waveformRenderer->beatGridAlpha();
// Not visible, nothing to do
if (alpha == 0)
return;
m_beatColor.setAlphaF(alpha/100.0);
m_barColor.setAlphaF(alpha/100.0);
m_phraseColor.setAlphaF(alpha/100.0);

// Get number of sample in the track
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
const int trackSamples = m_waveformRenderer->getTrackSamples();

// Empty track, nothing to do (?)
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
if (trackSamples <= 0) {
return;
}
Expand All @@ -49,53 +63,108 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) {
const double lastDisplayedPosition =
m_waveformRenderer->getLastDisplayedPosition();

// qDebug() << "trackSamples" << trackSamples
// << "firstDisplayedPosition" << firstDisplayedPosition
// << "lastDisplayedPosition" << lastDisplayedPosition;
// Calculate beat length
double beatLength = (60.0 * trackInfo->getSampleRate() / trackInfo->getBpm()) * 2;
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved

// Get the visible beats
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<BeatIterator> it(trackBeats->findBeats(
firstDisplayedPosition * trackSamples,
lastDisplayedPosition * trackSamples));

// if no beat do not waste time saving/restoring painter
// if no beats visible, nothing to do
if (!it || !it->hasNext()) {
return;
}

painter->save();
painter->setRenderHint(QPainter::Antialiasing);

// Create the different pens for beat, bar and phrase
QPen beatPen(m_beatColor);
beatPen.setWidthF(std::max(1.0, scaleFactor()));
painter->setPen(beatPen);

QPen barPen(m_barColor);
barPen.setWidthF(std::max(1.0, scaleFactor()*2));

QPen phrasePen(m_phraseColor);
phrasePen.setWidthF(std::max(1.0, scaleFactor()*2));

const Qt::Orientation orientation = m_waveformRenderer->getOrientation();
const float rendererWidth = m_waveformRenderer->getWidth();
const float rendererHeight = m_waveformRenderer->getHeight();

// TODO Needed?
int beatCount = 0;

while (it->hasNext()) {
double beatPosition = it->next();
double xBeatPoint =
m_waveformRenderer->transformSamplePositionInRendererWorld(beatPosition);

xBeatPoint = qRound(xBeatPoint);

// If we don't have enough space, double the size.
if (beatCount >= m_beats.size()) {
// TODO Needed?
if (beatCount++ >= m_beats.size()) {
m_beats.resize(m_beats.size() * 2);
}

// Calculates the beat number for the current beat
long beatNum = round(beatPosition / beatLength);

// Selects the right pen, if we are in phrase also paints the phrase tag
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
if(beatNum % 16 == 0 && beatNum > 0) {
// Selects the font
QFont font; // Uses the application default
font.setPointSizeF(10 * scaleFactor());
font.setStretch(100);
font.setWeight(75);

QFontMetrics metrics(font);

// Calculates the size of the box
QString label(QString::number(beatNum/16+1));
QRect wordRect = metrics.tightBoundingRect(label);
const int marginX = 1;
const int marginY = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be multiplied by the scale factor.

wordRect.moveTop(marginX + 1);
wordRect.moveLeft(marginY + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use scaleFactor() instead of 1

wordRect.setHeight(wordRect.height() + (wordRect.height()%2));
wordRect.setWidth(wordRect.width() + (wordRect.width())%2);
//even wordrect to have an even Image >> draw the line in the middle !

int labelRectWidth = wordRect.width() + 2 * marginX + 4;
int labelRectHeight = wordRect.height() + 2 * marginY + 4 ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int labelRectHeight = wordRect.height() + 2 * marginY + 4 ;
int labelRectHeight = wordRect.height() + 2 * marginY + 4 * scaleFactor();


QRectF labelRect(xBeatPoint-labelRectWidth, rendererHeight-labelRectHeight, (float)labelRectWidth, (float)labelRectHeight);

// Draw the label rect
QColor rectColor = m_phraseColor;
rectColor.setAlpha(200);
painter->setPen(m_phraseColor);
painter->setBrush(QBrush(rectColor));
painter->drawRoundedRect(labelRect, 2.0, 2.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 * scaleFactor()


// Draw the text
painter->setBrush(QBrush(QColor(0,0,0,0)));
painter->setFont(font);
painter->setPen(Qt::black);
painter->drawText(labelRect, Qt::AlignCenter, label);

painter->setPen(phrasePen);
} else if(beatNum % 4 == 0 && beatNum > 0) {
JaviVilarroig marked this conversation as resolved.
Show resolved Hide resolved
painter->setPen(barPen);
}
else {
painter->setPen(beatPen);
}

// Paints the beat line
if (orientation == Qt::Horizontal) {
m_beats[beatCount++].setLine(xBeatPoint, 0.0f, xBeatPoint, rendererHeight);
painter->drawLine(xBeatPoint, 0.0f, xBeatPoint, rendererHeight);
} else {
m_beats[beatCount++].setLine(0.0f, xBeatPoint, rendererWidth, xBeatPoint);
painter->drawLine(0.0f, xBeatPoint, rendererWidth, xBeatPoint);
}
}

// Make sure to use constData to prevent detaches!
painter->drawLines(m_beats.constData(), beatCount);

painter->restore();
}
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformrenderbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class WaveformRenderBeat : public WaveformRendererAbstract {

private:
QColor m_beatColor;
QColor m_barColor;
QColor m_phraseColor;
QVector<QLineF> m_beats;

DISALLOW_COPY_AND_ASSIGN(WaveformRenderBeat);
Expand Down