Mercurial > hg > svgui
comparison widgets/CSVFormatDialog.cpp @ 976:f2c63ec85901 alignment-simple
Branch to test simple FFT model code
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 09:15:55 +0100 |
parents | fd934705973f |
children | e5d40d89b1ec |
comparison
equal
deleted
inserted
replaced
946:36cddc3de023 | 976:f2c63ec85901 |
---|---|
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) | |
258 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { | |
259 QComboBox *cb = m_columnPurposeCombos[i]; | |
260 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { | |
261 return; | |
262 } | |
263 } | |
264 // and if not, select one | |
265 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { | |
266 QComboBox *cb = m_columnPurposeCombos[i]; | |
267 if (cb->currentIndex() == int(CSVFormat::ColumnValue)) { | |
268 cb->setCurrentIndex(int(CSVFormat::ColumnStartTime)); | |
269 return; | |
270 } | |
271 } | |
272 } | |
273 | |
274 void | |
275 CSVFormatDialog::removeStartTimePurpose() | |
276 { | |
277 // NB there may be fewer than m_format.getColumnCount() elements | |
278 // in m_columnPurposeCombos (because of the fuzzy column | |
279 // behaviour) | |
280 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { | |
281 QComboBox *cb = m_columnPurposeCombos[i]; | |
282 if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { | |
283 cb->setCurrentIndex(int(CSVFormat::ColumnValue)); | |
284 } | |
285 } | |
286 } | |
287 | |
288 void | |
289 CSVFormatDialog::updateComboVisibility() | |
290 { | |
291 bool wantRate = (m_format.getTimingType() == CSVFormat::ImplicitTiming || | |
292 m_format.getTimeUnits() == CSVFormat::TimeAudioFrames); | |
293 bool wantWindow = (m_format.getTimingType() == CSVFormat::ImplicitTiming); | |
294 | |
295 m_sampleRateCombo->setEnabled(wantRate); | |
296 m_sampleRateLabel->setEnabled(wantRate); | |
297 | |
298 m_windowSizeCombo->setEnabled(wantWindow); | |
299 m_windowSizeLabel->setEnabled(wantWindow); | |
300 } | |
301 | |
302 void | |
233 CSVFormatDialog::timingTypeChanged(int type) | 303 CSVFormatDialog::timingTypeChanged(int type) |
234 { | 304 { |
235 switch (type) { | 305 // Update any column purpose combos |
236 | 306 if (TimingOption(type) == TimingImplicit) { |
237 case 0: | 307 removeStartTimePurpose(); |
238 m_format.setTimingType(CSVFormat::ExplicitTiming); | 308 } else { |
239 m_format.setTimeUnits(CSVFormat::TimeSeconds); | 309 applyStartTimePurpose(); |
240 m_sampleRateCombo->setEnabled(false); | 310 } |
241 m_sampleRateLabel->setEnabled(false); | 311 updateFormatFromDialog(); |
242 m_windowSizeCombo->setEnabled(false); | 312 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 } | 313 } |
274 | 314 |
275 void | 315 void |
276 CSVFormatDialog::sampleRateChanged(QString rateString) | 316 CSVFormatDialog::sampleRateChanged(QString rateString) |
277 { | 317 { |
290 | 330 |
291 void | 331 void |
292 CSVFormatDialog::columnPurposeChanged(int p) | 332 CSVFormatDialog::columnPurposeChanged(int p) |
293 { | 333 { |
294 QObject *o = sender(); | 334 QObject *o = sender(); |
295 | |
296 QComboBox *cb = qobject_cast<QComboBox *>(o); | 335 QComboBox *cb = qobject_cast<QComboBox *>(o); |
297 if (!cb) return; | 336 if (!cb) return; |
298 | 337 |
299 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p; | 338 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p; |
300 | 339 |
301 bool haveStartTime = false; | 340 bool haveStartTime = false; // so as to update timing type combo appropriately |
302 bool haveDuration = false; | 341 |
303 bool havePitch = false; | 342 // Ensure the column purpose combos are consistent with one |
304 int valueCount = 0; | 343 // another, without reference to m_format (which we'll update |
305 | 344 // separately) |
345 | |
306 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { | 346 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { |
307 | 347 |
308 CSVFormat::ColumnPurpose cp = m_format.getColumnPurpose(i); | 348 QComboBox *thisCombo = m_columnPurposeCombos[i]; |
309 | |
310 bool thisChanged = (cb == m_columnPurposeCombos[i]); | |
311 | 349 |
312 if (thisChanged) { | 350 CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose) |
313 | 351 (thisCombo->currentIndex()); |
314 cerr << "i == " << i << ", fuzzy == " << m_fuzzyColumn | 352 bool thisChanged = (cb == thisCombo); |
315 << ", p == " << p << endl; | 353 |
316 | 354 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 | 355 |
333 if (i == m_fuzzyColumn) continue; | 356 if (i == m_fuzzyColumn) continue; |
334 | 357 |
335 // We can only have one ColumnStartTime column, and only | 358 // We can only have one ColumnStartTime column, and only |
336 // one of either ColumnDuration or ColumnEndTime | 359 // one of either ColumnDuration or ColumnEndTime |
351 if (purpose == CSVFormat::ColumnLabel) { | 374 if (purpose == CSVFormat::ColumnLabel) { |
352 if (cp == purpose) { | 375 if (cp == purpose) { |
353 cp = CSVFormat::ColumnUnknown; | 376 cp = CSVFormat::ColumnUnknown; |
354 } | 377 } |
355 } | 378 } |
356 } | 379 |
357 | 380 if (cp == CSVFormat::ColumnStartTime) { |
358 if (cp == CSVFormat::ColumnStartTime) { | 381 haveStartTime = true; |
382 } | |
383 | |
384 thisCombo->setCurrentIndex(int(cp)); | |
385 | |
386 } else { | |
387 if (purpose == CSVFormat::ColumnStartTime) { | |
388 haveStartTime = true; | |
389 } | |
390 } | |
391 } | |
392 | |
393 if (!haveStartTime) { | |
394 m_timingTypeCombo->setCurrentIndex(int(TimingImplicit)); | |
395 } else if (m_timingTypeCombo->currentIndex() == int(TimingImplicit)) { | |
396 if (m_initialTimingOption == TimingImplicit) { | |
397 m_timingTypeCombo->setCurrentIndex(TimingExplicitSeconds); | |
398 } else { | |
399 m_timingTypeCombo->setCurrentIndex(m_initialTimingOption); | |
400 } | |
401 } | |
402 | |
403 updateFormatFromDialog(); | |
404 updateComboVisibility(); | |
405 } | |
406 | |
407 void | |
408 CSVFormatDialog::updateFormatFromDialog() | |
409 { | |
410 switch (TimingOption(m_timingTypeCombo->currentIndex())) { | |
411 | |
412 case TimingExplicitSeconds: | |
413 m_format.setTimingType(CSVFormat::ExplicitTiming); | |
414 m_format.setTimeUnits(CSVFormat::TimeSeconds); | |
415 break; | |
416 | |
417 case TimingExplicitMsec: | |
418 m_format.setTimingType(CSVFormat::ExplicitTiming); | |
419 m_format.setTimeUnits(CSVFormat::TimeMilliseconds); | |
420 break; | |
421 | |
422 case TimingExplicitSamples: | |
423 m_format.setTimingType(CSVFormat::ExplicitTiming); | |
424 m_format.setTimeUnits(CSVFormat::TimeAudioFrames); | |
425 break; | |
426 | |
427 case TimingImplicit: | |
428 m_format.setTimingType(CSVFormat::ImplicitTiming); | |
429 m_format.setTimeUnits(CSVFormat::TimeWindows); | |
430 break; | |
431 } | |
432 | |
433 bool haveStartTime = false; | |
434 bool haveDuration = false; | |
435 bool havePitch = false; | |
436 int valueCount = 0; | |
437 | |
438 for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { | |
439 | |
440 QComboBox *thisCombo = m_columnPurposeCombos[i]; | |
441 | |
442 CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose) | |
443 (thisCombo->currentIndex()); | |
444 | |
445 if (purpose == CSVFormat::ColumnStartTime) { | |
359 haveStartTime = true; | 446 haveStartTime = true; |
360 } | 447 } |
361 if (cp == CSVFormat::ColumnEndTime || | 448 if (purpose == CSVFormat::ColumnEndTime || |
362 cp == CSVFormat::ColumnDuration) { | 449 purpose == CSVFormat::ColumnDuration) { |
363 haveDuration = true; | 450 haveDuration = true; |
364 } | 451 } |
365 if (cp == CSVFormat::ColumnPitch) { | 452 if (purpose == CSVFormat::ColumnPitch) { |
366 havePitch = true; | 453 havePitch = true; |
367 } | 454 } |
368 if (cp == CSVFormat::ColumnValue) { | 455 if (purpose == CSVFormat::ColumnValue) { |
369 ++valueCount; | 456 ++valueCount; |
370 } | 457 } |
371 | 458 |
372 m_columnPurposeCombos[i]->setCurrentIndex(int(cp)); | 459 m_format.setColumnPurpose(i, purpose); |
373 m_format.setColumnPurpose(i, cp); | 460 |
374 } | 461 if (i == m_fuzzyColumn) { |
375 | 462 for (int j = i + 1; j < m_format.getColumnCount(); ++j) { |
376 if (!haveStartTime) { | 463 if (purpose == CSVFormat::ColumnUnknown) { |
377 m_timingTypeCombo->setCurrentIndex(2); | 464 m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown); |
378 timingTypeChanged(2); | 465 } else { // Value |
466 m_format.setColumnPurpose(j, CSVFormat::ColumnValue); | |
467 ++valueCount; | |
468 } | |
469 } | |
470 } | |
379 } | 471 } |
380 | 472 |
381 if (haveStartTime && haveDuration) { | 473 if (haveStartTime && haveDuration) { |
382 if (havePitch) { | 474 if (havePitch) { |
383 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch); | 475 m_format.setModelType(CSVFormat::TwoDimensionalModelWithDurationAndPitch); |
396 | 488 |
397 updateModelLabel(); | 489 updateModelLabel(); |
398 } | 490 } |
399 | 491 |
400 | 492 |
493 |