Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 1794:71e97de5053f
Merge from branch time-frequency-boxes
author | Chris Cannam |
---|---|
date | Wed, 25 Sep 2019 13:47:46 +0100 |
parents | f0ffc88a36b3 |
children | 2654bf447a84 |
comparison
equal
deleted
inserted
replaced
1788:7fc6256af2d2 | 1794:71e97de5053f |
---|---|
23 #include "model/SparseOneDimensionalModel.h" | 23 #include "model/SparseOneDimensionalModel.h" |
24 #include "model/SparseTimeValueModel.h" | 24 #include "model/SparseTimeValueModel.h" |
25 #include "model/EditableDenseThreeDimensionalModel.h" | 25 #include "model/EditableDenseThreeDimensionalModel.h" |
26 #include "model/RegionModel.h" | 26 #include "model/RegionModel.h" |
27 #include "model/NoteModel.h" | 27 #include "model/NoteModel.h" |
28 #include "model/BoxModel.h" | |
28 #include "model/WritableWaveFileModel.h" | 29 #include "model/WritableWaveFileModel.h" |
29 #include "DataFileReaderFactory.h" | 30 #include "DataFileReaderFactory.h" |
30 | 31 |
31 #include <QFile> | 32 #include <QFile> |
32 #include <QDir> | 33 #include <QDir> |
199 | 200 |
200 SparseOneDimensionalModel *model1 = nullptr; | 201 SparseOneDimensionalModel *model1 = nullptr; |
201 SparseTimeValueModel *model2 = nullptr; | 202 SparseTimeValueModel *model2 = nullptr; |
202 RegionModel *model2a = nullptr; | 203 RegionModel *model2a = nullptr; |
203 NoteModel *model2b = nullptr; | 204 NoteModel *model2b = nullptr; |
205 BoxModel *model2c = nullptr; | |
204 EditableDenseThreeDimensionalModel *model3 = nullptr; | 206 EditableDenseThreeDimensionalModel *model3 = nullptr; |
205 WritableWaveFileModel *modelW = nullptr; | 207 WritableWaveFileModel *modelW = nullptr; |
206 Model *model = nullptr; | 208 Model *model = nullptr; |
207 | 209 |
208 QTextStream in(m_device); | 210 QTextStream in(m_device); |
331 case CSVFormat::TwoDimensionalModelWithDurationAndPitch: | 333 case CSVFormat::TwoDimensionalModelWithDurationAndPitch: |
332 model2b = new NoteModel(sampleRate, windowSize, false); | 334 model2b = new NoteModel(sampleRate, windowSize, false); |
333 model = model2b; | 335 model = model2b; |
334 break; | 336 break; |
335 | 337 |
338 case CSVFormat::TwoDimensionalModelWithDurationAndExtent: | |
339 model2c = new BoxModel(sampleRate, windowSize, false); | |
340 model = model2c; | |
341 break; | |
342 | |
336 case CSVFormat::ThreeDimensionalModel: | 343 case CSVFormat::ThreeDimensionalModel: |
337 model3 = new EditableDenseThreeDimensionalModel | 344 model3 = new EditableDenseThreeDimensionalModel |
338 (sampleRate, windowSize, valueColumns); | 345 (sampleRate, windowSize, valueColumns); |
339 model = model3; | 346 model = model3; |
340 break; | 347 break; |
366 SVCERR << "Failed to create model to load CSV file into" | 373 SVCERR << "Failed to create model to load CSV file into" |
367 << endl; | 374 << endl; |
368 if (model) { | 375 if (model) { |
369 delete model; | 376 delete model; |
370 model = nullptr; | 377 model = nullptr; |
371 model1 = nullptr; model2 = nullptr; model2a = nullptr; model2b = nullptr; | 378 model1 = nullptr; model2 = nullptr; |
379 model2a = nullptr; model2b = nullptr; model2c = nullptr; | |
372 model3 = nullptr; modelW = nullptr; | 380 model3 = nullptr; modelW = nullptr; |
373 } | 381 } |
374 abandoned = true; | 382 abandoned = true; |
375 break; | 383 break; |
376 } | 384 } |
377 | 385 |
378 float value = 0.f; | 386 float value = 0.f; |
387 float otherValue = 0.f; | |
379 float pitch = 0.f; | 388 float pitch = 0.f; |
380 QString label = ""; | 389 QString label = ""; |
381 | 390 |
382 duration = 0.f; | 391 duration = 0.f; |
383 haveEndTime = false; | 392 haveEndTime = false; |
405 case CSVFormat::ColumnDuration: | 414 case CSVFormat::ColumnDuration: |
406 duration = convertTimeValue(s, lineno, sampleRate, windowSize); | 415 duration = convertTimeValue(s, lineno, sampleRate, windowSize); |
407 break; | 416 break; |
408 | 417 |
409 case CSVFormat::ColumnValue: | 418 case CSVFormat::ColumnValue: |
419 if (haveAnyValue) { | |
420 otherValue = value; | |
421 } | |
410 value = s.toFloat(); | 422 value = s.toFloat(); |
411 haveAnyValue = true; | 423 haveAnyValue = true; |
412 break; | 424 break; |
413 | 425 |
414 case CSVFormat::ColumnPitch: | 426 case CSVFormat::ColumnPitch: |
450 } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) { | 462 } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) { |
451 | 463 |
452 float level = ((value >= 0.f && value <= 1.f) ? value : 1.f); | 464 float level = ((value >= 0.f && value <= 1.f) ? value : 1.f); |
453 Event note(frameNo, pitch, duration, level, label); | 465 Event note(frameNo, pitch, duration, level, label); |
454 model2b->add(note); | 466 model2b->add(note); |
467 | |
468 } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndExtent) { | |
469 | |
470 float level = 0.f; | |
471 if (value > otherValue) { | |
472 level = value - otherValue; | |
473 value = otherValue; | |
474 } else { | |
475 level = otherValue - value; | |
476 } | |
477 Event box(frameNo, value, duration, level, label); | |
478 model2c->add(box); | |
455 | 479 |
456 } else if (modelType == CSVFormat::ThreeDimensionalModel) { | 480 } else if (modelType == CSVFormat::ThreeDimensionalModel) { |
457 | 481 |
458 DenseThreeDimensionalModel::Column values; | 482 DenseThreeDimensionalModel::Column values; |
459 | 483 |