comparison layer/FlexiNoteLayer.cpp @ 810:b68af2be4545 tonioni

Merge from branch warnfix_no_size_t
author Chris Cannam
date Wed, 18 Jun 2014 13:42:25 +0100
parents 40c6c9344ff6
children a9731b49745a
comparison
equal deleted inserted replaced
802:584b11df8e4f 810:b68af2be4545
59 // m_scaleMinimum(0), 59 // m_scaleMinimum(0),
60 // m_scaleMaximum(0) 60 // m_scaleMaximum(0)
61 61
62 m_model(0), 62 m_model(0),
63 m_editing(false), 63 m_editing(false),
64 m_intelligentActions(true),
64 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), 65 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")),
65 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), 66 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")),
66 m_editingCommand(0), 67 m_editingCommand(0),
67 m_verticalScale(AutoAlignScale), 68 m_verticalScale(AutoAlignScale),
68 m_editMode(DragNote), 69 m_editMode(DragNote),
69 m_scaleMinimum(34), 70 m_scaleMinimum(34),
70 m_scaleMaximum(77), 71 m_scaleMaximum(77)
71 m_intelligentActions(true)
72 { 72 {
73 } 73 }
74 74
75 void 75 void
76 FlexiNoteLayer::setModel(FlexiNoteModel *model) 76 FlexiNoteLayer::setModel(FlexiNoteModel *model)
401 FlexiNoteModel::PointList 401 FlexiNoteModel::PointList
402 FlexiNoteLayer::getLocalPoints(View *v, int x) const 402 FlexiNoteLayer::getLocalPoints(View *v, int x) const
403 { 403 {
404 if (!m_model) return FlexiNoteModel::PointList(); 404 if (!m_model) return FlexiNoteModel::PointList();
405 405
406 long frame = v->getFrameForX(x); 406 int frame = v->getFrameForX(x);
407 407
408 FlexiNoteModel::PointList onPoints = 408 FlexiNoteModel::PointList onPoints =
409 m_model->getPoints(frame); 409 m_model->getPoints(frame);
410 410
411 if (!onPoints.empty()) { 411 if (!onPoints.empty()) {
419 419
420 FlexiNoteModel::PointList usePoints = prevPoints; 420 FlexiNoteModel::PointList usePoints = prevPoints;
421 421
422 if (prevPoints.empty()) { 422 if (prevPoints.empty()) {
423 usePoints = nextPoints; 423 usePoints = nextPoints;
424 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 424 } else if (prevPoints.begin()->frame < v->getStartFrame() &&
425 !(nextPoints.begin()->frame > v->getEndFrame())) { 425 !(nextPoints.begin()->frame > v->getEndFrame())) {
426 usePoints = nextPoints; 426 usePoints = nextPoints;
427 } else if (long(nextPoints.begin()->frame) - frame < 427 } else if (nextPoints.begin()->frame - frame <
428 frame - long(prevPoints.begin()->frame)) { 428 frame - prevPoints.begin()->frame) {
429 usePoints = nextPoints; 429 usePoints = nextPoints;
430 } 430 }
431 431
432 if (!usePoints.empty()) { 432 if (!usePoints.empty()) {
433 int fuzz = 2; 433 int fuzz = 2;
444 bool 444 bool
445 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const 445 FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const
446 { 446 {
447 if (!m_model) return false; 447 if (!m_model) return false;
448 448
449 long frame = v->getFrameForX(x); 449 int frame = v->getFrameForX(x);
450 450
451 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); 451 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
452 if (onPoints.empty()) return false; 452 if (onPoints.empty()) return false;
453 453
454 // cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << endl; 454 // cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << endl;
473 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const 473 FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const
474 { 474 {
475 // GF: find the note that is closest to the cursor 475 // GF: find the note that is closest to the cursor
476 if (!m_model) return false; 476 if (!m_model) return false;
477 477
478 long frame = v->getFrameForX(x); 478 int frame = v->getFrameForX(x);
479 479
480 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); 480 FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
481 if (onPoints.empty()) return false; 481 if (onPoints.empty()) return false;
482 482
483 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl; 483 // std::cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << std::endl;
586 return text; 586 return text;
587 } 587 }
588 588
589 bool 589 bool
590 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame, 590 FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
591 size_t &resolution, 591 int &resolution,
592 SnapType snap) const 592 SnapType snap) const
593 { 593 {
594 if (!m_model) { 594 if (!m_model) {
595 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 595 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
596 } 596 }
796 if (!sampleRate) return; 796 if (!sampleRate) return;
797 797
798 // Profiler profiler("FlexiNoteLayer::paint", true); 798 // Profiler profiler("FlexiNoteLayer::paint", true);
799 799
800 int x0 = rect.left(), x1 = rect.right(); 800 int x0 = rect.left(), x1 = rect.right();
801 long frame0 = v->getFrameForX(x0); 801 int frame0 = v->getFrameForX(x0);
802 long frame1 = v->getFrameForX(x1); 802 int frame1 = v->getFrameForX(x1);
803 803
804 FlexiNoteModel::PointList points(m_model->getPoints(frame0, frame1)); 804 FlexiNoteModel::PointList points(m_model->getPoints(frame0, frame1));
805 if (points.empty()) return; 805 if (points.empty()) return;
806 806
807 paint.setPen(getBaseQColor()); 807 paint.setPen(getBaseQColor());
817 if (max == min) max = min + 1.0; 817 if (max == min) max = min + 1.0;
818 818
819 QPoint localPos; 819 QPoint localPos;
820 FlexiNoteModel::Point illuminatePoint(0); 820 FlexiNoteModel::Point illuminatePoint(0);
821 bool shouldIlluminate = false; 821 bool shouldIlluminate = false;
822
823 822
824 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 823 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
825 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), 824 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(),
826 illuminatePoint); 825 illuminatePoint);
827 } 826 }
948 { 947 {
949 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; 948 // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl;
950 949
951 if (!m_model) return; 950 if (!m_model) return;
952 951
953 long frame = v->getFrameForX(e->x()); 952 int frame = v->getFrameForX(e->x());
954 if (frame < 0) frame = 0; 953 if (frame < 0) frame = 0;
955 frame = frame / m_model->getResolution() * m_model->getResolution(); 954 frame = frame / m_model->getResolution() * m_model->getResolution();
956 955
957 float value = getValueForY(v, e->y()); 956 float value = getValueForY(v, e->y());
958 957
972 { 971 {
973 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; 972 // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl;
974 973
975 if (!m_model || !m_editing) return; 974 if (!m_model || !m_editing) return;
976 975
977 long frame = v->getFrameForX(e->x()); 976 int frame = v->getFrameForX(e->x());
978 if (frame < 0) frame = 0; 977 if (frame < 0) frame = 0;
979 frame = frame / m_model->getResolution() * m_model->getResolution(); 978 frame = frame / m_model->getResolution() * m_model->getResolution();
980 979
981 float newValue = getValueForY(v, e->y()); 980 float newValue = getValueForY(v, e->y());
982 981
983 long newFrame = m_editingPoint.frame; 982 int newFrame = m_editingPoint.frame;
984 long newDuration = frame - newFrame; 983 int newDuration = frame - newFrame;
985 if (newDuration < 0) { 984 if (newDuration < 0) {
986 newFrame = frame; 985 newFrame = frame;
987 newDuration = -newDuration; 986 newDuration = -newDuration;
988 } else if (newDuration == 0) { 987 } else if (newDuration == 0) {
989 newDuration = 1; 988 newDuration = 1;
1020 1019
1021 m_editing = true; 1020 m_editing = true;
1022 } 1021 }
1023 1022
1024 void 1023 void
1025 FlexiNoteLayer::eraseDrag(View *v, QMouseEvent *e) 1024 FlexiNoteLayer::eraseDrag(View *, QMouseEvent *)
1026 { 1025 {
1027 } 1026 }
1028 1027
1029 void 1028 void
1030 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e) 1029 FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e)
1071 1070
1072 m_editing = true; 1071 m_editing = true;
1073 m_dragStartX = e->x(); 1072 m_dragStartX = e->x();
1074 m_dragStartY = e->y(); 1073 m_dragStartY = e->y();
1075 1074
1076 long onset = m_originalPoint.frame; 1075 int onset = m_originalPoint.frame;
1077 long offset = m_originalPoint.frame + m_originalPoint.duration - 1; 1076 int offset = m_originalPoint.frame + m_originalPoint.duration - 1;
1078 1077
1079 m_greatestLeftNeighbourFrame = -1; 1078 m_greatestLeftNeighbourFrame = -1;
1080 m_smallestRightNeighbourFrame = std::numeric_limits<long>::max(); 1079 m_smallestRightNeighbourFrame = std::numeric_limits<int>::max();
1081 1080
1082 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); 1081 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
1083 i != m_model->getPoints().end(); ++i) { 1082 i != m_model->getPoints().end(); ++i) {
1084 FlexiNote currentNote = *i; 1083 FlexiNote currentNote = *i;
1085 1084
1108 int xdist = e->x() - m_dragStartX; 1107 int xdist = e->x() - m_dragStartX;
1109 int ydist = e->y() - m_dragStartY; 1108 int ydist = e->y() - m_dragStartY;
1110 int newx = m_dragPointX + xdist; 1109 int newx = m_dragPointX + xdist;
1111 int newy = m_dragPointY + ydist; 1110 int newy = m_dragPointY + ydist;
1112 1111
1113 long dragFrame = v->getFrameForX(newx); 1112 int dragFrame = v->getFrameForX(newx);
1114 if (dragFrame < 0) dragFrame = 0; 1113 if (dragFrame < 0) dragFrame = 0;
1115 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution(); 1114 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution();
1116 1115
1117 float value = getValueForY(v, newy); 1116 float value = getValueForY(v, newy);
1118 1117
1153 } 1152 }
1154 m_editingPoint.frame = dragFrame; 1153 m_editingPoint.frame = dragFrame;
1155 m_editingPoint.value = value; 1154 m_editingPoint.value = value;
1156 break; 1155 break;
1157 } 1156 }
1157 case SplitNote: // nothing
1158 break;
1158 } 1159 }
1159 updateNoteValue(v, m_editingPoint); 1160 updateNoteValue(v, m_editingPoint);
1160 m_editingCommand->addPoint(m_editingPoint); 1161 m_editingCommand->addPoint(m_editingPoint);
1161 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; 1162 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
1162 1163
1163 } 1164 }
1164 1165
1165 void 1166 void
1166 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e) 1167 FlexiNoteLayer::editEnd(View *, QMouseEvent *e)
1167 { 1168 {
1168 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; 1169 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl;
1169 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; 1170 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
1170 1171
1171 if (!m_model || !m_editing) return; 1172 if (!m_model || !m_editing) return;
1228 if (xdist != 0 || ydist != 0) { 1229 if (xdist != 0 || ydist != 0) {
1229 std::cerr << "mouse moved" << std::endl; 1230 std::cerr << "mouse moved" << std::endl;
1230 return; 1231 return;
1231 } 1232 }
1232 1233
1233 long frame = v->getFrameForX(e->x()); 1234 int frame = v->getFrameForX(e->x());
1234 1235
1235 splitNotesAt(v, frame, e); 1236 splitNotesAt(v, frame, e);
1236 } 1237 }
1237 1238
1238 void 1239 void
1285 FlexiNoteLayer::addNote(View *v, QMouseEvent *e) 1286 FlexiNoteLayer::addNote(View *v, QMouseEvent *e)
1286 { 1287 {
1287 std::cerr << "addNote" << std::endl; 1288 std::cerr << "addNote" << std::endl;
1288 if (!m_model) return; 1289 if (!m_model) return;
1289 1290
1290 long duration = 10000; 1291 int duration = 10000;
1291 1292
1292 long frame = v->getFrameForX(e->x()); 1293 int frame = v->getFrameForX(e->x());
1293 float value = getValueForY(v, e->y()); 1294 float value = getValueForY(v, e->y());
1294 1295
1295 FlexiNoteModel::PointList noteList = m_model->getPoints(); 1296 FlexiNoteModel::PointList noteList = m_model->getPoints();
1296 1297
1297 if (m_intelligentActions) { 1298 if (m_intelligentActions) {
1298 long smallestRightNeighbourFrame = 0; 1299 int smallestRightNeighbourFrame = 0;
1299 for (FlexiNoteModel::PointList::const_iterator i = noteList.begin(); 1300 for (FlexiNoteModel::PointList::const_iterator i = noteList.begin();
1300 i != noteList.end(); ++i) { 1301 i != noteList.end(); ++i) {
1301 FlexiNote currentNote = *i; 1302 FlexiNote currentNote = *i;
1302 if (currentNote.frame > frame) { 1303 if (currentNote.frame > frame) {
1303 smallestRightNeighbourFrame = currentNote.frame; 1304 smallestRightNeighbourFrame = currentNote.frame;
1451 } 1452 }
1452 1453
1453 if (pitchValues.empty()) return false; 1454 if (pitchValues.empty()) return false;
1454 1455
1455 sort(pitchValues.begin(), pitchValues.end()); 1456 sort(pitchValues.begin(), pitchValues.end());
1456 size_t size = pitchValues.size(); 1457 int size = pitchValues.size();
1457 double median; 1458 double median;
1458 1459
1459 if (size % 2 == 0) { 1460 if (size % 2 == 0) {
1460 median = (pitchValues[size/2 - 1] + pitchValues[size/2]) / 2; 1461 median = (pitchValues[size/2 - 1] + pitchValues[size/2]) / 2;
1461 } else { 1462 } else {
1566 delete dialog; 1567 delete dialog;
1567 return true; 1568 return true;
1568 } 1569 }
1569 1570
1570 void 1571 void
1571 FlexiNoteLayer::moveSelection(Selection s, size_t newStartFrame) 1572 FlexiNoteLayer::moveSelection(Selection s, int newStartFrame)
1572 { 1573 {
1573 if (!m_model) return; 1574 if (!m_model) return;
1574 1575
1575 FlexiNoteModel::EditCommand *command = 1576 FlexiNoteModel::EditCommand *command =
1576 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection")); 1577 new FlexiNoteModel::EditCommand(m_model, tr("Drag Selection"));
1695 } 1696 }
1696 } 1697 }
1697 } 1698 }
1698 1699
1699 bool 1700 bool
1700 FlexiNoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */) 1701 FlexiNoteLayer::paste(View *v, const Clipboard &from, int /*frameOffset */, bool /* interactive */)
1701 { 1702 {
1702 if (!m_model) return false; 1703 if (!m_model) return false;
1703 1704
1704 const Clipboard::PointList &points = from.getPoints(); 1705 const Clipboard::PointList &points = from.getPoints();
1705 1706
1727 1728
1728 for (Clipboard::PointList::const_iterator i = points.begin(); 1729 for (Clipboard::PointList::const_iterator i = points.begin();
1729 i != points.end(); ++i) { 1730 i != points.end(); ++i) {
1730 1731
1731 if (!i->haveFrame()) continue; 1732 if (!i->haveFrame()) continue;
1732 size_t frame = 0; 1733 int frame = 0;
1733 1734
1734 if (!realign) { 1735 if (!realign) {
1735 1736
1736 frame = i->getFrame(); 1737 frame = i->getFrame();
1737 1738
1752 else newPoint.value = (m_model->getValueMinimum() + 1753 else newPoint.value = (m_model->getValueMinimum() +
1753 m_model->getValueMaximum()) / 2; 1754 m_model->getValueMaximum()) / 2;
1754 if (i->haveLevel()) newPoint.level = i->getLevel(); 1755 if (i->haveLevel()) newPoint.level = i->getLevel();
1755 if (i->haveDuration()) newPoint.duration = i->getDuration(); 1756 if (i->haveDuration()) newPoint.duration = i->getDuration();
1756 else { 1757 else {
1757 size_t nextFrame = frame; 1758 int nextFrame = frame;
1758 Clipboard::PointList::const_iterator j = i; 1759 Clipboard::PointList::const_iterator j = i;
1759 for (; j != points.end(); ++j) { 1760 for (; j != points.end(); ++j) {
1760 if (!j->haveFrame()) continue; 1761 if (!j->haveFrame()) continue;
1761 if (j != i) break; 1762 if (j != i) break;
1762 } 1763 }
1776 finish(command); 1777 finish(command);
1777 return true; 1778 return true;
1778 } 1779 }
1779 1780
1780 void 1781 void
1781 FlexiNoteLayer::addNoteOn(long frame, int pitch, int velocity) 1782 FlexiNoteLayer::addNoteOn(int frame, int pitch, int velocity)
1782 { 1783 {
1783 m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, "")); 1784 m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, ""));
1784 } 1785 }
1785 1786
1786 void 1787 void
1787 FlexiNoteLayer::addNoteOff(long frame, int pitch) 1788 FlexiNoteLayer::addNoteOff(int frame, int pitch)
1788 { 1789 {
1789 for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin(); 1790 for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin();
1790 i != m_pendingNoteOns.end(); ++i) { 1791 i != m_pendingNoteOns.end(); ++i) {
1791 if (lrintf((*i).value) == pitch) { 1792 if (lrintf((*i).value) == pitch) {
1792 FlexiNote note(*i); 1793 FlexiNote note(*i);
1831 void 1832 void
1832 FlexiNoteLayer::setProperties(const QXmlAttributes &attributes) 1833 FlexiNoteLayer::setProperties(const QXmlAttributes &attributes)
1833 { 1834 {
1834 SingleColourLayer::setProperties(attributes); 1835 SingleColourLayer::setProperties(attributes);
1835 1836
1836 bool ok, alsoOk; 1837 bool ok;
1837 VerticalScale scale = (VerticalScale) 1838 VerticalScale scale = (VerticalScale)
1838 attributes.value("verticalScale").toInt(&ok); 1839 attributes.value("verticalScale").toInt(&ok);
1839 if (ok) setVerticalScale(scale); 1840 if (ok) setVerticalScale(scale);
1840 1841
1841 float min = attributes.value("scaleMinimum").toFloat(&ok); 1842 // bool alsoOk;
1842 float max = attributes.value("scaleMaximum").toFloat(&alsoOk); 1843 // float min = attributes.value("scaleMinimum").toFloat(&ok);
1844 // float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
1843 // if (ok && alsoOk && min != max) setDisplayExtents(min, max); 1845 // if (ok && alsoOk && min != max) setDisplayExtents(min, max);
1844 } 1846 }
1845 1847
1846 void 1848 void
1847 FlexiNoteLayer::setVerticalRangeToNoteRange(View *v) 1849 FlexiNoteLayer::setVerticalRangeToNoteRange(View *v)