comparison data/fileio/CSVFileReader.cpp @ 1519:fbe8afdfa8a6 import-audio-data

Add recorded/converted locations logic to this library
author Chris Cannam
date Tue, 11 Sep 2018 14:36:51 +0100
parents 9c09a3f05139
children 954d0cf29ca7
comparison
equal deleted inserted replaced
1518:9c09a3f05139 1519:fbe8afdfa8a6
17 17
18 #include "model/Model.h" 18 #include "model/Model.h"
19 #include "base/RealTime.h" 19 #include "base/RealTime.h"
20 #include "base/StringBits.h" 20 #include "base/StringBits.h"
21 #include "base/ProgressReporter.h" 21 #include "base/ProgressReporter.h"
22 #include "base/RecordDirectory.h"
22 #include "model/SparseOneDimensionalModel.h" 23 #include "model/SparseOneDimensionalModel.h"
23 #include "model/SparseTimeValueModel.h" 24 #include "model/SparseTimeValueModel.h"
24 #include "model/EditableDenseThreeDimensionalModel.h" 25 #include "model/EditableDenseThreeDimensionalModel.h"
25 #include "model/RegionModel.h" 26 #include "model/RegionModel.h"
26 #include "model/NoteModel.h" 27 #include "model/NoteModel.h"
27 #include "model/WritableWaveFileModel.h" 28 #include "model/WritableWaveFileModel.h"
28 #include "DataFileReaderFactory.h" 29 #include "DataFileReaderFactory.h"
29 30
30 #include <QFile> 31 #include <QFile>
32 #include <QDir>
31 #include <QFileInfo> 33 #include <QFileInfo>
32 #include <QString> 34 #include <QString>
33 #include <QRegExp> 35 #include <QRegExp>
34 #include <QStringList> 36 #include <QStringList>
35 #include <QTextStream> 37 #include <QTextStream>
38 #include <QDateTime>
36 39
37 #include <iostream> 40 #include <iostream>
38 #include <map> 41 #include <map>
39 #include <string> 42 #include <string>
40 43
304 if (line.startsWith("#")) continue; 307 if (line.startsWith("#")) continue;
305 308
306 QStringList list = StringBits::split(line, separator, allowQuoting); 309 QStringList list = StringBits::split(line, separator, allowQuoting);
307 if (!model) { 310 if (!model) {
308 311
312 QString modelName = m_filename;
313
309 switch (modelType) { 314 switch (modelType) {
310 315
311 case CSVFormat::OneDimensionalModel: 316 case CSVFormat::OneDimensionalModel:
312 model1 = new SparseOneDimensionalModel(sampleRate, windowSize); 317 model1 = new SparseOneDimensionalModel(sampleRate, windowSize);
313 model = model1; 318 model = model1;
339 344
340 case CSVFormat::WaveFileModel: 345 case CSVFormat::WaveFileModel:
341 { 346 {
342 bool normalise = (m_format.getAudioSampleRange() 347 bool normalise = (m_format.getAudioSampleRange()
343 == CSVFormat::SampleRangeOther); 348 == CSVFormat::SampleRangeOther);
349 QString path = getConvertedAudioFilePath();
344 modelW = new WritableWaveFileModel 350 modelW = new WritableWaveFileModel
345 (sampleRate, valueColumns, QString(), normalise); 351 (sampleRate, valueColumns, path, normalise);
352 modelName = QFileInfo(path).fileName();
346 model = modelW; 353 model = modelW;
347 break; 354 break;
348 } 355 }
349 } 356 }
350 357
351 if (model && model->isOK()) { 358 if (model && model->isOK()) {
352 if (m_filename != "") { 359 if (modelName != "") {
353 model->setObjectName(m_filename); 360 model->setObjectName(modelName);
354 } 361 }
355 } 362 }
356 } 363 }
357 364
358 if (!model || !model->isOK()) { 365 if (!model || !model->isOK()) {
621 } 628 }
622 629
623 return model; 630 return model;
624 } 631 }
625 632
633 QString
634 CSVFileReader::getConvertedAudioFilePath() const
635 {
636 QString base = m_filename;
637 base.replace(QRegExp("[/\\,.:;~<>\"'|?%*]+"), "_");
638
639 QString convertedFileDir = RecordDirectory::getConvertedAudioDirectory();
640 if (convertedFileDir == "") {
641 SVCERR << "WARNING: CSVFileReader::getConvertedAudioFilePath: Failed to retrieve converted audio directory" << endl;
642 return "";
643 }
644
645 auto ms = QDateTime::currentDateTime().toMSecsSinceEpoch();
646 auto s = ms / 1000; // there is a toSecsSinceEpoch in Qt 5.8 but
647 // we currently want to support older versions
648
649 return QDir(convertedFileDir).filePath
650 (QString("%1-%2.wav").arg(base).arg(s));
651 }
652