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

Switch to a quadratic curve for note brightness based on note velocity #3260

Draft
wants to merge 10 commits into
base: community
Choose a base branch
from
7 changes: 7 additions & 0 deletions src/deluge/gui/colour/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class RGB {
});
}

/**
* @brief Change a color's brightness through a simple
* multiplication operation with a float value
* @return RGB The updated color
*/
[[nodiscard]] constexpr RGB operator*(float value) const { return RGB(r * value, g * value, b * value); }

/**
* @brief Dim a colour
*
Expand Down
13 changes: 8 additions & 5 deletions src/deluge/model/note/note_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ void NoteRow::renderRow(TimelineView* editorScreen, RGB rowColour, RGB rowTailCo

RGB& pixel = image[xDisplay];

// If Note starts somewhere within square, draw the blur colour
// If note starts somewhere within square, draw the blur colour
if (note && note->pos > squareStartPos) {
drewNote = true;
pixel = rowBlurColour;
Expand All @@ -1959,12 +1959,15 @@ void NoteRow::renderRow(TimelineView* editorScreen, RGB rowColour, RGB rowTailCo
}
}

// Or if Note starts exactly on square...
// Or if note starts exactly on square...
else if (note && note->pos == squareStartPos) {
drewNote = true;
// this is just colour * (0.25 + 0.75 * velocity) but in fixed point, i.e. it'll go linearly from 0.25
// to max brightness with velocity
pixel = rowColour.adjustFractional((65 + note->velocity + (note->velocity / 2)) << 8, 255 << 8);
float velocity_ratio = static_cast<float>(note->velocity) / 127.f; // velocity range is 1-127
float colour_intensity = 0.03 + 0.97 * velocity_ratio * velocity_ratio;
// The brightness is reduced as necessary to be proportional to the note velocity.
// below .03 (~4/127) it is not visible enough, so we set that as the minimum
// A quadratic curve makes the brightness gradient appear more linear.
pixel = rowColour * colour_intensity;
if (occupancyMask) {
occupancyMask[xDisplay] = 64;
}
Expand Down
Loading