svcore
1.9
CSVFormat.h
Go to the documentation of this file.
1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3
/*
4
Sonic Visualiser
5
An audio file viewer and annotation editor.
6
Centre for Digital Music, Queen Mary, University of London.
7
This file copyright 2006 Chris Cannam.
8
9
This program is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License as
11
published by the Free Software Foundation; either version 2 of the
12
License, or (at your option) any later version. See the file
13
COPYING included with this distribution for more information.
14
*/
15
16
#ifndef _CSV_FORMAT_H_
17
#define _CSV_FORMAT_H_
18
19
#include <QString>
20
#include <QStringList>
21
22
class
CSVFormat
23
{
24
public
:
25
enum
ModelType
{
26
OneDimensionalModel
,
27
TwoDimensionalModel
,
28
TwoDimensionalModelWithDuration
,
29
TwoDimensionalModelWithDurationAndPitch
,
30
ThreeDimensionalModel
31
};
32
33
enum
TimingType
{
34
ExplicitTiming
,
35
ImplicitTiming
36
};
37
38
enum
TimeUnits
{
39
TimeSeconds
,
40
TimeAudioFrames
,
41
TimeWindows
42
};
43
44
enum
ColumnPurpose
{
45
ColumnUnknown
,
46
ColumnStartTime
,
47
ColumnEndTime
,
48
ColumnDuration
,
49
ColumnValue
,
50
ColumnPitch
,
51
ColumnLabel
52
};
53
54
enum
ColumnQuality
{
55
ColumnNumeric
= 0x1,
56
ColumnIntegral
= 0x2,
57
ColumnIncreasing
= 0x4,
58
ColumnLarge
= 0x8
59
};
60
typedef
unsigned
int
ColumnQualities
;
61
62
CSVFormat
() :
// arbitrary defaults
63
m_modelType
(
TwoDimensionalModel
),
64
m_timingType
(
ExplicitTiming
),
65
m_timeUnits
(
TimeSeconds
),
66
m_separator
(
","
),
67
m_sampleRate
(44100),
68
m_windowSize
(1024),
69
m_columnCount
(0),
70
m_variableColumnCount
(false),
71
m_allowQuoting
(true),
72
m_maxExampleCols
(0)
73
{ }
74
75
CSVFormat
(QString path);
// guess format
76
84
void
guessFormatFor
(QString path);
85
86
ModelType
getModelType
()
const
{
return
m_modelType
; }
87
TimingType
getTimingType
()
const
{
return
m_timingType
; }
88
TimeUnits
getTimeUnits
()
const
{
return
m_timeUnits
; }
89
int
getSampleRate
()
const
{
return
m_sampleRate
; }
90
int
getWindowSize
()
const
{
return
m_windowSize
; }
91
int
getColumnCount
()
const
{
return
m_columnCount
; }
92
bool
getAllowQuoting
()
const
{
return
m_allowQuoting
; }
93
QChar
getSeparator
()
const
{
94
if
(
m_separator
==
""
)
return
' '
;
95
else
return
m_separator
[0];
96
}
97
98
void
setModelType
(
ModelType
t) {
m_modelType
= t; }
99
void
setTimingType
(
TimingType
t) {
m_timingType
= t; }
100
void
setTimeUnits
(
TimeUnits
t) {
m_timeUnits
= t; }
101
void
setSeparator
(QChar s) {
m_separator
= s; }
102
void
setSampleRate
(
int
r) {
m_sampleRate
= r; }
103
void
setWindowSize
(
int
s) {
m_windowSize
= s; }
104
void
setColumnCount
(
int
c) {
m_columnCount
= c; }
105
void
setAllowQuoting
(
bool
q) {
m_allowQuoting
= q; }
106
107
QList<ColumnPurpose>
getColumnPurposes
()
const
{
return
m_columnPurposes
; }
108
void
setColumnPurposes
(QList<ColumnPurpose> cl) {
m_columnPurposes
= cl; }
109
110
ColumnPurpose
getColumnPurpose
(
int
i);
111
ColumnPurpose
getColumnPurpose
(
int
i)
const
;
112
void
setColumnPurpose
(
int
i,
ColumnPurpose
p);
113
114
// read-only; only valid if format has been guessed:
115
QList<ColumnQualities>
getColumnQualities
()
const
{
return
m_columnQualities
; }
116
117
// read-only; only valid if format has been guessed:
118
QList<QStringList>
getExample
()
const
{
return
m_example
; }
119
int
getMaxExampleCols
()
const
{
return
m_maxExampleCols
; }
120
121
protected
:
122
ModelType
m_modelType
;
123
TimingType
m_timingType
;
124
TimeUnits
m_timeUnits
;
125
QString
m_separator
;
126
int
m_sampleRate
;
127
int
m_windowSize
;
128
129
int
m_columnCount
;
130
bool
m_variableColumnCount
;
131
132
QList<ColumnQualities>
m_columnQualities
;
133
QList<ColumnPurpose>
m_columnPurposes
;
134
135
QList<float>
m_prevValues
;
136
137
bool
m_allowQuoting
;
138
139
QList<QStringList>
m_example
;
140
int
m_maxExampleCols
;
141
142
void
guessSeparator
(QString line);
143
void
guessQualities
(QString line,
int
lineno);
144
void
guessPurposes
();
145
146
void
guessFormatFor_Old
(QString path);
147
148
};
149
150
#endif
CSVFormat::CSVFormat
CSVFormat()
Definition:
CSVFormat.h:62
CSVFormat::ImplicitTiming
Definition:
CSVFormat.h:35
CSVFormat::m_maxExampleCols
int m_maxExampleCols
Definition:
CSVFormat.h:140
CSVFormat::guessSeparator
void guessSeparator(QString line)
Definition:
CSVFormat.cpp:86
CSVFormat::getAllowQuoting
bool getAllowQuoting() const
Definition:
CSVFormat.h:92
CSVFormat::ExplicitTiming
Definition:
CSVFormat.h:34
CSVFormat::m_columnCount
int m_columnCount
Definition:
CSVFormat.h:129
CSVFormat::TimingType
TimingType
Definition:
CSVFormat.h:33
CSVFormat::ColumnDuration
Definition:
CSVFormat.h:48
CSVFormat::getExample
QList< QStringList > getExample() const
Definition:
CSVFormat.h:118
CSVFormat::guessFormatFor
void guessFormatFor(QString path)
Guess the format of the given CSV file, setting the fields in this object accordingly.
Definition:
CSVFormat.cpp:38
CSVFormat
Definition:
CSVFormat.h:22
CSVFormat::getColumnPurposes
QList< ColumnPurpose > getColumnPurposes() const
Definition:
CSVFormat.h:107
CSVFormat::TimeWindows
Definition:
CSVFormat.h:41
CSVFormat::TimeUnits
TimeUnits
Definition:
CSVFormat.h:38
CSVFormat::m_windowSize
int m_windowSize
Definition:
CSVFormat.h:127
CSVFormat::m_prevValues
QList< float > m_prevValues
Definition:
CSVFormat.h:135
CSVFormat::TwoDimensionalModelWithDurationAndPitch
Definition:
CSVFormat.h:29
CSVFormat::TimeAudioFrames
Definition:
CSVFormat.h:40
CSVFormat::getColumnPurpose
ColumnPurpose getColumnPurpose(int i)
Definition:
CSVFormat.cpp:303
CSVFormat::setSeparator
void setSeparator(QChar s)
Definition:
CSVFormat.h:101
CSVFormat::ColumnPitch
Definition:
CSVFormat.h:50
CSVFormat::getModelType
ModelType getModelType() const
Definition:
CSVFormat.h:86
CSVFormat::TwoDimensionalModelWithDuration
Definition:
CSVFormat.h:28
CSVFormat::m_columnPurposes
QList< ColumnPurpose > m_columnPurposes
Definition:
CSVFormat.h:133
CSVFormat::guessQualities
void guessQualities(QString line, int lineno)
Definition:
CSVFormat.cpp:99
CSVFormat::ColumnUnknown
Definition:
CSVFormat.h:45
CSVFormat::TimeSeconds
Definition:
CSVFormat.h:39
CSVFormat::ColumnIncreasing
Definition:
CSVFormat.h:57
CSVFormat::setWindowSize
void setWindowSize(int s)
Definition:
CSVFormat.h:103
CSVFormat::getMaxExampleCols
int getMaxExampleCols() const
Definition:
CSVFormat.h:119
CSVFormat::setAllowQuoting
void setAllowQuoting(bool q)
Definition:
CSVFormat.h:105
CSVFormat::guessPurposes
void guessPurposes()
Definition:
CSVFormat.cpp:187
CSVFormat::getSampleRate
int getSampleRate() const
Definition:
CSVFormat.h:89
CSVFormat::ColumnEndTime
Definition:
CSVFormat.h:47
CSVFormat::setSampleRate
void setSampleRate(int r)
Definition:
CSVFormat.h:102
CSVFormat::guessFormatFor_Old
void guessFormatFor_Old(QString path)
CSVFormat::m_modelType
ModelType m_modelType
Definition:
CSVFormat.h:122
CSVFormat::setModelType
void setModelType(ModelType t)
Definition:
CSVFormat.h:98
CSVFormat::setTimingType
void setTimingType(TimingType t)
Definition:
CSVFormat.h:99
CSVFormat::getTimingType
TimingType getTimingType() const
Definition:
CSVFormat.h:87
CSVFormat::getSeparator
QChar getSeparator() const
Definition:
CSVFormat.h:93
CSVFormat::OneDimensionalModel
Definition:
CSVFormat.h:26
CSVFormat::ColumnLabel
Definition:
CSVFormat.h:51
CSVFormat::m_timingType
TimingType m_timingType
Definition:
CSVFormat.h:123
CSVFormat::ColumnQuality
ColumnQuality
Definition:
CSVFormat.h:54
CSVFormat::ColumnIntegral
Definition:
CSVFormat.h:56
CSVFormat::ColumnValue
Definition:
CSVFormat.h:49
CSVFormat::getColumnQualities
QList< ColumnQualities > getColumnQualities() const
Definition:
CSVFormat.h:115
CSVFormat::m_example
QList< QStringList > m_example
Definition:
CSVFormat.h:139
CSVFormat::setColumnCount
void setColumnCount(int c)
Definition:
CSVFormat.h:104
CSVFormat::setColumnPurpose
void setColumnPurpose(int i, ColumnPurpose p)
Definition:
CSVFormat.cpp:321
CSVFormat::ColumnNumeric
Definition:
CSVFormat.h:55
CSVFormat::setColumnPurposes
void setColumnPurposes(QList< ColumnPurpose > cl)
Definition:
CSVFormat.h:108
CSVFormat::ThreeDimensionalModel
Definition:
CSVFormat.h:30
CSVFormat::ColumnLarge
Definition:
CSVFormat.h:58
CSVFormat::getTimeUnits
TimeUnits getTimeUnits() const
Definition:
CSVFormat.h:88
CSVFormat::ColumnPurpose
ColumnPurpose
Definition:
CSVFormat.h:44
CSVFormat::m_allowQuoting
bool m_allowQuoting
Definition:
CSVFormat.h:137
CSVFormat::m_separator
QString m_separator
Definition:
CSVFormat.h:125
CSVFormat::ColumnQualities
unsigned int ColumnQualities
Definition:
CSVFormat.h:60
CSVFormat::setTimeUnits
void setTimeUnits(TimeUnits t)
Definition:
CSVFormat.h:100
CSVFormat::getWindowSize
int getWindowSize() const
Definition:
CSVFormat.h:90
CSVFormat::TwoDimensionalModel
Definition:
CSVFormat.h:27
CSVFormat::m_variableColumnCount
bool m_variableColumnCount
Definition:
CSVFormat.h:130
CSVFormat::ModelType
ModelType
Definition:
CSVFormat.h:25
CSVFormat::m_timeUnits
TimeUnits m_timeUnits
Definition:
CSVFormat.h:124
CSVFormat::getColumnCount
int getColumnCount() const
Definition:
CSVFormat.h:91
CSVFormat::ColumnStartTime
Definition:
CSVFormat.h:46
CSVFormat::m_sampleRate
int m_sampleRate
Definition:
CSVFormat.h:126
CSVFormat::m_columnQualities
QList< ColumnQualities > m_columnQualities
Definition:
CSVFormat.h:132
data
fileio
CSVFormat.h
Generated by
1.8.15