annotate data/fileio/CSVFormat.h @ 1478:8ff5505ad28d plugin-path-config

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