# HG changeset patch # User Chris Cannam # Date 1547047491 0 # Node ID fa986b91d77f412f7e801a3cdfc3d0878505fa2c # Parent 0930a27ebea2900493df44300251d68f4e619eaf# Parent d057dcc827e7c2e3c82c9059b284cec8f9ae39d7 Merge from branch fix-static-analysis diff -r d057dcc827e7 -r fa986b91d77f layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Tue Dec 04 13:49:09 2018 +0000 +++ b/layer/Colour3DPlotLayer.cpp Wed Jan 09 15:24:51 2019 +0000 @@ -205,7 +205,7 @@ Colour3DPlotLayer::invalidateMagnitudes() { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "Colour3DPlotLayer::invalidateMagnitudes called" << endl; + SVDEBUG << "Colour3DPlotLayer::invalidateMagnitudes called" << endl; #endif m_viewMags.clear(); } @@ -626,7 +626,7 @@ if (dormant) { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")" + SVDEBUG << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")" << endl; #endif @@ -1118,8 +1118,9 @@ if (m_viewMags[viewId] != magRange) { m_viewMags[viewId] = magRange; #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "mag range in this view has changed: " - << magRange.getMin() << " -> " << magRange.getMax() << endl; + SVDEBUG << "mag range in this view has changed: " + << magRange.getMin() << " -> " + << magRange.getMax() << endl; #endif } } @@ -1127,7 +1128,7 @@ if (!continuingPaint && m_normalizeVisibleArea && m_viewMags[viewId] != m_lastRenderedMags[viewId]) { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "mag range has changed from last rendered range: re-rendering" + SVDEBUG << "mag range has changed from last rendered range: re-rendering" << endl; #endif delete m_renderers[viewId]; @@ -1146,7 +1147,7 @@ */ Profiler profiler("Colour3DPlotLayer::paint"); #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl; + SVDEBUG << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl; #endif int completion = 0; @@ -1160,7 +1161,7 @@ if (m_model->getWidth() == 0) { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "Colour3DPlotLayer::paint(): model width == 0, " + SVDEBUG << "Colour3DPlotLayer::paint(): model width == 0, " << "nothing to paint (yet)" << endl; #endif return; @@ -1305,8 +1306,8 @@ } else if (columnNormalization == "none") { setNormalization(ColumnNormalization::None); } else { - cerr << "NOTE: Unknown or unsupported columnNormalization attribute \"" - << columnNormalization << "\"" << endl; + SVCERR << "NOTE: Unknown or unsupported columnNormalization attribute \"" + << columnNormalization << "\"" << endl; } } diff -r d057dcc827e7 -r fa986b91d77f layer/Colour3DPlotRenderer.cpp --- a/layer/Colour3DPlotRenderer.cpp Tue Dec 04 13:49:09 2018 +0000 +++ b/layer/Colour3DPlotRenderer.cpp Wed Jan 09 15:24:51 2019 +0000 @@ -305,6 +305,14 @@ } MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); + +#ifdef DEBUG_COLOUR_PLOT_REPAINT + SVDEBUG << "render: returning rect rendered as " << pr.x() << "," << pr.y() + << " " << pr.width() << "x" << pr.height() << endl; + SVDEBUG << "render: mag range from cache in x-range " << reqx0 + << " to " << reqx1 << " is " << range.getMin() << " -> " + << range.getMax() << endl; +#endif return { pr, range }; } diff -r d057dcc827e7 -r fa986b91d77f layer/ScrollableMagRangeCache.cpp --- a/layer/ScrollableMagRangeCache.cpp Tue Dec 04 13:49:09 2018 +0000 +++ b/layer/ScrollableMagRangeCache.cpp Wed Jan 09 15:24:51 2019 +0000 @@ -15,6 +15,7 @@ #include "ScrollableMagRangeCache.h" #include "base/HitCount.h" +#include "base/Debug.h" #include using namespace std; @@ -31,8 +32,8 @@ v->getXForFrame(newStartFrame)); #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE - cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame - << " -> " << newStartFrame << ", dx = " << dx << endl; + SVDEBUG << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame + << " -> " << newStartFrame << ", dx = " << dx << endl; #endif if (m_startFrame == newStartFrame) { @@ -86,11 +87,11 @@ } #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE - cerr << "maxes (" << m_ranges.size() << ") now: "; + SVDEBUG << "maxes (" << m_ranges.size() << ") now: "; for (int i = 0; in_range_for(m_ranges, i); ++i) { - cerr << m_ranges[i].getMax() << " "; + SVDEBUG << m_ranges[i].getMax() << " "; } - cerr << endl; + SVDEBUG << endl; #endif } @@ -99,11 +100,20 @@ { MagnitudeRange r; #ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE - cerr << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; + SVDEBUG << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; #endif for (int i = 0; i < count; ++i) { - r.sample(m_ranges.at(x + i)); + const auto &cr = m_ranges.at(x + i); + if (cr.isSet()) { + r.sample(cr); + } +#ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE + SVDEBUG << cr.getMin() << "->" << cr.getMax() << " "; +#endif } +#ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE + SVDEBUG << endl; +#endif return r; } @@ -111,9 +121,9 @@ ScrollableMagRangeCache::sampleColumn(int column, const MagnitudeRange &r) { if (!in_range_for(m_ranges, column)) { - cerr << "ERROR: ScrollableMagRangeCache::sampleColumn: column " << column - << " is out of range for cache of width " << m_ranges.size() - << " (with start frame " << m_startFrame << ")" << endl; + SVCERR << "ERROR: ScrollableMagRangeCache::sampleColumn: column " << column + << " is out of range for cache of width " << m_ranges.size() + << " (with start frame " << m_startFrame << ")" << endl; throw logic_error("column out of range"); } else { m_ranges[column].sample(r); diff -r d057dcc827e7 -r fa986b91d77f widgets/CSVFormatDialog.cpp --- a/widgets/CSVFormatDialog.cpp Tue Dec 04 13:49:09 2018 +0000 +++ b/widgets/CSVFormatDialog.cpp Wed Jan 09 15:24:51 2019 +0000 @@ -34,16 +34,49 @@ #include "base/Debug.h" -CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format, +CSVFormatDialog::CSVFormatDialog(QWidget *parent, + CSVFormat format, int maxDisplayCols) : QDialog(parent), + m_csvFilePath(""), + m_referenceSampleRate(0), m_format(format), m_maxDisplayCols(maxDisplayCols), m_fuzzyColumn(-1) { + init(); +} + +CSVFormatDialog::CSVFormatDialog(QWidget *parent, + QString csvFilePath, + sv_samplerate_t referenceSampleRate, + int maxDisplayCols) : + QDialog(parent), + m_csvFilePath(csvFilePath), + m_referenceSampleRate(referenceSampleRate), + m_maxDisplayCols(maxDisplayCols), + m_fuzzyColumn(-1) +{ + m_format = CSVFormat(csvFilePath); + m_format.setSampleRate(referenceSampleRate); + init(); +} + +CSVFormatDialog::~CSVFormatDialog() +{ +} + +static int sampleRates[] = { + 8000, 11025, 12000, 22050, 24000, 32000, + 44100, 48000, 88200, 96000, 176400, 192000 +}; + +void +CSVFormatDialog::init() +{ setModal(true); setWindowTitle(tr("Select Data Format")); - + QGridLayout *layout = new QGridLayout; int row = 0; @@ -52,6 +85,105 @@ (new QLabel(tr("Please select the correct data format for this file.")), row++, 0, 1, 4); + m_exampleFrame = nullptr; + m_exampleFrameRow = row++; + + std::set plausible = m_format.getPlausibleSeparators(); + SVDEBUG << "Have " << plausible.size() << " plausible separator(s)" << endl; + + if (m_csvFilePath != "" && plausible.size() > 1) { + // can only update when separator changed if we still have a + // file to refer to + layout->addWidget(new QLabel(tr("Column separator:")), row, 0); + m_separatorCombo = new QComboBox; + for (QChar c: plausible) { + m_separatorCombo->addItem(QString(c)); + if (c == m_format.getSeparator()) { + m_separatorCombo->setCurrentIndex(m_separatorCombo->count()-1); + } + } + m_separatorCombo->setEditable(false); + + layout->addWidget(m_separatorCombo, row++, 1); + connect(m_separatorCombo, SIGNAL(activated(QString)), + this, SLOT(separatorChanged(QString))); + } + + layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); + + m_timingTypeCombo = new QComboBox; + + m_timingLabels = { + { TimingExplicitSeconds, tr("Explicitly, in seconds") }, + { TimingExplicitMsec, tr("Explicitly, in milliseconds") }, + { TimingExplicitSamples, tr("Explicitly, in audio sample frames") }, + { TimingImplicit, tr("Implicitly: rows are equally spaced in time") } + }; + + for (auto &l: m_timingLabels) { + m_timingTypeCombo->addItem(l.second); + } + + layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2); + + connect(m_timingTypeCombo, SIGNAL(activated(int)), + this, SLOT(timingTypeChanged(int))); + + m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); + layout->addWidget(m_sampleRateLabel, row, 0); + + m_sampleRateCombo = new QComboBox; + for (int i = 0; i < int(sizeof(sampleRates) / sizeof(sampleRates[0])); ++i) { + m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i])); + } + m_sampleRateCombo->setEditable(true); + + layout->addWidget(m_sampleRateCombo, row++, 1); + connect(m_sampleRateCombo, SIGNAL(activated(QString)), + this, SLOT(sampleRateChanged(QString))); + connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), + this, SLOT(sampleRateChanged(QString))); + + m_windowSizeLabel = new QLabel(tr("Frame increment between rows:")); + layout->addWidget(m_windowSizeLabel, row, 0); + + m_windowSizeCombo = new QComboBox; + for (int i = 0; i <= 16; ++i) { + int value = 1 << i; + m_windowSizeCombo->addItem(QString("%1").arg(value)); + } + m_windowSizeCombo->setEditable(true); + + layout->addWidget(m_windowSizeCombo, row++, 1); + connect(m_windowSizeCombo, SIGNAL(activated(QString)), + this, SLOT(windowSizeChanged(QString))); + connect(m_windowSizeCombo, SIGNAL(editTextChanged(QString)), + this, SLOT(windowSizeChanged(QString))); + + m_modelLabel = new QLabel; + QFont f(m_modelLabel->font()); + f.setItalic(true); + m_modelLabel->setFont(f); + layout->addWidget(m_modelLabel, row++, 0, 1, 4); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + layout->addWidget(bb, row++, 0, 1, 4); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); + + setLayout(layout); + + repopulate(); +} + +void +CSVFormatDialog::repopulate() +{ + SVCERR << "CSVFormatDialog::repopulate()" << endl; + + QGridLayout *layout = qobject_cast(this->layout()); + QFrame *exampleFrame = new QFrame; exampleFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); exampleFrame->setLineWidth(2); @@ -66,9 +198,11 @@ QFont fp; fp.setPointSize(int(floor(fp.pointSize() * 0.9))); - int columns = format.getColumnCount(); + int columns = m_format.getColumnCount(); QList example = m_format.getExample(); + m_columnPurposeCombos.clear(); + for (int i = 0; i < columns; ++i) { QComboBox *cpc = new QComboBox; @@ -115,29 +249,14 @@ } } - layout->addWidget(exampleFrame, row, 0, 1, 4); + if (m_exampleFrame) { + delete m_exampleFrame; + } + m_exampleFrame = exampleFrame; + + layout->addWidget(exampleFrame, m_exampleFrameRow, 0, 1, 4); layout->setColumnStretch(3, 10); - layout->setRowStretch(row++, 10); - - layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); - - m_timingTypeCombo = new QComboBox; - - m_timingLabels = { - { TimingExplicitSeconds, tr("Explicitly, in seconds") }, - { TimingExplicitMsec, tr("Explicitly, in milliseconds") }, - { TimingExplicitSamples, tr("Explicitly, in audio sample frames") }, - { TimingImplicit, tr("Implicitly: rows are equally spaced in time") } - }; - - for (auto &l: m_timingLabels) { - m_timingTypeCombo->addItem(l.second); - } - - layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2); - - connect(m_timingTypeCombo, SIGNAL(activated(int)), - this, SLOT(timingTypeChanged(int))); + layout->setRowStretch(m_exampleFrameRow, 10); m_initialTimingOption = TimingImplicit; if (m_format.getTimingType() == CSVFormat::ExplicitTiming) { @@ -153,70 +272,23 @@ } } m_timingTypeCombo->setCurrentIndex(int(m_initialTimingOption)); - - m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); - layout->addWidget(m_sampleRateLabel, row, 0); - int sampleRates[] = { - 8000, 11025, 12000, 22050, 24000, 32000, - 44100, 48000, 88200, 96000, 176400, 192000 - }; - - m_sampleRateCombo = new QComboBox; for (int i = 0; i < int(sizeof(sampleRates) / sizeof(sampleRates[0])); ++i) { - m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i])); if (sampleRates[i] == m_format.getSampleRate()) { m_sampleRateCombo->setCurrentIndex(i); } } - m_sampleRateCombo->setEditable(true); - - layout->addWidget(m_sampleRateCombo, row++, 1); - connect(m_sampleRateCombo, SIGNAL(activated(QString)), - this, SLOT(sampleRateChanged(QString))); - connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), - this, SLOT(sampleRateChanged(QString))); - - m_windowSizeLabel = new QLabel(tr("Frame increment between rows:")); - layout->addWidget(m_windowSizeLabel, row, 0); - m_windowSizeCombo = new QComboBox; for (int i = 0; i <= 16; ++i) { int value = 1 << i; - m_windowSizeCombo->addItem(QString("%1").arg(value)); if (value == int(m_format.getWindowSize())) { m_windowSizeCombo->setCurrentIndex(i); } } - m_windowSizeCombo->setEditable(true); - - layout->addWidget(m_windowSizeCombo, row++, 1); - connect(m_windowSizeCombo, SIGNAL(activated(QString)), - this, SLOT(windowSizeChanged(QString))); - connect(m_windowSizeCombo, SIGNAL(editTextChanged(QString)), - this, SLOT(windowSizeChanged(QString))); - - m_modelLabel = new QLabel; - QFont f(m_modelLabel->font()); - f.setItalic(true); - m_modelLabel->setFont(f); - layout->addWidget(m_modelLabel, row++, 0, 1, 4); - - QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | - QDialogButtonBox::Cancel); - layout->addWidget(bb, row++, 0, 1, 4); - connect(bb, SIGNAL(accepted()), this, SLOT(accept())); - connect(bb, SIGNAL(rejected()), this, SLOT(reject())); - - setLayout(layout); timingTypeChanged(m_timingTypeCombo->currentIndex()); } -CSVFormatDialog::~CSVFormatDialog() -{ -} - CSVFormat CSVFormatDialog::getFormat() const { @@ -315,6 +387,19 @@ } void +CSVFormatDialog::separatorChanged(QString sep) +{ + if (sep == "" || m_csvFilePath == "") { + return; + } + + m_format.setSeparator(sep[0]); + m_format.guessFormatFor(m_csvFilePath); + + repopulate(); +} + +void CSVFormatDialog::timingTypeChanged(int type) { // Update any column purpose combos diff -r d057dcc827e7 -r fa986b91d77f widgets/CSVFormatDialog.h --- a/widgets/CSVFormatDialog.h Tue Dec 04 13:49:09 2018 +0000 +++ b/widgets/CSVFormatDialog.h Wed Jan 09 15:24:51 2019 +0000 @@ -21,6 +21,7 @@ class QTableWidget; class QComboBox; class QLabel; +class QFrame; #include @@ -31,12 +32,19 @@ public: CSVFormatDialog(QWidget *parent, CSVFormat initialFormat, - int maxDisplayCols = 5); + int maxDisplayCols); + + CSVFormatDialog(QWidget *parent, + QString csvFilePath, // to guess format of + sv_samplerate_t referenceSampleRate, + int maxDisplayCols); + ~CSVFormatDialog(); CSVFormat getFormat() const; protected slots: + void separatorChanged(QString); void timingTypeChanged(int type); void sampleRateChanged(QString); void windowSizeChanged(QString); @@ -46,6 +54,8 @@ void updateModelLabel(); protected: + QString m_csvFilePath; + sv_samplerate_t m_referenceSampleRate; CSVFormat m_format; int m_maxDisplayCols; @@ -58,11 +68,17 @@ std::map m_timingLabels; TimingOption m_initialTimingOption; + void init(); + void repopulate(); void columnPurposeChangedForAnnotationType(QComboBox *, int purpose); void updateComboVisibility(); void applyStartTimePurpose(); void removeStartTimePurpose(); + + QFrame *m_exampleFrame; + int m_exampleFrameRow; + QComboBox *m_separatorCombo; QComboBox *m_timingTypeCombo; QLabel *m_sampleRateLabel; QComboBox *m_sampleRateCombo;