Mercurial > hg > svcore
comparison data/fileio/CSVFormat.h @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 64ef24ebb19c |
children | 9570ef94eaa3 |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #ifndef _CSV_FORMAT_H_ | 16 #ifndef SV_CSV_FORMAT_H |
17 #define _CSV_FORMAT_H_ | 17 #define SV_CSV_FORMAT_H |
18 | 18 |
19 #include <QString> | 19 #include <QString> |
20 #include <QStringList> | 20 #include <QStringList> |
21 | 21 |
22 #include "base/BaseTypes.h" | 22 #include "base/BaseTypes.h" |
23 | 23 |
24 class CSVFormat | 24 class CSVFormat |
25 { | 25 { |
26 public: | 26 public: |
27 enum ModelType { | 27 enum ModelType { |
28 OneDimensionalModel, | 28 OneDimensionalModel, |
29 TwoDimensionalModel, | 29 TwoDimensionalModel, |
30 TwoDimensionalModelWithDuration, | 30 TwoDimensionalModelWithDuration, |
31 TwoDimensionalModelWithDurationAndPitch, | 31 TwoDimensionalModelWithDurationAndPitch, |
32 ThreeDimensionalModel | 32 ThreeDimensionalModel, |
33 WaveFileModel | |
33 }; | 34 }; |
34 | 35 |
35 enum TimingType { | 36 enum TimingType { |
36 ExplicitTiming, | 37 ExplicitTiming, |
37 ImplicitTiming | 38 ImplicitTiming |
38 }; | 39 }; |
39 | 40 |
40 enum TimeUnits { | 41 enum TimeUnits { |
41 TimeSeconds, | 42 TimeSeconds, |
42 TimeMilliseconds, | 43 TimeMilliseconds, |
43 TimeAudioFrames, | 44 TimeAudioFrames, |
44 TimeWindows, | 45 TimeWindows, |
45 }; | 46 }; |
46 | 47 |
47 enum ColumnPurpose { | 48 enum ColumnPurpose { |
48 ColumnUnknown, | 49 ColumnUnknown, |
49 ColumnStartTime, | 50 ColumnStartTime, |
53 ColumnPitch, | 54 ColumnPitch, |
54 ColumnLabel | 55 ColumnLabel |
55 }; | 56 }; |
56 | 57 |
57 enum ColumnQuality { | 58 enum ColumnQuality { |
58 ColumnNumeric = 1, | 59 ColumnNumeric = 1, // No non-numeric values were seen in sample |
59 ColumnIntegral = 2, | 60 ColumnIntegral = 2, // All sampled values were integers |
60 ColumnIncreasing = 4, | 61 ColumnIncreasing = 4, // Sampled values were monotonically increasing |
61 ColumnLarge = 8, | 62 ColumnSmall = 8, // All sampled values had magnitude < 1 |
62 ColumnNearEmpty = 16, | 63 ColumnLarge = 16, // Values "quickly" grew to over 1000 |
64 ColumnSigned = 32, // Some negative values were seen | |
65 ColumnNearEmpty = 64, // Nothing in this column beyond first row | |
63 }; | 66 }; |
64 typedef unsigned int ColumnQualities; | 67 typedef unsigned int ColumnQualities; |
68 | |
69 enum AudioSampleRange { | |
70 SampleRangeSigned1 = 0, // -1 .. 1 | |
71 SampleRangeUnsigned255, // 0 .. 255 | |
72 SampleRangeSigned32767, // -32768 .. 32767 | |
73 SampleRangeOther // Other/unknown: Normalise on load | |
74 }; | |
65 | 75 |
66 CSVFormat() : // arbitrary defaults | 76 CSVFormat() : // arbitrary defaults |
67 m_modelType(TwoDimensionalModel), | 77 m_modelType(TwoDimensionalModel), |
68 m_timingType(ExplicitTiming), | 78 m_timingType(ExplicitTiming), |
69 m_timeUnits(TimeSeconds), | 79 m_timeUnits(TimeSeconds), |
70 m_separator(","), | 80 m_separator(","), |
71 m_sampleRate(44100), | 81 m_sampleRate(44100), |
72 m_windowSize(1024), | 82 m_windowSize(1024), |
73 m_columnCount(0), | 83 m_columnCount(0), |
74 m_variableColumnCount(false), | 84 m_variableColumnCount(false), |
85 m_audioSampleRange(SampleRangeOther), | |
75 m_allowQuoting(true), | 86 m_allowQuoting(true), |
76 m_maxExampleCols(0) | 87 m_maxExampleCols(0) |
77 { } | 88 { } |
78 | 89 |
79 CSVFormat(QString path); // guess format | 90 CSVFormat(QString path); // guess format |
82 * Guess the format of the given CSV file, setting the fields in | 93 * Guess the format of the given CSV file, setting the fields in |
83 * this object accordingly. If the current separator is the empty | 94 * this object accordingly. If the current separator is the empty |
84 * string, the separator character will also be guessed; otherwise | 95 * string, the separator character will also be guessed; otherwise |
85 * the current separator will be used. The other properties of | 96 * the current separator will be used. The other properties of |
86 * this object will be set according to guesses from the file. | 97 * this object will be set according to guesses from the file. |
98 * | |
99 * The properties that are guessed from the file contents are: | |
100 * separator, column count, variable-column-count flag, audio | |
101 * sample range, timing type, time units, column qualities, column | |
102 * purposes, and model type. The sample rate and window size | |
103 * cannot be guessed and will not be changed by this function. | |
104 * Note also that this function will never guess WaveFileModel for | |
105 * the model type. | |
106 * | |
107 * Return false if there is some fundamental error, e.g. the file | |
108 * could not be opened at all. Return true otherwise. Note that | |
109 * this function returns true even if the file doesn't appear to | |
110 * make much sense as a data format. | |
87 */ | 111 */ |
88 void guessFormatFor(QString path); | 112 bool guessFormatFor(QString path); |
89 | 113 |
90 ModelType getModelType() const { return m_modelType; } | 114 ModelType getModelType() const { return m_modelType; } |
91 TimingType getTimingType() const { return m_timingType; } | 115 TimingType getTimingType() const { return m_timingType; } |
92 TimeUnits getTimeUnits() const { return m_timeUnits; } | 116 TimeUnits getTimeUnits() const { return m_timeUnits; } |
93 sv_samplerate_t getSampleRate() const { return m_sampleRate; } | 117 sv_samplerate_t getSampleRate() const { return m_sampleRate; } |
94 int getWindowSize() const { return m_windowSize; } | 118 int getWindowSize() const { return m_windowSize; } |
95 int getColumnCount() const { return m_columnCount; } | 119 int getColumnCount() const { return m_columnCount; } |
120 AudioSampleRange getAudioSampleRange() const { return m_audioSampleRange; } | |
96 bool getAllowQuoting() const { return m_allowQuoting; } | 121 bool getAllowQuoting() const { return m_allowQuoting; } |
97 QChar getSeparator() const { | 122 QChar getSeparator() const { |
98 if (m_separator == "") return ' '; | 123 if (m_separator == "") return ' '; |
99 else return m_separator[0]; | 124 else return m_separator[0]; |
100 } | 125 } |
104 void setTimeUnits(TimeUnits t) { m_timeUnits = t; } | 129 void setTimeUnits(TimeUnits t) { m_timeUnits = t; } |
105 void setSeparator(QChar s) { m_separator = s; } | 130 void setSeparator(QChar s) { m_separator = s; } |
106 void setSampleRate(sv_samplerate_t r) { m_sampleRate = r; } | 131 void setSampleRate(sv_samplerate_t r) { m_sampleRate = r; } |
107 void setWindowSize(int s) { m_windowSize = s; } | 132 void setWindowSize(int s) { m_windowSize = s; } |
108 void setColumnCount(int c) { m_columnCount = c; } | 133 void setColumnCount(int c) { m_columnCount = c; } |
134 void setAudioSampleRange(AudioSampleRange r) { m_audioSampleRange = r; } | |
109 void setAllowQuoting(bool q) { m_allowQuoting = q; } | 135 void setAllowQuoting(bool q) { m_allowQuoting = q; } |
110 | 136 |
111 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; } | 137 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; } |
112 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; } | 138 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; } |
113 | 139 |
114 ColumnPurpose getColumnPurpose(int i); | 140 ColumnPurpose getColumnPurpose(int i); |
115 ColumnPurpose getColumnPurpose(int i) const; | 141 ColumnPurpose getColumnPurpose(int i) const; |
116 void setColumnPurpose(int i, ColumnPurpose p); | 142 void setColumnPurpose(int i, ColumnPurpose p); |
117 | 143 |
118 // read-only; only valid if format has been guessed: | 144 // read-only; only valid if format has been guessed: |
119 QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; } | 145 const QList<ColumnQualities> &getColumnQualities() const { |
146 return m_columnQualities; | |
147 } | |
120 | 148 |
121 // read-only; only valid if format has been guessed: | 149 // read-only; only valid if format has been guessed: |
122 QList<QStringList> getExample() const { return m_example; } | 150 const QList<QStringList> &getExample() const { |
151 return m_example; | |
152 } | |
153 | |
123 int getMaxExampleCols() const { return m_maxExampleCols; } | 154 int getMaxExampleCols() const { return m_maxExampleCols; } |
124 | 155 |
125 protected: | 156 protected: |
126 ModelType m_modelType; | 157 ModelType m_modelType; |
127 TimingType m_timingType; | 158 TimingType m_timingType; |
128 TimeUnits m_timeUnits; | 159 TimeUnits m_timeUnits; |
129 QString m_separator; | 160 QString m_separator; |
134 bool m_variableColumnCount; | 165 bool m_variableColumnCount; |
135 | 166 |
136 QList<ColumnQualities> m_columnQualities; | 167 QList<ColumnQualities> m_columnQualities; |
137 QList<ColumnPurpose> m_columnPurposes; | 168 QList<ColumnPurpose> m_columnPurposes; |
138 | 169 |
170 AudioSampleRange m_audioSampleRange; | |
171 | |
139 QList<float> m_prevValues; | 172 QList<float> m_prevValues; |
140 | 173 |
141 bool m_allowQuoting; | 174 bool m_allowQuoting; |
142 | 175 |
143 QList<QStringList> m_example; | 176 QList<QStringList> m_example; |
144 int m_maxExampleCols; | 177 int m_maxExampleCols; |
145 | 178 |
146 void guessSeparator(QString line); | 179 void guessSeparator(QString line); |
147 void guessQualities(QString line, int lineno); | 180 void guessQualities(QString line, int lineno); |
148 void guessPurposes(); | 181 void guessPurposes(); |
149 | 182 void guessAudioSampleRange(); |
150 void guessFormatFor_Old(QString path); | |
151 | |
152 }; | 183 }; |
153 | 184 |
154 #endif | 185 #endif |