-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add option to show note values on notes in Piano Roll (#4466) #4467
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -751,6 +751,12 @@ QColor PianoRoll::noteColor() const | |
void PianoRoll::setNoteColor( const QColor & c ) | ||
{ m_noteColor = c; } | ||
|
||
QColor PianoRoll::noteTextColor() const | ||
{ return m_noteTextColor; } | ||
|
||
void PianoRoll::setNoteTextColor( const QColor & c ) | ||
{ m_noteTextColor = c; } | ||
|
||
QColor PianoRoll::barColor() const | ||
{ return m_barColor; } | ||
|
||
|
@@ -810,8 +816,8 @@ void PianoRoll::setBackgroundShade( const QColor & c ) | |
|
||
|
||
void PianoRoll::drawNoteRect( QPainter & p, int x, int y, | ||
int width, const Note * n, const QColor & noteCol, | ||
const QColor & selCol, const int noteOpc, const bool borders ) | ||
int width, const Note * n, const QColor & noteCol, const QColor & noteTextColor, | ||
const QColor & selCol, const int noteOpc, const bool borders, bool drawNoteName ) | ||
{ | ||
++x; | ||
++y; | ||
|
@@ -822,15 +828,19 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, | |
width = 2; | ||
} | ||
|
||
int volVal = qMin( 255, 100 + (int) ( ( (float)( n->getVolume() - MinVolume ) ) / | ||
( (float)( MaxVolume - MinVolume ) ) * 155.0f) ); | ||
float rightPercent = qMin<float>( 1.0f, | ||
( (float)( n->getPanning() - PanningLeft ) ) / | ||
( (float)( PanningRight - PanningLeft ) ) * 2.0f ); | ||
// Volume | ||
float const volumeRange = static_cast<float>(MaxVolume - MinVolume); | ||
float const volumeSpan = static_cast<float>(n->getVolume() - MinVolume); | ||
float const volumeRatio = volumeSpan / volumeRange; | ||
int volVal = qMin( 255, 100 + static_cast<int>( volumeRatio * 155.0f) ); | ||
|
||
float leftPercent = qMin<float>( 1.0f, | ||
( (float)( PanningRight - n->getPanning() ) ) / | ||
( (float)( PanningRight - PanningLeft ) ) * 2.0f ); | ||
// Panning | ||
float const panningRange = static_cast<float>(PanningRight - PanningLeft); | ||
float const leftPanSpan = static_cast<float>(PanningRight - n->getPanning()); | ||
float const rightPanSpan = static_cast<float>(n->getPanning() - PanningLeft); | ||
|
||
float leftPercent = qMin<float>( 1.0f, leftPanSpan / panningRange * 2.0f ); | ||
float rightPercent = qMin<float>( 1.0f, rightPanSpan / panningRange * 2.0f ); | ||
|
||
QColor col = QColor( noteCol ); | ||
QPen pen; | ||
|
@@ -848,9 +858,9 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, | |
// adjust note to make it a bit faded if it has a lower volume | ||
// in stereo using gradients | ||
QColor lcol = QColor::fromHsv( col.hue(), col.saturation(), | ||
volVal * leftPercent, noteOpc ); | ||
static_cast<int>(volVal * leftPercent), noteOpc ); | ||
QColor rcol = QColor::fromHsv( col.hue(), col.saturation(), | ||
volVal * rightPercent, noteOpc ); | ||
static_cast<int>(volVal * rightPercent), noteOpc ); | ||
|
||
QLinearGradient gradient( x, y, x, y + noteHeight ); | ||
gradient.setColorAt( 0, rcol ); | ||
|
@@ -868,6 +878,35 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, | |
|
||
p.drawRect( x, y, noteWidth, noteHeight ); | ||
|
||
// Draw note key text | ||
if (drawNoteName) | ||
{ | ||
p.save(); | ||
int const noteTextHeight = static_cast<int>(noteHeight * 0.8); | ||
if (noteTextHeight > 6) | ||
{ | ||
QString noteKeyString = getNoteString(n->key()); | ||
|
||
QFont noteFont(p.font()); | ||
noteFont.setPixelSize(noteTextHeight); | ||
QFontMetrics fontMetrics(noteFont); | ||
QSize textSize = fontMetrics.size(Qt::TextSingleLine, noteKeyString); | ||
|
||
int const distanceToBorder = 2; | ||
int const xOffset = borderWidth + distanceToBorder; | ||
|
||
if (textSize.width() < noteWidth - xOffset) | ||
{ | ||
p.setPen(noteTextColor); | ||
p.setFont(noteFont); | ||
QPoint textStart(x + xOffset, y + (noteTextHeight + (noteHeight - noteTextHeight) / 2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth, the calculation of the y-coordinate (baseline) could be expressed more succinctly as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 27bd8aa. |
||
|
||
p.drawText(textStart, noteKeyString); | ||
} | ||
} | ||
p.restore(); | ||
} | ||
|
||
// draw the note endmark, to hint the user to resize | ||
p.setBrush( col ); | ||
if( width > 2 ) | ||
|
@@ -3022,8 +3061,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) | |
// note | ||
drawNoteRect( p, x + WHITE_KEY_WIDTH, | ||
y_base - key * KEY_LINE_HEIGHT, | ||
note_width, note, noteColor(), selectedNoteColor(), | ||
noteOpacity(), noteBorders() ); | ||
note_width, note, noteColor(), noteTextColor(), selectedNoteColor(), | ||
noteOpacity(), noteBorders(), drawNoteNames ); | ||
} | ||
|
||
// draw note editing stuff | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use tab indentation instead of spaces to match the style of the surrounding lines (same with the change to
data/themes/default/style.css
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with 27bd8aa.