Skip to content

Commit 6116623

Browse files
committedFeb 28, 2025·
Add note time editing event
1 parent e8490c8 commit 6116623

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed
 

‎src/ui/component/editor/MIDIContentViewer.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,35 @@ void MIDIContentViewer::mouseDown(const juce::MouseEvent& event) {
406406
this->noteInsertChannel = Tools::getInstance()->getMIDIChannel();
407407
this->repaint();
408408
}
409+
/** Edit Note */
410+
else if (type == NoteControllerType::Left || type == NoteControllerType::Right) {
411+
/** Get Time */
412+
double time = this->secStart + (pos.x / this->getWidth()) * (this->secEnd - this->secStart);
413+
time = quickAPI::limitTimeSec(time, Tools::getInstance()->getAdsorb());
414+
415+
/** Limit Note Length */
416+
int tempoIndex = quickAPI::getTempoTempIndexBySec(time);
417+
auto tempo = quickAPI::getTempoData(tempoIndex);
418+
double minLength = std::get<3>(tempo) / 64;
419+
420+
auto& [noteIndex, rect, channel] = this->noteRectTempList.getReference(index);
421+
auto& note = this->midiDataTemp.getReference(noteIndex);
422+
double noteStartTime = note.startSec;
423+
double noteEndTime = note.endSec;
424+
if (type == NoteControllerType::Right && time < noteStartTime + minLength) {
425+
time = noteStartTime + minLength;
426+
}
427+
else if (type == NoteControllerType::Left && time > noteEndTime - minLength) {
428+
time = noteEndTime - minLength;
429+
}
430+
431+
/** Set Temp */
432+
this->noteEditStatus = type;
433+
this->noteEditIndex = index;
434+
this->noteEditTime = time;
435+
this->noteEditMinLength = minLength;
436+
this->repaint();
437+
}
409438
}
410439
}
411440
}
@@ -433,6 +462,24 @@ void MIDIContentViewer::mouseUp(const juce::MouseEvent& event) {
433462
this->noteInsertChannel = 0;
434463
this->repaint();
435464
}
465+
466+
/** Edit Time */
467+
if (this->noteEditStatus == NoteControllerType::Left || this->noteEditStatus == NoteControllerType::Right) {
468+
/** Set Note Time */
469+
if (this->noteEditStatus == NoteControllerType::Left) {
470+
this->setNoteStartTime(this->noteEditIndex, this->noteEditTime);
471+
}
472+
else if (this->noteEditStatus == NoteControllerType::Right) {
473+
this->setNoteEndTime(this->noteEditIndex, this->noteEditTime);
474+
}
475+
476+
/** Reset Temp */
477+
this->noteEditStatus = NoteControllerType::None;
478+
this->noteEditIndex = -1;
479+
this->noteEditTime = -1;
480+
this->noteEditMinLength = -1;
481+
this->repaint();
482+
}
436483
}
437484
}
438485

@@ -487,6 +534,29 @@ void MIDIContentViewer::mouseDrag(const juce::MouseEvent& event) {
487534
this->noteInsertPitch = pitch;
488535
this->repaint();
489536
}
537+
538+
/** Edit Time */
539+
if (this->noteEditStatus == NoteControllerType::Left || this->noteEditStatus == NoteControllerType::Right) {
540+
/** Get Time */
541+
double time = this->secStart + (pos.x / this->getWidth()) * (this->secEnd - this->secStart);
542+
time = quickAPI::limitTimeSec(time, Tools::getInstance()->getAdsorb());
543+
544+
/** Limit Note Length */
545+
auto& [noteIndex, rect, channel] = this->noteRectTempList.getReference(this->noteEditIndex);
546+
auto& note = this->midiDataTemp.getReference(noteIndex);
547+
double noteStartTime = note.startSec;
548+
double noteEndTime = note.endSec;
549+
if (this->noteEditStatus == NoteControllerType::Right && time < noteStartTime + this->noteEditMinLength) {
550+
time = noteStartTime + this->noteEditMinLength;
551+
}
552+
else if (this->noteEditStatus == NoteControllerType::Left && time > noteEndTime - this->noteEditMinLength) {
553+
time = noteEndTime - this->noteEditMinLength;
554+
}
555+
556+
/** Set Temp */
557+
this->noteEditTime = time;
558+
this->repaint();
559+
}
490560
}
491561
}
492562

@@ -510,6 +580,16 @@ void MIDIContentViewer::mouseExit(const juce::MouseEvent& event) {
510580
this->noteInsertChannel = 0;
511581
this->repaint();
512582
}
583+
584+
/** Edit Time */
585+
if (this->noteEditStatus == NoteControllerType::Left || this->noteEditStatus == NoteControllerType::Right) {
586+
/** Reset Temp */
587+
this->noteEditStatus = NoteControllerType::None;
588+
this->noteEditIndex = -1;
589+
this->noteEditTime = -1;
590+
this->noteEditMinLength = -1;
591+
this->repaint();
592+
}
513593
}
514594

515595
void MIDIContentViewer::mouseWheelMove(
@@ -549,6 +629,14 @@ void MIDIContentViewer::insertNote(
549629
}
550630
}
551631

632+
void MIDIContentViewer::setNoteStartTime(int tempIndex, double time) {
633+
/** TODO */
634+
}
635+
636+
void MIDIContentViewer::setNoteEndTime(int tempIndex, double time) {
637+
/** TODO */
638+
}
639+
552640
void MIDIContentViewer::updateKeyImageTemp() {
553641
/** Clear Temp */
554642
juce::Graphics g(*(this->keyTemp.get()));

‎src/ui/component/editor/MIDIContentViewer.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ class MIDIContentViewer final
105105
double noteInsertTime = -1, noteInsertLength = -1;
106106
uint8_t noteInsertPitch = 0, noteInsertChannel = 0;
107107

108+
enum class NoteControllerType {
109+
None, Left, Right, Inside
110+
};
111+
NoteControllerType noteEditStatus = NoteControllerType::None;
112+
int noteEditIndex = -1;
113+
double noteEditTime = -1;
114+
double noteEditMinLength = -1;
115+
108116
std::unique_ptr<juce::Image> rulerTemp = nullptr;
109117
std::unique_ptr<juce::Image> keyTemp = nullptr;
110118
std::unique_ptr<juce::Image> blockTemp = nullptr;
@@ -122,6 +130,8 @@ class MIDIContentViewer final
122130
std::unique_ptr<juce::ChangeListener> midiChannelListener = nullptr;
123131

124132
void insertNote(double startTime, double length, uint8_t pitch, uint8_t channel);
133+
void setNoteStartTime(int tempIndex, double time);
134+
void setNoteEndTime(int tempIndex, double time);
125135

126136
void updateKeyImageTemp();
127137
void updateRulerImageTemp();
@@ -130,9 +140,6 @@ class MIDIContentViewer final
130140

131141
void updateMouseCursor(const juce::Point<float>& pos);
132142

133-
enum class NoteControllerType {
134-
None, Left, Right, Inside
135-
};
136143
std::tuple<NoteControllerType, int> getNoteController(const juce::Point<float>& pos) const;
137144
std::tuple<NoteControllerType, int> getNoteControllerWithoutEdge(const juce::Point<float>& pos) const;
138145

0 commit comments

Comments
 (0)
Please sign in to comment.