Skip to content

Commit

Permalink
Add seq block note paint
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed May 23, 2024
1 parent 7bb5d5e commit ffb478f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/ui/component/sequencer/SeqTrackContentViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ void SeqTrackContentViewer::paint(juce::Graphics& g) {

float blockNameFontHeight = screenSize.getHeight() * 0.015;

float noteMaxHeight = screenSize.getHeight() * 0.015;

/** Color */
auto& laf = this->getLookAndFeel();
juce::Colour outlineColor = laf.findColour(
Expand Down Expand Up @@ -294,6 +296,69 @@ void SeqTrackContentViewer::paint(juce::Graphics& g) {
}
}
}

/** Note */
if (!this->compressed) {
/** Select Time */
double startSec = std::max(block->startTime + block->offset, this->secStart);
double endSec = std::min(block->endTime + block->offset, this->secEnd);

/** Content Area */
float notePosY = blockPaddingHeight + blockNameFontHeight + blockPaddingHeight;
float noteAreaHeight = this->getHeight() - blockPaddingHeight - notePosY;
juce::Rectangle<float> noteContentRect(0, notePosY, this->getWidth(), noteAreaHeight);

/** Limit Note Height */
double minNoteID = this->midiMinNote, maxNoteID = this->midiMaxNote;
float noteHeight = noteAreaHeight / (maxNoteID - minNoteID + 1);
if (noteHeight > noteMaxHeight) {
noteHeight = noteMaxHeight;

double centerNoteID = minNoteID + (maxNoteID - minNoteID) / 2;
minNoteID = centerNoteID - ((noteAreaHeight / noteHeight + 1) / 2 - 1);
maxNoteID = centerNoteID + ((noteAreaHeight / noteHeight + 1) / 2 - 1);
}

/** Paint Each MIDI Track */
g.setColour(this->nameColor);
int trackNum = this->midiDataTemp.getNumTracks();
for (int i = 0; i < trackNum; i++) {
auto track = this->midiDataTemp.getTrack(i);

/** Paint Each Note */
std::array<double, 128> noteStartTime{};
for (int i = 0; i < 128; i++) {
noteStartTime[i] = -1;
}

for (auto event : *track) {
if (event->message.isNoteOn(true)) {
int noteNumber = event->message.getNoteNumber();
if (noteNumber >= 0 && noteNumber < 128) {
noteStartTime[noteNumber] = event->message.getTimeStamp();
}
}
else if (event->message.isNoteOff(false)) {
int noteNumber = event->message.getNoteNumber();
if (noteNumber >= 0 && noteNumber < 128) {
double noteStart = noteStartTime[noteNumber];
noteStartTime[noteNumber] = -1;
if (noteStart >= 0) {
double noteEnd = event->message.getTimeStamp();
if (noteStart <= endSec && noteEnd >= startSec) {
juce::Rectangle<float> noteRect(
(noteStart - this->secStart) / (this->secEnd - this->secStart) * this->getWidth(),
notePosY + (maxNoteID - event->message.getNoteNumber()) * noteHeight,
(noteEnd - noteStart) / (this->secEnd - this->secStart) * this->getWidth(),
noteHeight);
g.fillRect(noteRect);
}
}
}
}
}
}
}
}
}
}
Expand Down

0 comments on commit ffb478f

Please sign in to comment.