comparison layer/FlexiNoteLayer.cpp @ 657:ac26de7b727a tonioni

re-did, and improved the moving constraints
author matthiasm
date Wed, 19 Jun 2013 22:56:17 +0100
parents 902c7c9d77ea
children 050404ae7799 65b966394650
comparison
equal deleted inserted replaced
656:902c7c9d77ea 657:ac26de7b727a
1000 int xdist = e->x() - m_dragStartX; 1000 int xdist = e->x() - m_dragStartX;
1001 int ydist = e->y() - m_dragStartY; 1001 int ydist = e->y() - m_dragStartY;
1002 int newx = m_dragPointX + xdist; 1002 int newx = m_dragPointX + xdist;
1003 int newy = m_dragPointY + ydist; 1003 int newy = m_dragPointY + ydist;
1004 1004
1005 long frame = v->getFrameForX(newx); 1005 long dragFrame = v->getFrameForX(newx);
1006 if (frame < 0) frame = 0; 1006 if (dragFrame < 0) dragFrame = 0;
1007 frame = frame / m_model->getResolution() * m_model->getResolution(); 1007 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution();
1008 1008
1009 float value = getValueForY(v, newy); 1009 float value = getValueForY(v, newy);
1010 1010
1011 if (!m_editingCommand) { 1011 if (!m_editingCommand) {
1012 m_editingCommand = new FlexiNoteModel::EditCommand(m_model, 1012 m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
1014 } 1014 }
1015 1015
1016 m_editingCommand->deletePoint(m_editingPoint); 1016 m_editingCommand->deletePoint(m_editingPoint);
1017 1017
1018 std::cerr << "edit mode: " << m_editMode << std::endl; 1018 std::cerr << "edit mode: " << m_editMode << std::endl;
1019
1019 switch (m_editMode) { 1020 switch (m_editMode) {
1020 case LeftBoundary : { 1021 case LeftBoundary : {
1021 if ((frame > m_greatestLeftNeighbourFrame) 1022 // left
1022 && (frame < m_originalPoint.frame + m_originalPoint.duration - 1) 1023 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1023 && (frame < m_smallestRightNeighbourFrame)) { 1024 // right
1024 m_editingPoint.duration = m_editingPoint.frame + m_editingPoint.duration - frame + 1; 1025 if (dragFrame >= m_originalPoint.frame + m_originalPoint.duration) {
1025 m_editingPoint.frame = frame; 1026 dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1;
1026 } 1027 }
1028 m_editingPoint.frame = dragFrame;
1029 m_editingPoint.duration = m_originalPoint.frame - dragFrame + m_originalPoint.duration;
1027 break; 1030 break;
1028 } 1031 }
1029 case RightBoundary : { 1032 case RightBoundary : {
1030 long tempDuration = frame - m_originalPoint.frame; 1033 // left
1031 if (tempDuration > 0 && m_originalPoint.frame + tempDuration - 1 < m_smallestRightNeighbourFrame) { 1034 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1032 m_editingPoint.duration = tempDuration; 1035 if (dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1;
1036 m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1;
1037 break;
1038 }
1039 case DragNote : {
1040 // left
1041 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1;
1042 // right
1043 if (dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) {
1044 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration;
1033 } 1045 }
1034 break; 1046 m_editingPoint.frame = dragFrame;
1035 }
1036 case DragNote : {
1037 if (frame <= m_smallestRightNeighbourFrame - m_editingPoint.duration
1038 && frame > m_greatestLeftNeighbourFrame) {
1039 m_editingPoint.frame = frame; // only move if it doesn't overlap with right note or left note
1040 }
1041 m_editingPoint.value = value; 1047 m_editingPoint.value = value;
1042 break; 1048 break;
1043 } 1049 }
1044 } 1050 }
1045 m_editingCommand->addPoint(m_editingPoint); 1051 m_editingCommand->addPoint(m_editingPoint);