# HG changeset patch # User Chris Cannam # Date 1373978581 -3600 # Node ID 12e6efc8cdc0a88a326ea1b42d0de31e926ef53e # Parent ab9fefdaa103771361af4703809acb939573f83d# Parent 7cb6112c59ca1e4161876dca31adcb00f77c6d6b Merge diff -r 7cb6112c59ca -r 12e6efc8cdc0 layer/NoteLayer.cpp --- a/layer/NoteLayer.cpp Thu Jul 11 17:34:33 2013 +0100 +++ b/layer/NoteLayer.cpp Tue Jul 16 13:43:01 2013 +0100 @@ -38,6 +38,8 @@ #include #include +//#define DEBUG_NOTE_LAYER 1 + NoteLayer::NoteLayer() : SingleColourLayer(), m_model(0), @@ -615,13 +617,17 @@ max = Pitch::getFrequencyForPitch(lrintf(max + 1)); } +#ifdef DEBUG_NOTE_LAYER std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; +#endif } else if (log) { LogRange::mapRange(min, max); +#ifdef DEBUG_NOTE_LAYER std::cerr << "NoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; +#endif } @@ -655,21 +661,29 @@ getScaleExtents(v, min, max, logarithmic); -// std::cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "NoteLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; +#endif if (shouldConvertMIDIToHz()) { val = Pitch::getFrequencyForPitch(lrintf(val), lrintf((val - lrintf(val)) * 100)); -// std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "shouldConvertMIDIToHz true, val now = " << val << std::endl; +#endif } if (logarithmic) { val = LogRange::map(val); -// std::cerr << "logarithmic true, val now = " << val << std::endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "logarithmic true, val now = " << val << std::endl; +#endif } int y = int(h - ((val - min) * h) / (max - min)) - 1; -// std::cerr << "y = " << y << std::endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "y = " << y << std::endl; +#endif return y; } diff -r 7cb6112c59ca -r 12e6efc8cdc0 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Thu Jul 11 17:34:33 2013 +0100 +++ b/layer/TimeValueLayer.cpp Tue Jul 16 13:43:01 2013 +0100 @@ -746,13 +746,18 @@ max = 0.0; log = false; + bool haveAutoAlignment = false; + if (shouldAutoAlign()) { if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) { min = m_model->getValueMinimum(); max = m_model->getValueMaximum(); - } else if (log) { - LogRange::mapRange(min, max); + } else { + haveAutoAlignment = true; + if (log) { + LogRange::mapRange(min, max); + } } } else if (m_verticalScale == PlusMinusOneScale) { @@ -774,18 +779,21 @@ std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; #endif - if (max == min) { - max = max + 0.5; - min = min - 0.5; - } else { - float margin = (max - min) / 10.0; - max = max + margin; - min = min - margin; - } + if (!haveAutoAlignment) { + + if (max == min) { + max = max + 0.5; + min = min - 0.5; + } else { + float margin = (max - min) / 10.0; + max = max + margin; + min = min - margin; + } #ifdef DEBUG_TIME_VALUE_LAYER - std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; + std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; #endif + } } int @@ -1255,7 +1263,7 @@ if (prec < 0) dp = -prec; round = powf(10.f, prec); #ifdef DEBUG_TIME_VALUE_LAYER - std::cerr << "inc = " << inc << ", round = " << round << std::endl; + std::cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << std::endl; #endif } @@ -1295,7 +1303,11 @@ } if (logarithmic) { - sprintf(buffer, "%.*g", dp < 2 ? 2 : dp, LogRange::unmap(dispval)); + double dv = LogRange::unmap(dispval); + int digits = trunc(log10f(dv)); + int sf = dp + (digits > 0 ? digits : 0); + if (sf < 2) sf = 2; + sprintf(buffer, "%.*g", sf, dv); } else { sprintf(buffer, "%.*f", dp, dispval); }