Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp Wed Dec 04 11:35:08 2013 +0000 +++ b/layer/FlexiNoteLayer.cpp Wed Dec 04 13:46:29 2013 +0000 @@ -24,11 +24,15 @@ #include "base/RangeMapper.h" #include "ColourDatabase.h" #include "view/View.h" + #include "PianoScale.h" +#include "LinearNumericalScale.h" +#include "LogNumericalScale.h" #include "data/model/FlexiNoteModel.h" #include "widgets/ItemEditDialog.h" +#include "widgets/TextAbbrev.h" #include <QPainter> #include <QPainterPath> @@ -116,6 +120,13 @@ return SingleColourLayer::getPropertyGroupName(name); } +QString +NoteLayer::getScaleUnits() const +{ + if (m_model) return m_model->getScaleUnits(); + else return ""; +} + int FlexiNoteLayer::getPropertyRangeAndValue(const PropertyName &name, int *min, int *max, int *deflt) const @@ -135,7 +146,7 @@ if (deflt) *deflt = 0; if (m_model) { val = UnitDatabase::getInstance()->getUnitId - (m_model->getScaleUnits()); + (getScaleUnits()); } } else { @@ -196,7 +207,7 @@ bool FlexiNoteLayer::shouldConvertMIDIToHz() const { - QString unit = m_model->getScaleUnits(); + QString unit = getScaleUnits(); return (unit != "Hz"); // if (unit == "" || // unit.startsWith("MIDI") || @@ -216,7 +227,7 @@ unit = "Hz"; min = Pitch::getFrequencyForPitch(lrintf(min)); max = Pitch::getFrequencyForPitch(lrintf(max + 1)); - } else unit = m_model->getScaleUnits(); + } else unit = getScaleUnits(); if (m_verticalScale == MIDIRangeScale || m_verticalScale == LogScale) logarithmic = true; @@ -543,7 +554,7 @@ .arg(mnote) .arg(freq); - } else if (m_model->getScaleUnits() == "Hz") { + } else if (getScaleUnits() == "Hz") { pitchText = tr("%1 Hz (%2, %3)") .arg(note.value) @@ -552,7 +563,7 @@ } else { pitchText = tr("%1 %2") - .arg(note.value).arg(m_model->getScaleUnits()); + .arg(note.value).arg(getScaleUnits()); } QString text; @@ -656,7 +667,7 @@ QString queryUnits; if (shouldConvertMIDIToHz()) queryUnits = "Hz"; - else queryUnits = m_model->getScaleUnits(); + else queryUnits = getScaleUnits(); if (shouldAutoAlign()) { @@ -858,30 +869,54 @@ } int -FlexiNoteLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const +FlexiNoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const { - if (m_verticalScale == LinearScale || - m_verticalScale == AutoAlignScale) { + if (!m_model || shouldAutoAlign()) { return 0; - } else { - return 10; + } else { + if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { + return LogNumericalScale().getWidth(v, paint) + 10; // for piano + } else { + return LinearNumericalScale().getWidth(v, paint); + } } } void FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const { - if (m_verticalScale == LinearScale || - m_verticalScale == AutoAlignScale) { - return; + if (!m_model) return; + + QString unit; + float min, max; + bool logarithmic; + + int w = getVerticalScaleWidth(v, false, paint); + int h = v->height(); + + getScaleExtents(v, min, max, logarithmic); + + if (logarithmic) { + LogNumericalScale().paintVertical(v, this, paint, 0, min, max); } else { - float fmin, fmax; - bool log; - QString unit; - if (!getValueExtents(fmin, fmax, log, unit)) return; + LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); + } + + if (logarithmic && (getScaleUnits() == "Hz")) { PianoScale().paintPianoVertical - (v, paint, QRect(0, 0, 10, v->height()), fmin, fmax); - paint.drawLine(10, 0, 10, v->height()); + (v, paint, QRect(w - 10, 0, 10, h), + LogRange::unmap(min), + LogRange::unmap(max)); + paint.drawLine(w, 0, w, h); + } + + if (getScaleUnits() != "") { + int mw = w - 5; + paint.drawText(5, + 5 + paint.fontMetrics().ascent(), + TextAbbrev::abbreviate(getScaleUnits(), + paint.fontMetrics(), + mw)); } } @@ -1355,7 +1390,7 @@ ItemEditDialog::ShowDuration | ItemEditDialog::ShowValue | ItemEditDialog::ShowText, - m_model->getScaleUnits()); + getScaleUnits()); dialog->setFrameTime(note.frame); dialog->setValue(note.value);