annotate transform/FeatureWriter.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 98339fac0faf
children
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@1581 20 #ifndef SV_FEATURE_WRITER_H
Chris@1581 21 #define SV_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@1129 45 Parameter() : hasArg(false), mandatory(false) { }
Chris@498 46 string name;
Chris@498 47 string description;
Chris@498 48 bool hasArg;
Chris@1129 49 bool mandatory;
Chris@498 50 };
Chris@498 51 typedef vector<Parameter> ParameterList;
Chris@498 52 virtual ParameterList getSupportedParameters() const {
Chris@498 53 return ParameterList();
Chris@498 54 }
Chris@498 55
Chris@930 56 virtual void setParameters(map<string, string> &) {
Chris@498 57 return;
Chris@498 58 }
Chris@498 59
Chris@504 60 struct TrackMetadata {
Chris@504 61 QString title;
Chris@504 62 QString maker;
Chris@1143 63 RealTime duration;
Chris@504 64 };
Chris@930 65 virtual void setTrackMetadata(QString /* trackid */, TrackMetadata) { }
Chris@504 66
Chris@604 67 class FailedToOpenOutputStream : virtual public std::exception
Chris@604 68 {
Chris@604 69 public:
Chris@604 70 FailedToOpenOutputStream(QString trackId, QString transformId) throw() :
Chris@604 71 m_trackId(trackId),
Chris@604 72 m_transformId(transformId)
Chris@604 73 { }
Chris@604 74 virtual ~FailedToOpenOutputStream() throw() { }
Chris@1580 75 const char *what() const throw() override {
Chris@1848 76 static QByteArray msg;
Chris@1848 77 msg = QString("Failed to open output stream for track id \"%1\", transform id \"%2\"")
Chris@1848 78 .arg(m_trackId).arg(m_transformId).toLocal8Bit();
Chris@1848 79 return msg.data();
Chris@604 80 }
Chris@604 81
Chris@604 82 protected:
Chris@604 83 QString m_trackId;
Chris@604 84 QString m_transformId;
Chris@604 85 };
Chris@604 86
Chris@1005 87 /**
Chris@1005 88 * Notify the writer that we are about to start extraction for
Chris@1005 89 * input file N of M (where N is 1..M). May be useful when writing
Chris@1005 90 * multiple outputs into a single file where some syntactic
Chris@1005 91 * element is needed to connect them.
Chris@1005 92 */
Chris@1005 93 virtual void setNofM(int /* N */, int /* M */) { }
Chris@1005 94
Chris@498 95 // may throw FailedToOpenFile or other exceptions
Chris@498 96 virtual void write(QString trackid,
Chris@498 97 const Transform &transform,
Chris@498 98 const Vamp::Plugin::OutputDescriptor &output,
Chris@498 99 const Vamp::Plugin::FeatureList &features,
Chris@498 100 std::string summaryType = "") = 0;
Chris@498 101
Chris@625 102 /**
Chris@625 103 * Throw FailedToOpenOutputStream if we can already tell that we
Chris@625 104 * will be unable to write to the output file. This is called to
Chris@625 105 * test the output stream before processing begins. The writer
Chris@625 106 * may legitimately succeed here but still fail later -- this is
Chris@625 107 * really an optimisation to ensure that easy-to-recognise failure
Chris@625 108 * cases fail early.
Chris@625 109 */
Chris@930 110 virtual void testOutputFile(QString /* trackId */, TransformId) { }
Chris@625 111
Chris@515 112 virtual void flush() { } // whatever the last stream was
Chris@515 113
Chris@498 114 virtual void finish() = 0;
Chris@604 115
Chris@604 116 virtual QString getWriterTag() const = 0;
Chris@498 117 };
Chris@498 118
Chris@498 119 #endif