Skip to content

Commit 28bda8a

Browse files
Add midi note name label
1 parent a5a52bc commit 28bda8a

File tree

9 files changed

+54
-12
lines changed

9 files changed

+54
-12
lines changed

src/ui/Utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,12 @@ namespace utils {
736736
return darkContrast < lightContrast;
737737
}
738738

739+
juce::Colour chooseTextColor(const juce::Colour& backgroundColor,
740+
const juce::Colour& textColorLight, const juce::Colour& textColorDark) {
741+
return utils::isLightColor(backgroundColor, textColorLight, textColorDark)
742+
? textColorLight : textColorDark;
743+
}
744+
739745
const IntSectionList getUnionSections(const IntSectionList& source) {
740746
if (source.size() <= 0) return {};
741747

src/ui/Utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ namespace utils {
161161
bool isLightColor(const juce::Colour& color,
162162
const juce::Colour& textColorLight = juce::Colours::black,
163163
const juce::Colour& textColorDark = juce::Colours::white);
164+
juce::Colour chooseTextColor(const juce::Colour& backgroundColor,
165+
const juce::Colour& textColorLight = juce::Colours::black,
166+
const juce::Colour& textColorDark = juce::Colours::white);
164167
using IntSection = std::pair<int, int>;
165168
using IntSectionList = juce::Array<IntSection>;
166169
const IntSectionList getUnionSections(const IntSectionList& source);

src/ui/component/editor/MIDIContentViewer.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ void MIDIContentViewer::update(int index, uint64_t ref) {
4444
juce::Label::ColourIds::backgroundWhenEditingColourId);
4545
this->noteColorGradient = utils::generateBezierColorGradient(
4646
this->trackColor, highChannelNoteColor, 16);
47+
48+
/** Note Name Color Gradient */
49+
juce::Colour lightNoteLabelColor = laf.findColour(
50+
juce::MidiKeyboardComponent::ColourIds::textLabelColourId);
51+
juce::Colour darkNoteLabelColor = laf.findColour(
52+
juce::MidiKeyboardComponent::ColourIds::textLabelColourId + 2);
53+
this->noteLabelColorGradient.clearQuick();
54+
for (auto& backColor : this->noteColorGradient) {
55+
this->noteLabelColorGradient.add(utils::chooseTextColor(
56+
backColor, lightNoteLabelColor, darkNoteLabelColor));
57+
}
4758
}
4859

4960
this->updateBlocks();
@@ -501,18 +512,26 @@ void MIDIContentViewer::updateNoteImageTemp() {
501512
float noteCornerSize = screenSize.getHeight() * 0.003;
502513
float noteOutlineThickness = screenSize.getHeight() * 0.001;
503514

515+
float notePaddingWidth = screenSize.getWidth() * 0.003;
516+
float notePaddingHeight = screenSize.getHeight() * 0.0025;
517+
float noteFontHeight = screenSize.getHeight() * 0.0135;
518+
504519
/** Colors */
505520
auto& laf = this->getLookAndFeel();
506521
juce::Colour noteOutlineColor = laf.findColour(
507522
juce::Label::ColourIds::outlineColourId);
508523

524+
/** Font */
525+
juce::Font noteLabelFont(juce::FontOptions{ noteFontHeight });
526+
509527
/** Notes */
510528
int minNoteNum = std::floor(this->keyBottom), maxNoteNum = std::floor(this->keyTop);
511529
for (auto& note : this->midiDataTemp) {
512530
if (note.startSec <= this->secEnd &&
513531
this->secStart <= note.endSec) {
514-
if (note.num >= minNoteNum &&
532+
if (note.num >= (minNoteNum - 1) &&
515533
note.num <= maxNoteNum) {
534+
/** Note Rect */
516535
float startXPos = (note.startSec - this->secStart) / (this->secEnd - this->secStart) * width;
517536
float endXPos = (note.endSec - this->secStart) / (this->secEnd - this->secStart) * width;
518537
float noteYPos = ((note.num + 1) - this->keyTop) / (this->keyBottom - this->keyTop) * height;
@@ -523,6 +542,18 @@ void MIDIContentViewer::updateNoteImageTemp() {
523542
g.fillRoundedRectangle(noteRect,noteCornerSize);
524543
g.setColour(noteOutlineColor);
525544
g.drawRoundedRectangle(noteRect, noteCornerSize, noteOutlineThickness);
545+
546+
/** Note Name */
547+
juce::String noteName = this->keyNames[note.num % this->keyMasks.size()] + juce::String{ note.num / this->keyMasks.size() };
548+
float noteNameWidth = juce::TextLayout::getStringWidth(noteLabelFont, noteName);
549+
if ((noteNameWidth + notePaddingWidth * 2) <= noteRect.getWidth()
550+
&& (noteFontHeight + notePaddingHeight * 2) <= noteRect.getHeight()) {
551+
juce::Rectangle<float> noteLabelRect = noteRect.withWidth(noteNameWidth + notePaddingWidth * 2);
552+
g.setFont(noteLabelFont);
553+
g.setColour(this->noteLabelColorGradient[note.channel]);
554+
g.drawFittedText(noteName, noteLabelRect.toNearestInt(),
555+
juce::Justification::centred, 1, 0.75f);
556+
}
526557
}
527558
}
528559
}

src/ui/component/editor/MIDIContentViewer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class MIDIContentViewer final
6060
const std::array<int, 12> keyMasks{ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
6161
const int totalKeys = 128;
6262

63+
const juce::StringArray keyNames{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
64+
6365
int index = -1;
6466
uint64_t ref = 0;
6567

@@ -105,6 +107,7 @@ class MIDIContentViewer final
105107
juce::Colour trackColor;
106108
//bool trackColorIsLight = false;
107109
juce::Array<juce::Colour> noteColorGradient;
110+
juce::Array<juce::Colour> noteLabelColorGradient;
108111

109112
void updateKeyImageTemp();
110113
void updateRulerImageTemp();

src/ui/component/editor/PianoComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void PianoComponent::paint(juce::Graphics& g) {
5151
/** Keys */
5252
for (int i = 0; i < octaveNum; i++) {
5353
int octave = startOctave + i;
54-
juce::String octaveName = juce::String{ octave - 1 };
54+
juce::String octaveName = juce::String{ octave };
5555
float octavePos = startOctavePos - i * sizePerOctave;
5656

5757
/** White Keys */

src/ui/component/mixer/MixerTrackComponent.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ void MixerTrackComponent::update(int index) {
293293
juce::Label::ColourIds::textWhenEditingColourId);
294294
auto textColorDark = laf.findColour(
295295
juce::Label::ColourIds::textColourId);
296-
this->nameColor = utils::isLightColor(this->trackColor, textColorLight, textColorDark)
297-
? textColorLight : textColorDark;
296+
this->nameColor = utils::chooseTextColor(this->trackColor, textColorLight, textColorDark);
298297

299298
this->sideChain->update(index);
300299

src/ui/component/sequencer/SeqTrackComponent.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void SeqTrackComponent::update(int index) {
134134
juce::Label::ColourIds::textWhenEditingColourId);
135135
auto textColorDark = laf.findColour(
136136
juce::Label::ColourIds::textColourId);
137-
this->idColor = utils::isLightColor(this->trackColor, textColorLight, textColorDark)
138-
? textColorLight : textColorDark;
137+
this->idColor = utils::chooseTextColor(this->trackColor, textColorLight, textColorDark);
139138

140139
auto name = quickAPI::getSeqTrackName(index);
141140
if (name.isEmpty()) {

src/ui/component/sequencer/SeqTrackContentViewer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void SeqTrackContentViewer::update(int index) {
7575
juce::Label::ColourIds::textWhenEditingColourId);
7676
auto textColorDark = laf.findColour(
7777
juce::Label::ColourIds::textColourId);
78-
this->nameColor = utils::isLightColor(this->trackColor, textColorLight, textColorDark)
79-
? textColorLight : textColorDark;
78+
this->nameColor = utils::chooseTextColor(this->trackColor, textColorLight, textColorDark);
8079

8180
if (changeData) {
8281
this->updateDataRef();

src/ui/lookAndFeel/editor/MidiContentLookAndFeel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ MidiContentLookAndFeel::MidiContentLookAndFeel()
1717

1818
/** Key Line */
1919
this->setColour(juce::MidiKeyboardComponent::ColourIds::whiteNoteColourId,
20-
ColorMap::getInstance()->get("ThemeColorB3"));
20+
ColorMap::getInstance()->get("ThemeColorB3"));/**< White Key Line */
2121
this->setColour(juce::MidiKeyboardComponent::ColourIds::blackNoteColourId,
22-
ColorMap::getInstance()->get("ThemeColorB2"));
22+
ColorMap::getInstance()->get("ThemeColorB2"));/**< Black Key Line */
2323
this->setColour(juce::MidiKeyboardComponent::ColourIds::keySeparatorLineColourId,
24-
ColorMap::getInstance()->get("ThemeColorB1"));
24+
ColorMap::getInstance()->get("ThemeColorB1"));/**< Line Split */
2525
this->setColour(juce::MidiKeyboardComponent::ColourIds::mouseOverKeyOverlayColourId,
2626
ColorMap::getInstance()->get("ThemeColorB5").withAlpha(0.5f));
2727
this->setColour(juce::MidiKeyboardComponent::ColourIds::keyDownOverlayColourId,
2828
ColorMap::getInstance()->get("ThemeColorB5").withAlpha(0.5f));
2929
this->setColour(juce::MidiKeyboardComponent::ColourIds::textLabelColourId,
30-
ColorMap::getInstance()->get("ThemeColorB4"));
30+
ColorMap::getInstance()->get("ThemeColorB0"));/**< Light Note Label */
31+
this->setColour(juce::MidiKeyboardComponent::ColourIds::textLabelColourId + 2,
32+
ColorMap::getInstance()->get("ThemeColorB10"));/**< Dark Note Label */
3133

3234
/** Lines */
3335
this->setColour(juce::Label::ColourIds::backgroundColourId,

0 commit comments

Comments
 (0)