Chris@392
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@392
|
2
|
Chris@392
|
3 /*
|
Chris@392
|
4 Sonic Visualiser
|
Chris@392
|
5 An audio file viewer and annotation editor.
|
Chris@392
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@392
|
7 This file copyright 2006 Chris Cannam.
|
Chris@392
|
8
|
Chris@392
|
9 This program is free software; you can redistribute it and/or
|
Chris@392
|
10 modify it under the terms of the GNU General Public License as
|
Chris@392
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@392
|
12 License, or (at your option) any later version. See the file
|
Chris@392
|
13 COPYING included with this distribution for more information.
|
Chris@392
|
14 */
|
Chris@392
|
15
|
Chris@1362
|
16 #ifndef SV_CSV_FORMAT_H
|
Chris@1362
|
17 #define SV_CSV_FORMAT_H
|
Chris@392
|
18
|
Chris@392
|
19 #include <QString>
|
Chris@392
|
20 #include <QStringList>
|
Chris@392
|
21
|
Chris@1047
|
22 #include "base/BaseTypes.h"
|
Chris@1047
|
23
|
Chris@392
|
24 class CSVFormat
|
Chris@392
|
25 {
|
Chris@392
|
26 public:
|
Chris@392
|
27 enum ModelType {
|
Chris@1429
|
28 OneDimensionalModel,
|
Chris@1429
|
29 TwoDimensionalModel,
|
Chris@628
|
30 TwoDimensionalModelWithDuration,
|
Chris@897
|
31 TwoDimensionalModelWithDurationAndPitch,
|
Chris@1488
|
32 ThreeDimensionalModel,
|
Chris@1488
|
33 WaveFileModel
|
Chris@392
|
34 };
|
Chris@392
|
35
|
Chris@392
|
36 enum TimingType {
|
Chris@1429
|
37 ExplicitTiming,
|
Chris@1429
|
38 ImplicitTiming
|
Chris@392
|
39 };
|
Chris@628
|
40
|
Chris@392
|
41 enum TimeUnits {
|
Chris@1429
|
42 TimeSeconds,
|
Chris@990
|
43 TimeMilliseconds,
|
Chris@1429
|
44 TimeAudioFrames,
|
Chris@1429
|
45 TimeWindows,
|
Chris@392
|
46 };
|
Chris@392
|
47
|
Chris@629
|
48 enum ColumnPurpose {
|
Chris@629
|
49 ColumnUnknown,
|
Chris@629
|
50 ColumnStartTime,
|
Chris@629
|
51 ColumnEndTime,
|
Chris@629
|
52 ColumnDuration,
|
Chris@629
|
53 ColumnValue,
|
Chris@897
|
54 ColumnPitch,
|
Chris@629
|
55 ColumnLabel
|
Chris@629
|
56 };
|
Chris@629
|
57
|
Chris@629
|
58 enum ColumnQuality {
|
Chris@1512
|
59 ColumnNumeric = 1, // No non-numeric values were seen in sample
|
Chris@1512
|
60 ColumnIntegral = 2, // All sampled values were integers
|
Chris@1512
|
61 ColumnIncreasing = 4, // Sampled values were monotonically increasing
|
Chris@1512
|
62 ColumnSmall = 8, // All sampled values had magnitude < 1
|
Chris@1512
|
63 ColumnLarge = 16, // Values "quickly" grew to over 1000
|
Chris@1512
|
64 ColumnSigned = 32, // Some negative values were seen
|
Chris@1512
|
65 ColumnNearEmpty = 64, // Nothing in this column beyond first row
|
Chris@629
|
66 };
|
Chris@629
|
67 typedef unsigned int ColumnQualities;
|
Chris@392
|
68
|
Chris@392
|
69 CSVFormat() : // arbitrary defaults
|
Chris@392
|
70 m_modelType(TwoDimensionalModel),
|
Chris@392
|
71 m_timingType(ExplicitTiming),
|
Chris@392
|
72 m_timeUnits(TimeSeconds),
|
Chris@392
|
73 m_separator(","),
|
Chris@392
|
74 m_sampleRate(44100),
|
Chris@392
|
75 m_windowSize(1024),
|
Chris@629
|
76 m_columnCount(0),
|
Chris@629
|
77 m_variableColumnCount(false),
|
Chris@629
|
78 m_allowQuoting(true),
|
Chris@629
|
79 m_maxExampleCols(0)
|
Chris@392
|
80 { }
|
Chris@629
|
81
|
Chris@629
|
82 CSVFormat(QString path); // guess format
|
Chris@629
|
83
|
Chris@629
|
84 /**
|
Chris@629
|
85 * Guess the format of the given CSV file, setting the fields in
|
Chris@629
|
86 * this object accordingly. If the current separator is the empty
|
Chris@629
|
87 * string, the separator character will also be guessed; otherwise
|
Chris@629
|
88 * the current separator will be used. The other properties of
|
Chris@629
|
89 * this object will be set according to guesses from the file.
|
Chris@629
|
90 */
|
Chris@629
|
91 void guessFormatFor(QString path);
|
Chris@628
|
92
|
Chris@628
|
93 ModelType getModelType() const { return m_modelType; }
|
Chris@628
|
94 TimingType getTimingType() const { return m_timingType; }
|
Chris@628
|
95 TimeUnits getTimeUnits() const { return m_timeUnits; }
|
Chris@1047
|
96 sv_samplerate_t getSampleRate() const { return m_sampleRate; }
|
Chris@929
|
97 int getWindowSize() const { return m_windowSize; }
|
Chris@630
|
98 int getColumnCount() const { return m_columnCount; }
|
Chris@631
|
99 bool getAllowQuoting() const { return m_allowQuoting; }
|
Chris@631
|
100 QChar getSeparator() const {
|
Chris@631
|
101 if (m_separator == "") return ' ';
|
Chris@631
|
102 else return m_separator[0];
|
Chris@631
|
103 }
|
Chris@630
|
104
|
Chris@628
|
105 void setModelType(ModelType t) { m_modelType = t; }
|
Chris@628
|
106 void setTimingType(TimingType t) { m_timingType = t; }
|
Chris@628
|
107 void setTimeUnits(TimeUnits t) { m_timeUnits = t; }
|
Chris@631
|
108 void setSeparator(QChar s) { m_separator = s; }
|
Chris@1047
|
109 void setSampleRate(sv_samplerate_t r) { m_sampleRate = r; }
|
Chris@1009
|
110 void setWindowSize(int s) { m_windowSize = s; }
|
Chris@630
|
111 void setColumnCount(int c) { m_columnCount = c; }
|
Chris@631
|
112 void setAllowQuoting(bool q) { m_allowQuoting = q; }
|
Chris@392
|
113
|
Chris@631
|
114 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; }
|
Chris@629
|
115 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; }
|
Chris@631
|
116
|
Chris@631
|
117 ColumnPurpose getColumnPurpose(int i);
|
Chris@631
|
118 ColumnPurpose getColumnPurpose(int i) const;
|
Chris@631
|
119 void setColumnPurpose(int i, ColumnPurpose p);
|
Chris@392
|
120
|
Chris@629
|
121 // read-only; only valid if format has been guessed:
|
Chris@1510
|
122 const QList<ColumnQualities> &getColumnQualities() const {
|
Chris@1510
|
123 return m_columnQualities;
|
Chris@1510
|
124 }
|
Chris@629
|
125
|
Chris@1511
|
126 bool isColumnNumeric(int i) const {
|
Chris@1511
|
127 return (m_columnQualities.size() > i &&
|
Chris@1511
|
128 m_columnQualities[i] & ColumnNumeric);
|
Chris@1511
|
129 }
|
Chris@1511
|
130
|
Chris@629
|
131 // read-only; only valid if format has been guessed:
|
Chris@1510
|
132 const QList<QStringList> &getExample() const {
|
Chris@1510
|
133 return m_example;
|
Chris@1510
|
134 }
|
Chris@1510
|
135
|
Chris@392
|
136 int getMaxExampleCols() const { return m_maxExampleCols; }
|
Chris@1429
|
137
|
Chris@392
|
138 protected:
|
Chris@628
|
139 ModelType m_modelType;
|
Chris@628
|
140 TimingType m_timingType;
|
Chris@628
|
141 TimeUnits m_timeUnits;
|
Chris@628
|
142 QString m_separator;
|
Chris@1047
|
143 sv_samplerate_t m_sampleRate;
|
Chris@929
|
144 int m_windowSize;
|
Chris@392
|
145
|
Chris@629
|
146 int m_columnCount;
|
Chris@629
|
147 bool m_variableColumnCount;
|
Chris@629
|
148
|
Chris@629
|
149 QList<ColumnQualities> m_columnQualities;
|
Chris@629
|
150 QList<ColumnPurpose> m_columnPurposes;
|
Chris@629
|
151
|
Chris@629
|
152 QList<float> m_prevValues;
|
Chris@629
|
153
|
Chris@629
|
154 bool m_allowQuoting;
|
Chris@392
|
155
|
Chris@392
|
156 QList<QStringList> m_example;
|
Chris@392
|
157 int m_maxExampleCols;
|
Chris@629
|
158
|
Chris@629
|
159 void guessSeparator(QString line);
|
Chris@629
|
160 void guessQualities(QString line, int lineno);
|
Chris@629
|
161 void guessPurposes();
|
Chris@629
|
162
|
Chris@629
|
163 void guessFormatFor_Old(QString path);
|
Chris@629
|
164
|
Chris@392
|
165 };
|
Chris@392
|
166
|
Chris@392
|
167 #endif
|