comparison data/fileio/CSVFormat.h @ 631:3a5ee4b6c9ad

* Complete the overhaul of CSV file import; now you can pick the purpose for each column in the file, and SV should do the rest. The most significant practical improvement here is that we can now handle files in which time and duration do not necessarily appear in known columns.
author Chris Cannam
date Mon, 19 Jul 2010 17:08:56 +0000
parents 11a664058dd8
children 69cc0454ed72
comparison
equal deleted inserted replaced
630:11a664058dd8 631:3a5ee4b6c9ad
32 enum TimingType { 32 enum TimingType {
33 ExplicitTiming, 33 ExplicitTiming,
34 ImplicitTiming 34 ImplicitTiming
35 }; 35 };
36 36
37 enum DurationType {
38 Durations,
39 EndTimes
40 };
41
42 enum TimeUnits { 37 enum TimeUnits {
43 TimeSeconds, 38 TimeSeconds,
44 TimeAudioFrames, 39 TimeAudioFrames,
45 TimeWindows 40 TimeWindows
46 }; 41 };
63 typedef unsigned int ColumnQualities; 58 typedef unsigned int ColumnQualities;
64 59
65 CSVFormat() : // arbitrary defaults 60 CSVFormat() : // arbitrary defaults
66 m_modelType(TwoDimensionalModel), 61 m_modelType(TwoDimensionalModel),
67 m_timingType(ExplicitTiming), 62 m_timingType(ExplicitTiming),
68 m_durationType(Durations),
69 m_timeUnits(TimeSeconds), 63 m_timeUnits(TimeSeconds),
70 m_separator(","), 64 m_separator(","),
71 m_sampleRate(44100), 65 m_sampleRate(44100),
72 m_windowSize(1024), 66 m_windowSize(1024),
73 m_columnCount(0), 67 m_columnCount(0),
74 m_variableColumnCount(false), 68 m_variableColumnCount(false),
75 m_behaviour(QString::KeepEmptyParts),
76 m_allowQuoting(true), 69 m_allowQuoting(true),
77 m_maxExampleCols(0) 70 m_maxExampleCols(0)
78 { } 71 { }
79 72
80 CSVFormat(QString path); // guess format 73 CSVFormat(QString path); // guess format
88 */ 81 */
89 void guessFormatFor(QString path); 82 void guessFormatFor(QString path);
90 83
91 ModelType getModelType() const { return m_modelType; } 84 ModelType getModelType() const { return m_modelType; }
92 TimingType getTimingType() const { return m_timingType; } 85 TimingType getTimingType() const { return m_timingType; }
93 DurationType getDurationType() const { return m_durationType; }
94 TimeUnits getTimeUnits() const { return m_timeUnits; } 86 TimeUnits getTimeUnits() const { return m_timeUnits; }
95 QString getSeparator() const { return m_separator; }
96 size_t getSampleRate() const { return m_sampleRate; } 87 size_t getSampleRate() const { return m_sampleRate; }
97 size_t getWindowSize() const { return m_windowSize; } 88 size_t getWindowSize() const { return m_windowSize; }
98 int getColumnCount() const { return m_columnCount; } 89 int getColumnCount() const { return m_columnCount; }
99 90 bool getAllowQuoting() const { return m_allowQuoting; }
100 QString::SplitBehavior getSplitBehaviour() const { return m_behaviour; } 91 QChar getSeparator() const {
101 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; } 92 if (m_separator == "") return ' ';
93 else return m_separator[0];
94 }
102 95
103 ColumnPurpose getColumnPurpose(int i) { return m_columnPurposes[i]; }
104
105 void setModelType(ModelType t) { m_modelType = t; } 96 void setModelType(ModelType t) { m_modelType = t; }
106 void setTimingType(TimingType t) { m_timingType = t; } 97 void setTimingType(TimingType t) { m_timingType = t; }
107 void setDurationType(DurationType t) { m_durationType = t; }
108 void setTimeUnits(TimeUnits t) { m_timeUnits = t; } 98 void setTimeUnits(TimeUnits t) { m_timeUnits = t; }
109 void setSeparator(QString s) { m_separator = s; } 99 void setSeparator(QChar s) { m_separator = s; }
110 void setSampleRate(size_t r) { m_sampleRate = r; } 100 void setSampleRate(size_t r) { m_sampleRate = r; }
111 void setWindowSize(size_t s) { m_windowSize = s; } 101 void setWindowSize(size_t s) { m_windowSize = s; }
112 void setColumnCount(int c) { m_columnCount = c; } 102 void setColumnCount(int c) { m_columnCount = c; }
103 void setAllowQuoting(bool q) { m_allowQuoting = q; }
113 104
114 void setSplitBehaviour(QString::SplitBehavior b) { m_behaviour = b; } 105 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; }
115 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; } 106 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; }
107
108 ColumnPurpose getColumnPurpose(int i);
109 ColumnPurpose getColumnPurpose(int i) const;
110 void setColumnPurpose(int i, ColumnPurpose p);
116 111
117 void setColumnPurpose(int i, ColumnPurpose p) { m_columnPurposes[i] = p; }
118
119 // read-only; only valid if format has been guessed: 112 // read-only; only valid if format has been guessed:
120 QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; } 113 QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; }
121 114
122 // read-only; only valid if format has been guessed: 115 // read-only; only valid if format has been guessed:
123 QList<QStringList> getExample() const { return m_example; } 116 QList<QStringList> getExample() const { return m_example; }
124 int getMaxExampleCols() const { return m_maxExampleCols; } 117 int getMaxExampleCols() const { return m_maxExampleCols; }
125 118
126 protected: 119 protected:
127 ModelType m_modelType; 120 ModelType m_modelType;
128 TimingType m_timingType; 121 TimingType m_timingType;
129 DurationType m_durationType;
130 TimeUnits m_timeUnits; 122 TimeUnits m_timeUnits;
131 QString m_separator; 123 QString m_separator;
132 size_t m_sampleRate; 124 size_t m_sampleRate;
133 size_t m_windowSize; 125 size_t m_windowSize;
134 126
138 QList<ColumnQualities> m_columnQualities; 130 QList<ColumnQualities> m_columnQualities;
139 QList<ColumnPurpose> m_columnPurposes; 131 QList<ColumnPurpose> m_columnPurposes;
140 132
141 QList<float> m_prevValues; 133 QList<float> m_prevValues;
142 134
143 QString::SplitBehavior m_behaviour;
144 bool m_allowQuoting; 135 bool m_allowQuoting;
145 136
146 QList<QStringList> m_example; 137 QList<QStringList> m_example;
147 int m_maxExampleCols; 138 int m_maxExampleCols;
148 139