Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 810:b68af2be4545 tonioni
Merge from branch warnfix_no_size_t
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 13:42:25 +0100 |
parents | 4c8ca536b54f |
children | 0f5961c1bb6c |
comparison
equal
deleted
inserted
replaced
802:584b11df8e4f | 810:b68af2be4545 |
---|---|
387 NoteModel::PointList | 387 NoteModel::PointList |
388 NoteLayer::getLocalPoints(View *v, int x) const | 388 NoteLayer::getLocalPoints(View *v, int x) const |
389 { | 389 { |
390 if (!m_model) return NoteModel::PointList(); | 390 if (!m_model) return NoteModel::PointList(); |
391 | 391 |
392 long frame = v->getFrameForX(x); | 392 int frame = v->getFrameForX(x); |
393 | 393 |
394 NoteModel::PointList onPoints = | 394 NoteModel::PointList onPoints = |
395 m_model->getPoints(frame); | 395 m_model->getPoints(frame); |
396 | 396 |
397 if (!onPoints.empty()) { | 397 if (!onPoints.empty()) { |
405 | 405 |
406 NoteModel::PointList usePoints = prevPoints; | 406 NoteModel::PointList usePoints = prevPoints; |
407 | 407 |
408 if (prevPoints.empty()) { | 408 if (prevPoints.empty()) { |
409 usePoints = nextPoints; | 409 usePoints = nextPoints; |
410 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && | 410 } else if (int(prevPoints.begin()->frame) < v->getStartFrame() && |
411 !(nextPoints.begin()->frame > v->getEndFrame())) { | 411 !(nextPoints.begin()->frame > v->getEndFrame())) { |
412 usePoints = nextPoints; | 412 usePoints = nextPoints; |
413 } else if (long(nextPoints.begin()->frame) - frame < | 413 } else if (int(nextPoints.begin()->frame) - frame < |
414 frame - long(prevPoints.begin()->frame)) { | 414 frame - int(prevPoints.begin()->frame)) { |
415 usePoints = nextPoints; | 415 usePoints = nextPoints; |
416 } | 416 } |
417 | 417 |
418 if (!usePoints.empty()) { | 418 if (!usePoints.empty()) { |
419 int fuzz = 2; | 419 int fuzz = 2; |
430 bool | 430 bool |
431 NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const | 431 NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const |
432 { | 432 { |
433 if (!m_model) return false; | 433 if (!m_model) return false; |
434 | 434 |
435 long frame = v->getFrameForX(x); | 435 int frame = v->getFrameForX(x); |
436 | 436 |
437 NoteModel::PointList onPoints = m_model->getPoints(frame); | 437 NoteModel::PointList onPoints = m_model->getPoints(frame); |
438 if (onPoints.empty()) return false; | 438 if (onPoints.empty()) return false; |
439 | 439 |
440 // cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << endl; | 440 // cerr << "frame " << frame << ": " << onPoints.size() << " candidate points" << endl; |
542 return text; | 542 return text; |
543 } | 543 } |
544 | 544 |
545 bool | 545 bool |
546 NoteLayer::snapToFeatureFrame(View *v, int &frame, | 546 NoteLayer::snapToFeatureFrame(View *v, int &frame, |
547 size_t &resolution, | 547 int &resolution, |
548 SnapType snap) const | 548 SnapType snap) const |
549 { | 549 { |
550 if (!m_model) { | 550 if (!m_model) { |
551 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 551 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
552 } | 552 } |
745 if (!sampleRate) return; | 745 if (!sampleRate) return; |
746 | 746 |
747 // Profiler profiler("NoteLayer::paint", true); | 747 // Profiler profiler("NoteLayer::paint", true); |
748 | 748 |
749 int x0 = rect.left(), x1 = rect.right(); | 749 int x0 = rect.left(), x1 = rect.right(); |
750 long frame0 = v->getFrameForX(x0); | 750 int frame0 = v->getFrameForX(x0); |
751 long frame1 = v->getFrameForX(x1); | 751 int frame1 = v->getFrameForX(x1); |
752 | 752 |
753 NoteModel::PointList points(m_model->getPoints(frame0, frame1)); | 753 NoteModel::PointList points(m_model->getPoints(frame0, frame1)); |
754 if (points.empty()) return; | 754 if (points.empty()) return; |
755 | 755 |
756 paint.setPen(getBaseQColor()); | 756 paint.setPen(getBaseQColor()); |
882 { | 882 { |
883 // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 883 // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
884 | 884 |
885 if (!m_model) return; | 885 if (!m_model) return; |
886 | 886 |
887 long frame = v->getFrameForX(e->x()); | 887 int frame = v->getFrameForX(e->x()); |
888 if (frame < 0) frame = 0; | 888 if (frame < 0) frame = 0; |
889 frame = frame / m_model->getResolution() * m_model->getResolution(); | 889 frame = frame / m_model->getResolution() * m_model->getResolution(); |
890 | 890 |
891 float value = getValueForY(v, e->y()); | 891 float value = getValueForY(v, e->y()); |
892 | 892 |
906 { | 906 { |
907 // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 907 // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
908 | 908 |
909 if (!m_model || !m_editing) return; | 909 if (!m_model || !m_editing) return; |
910 | 910 |
911 long frame = v->getFrameForX(e->x()); | 911 int frame = v->getFrameForX(e->x()); |
912 if (frame < 0) frame = 0; | 912 if (frame < 0) frame = 0; |
913 frame = frame / m_model->getResolution() * m_model->getResolution(); | 913 frame = frame / m_model->getResolution() * m_model->getResolution(); |
914 | 914 |
915 float newValue = getValueForY(v, e->y()); | 915 float newValue = getValueForY(v, e->y()); |
916 | 916 |
917 long newFrame = m_editingPoint.frame; | 917 int newFrame = m_editingPoint.frame; |
918 long newDuration = frame - newFrame; | 918 int newDuration = frame - newFrame; |
919 if (newDuration < 0) { | 919 if (newDuration < 0) { |
920 newFrame = frame; | 920 newFrame = frame; |
921 newDuration = -newDuration; | 921 newDuration = -newDuration; |
922 } else if (newDuration == 0) { | 922 } else if (newDuration == 0) { |
923 newDuration = 1; | 923 newDuration = 1; |
954 | 954 |
955 m_editing = true; | 955 m_editing = true; |
956 } | 956 } |
957 | 957 |
958 void | 958 void |
959 NoteLayer::eraseDrag(View *v, QMouseEvent *e) | 959 NoteLayer::eraseDrag(View *, QMouseEvent *) |
960 { | 960 { |
961 } | 961 } |
962 | 962 |
963 void | 963 void |
964 NoteLayer::eraseEnd(View *v, QMouseEvent *e) | 964 NoteLayer::eraseEnd(View *v, QMouseEvent *e) |
1013 int xdist = e->x() - m_dragStartX; | 1013 int xdist = e->x() - m_dragStartX; |
1014 int ydist = e->y() - m_dragStartY; | 1014 int ydist = e->y() - m_dragStartY; |
1015 int newx = m_dragPointX + xdist; | 1015 int newx = m_dragPointX + xdist; |
1016 int newy = m_dragPointY + ydist; | 1016 int newy = m_dragPointY + ydist; |
1017 | 1017 |
1018 long frame = v->getFrameForX(newx); | 1018 int frame = v->getFrameForX(newx); |
1019 if (frame < 0) frame = 0; | 1019 if (frame < 0) frame = 0; |
1020 frame = frame / m_model->getResolution() * m_model->getResolution(); | 1020 frame = frame / m_model->getResolution() * m_model->getResolution(); |
1021 | 1021 |
1022 float value = getValueForY(v, newy); | 1022 float value = getValueForY(v, newy); |
1023 | 1023 |
1101 delete dialog; | 1101 delete dialog; |
1102 return true; | 1102 return true; |
1103 } | 1103 } |
1104 | 1104 |
1105 void | 1105 void |
1106 NoteLayer::moveSelection(Selection s, size_t newStartFrame) | 1106 NoteLayer::moveSelection(Selection s, int newStartFrame) |
1107 { | 1107 { |
1108 if (!m_model) return; | 1108 if (!m_model) return; |
1109 | 1109 |
1110 NoteModel::EditCommand *command = | 1110 NoteModel::EditCommand *command = |
1111 new NoteModel::EditCommand(m_model, tr("Drag Selection")); | 1111 new NoteModel::EditCommand(m_model, tr("Drag Selection")); |
1205 } | 1205 } |
1206 } | 1206 } |
1207 } | 1207 } |
1208 | 1208 |
1209 bool | 1209 bool |
1210 NoteLayer::paste(View *v, const Clipboard &from, int frameOffset, bool /* interactive */) | 1210 NoteLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) |
1211 { | 1211 { |
1212 if (!m_model) return false; | 1212 if (!m_model) return false; |
1213 | 1213 |
1214 const Clipboard::PointList &points = from.getPoints(); | 1214 const Clipboard::PointList &points = from.getPoints(); |
1215 | 1215 |
1237 | 1237 |
1238 for (Clipboard::PointList::const_iterator i = points.begin(); | 1238 for (Clipboard::PointList::const_iterator i = points.begin(); |
1239 i != points.end(); ++i) { | 1239 i != points.end(); ++i) { |
1240 | 1240 |
1241 if (!i->haveFrame()) continue; | 1241 if (!i->haveFrame()) continue; |
1242 size_t frame = 0; | 1242 int frame = 0; |
1243 | 1243 |
1244 if (!realign) { | 1244 if (!realign) { |
1245 | 1245 |
1246 frame = i->getFrame(); | 1246 frame = i->getFrame(); |
1247 | 1247 |
1262 else newPoint.value = (m_model->getValueMinimum() + | 1262 else newPoint.value = (m_model->getValueMinimum() + |
1263 m_model->getValueMaximum()) / 2; | 1263 m_model->getValueMaximum()) / 2; |
1264 if (i->haveLevel()) newPoint.level = i->getLevel(); | 1264 if (i->haveLevel()) newPoint.level = i->getLevel(); |
1265 if (i->haveDuration()) newPoint.duration = i->getDuration(); | 1265 if (i->haveDuration()) newPoint.duration = i->getDuration(); |
1266 else { | 1266 else { |
1267 size_t nextFrame = frame; | 1267 int nextFrame = frame; |
1268 Clipboard::PointList::const_iterator j = i; | 1268 Clipboard::PointList::const_iterator j = i; |
1269 for (; j != points.end(); ++j) { | 1269 for (; j != points.end(); ++j) { |
1270 if (!j->haveFrame()) continue; | 1270 if (!j->haveFrame()) continue; |
1271 if (j != i) break; | 1271 if (j != i) break; |
1272 } | 1272 } |
1286 finish(command); | 1286 finish(command); |
1287 return true; | 1287 return true; |
1288 } | 1288 } |
1289 | 1289 |
1290 void | 1290 void |
1291 NoteLayer::addNoteOn(long frame, int pitch, int velocity) | 1291 NoteLayer::addNoteOn(int frame, int pitch, int velocity) |
1292 { | 1292 { |
1293 m_pendingNoteOns.insert(Note(frame, pitch, 0, float(velocity) / 127.0, "")); | 1293 m_pendingNoteOns.insert(Note(frame, pitch, 0, float(velocity) / 127.0, "")); |
1294 } | 1294 } |
1295 | 1295 |
1296 void | 1296 void |
1297 NoteLayer::addNoteOff(long frame, int pitch) | 1297 NoteLayer::addNoteOff(int frame, int pitch) |
1298 { | 1298 { |
1299 for (NoteSet::iterator i = m_pendingNoteOns.begin(); | 1299 for (NoteSet::iterator i = m_pendingNoteOns.begin(); |
1300 i != m_pendingNoteOns.end(); ++i) { | 1300 i != m_pendingNoteOns.end(); ++i) { |
1301 if (lrintf((*i).value) == pitch) { | 1301 if (lrintf((*i).value) == pitch) { |
1302 Note note(*i); | 1302 Note note(*i); |