# HG changeset patch # User Chris Cannam # Date 1383585152 0 # Node ID 26c5f7fd4807211cc18b3e8e68b67f43e962203c # Parent 5e5ab4e8d64bf25a784bd22be3166bf8c2f79aad# Parent d8bd193ad17dfac2e50090969a217461441ea70c Merge from the default branch diff -r 5e5ab4e8d64b -r 26c5f7fd4807 .hgtags --- a/.hgtags Mon Nov 04 17:10:51 2013 +0000 +++ b/.hgtags Mon Nov 04 17:12:32 2013 +0000 @@ -25,3 +25,5 @@ 3803f6dcf361c9ec82badb20e3ca9f5c712c5d2f sv_v1.9 ea786e8bd931243adc95a040988edd0d6b5bbc0a sv_v2.0 c6d705bf1672f2cd7f3d4cfe46aa3db6062c004c sv_v2.1 +c6d705bf1672f2cd7f3d4cfe46aa3db6062c004c sv_v2.1 +77fa3fdbfc7e2b9f96eac6524d48294fb47760c3 sv_v2.1 diff -r 5e5ab4e8d64b -r 26c5f7fd4807 layer/NoteLayer.cpp --- a/layer/NoteLayer.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/layer/NoteLayer.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -38,6 +38,8 @@ #include #include +//#define DEBUG_NOTE_LAYER 1 + NoteLayer::NoteLayer() : SingleColourLayer(), m_model(0), @@ -234,6 +236,10 @@ max = Pitch::getFrequencyForPitch(lrintf(max + 1)); } +#ifdef DEBUG_NOTE_LAYER + std::cerr << "NoteLayer::getDisplayExtents: min = " << min << ", max = " << max << " (m_scaleMinimum = " << m_scaleMinimum << ", m_scaleMaximum = " << m_scaleMaximum << ")" << std::endl; +#endif + return true; } @@ -253,7 +259,9 @@ m_scaleMinimum = min; m_scaleMaximum = max; -// SVDEBUG << "NoteLayer::setDisplayExtents: min = " << min << ", max = " << max << endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "NoteLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl; +#endif emit layerParametersChanged(); return true; @@ -334,7 +342,9 @@ newmax = max; } - SVDEBUG << "NoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; +#ifdef DEBUG_NOTE_LAYER + std::cerr << "NoteLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl; +#endif setDisplayExtents(newmin, newmax); } @@ -615,13 +625,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 +669,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; } @@ -1264,7 +1286,7 @@ float min = attributes.value("scaleMinimum").toFloat(&ok); float max = attributes.value("scaleMaximum").toFloat(&alsoOk); - if (ok && alsoOk) setDisplayExtents(min, max); + if (ok && alsoOk && min != max) setDisplayExtents(min, max); } diff -r 5e5ab4e8d64b -r 26c5f7fd4807 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/layer/TimeValueLayer.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -320,10 +320,14 @@ bool &logarithmic, QString &unit) const { if (!m_model) return false; + min = m_model->getValueMinimum(); max = m_model->getValueMaximum(); + logarithmic = (m_verticalScale == LogScale); + unit = m_model->getScaleUnits(); + if (m_derivative) { max = std::max(fabsf(min), fabsf(max)); min = -max; @@ -333,6 +337,22 @@ std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; #endif + if (!shouldAutoAlign() && !logarithmic && !m_derivative) { + + 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::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; +#endif + } + return true; } @@ -342,8 +362,9 @@ if (!m_model || shouldAutoAlign()) return false; if (m_scaleMinimum == m_scaleMaximum) { - min = m_model->getValueMinimum(); - max = m_model->getValueMaximum(); + bool log; + QString unit; + getValueExtents(min, max, log, unit); } else { min = m_scaleMinimum; max = m_scaleMaximum; @@ -773,19 +794,6 @@ #ifdef DEBUG_TIME_VALUE_LAYER 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; - } - -#ifdef DEBUG_TIME_VALUE_LAYER - 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); } diff -r 5e5ab4e8d64b -r 26c5f7fd4807 layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/layer/WaveformLayer.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -670,7 +670,7 @@ *ranges, modelZoomLevel); #ifdef DEBUG_WAVEFORM_PAINT - std::cerr << ranges->size() << " ranges from " << frame0 << " to " << frame1 << std::endl; + std::cerr << "channel " << ch << ": " << ranges->size() << " ranges from " << frame0 << " to " << frame1 << " at zoom level " << modelZoomLevel << std::endl; #endif if (mergingChannels || mixingChannels) { @@ -844,18 +844,18 @@ } if (x != x0 && prevRangeBottom != -1) { - if (prevRangeBottom > rangeBottom && - prevRangeTop > rangeBottom) { + if (prevRangeBottom > rangeBottom + 1 && + prevRangeTop > rangeBottom + 1) { // paint->setPen(midColour); paint->setPen(baseColour); - paint->drawLine(x-1, prevRangeTop, x, rangeBottom); + paint->drawLine(x-1, prevRangeTop, x, rangeBottom + 1); paint->setPen(prevRangeTopColour); paint->drawPoint(x-1, prevRangeTop); - } else if (prevRangeBottom < rangeTop && - prevRangeTop < rangeTop) { + } else if (prevRangeBottom < rangeTop - 1 && + prevRangeTop < rangeTop - 1) { // paint->setPen(midColour); paint->setPen(baseColour); - paint->drawLine(x-1, prevRangeBottom, x, rangeTop); + paint->drawLine(x-1, prevRangeBottom, x, rangeTop - 1); paint->setPen(prevRangeBottomColour); paint->drawPoint(x-1, prevRangeBottom); } @@ -874,7 +874,7 @@ } #ifdef DEBUG_WAVEFORM_PAINT - std::cerr << "range " << rangeBottom << " -> " << rangeTop << std::endl; + std::cerr << "range " << rangeBottom << " -> " << rangeTop << ", means " << meanBottom << " -> " << meanTop << ", raw range " << range.min() << " -> " << range.max() << std::endl; #endif if (rangeTop == rangeBottom) { @@ -990,11 +990,11 @@ max = range.max(); singleValue = (min == max); } else { - int imin = int(range.min() * 1000); - int imax = int(range.max() * 1000); + int imin = lrint(range.min() * 10000); + int imax = lrint(range.max() * 10000); singleValue = (imin == imax); - min = float(imin)/1000; - max = float(imax)/1000; + min = float(imin)/10000; + max = float(imax)/10000; } int db = int(AudioLevel::multiplier_to_dB(std::max(fabsf(range.min()), diff -r 5e5ab4e8d64b -r 26c5f7fd4807 view/Pane.cpp --- a/view/Pane.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/view/Pane.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -1120,7 +1120,6 @@ if (m_manager && m_manager->shouldShowVerticalScale()) { for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { --vi; - QPainter paint(image); sw = (*vi)->getVerticalScaleWidth (this, m_manager->shouldShowVerticalColourScale(), paint); break; diff -r 5e5ab4e8d64b -r 26c5f7fd4807 view/View.cpp --- a/view/View.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/view/View.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -995,7 +995,7 @@ case PlaybackScrollPage: { int xold = getXForFrame(oldPlayPointerFrame); - update(xold - 1, 0, 3, height()); + update(xold - 4, 0, 9, height()); long w = getEndFrame() - getStartFrame(); w -= w/5; @@ -1034,12 +1034,12 @@ bool changed = setCentreFrame(newCentre, false); if (changed) { xold = getXForFrame(oldPlayPointerFrame); - update(xold - 1, 0, 3, height()); + update(xold - 4, 0, 9, height()); } } } - update(xnew - 1, 0, 3, height()); + update(xnew - 4, 0, 9, height()); break; } diff -r 5e5ab4e8d64b -r 26c5f7fd4807 widgets/CSVFormatDialog.cpp --- a/widgets/CSVFormatDialog.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/widgets/CSVFormatDialog.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -17,6 +17,8 @@ #include "layer/LayerFactory.h" +#include "TextAbbrev.h" + #include #include #include @@ -96,7 +98,8 @@ for (int j = 0; j < example.size() && j < 6; ++j) { QLabel *label = new QLabel; label->setTextFormat(Qt::PlainText); - label->setText(example[j][i]); + QString text = TextAbbrev::abbreviate(example[j][i], 35); + label->setText(text); label->setFont(fp); label->setPalette(palette); label->setIndent(8); diff -r 5e5ab4e8d64b -r 26c5f7fd4807 widgets/InteractiveFileFinder.cpp --- a/widgets/InteractiveFileFinder.cpp Mon Nov 04 17:10:51 2013 +0000 +++ b/widgets/InteractiveFileFinder.cpp Mon Nov 04 17:12:32 2013 +0000 @@ -102,6 +102,11 @@ } break; + case CSVFile: + settingsKey = "layerpath"; + filter = tr("Comma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nText files (*.txt)\nAll files (*.*)"); + break; + case AnyFile: settingsKey = "lastpath"; filter = tr("All supported files (*.sv %1 %2 %3)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nLayer files (%2)\nRDF files (%3)\nAll files (*.*)") @@ -229,6 +234,12 @@ filter = tr("Portable Network Graphics files (*.png)\nAll files (*.*)"); break; + case CSVFile: + settingsKey = "savelayerpath"; + title = tr("Select a file to export to"); + filter = tr("Comma-separated data files (*.csv)\nText files (*.txt)\nAll files (*.*)"); + break; + case AnyFile: std::cerr << "ERROR: Internal error: InteractiveFileFinder::getSaveFileName: AnyFile cannot be used here" << std::endl; abort(); @@ -268,6 +279,8 @@ dialog.setDefaultSuffix("wav"); } else if (type == ImageFile) { dialog.setDefaultSuffix("png"); + } else if (type == CSVFile) { + dialog.setDefaultSuffix("csv"); } bool good = false; @@ -364,6 +377,10 @@ settingsKey = "imagepath"; break; + case CSVFile: + settingsKey = "layerpath"; + break; + case AnyFile: settingsKey = "lastpath"; break;