|
1 | 1 | #include "MIDIContentViewer.h"
|
| 2 | +#include "../../misc/Tools.h" |
2 | 3 | #include "../../lookAndFeel/LookAndFeelFactory.h"
|
3 | 4 | #include "../../Utils.h"
|
4 | 5 | #include "../../../audioCore/AC_API.h"
|
@@ -296,6 +297,9 @@ void MIDIContentViewer::mouseUp(const juce::MouseEvent& event) {
|
296 | 297 | void MIDIContentViewer::mouseMove(const juce::MouseEvent& event) {
|
297 | 298 | /** Send Y Pos */
|
298 | 299 | this->mouseYPosFunc(event.position.getY());
|
| 300 | + |
| 301 | + /** Update Mouse Cursor */ |
| 302 | + this->updateMouseCursor(event.position); |
299 | 303 | }
|
300 | 304 |
|
301 | 305 | void MIDIContentViewer::mouseDrag(const juce::MouseEvent& event) {
|
@@ -528,9 +532,13 @@ void MIDIContentViewer::updateNoteImageTemp() {
|
528 | 532 | juce::Font noteLabelFont(juce::FontOptions{ noteFontHeight });
|
529 | 533 | juce::Font noteLyricsFont(juce::FontOptions{ noteLyricsFontHeight });
|
530 | 534 |
|
| 535 | + /** Temp */ |
| 536 | + this->noteRectTempList.clear(); |
| 537 | + |
531 | 538 | /** Notes */
|
532 | 539 | int minNoteNum = std::floor(this->keyBottom), maxNoteNum = std::floor(this->keyTop);
|
533 |
| - for (auto& note : this->midiDataTemp) { |
| 540 | + for (int i = 0; i < this->midiDataTemp.size(); i++) { |
| 541 | + auto& note = this->midiDataTemp.getReference(i); |
534 | 542 | if (note.startSec <= this->secEnd &&
|
535 | 543 | this->secStart <= note.endSec) {
|
536 | 544 | if (note.num >= (minNoteNum - 1) &&
|
@@ -570,11 +578,119 @@ void MIDIContentViewer::updateNoteImageTemp() {
|
570 | 578 | g.drawFittedText(note.lyrics, noteLyricsRect.toNearestInt(),
|
571 | 579 | juce::Justification::left, 1, 1.0f);
|
572 | 580 | }
|
| 581 | + |
| 582 | + /** Add Temp */ |
| 583 | + this->noteRectTempList.add({ i, noteRect }); |
573 | 584 | }
|
574 | 585 | }
|
575 | 586 | }
|
576 | 587 | }
|
577 | 588 |
|
| 589 | +void MIDIContentViewer::updateMouseCursor(const juce::Point<float>& pos) { |
| 590 | + std::tuple<MIDIContentViewer::NoteControllerType, int> noteController; |
| 591 | + switch (Tools::getInstance()->getType()) { |
| 592 | + case Tools::Type::Arrow: |
| 593 | + noteController = this->getNoteControllerWithoutEdge(pos); |
| 594 | + break; |
| 595 | + case Tools::Type::Pencil: |
| 596 | + noteController = this->getNoteController(pos); |
| 597 | + break; |
| 598 | + } |
| 599 | + |
| 600 | + switch (std::get<0>(noteController)) { |
| 601 | + case NoteControllerType::Left: |
| 602 | + this->setMouseCursor(juce::MouseCursor::LeftEdgeResizeCursor); |
| 603 | + break; |
| 604 | + case NoteControllerType::Right: |
| 605 | + this->setMouseCursor(juce::MouseCursor::RightEdgeResizeCursor); |
| 606 | + break; |
| 607 | + case NoteControllerType::Inside: |
| 608 | + this->setMouseCursor(juce::MouseCursor::PointingHandCursor); |
| 609 | + break; |
| 610 | + default: |
| 611 | + this->setMouseCursor(juce::MouseCursor::NormalCursor); |
| 612 | + break; |
| 613 | + } |
| 614 | +} |
| 615 | + |
| 616 | +std::tuple<MIDIContentViewer::NoteControllerType, int> |
| 617 | +MIDIContentViewer::getNoteController(const juce::Point<float>& pos) const { |
| 618 | + /** Size */ |
| 619 | + auto screenSize = utils::getScreenSize(this); |
| 620 | + int noteJudgeWidth = screenSize.getWidth() * 0.005; |
| 621 | + |
| 622 | + int width = this->noteTemp->getWidth(), height = this->noteTemp->getHeight(); |
| 623 | + |
| 624 | + /** Check Pos Inside Note */ |
| 625 | + auto [type, index] = this->getNoteControllerWithoutEdge(pos); |
| 626 | + if (index >= 0) { |
| 627 | + auto& note = this->midiDataTemp.getReference(index); |
| 628 | + float startXPos = (note.startSec - this->secStart) / (this->secEnd - this->secStart) * width; |
| 629 | + float endXPos = (note.endSec - this->secStart) / (this->secEnd - this->secStart) * width; |
| 630 | + |
| 631 | + /** Judge Area */ |
| 632 | + float judgeSSX = startXPos - noteJudgeWidth, judgeSEX = startXPos + noteJudgeWidth; |
| 633 | + float judgeESX = endXPos - noteJudgeWidth, judgeEEX = endXPos + noteJudgeWidth; |
| 634 | + if (endXPos - startXPos < noteJudgeWidth * 2) { |
| 635 | + judgeSEX = startXPos + (endXPos - startXPos) / 2; |
| 636 | + judgeESX = endXPos - (endXPos - startXPos) / 2; |
| 637 | + } |
| 638 | + |
| 639 | + /** Get Controller */ |
| 640 | + if (pos.getX() >= judgeSSX && pos.getX() < judgeSEX) { |
| 641 | + return { NoteControllerType::Left, index }; |
| 642 | + } |
| 643 | + else if (pos.getX() >= judgeESX && pos.getX() < judgeEEX) { |
| 644 | + return { NoteControllerType::Right, index }; |
| 645 | + } |
| 646 | + else if (pos.getX() >= judgeSEX && pos.getX() < judgeESX) { |
| 647 | + return { NoteControllerType::Inside, index }; |
| 648 | + } |
| 649 | + } |
| 650 | + |
| 651 | + /** Get Each Block */ |
| 652 | + for (auto& [index, rect] : this->noteRectTempList) { |
| 653 | + if (pos.getY() >= rect.getY() && pos.getY() < rect.getBottom()) { |
| 654 | + /** Judge Area */ |
| 655 | + float judgeSSX = rect.getX() - noteJudgeWidth, judgeSEX = rect.getX() + noteJudgeWidth; |
| 656 | + float judgeESX = rect.getRight() - noteJudgeWidth, judgeEEX = rect.getRight() + noteJudgeWidth; |
| 657 | + if (rect.getRight() - rect.getX() < noteJudgeWidth * 2) { |
| 658 | + judgeSEX = rect.getX() + (rect.getRight() - rect.getX()) / 2; |
| 659 | + judgeESX = rect.getRight() - (rect.getRight() - rect.getX()) / 2; |
| 660 | + } |
| 661 | + |
| 662 | + /** Get Controller */ |
| 663 | + if (pos.getX() >= judgeSSX && pos.getX() < judgeSEX) { |
| 664 | + return { NoteControllerType::Left, index }; |
| 665 | + } |
| 666 | + else if (pos.getX() >= judgeESX && pos.getX() < judgeEEX) { |
| 667 | + return { NoteControllerType::Right, index }; |
| 668 | + } |
| 669 | + else if (pos.getX() >= judgeSEX && pos.getX() < judgeESX) { |
| 670 | + return { NoteControllerType::Inside, index }; |
| 671 | + } |
| 672 | + } |
| 673 | + } |
| 674 | + |
| 675 | + /** None */ |
| 676 | + return { NoteControllerType::None, -1 }; |
| 677 | +} |
| 678 | + |
| 679 | +std::tuple<MIDIContentViewer::NoteControllerType, int> |
| 680 | +MIDIContentViewer::getNoteControllerWithoutEdge(const juce::Point<float>& pos) const { |
| 681 | + /** Get Each Note */ |
| 682 | + for (auto& [index, rect] : this->noteRectTempList) { |
| 683 | + /** Inside Note */ |
| 684 | + if (pos.getX() >= rect.getX() && pos.getX() < rect.getRight() |
| 685 | + && pos.getY() >= rect.getY() && pos.getY() < rect.getBottom()) { |
| 686 | + return { NoteControllerType::Inside, index }; |
| 687 | + } |
| 688 | + } |
| 689 | + |
| 690 | + /** None */ |
| 691 | + return { NoteControllerType::None, -1 }; |
| 692 | +} |
| 693 | + |
578 | 694 | std::tuple<double, double> MIDIContentViewer::getHViewArea(double pos, double itemSize) const {
|
579 | 695 | double secStart = pos / itemSize;
|
580 | 696 | double secLength = this->getWidth() / itemSize;
|
|
0 commit comments