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@392
|
16 #ifndef _CSV_FORMAT_H_
|
Chris@392
|
17 #define _CSV_FORMAT_H_
|
Chris@392
|
18
|
Chris@392
|
19 #include <QString>
|
Chris@392
|
20 #include <QStringList>
|
Chris@392
|
21
|
Chris@392
|
22 class CSVFormat
|
Chris@392
|
23 {
|
Chris@392
|
24 public:
|
Chris@392
|
25 enum ModelType {
|
Chris@392
|
26 OneDimensionalModel,
|
Chris@392
|
27 TwoDimensionalModel,
|
Chris@628
|
28 TwoDimensionalModelWithDuration,
|
Chris@897
|
29 TwoDimensionalModelWithDurationAndPitch,
|
Chris@392
|
30 ThreeDimensionalModel
|
Chris@392
|
31 };
|
Chris@392
|
32
|
Chris@392
|
33 enum TimingType {
|
Chris@392
|
34 ExplicitTiming,
|
Chris@392
|
35 ImplicitTiming
|
Chris@392
|
36 };
|
Chris@628
|
37
|
Chris@392
|
38 enum TimeUnits {
|
Chris@392
|
39 TimeSeconds,
|
Chris@990
|
40 TimeMilliseconds,
|
Chris@392
|
41 TimeAudioFrames,
|
Chris@990
|
42 TimeWindows,
|
Chris@392
|
43 };
|
Chris@392
|
44
|
Chris@629
|
45 enum ColumnPurpose {
|
Chris@629
|
46 ColumnUnknown,
|
Chris@629
|
47 ColumnStartTime,
|
Chris@629
|
48 ColumnEndTime,
|
Chris@629
|
49 ColumnDuration,
|
Chris@629
|
50 ColumnValue,
|
Chris@897
|
51 ColumnPitch,
|
Chris@629
|
52 ColumnLabel
|
Chris@629
|
53 };
|
Chris@629
|
54
|
Chris@629
|
55 enum ColumnQuality {
|
Chris@1021
|
56 ColumnNumeric = 1,
|
Chris@1021
|
57 ColumnIntegral = 2,
|
Chris@1021
|
58 ColumnIncreasing = 4,
|
Chris@1021
|
59 ColumnLarge = 8,
|
Chris@1021
|
60 ColumnNearEmpty = 16,
|
Chris@629
|
61 };
|
Chris@629
|
62 typedef unsigned int ColumnQualities;
|
Chris@392
|
63
|
Chris@392
|
64 CSVFormat() : // arbitrary defaults
|
Chris@392
|
65 m_modelType(TwoDimensionalModel),
|
Chris@392
|
66 m_timingType(ExplicitTiming),
|
Chris@392
|
67 m_timeUnits(TimeSeconds),
|
Chris@392
|
68 m_separator(","),
|
Chris@392
|
69 m_sampleRate(44100),
|
Chris@392
|
70 m_windowSize(1024),
|
Chris@629
|
71 m_columnCount(0),
|
Chris@629
|
72 m_variableColumnCount(false),
|
Chris@629
|
73 m_allowQuoting(true),
|
Chris@629
|
74 m_maxExampleCols(0)
|
Chris@392
|
75 { }
|
Chris@629
|
76
|
Chris@629
|
77 CSVFormat(QString path); // guess format
|
Chris@629
|
78
|
Chris@629
|
79 /**
|
Chris@629
|
80 * Guess the format of the given CSV file, setting the fields in
|
Chris@629
|
81 * this object accordingly. If the current separator is the empty
|
Chris@629
|
82 * string, the separator character will also be guessed; otherwise
|
Chris@629
|
83 * the current separator will be used. The other properties of
|
Chris@629
|
84 * this object will be set according to guesses from the file.
|
Chris@629
|
85 */
|
Chris@629
|
86 void guessFormatFor(QString path);
|
Chris@628
|
87
|
Chris@628
|
88 ModelType getModelType() const { return m_modelType; }
|
Chris@628
|
89 TimingType getTimingType() const { return m_timingType; }
|
Chris@628
|
90 TimeUnits getTimeUnits() const { return m_timeUnits; }
|
Chris@929
|
91 int getSampleRate() const { return m_sampleRate; }
|
Chris@929
|
92 int getWindowSize() const { return m_windowSize; }
|
Chris@630
|
93 int getColumnCount() const { return m_columnCount; }
|
Chris@631
|
94 bool getAllowQuoting() const { return m_allowQuoting; }
|
Chris@631
|
95 QChar getSeparator() const {
|
Chris@631
|
96 if (m_separator == "") return ' ';
|
Chris@631
|
97 else return m_separator[0];
|
Chris@631
|
98 }
|
Chris@630
|
99
|
Chris@628
|
100 void setModelType(ModelType t) { m_modelType = t; }
|
Chris@628
|
101 void setTimingType(TimingType t) { m_timingType = t; }
|
Chris@628
|
102 void setTimeUnits(TimeUnits t) { m_timeUnits = t; }
|
Chris@631
|
103 void setSeparator(QChar s) { m_separator = s; }
|
Chris@1009
|
104 void setSampleRate(int r) { m_sampleRate = r; }
|
Chris@1009
|
105 void setWindowSize(int s) { m_windowSize = s; }
|
Chris@630
|
106 void setColumnCount(int c) { m_columnCount = c; }
|
Chris@631
|
107 void setAllowQuoting(bool q) { m_allowQuoting = q; }
|
Chris@392
|
108
|
Chris@631
|
109 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; }
|
Chris@629
|
110 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; }
|
Chris@631
|
111
|
Chris@631
|
112 ColumnPurpose getColumnPurpose(int i);
|
Chris@631
|
113 ColumnPurpose getColumnPurpose(int i) const;
|
Chris@631
|
114 void setColumnPurpose(int i, ColumnPurpose p);
|
Chris@392
|
115
|
Chris@629
|
116 // read-only; only valid if format has been guessed:
|
Chris@629
|
117 QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; }
|
Chris@629
|
118
|
Chris@629
|
119 // read-only; only valid if format has been guessed:
|
Chris@392
|
120 QList<QStringList> getExample() const { return m_example; }
|
Chris@392
|
121 int getMaxExampleCols() const { return m_maxExampleCols; }
|
Chris@631
|
122
|
Chris@392
|
123 protected:
|
Chris@628
|
124 ModelType m_modelType;
|
Chris@628
|
125 TimingType m_timingType;
|
Chris@628
|
126 TimeUnits m_timeUnits;
|
Chris@628
|
127 QString m_separator;
|
Chris@929
|
128 int m_sampleRate;
|
Chris@929
|
129 int m_windowSize;
|
Chris@392
|
130
|
Chris@629
|
131 int m_columnCount;
|
Chris@629
|
132 bool m_variableColumnCount;
|
Chris@629
|
133
|
Chris@629
|
134 QList<ColumnQualities> m_columnQualities;
|
Chris@629
|
135 QList<ColumnPurpose> m_columnPurposes;
|
Chris@629
|
136
|
Chris@629
|
137 QList<float> m_prevValues;
|
Chris@629
|
138
|
Chris@629
|
139 bool m_allowQuoting;
|
Chris@392
|
140
|
Chris@392
|
141 QList<QStringList> m_example;
|
Chris@392
|
142 int m_maxExampleCols;
|
Chris@629
|
143
|
Chris@629
|
144 void guessSeparator(QString line);
|
Chris@629
|
145 void guessQualities(QString line, int lineno);
|
Chris@629
|
146 void guessPurposes();
|
Chris@629
|
147
|
Chris@629
|
148 void guessFormatFor_Old(QString path);
|
Chris@629
|
149
|
Chris@392
|
150 };
|
Chris@392
|
151
|
Chris@392
|
152 #endif
|