Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 804:5c4a405a70fc tony_integration
Merge from branch "tonioni"
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 12:55:18 +0100 |
parents | d6b79166ae0d |
children | 40c6c9344ff6 |
comparison
equal
deleted
inserted
replaced
803:5d2966b7c201 | 804:5c4a405a70fc |
---|---|
818 | 818 |
819 QPoint localPos; | 819 QPoint localPos; |
820 FlexiNoteModel::Point illuminatePoint(0); | 820 FlexiNoteModel::Point illuminatePoint(0); |
821 bool shouldIlluminate = false; | 821 bool shouldIlluminate = false; |
822 | 822 |
823 | |
823 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | 824 if (v->shouldIlluminateLocalFeatures(this, localPos)) { |
824 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), | 825 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), |
825 illuminatePoint); | 826 illuminatePoint); |
826 } | 827 } |
827 | 828 |
845 | 846 |
846 if (w < 1) w = 1; | 847 if (w < 1) w = 1; |
847 paint.setPen(getBaseQColor()); | 848 paint.setPen(getBaseQColor()); |
848 paint.setBrush(brushColour); | 849 paint.setBrush(brushColour); |
849 | 850 |
850 // if (shouldIlluminate && | 851 if (shouldIlluminate && |
851 // // "illuminatePoint == p" | 852 // "illuminatePoint == p" |
852 // !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && | 853 !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && |
853 // !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { | 854 !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { |
854 // | 855 |
855 // paint.setPen(v->getForeground()); | 856 paint.drawLine(x, -1, x, v->height() + 1); |
856 // paint.setBrush(v->getForeground()); | 857 paint.drawLine(x+w, -1, x+w, v->height() + 1); |
857 // | 858 |
858 // QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); | 859 paint.setPen(v->getForeground()); |
859 // v->drawVisibleText(paint, | 860 // paint.setBrush(v->getForeground()); |
860 // x - paint.fontMetrics().width(vlabel) - 2, | 861 |
861 // y + paint.fontMetrics().height()/2 | 862 QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); |
862 // - paint.fontMetrics().descent(), | 863 // v->drawVisibleText(paint, |
863 // vlabel, View::OutlinedText); | 864 // x - paint.fontMetrics().width(vlabel) - 2, |
864 // | 865 // y + paint.fontMetrics().height()/2 |
865 // QString hlabel = RealTime::frame2RealTime | 866 // - paint.fontMetrics().descent(), |
866 // (p.frame, m_model->getSampleRate()).toText(true).c_str(); | 867 // vlabel, View::OutlinedText); |
867 // v->drawVisibleText(paint, | 868 v->drawVisibleText(paint, |
868 // x, | 869 x, |
869 // y - h/2 - paint.fontMetrics().descent() - 2, | 870 y - h/2 - 2 - paint.fontMetrics().height() |
870 // hlabel, View::OutlinedText); | 871 - paint.fontMetrics().descent(), |
871 // } | 872 vlabel, View::OutlinedText); |
873 | |
874 QString hlabel = "dur: " + QString(RealTime::frame2RealTime | |
875 (p.duration, m_model->getSampleRate()).toText(true).c_str()); | |
876 v->drawVisibleText(paint, | |
877 x, | |
878 y - h/2 - paint.fontMetrics().descent() - 2, | |
879 hlabel, View::OutlinedText); | |
880 | |
881 QString llabel = QString("%1").arg(p.label); | |
882 v->drawVisibleText(paint, | |
883 x, | |
884 y + h + 2 + paint.fontMetrics().descent(), | |
885 llabel, View::OutlinedText); | |
886 } | |
872 | 887 |
873 paint.drawRect(x, y - h/2, w, h); | 888 paint.drawRect(x, y - h/2, w, h); |
874 } | 889 } |
875 | 890 |
876 paint.restore(); | 891 paint.restore(); |
1275 long duration = 10000; | 1290 long duration = 10000; |
1276 | 1291 |
1277 long frame = v->getFrameForX(e->x()); | 1292 long frame = v->getFrameForX(e->x()); |
1278 float value = getValueForY(v, e->y()); | 1293 float value = getValueForY(v, e->y()); |
1279 | 1294 |
1295 FlexiNoteModel::PointList noteList = m_model->getPoints(); | |
1296 | |
1280 if (m_intelligentActions) { | 1297 if (m_intelligentActions) { |
1281 long smallestRightNeighbourFrame = 0; | 1298 long smallestRightNeighbourFrame = 0; |
1282 for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); | 1299 for (FlexiNoteModel::PointList::const_iterator i = noteList.begin(); |
1283 i != m_model->getPoints().end(); ++i) { | 1300 i != noteList.end(); ++i) { |
1284 FlexiNote currentNote = *i; | 1301 FlexiNote currentNote = *i; |
1285 if (currentNote.frame > frame) { | 1302 if (currentNote.frame > frame) { |
1286 smallestRightNeighbourFrame = currentNote.frame; | 1303 smallestRightNeighbourFrame = currentNote.frame; |
1287 break; | 1304 break; |
1288 } | 1305 } |
1289 } | 1306 } |
1290 | 1307 if (smallestRightNeighbourFrame > 0) { |
1291 duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); | 1308 duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); |
1292 duration = (duration > 0) ? duration : 0; | 1309 duration = (duration > 0) ? duration : 0; |
1310 } | |
1293 } | 1311 } |
1294 | 1312 |
1295 if (!m_intelligentActions || | 1313 if (!m_intelligentActions || |
1296 (m_model->getPoints(frame).empty() && duration > 0)) { | 1314 (m_model->getPoints(frame).empty() && duration > 0)) { |
1297 FlexiNote newNote(frame, value, duration, 100, "new note"); | 1315 FlexiNote newNote(frame, value, duration, 100, "new note"); |
1309 | 1327 |
1310 cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; | 1328 cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; |
1311 | 1329 |
1312 for (int i = 0; i < v->getLayerCount(); ++i) { | 1330 for (int i = 0; i < v->getLayerCount(); ++i) { |
1313 Layer *layer = v->getLayer(i); | 1331 Layer *layer = v->getLayer(i); |
1314 if (layer && !layer->isLayerDormant(v) && | 1332 if (layer && |
1315 layer->getLayerPresentationName() != "candidate") { | 1333 layer->getLayerPresentationName() != "candidate") { |
1316 cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; | 1334 cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; |
1317 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> | 1335 SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> |
1318 (layer->getModel()); | 1336 (layer->getModel()); |
1319 cerr << "FlexiNoteLayer::getAssociatedPitchModel: and its model is " << model << endl; | 1337 cerr << "FlexiNoteLayer::getAssociatedPitchModel: and its model is " << model << endl; |
1470 if (closeToTop) { v->setCursor(Qt::CrossCursor); m_editMode = DragNote; return; } | 1488 if (closeToTop) { v->setCursor(Qt::CrossCursor); m_editMode = DragNote; return; } |
1471 if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); m_editMode = SplitNote; return; } | 1489 if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); m_editMode = SplitNote; return; } |
1472 | 1490 |
1473 v->setCursor(Qt::ArrowCursor); | 1491 v->setCursor(Qt::ArrowCursor); |
1474 | 1492 |
1475 // std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl; | 1493 std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl; |
1476 // v->setCursor(Qt::SizeHorCursor); | 1494 // v->setCursor(Qt::SizeHorCursor); |
1477 | 1495 |
1478 } | 1496 } |
1479 | 1497 |
1480 void | 1498 void |
1632 } | 1650 } |
1633 } | 1651 } |
1634 | 1652 |
1635 finish(command); | 1653 finish(command); |
1636 } | 1654 } |
1655 | |
1656 void | |
1657 FlexiNoteLayer::deleteSelectionInclusive(Selection s) | |
1658 { | |
1659 if (!m_model) return; | |
1660 | |
1661 FlexiNoteModel::EditCommand *command = | |
1662 new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points")); | |
1663 | |
1664 FlexiNoteModel::PointList points = | |
1665 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | |
1666 | |
1667 for (FlexiNoteModel::PointList::iterator i = points.begin(); | |
1668 i != points.end(); ++i) { | |
1669 bool overlap = !( | |
1670 ((s.getStartFrame() <= i->frame) && (s.getEndFrame() <= i->frame)) || // selection is left of note | |
1671 ((s.getStartFrame() >= (i->frame+i->duration)) && (s.getEndFrame() >= (i->frame+i->duration))) // selection is right of note | |
1672 ); | |
1673 if (overlap) { | |
1674 command->deletePoint(*i); | |
1675 } | |
1676 } | |
1677 | |
1678 finish(command); | |
1679 } | |
1637 | 1680 |
1638 void | 1681 void |
1639 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) | 1682 FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) |
1640 { | 1683 { |
1641 if (!m_model) return; | 1684 if (!m_model) return; |