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 SV_FEATURE_WRITER_H
21 #define SV_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  virtual string getDescription() const = 0;
43 
44  struct Parameter { // parameter of the writer, not the plugin
45  Parameter() : hasArg(false), mandatory(false) { }
46  string name;
47  string description;
48  bool hasArg;
49  bool mandatory;
50  };
51  typedef vector<Parameter> ParameterList;
52  virtual ParameterList getSupportedParameters() const {
53  return ParameterList();
54  }
55 
56  virtual void setParameters(map<string, string> &) {
57  return;
58  }
59 
60  struct TrackMetadata {
61  QString title;
62  QString maker;
64  };
65  virtual void setTrackMetadata(QString /* trackid */, TrackMetadata) { }
66 
67  class FailedToOpenOutputStream : virtual public std::exception
68  {
69  public:
70  FailedToOpenOutputStream(QString trackId, QString transformId) throw() :
71  m_trackId(trackId),
72  m_transformId(transformId)
73  { }
74  virtual ~FailedToOpenOutputStream() throw() { }
75  const char *what() const throw() override {
76  static QByteArray msg;
77  msg = QString("Failed to open output stream for track id \"%1\", transform id \"%2\"")
78  .arg(m_trackId).arg(m_transformId).toLocal8Bit();
79  return msg.data();
80  }
81 
82  protected:
83  QString m_trackId;
84  QString m_transformId;
85  };
86 
93  virtual void setNofM(int /* N */, int /* M */) { }
94 
95  // may throw FailedToOpenFile or other exceptions
96  virtual void write(QString trackid,
97  const Transform &transform,
98  const Vamp::Plugin::OutputDescriptor &output,
99  const Vamp::Plugin::FeatureList &features,
100  std::string summaryType = "") = 0;
101 
110  virtual void testOutputFile(QString /* trackId */, TransformId) { }
111 
112  virtual void flush() { } // whatever the last stream was
113 
114  virtual void finish() = 0;
115 
116  virtual QString getWriterTag() const = 0;
117 };
118 
119 #endif
virtual void flush()
vector< Parameter > ParameterList
Definition: FeatureWriter.h:51
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:65
virtual void testOutputFile(QString, TransformId)
Throw FailedToOpenOutputStream if we can already tell that we will be unable to write to the output f...
virtual void setNofM(int, int)
Notify the writer that we are about to start extraction for input file N of M (where N is 1...
Definition: FeatureWriter.h:93
virtual void setParameters(map< string, string > &)
Definition: FeatureWriter.h:56
FailedToOpenOutputStream(QString trackId, QString transformId)
Definition: FeatureWriter.h:70
virtual QString getWriterTag() const =0
virtual string getDescription() const =0
virtual void finish()=0
virtual ~FeatureWriter()
Definition: FeatureWriter.h:40
const char * what() const override
Definition: FeatureWriter.h:75
virtual ParameterList getSupportedParameters() const
Definition: FeatureWriter.h:52
QString TransformId
Definition: Transform.h:30
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:42