Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 1069:32ab6c48efaa
Merge from branch tonioni
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:11:34 +0100 |
parents | 26cf6d5251ec |
children | ed207f89aaef e22bfe8ca248 |
comparison
equal
deleted
inserted
replaced
1036:682d64f05e72 | 1069:32ab6c48efaa |
---|---|
34 | 34 |
35 #include <iostream> | 35 #include <iostream> |
36 #include <map> | 36 #include <map> |
37 | 37 |
38 CSVFileReader::CSVFileReader(QString path, CSVFormat format, | 38 CSVFileReader::CSVFileReader(QString path, CSVFormat format, |
39 int mainModelSampleRate) : | 39 sv_samplerate_t mainModelSampleRate) : |
40 m_format(format), | 40 m_format(format), |
41 m_device(0), | 41 m_device(0), |
42 m_ownDevice(true), | 42 m_ownDevice(true), |
43 m_warnings(0), | 43 m_warnings(0), |
44 m_mainModelSampleRate(mainModelSampleRate) | 44 m_mainModelSampleRate(mainModelSampleRate) |
61 delete file; | 61 delete file; |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 CSVFileReader::CSVFileReader(QIODevice *device, CSVFormat format, | 65 CSVFileReader::CSVFileReader(QIODevice *device, CSVFormat format, |
66 int mainModelSampleRate) : | 66 sv_samplerate_t mainModelSampleRate) : |
67 m_format(format), | 67 m_format(format), |
68 m_device(device), | 68 m_device(device), |
69 m_ownDevice(false), | 69 m_ownDevice(false), |
70 m_warnings(0), | 70 m_warnings(0), |
71 m_mainModelSampleRate(mainModelSampleRate) | 71 m_mainModelSampleRate(mainModelSampleRate) |
93 CSVFileReader::getError() const | 93 CSVFileReader::getError() const |
94 { | 94 { |
95 return m_error; | 95 return m_error; |
96 } | 96 } |
97 | 97 |
98 int | 98 sv_frame_t |
99 CSVFileReader::convertTimeValue(QString s, int lineno, int sampleRate, | 99 CSVFileReader::convertTimeValue(QString s, int lineno, |
100 sv_samplerate_t sampleRate, | |
100 int windowSize) const | 101 int windowSize) const |
101 { | 102 { |
102 QRegExp nonNumericRx("[^0-9eE.,+-]"); | 103 QRegExp nonNumericRx("[^0-9eE.,+-]"); |
103 int warnLimit = 10; | 104 int warnLimit = 10; |
104 | 105 |
105 CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits(); | 106 CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits(); |
106 | 107 |
107 int calculatedFrame = 0; | 108 sv_frame_t calculatedFrame = 0; |
108 | 109 |
109 bool ok = false; | 110 bool ok = false; |
110 QString numeric = s; | 111 QString numeric = s; |
111 numeric.remove(nonNumericRx); | 112 numeric.remove(nonNumericRx); |
112 | 113 |
113 if (timeUnits == CSVFormat::TimeSeconds) { | 114 if (timeUnits == CSVFormat::TimeSeconds) { |
114 | 115 |
115 double time = numeric.toDouble(&ok); | 116 double time = numeric.toDouble(&ok); |
116 if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok); | 117 if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok); |
117 calculatedFrame = int(time * sampleRate + 0.5); | 118 calculatedFrame = sv_frame_t(time * sampleRate + 0.5); |
118 | 119 |
119 } else if (timeUnits == CSVFormat::TimeMilliseconds) { | 120 } else if (timeUnits == CSVFormat::TimeMilliseconds) { |
120 | 121 |
121 double time = numeric.toDouble(&ok); | 122 double time = numeric.toDouble(&ok); |
122 if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok); | 123 if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok); |
123 calculatedFrame = int((time / 1000.0) * sampleRate + 0.5); | 124 calculatedFrame = sv_frame_t((time / 1000.0) * sampleRate + 0.5); |
124 | 125 |
125 } else { | 126 } else { |
126 | 127 |
127 long n = numeric.toLong(&ok); | 128 long n = numeric.toLong(&ok); |
128 if (n >= 0) calculatedFrame = n; | 129 if (n >= 0) calculatedFrame = n; |
153 if (!m_device) return 0; | 154 if (!m_device) return 0; |
154 | 155 |
155 CSVFormat::ModelType modelType = m_format.getModelType(); | 156 CSVFormat::ModelType modelType = m_format.getModelType(); |
156 CSVFormat::TimingType timingType = m_format.getTimingType(); | 157 CSVFormat::TimingType timingType = m_format.getTimingType(); |
157 CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits(); | 158 CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits(); |
158 int sampleRate = m_format.getSampleRate(); | 159 sv_samplerate_t sampleRate = m_format.getSampleRate(); |
159 int windowSize = m_format.getWindowSize(); | 160 int windowSize = m_format.getWindowSize(); |
160 QChar separator = m_format.getSeparator(); | 161 QChar separator = m_format.getSeparator(); |
161 bool allowQuoting = m_format.getAllowQuoting(); | 162 bool allowQuoting = m_format.getAllowQuoting(); |
162 | 163 |
163 if (timingType == CSVFormat::ExplicitTiming) { | 164 if (timingType == CSVFormat::ExplicitTiming) { |
187 unsigned int warnings = 0, warnLimit = 10; | 188 unsigned int warnings = 0, warnLimit = 10; |
188 unsigned int lineno = 0; | 189 unsigned int lineno = 0; |
189 | 190 |
190 float min = 0.0, max = 0.0; | 191 float min = 0.0, max = 0.0; |
191 | 192 |
192 int frameNo = 0; | 193 sv_frame_t frameNo = 0; |
193 int duration = 0; | 194 sv_frame_t duration = 0; |
194 int endFrame = 0; | 195 sv_frame_t endFrame = 0; |
195 | 196 |
196 bool haveAnyValue = false; | 197 bool haveAnyValue = false; |
197 bool haveEndTime = false; | 198 bool haveEndTime = false; |
198 bool pitchLooksLikeMIDI = true; | 199 bool pitchLooksLikeMIDI = true; |
199 | 200 |
200 int startFrame = 0; // for calculation of dense model resolution | 201 sv_frame_t startFrame = 0; // for calculation of dense model resolution |
201 bool firstEverValue = true; | 202 bool firstEverValue = true; |
202 | 203 |
203 std::map<QString, int> labelCountMap; | 204 std::map<QString, int> labelCountMap; |
204 | 205 |
205 int valueColumns = 0; | 206 int valueColumns = 0; |
371 if (firstEverValue) { | 372 if (firstEverValue) { |
372 startFrame = frameNo; | 373 startFrame = frameNo; |
373 model3->setStartFrame(startFrame); | 374 model3->setStartFrame(startFrame); |
374 } else if (lineno == 1 && | 375 } else if (lineno == 1 && |
375 timingType == CSVFormat::ExplicitTiming) { | 376 timingType == CSVFormat::ExplicitTiming) { |
376 model3->setResolution(frameNo - startFrame); | 377 model3->setResolution(int(frameNo - startFrame)); |
377 } | 378 } |
378 | 379 |
379 firstEverValue = false; | 380 firstEverValue = false; |
380 | 381 |
381 if (!ok) { | 382 if (!ok) { |