annotate widgets/CSVAudioFormatDialog.cpp @ 1386:fc3d89f88690 spectrogramparam

Use log-frequency rather than log-bin for calculating x coord in spectrum. This has the advantage that frequency positions don't move when we change the window size or oversampling ratio, but it does give us an unhelpfully large amount of space for very low frequencies - to be considered
author Chris Cannam
date Mon, 12 Nov 2018 11:34:34 +0000
parents f33ee2702447
children
rev   line source
Chris@378 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@378 2
Chris@378 3 /*
Chris@378 4 Sonic Visualiser
Chris@378 5 An audio file viewer and annotation editor.
Chris@378 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1319 7 This file copyright 2006-2018 Chris Cannam and QMUL.
Chris@378 8
Chris@378 9 This program is free software; you can redistribute it and/or
Chris@378 10 modify it under the terms of the GNU General Public License as
Chris@378 11 published by the Free Software Foundation; either version 2 of the
Chris@378 12 License, or (at your option) any later version. See the file
Chris@378 13 COPYING included with this distribution for more information.
Chris@378 14 */
Chris@378 15
Chris@1319 16 #include "CSVAudioFormatDialog.h"
Chris@378 17
Chris@561 18 #include "layer/LayerFactory.h"
Chris@561 19
Chris@674 20 #include "TextAbbrev.h"
Chris@674 21
Chris@378 22 #include <QFrame>
Chris@378 23 #include <QGridLayout>
Chris@378 24 #include <QPushButton>
Chris@378 25 #include <QHBoxLayout>
Chris@378 26 #include <QVBoxLayout>
Chris@378 27 #include <QTableWidget>
Chris@378 28 #include <QComboBox>
Chris@378 29 #include <QLabel>
Chris@512 30 #include <QDialogButtonBox>
Chris@378 31
Chris@560 32 #include <iostream>
Chris@913 33 #include <cmath>
Chris@378 34
Chris@682 35 #include "base/Debug.h"
Chris@682 36
Chris@1319 37 CSVAudioFormatDialog::CSVAudioFormatDialog(QWidget *parent, CSVFormat format,
Chris@1319 38 int maxDisplayCols) :
Chris@378 39 QDialog(parent),
Chris@581 40 m_format(format),
Chris@581 41 m_maxDisplayCols(maxDisplayCols),
Chris@581 42 m_fuzzyColumn(-1)
Chris@378 43 {
Chris@378 44 setModal(true);
Chris@1319 45 setWindowTitle(tr("Select Audio Data Format"));
Chris@378 46
Chris@378 47 QGridLayout *layout = new QGridLayout;
Chris@378 48
Chris@560 49 int row = 0;
Chris@378 50
Chris@1318 51 layout->addWidget
Chris@1318 52 (new QLabel(tr("Please select the correct data format for this file.")),
Chris@1318 53 row++, 0, 1, 4);
Chris@560 54
Chris@560 55 QFrame *exampleFrame = new QFrame;
Chris@560 56 exampleFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@560 57 exampleFrame->setLineWidth(2);
Chris@560 58 QGridLayout *exampleLayout = new QGridLayout;
Chris@561 59 exampleLayout->setSpacing(4);
Chris@560 60 exampleFrame->setLayout(exampleLayout);
Chris@560 61
Chris@560 62 QPalette palette = exampleFrame->palette();
Chris@560 63 palette.setColor(QPalette::Window, palette.color(QPalette::Base));
Chris@560 64 exampleFrame->setPalette(palette);
Chris@560 65
Chris@560 66 QFont fp;
Chris@908 67 fp.setPointSize(int(floor(fp.pointSize() * 0.9)));
Chris@560 68
Chris@560 69 int columns = format.getColumnCount();
Chris@560 70 QList<QStringList> example = m_format.getExample();
Chris@560 71
Chris@560 72 for (int i = 0; i < columns; ++i) {
Chris@581 73
Chris@560 74 QComboBox *cpc = new QComboBox;
Chris@560 75 m_columnPurposeCombos.push_back(cpc);
Chris@560 76 exampleLayout->addWidget(cpc, 0, i);
Chris@581 77 connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int)));
Chris@1318 78
Chris@581 79 if (i == m_maxDisplayCols && columns > i + 2) {
Chris@581 80 m_fuzzyColumn = i;
Chris@1318 81
Chris@1319 82 cpc->addItem(tr("<ignore>"));
Chris@1319 83 cpc->addItem(tr("Audio channels"));
Chris@1319 84 cpc->setCurrentIndex
Chris@1322 85 (m_format.getColumnPurpose(i-1) == CSVFormat::ColumnValue ?
Chris@1322 86 1 : 0);
Chris@1319 87
Chris@1318 88 exampleLayout->addWidget
Chris@1318 89 (new QLabel(tr("(%1 more)").arg(columns - i)), 1, i);
Chris@581 90 break;
Chris@581 91 }
Chris@560 92
Chris@1319 93 cpc->addItem(tr("<ignore>"));
Chris@1319 94 cpc->addItem(tr("Audio channel"));
Chris@1322 95 cpc->setCurrentIndex
Chris@1322 96 (m_format.getColumnPurpose(i) == CSVFormat::ColumnValue ? 1 : 0);
Chris@1318 97
Chris@581 98 for (int j = 0; j < example.size() && j < 6; ++j) {
Chris@866 99 if (i >= example[j].size()) {
Chris@866 100 continue;
Chris@866 101 }
Chris@581 102 QLabel *label = new QLabel;
Chris@581 103 label->setTextFormat(Qt::PlainText);
Chris@674 104 QString text = TextAbbrev::abbreviate(example[j][i], 35);
Chris@674 105 label->setText(text);
Chris@581 106 label->setFont(fp);
Chris@581 107 label->setPalette(palette);
Chris@581 108 label->setIndent(8);
Chris@581 109 exampleLayout->addWidget(label, j+1, i);
Chris@560 110 }
Chris@560 111 }
Chris@560 112
Chris@560 113 layout->addWidget(exampleFrame, row, 0, 1, 4);
Chris@560 114 layout->setColumnStretch(3, 10);
Chris@560 115 layout->setRowStretch(row++, 10);
Chris@560 116
Chris@1320 117 layout->addWidget(new QLabel(tr("Audio sample rate (Hz):")), row, 0);
Chris@378 118
Chris@807 119 int sampleRates[] = {
Chris@1266 120 8000, 11025, 12000, 22050, 24000, 32000,
Chris@1266 121 44100, 48000, 88200, 96000, 176400, 192000
Chris@378 122 };
Chris@378 123
Chris@378 124 m_sampleRateCombo = new QComboBox;
Chris@807 125 for (int i = 0; i < int(sizeof(sampleRates) / sizeof(sampleRates[0])); ++i) {
Chris@1266 126 m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i]));
Chris@1266 127 if (sampleRates[i] == m_format.getSampleRate()) {
Chris@560 128 m_sampleRateCombo->setCurrentIndex(i);
Chris@560 129 }
Chris@378 130 }
Chris@378 131 m_sampleRateCombo->setEditable(true);
Chris@378 132
Chris@560 133 layout->addWidget(m_sampleRateCombo, row++, 1);
Chris@378 134 connect(m_sampleRateCombo, SIGNAL(activated(QString)),
Chris@1266 135 this, SLOT(sampleRateChanged(QString)));
Chris@378 136 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)),
Chris@1266 137 this, SLOT(sampleRateChanged(QString)));
Chris@1320 138
Chris@1320 139 layout->addWidget(new QLabel(tr("Sample values are:")), row, 0);
Chris@1320 140
Chris@1320 141 m_sampleRangeCombo = new QComboBox;
Chris@1321 142 // NB must be in the same order as the CSVFormat::AudioSampleRange enum
Chris@1320 143 m_sampleRangeCombo->addItem(tr("Floating-point in range -1 to 1"));
Chris@1320 144 m_sampleRangeCombo->addItem(tr("8-bit in range 0 to 255"));
Chris@1320 145 m_sampleRangeCombo->addItem(tr("16-bit in range -32768 to 32767"));
Chris@1320 146 m_sampleRangeCombo->addItem(tr("Unknown range: normalise on load"));
Chris@1321 147 m_sampleRangeCombo->setCurrentIndex(int(m_format.getAudioSampleRange()));
Chris@1320 148
Chris@1320 149 layout->addWidget(m_sampleRangeCombo, row++, 1);
Chris@1320 150 connect(m_sampleRangeCombo, SIGNAL(activated(int)),
Chris@1320 151 this, SLOT(sampleRangeChanged(int)));
Chris@1320 152
Chris@512 153 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@512 154 QDialogButtonBox::Cancel);
Chris@560 155 layout->addWidget(bb, row++, 0, 1, 4);
Chris@512 156 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@512 157 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@378 158
Chris@512 159 setLayout(layout);
Chris@378 160
Chris@1319 161 updateFormatFromDialog();
Chris@378 162 }
Chris@378 163
Chris@1319 164 CSVAudioFormatDialog::~CSVAudioFormatDialog()
Chris@378 165 {
Chris@378 166 }
Chris@378 167
Chris@378 168 CSVFormat
Chris@1319 169 CSVAudioFormatDialog::getFormat() const
Chris@378 170 {
Chris@560 171 return m_format;
Chris@378 172 }
Chris@378 173
Chris@378 174 void
Chris@1319 175 CSVAudioFormatDialog::sampleRateChanged(QString rateString)
Chris@378 176 {
Chris@378 177 bool ok = false;
Chris@378 178 int sampleRate = rateString.toInt(&ok);
Chris@560 179 if (ok) m_format.setSampleRate(sampleRate);
Chris@378 180 }
Chris@378 181
Chris@378 182 void
Chris@1320 183 CSVAudioFormatDialog::sampleRangeChanged(int range)
Chris@1320 184 {
Chris@1321 185 m_format.setAudioSampleRange((CSVFormat::AudioSampleRange)range);
Chris@1320 186 }
Chris@1320 187
Chris@1320 188 void
Chris@1319 189 CSVAudioFormatDialog::columnPurposeChanged(int)
Chris@378 190 {
Chris@1318 191 updateFormatFromDialog();
Chris@1318 192 }
Chris@1318 193
Chris@1318 194 void
Chris@1319 195 CSVAudioFormatDialog::updateFormatFromDialog()
Chris@1318 196 {
Chris@1319 197 m_format.setModelType(CSVFormat::WaveFileModel);
Chris@1319 198 m_format.setTimingType(CSVFormat::ImplicitTiming);
Chris@1319 199 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
Chris@1318 200
Chris@959 201 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
Chris@959 202
Chris@959 203 QComboBox *thisCombo = m_columnPurposeCombos[i];
Chris@959 204
Chris@1319 205 CSVFormat::ColumnPurpose purpose = (thisCombo->currentIndex() == 1 ?
Chris@1319 206 CSVFormat::ColumnValue :
Chris@1319 207 CSVFormat::ColumnUnknown);
Chris@1319 208
Chris@959 209 if (i == m_fuzzyColumn) {
Chris@992 210 for (int j = i; j < m_format.getColumnCount(); ++j) {
Chris@1319 211 m_format.setColumnPurpose(j, purpose);
Chris@959 212 }
Chris@992 213 } else {
Chris@992 214 m_format.setColumnPurpose(i, purpose);
Chris@959 215 }
Chris@561 216 }
Chris@560 217 }
Chris@560 218
Chris@560 219
Chris@959 220