# HG changeset patch # User Chris Cannam # Date 1396864035 -3600 # Node ID 69cc0454ed7221ab389d81b449d696bf44f6dbb0 # Parent 451f7f3ab6e7a1efeb603fdab0b5b9c9434d1e5b Make it possible to import CSV files directly into Note layers diff -r 451f7f3ab6e7 -r 69cc0454ed72 data/fft/FFTDataServer.cpp --- a/data/fft/FFTDataServer.cpp Thu Mar 27 13:32:56 2014 +0000 +++ b/data/fft/FFTDataServer.cpp Mon Apr 07 10:47:15 2014 +0100 @@ -868,7 +868,7 @@ // and previous cache readers) int deleteCandidate = c - 2; if (deleteCandidate < 0) deleteCandidate = c + 2; - if (deleteCandidate >= m_caches.size()) { + if (deleteCandidate >= (int)m_caches.size()) { return true; } diff -r 451f7f3ab6e7 -r 69cc0454ed72 data/fileio/CSVFileReader.cpp --- a/data/fileio/CSVFileReader.cpp Thu Mar 27 13:32:56 2014 +0000 +++ b/data/fileio/CSVFileReader.cpp Mon Apr 07 10:47:15 2014 +0100 @@ -22,6 +22,7 @@ #include "model/SparseTimeValueModel.h" #include "model/EditableDenseThreeDimensionalModel.h" #include "model/RegionModel.h" +#include "model/NoteModel.h" #include "DataFileReaderFactory.h" #include @@ -85,7 +86,7 @@ size_t windowSize) const { QRegExp nonNumericRx("[^0-9eE.,+-]"); - unsigned int warnLimit = 10; + int warnLimit = 10; CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits(); @@ -156,6 +157,7 @@ SparseOneDimensionalModel *model1 = 0; SparseTimeValueModel *model2 = 0; RegionModel *model2a = 0; + NoteModel *model2b = 0; EditableDenseThreeDimensionalModel *model3 = 0; Model *model = 0; @@ -173,6 +175,7 @@ bool haveAnyValue = false; bool haveEndTime = false; + bool pitchLooksLikeMIDI = true; size_t startFrame = 0; // for calculation of dense model resolution bool firstEverValue = true; @@ -202,7 +205,7 @@ QString chunk = in.readLine(); QStringList lines = chunk.split('\r', QString::SkipEmptyParts); - for (size_t li = 0; li < lines.size(); ++li) { + for (int li = 0; li < lines.size(); ++li) { QString line = lines[li]; @@ -228,6 +231,11 @@ model = model2a; break; + case CSVFormat::TwoDimensionalModelWithDurationAndPitch: + model2b = new NoteModel(sampleRate, windowSize, false); + model = model2b; + break; + case CSVFormat::ThreeDimensionalModel: model3 = new EditableDenseThreeDimensionalModel (sampleRate, @@ -240,6 +248,7 @@ } float value = 0.f; + float pitch = 0.f; QString label = ""; duration = 0.f; @@ -274,6 +283,13 @@ haveAnyValue = true; break; + case CSVFormat::ColumnPitch: + pitch = s.toFloat(); + if (pitch < 0.f || pitch > 127.f) { + pitchLooksLikeMIDI = false; + } + break; + case CSVFormat::ColumnLabel: label = s; ++labelCountMap[label]; @@ -302,6 +318,12 @@ RegionModel::Point point(frameNo, value, duration, label); model2a->addPoint(point); + } else if (modelType == CSVFormat::TwoDimensionalModelWithDurationAndPitch) { + + float level = ((value >= 0.f && value <= 1.f) ? value : 1.f); + NoteModel::Point point(frameNo, pitch, duration, level, label); + model2b->addPoint(point); + } else if (modelType == CSVFormat::ThreeDimensionalModel) { DenseThreeDimensionalModel::Column values; @@ -400,6 +422,14 @@ } } + if (model2b) { + if (pitchLooksLikeMIDI) { + model2b->setScaleUnits("MIDI Pitch"); + } else { + model2b->setScaleUnits("Hz"); + } + } + if (modelType == CSVFormat::ThreeDimensionalModel) { model3->setMinimumLevel(min); model3->setMaximumLevel(max); diff -r 451f7f3ab6e7 -r 69cc0454ed72 data/fileio/CSVFormat.cpp --- a/data/fileio/CSVFormat.cpp Thu Mar 27 13:32:56 2014 +0000 +++ b/data/fileio/CSVFormat.cpp Mon Apr 07 10:47:15 2014 +0100 @@ -66,7 +66,7 @@ QString chunk = in.readLine(); QStringList lines = chunk.split('\r', QString::SkipEmptyParts); - for (size_t li = 0; li < lines.size(); ++li) { + for (int li = 0; li < lines.size(); ++li) { QString line = lines[li]; if (line.startsWith("#") || line == "") continue; @@ -86,7 +86,7 @@ CSVFormat::guessSeparator(QString line) { char candidates[] = { ',', '\t', ' ', '|', '/', ':' }; - for (int i = 0; i < sizeof(candidates)/sizeof(candidates[0]); ++i) { + for (int i = 0; i < int(sizeof(candidates)/sizeof(candidates[0])); ++i) { if (StringBits::split(line, candidates[i], m_allowQuoting).size() >= 2) { m_separator = candidates[i]; return; diff -r 451f7f3ab6e7 -r 69cc0454ed72 data/fileio/CSVFormat.h --- a/data/fileio/CSVFormat.h Thu Mar 27 13:32:56 2014 +0000 +++ b/data/fileio/CSVFormat.h Mon Apr 07 10:47:15 2014 +0100 @@ -26,6 +26,7 @@ OneDimensionalModel, TwoDimensionalModel, TwoDimensionalModelWithDuration, + TwoDimensionalModelWithDurationAndPitch, ThreeDimensionalModel }; @@ -46,6 +47,7 @@ ColumnEndTime, ColumnDuration, ColumnValue, + ColumnPitch, ColumnLabel }; diff -r 451f7f3ab6e7 -r 69cc0454ed72 data/model/Model.h --- a/data/model/Model.h Thu Mar 27 13:32:56 2014 +0000 +++ b/data/model/Model.h Mon Apr 07 10:47:15 2014 +0100 @@ -216,7 +216,7 @@ virtual QString toDelimitedDataString(QString delimiter) const { return toDelimitedDataString(delimiter, getStartFrame(), getEndFrame()); } - virtual QString toDelimitedDataString(QString, size_t f0, size_t f1) const { + virtual QString toDelimitedDataString(QString, size_t /* f0 */, size_t /* f1 */) const { return ""; }