Skip to content

Commit 5348a05

Browse files
Add note color gradient
1 parent 0e53a25 commit 5348a05

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

src/ui/Utils.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,41 @@ namespace utils {
739739

740740
return merged;
741741
}
742+
743+
float bezierInterpolate(float p0, float p1, float p2, float p3, float t) {
744+
float u = 1 - t;
745+
return u * u * u * p0 + 3 * u * u * t * p1 + 3 * u * t * t * p2 + t * t * t * p3;
746+
}
747+
748+
juce::Colour bezierInterpolateColor(
749+
const juce::Colour& color1, const juce::Colour& control1,
750+
const juce::Colour& control2, const juce::Colour& color2, float t) {
751+
return juce::Colour::fromRGB(
752+
(int)bezierInterpolate(color1.getRed(), control1.getRed(), control2.getRed(), color2.getRed(), t),
753+
(int)bezierInterpolate(color1.getGreen(), control1.getGreen(), control2.getGreen(), color2.getGreen(), t),
754+
(int)bezierInterpolate(color1.getBlue(), control1.getBlue(), control2.getBlue(), color2.getBlue(), t));
755+
}
756+
757+
const juce::Array<juce::Colour> generateBezierColorGradient(
758+
const juce::Colour& baseColor, const juce::Colour& targetColor, int num,
759+
float control1, float control2) {
760+
juce::Array<juce::Colour> gradient;
761+
762+
auto controlColor1 = juce::Colour::fromRGB(
763+
baseColor.getRed() + (int)((targetColor.getRed() - baseColor.getRed()) * control1),
764+
baseColor.getGreen() + (int)((targetColor.getGreen() - baseColor.getGreen()) * control1),
765+
baseColor.getBlue() + (int)((targetColor.getBlue() - baseColor.getBlue()) * control1));
766+
767+
auto controlColor2 = juce::Colour::fromRGB(
768+
baseColor.getRed() + static_cast<int>((targetColor.getRed() - baseColor.getRed()) * control2),
769+
baseColor.getGreen() + static_cast<int>((targetColor.getGreen() - baseColor.getGreen()) * control2),
770+
baseColor.getBlue() + static_cast<int>((targetColor.getBlue() - baseColor.getBlue()) * control2));
771+
772+
for (int i = 0; i < num; i++) {
773+
float t = i / (float)(num - 1);
774+
gradient.add(bezierInterpolateColor(baseColor, controlColor1, controlColor2, targetColor, t));
775+
}
776+
777+
return gradient;
778+
}
742779
}

src/ui/Utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,12 @@ namespace utils {
160160
using IntSection = std::pair<int, int>;
161161
using IntSectionList = juce::Array<IntSection>;
162162
const IntSectionList getUnionSections(const IntSectionList& source);
163+
164+
float bezierInterpolate(float p0, float p1, float p2, float p3, float t);
165+
juce::Colour bezierInterpolateColor(
166+
const juce::Colour& color1, const juce::Colour& control1,
167+
const juce::Colour& control2, const juce::Colour& color2, float t);
168+
const juce::Array<juce::Colour> generateBezierColorGradient(
169+
const juce::Colour& baseColor, const juce::Colour& targetColor, int num,
170+
float control1 = 0.3f, float control2 = 0.7f);
163171
}

src/ui/component/editor/MIDIContentViewer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ void MIDIContentViewer::update(int index, uint64_t ref) {
3434
this->index = index;
3535
this->ref = ref;
3636

37+
if (index >= 0) {
38+
this->trackColor = quickAPI::getSeqTrackColor(index);
39+
this->trackColorIsLight = utils::isLightColor(this->trackColor);
40+
41+
/** Note Color Gradient */
42+
auto& laf = this->getLookAndFeel();
43+
juce::Colour highChannelNoteColor = laf.findColour(
44+
juce::Label::ColourIds::backgroundWhenEditingColourId);
45+
this->noteColorGradient = utils::generateBezierColorGradient(
46+
this->trackColor, highChannelNoteColor, 16);
47+
}
48+
3749
this->updateBlocks();
3850
}
3951

src/ui/component/editor/MIDIContentViewer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class MIDIContentViewer final
102102
std::unique_ptr<juce::Image> blockTemp = nullptr;
103103
std::unique_ptr<juce::Image> noteTemp = nullptr;
104104

105+
juce::Colour trackColor;
106+
bool trackColorIsLight = false;
107+
juce::Array<juce::Colour> noteColorGradient;
108+
105109
void updateKeyImageTemp();
106110
void updateRulerImageTemp();
107111
void updateBlockImageTemp();

src/ui/lookAndFeel/editor/MidiContentLookAndFeel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ MidiContentLookAndFeel::MidiContentLookAndFeel()
3737
this->setColour(juce::Label::ColourIds::outlineColourId,
3838
ColorMap::getInstance()->get("ThemeColorB3"));
3939
this->setColour(juce::Label::ColourIds::backgroundWhenEditingColourId,
40-
ColorMap::getInstance()->get("ThemeColorB2"));
40+
ColorMap::getInstance()->get("ThemeColorB9"));/**< Notes In High Channel */
4141
this->setColour(juce::Label::ColourIds::textWhenEditingColourId,
4242
ColorMap::getInstance()->get("ThemeColorB1").withAlpha(0.8f));/**< Time Out of Blocks */
4343
this->setColour(juce::Label::ColourIds::outlineWhenEditingColourId,

0 commit comments

Comments
 (0)