svcore  1.9
FeatureWriter.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 _FEATURE_WRITER_H_
21 #define _FEATURE_WRITER_H_
22 
23 #include <string>
24 #include <map>
25 #include <vector>
26 
27 #include <QString>
28 
29 #include "Transform.h"
30 
31 #include <vamp-hostsdk/Plugin.h>
32 
33 using std::string;
34 using std::map;
35 using std::vector;
36 
38 {
39 public:
40  virtual ~FeatureWriter() { }
41 
42  struct Parameter { // parameter of the writer, not the plugin
43  string name;
44  string description;
45  bool hasArg;
46  };
47  typedef vector<Parameter> ParameterList;
49  return ParameterList();
50  }
51 
52  virtual void setParameters(map<string, string> &) {
53  return;
54  }
55 
56  struct TrackMetadata {
57  QString title;
58  QString maker;
59  };
60  virtual void setTrackMetadata(QString /* trackid */, TrackMetadata) { }
61 
62  class FailedToOpenOutputStream : virtual public std::exception
63  {
64  public:
65  FailedToOpenOutputStream(QString trackId, QString transformId) throw() :
66  m_trackId(trackId),
67  m_transformId(transformId)
68  { }
69  virtual ~FailedToOpenOutputStream() throw() { }
70  virtual const char *what() const throw() {
71  return QString("Failed to open output stream for track id \"%1\", transform id \"%2\"")
72  .arg(m_trackId).arg(m_transformId).toLocal8Bit().data();
73  }
74 
75  protected:
76  QString m_trackId;
77  QString m_transformId;
78  };
79 
80  // may throw FailedToOpenFile or other exceptions
81 
82  virtual void write(QString trackid,
83  const Transform &transform,
84  const Vamp::Plugin::OutputDescriptor &output,
85  const Vamp::Plugin::FeatureList &features,
86  std::string summaryType = "") = 0;
87 
96  virtual void testOutputFile(QString /* trackId */, TransformId) { }
97 
98  virtual void flush() { } // whatever the last stream was
99 
100  virtual void finish() = 0;
101 
102  virtual QString getWriterTag() const = 0;
103 };
104 
105 #endif
virtual void flush()
Definition: FeatureWriter.h:98
virtual const char * what() const
Definition: FeatureWriter.h:70
vector< Parameter > ParameterList
Definition: FeatureWriter.h:47
virtual void write(QString trackid, const Transform &transform, const Vamp::Plugin::OutputDescriptor &output, const Vamp::Plugin::FeatureList &features, std::string summaryType="")=0
virtual void setTrackMetadata(QString, TrackMetadata)
Definition: FeatureWriter.h:60
virtual void testOutputFile(QString, TransformId)
Throw FailedToOpenOutputStream if we can already tell that we will be unable to write to the output f...
Definition: FeatureWriter.h:96
virtual void setParameters(map< string, string > &)
Definition: FeatureWriter.h:52
FailedToOpenOutputStream(QString trackId, QString transformId)
Definition: FeatureWriter.h:65
virtual QString getWriterTag() const =0
virtual void finish()=0
virtual ParameterList getSupportedParameters() const
Definition: FeatureWriter.h:48
virtual ~FeatureWriter()
Definition: FeatureWriter.h:40
QString TransformId
Definition: Transform.h:30