svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _CSV_FORMAT_H_ 00017 #define _CSV_FORMAT_H_ 00018 00019 #include <QString> 00020 #include <QStringList> 00021 00022 class CSVFormat 00023 { 00024 public: 00025 enum ModelType { 00026 OneDimensionalModel, 00027 TwoDimensionalModel, 00028 TwoDimensionalModelWithDuration, 00029 TwoDimensionalModelWithDurationAndPitch, 00030 ThreeDimensionalModel 00031 }; 00032 00033 enum TimingType { 00034 ExplicitTiming, 00035 ImplicitTiming 00036 }; 00037 00038 enum TimeUnits { 00039 TimeSeconds, 00040 TimeAudioFrames, 00041 TimeWindows 00042 }; 00043 00044 enum ColumnPurpose { 00045 ColumnUnknown, 00046 ColumnStartTime, 00047 ColumnEndTime, 00048 ColumnDuration, 00049 ColumnValue, 00050 ColumnPitch, 00051 ColumnLabel 00052 }; 00053 00054 enum ColumnQuality { 00055 ColumnNumeric = 0x1, 00056 ColumnIntegral = 0x2, 00057 ColumnIncreasing = 0x4, 00058 ColumnLarge = 0x8 00059 }; 00060 typedef unsigned int ColumnQualities; 00061 00062 CSVFormat() : // arbitrary defaults 00063 m_modelType(TwoDimensionalModel), 00064 m_timingType(ExplicitTiming), 00065 m_timeUnits(TimeSeconds), 00066 m_separator(","), 00067 m_sampleRate(44100), 00068 m_windowSize(1024), 00069 m_columnCount(0), 00070 m_variableColumnCount(false), 00071 m_allowQuoting(true), 00072 m_maxExampleCols(0) 00073 { } 00074 00075 CSVFormat(QString path); // guess format 00076 00084 void guessFormatFor(QString path); 00085 00086 ModelType getModelType() const { return m_modelType; } 00087 TimingType getTimingType() const { return m_timingType; } 00088 TimeUnits getTimeUnits() const { return m_timeUnits; } 00089 int getSampleRate() const { return m_sampleRate; } 00090 int getWindowSize() const { return m_windowSize; } 00091 int getColumnCount() const { return m_columnCount; } 00092 bool getAllowQuoting() const { return m_allowQuoting; } 00093 QChar getSeparator() const { 00094 if (m_separator == "") return ' '; 00095 else return m_separator[0]; 00096 } 00097 00098 void setModelType(ModelType t) { m_modelType = t; } 00099 void setTimingType(TimingType t) { m_timingType = t; } 00100 void setTimeUnits(TimeUnits t) { m_timeUnits = t; } 00101 void setSeparator(QChar s) { m_separator = s; } 00102 void setSampleRate(int r) { m_sampleRate = r; } 00103 void setWindowSize(int s) { m_windowSize = s; } 00104 void setColumnCount(int c) { m_columnCount = c; } 00105 void setAllowQuoting(bool q) { m_allowQuoting = q; } 00106 00107 QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; } 00108 void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; } 00109 00110 ColumnPurpose getColumnPurpose(int i); 00111 ColumnPurpose getColumnPurpose(int i) const; 00112 void setColumnPurpose(int i, ColumnPurpose p); 00113 00114 // read-only; only valid if format has been guessed: 00115 QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; } 00116 00117 // read-only; only valid if format has been guessed: 00118 QList<QStringList> getExample() const { return m_example; } 00119 int getMaxExampleCols() const { return m_maxExampleCols; } 00120 00121 protected: 00122 ModelType m_modelType; 00123 TimingType m_timingType; 00124 TimeUnits m_timeUnits; 00125 QString m_separator; 00126 int m_sampleRate; 00127 int m_windowSize; 00128 00129 int m_columnCount; 00130 bool m_variableColumnCount; 00131 00132 QList<ColumnQualities> m_columnQualities; 00133 QList<ColumnPurpose> m_columnPurposes; 00134 00135 QList<float> m_prevValues; 00136 00137 bool m_allowQuoting; 00138 00139 QList<QStringList> m_example; 00140 int m_maxExampleCols; 00141 00142 void guessSeparator(QString line); 00143 void guessQualities(QString line, int lineno); 00144 void guessPurposes(); 00145 00146 void guessFormatFor_Old(QString path); 00147 00148 }; 00149 00150 #endif