Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 1427:f792a5001d80 single-point
Update to use external set of commands
author | Chris Cannam |
---|---|
date | Fri, 15 Mar 2019 11:09:17 +0000 |
parents | e1a08da75427 |
children | 8a7c82282fbc |
comparison
equal
deleted
inserted
replaced
1426:e1a08da75427 | 1427:f792a5001d80 |
---|---|
51 | 51 |
52 #define NOTE_HEIGHT 16 | 52 #define NOTE_HEIGHT 16 |
53 | 53 |
54 FlexiNoteLayer::FlexiNoteLayer() : | 54 FlexiNoteLayer::FlexiNoteLayer() : |
55 SingleColourLayer(), | 55 SingleColourLayer(), |
56 | |
57 // m_model(0), | |
58 // m_editing(false), | |
59 // m_originalPoint(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), | |
62 // m_verticalScale(AutoAlignScale), | |
63 // m_scaleMinimum(0), | |
64 // m_scaleMaximum(0) | |
65 | |
66 m_model(nullptr), | 56 m_model(nullptr), |
67 m_editing(false), | 57 m_editing(false), |
68 m_intelligentActions(true), | 58 m_intelligentActions(true), |
69 m_dragPointX(0), | 59 m_dragPointX(0), |
70 m_dragPointY(0), | 60 m_dragPointY(0), |
943 | 933 |
944 m_editingPoint = Event(frame, float(value), 0, 0.8f, tr("New Point")); | 934 m_editingPoint = Event(frame, float(value), 0, 0.8f, tr("New Point")); |
945 m_originalPoint = m_editingPoint; | 935 m_originalPoint = m_editingPoint; |
946 | 936 |
947 if (m_editingCommand) finish(m_editingCommand); | 937 if (m_editingCommand) finish(m_editingCommand); |
948 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Draw Point")); | 938 m_editingCommand = new ChangeEventsCommand(m_model, tr("Draw Point")); |
949 m_editingCommand->add(m_editingPoint); | 939 m_editingCommand->add(m_editingPoint); |
950 | 940 |
951 m_editing = true; | 941 m_editing = true; |
952 } | 942 } |
953 | 943 |
1020 | 1010 |
1021 Event p(0); | 1011 Event p(0); |
1022 if (!getPointToDrag(v, e->x(), e->y(), p)) return; | 1012 if (!getPointToDrag(v, e->x(), e->y(), p)) return; |
1023 if (p.getFrame() != m_editingPoint.getFrame() || p.getValue() != m_editingPoint.getValue()) return; | 1013 if (p.getFrame() != m_editingPoint.getFrame() || p.getValue() != m_editingPoint.getValue()) return; |
1024 | 1014 |
1025 m_editingCommand = new NoteModel::EditCommand(m_model, tr("Erase Point")); | 1015 m_editingCommand = new ChangeEventsCommand(m_model, tr("Erase Point")); |
1026 | |
1027 m_editingCommand->remove(m_editingPoint); | 1016 m_editingCommand->remove(m_editingPoint); |
1028 | |
1029 finish(m_editingCommand); | 1017 finish(m_editingCommand); |
1030 m_editingCommand = nullptr; | 1018 m_editingCommand = nullptr; |
1031 m_editing = false; | 1019 m_editing = false; |
1032 } | 1020 } |
1033 | 1021 |
1106 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution(); | 1094 dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution(); |
1107 | 1095 |
1108 double value = getValueForY(v, newy); | 1096 double value = getValueForY(v, newy); |
1109 | 1097 |
1110 if (!m_editingCommand) { | 1098 if (!m_editingCommand) { |
1111 m_editingCommand = new NoteModel::EditCommand(m_model, | 1099 m_editingCommand = new ChangeEventsCommand(m_model, tr("Drag Point")); |
1112 tr("Drag Point")); | 1100 } |
1113 } | |
1114 | |
1115 m_editingCommand->remove(m_editingPoint); | 1101 m_editingCommand->remove(m_editingPoint); |
1116 | 1102 |
1117 std::cerr << "edit mode: " << m_editMode << " intelligent actions = " | 1103 std::cerr << "edit mode: " << m_editMode << " intelligent actions = " |
1118 << m_intelligentActions << std::endl; | 1104 << m_intelligentActions << std::endl; |
1119 | 1105 |
1283 EventVector onPoints = m_model->getEventsCovering(frame); | 1269 EventVector onPoints = m_model->getEventsCovering(frame); |
1284 if (onPoints.empty()) return; | 1270 if (onPoints.empty()) return; |
1285 | 1271 |
1286 Event note(*onPoints.begin()); | 1272 Event note(*onPoints.begin()); |
1287 | 1273 |
1288 NoteModel::EditCommand *command = new NoteModel::EditCommand | 1274 ChangeEventsCommand *command = new ChangeEventsCommand |
1289 (m_model, tr("Edit Point")); | 1275 (m_model, tr("Edit Point")); |
1290 command->remove(note); | 1276 command->remove(note); |
1291 | 1277 |
1292 if (!e || !(e->modifiers() & Qt::ShiftModifier)) { | 1278 if (!e || !(e->modifiers() & Qt::ShiftModifier)) { |
1293 | 1279 |
1347 } | 1333 } |
1348 | 1334 |
1349 if (!m_intelligentActions || | 1335 if (!m_intelligentActions || |
1350 (m_model->getEventsCovering(frame).empty() && duration > 0)) { | 1336 (m_model->getEventsCovering(frame).empty() && duration > 0)) { |
1351 Event newNote(frame, float(value), duration, 100.f, tr("new note")); | 1337 Event newNote(frame, float(value), duration, 100.f, tr("new note")); |
1352 NoteModel::EditCommand *command = new NoteModel::EditCommand | 1338 ChangeEventsCommand *command = new ChangeEventsCommand |
1353 (m_model, tr("Add Point")); | 1339 (m_model, tr("Add Point")); |
1354 command->add(newNote); | 1340 command->add(newNote); |
1355 finish(command); | 1341 finish(command); |
1356 } | 1342 } |
1357 } | 1343 } |
1387 if (!m_model) return; | 1373 if (!m_model) return; |
1388 | 1374 |
1389 EventVector points = | 1375 EventVector points = |
1390 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); | 1376 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1391 | 1377 |
1392 NoteModel::EditCommand *command = new NoteModel::EditCommand | 1378 ChangeEventsCommand *command = new ChangeEventsCommand |
1393 (m_model, tr("Snap Notes")); | 1379 (m_model, tr("Snap Notes")); |
1394 | 1380 |
1395 cerr << "snapSelectedNotesToPitchTrack: selection is from " << s.getStartFrame() << " to " << s.getEndFrame() << endl; | 1381 cerr << "snapSelectedNotesToPitchTrack: selection is from " << s.getStartFrame() << " to " << s.getEndFrame() << endl; |
1396 | 1382 |
1397 for (EventVector::iterator i = points.begin(); | 1383 for (EventVector::iterator i = points.begin(); |
1430 } | 1416 } |
1431 | 1417 |
1432 EventVector::iterator i = points.begin(); | 1418 EventVector::iterator i = points.begin(); |
1433 if (i == points.end()) return; | 1419 if (i == points.end()) return; |
1434 | 1420 |
1435 NoteModel::EditCommand *command = | 1421 ChangeEventsCommand *command = |
1436 new NoteModel::EditCommand(m_model, tr("Merge Notes")); | 1422 new ChangeEventsCommand(m_model, tr("Merge Notes")); |
1437 | 1423 |
1438 Event newNote(*i); | 1424 Event newNote(*i); |
1439 | 1425 |
1440 while (i != points.end()) { | 1426 while (i != points.end()) { |
1441 | 1427 |
1598 .withFrame(dialog->getFrameTime()) | 1584 .withFrame(dialog->getFrameTime()) |
1599 .withValue(dialog->getValue()) | 1585 .withValue(dialog->getValue()) |
1600 .withDuration(dialog->getFrameDuration()) | 1586 .withDuration(dialog->getFrameDuration()) |
1601 .withLabel(dialog->getText()); | 1587 .withLabel(dialog->getText()); |
1602 | 1588 |
1603 NoteModel::EditCommand *command = new NoteModel::EditCommand | 1589 ChangeEventsCommand *command = new ChangeEventsCommand |
1604 (m_model, tr("Edit Point")); | 1590 (m_model, tr("Edit Point")); |
1605 command->remove(note); | 1591 command->remove(note); |
1606 command->add(newNote); | 1592 command->add(newNote); |
1607 finish(command); | 1593 finish(command); |
1608 } | 1594 } |
1614 void | 1600 void |
1615 FlexiNoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) | 1601 FlexiNoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) |
1616 { | 1602 { |
1617 if (!m_model) return; | 1603 if (!m_model) return; |
1618 | 1604 |
1619 NoteModel::EditCommand *command = | 1605 ChangeEventsCommand *command = |
1620 new NoteModel::EditCommand(m_model, tr("Drag Selection")); | 1606 new ChangeEventsCommand(m_model, tr("Drag Selection")); |
1621 | 1607 |
1622 EventVector points = | 1608 EventVector points = |
1623 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); | 1609 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1624 | 1610 |
1625 for (Event p: points) { | 1611 for (Event p: points) { |
1635 void | 1621 void |
1636 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize) | 1622 FlexiNoteLayer::resizeSelection(Selection s, Selection newSize) |
1637 { | 1623 { |
1638 if (!m_model || !s.getDuration()) return; | 1624 if (!m_model || !s.getDuration()) return; |
1639 | 1625 |
1640 NoteModel::EditCommand *command = | 1626 ChangeEventsCommand *command = |
1641 new NoteModel::EditCommand(m_model, tr("Resize Selection")); | 1627 new ChangeEventsCommand(m_model, tr("Resize Selection")); |
1642 | 1628 |
1643 EventVector points = | 1629 EventVector points = |
1644 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); | 1630 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1645 | 1631 |
1646 double ratio = double(newSize.getDuration()) / double(s.getDuration()); | 1632 double ratio = double(newSize.getDuration()) / double(s.getDuration()); |
1665 void | 1651 void |
1666 FlexiNoteLayer::deleteSelection(Selection s) | 1652 FlexiNoteLayer::deleteSelection(Selection s) |
1667 { | 1653 { |
1668 if (!m_model) return; | 1654 if (!m_model) return; |
1669 | 1655 |
1670 NoteModel::EditCommand *command = | 1656 ChangeEventsCommand *command = |
1671 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); | 1657 new ChangeEventsCommand(m_model, tr("Delete Selected Points")); |
1672 | 1658 |
1673 EventVector points = | 1659 EventVector points = |
1674 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); | 1660 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration()); |
1675 | 1661 |
1676 for (Event p: points) { | 1662 for (Event p: points) { |
1683 void | 1669 void |
1684 FlexiNoteLayer::deleteSelectionInclusive(Selection s) | 1670 FlexiNoteLayer::deleteSelectionInclusive(Selection s) |
1685 { | 1671 { |
1686 if (!m_model) return; | 1672 if (!m_model) return; |
1687 | 1673 |
1688 NoteModel::EditCommand *command = | 1674 ChangeEventsCommand *command = |
1689 new NoteModel::EditCommand(m_model, tr("Delete Selected Points")); | 1675 new ChangeEventsCommand(m_model, tr("Delete Selected Points")); |
1690 | 1676 |
1691 EventVector points = | 1677 EventVector points = |
1692 m_model->getEventsSpanning(s.getStartFrame(), s.getDuration()); | 1678 m_model->getEventsSpanning(s.getStartFrame(), s.getDuration()); |
1693 | 1679 |
1694 for (Event p: points) { | 1680 for (Event p: points) { |
1735 if (button == QMessageBox::Yes) { | 1721 if (button == QMessageBox::Yes) { |
1736 realign = true; | 1722 realign = true; |
1737 } | 1723 } |
1738 } | 1724 } |
1739 | 1725 |
1740 NoteModel::EditCommand *command = | 1726 ChangeEventsCommand *command = |
1741 new NoteModel::EditCommand(m_model, tr("Paste")); | 1727 new ChangeEventsCommand(m_model, tr("Paste")); |
1742 | 1728 |
1743 for (EventVector::const_iterator i = points.begin(); | 1729 for (EventVector::const_iterator i = points.begin(); |
1744 i != points.end(); ++i) { | 1730 i != points.end(); ++i) { |
1745 | 1731 |
1746 sv_frame_t frame = 0; | 1732 sv_frame_t frame = 0; |
1805 | 1791 |
1806 if (lrintf(p.getValue()) == pitch) { | 1792 if (lrintf(p.getValue()) == pitch) { |
1807 m_pendingNoteOns.erase(i); | 1793 m_pendingNoteOns.erase(i); |
1808 Event note = p.withDuration(frame - p.getFrame()); | 1794 Event note = p.withDuration(frame - p.getFrame()); |
1809 if (m_model) { | 1795 if (m_model) { |
1810 NoteModel::EditCommand *c = new NoteModel::EditCommand | 1796 ChangeEventsCommand *c = new ChangeEventsCommand |
1811 (m_model, tr("Record Note")); | 1797 (m_model, tr("Record Note")); |
1812 c->add(note); | 1798 c->add(note); |
1813 // execute and bundle: | 1799 // execute and bundle: |
1814 CommandHistory::getInstance()->addCommand(c, true, true); | 1800 CommandHistory::getInstance()->addCommand(c, true, true); |
1815 } | 1801 } |