Mercurial > hg > svgui
comparison layer/FlexiNoteLayer.cpp @ 702:ceb9a2992d96 tonioni
Merge from default branch
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 13:46:29 +0000 |
parents | layer/NoteLayer.cpp@084f65094203 layer/NoteLayer.cpp@e77b1673e17e |
children | cc6b21976261 |
comparison
equal
deleted
inserted
replaced
696:e77b1673e17e | 702:ceb9a2992d96 |
---|---|
22 #include "base/Pitch.h" | 22 #include "base/Pitch.h" |
23 #include "base/LogRange.h" | 23 #include "base/LogRange.h" |
24 #include "base/RangeMapper.h" | 24 #include "base/RangeMapper.h" |
25 #include "ColourDatabase.h" | 25 #include "ColourDatabase.h" |
26 #include "view/View.h" | 26 #include "view/View.h" |
27 | |
27 #include "PianoScale.h" | 28 #include "PianoScale.h" |
29 #include "LinearNumericalScale.h" | |
30 #include "LogNumericalScale.h" | |
28 | 31 |
29 #include "data/model/FlexiNoteModel.h" | 32 #include "data/model/FlexiNoteModel.h" |
30 | 33 |
31 #include "widgets/ItemEditDialog.h" | 34 #include "widgets/ItemEditDialog.h" |
35 #include "widgets/TextAbbrev.h" | |
32 | 36 |
33 #include <QPainter> | 37 #include <QPainter> |
34 #include <QPainterPath> | 38 #include <QPainterPath> |
35 #include <QMouseEvent> | 39 #include <QMouseEvent> |
36 #include <QTextStream> | 40 #include <QTextStream> |
114 return tr("Scale"); | 118 return tr("Scale"); |
115 } | 119 } |
116 return SingleColourLayer::getPropertyGroupName(name); | 120 return SingleColourLayer::getPropertyGroupName(name); |
117 } | 121 } |
118 | 122 |
123 QString | |
124 NoteLayer::getScaleUnits() const | |
125 { | |
126 if (m_model) return m_model->getScaleUnits(); | |
127 else return ""; | |
128 } | |
129 | |
119 int | 130 int |
120 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name, | 131 FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name, |
121 int *min, int *max, int *deflt) const | 132 int *min, int *max, int *deflt) const |
122 { | 133 { |
123 int val = 0; | 134 int val = 0; |
133 } else if (name == "Scale Units") { | 144 } else if (name == "Scale Units") { |
134 | 145 |
135 if (deflt) *deflt = 0; | 146 if (deflt) *deflt = 0; |
136 if (m_model) { | 147 if (m_model) { |
137 val = UnitDatabase::getInstance()->getUnitId | 148 val = UnitDatabase::getInstance()->getUnitId |
138 (m_model->getScaleUnits()); | 149 (getScaleUnits()); |
139 } | 150 } |
140 | 151 |
141 } else { | 152 } else { |
142 | 153 |
143 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); | 154 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
194 } | 205 } |
195 | 206 |
196 bool | 207 bool |
197 FlexiNoteLayer::shouldConvertMIDIToHz() const | 208 FlexiNoteLayer::shouldConvertMIDIToHz() const |
198 { | 209 { |
199 QString unit = m_model->getScaleUnits(); | 210 QString unit = getScaleUnits(); |
200 return (unit != "Hz"); | 211 return (unit != "Hz"); |
201 // if (unit == "" || | 212 // if (unit == "" || |
202 // unit.startsWith("MIDI") || | 213 // unit.startsWith("MIDI") || |
203 // unit.startsWith("midi")) return true; | 214 // unit.startsWith("midi")) return true; |
204 // return false; | 215 // return false; |
214 | 225 |
215 if (shouldConvertMIDIToHz()) { | 226 if (shouldConvertMIDIToHz()) { |
216 unit = "Hz"; | 227 unit = "Hz"; |
217 min = Pitch::getFrequencyForPitch(lrintf(min)); | 228 min = Pitch::getFrequencyForPitch(lrintf(min)); |
218 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); | 229 max = Pitch::getFrequencyForPitch(lrintf(max + 1)); |
219 } else unit = m_model->getScaleUnits(); | 230 } else unit = getScaleUnits(); |
220 | 231 |
221 if (m_verticalScale == MIDIRangeScale || | 232 if (m_verticalScale == MIDIRangeScale || |
222 m_verticalScale == LogScale) logarithmic = true; | 233 m_verticalScale == LogScale) logarithmic = true; |
223 | 234 |
224 return true; | 235 return true; |
541 pitchText = tr("%1 (%2, %3 Hz)") | 552 pitchText = tr("%1 (%2, %3 Hz)") |
542 .arg(Pitch::getPitchLabel(mnote, cents)) | 553 .arg(Pitch::getPitchLabel(mnote, cents)) |
543 .arg(mnote) | 554 .arg(mnote) |
544 .arg(freq); | 555 .arg(freq); |
545 | 556 |
546 } else if (m_model->getScaleUnits() == "Hz") { | 557 } else if (getScaleUnits() == "Hz") { |
547 | 558 |
548 pitchText = tr("%1 Hz (%2, %3)") | 559 pitchText = tr("%1 Hz (%2, %3)") |
549 .arg(note.value) | 560 .arg(note.value) |
550 .arg(Pitch::getPitchLabelForFrequency(note.value)) | 561 .arg(Pitch::getPitchLabelForFrequency(note.value)) |
551 .arg(Pitch::getPitchForFrequency(note.value)); | 562 .arg(Pitch::getPitchForFrequency(note.value)); |
552 | 563 |
553 } else { | 564 } else { |
554 pitchText = tr("%1 %2") | 565 pitchText = tr("%1 %2") |
555 .arg(note.value).arg(m_model->getScaleUnits()); | 566 .arg(note.value).arg(getScaleUnits()); |
556 } | 567 } |
557 | 568 |
558 QString text; | 569 QString text; |
559 | 570 |
560 if (note.label == "") { | 571 if (note.label == "") { |
654 max = 0.0; | 665 max = 0.0; |
655 log = false; | 666 log = false; |
656 | 667 |
657 QString queryUnits; | 668 QString queryUnits; |
658 if (shouldConvertMIDIToHz()) queryUnits = "Hz"; | 669 if (shouldConvertMIDIToHz()) queryUnits = "Hz"; |
659 else queryUnits = m_model->getScaleUnits(); | 670 else queryUnits = getScaleUnits(); |
660 | 671 |
661 if (shouldAutoAlign()) { | 672 if (shouldAutoAlign()) { |
662 | 673 |
663 if (!v->getValueExtents(queryUnits, min, max, log)) { | 674 if (!v->getValueExtents(queryUnits, min, max, log)) { |
664 | 675 |
856 | 867 |
857 paint.restore(); | 868 paint.restore(); |
858 } | 869 } |
859 | 870 |
860 int | 871 int |
861 FlexiNoteLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const | 872 FlexiNoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const |
862 { | 873 { |
863 if (m_verticalScale == LinearScale || | 874 if (!m_model || shouldAutoAlign()) { |
864 m_verticalScale == AutoAlignScale) { | |
865 return 0; | 875 return 0; |
876 } else { | |
877 if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { | |
878 return LogNumericalScale().getWidth(v, paint) + 10; // for piano | |
879 } else { | |
880 return LinearNumericalScale().getWidth(v, paint); | |
881 } | |
882 } | |
883 } | |
884 | |
885 void | |
886 FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | |
887 { | |
888 if (!m_model) return; | |
889 | |
890 QString unit; | |
891 float min, max; | |
892 bool logarithmic; | |
893 | |
894 int w = getVerticalScaleWidth(v, false, paint); | |
895 int h = v->height(); | |
896 | |
897 getScaleExtents(v, min, max, logarithmic); | |
898 | |
899 if (logarithmic) { | |
900 LogNumericalScale().paintVertical(v, this, paint, 0, min, max); | |
866 } else { | 901 } else { |
867 return 10; | 902 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); |
868 } | 903 } |
869 } | 904 |
870 | 905 if (logarithmic && (getScaleUnits() == "Hz")) { |
871 void | |
872 FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const | |
873 { | |
874 if (m_verticalScale == LinearScale || | |
875 m_verticalScale == AutoAlignScale) { | |
876 return; | |
877 } else { | |
878 float fmin, fmax; | |
879 bool log; | |
880 QString unit; | |
881 if (!getValueExtents(fmin, fmax, log, unit)) return; | |
882 PianoScale().paintPianoVertical | 906 PianoScale().paintPianoVertical |
883 (v, paint, QRect(0, 0, 10, v->height()), fmin, fmax); | 907 (v, paint, QRect(w - 10, 0, 10, h), |
884 paint.drawLine(10, 0, 10, v->height()); | 908 LogRange::unmap(min), |
909 LogRange::unmap(max)); | |
910 paint.drawLine(w, 0, w, h); | |
911 } | |
912 | |
913 if (getScaleUnits() != "") { | |
914 int mw = w - 5; | |
915 paint.drawText(5, | |
916 5 + paint.fontMetrics().ascent(), | |
917 TextAbbrev::abbreviate(getScaleUnits(), | |
918 paint.fontMetrics(), | |
919 mw)); | |
885 } | 920 } |
886 } | 921 } |
887 | 922 |
888 void | 923 void |
889 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e) | 924 FlexiNoteLayer::drawStart(View *v, QMouseEvent *e) |
1353 (m_model->getSampleRate(), | 1388 (m_model->getSampleRate(), |
1354 ItemEditDialog::ShowTime | | 1389 ItemEditDialog::ShowTime | |
1355 ItemEditDialog::ShowDuration | | 1390 ItemEditDialog::ShowDuration | |
1356 ItemEditDialog::ShowValue | | 1391 ItemEditDialog::ShowValue | |
1357 ItemEditDialog::ShowText, | 1392 ItemEditDialog::ShowText, |
1358 m_model->getScaleUnits()); | 1393 getScaleUnits()); |
1359 | 1394 |
1360 dialog->setFrameTime(note.frame); | 1395 dialog->setFrameTime(note.frame); |
1361 dialog->setValue(note.value); | 1396 dialog->setValue(note.value); |
1362 dialog->setFrameDuration(note.duration); | 1397 dialog->setFrameDuration(note.duration); |
1363 dialog->setText(note.label); | 1398 dialog->setText(note.label); |