Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp Sat Sep 08 20:53:48 2018 +0100 +++ b/data/fileio/CSVFileReader.cpp Tue Sep 11 14:36:51 2018 +0100 @@ -19,6 +19,7 @@ #include "base/RealTime.h" #include "base/StringBits.h" #include "base/ProgressReporter.h" +#include "base/RecordDirectory.h" #include "model/SparseOneDimensionalModel.h" #include "model/SparseTimeValueModel.h" #include "model/EditableDenseThreeDimensionalModel.h" @@ -28,11 +29,13 @@ #include "DataFileReaderFactory.h" #include <QFile> +#include <QDir> #include <QFileInfo> #include <QString> #include <QRegExp> #include <QStringList> #include <QTextStream> +#include <QDateTime> #include <iostream> #include <map> @@ -306,6 +309,8 @@ QStringList list = StringBits::split(line, separator, allowQuoting); if (!model) { + QString modelName = m_filename; + switch (modelType) { case CSVFormat::OneDimensionalModel: @@ -341,16 +346,18 @@ { bool normalise = (m_format.getAudioSampleRange() == CSVFormat::SampleRangeOther); + QString path = getConvertedAudioFilePath(); modelW = new WritableWaveFileModel - (sampleRate, valueColumns, QString(), normalise); + (sampleRate, valueColumns, path, normalise); + modelName = QFileInfo(path).fileName(); model = modelW; break; } } if (model && model->isOK()) { - if (m_filename != "") { - model->setObjectName(m_filename); + if (modelName != "") { + model->setObjectName(modelName); } } } @@ -623,3 +630,23 @@ return model; } +QString +CSVFileReader::getConvertedAudioFilePath() const +{ + QString base = m_filename; + base.replace(QRegExp("[/\\,.:;~<>\"'|?%*]+"), "_"); + + QString convertedFileDir = RecordDirectory::getConvertedAudioDirectory(); + if (convertedFileDir == "") { + SVCERR << "WARNING: CSVFileReader::getConvertedAudioFilePath: Failed to retrieve converted audio directory" << endl; + return ""; + } + + auto ms = QDateTime::currentDateTime().toMSecsSinceEpoch(); + auto s = ms / 1000; // there is a toSecsSinceEpoch in Qt 5.8 but + // we currently want to support older versions + + return QDir(convertedFileDir).filePath + (QString("%1-%2.wav").arg(base).arg(s)); +} +