Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 875:0e674f1bbf08 tonioni
(Very slowly) perform local reanalysis when dragging a note up or down
author | Chris Cannam |
---|---|
date | Tue, 11 Nov 2014 14:11:07 +0000 |
parents | 7a80fa6a6dfc |
children | b62c2785ed83 |
comparison
equal
deleted
inserted
replaced
874:7a80fa6a6dfc | 875:0e674f1bbf08 |
---|---|
1164 if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { | 1164 if (m_intelligentActions && dragFrame + m_originalPoint.duration >= m_smallestRightNeighbourFrame) { |
1165 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; | 1165 dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; |
1166 } | 1166 } |
1167 m_editingPoint.frame = dragFrame; | 1167 m_editingPoint.frame = dragFrame; |
1168 m_editingPoint.value = value; | 1168 m_editingPoint.value = value; |
1169 | |
1170 // Re-analyse region within +/- 1 semitone of the dragged value | |
1171 float cents = 0; | |
1172 int midiPitch = Pitch::getPitchForFrequency(m_editingPoint.value, ¢s); | |
1173 float lower = Pitch::getFrequencyForPitch(midiPitch - 1, cents); | |
1174 float higher = Pitch::getFrequencyForPitch(midiPitch + 1, cents); | |
1175 | |
1176 emit reAnalyseRegion(m_editingPoint.frame, | |
1177 m_editingPoint.frame + m_editingPoint.duration, | |
1178 lower, higher); | |
1169 break; | 1179 break; |
1170 } | 1180 } |
1171 case SplitNote: // nothing | 1181 case SplitNote: // nothing |
1172 break; | 1182 break; |
1173 } | 1183 } |
1174 updateNoteValue(v, m_editingPoint); | 1184 |
1185 // updateNoteValueFromPitchCurve(v, m_editingPoint); | |
1175 m_editingCommand->addPoint(m_editingPoint); | 1186 m_editingCommand->addPoint(m_editingPoint); |
1187 | |
1176 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; | 1188 std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; |
1177 | 1189 } |
1178 } | 1190 |
1179 | 1191 void |
1180 void | 1192 FlexiNoteLayer::editEnd(View *v, QMouseEvent *e) |
1181 FlexiNoteLayer::editEnd(View *, QMouseEvent *e) | |
1182 { | 1193 { |
1183 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 1194 // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
1184 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; | 1195 std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; |
1185 | 1196 |
1186 if (!m_model || !m_editing) return; | 1197 if (!m_model || !m_editing) return; |
1187 | 1198 |
1188 if (m_editingCommand) { | 1199 if (m_editingCommand) { |
1189 | 1200 |
1190 QString newName = m_editingCommand->getName(); | 1201 QString newName = m_editingCommand->getName(); |
1202 | |
1203 m_editingCommand->deletePoint(m_editingPoint); | |
1204 updateNoteValueFromPitchCurve(v, m_editingPoint); | |
1205 m_editingCommand->addPoint(m_editingPoint); | |
1191 | 1206 |
1192 if (m_editingPoint.frame != m_originalPoint.frame) { | 1207 if (m_editingPoint.frame != m_originalPoint.frame) { |
1193 if (m_editingPoint.value != m_originalPoint.value) { | 1208 if (m_editingPoint.value != m_originalPoint.value) { |
1194 newName = tr("Edit Point"); | 1209 newName = tr("Edit Point"); |
1195 } else { | 1210 } else { |
1278 FlexiNote newNote2(frame, note.value, | 1293 FlexiNote newNote2(frame, note.value, |
1279 note.duration - newNote1.duration, | 1294 note.duration - newNote1.duration, |
1280 note.level, note.label); | 1295 note.level, note.label); |
1281 | 1296 |
1282 if (m_intelligentActions) { | 1297 if (m_intelligentActions) { |
1283 if (updateNoteValue(v, newNote1)) { | 1298 if (updateNoteValueFromPitchCurve(v, newNote1)) { |
1284 command->addPoint(newNote1); | 1299 command->addPoint(newNote1); |
1285 } | 1300 } |
1286 if (updateNoteValue(v, newNote2)) { | 1301 if (updateNoteValueFromPitchCurve(v, newNote2)) { |
1287 command->addPoint(newNote2); | 1302 command->addPoint(newNote2); |
1288 } | 1303 } |
1289 } else { | 1304 } else { |
1290 command->addPoint(newNote1); | 1305 command->addPoint(newNote1); |
1291 command->addPoint(newNote2); | 1306 command->addPoint(newNote2); |
1387 cerr << "snapSelectedNotesToPitchTrack: making new note" << endl; | 1402 cerr << "snapSelectedNotesToPitchTrack: making new note" << endl; |
1388 FlexiNote newNote(note); | 1403 FlexiNote newNote(note); |
1389 | 1404 |
1390 command->deletePoint(note); | 1405 command->deletePoint(note); |
1391 | 1406 |
1392 if (updateNoteValue(v, newNote)) { | 1407 if (updateNoteValueFromPitchCurve(v, newNote)) { |
1393 command->addPoint(newNote); | 1408 command->addPoint(newNote); |
1394 } | 1409 } |
1395 } | 1410 } |
1396 | 1411 |
1397 finish(command); | 1412 finish(command); |
1433 command->deletePoint(*i); | 1448 command->deletePoint(*i); |
1434 | 1449 |
1435 ++i; | 1450 ++i; |
1436 } | 1451 } |
1437 | 1452 |
1438 updateNoteValue(v, newNote); | 1453 updateNoteValueFromPitchCurve(v, newNote); |
1439 command->addPoint(newNote); | 1454 command->addPoint(newNote); |
1440 finish(command); | 1455 finish(command); |
1441 } | 1456 } |
1442 | 1457 |
1443 bool | 1458 bool |
1444 FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const | 1459 FlexiNoteLayer::updateNoteValueFromPitchCurve(View *v, |
1460 FlexiNoteModel::Point ¬e) const | |
1445 { | 1461 { |
1446 SparseTimeValueModel *model = getAssociatedPitchModel(v); | 1462 SparseTimeValueModel *model = getAssociatedPitchModel(v); |
1447 if (!model) return false; | 1463 if (!model) return false; |
1448 | 1464 |
1449 std::cerr << model->getTypeName() << std::endl; | 1465 std::cerr << model->getTypeName() << std::endl; |
1474 if (size % 2 == 0) { | 1490 if (size % 2 == 0) { |
1475 median = (pitchValues[size/2 - 1] + pitchValues[size/2]) / 2; | 1491 median = (pitchValues[size/2 - 1] + pitchValues[size/2]) / 2; |
1476 } else { | 1492 } else { |
1477 median = pitchValues[size/2]; | 1493 median = pitchValues[size/2]; |
1478 } | 1494 } |
1495 | |
1496 std::cerr << "updateNoteValueFromPitchCurve: corrected from " << note.value << " to median " << median << std::endl; | |
1479 | 1497 |
1480 note.value = median; | 1498 note.value = median; |
1481 | 1499 |
1482 return true; | 1500 return true; |
1483 } | 1501 } |