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@378
|
7 This file copyright 2006 Chris Cannam.
|
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@378
|
16 #include "CSVFormatDialog.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@581
|
37 CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format,
|
Chris@581
|
38 int maxDisplayCols) :
|
Chris@378
|
39 QDialog(parent),
|
Chris@1318
|
40 m_dialogType(format.getModelType() == CSVFormat::WaveFileModel ?
|
Chris@1318
|
41 AudioDataDialog :
|
Chris@1318
|
42 AnnotationDataDialog),
|
Chris@581
|
43 m_format(format),
|
Chris@581
|
44 m_maxDisplayCols(maxDisplayCols),
|
Chris@581
|
45 m_fuzzyColumn(-1)
|
Chris@378
|
46 {
|
Chris@378
|
47 setModal(true);
|
Chris@378
|
48 setWindowTitle(tr("Select Data Format"));
|
Chris@378
|
49
|
Chris@378
|
50 QGridLayout *layout = new QGridLayout;
|
Chris@378
|
51
|
Chris@560
|
52 int row = 0;
|
Chris@378
|
53
|
Chris@1318
|
54 layout->addWidget
|
Chris@1318
|
55 (new QLabel(tr("Please select the correct data format for this file.")),
|
Chris@1318
|
56 row++, 0, 1, 4);
|
Chris@560
|
57
|
Chris@560
|
58 QFrame *exampleFrame = new QFrame;
|
Chris@560
|
59 exampleFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
Chris@560
|
60 exampleFrame->setLineWidth(2);
|
Chris@560
|
61 QGridLayout *exampleLayout = new QGridLayout;
|
Chris@561
|
62 exampleLayout->setSpacing(4);
|
Chris@560
|
63 exampleFrame->setLayout(exampleLayout);
|
Chris@560
|
64
|
Chris@560
|
65 QPalette palette = exampleFrame->palette();
|
Chris@560
|
66 palette.setColor(QPalette::Window, palette.color(QPalette::Base));
|
Chris@560
|
67 exampleFrame->setPalette(palette);
|
Chris@560
|
68
|
Chris@560
|
69 QFont fp;
|
Chris@908
|
70 fp.setPointSize(int(floor(fp.pointSize() * 0.9)));
|
Chris@560
|
71
|
Chris@560
|
72 int columns = format.getColumnCount();
|
Chris@560
|
73 QList<QStringList> example = m_format.getExample();
|
Chris@560
|
74
|
Chris@560
|
75 for (int i = 0; i < columns; ++i) {
|
Chris@581
|
76
|
Chris@560
|
77 QComboBox *cpc = new QComboBox;
|
Chris@560
|
78 m_columnPurposeCombos.push_back(cpc);
|
Chris@560
|
79 exampleLayout->addWidget(cpc, 0, i);
|
Chris@581
|
80 connect(cpc, SIGNAL(activated(int)), this, SLOT(columnPurposeChanged(int)));
|
Chris@1318
|
81
|
Chris@581
|
82 if (i == m_maxDisplayCols && columns > i + 2) {
|
Chris@581
|
83 m_fuzzyColumn = i;
|
Chris@1318
|
84
|
Chris@1318
|
85 if (m_dialogType == AnnotationDataDialog) {
|
Chris@1318
|
86 cpc->addItem(tr("<ignore>"));
|
Chris@1318
|
87 cpc->addItem(tr("Values"));
|
Chris@1318
|
88 cpc->setCurrentIndex
|
Chris@1318
|
89 (m_format.getColumnPurpose(i-1) ==
|
Chris@1318
|
90 CSVFormat::ColumnUnknown ? 0 : 1);
|
Chris@1318
|
91 } else {
|
Chris@1318
|
92 cpc->addItem(tr("<ignore>"));
|
Chris@1318
|
93 cpc->addItem(tr("Audio channels"));
|
Chris@1318
|
94 cpc->setCurrentIndex
|
Chris@1318
|
95 (m_format.isColumnNumeric(i-1) ? 1 : 0);
|
Chris@1318
|
96 }
|
Chris@1318
|
97 exampleLayout->addWidget
|
Chris@1318
|
98 (new QLabel(tr("(%1 more)").arg(columns - i)), 1, i);
|
Chris@581
|
99 break;
|
Chris@581
|
100 }
|
Chris@560
|
101
|
Chris@1318
|
102 if (m_dialogType == AnnotationDataDialog) {
|
Chris@560
|
103
|
Chris@1318
|
104 // NB must be in the same order as the CSVFormat::ColumnPurpose enum
|
Chris@1318
|
105 cpc->addItem(tr("<ignore>")); // ColumnUnknown
|
Chris@1318
|
106 cpc->addItem(tr("Time")); // ColumnStartTime
|
Chris@1318
|
107 cpc->addItem(tr("End time")); // ColumnEndTime
|
Chris@1318
|
108 cpc->addItem(tr("Duration")); // ColumnDuration
|
Chris@1318
|
109 cpc->addItem(tr("Value")); // ColumnValue
|
Chris@1318
|
110 cpc->addItem(tr("Pitch")); // ColumnPitch
|
Chris@1318
|
111 cpc->addItem(tr("Label")); // ColumnLabel
|
Chris@1318
|
112 cpc->setCurrentIndex(int(m_format.getColumnPurpose(i)));
|
Chris@1318
|
113
|
Chris@1318
|
114 } else {
|
Chris@1318
|
115 cpc->addItem(tr("<ignore>"));
|
Chris@1318
|
116 cpc->addItem(tr("Audio channel"));
|
Chris@1318
|
117 if (m_format.isColumnNumeric(i)) {
|
Chris@1318
|
118 cpc->setCurrentIndex(1);
|
Chris@1318
|
119 } else {
|
Chris@1318
|
120 cpc->setCurrentIndex(0);
|
Chris@1318
|
121 }
|
Chris@1318
|
122 }
|
Chris@1318
|
123
|
Chris@581
|
124 for (int j = 0; j < example.size() && j < 6; ++j) {
|
Chris@866
|
125 if (i >= example[j].size()) {
|
Chris@866
|
126 continue;
|
Chris@866
|
127 }
|
Chris@581
|
128 QLabel *label = new QLabel;
|
Chris@581
|
129 label->setTextFormat(Qt::PlainText);
|
Chris@674
|
130 QString text = TextAbbrev::abbreviate(example[j][i], 35);
|
Chris@674
|
131 label->setText(text);
|
Chris@581
|
132 label->setFont(fp);
|
Chris@581
|
133 label->setPalette(palette);
|
Chris@581
|
134 label->setIndent(8);
|
Chris@581
|
135 exampleLayout->addWidget(label, j+1, i);
|
Chris@560
|
136 }
|
Chris@560
|
137 }
|
Chris@560
|
138
|
Chris@560
|
139 layout->addWidget(exampleFrame, row, 0, 1, 4);
|
Chris@560
|
140 layout->setColumnStretch(3, 10);
|
Chris@560
|
141 layout->setRowStretch(row++, 10);
|
Chris@560
|
142
|
Chris@1318
|
143 if (m_dialogType == AnnotationDataDialog) {
|
Chris@378
|
144
|
Chris@1318
|
145 layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0);
|
Chris@1318
|
146
|
Chris@1318
|
147 m_timingTypeCombo = new QComboBox;
|
Chris@959
|
148
|
Chris@1318
|
149 m_timingLabels = {
|
Chris@1318
|
150 { TimingExplicitSeconds, tr("Explicitly, in seconds") },
|
Chris@1318
|
151 { TimingExplicitMsec, tr("Explicitly, in milliseconds") },
|
Chris@1318
|
152 { TimingExplicitSamples, tr("Explicitly, in audio sample frames") },
|
Chris@1318
|
153 { TimingImplicit, tr("Implicitly: rows are equally spaced in time") }
|
Chris@1318
|
154 };
|
Chris@959
|
155
|
Chris@1318
|
156 for (auto &l: m_timingLabels) {
|
Chris@1318
|
157 m_timingTypeCombo->addItem(l.second);
|
Chris@1318
|
158 }
|
Chris@1318
|
159
|
Chris@1318
|
160 layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2);
|
Chris@1318
|
161
|
Chris@1318
|
162 connect(m_timingTypeCombo, SIGNAL(activated(int)),
|
Chris@1318
|
163 this, SLOT(timingTypeChanged(int)));
|
Chris@1318
|
164
|
Chris@1318
|
165 m_initialTimingOption = TimingImplicit;
|
Chris@1318
|
166 if (m_format.getTimingType() == CSVFormat::ExplicitTiming) {
|
Chris@1318
|
167 switch (m_format.getTimeUnits()) {
|
Chris@1318
|
168 case CSVFormat::TimeSeconds:
|
Chris@1318
|
169 m_initialTimingOption = TimingExplicitSeconds; break;
|
Chris@1318
|
170 case CSVFormat::TimeMilliseconds:
|
Chris@1318
|
171 m_initialTimingOption = TimingExplicitMsec; break;
|
Chris@1318
|
172 case CSVFormat::TimeAudioFrames:
|
Chris@1318
|
173 m_initialTimingOption = TimingExplicitSamples; break;
|
Chris@1318
|
174 case CSVFormat::TimeWindows:
|
Chris@1318
|
175 m_initialTimingOption = TimingImplicit; break;
|
Chris@1318
|
176 }
|
Chris@1318
|
177 }
|
Chris@1318
|
178 m_timingTypeCombo->setCurrentIndex(int(m_initialTimingOption));
|
Chris@1318
|
179
|
Chris@1318
|
180 } else {
|
Chris@1318
|
181
|
Chris@1318
|
182 m_timingTypeCombo = 0;
|
Chris@959
|
183 }
|
Chris@1318
|
184
|
Chris@378
|
185 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):"));
|
Chris@560
|
186 layout->addWidget(m_sampleRateLabel, row, 0);
|
Chris@378
|
187
|
Chris@807
|
188 int sampleRates[] = {
|
Chris@1266
|
189 8000, 11025, 12000, 22050, 24000, 32000,
|
Chris@1266
|
190 44100, 48000, 88200, 96000, 176400, 192000
|
Chris@378
|
191 };
|
Chris@378
|
192
|
Chris@378
|
193 m_sampleRateCombo = new QComboBox;
|
Chris@807
|
194 for (int i = 0; i < int(sizeof(sampleRates) / sizeof(sampleRates[0])); ++i) {
|
Chris@1266
|
195 m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i]));
|
Chris@1266
|
196 if (sampleRates[i] == m_format.getSampleRate()) {
|
Chris@560
|
197 m_sampleRateCombo->setCurrentIndex(i);
|
Chris@560
|
198 }
|
Chris@378
|
199 }
|
Chris@378
|
200 m_sampleRateCombo->setEditable(true);
|
Chris@378
|
201
|
Chris@560
|
202 layout->addWidget(m_sampleRateCombo, row++, 1);
|
Chris@378
|
203 connect(m_sampleRateCombo, SIGNAL(activated(QString)),
|
Chris@1266
|
204 this, SLOT(sampleRateChanged(QString)));
|
Chris@378
|
205 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)),
|
Chris@1266
|
206 this, SLOT(sampleRateChanged(QString)));
|
Chris@378
|
207
|
Chris@1318
|
208 if (m_dialogType == AnnotationDataDialog) {
|
Chris@1318
|
209
|
Chris@1318
|
210 m_windowSizeLabel = new QLabel(tr("Frame increment between rows:"));
|
Chris@1318
|
211 layout->addWidget(m_windowSizeLabel, row, 0);
|
Chris@378
|
212
|
Chris@1318
|
213 m_windowSizeCombo = new QComboBox;
|
Chris@1318
|
214 for (int i = 0; i <= 16; ++i) {
|
Chris@1318
|
215 int value = 1 << i;
|
Chris@1318
|
216 m_windowSizeCombo->addItem(QString("%1").arg(value));
|
Chris@1318
|
217 if (value == int(m_format.getWindowSize())) {
|
Chris@1318
|
218 m_windowSizeCombo->setCurrentIndex(i);
|
Chris@1318
|
219 }
|
Chris@560
|
220 }
|
Chris@1318
|
221 m_windowSizeCombo->setEditable(true);
|
Chris@1318
|
222
|
Chris@1318
|
223 layout->addWidget(m_windowSizeCombo, row++, 1);
|
Chris@1318
|
224 connect(m_windowSizeCombo, SIGNAL(activated(QString)),
|
Chris@1318
|
225 this, SLOT(windowSizeChanged(QString)));
|
Chris@1318
|
226 connect(m_windowSizeCombo, SIGNAL(editTextChanged(QString)),
|
Chris@1318
|
227 this, SLOT(windowSizeChanged(QString)));
|
Chris@1318
|
228
|
Chris@1318
|
229 m_modelLabel = new QLabel;
|
Chris@1318
|
230 QFont f(m_modelLabel->font());
|
Chris@1318
|
231 f.setItalic(true);
|
Chris@1318
|
232 m_modelLabel->setFont(f);
|
Chris@1318
|
233 layout->addWidget(m_modelLabel, row++, 0, 1, 4);
|
Chris@1318
|
234
|
Chris@1318
|
235 } else {
|
Chris@1318
|
236 m_windowSizeLabel = 0;
|
Chris@1318
|
237 m_windowSizeCombo = 0;
|
Chris@1318
|
238 m_modelLabel = 0;
|
Chris@378
|
239 }
|
Chris@561
|
240
|
Chris@512
|
241 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
|
Chris@512
|
242 QDialogButtonBox::Cancel);
|
Chris@560
|
243 layout->addWidget(bb, row++, 0, 1, 4);
|
Chris@512
|
244 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@512
|
245 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
|
Chris@378
|
246
|
Chris@512
|
247 setLayout(layout);
|
Chris@378
|
248
|
Chris@1318
|
249 if (m_timingTypeCombo) {
|
Chris@1318
|
250 timingTypeChanged(m_timingTypeCombo->currentIndex());
|
Chris@1318
|
251 } else {
|
Chris@1318
|
252 updateFormatFromDialog();
|
Chris@1318
|
253 updateComboVisibility();
|
Chris@1318
|
254 }
|
Chris@378
|
255 }
|
Chris@378
|
256
|
Chris@378
|
257 CSVFormatDialog::~CSVFormatDialog()
|
Chris@378
|
258 {
|
Chris@378
|
259 }
|
Chris@378
|
260
|
Chris@378
|
261 CSVFormat
|
Chris@378
|
262 CSVFormatDialog::getFormat() const
|
Chris@378
|
263 {
|
Chris@560
|
264 return m_format;
|
Chris@378
|
265 }
|
Chris@378
|
266
|
Chris@378
|
267 void
|
Chris@561
|
268 CSVFormatDialog::updateModelLabel()
|
Chris@378
|
269 {
|
Chris@1318
|
270 if (!m_modelLabel) {
|
Chris@1318
|
271 return;
|
Chris@1318
|
272 }
|
Chris@1318
|
273
|
Chris@561
|
274 LayerFactory *f = LayerFactory::getInstance();
|
Chris@561
|
275
|
Chris@561
|
276 QString s;
|
Chris@561
|
277 switch (m_format.getModelType()) {
|
Chris@561
|
278 case CSVFormat::OneDimensionalModel:
|
Chris@561
|
279 s = f->getLayerPresentationName(LayerFactory::TimeInstants);
|
Chris@561
|
280 break;
|
Chris@561
|
281 case CSVFormat::TwoDimensionalModel:
|
Chris@561
|
282 s = f->getLayerPresentationName(LayerFactory::TimeValues);
|
Chris@561
|
283 break;
|
Chris@561
|
284 case CSVFormat::TwoDimensionalModelWithDuration:
|
Chris@561
|
285 s = f->getLayerPresentationName(LayerFactory::Regions);
|
Chris@561
|
286 break;
|
Chris@763
|
287 case CSVFormat::TwoDimensionalModelWithDurationAndPitch:
|
Chris@763
|
288 s = f->getLayerPresentationName(LayerFactory::Notes);
|
Chris@763
|
289 break;
|
Chris@561
|
290 case CSVFormat::ThreeDimensionalModel:
|
Chris@561
|
291 s = f->getLayerPresentationName(LayerFactory::Colour3DPlot);
|
Chris@561
|
292 break;
|
Chris@1312
|
293 case CSVFormat::WaveFileModel:
|
Chris@1312
|
294 s = f->getLayerPresentationName(LayerFactory::Waveform);
|
Chris@1312
|
295 break;
|
Chris@561
|
296 }
|
Chris@561
|
297
|
Chris@1318
|
298 m_modelLabel->setText("\n" + tr("Data will be displayed in a %1 layer.")
|
Chris@1318
|
299 .arg(s));
|
Chris@378
|
300 }
|
Chris@378
|
301
|
Chris@378
|
302 void
|
Chris@959
|
303 CSVFormatDialog::applyStartTimePurpose()
|
Chris@959
|
304 {
|
Chris@1318
|
305 if (m_dialogType == AudioDataDialog) {
|
Chris@1318
|
306 return;
|
Chris@1318
|
307 }
|
Chris@1318
|
308
|
Chris@971
|
309 // First check if we already have any. NB there may be fewer than
|
Chris@971
|
310 // m_format.getColumnCount() elements in m_columnPurposeCombos
|
Chris@992
|
311 // (because of the fuzzy column behaviour). Note also that the
|
Chris@992
|
312 // fuzzy column (which is the one just showing how many more
|
Chris@992
|
313 // columns there are) has a different combo with only two items
|
Chris@992
|
314 // (ignore or Values)
|
Chris@971
|
315 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
|
Chris@992
|
316 if (i == m_fuzzyColumn) continue;
|
Chris@959
|
317 QComboBox *cb = m_columnPurposeCombos[i];
|
Chris@959
|
318 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
|
Chris@959
|
319 return;
|
Chris@959
|
320 }
|
Chris@959
|
321 }
|
Chris@959
|
322 // and if not, select one
|
Chris@971
|
323 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
|
Chris@992
|
324 if (i == m_fuzzyColumn) continue;
|
Chris@959
|
325 QComboBox *cb = m_columnPurposeCombos[i];
|
Chris@959
|
326 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
|
Chris@959
|
327 cb->setCurrentIndex(int(CSVFormat::ColumnStartTime));
|
Chris@959
|
328 return;
|
Chris@959
|
329 }
|
Chris@959
|
330 }
|
Chris@959
|
331 }
|
Chris@959
|
332
|
Chris@959
|
333 void
|
Chris@959
|
334 CSVFormatDialog::removeStartTimePurpose()
|
Chris@959
|
335 {
|
Chris@1318
|
336 if (m_dialogType == AudioDataDialog) {
|
Chris@1318
|
337 return;
|
Chris@1318
|
338 }
|
Chris@1318
|
339
|
Chris@971
|
340 // NB there may be fewer than m_format.getColumnCount() elements
|
Chris@971
|
341 // in m_columnPurposeCombos (because of the fuzzy column
|
Chris@971
|
342 // behaviour)
|
Chris@971
|
343 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
|
Chris@992
|
344 if (i == m_fuzzyColumn) continue;
|
Chris@959
|
345 QComboBox *cb = m_columnPurposeCombos[i];
|
Chris@959
|
346 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
|
Chris@959
|
347 cb->setCurrentIndex(int(CSVFormat::ColumnValue));
|
Chris@959
|
348 }
|
Chris@959
|
349 }
|
Chris@959
|
350 }
|
Chris@959
|
351
|
Chris@959
|
352 void
|
Chris@959
|
353 CSVFormatDialog::updateComboVisibility()
|
Chris@959
|
354 {
|
Chris@1318
|
355 bool wantRate = (m_dialogType == AudioDataDialog ||
|
Chris@1318
|
356 m_format.getTimingType() == CSVFormat::ImplicitTiming ||
|
Chris@959
|
357 m_format.getTimeUnits() == CSVFormat::TimeAudioFrames);
|
Chris@959
|
358 bool wantWindow = (m_format.getTimingType() == CSVFormat::ImplicitTiming);
|
Chris@959
|
359
|
Chris@959
|
360 m_sampleRateCombo->setEnabled(wantRate);
|
Chris@959
|
361 m_sampleRateLabel->setEnabled(wantRate);
|
Chris@959
|
362
|
Chris@1318
|
363 if (m_windowSizeCombo) {
|
Chris@1318
|
364 m_windowSizeCombo->setEnabled(wantWindow);
|
Chris@1318
|
365 m_windowSizeLabel->setEnabled(wantWindow);
|
Chris@1318
|
366 }
|
Chris@959
|
367 }
|
Chris@959
|
368
|
Chris@959
|
369 void
|
Chris@378
|
370 CSVFormatDialog::timingTypeChanged(int type)
|
Chris@378
|
371 {
|
Chris@959
|
372 // Update any column purpose combos
|
Chris@959
|
373 if (TimingOption(type) == TimingImplicit) {
|
Chris@959
|
374 removeStartTimePurpose();
|
Chris@959
|
375 } else {
|
Chris@959
|
376 applyStartTimePurpose();
|
Chris@378
|
377 }
|
Chris@959
|
378 updateFormatFromDialog();
|
Chris@959
|
379 updateComboVisibility();
|
Chris@559
|
380 }
|
Chris@559
|
381
|
Chris@559
|
382 void
|
Chris@378
|
383 CSVFormatDialog::sampleRateChanged(QString rateString)
|
Chris@378
|
384 {
|
Chris@378
|
385 bool ok = false;
|
Chris@378
|
386 int sampleRate = rateString.toInt(&ok);
|
Chris@560
|
387 if (ok) m_format.setSampleRate(sampleRate);
|
Chris@378
|
388 }
|
Chris@378
|
389
|
Chris@378
|
390 void
|
Chris@378
|
391 CSVFormatDialog::windowSizeChanged(QString sizeString)
|
Chris@378
|
392 {
|
Chris@378
|
393 bool ok = false;
|
Chris@378
|
394 int size = sizeString.toInt(&ok);
|
Chris@560
|
395 if (ok) m_format.setWindowSize(size);
|
Chris@378
|
396 }
|
Chris@560
|
397
|
Chris@560
|
398 void
|
Chris@561
|
399 CSVFormatDialog::columnPurposeChanged(int p)
|
Chris@560
|
400 {
|
Chris@560
|
401 QObject *o = sender();
|
Chris@560
|
402 QComboBox *cb = qobject_cast<QComboBox *>(o);
|
Chris@560
|
403 if (!cb) return;
|
Chris@561
|
404
|
Chris@1318
|
405 if (m_dialogType == AnnotationDataDialog) {
|
Chris@1318
|
406 columnPurposeChangedForAnnotationType(cb, p);
|
Chris@1318
|
407 }
|
Chris@1318
|
408
|
Chris@1318
|
409 updateFormatFromDialog();
|
Chris@1318
|
410 updateComboVisibility();
|
Chris@1318
|
411 }
|
Chris@1318
|
412
|
Chris@1318
|
413 void
|
Chris@1318
|
414 CSVFormatDialog::columnPurposeChangedForAnnotationType(QComboBox *cb, int p)
|
Chris@1318
|
415 {
|
Chris@1318
|
416 // Ensure a consistent set of column purposes, in a situation
|
Chris@1318
|
417 // where some combinations are contradictory. This is only
|
Chris@1318
|
418 // relevant to annotation type formats. Only updates the UI, does
|
Chris@1318
|
419 // not update the stored format record from the UI - that's the
|
Chris@1318
|
420 // job of updateFormatFromDialog
|
Chris@1318
|
421
|
Chris@561
|
422 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p;
|
Chris@561
|
423
|
Chris@959
|
424 bool haveStartTime = false; // so as to update timing type combo appropriately
|
Chris@959
|
425
|
Chris@959
|
426 // Ensure the column purpose combos are consistent with one
|
Chris@959
|
427 // another, without reference to m_format (which we'll update
|
Chris@959
|
428 // separately)
|
Chris@959
|
429
|
Chris@560
|
430 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
|
Chris@561
|
431
|
Chris@992
|
432 // The fuzzy column combo only has the entries <ignore> or
|
Chris@992
|
433 // Values, so it can't affect the timing type and none of this
|
Chris@992
|
434 // logic affects it
|
Chris@992
|
435 if (i == m_fuzzyColumn) continue;
|
Chris@992
|
436
|
Chris@959
|
437 QComboBox *thisCombo = m_columnPurposeCombos[i];
|
Chris@561
|
438
|
Chris@959
|
439 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose)
|
Chris@959
|
440 (thisCombo->currentIndex());
|
Chris@959
|
441 bool thisChanged = (cb == thisCombo);
|
Chris@959
|
442
|
Chris@959
|
443 if (!thisChanged) {
|
Chris@561
|
444
|
Chris@561
|
445 // We can only have one ColumnStartTime column, and only
|
Chris@561
|
446 // one of either ColumnDuration or ColumnEndTime
|
Chris@561
|
447
|
Chris@561
|
448 if (purpose == CSVFormat::ColumnStartTime) {
|
Chris@561
|
449 if (cp == purpose) {
|
Chris@561
|
450 cp = CSVFormat::ColumnValue;
|
Chris@561
|
451 }
|
Chris@561
|
452 } else if (purpose == CSVFormat::ColumnDuration ||
|
Chris@561
|
453 purpose == CSVFormat::ColumnEndTime) {
|
Chris@561
|
454 if (cp == CSVFormat::ColumnDuration ||
|
Chris@561
|
455 cp == CSVFormat::ColumnEndTime) {
|
Chris@561
|
456 cp = CSVFormat::ColumnValue;
|
Chris@561
|
457 }
|
Chris@561
|
458 }
|
Chris@561
|
459
|
Chris@561
|
460 // And we can only have one label
|
Chris@561
|
461 if (purpose == CSVFormat::ColumnLabel) {
|
Chris@561
|
462 if (cp == purpose) {
|
Chris@561
|
463 cp = CSVFormat::ColumnUnknown;
|
Chris@561
|
464 }
|
Chris@561
|
465 }
|
Chris@959
|
466
|
Chris@959
|
467 if (cp == CSVFormat::ColumnStartTime) {
|
Chris@959
|
468 haveStartTime = true;
|
Chris@959
|
469 }
|
Chris@959
|
470
|
Chris@959
|
471 thisCombo->setCurrentIndex(int(cp));
|
Chris@959
|
472
|
Chris@959
|
473 } else {
|
Chris@959
|
474 if (purpose == CSVFormat::ColumnStartTime) {
|
Chris@959
|
475 haveStartTime = true;
|
Chris@959
|
476 }
|
Chris@561
|
477 }
|
Chris@959
|
478 }
|
Chris@561
|
479
|
Chris@1318
|
480 if (m_timingTypeCombo) {
|
Chris@1318
|
481 if (!haveStartTime) {
|
Chris@1318
|
482 m_timingTypeCombo->setCurrentIndex(int(TimingImplicit));
|
Chris@1318
|
483 } else if (m_timingTypeCombo->currentIndex() == int(TimingImplicit)) {
|
Chris@1318
|
484 if (m_initialTimingOption == TimingImplicit) {
|
Chris@1318
|
485 m_timingTypeCombo->setCurrentIndex(TimingExplicitSeconds);
|
Chris@1318
|
486 } else {
|
Chris@1318
|
487 m_timingTypeCombo->setCurrentIndex(m_initialTimingOption);
|
Chris@1318
|
488 }
|
Chris@959
|
489 }
|
Chris@959
|
490 }
|
Chris@959
|
491 }
|
Chris@1318
|
492
|
Chris@959
|
493 void
|
Chris@959
|
494 CSVFormatDialog::updateFormatFromDialog()
|
Chris@959
|
495 {
|
Chris@1318
|
496 if (m_timingTypeCombo) {
|
Chris@1318
|
497 switch (TimingOption(m_timingTypeCombo->currentIndex())) {
|
Chris@959
|
498
|
Chris@1318
|
499 case TimingExplicitSeconds:
|
Chris@1318
|
500 m_format.setTimingType(CSVFormat::ExplicitTiming);
|
Chris@1318
|
501 m_format.setTimeUnits(CSVFormat::TimeSeconds);
|
Chris@1318
|
502 break;
|
Chris@959
|
503
|
Chris@1318
|
504 case TimingExplicitMsec:
|
Chris@1318
|
505 m_format.setTimingType(CSVFormat::ExplicitTiming);
|
Chris@1318
|
506 m_format.setTimeUnits(CSVFormat::TimeMilliseconds);
|
Chris@1318
|
507 break;
|
Chris@959
|
508
|
Chris@1318
|
509 case TimingExplicitSamples:
|
Chris@1318
|
510 m_format.setTimingType(CSVFormat::ExplicitTiming);
|
Chris@1318
|
511 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
|
Chris@1318
|
512 break;
|
Chris@1318
|
513
|
Chris@1318
|
514 case TimingImplicit:
|
Chris@1318
|
515 m_format.setTimingType(CSVFormat::ImplicitTiming);
|
Chris@1318
|
516 m_format.setTimeUnits(CSVFormat::TimeWindows);
|
Chris@1318
|
517 break;
|
Chris@1318
|
518 }
|
Chris@1318
|
519 } else if (m_dialogType == AudioDataDialog) {
|
Chris@1318
|
520 m_format.setTimingType(CSVFormat::ImplicitTiming);
|
Chris@1266
|
521 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
|
Chris@959
|
522 }
|
Chris@1318
|
523
|
Chris@959
|
524 bool haveStartTime = false;
|
Chris@959
|
525 bool haveDuration = false;
|
Chris@959
|
526 bool havePitch = false;
|
Chris@959
|
527 int valueCount = 0;
|
Chris@959
|
528
|
Chris@959
|
529 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
|
Chris@959
|
530
|
Chris@959
|
531 QComboBox *thisCombo = m_columnPurposeCombos[i];
|
Chris@959
|
532
|
Chris@1318
|
533 CSVFormat::ColumnPurpose purpose;
|
Chris@1318
|
534
|
Chris@1318
|
535 if (m_dialogType == AnnotationDataDialog) {
|
Chris@1318
|
536 purpose = (CSVFormat::ColumnPurpose) (thisCombo->currentIndex());
|
Chris@1318
|
537 } else {
|
Chris@1318
|
538 purpose = (thisCombo->currentIndex() == 1 ?
|
Chris@1318
|
539 CSVFormat::ColumnValue :
|
Chris@1318
|
540 CSVFormat::ColumnUnknown);
|
Chris@1318
|
541 }
|
Chris@959
|
542
|
Chris@959
|
543 if (i == m_fuzzyColumn) {
|
Chris@992
|
544 for (int j = i; j < m_format.getColumnCount(); ++j) {
|
Chris@959
|
545 if (purpose == CSVFormat::ColumnUnknown) {
|
Chris@959
|
546 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
|
Chris@959
|
547 } else { // Value
|
Chris@959
|
548 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
|
Chris@959
|
549 ++valueCount;
|
Chris@959
|
550 }
|
Chris@959
|
551 }
|
Chris@992
|
552 } else {
|
Chris@992
|
553
|
Chris@992
|
554 if (purpose == CSVFormat::ColumnStartTime) {
|
Chris@992
|
555 haveStartTime = true;
|
Chris@992
|
556 }
|
Chris@992
|
557 if (purpose == CSVFormat::ColumnEndTime ||
|
Chris@992
|
558 purpose == CSVFormat::ColumnDuration) {
|
Chris@992
|
559 haveDuration = true;
|
Chris@992
|
560 }
|
Chris@992
|
561 if (purpose == CSVFormat::ColumnPitch) {
|
Chris@992
|
562 havePitch = true;
|
Chris@992
|
563 }
|
Chris@992
|
564 if (purpose == CSVFormat::ColumnValue) {
|
Chris@992
|
565 ++valueCount;
|
Chris@992
|
566 }
|
Chris@992
|
567
|
Chris@992
|
568 m_format.setColumnPurpose(i, purpose);
|
Chris@959
|
569 }
|
Chris@561
|
570 }
|
Chris@561
|
571
|
Chris@1318
|
572 if (m_dialogType == AudioDataDialog) {
|
Chris@1318
|
573 m_format.setModelType(CSVFormat::WaveFileModel);
|
Chris@1318
|
574 } else if (haveStartTime && haveDuration) {
|
Chris@763
|
575 if (havePitch) {
|
Chris@763
|
576 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch);
|
Chris@763
|
577 } else {
|
Chris@763
|
578 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDuration);
|
Chris@763
|
579 }
|
Chris@561
|
580 } else {
|
Chris@561
|
581 if (valueCount > 1) {
|
Chris@561
|
582 m_format.setModelType(CSVFormat::ThreeDimensionalModel);
|
Chris@561
|
583 } else if (valueCount > 0) {
|
Chris@561
|
584 m_format.setModelType(CSVFormat::TwoDimensionalModel);
|
Chris@561
|
585 } else {
|
Chris@561
|
586 m_format.setModelType(CSVFormat::OneDimensionalModel);
|
Chris@560
|
587 }
|
Chris@560
|
588 }
|
Chris@561
|
589
|
Chris@561
|
590 updateModelLabel();
|
Chris@560
|
591 }
|
Chris@560
|
592
|
Chris@560
|
593
|
Chris@959
|
594
|