comparison data/fileio/CSVFormat.cpp @ 628:001db550bd48

* Add option to import time+duration (or time+endtime) from CSV files (importing to Region layers) * Fix ffwd/rwd in Region layers so as to behave like time-value layers
author Chris Cannam
date Thu, 08 Jul 2010 14:22:28 +0000
parents d095214ffbaf
children 35499d48a5d1
comparison
equal deleted inserted replaced
627:080d8bdd8762 628:001db550bd48
24 #include <iostream> 24 #include <iostream>
25 25
26 CSVFormat::CSVFormat(QString filename) : 26 CSVFormat::CSVFormat(QString filename) :
27 m_modelType(TwoDimensionalModel), 27 m_modelType(TwoDimensionalModel),
28 m_timingType(ExplicitTiming), 28 m_timingType(ExplicitTiming),
29 m_durationType(Durations),
29 m_timeUnits(TimeSeconds), 30 m_timeUnits(TimeSeconds),
30 m_separator(","), 31 m_separator(","),
31 m_sampleRate(44100), 32 m_sampleRate(44100),
32 m_windowSize(1024), 33 m_windowSize(1024),
33 m_behaviour(QString::KeepEmptyParts), 34 m_behaviour(QString::KeepEmptyParts),
41 in.seek(0); 42 in.seek(0);
42 43
43 unsigned int lineno = 0; 44 unsigned int lineno = 0;
44 45
45 bool nonIncreasingPrimaries = false; 46 bool nonIncreasingPrimaries = false;
47 bool nonIncreasingSecondaries = false;
46 bool nonNumericPrimaries = false; 48 bool nonNumericPrimaries = false;
47 bool floatPrimaries = false; 49 bool floatPrimaries = false;
48 bool variableItemCount = false; 50 bool variableItemCount = false;
49 int itemCount = 1; 51 int itemCount = 1;
50 int earliestNonNumericItem = -1; 52 int earliestNonNumericItem = -1;
51 53
52 float prevPrimary = 0.0; 54 float prevPrimary = 0.0;
55 float prevSecondary = 0.0;
53 56
54 m_maxExampleCols = 0; 57 m_maxExampleCols = 0;
55 m_separator = ""; 58 m_separator = "";
56 59
57 while (!in.atEnd()) { 60 while (!in.atEnd()) {
135 if (!numeric) { 138 if (!numeric) {
136 if (earliestNonNumericItem < 0 || 139 if (earliestNonNumericItem < 0 ||
137 i < earliestNonNumericItem) { 140 i < earliestNonNumericItem) {
138 earliestNonNumericItem = i; 141 earliestNonNumericItem = i;
139 } 142 }
143 } else if (i == 1) {
144 float secondary = s.toFloat();
145 if (lineno > 0 && secondary <= prevSecondary) {
146 nonIncreasingSecondaries = true;
147 }
148 prevSecondary = secondary;
140 } 149 }
141 } 150 }
142 } 151 }
143 152
144 if (lineno < 10) { 153 if (lineno < 10) {
191 m_modelType = CSVFormat::TwoDimensionalModel; 200 m_modelType = CSVFormat::TwoDimensionalModel;
192 } 201 }
193 } else { 202 } else {
194 m_modelType = CSVFormat::ThreeDimensionalModel; 203 m_modelType = CSVFormat::ThreeDimensionalModel;
195 } 204 }
205
206 if (nonIncreasingSecondaries) {
207 m_durationType = Durations;
208 } else {
209 m_durationType = EndTimes;
210 }
196 } 211 }
197 212
198 std::cerr << "Estimated model type: " << m_modelType << std::endl; 213 std::cerr << "Estimated model type: " << m_modelType << std::endl;
199 std::cerr << "Estimated timing type: " << m_timingType << std::endl; 214 std::cerr << "Estimated timing type: " << m_timingType << std::endl;
215 std::cerr << "Estimated duration type: " << m_durationType << std::endl;
200 std::cerr << "Estimated units: " << m_timeUnits << std::endl; 216 std::cerr << "Estimated units: " << m_timeUnits << std::endl;
201 } 217 }
202 218