annotate transform/FeatureWriter.h @ 1003:274c4362bda6

Add plugin_version to transform RDF serialisation (if non-empty)
author Chris Cannam
date Wed, 15 Oct 2014 13:06:27 +0100
parents e25dc8d57565
children 6b2a8b34e9d3
rev   line source
Chris@498 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@498 2
Chris@498 3 /*
Chris@498 4 Sonic Visualiser
Chris@498 5 An audio file viewer and annotation editor.
Chris@498 6
Chris@498 7 Sonic Annotator
Chris@498 8 A utility for batch feature extraction from audio files.
Chris@498 9
Chris@498 10 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
Chris@498 11 Copyright 2007-2008 QMUL.
Chris@498 12
Chris@498 13 This program is free software; you can redistribute it and/or
Chris@498 14 modify it under the terms of the GNU General Public License as
Chris@498 15 published by the Free Software Foundation; either version 2 of the
Chris@498 16 License, or (at your option) any later version. See the file
Chris@498 17 COPYING included with this distribution for more information.
Chris@498 18 */
Chris@498 19
Chris@498 20 #ifndef _FEATURE_WRITER_H_
Chris@498 21 #define _FEATURE_WRITER_H_
Chris@498 22
Chris@498 23 #include <string>
Chris@498 24 #include <map>
Chris@498 25 #include <vector>
Chris@498 26
Chris@498 27 #include <QString>
Chris@498 28
Chris@498 29 #include "Transform.h"
Chris@498 30
Chris@498 31 #include <vamp-hostsdk/Plugin.h>
Chris@498 32
Chris@498 33 using std::string;
Chris@498 34 using std::map;
Chris@498 35 using std::vector;
Chris@498 36
Chris@498 37 class FeatureWriter
Chris@498 38 {
Chris@498 39 public:
Chris@498 40 virtual ~FeatureWriter() { }
Chris@498 41
Chris@998 42 virtual string getDescription() const = 0;
Chris@998 43
Chris@498 44 struct Parameter { // parameter of the writer, not the plugin
Chris@498 45 string name;
Chris@498 46 string description;
Chris@498 47 bool hasArg;
Chris@498 48 };
Chris@498 49 typedef vector<Parameter> ParameterList;
Chris@498 50 virtual ParameterList getSupportedParameters() const {
Chris@498 51 return ParameterList();
Chris@498 52 }
Chris@498 53
Chris@930 54 virtual void setParameters(map<string, string> &) {
Chris@498 55 return;
Chris@498 56 }
Chris@498 57
Chris@504 58 struct TrackMetadata {
Chris@504 59 QString title;
Chris@504 60 QString maker;
Chris@504 61 };
Chris@930 62 virtual void setTrackMetadata(QString /* trackid */, TrackMetadata) { }
Chris@504 63
Chris@604 64 class FailedToOpenOutputStream : virtual public std::exception
Chris@604 65 {
Chris@604 66 public:
Chris@604 67 FailedToOpenOutputStream(QString trackId, QString transformId) throw() :
Chris@604 68 m_trackId(trackId),
Chris@604 69 m_transformId(transformId)
Chris@604 70 { }
Chris@604 71 virtual ~FailedToOpenOutputStream() throw() { }
Chris@604 72 virtual const char *what() const throw() {
Chris@604 73 return QString("Failed to open output stream for track id \"%1\", transform id \"%2\"")
Chris@604 74 .arg(m_trackId).arg(m_transformId).toLocal8Bit().data();
Chris@604 75 }
Chris@604 76
Chris@604 77 protected:
Chris@604 78 QString m_trackId;
Chris@604 79 QString m_transformId;
Chris@604 80 };
Chris@604 81
Chris@498 82 // may throw FailedToOpenFile or other exceptions
Chris@498 83
Chris@498 84 virtual void write(QString trackid,
Chris@498 85 const Transform &transform,
Chris@498 86 const Vamp::Plugin::OutputDescriptor &output,
Chris@498 87 const Vamp::Plugin::FeatureList &features,
Chris@498 88 std::string summaryType = "") = 0;
Chris@498 89
Chris@625 90 /**
Chris@625 91 * Throw FailedToOpenOutputStream if we can already tell that we
Chris@625 92 * will be unable to write to the output file. This is called to
Chris@625 93 * test the output stream before processing begins. The writer
Chris@625 94 * may legitimately succeed here but still fail later -- this is
Chris@625 95 * really an optimisation to ensure that easy-to-recognise failure
Chris@625 96 * cases fail early.
Chris@625 97 */
Chris@930 98 virtual void testOutputFile(QString /* trackId */, TransformId) { }
Chris@625 99
Chris@515 100 virtual void flush() { } // whatever the last stream was
Chris@515 101
Chris@498 102 virtual void finish() = 0;
Chris@604 103
Chris@604 104 virtual QString getWriterTag() const = 0;
Chris@498 105 };
Chris@498 106
Chris@498 107 #endif