comparison layer/NoteLayer.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 984c1975f1ff
children
comparison
equal deleted inserted replaced
332:6440e280122e 374:64e84e5efb76
31 31
32 #include <QPainter> 32 #include <QPainter>
33 #include <QPainterPath> 33 #include <QPainterPath>
34 #include <QMouseEvent> 34 #include <QMouseEvent>
35 #include <QTextStream> 35 #include <QTextStream>
36 #include <QMessageBox>
36 37
37 #include <iostream> 38 #include <iostream>
38 #include <cmath> 39 #include <cmath>
39 40
40 NoteLayer::NoteLayer() : 41 NoteLayer::NoteLayer() :
41 SingleColourLayer(), 42 SingleColourLayer(),
42 m_model(0), 43 m_model(0),
43 m_editing(false), 44 m_editing(false),
44 m_originalPoint(0, 0.0, 0, tr("New Point")), 45 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
45 m_editingPoint(0, 0.0, 0, tr("New Point")), 46 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
46 m_editingCommand(0), 47 m_editingCommand(0),
47 m_verticalScale(AutoAlignScale) 48 m_verticalScale(AutoAlignScale)
48 { 49 {
49 50
50 } 51 }
617 if (frame < 0) frame = 0; 618 if (frame < 0) frame = 0;
618 frame = frame / m_model->getResolution() * m_model->getResolution(); 619 frame = frame / m_model->getResolution() * m_model->getResolution();
619 620
620 float value = getValueForY(v, e->y()); 621 float value = getValueForY(v, e->y());
621 622
622 m_editingPoint = NoteModel::Point(frame, value, 0, tr("New Point")); 623 m_editingPoint = NoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
623 m_originalPoint = m_editingPoint; 624 m_originalPoint = m_editingPoint;
624 625
625 if (m_editingCommand) m_editingCommand->finish(); 626 if (m_editingCommand) m_editingCommand->finish();
626 m_editingCommand = new NoteModel::EditCommand(m_model, 627 m_editingCommand = new NoteModel::EditCommand(m_model,
627 tr("Draw Point")); 628 tr("Draw Point"));
662 void 663 void
663 NoteLayer::drawEnd(View *, QMouseEvent *) 664 NoteLayer::drawEnd(View *, QMouseEvent *)
664 { 665 {
665 // std::cerr << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; 666 // std::cerr << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
666 if (!m_model || !m_editing) return; 667 if (!m_model || !m_editing) return;
668 m_editingCommand->finish();
669 m_editingCommand = 0;
670 m_editing = false;
671 }
672
673 void
674 NoteLayer::eraseStart(View *v, QMouseEvent *e)
675 {
676 if (!m_model) return;
677
678 NoteModel::PointList points = getLocalPoints(v, e->x());
679 if (points.empty()) return;
680
681 m_editingPoint = *points.begin();
682
683 if (m_editingCommand) {
684 m_editingCommand->finish();
685 m_editingCommand = 0;
686 }
687
688 m_editing = true;
689 }
690
691 void
692 NoteLayer::eraseDrag(View *v, QMouseEvent *e)
693 {
694 }
695
696 void
697 NoteLayer::eraseEnd(View *v, QMouseEvent *e)
698 {
699 if (!m_model || !m_editing) return;
700
701 m_editing = false;
702
703 NoteModel::PointList points = getLocalPoints(v, e->x());
704 if (points.empty()) return;
705 if (points.begin()->frame != m_editingPoint.frame ||
706 points.begin()->value != m_editingPoint.value) return;
707
708 m_editingCommand = new NoteModel::EditCommand
709 (m_model, tr("Erase Point"));
710
711 m_editingCommand->deletePoint(m_editingPoint);
712
667 m_editingCommand->finish(); 713 m_editingCommand->finish();
668 m_editingCommand = 0; 714 m_editingCommand = 0;
669 m_editing = false; 715 m_editing = false;
670 } 716 }
671 717
869 915
870 command->finish(); 916 command->finish();
871 } 917 }
872 918
873 void 919 void
874 NoteLayer::copy(Selection s, Clipboard &to) 920 NoteLayer::copy(View *v, Selection s, Clipboard &to)
875 { 921 {
876 if (!m_model) return; 922 if (!m_model) return;
877 923
878 NoteModel::PointList points = 924 NoteModel::PointList points =
879 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 925 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
880 926
881 for (NoteModel::PointList::iterator i = points.begin(); 927 for (NoteModel::PointList::iterator i = points.begin();
882 i != points.end(); ++i) { 928 i != points.end(); ++i) {
883 if (s.contains(i->frame)) { 929 if (s.contains(i->frame)) {
884 Clipboard::Point point(i->frame, i->value, i->duration, i->label); 930 Clipboard::Point point(i->frame, i->value, i->duration, i->level, i->label);
931 point.setReferenceFrame(alignToReference(v, i->frame));
885 to.addPoint(point); 932 to.addPoint(point);
886 } 933 }
887 } 934 }
888 } 935 }
889 936
890 bool 937 bool
891 NoteLayer::paste(const Clipboard &from, int frameOffset, bool /* interactive */) 938 NoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */)
892 { 939 {
893 if (!m_model) return false; 940 if (!m_model) return false;
894 941
895 const Clipboard::PointList &points = from.getPoints(); 942 const Clipboard::PointList &points = from.getPoints();
943
944 bool realign = false;
945
946 if (clipboardHasDifferentAlignment(v, from)) {
947
948 QMessageBox::StandardButton button =
949 QMessageBox::question(v, tr("Re-align pasted items?"),
950 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
951 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
952 QMessageBox::Yes);
953
954 if (button == QMessageBox::Cancel) {
955 return false;
956 }
957
958 if (button == QMessageBox::Yes) {
959 realign = true;
960 }
961 }
896 962
897 NoteModel::EditCommand *command = 963 NoteModel::EditCommand *command =
898 new NoteModel::EditCommand(m_model, tr("Paste")); 964 new NoteModel::EditCommand(m_model, tr("Paste"));
899 965
900 for (Clipboard::PointList::const_iterator i = points.begin(); 966 for (Clipboard::PointList::const_iterator i = points.begin();
901 i != points.end(); ++i) { 967 i != points.end(); ++i) {
902 968
903 if (!i->haveFrame()) continue; 969 if (!i->haveFrame()) continue;
904 size_t frame = 0; 970 size_t frame = 0;
905 if (frameOffset > 0 || -frameOffset < i->getFrame()) { 971
906 frame = i->getFrame() + frameOffset; 972 if (!realign) {
973
974 frame = i->getFrame();
975
976 } else {
977
978 if (i->haveReferenceFrame()) {
979 frame = i->getReferenceFrame();
980 frame = alignFromReference(v, frame);
981 } else {
982 frame = i->getFrame();
983 }
907 } 984 }
985
908 NoteModel::Point newPoint(frame); 986 NoteModel::Point newPoint(frame);
909 987
910 if (i->haveLabel()) newPoint.label = i->getLabel(); 988 if (i->haveLabel()) newPoint.label = i->getLabel();
911 if (i->haveValue()) newPoint.value = i->getValue(); 989 if (i->haveValue()) newPoint.value = i->getValue();
912 else newPoint.value = (m_model->getValueMinimum() + 990 else newPoint.value = (m_model->getValueMinimum() +
913 m_model->getValueMaximum()) / 2; 991 m_model->getValueMaximum()) / 2;
992 if (i->haveLevel()) newPoint.level = i->getLevel();
914 if (i->haveDuration()) newPoint.duration = i->getDuration(); 993 if (i->haveDuration()) newPoint.duration = i->getDuration();
915 else { 994 else {
916 size_t nextFrame = frame; 995 size_t nextFrame = frame;
917 Clipboard::PointList::const_iterator j = i; 996 Clipboard::PointList::const_iterator j = i;
918 for (; j != points.end(); ++j) { 997 for (; j != points.end(); ++j) {