FileFeatureWriter.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 
7  Sonic Annotator
8  A utility for batch feature extraction from audio files.
9 
10  Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
11  Copyright 2007-2008 QMUL.
12 
13  This program is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version. See the file
17  COPYING included with this distribution for more information.
18 */
19 
20 #ifndef SV_FILE_FEATURE_WRITER_H
21 #define SV_FILE_FEATURE_WRITER_H
22 
23 #include <string>
24 #include <map>
25 #include <set>
26 
27 #include "FeatureWriter.h"
28 
29 using std::string;
30 using std::map;
31 using std::set;
32 using std::pair;
33 
34 class QTextStream;
35 class QTextCodec;
36 class QFile;
37 
39 {
40 public:
41  virtual ~FileFeatureWriter();
42 
43  ParameterList getSupportedParameters() const override;
44  void setParameters(map<string, string> &params) override;
45 
46  void testOutputFile(QString trackId, TransformId transformId) override;
47  void flush() override;
48  void finish() override;
49 
50 protected:
56  };
57 
58  FileFeatureWriter(int support, QString extension);
59  QTextStream *getOutputStream(QString, TransformId, QTextCodec *);
60 
61  typedef pair<QString, TransformId> TrackTransformPair;
62  typedef map<TrackTransformPair, QString> FileNameMap;
63  typedef map<TrackTransformPair, QFile *> FileMap;
64  typedef map<QFile *, QTextStream *> FileStreamMap;
65  FileMap m_files;
66  FileNameMap m_filenames;
67  FileStreamMap m_streams;
68  QTextStream *m_prevstream;
69 
70  TrackTransformPair getFilenameKey(QString, TransformId);
71 
72  // Come up with a suitable output filename for the given track ID -
73  // transform ID combo. Fail if it already exists, etc.
74  QString createOutputFilename(QString, TransformId);
75 
76  // Look up and return the output filename for the given track ID -
77  // transform ID combo.
78  QString getOutputFilename(QString, TransformId);
79 
80  // Look up and return the output file handle for the given track
81  // ID - transform ID combo. Return 0 if it could not be opened.
82  QFile *getOutputFile(QString, TransformId);
83 
84  // subclass can implement this to be called before file is opened for append
85  virtual void reviewFileForAppending(QString) { }
86 
87  int m_support;
88  QString m_extension;
89  QString m_baseDir;
92  bool m_stdout;
93  bool m_append;
94  bool m_force;
95 };
96 
97 #endif
QString createOutputFilename(QString, TransformId)
map< TrackTransformPair, QString > FileNameMap
FileNameMap m_filenames
QFile * getOutputFile(QString, TransformId)
QTextStream * m_prevstream
FileStreamMap m_streams
QTextStream * getOutputStream(QString, TransformId, QTextCodec *)
vector< Parameter > ParameterList
Definition: FeatureWriter.h:51
void testOutputFile(QString trackId, TransformId transformId) override
Throw FailedToOpenOutputStream if we can already tell that we will be unable to write to the output f...
map< QFile *, QTextStream * > FileStreamMap
void setParameters(map< string, string > &params) override
TrackTransformPair getFilenameKey(QString, TransformId)
map< TrackTransformPair, QFile * > FileMap
void flush() override
void finish() override
pair< QString, TransformId > TrackTransformPair
QString getOutputFilename(QString, TransformId)
FileFeatureWriter(int support, QString extension)
ParameterList getSupportedParameters() const override
QString TransformId
Definition: Transform.h:30
virtual void reviewFileForAppending(QString)