Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 660:8663a831838f tonioni
instrument is now "click" -- some other minor changes I don't remember
author | matthiasm |
---|---|
date | Thu, 20 Jun 2013 13:47:36 +0100 |
parents | 65b966394650 050404ae7799 |
children | 123ebecd12e6 |
comparison
equal
deleted
inserted
replaced
659:65b966394650 | 660:8663a831838f |
---|---|
59 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), | 59 m_originalPoint(0, 0.0, 0, 1.f, tr("New Point")), |
60 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), | 60 m_editingPoint(0, 0.0, 0, 1.f, tr("New Point")), |
61 m_editingCommand(0), | 61 m_editingCommand(0), |
62 m_verticalScale(AutoAlignScale), | 62 m_verticalScale(AutoAlignScale), |
63 m_scaleMinimum(34), | 63 m_scaleMinimum(34), |
64 m_scaleMaximum(77) | 64 m_scaleMaximum(77), |
65 m_intelligentActions(true) | |
65 { | 66 { |
66 } | 67 } |
67 | 68 |
68 void | 69 void |
69 FlexiNoteLayer::setModel(FlexiNoteModel *model) | 70 FlexiNoteLayer::setModel(FlexiNoteModel *model) |
1017 | 1018 |
1018 std::cerr << "edit mode: " << m_editMode << std::endl; | 1019 std::cerr << "edit mode: " << m_editMode << std::endl; |
1019 | 1020 |
1020 switch (m_editMode) { | 1021 switch (m_editMode) { |
1021 case LeftBoundary : { | 1022 case LeftBoundary : { |
1022 // left | 1023 // left |
1023 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; | 1024 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; |
1024 // right | 1025 // right |
1025 if (dragFrame >= m_originalPoint.frame + m_originalPoint.duration) { | 1026 if (m_intelligentActions && dragFrame >= m_originalPoint.frame + m_originalPoint.duration) { |
1026 dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1; | 1027 dragFrame = m_originalPoint.frame + m_originalPoint.duration - 1; |
1027 } | 1028 } |
1028 m_editingPoint.frame = dragFrame; | 1029 m_editingPoint.frame = dragFrame; |
1029 m_editingPoint.duration = m_originalPoint.frame - dragFrame + m_originalPoint.duration; | 1030 m_editingPoint.duration = m_originalPoint.frame - dragFrame + m_originalPoint.duration; |
1030 break; | 1031 break; |
1031 } | 1032 } |
1032 case RightBoundary : { | 1033 case RightBoundary : { |
1033 // left | 1034 // left |
1034 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; | 1035 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; |
1035 if (dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1; | 1036 if (m_intelligentActions && dragFrame >= m_smallestRightNeighbourFrame) dragFrame = m_smallestRightNeighbourFrame - 1; |
1036 m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1; | 1037 m_editingPoint.duration = dragFrame - m_originalPoint.frame + 1; |
1037 break; | 1038 break; |
1038 } | 1039 } |
1039 case DragNote : { | 1040 case DragNote : { |
1040 // left | 1041 // left |
1041 if (dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; | 1042 if (m_intelligentActions && dragFrame <= m_greatestLeftNeighbourFrame) dragFrame = m_greatestLeftNeighbourFrame + 1; |
1042 // right | 1043 // right |
1043 if (dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { | 1044 if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { |
1044 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; | 1045 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; |
1045 } | 1046 } |
1046 m_editingPoint.frame = dragFrame; | 1047 m_editingPoint.frame = dragFrame; |
1047 m_editingPoint.value = value; | 1048 m_editingPoint.value = value; |
1048 break; | 1049 break; |
1135 note.level, note.label); | 1136 note.level, note.label); |
1136 | 1137 |
1137 FlexiNote newNote2(frame, note.value, | 1138 FlexiNote newNote2(frame, note.value, |
1138 note.duration - newNote1.duration, | 1139 note.duration - newNote1.duration, |
1139 note.level, note.label); | 1140 note.level, note.label); |
1140 | 1141 |
1141 updateNoteValue(v,newNote1); | 1142 if (m_intelligentActions) { |
1142 updateNoteValue(v,newNote2); | 1143 updateNoteValue(v,newNote1); |
1144 updateNoteValue(v,newNote2); | |
1145 } | |
1143 | 1146 |
1144 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand | 1147 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand |
1145 (m_model, tr("Edit Point")); | 1148 (m_model, tr("Edit Point")); |
1146 command->deletePoint(note); | 1149 command->deletePoint(note); |
1147 if ((e->modifiers() & Qt::ShiftModifier)) { | 1150 if ((e->modifiers() & Qt::ShiftModifier)) { |
1151 command->addPoint(newNote1); | 1154 command->addPoint(newNote1); |
1152 command->addPoint(newNote2); | 1155 command->addPoint(newNote2); |
1153 finish(command); | 1156 finish(command); |
1154 | 1157 |
1155 } | 1158 } |
1159 | |
1160 void | |
1161 FlexiNoteLayer::addNote(View *v, QMouseEvent *e) | |
1162 { | |
1163 std::cerr << "addNote" << std::endl; | |
1164 if (!m_model) return; | |
1165 | |
1166 long duration = 10000; | |
1167 | |
1168 long frame = v->getFrameForX(e->x()); | |
1169 float value = getValueForY(v, e->y()); | |
1170 | |
1171 if (m_intelligentActions) { | |
1172 long smallestRightNeighbourFrame = 0; | |
1173 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); | |
1174 i != m_model->getPoints().end(); ++i) { | |
1175 FlexiNote currentNote = *i; | |
1176 if (currentNote.frame > frame) { | |
1177 smallestRightNeighbourFrame = currentNote.frame; | |
1178 break; | |
1179 } | |
1180 } | |
1181 | |
1182 duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); | |
1183 duration = (duration > 0) ? duration : 0; | |
1184 } | |
1185 | |
1186 if (!m_intelligentActions || | |
1187 m_model->getPoints(frame).empty() && duration > 0) | |
1188 { | |
1189 FlexiNote newNote(frame, value, duration, 100, "new note"); | |
1190 FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand | |
1191 (m_model, tr("Add Point")); | |
1192 command->addPoint(newNote); | |
1193 finish(command); | |
1194 } | |
1195 } | |
1196 | |
1156 | 1197 |
1157 void | 1198 void |
1158 FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const | 1199 FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const |
1159 { | 1200 { |
1160 //GF: update the note value conforming the median of pitch values in the underlying note layer | 1201 //GF: update the note value conforming the median of pitch values in the underlying note layer |