Mercurial > hg > svgui
comparison layer/NoteLayer.cpp @ 1045:f535f6e5dbb0 alignment-simple
Merge in from SV 3.0-integration branches
| author | Chris Cannam |
|---|---|
| date | Wed, 02 Mar 2016 17:25:27 +0000 |
| parents | 4fe7a09be0fe |
| children | 5144d7185fb5 |
comparison
equal
deleted
inserted
replaced
| 976:f2c63ec85901 | 1045:f535f6e5dbb0 |
|---|---|
| 189 m_verticalScale = scale; | 189 m_verticalScale = scale; |
| 190 emit layerParametersChanged(); | 190 emit layerParametersChanged(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool | 193 bool |
| 194 NoteLayer::isLayerScrollable(const View *v) const | 194 NoteLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
| 195 { | 195 { |
| 196 QPoint discard; | 196 QPoint discard; |
| 197 return !v->shouldIlluminateLocalFeatures(this, discard); | 197 return !v->shouldIlluminateLocalFeatures(this, discard); |
| 198 } | 198 } |
| 199 | 199 |
| 387 | 387 |
| 388 return mapper; | 388 return mapper; |
| 389 } | 389 } |
| 390 | 390 |
| 391 NoteModel::PointList | 391 NoteModel::PointList |
| 392 NoteLayer::getLocalPoints(View *v, int x) const | 392 NoteLayer::getLocalPoints(LayerGeometryProvider *v, int x) const |
| 393 { | 393 { |
| 394 if (!m_model) return NoteModel::PointList(); | 394 if (!m_model) return NoteModel::PointList(); |
| 395 | 395 |
| 396 sv_frame_t frame = v->getFrameForX(x); | 396 sv_frame_t frame = v->getFrameForX(x); |
| 397 | 397 |
| 430 | 430 |
| 431 return usePoints; | 431 return usePoints; |
| 432 } | 432 } |
| 433 | 433 |
| 434 bool | 434 bool |
| 435 NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const | 435 NoteLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, NoteModel::Point &p) const |
| 436 { | 436 { |
| 437 if (!m_model) return false; | 437 if (!m_model) return false; |
| 438 | 438 |
| 439 sv_frame_t frame = v->getFrameForX(x); | 439 sv_frame_t frame = v->getFrameForX(x); |
| 440 | 440 |
| 458 | 458 |
| 459 return true; | 459 return true; |
| 460 } | 460 } |
| 461 | 461 |
| 462 QString | 462 QString |
| 463 NoteLayer::getFeatureDescription(View *v, QPoint &pos) const | 463 NoteLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
| 464 { | 464 { |
| 465 int x = pos.x(); | 465 int x = pos.x(); |
| 466 | 466 |
| 467 if (!m_model || !m_model->getSampleRate()) return ""; | 467 if (!m_model || !m_model->getSampleRate()) return ""; |
| 468 | 468 |
| 545 getYForValue(v, note.value)); | 545 getYForValue(v, note.value)); |
| 546 return text; | 546 return text; |
| 547 } | 547 } |
| 548 | 548 |
| 549 bool | 549 bool |
| 550 NoteLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 550 NoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
| 551 int &resolution, | 551 int &resolution, |
| 552 SnapType snap) const | 552 SnapType snap) const |
| 553 { | 553 { |
| 554 if (!m_model) { | 554 if (!m_model) { |
| 555 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 555 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
| 617 frame = snapped; | 617 frame = snapped; |
| 618 return found; | 618 return found; |
| 619 } | 619 } |
| 620 | 620 |
| 621 void | 621 void |
| 622 NoteLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const | 622 NoteLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const |
| 623 { | 623 { |
| 624 min = 0.0; | 624 min = 0.0; |
| 625 max = 0.0; | 625 max = 0.0; |
| 626 log = false; | 626 log = false; |
| 627 | 627 |
| 675 | 675 |
| 676 if (max == min) max = min + 1.0; | 676 if (max == min) max = min + 1.0; |
| 677 } | 677 } |
| 678 | 678 |
| 679 int | 679 int |
| 680 NoteLayer::getYForValue(View *v, double val) const | 680 NoteLayer::getYForValue(LayerGeometryProvider *v, double val) const |
| 681 { | 681 { |
| 682 double min = 0.0, max = 0.0; | 682 double min = 0.0, max = 0.0; |
| 683 bool logarithmic = false; | 683 bool logarithmic = false; |
| 684 int h = v->height(); | 684 int h = v->getPaintHeight(); |
| 685 | 685 |
| 686 getScaleExtents(v, min, max, logarithmic); | 686 getScaleExtents(v, min, max, logarithmic); |
| 687 | 687 |
| 688 #ifdef DEBUG_NOTE_LAYER | 688 #ifdef DEBUG_NOTE_LAYER |
| 689 cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl; | 689 cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl; |
| 710 #endif | 710 #endif |
| 711 return y; | 711 return y; |
| 712 } | 712 } |
| 713 | 713 |
| 714 double | 714 double |
| 715 NoteLayer::getValueForY(View *v, int y) const | 715 NoteLayer::getValueForY(LayerGeometryProvider *v, int y) const |
| 716 { | 716 { |
| 717 double min = 0.0, max = 0.0; | 717 double min = 0.0, max = 0.0; |
| 718 bool logarithmic = false; | 718 bool logarithmic = false; |
| 719 int h = v->height(); | 719 int h = v->getPaintHeight(); |
| 720 | 720 |
| 721 getScaleExtents(v, min, max, logarithmic); | 721 getScaleExtents(v, min, max, logarithmic); |
| 722 | 722 |
| 723 double val = min + (double(h - y) * double(max - min)) / h; | 723 double val = min + (double(h - y) * double(max - min)) / h; |
| 724 | 724 |
| 739 if (!m_model) return false; | 739 if (!m_model) return false; |
| 740 return (m_verticalScale == AutoAlignScale); | 740 return (m_verticalScale == AutoAlignScale); |
| 741 } | 741 } |
| 742 | 742 |
| 743 void | 743 void |
| 744 NoteLayer::paint(View *v, QPainter &paint, QRect rect) const | 744 NoteLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
| 745 { | 745 { |
| 746 if (!m_model || !m_model->isOK()) return; | 746 if (!m_model || !m_model->isOK()) return; |
| 747 | 747 |
| 748 sv_samplerate_t sampleRate = m_model->getSampleRate(); | 748 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
| 749 if (!sampleRate) return; | 749 if (!sampleRate) return; |
| 828 | 828 |
| 829 paint.restore(); | 829 paint.restore(); |
| 830 } | 830 } |
| 831 | 831 |
| 832 int | 832 int |
| 833 NoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const | 833 NoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const |
| 834 { | 834 { |
| 835 if (!m_model || shouldAutoAlign()) { | 835 if (!m_model || shouldAutoAlign()) { |
| 836 return 0; | 836 return 0; |
| 837 } else { | 837 } else { |
| 838 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { | 838 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { |
| 842 } | 842 } |
| 843 } | 843 } |
| 844 } | 844 } |
| 845 | 845 |
| 846 void | 846 void |
| 847 NoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | 847 NoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const |
| 848 { | 848 { |
| 849 if (!m_model || m_model->getPoints().empty()) return; | 849 if (!m_model || m_model->getPoints().empty()) return; |
| 850 | 850 |
| 851 QString unit; | 851 QString unit; |
| 852 double min, max; | 852 double min, max; |
| 853 bool logarithmic; | 853 bool logarithmic; |
| 854 | 854 |
| 855 int w = getVerticalScaleWidth(v, false, paint); | 855 int w = getVerticalScaleWidth(v, false, paint); |
| 856 int h = v->height(); | 856 int h = v->getPaintHeight(); |
| 857 | 857 |
| 858 getScaleExtents(v, min, max, logarithmic); | 858 getScaleExtents(v, min, max, logarithmic); |
| 859 | 859 |
| 860 if (logarithmic) { | 860 if (logarithmic) { |
| 861 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); | 861 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); |
| 880 mw)); | 880 mw)); |
| 881 } | 881 } |
| 882 } | 882 } |
| 883 | 883 |
| 884 void | 884 void |
| 885 NoteLayer::drawStart(View *v, QMouseEvent *e) | 885 NoteLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
| 886 { | 886 { |
| 887 // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 887 // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
| 888 | 888 |
| 889 if (!m_model) return; | 889 if (!m_model) return; |
| 890 | 890 |
| 904 | 904 |
| 905 m_editing = true; | 905 m_editing = true; |
| 906 } | 906 } |
| 907 | 907 |
| 908 void | 908 void |
| 909 NoteLayer::drawDrag(View *v, QMouseEvent *e) | 909 NoteLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) |
| 910 { | 910 { |
| 911 // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 911 // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
| 912 | 912 |
| 913 if (!m_model || !m_editing) return; | 913 if (!m_model || !m_editing) return; |
| 914 | 914 |
| 933 m_editingPoint.duration = newDuration; | 933 m_editingPoint.duration = newDuration; |
| 934 m_editingCommand->addPoint(m_editingPoint); | 934 m_editingCommand->addPoint(m_editingPoint); |
| 935 } | 935 } |
| 936 | 936 |
| 937 void | 937 void |
| 938 NoteLayer::drawEnd(View *, QMouseEvent *) | 938 NoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) |
| 939 { | 939 { |
| 940 // SVDEBUG << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; | 940 // SVDEBUG << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; |
| 941 if (!m_model || !m_editing) return; | 941 if (!m_model || !m_editing) return; |
| 942 finish(m_editingCommand); | 942 finish(m_editingCommand); |
| 943 m_editingCommand = 0; | 943 m_editingCommand = 0; |
| 944 m_editing = false; | 944 m_editing = false; |
| 945 } | 945 } |
| 946 | 946 |
| 947 void | 947 void |
| 948 NoteLayer::eraseStart(View *v, QMouseEvent *e) | 948 NoteLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) |
| 949 { | 949 { |
| 950 if (!m_model) return; | 950 if (!m_model) return; |
| 951 | 951 |
| 952 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 952 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
| 953 | 953 |
| 958 | 958 |
| 959 m_editing = true; | 959 m_editing = true; |
| 960 } | 960 } |
| 961 | 961 |
| 962 void | 962 void |
| 963 NoteLayer::eraseDrag(View *, QMouseEvent *) | 963 NoteLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) |
| 964 { | 964 { |
| 965 } | 965 } |
| 966 | 966 |
| 967 void | 967 void |
| 968 NoteLayer::eraseEnd(View *v, QMouseEvent *e) | 968 NoteLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) |
| 969 { | 969 { |
| 970 if (!m_model || !m_editing) return; | 970 if (!m_model || !m_editing) return; |
| 971 | 971 |
| 972 m_editing = false; | 972 m_editing = false; |
| 973 | 973 |
| 983 m_editingCommand = 0; | 983 m_editingCommand = 0; |
| 984 m_editing = false; | 984 m_editing = false; |
| 985 } | 985 } |
| 986 | 986 |
| 987 void | 987 void |
| 988 NoteLayer::editStart(View *v, QMouseEvent *e) | 988 NoteLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) |
| 989 { | 989 { |
| 990 // SVDEBUG << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; | 990 // SVDEBUG << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; |
| 991 | 991 |
| 992 if (!m_model) return; | 992 if (!m_model) return; |
| 993 | 993 |
| 1006 m_dragStartX = e->x(); | 1006 m_dragStartX = e->x(); |
| 1007 m_dragStartY = e->y(); | 1007 m_dragStartY = e->y(); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 void | 1010 void |
| 1011 NoteLayer::editDrag(View *v, QMouseEvent *e) | 1011 NoteLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) |
| 1012 { | 1012 { |
| 1013 // SVDEBUG << "NoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; | 1013 // SVDEBUG << "NoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; |
| 1014 | 1014 |
| 1015 if (!m_model || !m_editing) return; | 1015 if (!m_model || !m_editing) return; |
| 1016 | 1016 |
| 1035 m_editingPoint.value = float(value); | 1035 m_editingPoint.value = float(value); |
| 1036 m_editingCommand->addPoint(m_editingPoint); | 1036 m_editingCommand->addPoint(m_editingPoint); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 void | 1039 void |
| 1040 NoteLayer::editEnd(View *, QMouseEvent *) | 1040 NoteLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) |
| 1041 { | 1041 { |
| 1042 // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 1042 // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
| 1043 if (!m_model || !m_editing) return; | 1043 if (!m_model || !m_editing) return; |
| 1044 | 1044 |
| 1045 if (m_editingCommand) { | 1045 if (m_editingCommand) { |
| 1063 m_editingCommand = 0; | 1063 m_editingCommand = 0; |
| 1064 m_editing = false; | 1064 m_editing = false; |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 bool | 1067 bool |
| 1068 NoteLayer::editOpen(View *v, QMouseEvent *e) | 1068 NoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
| 1069 { | 1069 { |
| 1070 if (!m_model) return false; | 1070 if (!m_model) return false; |
| 1071 | 1071 |
| 1072 NoteModel::Point note(0); | 1072 NoteModel::Point note(0); |
| 1073 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; | 1073 if (!getPointToDrag(v, e->x(), e->y(), note)) return false; |
| 1191 | 1191 |
| 1192 finish(command); | 1192 finish(command); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 void | 1195 void |
| 1196 NoteLayer::copy(View *v, Selection s, Clipboard &to) | 1196 NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
| 1197 { | 1197 { |
| 1198 if (!m_model) return; | 1198 if (!m_model) return; |
| 1199 | 1199 |
| 1200 NoteModel::PointList points = | 1200 NoteModel::PointList points = |
| 1201 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 1201 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
| 1209 } | 1209 } |
| 1210 } | 1210 } |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 bool | 1213 bool |
| 1214 NoteLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) | 1214 NoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) |
| 1215 { | 1215 { |
| 1216 if (!m_model) return false; | 1216 if (!m_model) return false; |
| 1217 | 1217 |
| 1218 const Clipboard::PointList &points = from.getPoints(); | 1218 const Clipboard::PointList &points = from.getPoints(); |
| 1219 | 1219 |
| 1220 bool realign = false; | 1220 bool realign = false; |
| 1221 | 1221 |
| 1222 if (clipboardHasDifferentAlignment(v, from)) { | 1222 if (clipboardHasDifferentAlignment(v, from)) { |
| 1223 | 1223 |
| 1224 QMessageBox::StandardButton button = | 1224 QMessageBox::StandardButton button = |
| 1225 QMessageBox::question(v, tr("Re-align pasted items?"), | 1225 QMessageBox::question(v->getView(), tr("Re-align pasted items?"), |
| 1226 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), | 1226 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), |
| 1227 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 1227 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
| 1228 QMessageBox::Yes); | 1228 QMessageBox::Yes); |
| 1229 | 1229 |
| 1230 if (button == QMessageBox::Cancel) { | 1230 if (button == QMessageBox::Cancel) { |
