Mercurial > hg > svgui
comparison widgets/CSVAudioFormatDialog.cpp @ 1320:6440ba1ffc86 import-audio-data
Sample range
author | Chris Cannam |
---|---|
date | Thu, 06 Sep 2018 16:26:40 +0100 |
parents | fbda05431ce0 |
children | 4616e1e89189 |
comparison
equal
deleted
inserted
replaced
1319:fbda05431ce0 | 1320:6440ba1ffc86 |
---|---|
36 | 36 |
37 CSVAudioFormatDialog::CSVAudioFormatDialog(QWidget *parent, CSVFormat format, | 37 CSVAudioFormatDialog::CSVAudioFormatDialog(QWidget *parent, CSVFormat format, |
38 int maxDisplayCols) : | 38 int maxDisplayCols) : |
39 QDialog(parent), | 39 QDialog(parent), |
40 m_format(format), | 40 m_format(format), |
41 m_sampleRange(RangeSigned1), | |
41 m_maxDisplayCols(maxDisplayCols), | 42 m_maxDisplayCols(maxDisplayCols), |
42 m_fuzzyColumn(-1) | 43 m_fuzzyColumn(-1) |
43 { | 44 { |
44 setModal(true); | 45 setModal(true); |
45 setWindowTitle(tr("Select Audio Data Format")); | 46 setWindowTitle(tr("Select Audio Data Format")); |
114 | 115 |
115 layout->addWidget(exampleFrame, row, 0, 1, 4); | 116 layout->addWidget(exampleFrame, row, 0, 1, 4); |
116 layout->setColumnStretch(3, 10); | 117 layout->setColumnStretch(3, 10); |
117 layout->setRowStretch(row++, 10); | 118 layout->setRowStretch(row++, 10); |
118 | 119 |
119 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); | 120 layout->addWidget(new QLabel(tr("Audio sample rate (Hz):")), row, 0); |
120 layout->addWidget(m_sampleRateLabel, row, 0); | |
121 | 121 |
122 int sampleRates[] = { | 122 int sampleRates[] = { |
123 8000, 11025, 12000, 22050, 24000, 32000, | 123 8000, 11025, 12000, 22050, 24000, 32000, |
124 44100, 48000, 88200, 96000, 176400, 192000 | 124 44100, 48000, 88200, 96000, 176400, 192000 |
125 }; | 125 }; |
137 connect(m_sampleRateCombo, SIGNAL(activated(QString)), | 137 connect(m_sampleRateCombo, SIGNAL(activated(QString)), |
138 this, SLOT(sampleRateChanged(QString))); | 138 this, SLOT(sampleRateChanged(QString))); |
139 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), | 139 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), |
140 this, SLOT(sampleRateChanged(QString))); | 140 this, SLOT(sampleRateChanged(QString))); |
141 | 141 |
142 m_sampleRange = RangeSigned1; | |
143 bool knownSigned = false; | |
144 bool knownNonIntegral = false; | |
145 | |
146 for (int i = 0; i < columns; ++i) { | |
147 if (!(format.getColumnQualities()[i] & CSVFormat::ColumnIntegral)) { | |
148 knownNonIntegral = true; | |
149 if (m_sampleRange == RangeUnsigned255 || | |
150 m_sampleRange == RangeSigned32767) { | |
151 m_sampleRange = RangeOther; | |
152 } | |
153 } | |
154 if (format.getColumnQualities()[i] & CSVFormat::ColumnLarge) { | |
155 if (m_sampleRange == RangeSigned1 || | |
156 m_sampleRange == RangeUnsigned255) { | |
157 if (knownNonIntegral) { | |
158 m_sampleRange = RangeOther; | |
159 } else { | |
160 m_sampleRange = RangeSigned32767; | |
161 } | |
162 } | |
163 } | |
164 if (format.getColumnQualities()[i] & CSVFormat::ColumnSigned) { | |
165 knownSigned = true; | |
166 if (m_sampleRange == RangeUnsigned255) { | |
167 m_sampleRange = RangeSigned32767; | |
168 } | |
169 } | |
170 if (!(format.getColumnQualities()[i] & CSVFormat::ColumnSmall)) { | |
171 if (m_sampleRange == RangeSigned1) { | |
172 if (knownNonIntegral) { | |
173 m_sampleRange = RangeOther; | |
174 } else if (knownSigned) { | |
175 m_sampleRange = RangeSigned32767; | |
176 } else { | |
177 m_sampleRange = RangeUnsigned255; | |
178 } | |
179 } | |
180 } | |
181 } | |
182 | |
183 layout->addWidget(new QLabel(tr("Sample values are:")), row, 0); | |
184 | |
185 m_sampleRangeCombo = new QComboBox; | |
186 // NB must be in the same order as the CSVSampleRange enum | |
187 m_sampleRangeCombo->addItem(tr("Floating-point in range -1 to 1")); | |
188 m_sampleRangeCombo->addItem(tr("8-bit in range 0 to 255")); | |
189 m_sampleRangeCombo->addItem(tr("16-bit in range -32768 to 32767")); | |
190 m_sampleRangeCombo->addItem(tr("Unknown range: normalise on load")); | |
191 m_sampleRangeCombo->setCurrentIndex(int(m_sampleRange)); | |
192 | |
193 layout->addWidget(m_sampleRangeCombo, row++, 1); | |
194 connect(m_sampleRangeCombo, SIGNAL(activated(int)), | |
195 this, SLOT(sampleRangeChanged(int))); | |
196 | |
142 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | 197 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | |
143 QDialogButtonBox::Cancel); | 198 QDialogButtonBox::Cancel); |
144 layout->addWidget(bb, row++, 0, 1, 4); | 199 layout->addWidget(bb, row++, 0, 1, 4); |
145 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | 200 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); |
146 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | 201 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); |
158 CSVAudioFormatDialog::getFormat() const | 213 CSVAudioFormatDialog::getFormat() const |
159 { | 214 { |
160 return m_format; | 215 return m_format; |
161 } | 216 } |
162 | 217 |
218 CSVAudioFormatDialog::CSVSampleRange | |
219 CSVAudioFormatDialog::getSampleRange() const | |
220 { | |
221 return m_sampleRange; | |
222 } | |
223 | |
163 void | 224 void |
164 CSVAudioFormatDialog::sampleRateChanged(QString rateString) | 225 CSVAudioFormatDialog::sampleRateChanged(QString rateString) |
165 { | 226 { |
166 bool ok = false; | 227 bool ok = false; |
167 int sampleRate = rateString.toInt(&ok); | 228 int sampleRate = rateString.toInt(&ok); |
168 if (ok) m_format.setSampleRate(sampleRate); | 229 if (ok) m_format.setSampleRate(sampleRate); |
169 } | 230 } |
170 | 231 |
171 void | 232 void |
233 CSVAudioFormatDialog::sampleRangeChanged(int range) | |
234 { | |
235 m_sampleRange = (CSVSampleRange) range; | |
236 } | |
237 | |
238 void | |
172 CSVAudioFormatDialog::columnPurposeChanged(int) | 239 CSVAudioFormatDialog::columnPurposeChanged(int) |
173 { | 240 { |
174 updateFormatFromDialog(); | 241 updateFormatFromDialog(); |
175 } | 242 } |
176 | 243 |