svcore  1.9
FileFeatureWriter.h
Go to the documentation of this file.
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 
00007     Sonic Annotator
00008     A utility for batch feature extraction from audio files.
00009 
00010     Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
00011     Copyright 2007-2008 QMUL.
00012 
00013     This program is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU General Public License as
00015     published by the Free Software Foundation; either version 2 of the
00016     License, or (at your option) any later version.  See the file
00017     COPYING included with this distribution for more information.
00018 */
00019 
00020 #ifndef _FILE_FEATURE_WRITER_H_
00021 #define _FILE_FEATURE_WRITER_H_
00022 
00023 #include <string>
00024 #include <map>
00025 #include <set>
00026 
00027 #include "FeatureWriter.h"
00028 
00029 using std::string;
00030 using std::map;
00031 using std::set;
00032 using std::pair;
00033 
00034 class QTextStream;
00035 class QFile;
00036 
00037 class FileFeatureWriter : public FeatureWriter
00038 {
00039 public:
00040     virtual ~FileFeatureWriter();
00041 
00042     virtual ParameterList getSupportedParameters() const;
00043     virtual void setParameters(map<string, string> &params);
00044 
00045     virtual void testOutputFile(QString trackId, TransformId transformId);
00046     virtual void flush();
00047     virtual void finish();
00048 
00049 protected:
00050     enum FileWriteSupport {
00051         SupportOneFilePerTrackTransform = 1,
00052         SupportOneFilePerTrack = 2,
00053         SupportOneFileTotal = 4
00054     };
00055 
00056     FileFeatureWriter(int support, QString extension);
00057     QTextStream *getOutputStream(QString, TransformId);
00058 
00059     typedef pair<QString, TransformId> TrackTransformPair;
00060     typedef map<TrackTransformPair, QFile *> FileMap;
00061     typedef map<QFile *, QTextStream *> FileStreamMap;
00062     FileMap m_files;
00063     FileStreamMap m_streams;
00064     QTextStream *m_prevstream;
00065 
00066     QString getOutputFilename(QString, TransformId);
00067     QFile *getOutputFile(QString, TransformId);
00068     
00069     // subclass can implement this to be called before file is opened for append
00070     virtual void reviewFileForAppending(QString) { }
00071 
00072     int m_support;
00073     QString m_extension;
00074     QString m_baseDir;
00075     bool m_manyFiles;
00076     QString m_singleFileName;
00077     bool m_stdout;
00078     bool m_append;
00079     bool m_force;
00080 };
00081 
00082 #endif