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 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 _FEATURE_WRITER_H_ 00021 #define _FEATURE_WRITER_H_ 00022 00023 #include <string> 00024 #include <map> 00025 #include <vector> 00026 00027 #include <QString> 00028 00029 #include "Transform.h" 00030 00031 #include <vamp-hostsdk/Plugin.h> 00032 00033 using std::string; 00034 using std::map; 00035 using std::vector; 00036 00037 class FeatureWriter 00038 { 00039 public: 00040 virtual ~FeatureWriter() { } 00041 00042 struct Parameter { // parameter of the writer, not the plugin 00043 string name; 00044 string description; 00045 bool hasArg; 00046 }; 00047 typedef vector<Parameter> ParameterList; 00048 virtual ParameterList getSupportedParameters() const { 00049 return ParameterList(); 00050 } 00051 00052 virtual void setParameters(map<string, string> &) { 00053 return; 00054 } 00055 00056 struct TrackMetadata { 00057 QString title; 00058 QString maker; 00059 }; 00060 virtual void setTrackMetadata(QString /* trackid */, TrackMetadata) { } 00061 00062 class FailedToOpenOutputStream : virtual public std::exception 00063 { 00064 public: 00065 FailedToOpenOutputStream(QString trackId, QString transformId) throw() : 00066 m_trackId(trackId), 00067 m_transformId(transformId) 00068 { } 00069 virtual ~FailedToOpenOutputStream() throw() { } 00070 virtual const char *what() const throw() { 00071 return QString("Failed to open output stream for track id \"%1\", transform id \"%2\"") 00072 .arg(m_trackId).arg(m_transformId).toLocal8Bit().data(); 00073 } 00074 00075 protected: 00076 QString m_trackId; 00077 QString m_transformId; 00078 }; 00079 00080 // may throw FailedToOpenFile or other exceptions 00081 00082 virtual void write(QString trackid, 00083 const Transform &transform, 00084 const Vamp::Plugin::OutputDescriptor &output, 00085 const Vamp::Plugin::FeatureList &features, 00086 std::string summaryType = "") = 0; 00087 00096 virtual void testOutputFile(QString /* trackId */, TransformId) { } 00097 00098 virtual void flush() { } // whatever the last stream was 00099 00100 virtual void finish() = 0; 00101 00102 virtual QString getWriterTag() const = 0; 00103 }; 00104 00105 #endif