Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 87ae75da6527 |
children | 53fa8d57b728 |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
48 { | 48 { |
49 QFile *file = new QFile(path); | 49 QFile *file = new QFile(path); |
50 bool good = false; | 50 bool good = false; |
51 | 51 |
52 if (!file->exists()) { | 52 if (!file->exists()) { |
53 m_error = QFile::tr("File \"%1\" does not exist").arg(path); | 53 m_error = QFile::tr("File \"%1\" does not exist").arg(path); |
54 } else if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { | 54 } else if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { |
55 m_error = QFile::tr("Failed to open file \"%1\"").arg(path); | 55 m_error = QFile::tr("Failed to open file \"%1\"").arg(path); |
56 } else { | 56 } else { |
57 good = true; | 57 good = true; |
58 } | 58 } |
59 | 59 |
60 if (good) { | 60 if (good) { |
61 m_device = file; | 61 m_device = file; |
62 m_filename = QFileInfo(path).fileName(); | 62 m_filename = QFileInfo(path).fileName(); |
63 } else { | 63 } else { |
64 delete file; | 64 delete file; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 CSVFileReader::CSVFileReader(QIODevice *device, CSVFormat format, | 68 CSVFileReader::CSVFileReader(QIODevice *device, CSVFormat format, |
69 sv_samplerate_t mainModelSampleRate) : | 69 sv_samplerate_t mainModelSampleRate) : |
171 // that's likely to be visible | 171 // that's likely to be visible |
172 windowSize = 1024; | 172 windowSize = 1024; |
173 } else { | 173 } else { |
174 windowSize = 1; | 174 windowSize = 1; |
175 } | 175 } |
176 if (timeUnits == CSVFormat::TimeSeconds || | 176 if (timeUnits == CSVFormat::TimeSeconds || |
177 timeUnits == CSVFormat::TimeMilliseconds) { | 177 timeUnits == CSVFormat::TimeMilliseconds) { |
178 sampleRate = m_mainModelSampleRate; | 178 sampleRate = m_mainModelSampleRate; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 SparseOneDimensionalModel *model1 = 0; | 182 SparseOneDimensionalModel *model1 = 0; |
183 SparseTimeValueModel *model2 = 0; | 183 SparseTimeValueModel *model2 = 0; |
184 RegionModel *model2a = 0; | 184 RegionModel *model2a = 0; |
242 | 242 |
243 case CSVFormat::OneDimensionalModel: | 243 case CSVFormat::OneDimensionalModel: |
244 model1 = new SparseOneDimensionalModel(sampleRate, windowSize); | 244 model1 = new SparseOneDimensionalModel(sampleRate, windowSize); |
245 model = model1; | 245 model = model1; |
246 break; | 246 break; |
247 | 247 |
248 case CSVFormat::TwoDimensionalModel: | 248 case CSVFormat::TwoDimensionalModel: |
249 model2 = new SparseTimeValueModel(sampleRate, windowSize, false); | 249 model2 = new SparseTimeValueModel(sampleRate, windowSize, false); |
250 model = model2; | 250 model = model2; |
251 break; | 251 break; |
252 | 252 |
253 case CSVFormat::TwoDimensionalModelWithDuration: | 253 case CSVFormat::TwoDimensionalModelWithDuration: |
254 model2a = new RegionModel(sampleRate, windowSize, false); | 254 model2a = new RegionModel(sampleRate, windowSize, false); |
255 model = model2a; | 255 model = model2a; |
256 break; | 256 break; |
257 | 257 |
258 case CSVFormat::TwoDimensionalModelWithDurationAndPitch: | 258 case CSVFormat::TwoDimensionalModelWithDurationAndPitch: |
259 model2b = new NoteModel(sampleRate, windowSize, false); | 259 model2b = new NoteModel(sampleRate, windowSize, false); |
260 model = model2b; | 260 model = model2b; |
261 break; | 261 break; |
262 | 262 |
263 case CSVFormat::ThreeDimensionalModel: | 263 case CSVFormat::ThreeDimensionalModel: |
264 model3 = new EditableDenseThreeDimensionalModel | 264 model3 = new EditableDenseThreeDimensionalModel |
265 (sampleRate, | 265 (sampleRate, |
266 windowSize, | 266 windowSize, |
267 valueColumns, | 267 valueColumns, |
333 duration = endFrame - frameNo; | 333 duration = endFrame - frameNo; |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 if (modelType == CSVFormat::OneDimensionalModel) { | 337 if (modelType == CSVFormat::OneDimensionalModel) { |
338 | 338 |
339 SparseOneDimensionalModel::Point point(frameNo, label); | 339 SparseOneDimensionalModel::Point point(frameNo, label); |
340 model1->addPoint(point); | 340 model1->addPoint(point); |
341 | 341 |
342 } else if (modelType == CSVFormat::TwoDimensionalModel) { | 342 } else if (modelType == CSVFormat::TwoDimensionalModel) { |
343 | 343 |
367 | 367 |
368 bool ok = false; | 368 bool ok = false; |
369 float value = list[i].toFloat(&ok); | 369 float value = list[i].toFloat(&ok); |
370 | 370 |
371 values.push_back(value); | 371 values.push_back(value); |
372 | 372 |
373 if (firstEverValue || value < min) min = value; | 373 if (firstEverValue || value < min) min = value; |
374 if (firstEverValue || value > max) max = value; | 374 if (firstEverValue || value > max) max = value; |
375 | 375 |
376 if (firstEverValue) { | 376 if (firstEverValue) { |
377 startFrame = frameNo; | 377 startFrame = frameNo; |
395 } else if (warnings == warnLimit) { | 395 } else if (warnings == warnLimit) { |
396 // SVCERR << "WARNING: Too many warnings" << endl; | 396 // SVCERR << "WARNING: Too many warnings" << endl; |
397 } | 397 } |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 // SVDEBUG << "Setting bin values for count " << lineno << ", frame " | 401 // SVDEBUG << "Setting bin values for count " << lineno << ", frame " |
402 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << endl; | 402 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << endl; |
403 | 403 |
404 model3->setColumn(lineno, values); | 404 model3->setColumn(lineno, values); |
405 } | 405 } |
473 model2b->setScaleUnits("Hz"); | 473 model2b->setScaleUnits("Hz"); |
474 } | 474 } |
475 } | 475 } |
476 | 476 |
477 if (model3) { | 477 if (model3) { |
478 model3->setMinimumLevel(min); | 478 model3->setMinimumLevel(min); |
479 model3->setMaximumLevel(max); | 479 model3->setMaximumLevel(max); |
480 } | 480 } |
481 | 481 |
482 return model; | 482 return model; |
483 } | 483 } |
484 | 484 |