comparison widgets/CSVFormatDialog.cpp @ 997:296ccd36f626 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents e5d40d89b1ec
children a34a2a25907c
comparison
equal deleted inserted replaced
943:788b7623bfca 997:296ccd36f626
119 layout->setRowStretch(row++, 10); 119 layout->setRowStretch(row++, 10);
120 120
121 layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); 121 layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0);
122 122
123 m_timingTypeCombo = new QComboBox; 123 m_timingTypeCombo = new QComboBox;
124 m_timingTypeCombo->addItem(tr("Explicitly, in seconds")); 124
125 m_timingTypeCombo->addItem(tr("Explicitly, in milliseconds")); 125 m_timingLabels = {
126 m_timingTypeCombo->addItem(tr("Explicitly, in audio sample frames")); 126 { TimingExplicitSeconds, tr("Explicitly, in seconds") },
127 m_timingTypeCombo->addItem(tr("Implicitly: rows are equally spaced in time")); 127 { TimingExplicitMsec, tr("Explicitly, in milliseconds") },
128 { TimingExplicitSamples, tr("Explicitly, in audio sample frames") },
129 { TimingImplicit, tr("Implicitly: rows are equally spaced in time") }
130 };
131
132 for (auto &l: m_timingLabels) {
133 m_timingTypeCombo->addItem(l.second);
134 }
135
128 layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2); 136 layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2);
137
129 connect(m_timingTypeCombo, SIGNAL(activated(int)), 138 connect(m_timingTypeCombo, SIGNAL(activated(int)),
130 this, SLOT(timingTypeChanged(int))); 139 this, SLOT(timingTypeChanged(int)));
131 m_timingTypeCombo->setCurrentIndex 140
132 (m_format.getTimingType() == CSVFormat::ExplicitTiming ? 141 m_initialTimingOption = TimingImplicit;
133 m_format.getTimeUnits() == CSVFormat::TimeSeconds ? 0 : 2 : 3); 142 if (m_format.getTimingType() == CSVFormat::ExplicitTiming) {
143 switch (m_format.getTimeUnits()) {
144 case CSVFormat::TimeSeconds:
145 m_initialTimingOption = TimingExplicitSeconds; break;
146 case CSVFormat::TimeMilliseconds:
147 m_initialTimingOption = TimingExplicitMsec; break;
148 case CSVFormat::TimeAudioFrames:
149 m_initialTimingOption = TimingExplicitSamples; break;
150 case CSVFormat::TimeWindows:
151 m_initialTimingOption = TimingImplicit; break;
152 }
153 }
154 m_timingTypeCombo->setCurrentIndex(int(m_initialTimingOption));
134 155
135 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); 156 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):"));
136 layout->addWidget(m_sampleRateLabel, row, 0); 157 layout->addWidget(m_sampleRateLabel, row, 0);
137 158
138 int sampleRates[] = { 159 int sampleRates[] = {
187 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); 208 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
188 209
189 setLayout(layout); 210 setLayout(layout);
190 211
191 timingTypeChanged(m_timingTypeCombo->currentIndex()); 212 timingTypeChanged(m_timingTypeCombo->currentIndex());
192 updateModelLabel();
193 } 213 }
194 214
195 CSVFormatDialog::~CSVFormatDialog() 215 CSVFormatDialog::~CSVFormatDialog()
196 { 216 {
197 } 217 }
228 248
229 m_modelLabel->setText("\n" + tr("Data will be displayed in a %1 layer.").arg(s)); 249 m_modelLabel->setText("\n" + tr("Data will be displayed in a %1 layer.").arg(s));
230 } 250 }
231 251
232 void 252 void
253 CSVFormatDialog::applyStartTimePurpose()
254 {
255 // First check if we already have any. NB there may be fewer than
256 // m_format.getColumnCount() elements in m_columnPurposeCombos
257 // (because of the fuzzy column behaviour). Note also that the
258 // fuzzy column (which is the one just showing how many more
259 // columns there are) has a different combo with only two items
260 // (ignore or Values)
261 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
262 if (i == m_fuzzyColumn) continue;
263 QComboBox *cb = m_columnPurposeCombos[i];
264 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
265 return;
266 }
267 }
268 // and if not, select one
269 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
270 if (i == m_fuzzyColumn) continue;
271 QComboBox *cb = m_columnPurposeCombos[i];
272 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) {
273 cb->setCurrentIndex(int(CSVFormat::ColumnStartTime));
274 return;
275 }
276 }
277 }
278
279 void
280 CSVFormatDialog::removeStartTimePurpose()
281 {
282 // NB there may be fewer than m_format.getColumnCount() elements
283 // in m_columnPurposeCombos (because of the fuzzy column
284 // behaviour)
285 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
286 if (i == m_fuzzyColumn) continue;
287 QComboBox *cb = m_columnPurposeCombos[i];
288 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) {
289 cb->setCurrentIndex(int(CSVFormat::ColumnValue));
290 }
291 }
292 }
293
294 void
295 CSVFormatDialog::updateComboVisibility()
296 {
297 bool wantRate = (m_format.getTimingType() == CSVFormat::ImplicitTiming ||
298 m_format.getTimeUnits() == CSVFormat::TimeAudioFrames);
299 bool wantWindow = (m_format.getTimingType() == CSVFormat::ImplicitTiming);
300
301 m_sampleRateCombo->setEnabled(wantRate);
302 m_sampleRateLabel->setEnabled(wantRate);
303
304 m_windowSizeCombo->setEnabled(wantWindow);
305 m_windowSizeLabel->setEnabled(wantWindow);
306 }
307
308 void
233 CSVFormatDialog::timingTypeChanged(int type) 309 CSVFormatDialog::timingTypeChanged(int type)
234 { 310 {
235 switch (type) { 311 // Update any column purpose combos
236 312 if (TimingOption(type) == TimingImplicit) {
237 case 0: 313 removeStartTimePurpose();
238 m_format.setTimingType(CSVFormat::ExplicitTiming); 314 } else {
239 m_format.setTimeUnits(CSVFormat::TimeSeconds); 315 applyStartTimePurpose();
240 m_sampleRateCombo->setEnabled(false); 316 }
241 m_sampleRateLabel->setEnabled(false); 317 updateFormatFromDialog();
242 m_windowSizeCombo->setEnabled(false); 318 updateComboVisibility();
243 m_windowSizeLabel->setEnabled(false);
244 break;
245
246 case 1:
247 m_format.setTimingType(CSVFormat::ExplicitTiming);
248 m_format.setTimeUnits(CSVFormat::TimeMilliseconds);
249 m_sampleRateCombo->setEnabled(true);
250 m_sampleRateLabel->setEnabled(true);
251 m_windowSizeCombo->setEnabled(false);
252 m_windowSizeLabel->setEnabled(false);
253 break;
254
255 case 2:
256 m_format.setTimingType(CSVFormat::ExplicitTiming);
257 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
258 m_sampleRateCombo->setEnabled(true);
259 m_sampleRateLabel->setEnabled(true);
260 m_windowSizeCombo->setEnabled(false);
261 m_windowSizeLabel->setEnabled(false);
262 break;
263
264 case 3:
265 m_format.setTimingType(CSVFormat::ImplicitTiming);
266 m_format.setTimeUnits(CSVFormat::TimeWindows);
267 m_sampleRateCombo->setEnabled(true);
268 m_sampleRateLabel->setEnabled(true);
269 m_windowSizeCombo->setEnabled(true);
270 m_windowSizeLabel->setEnabled(true);
271 break;
272 }
273 } 319 }
274 320
275 void 321 void
276 CSVFormatDialog::sampleRateChanged(QString rateString) 322 CSVFormatDialog::sampleRateChanged(QString rateString)
277 { 323 {
290 336
291 void 337 void
292 CSVFormatDialog::columnPurposeChanged(int p) 338 CSVFormatDialog::columnPurposeChanged(int p)
293 { 339 {
294 QObject *o = sender(); 340 QObject *o = sender();
295
296 QComboBox *cb = qobject_cast<QComboBox *>(o); 341 QComboBox *cb = qobject_cast<QComboBox *>(o);
297 if (!cb) return; 342 if (!cb) return;
298 343
299 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p; 344 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p;
300 345
301 bool haveStartTime = false; 346 bool haveStartTime = false; // so as to update timing type combo appropriately
302 bool haveDuration = false; 347
303 bool havePitch = false; 348 // Ensure the column purpose combos are consistent with one
304 int valueCount = 0; 349 // another, without reference to m_format (which we'll update
305 350 // separately)
351
306 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { 352 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
307 353
308 CSVFormat::ColumnPurpose cp = m_format.getColumnPurpose(i); 354 // The fuzzy column combo only has the entries <ignore> or
309 355 // Values, so it can't affect the timing type and none of this
310 bool thisChanged = (cb == m_columnPurposeCombos[i]); 356 // logic affects it
357 if (i == m_fuzzyColumn) continue;
358
359 QComboBox *thisCombo = m_columnPurposeCombos[i];
311 360
312 if (thisChanged) { 361 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose)
313 362 (thisCombo->currentIndex());
314 cerr << "i == " << i << ", fuzzy == " << m_fuzzyColumn 363 bool thisChanged = (cb == thisCombo);
315 << ", p == " << p << endl; 364
316 365 if (!thisChanged) {
317 if (i == m_fuzzyColumn) {
318 for (int j = i; j < m_format.getColumnCount(); ++j) {
319 if (p == 0) { // Ignore
320 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
321 } else { // Value
322 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
323 ++valueCount;
324 }
325 }
326 continue;
327 }
328
329 cp = purpose;
330
331 } else {
332
333 if (i == m_fuzzyColumn) continue;
334 366
335 // We can only have one ColumnStartTime column, and only 367 // We can only have one ColumnStartTime column, and only
336 // one of either ColumnDuration or ColumnEndTime 368 // one of either ColumnDuration or ColumnEndTime
337 369
338 if (purpose == CSVFormat::ColumnStartTime) { 370 if (purpose == CSVFormat::ColumnStartTime) {
351 if (purpose == CSVFormat::ColumnLabel) { 383 if (purpose == CSVFormat::ColumnLabel) {
352 if (cp == purpose) { 384 if (cp == purpose) {
353 cp = CSVFormat::ColumnUnknown; 385 cp = CSVFormat::ColumnUnknown;
354 } 386 }
355 } 387 }
356 } 388
357 389 if (cp == CSVFormat::ColumnStartTime) {
358 if (cp == CSVFormat::ColumnStartTime) { 390 haveStartTime = true;
359 haveStartTime = true; 391 }
360 } 392
361 if (cp == CSVFormat::ColumnEndTime || 393 thisCombo->setCurrentIndex(int(cp));
362 cp == CSVFormat::ColumnDuration) { 394
363 haveDuration = true; 395 } else {
364 } 396 if (purpose == CSVFormat::ColumnStartTime) {
365 if (cp == CSVFormat::ColumnPitch) { 397 haveStartTime = true;
366 havePitch = true; 398 }
367 } 399 }
368 if (cp == CSVFormat::ColumnValue) {
369 ++valueCount;
370 }
371
372 m_columnPurposeCombos[i]->setCurrentIndex(int(cp));
373 m_format.setColumnPurpose(i, cp);
374 } 400 }
375 401
376 if (!haveStartTime) { 402 if (!haveStartTime) {
377 m_timingTypeCombo->setCurrentIndex(2); 403 m_timingTypeCombo->setCurrentIndex(int(TimingImplicit));
378 timingTypeChanged(2); 404 } else if (m_timingTypeCombo->currentIndex() == int(TimingImplicit)) {
405 if (m_initialTimingOption == TimingImplicit) {
406 m_timingTypeCombo->setCurrentIndex(TimingExplicitSeconds);
407 } else {
408 m_timingTypeCombo->setCurrentIndex(m_initialTimingOption);
409 }
410 }
411
412 updateFormatFromDialog();
413 updateComboVisibility();
414 }
415
416 void
417 CSVFormatDialog::updateFormatFromDialog()
418 {
419 switch (TimingOption(m_timingTypeCombo->currentIndex())) {
420
421 case TimingExplicitSeconds:
422 m_format.setTimingType(CSVFormat::ExplicitTiming);
423 m_format.setTimeUnits(CSVFormat::TimeSeconds);
424 break;
425
426 case TimingExplicitMsec:
427 m_format.setTimingType(CSVFormat::ExplicitTiming);
428 m_format.setTimeUnits(CSVFormat::TimeMilliseconds);
429 break;
430
431 case TimingExplicitSamples:
432 m_format.setTimingType(CSVFormat::ExplicitTiming);
433 m_format.setTimeUnits(CSVFormat::TimeAudioFrames);
434 break;
435
436 case TimingImplicit:
437 m_format.setTimingType(CSVFormat::ImplicitTiming);
438 m_format.setTimeUnits(CSVFormat::TimeWindows);
439 break;
440 }
441
442 bool haveStartTime = false;
443 bool haveDuration = false;
444 bool havePitch = false;
445 int valueCount = 0;
446
447 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) {
448
449 QComboBox *thisCombo = m_columnPurposeCombos[i];
450
451 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)
452 (thisCombo->currentIndex());
453
454 if (i == m_fuzzyColumn) {
455 for (int j = i; j < m_format.getColumnCount(); ++j) {
456 if (purpose == CSVFormat::ColumnUnknown) {
457 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown);
458 } else { // Value
459 m_format.setColumnPurpose(j, CSVFormat::ColumnValue);
460 ++valueCount;
461 }
462 }
463 } else {
464
465 if (purpose == CSVFormat::ColumnStartTime) {
466 haveStartTime = true;
467 }
468 if (purpose == CSVFormat::ColumnEndTime ||
469 purpose == CSVFormat::ColumnDuration) {
470 haveDuration = true;
471 }
472 if (purpose == CSVFormat::ColumnPitch) {
473 havePitch = true;
474 }
475 if (purpose == CSVFormat::ColumnValue) {
476 ++valueCount;
477 }
478
479 m_format.setColumnPurpose(i, purpose);
480 }
379 } 481 }
380 482
381 if (haveStartTime && haveDuration) { 483 if (haveStartTime && haveDuration) {
382 if (havePitch) { 484 if (havePitch) {
383 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch); 485 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch);
396 498
397 updateModelLabel(); 499 updateModelLabel();
398 } 500 }
399 501
400 502
503