annotate Test.h @ 4:d8724c5a6d83

* numbering and clearer output
author cannam
date Tue, 17 Mar 2009 17:11:35 +0000
parents 0f65bb22172b
children 3019cb6b538d
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp Plugin Tester
cannam@0 5 Chris Cannam, cannam@all-day-breakfast.com
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
cannam@0 7 Copyright 2009 QMUL.
cannam@0 8
cannam@0 9 This program loads a Vamp plugin and tests its susceptibility to a
cannam@0 10 number of common pitfalls, including handling of extremes of input
cannam@0 11 data. If you can think of any additional useful tests that are
cannam@0 12 easily added, please send them to me.
cannam@0 13
cannam@0 14 Permission is hereby granted, free of charge, to any person
cannam@0 15 obtaining a copy of this software and associated documentation
cannam@0 16 files (the "Software"), to deal in the Software without
cannam@0 17 restriction, including without limitation the rights to use, copy,
cannam@0 18 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@0 19 of the Software, and to permit persons to whom the Software is
cannam@0 20 furnished to do so, subject to the following conditions:
cannam@0 21
cannam@0 22 The above copyright notice and this permission notice shall be
cannam@0 23 included in all copies or substantial portions of the Software.
cannam@0 24
cannam@0 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@0 26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@0 27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@0 28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@0 29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@0 30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@0 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@0 32
cannam@0 33 Except as contained in this notice, the names of the Centre for
cannam@0 34 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@0 35 shall not be used in advertising or otherwise to promote the sale,
cannam@0 36 use or other dealings in this Software without prior written
cannam@0 37 authorization.
cannam@0 38 */
cannam@0 39
cannam@0 40 #ifndef _TEST_H_
cannam@0 41 #define _TEST_H_
cannam@0 42
cannam@0 43 #include <string>
cannam@0 44
cannam@0 45 #include <vamp-hostsdk/Plugin.h>
cannam@0 46
cannam@0 47 class Test
cannam@0 48 {
cannam@0 49 public:
cannam@0 50 virtual ~Test();
cannam@0 51
cannam@0 52 class Result {
cannam@0 53
cannam@0 54 public:
cannam@3 55 enum Code { Success, Note, Warning, Error };
cannam@0 56
cannam@0 57 Result(Code c, std::string m) : m_code(c), m_message(m) { }
cannam@0 58
cannam@3 59 Code code() const { return m_code; }
cannam@3 60 std::string message() const { return m_message; }
cannam@0 61
cannam@0 62 protected:
cannam@0 63 Code m_code;
cannam@0 64 std::string m_message;
cannam@0 65 };
cannam@0 66
cannam@0 67 static Result success() { return Result(Result::Success, ""); }
cannam@3 68 static Result note(std::string m) { return Result(Result::Note, m); }
cannam@0 69 static Result warning(std::string m) { return Result(Result::Warning, m); }
cannam@0 70 static Result error(std::string m) { return Result(Result::Error, m); }
cannam@0 71
cannam@0 72 typedef std::vector<Result> Results;
cannam@0 73
cannam@0 74 class FailedToLoadPlugin { };
cannam@0 75
cannam@0 76 // may throw FailedToLoadPlugin
cannam@0 77 virtual Results test(std::string key) = 0;
cannam@0 78
cannam@0 79 protected:
cannam@0 80 Test();
cannam@0 81
cannam@0 82 // may throw FailedToLoadPlugin
cannam@0 83 Vamp::Plugin *load(std::string key, float rate = 44100);
cannam@0 84
cannam@1 85 float **createBlock(size_t channels, size_t blocksize);
cannam@1 86 void destroyBlock(float **blocks, size_t channels);
cannam@1 87
cannam@3 88 float **createTestAudio(size_t channels, size_t blocksize, size_t blocks);
cannam@3 89 void destroyTestAudio(float **audio, size_t channels);
cannam@3 90
cannam@4 91 // use plugin's preferred step/block size, return them:
cannam@1 92 bool initDefaults(Vamp::Plugin *, size_t &channels,
cannam@1 93 size_t &step, size_t &block, Results &r);
cannam@1 94
cannam@4 95 // use the given step/block size and an adapter:
cannam@3 96 bool initAdapted(Vamp::Plugin *, size_t &channels,
cannam@3 97 size_t step, size_t block, Results &r);
cannam@3 98
cannam@0 99 void appendFeatures(Vamp::Plugin::FeatureSet &a,
cannam@0 100 const Vamp::Plugin::FeatureSet &b);
cannam@1 101
cannam@1 102 bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf
cannam@3 103
cannam@3 104 void dump(const Vamp::Plugin::FeatureSet &);
cannam@3 105 void dump(const Result &r,
cannam@3 106 const Vamp::Plugin::FeatureSet &,
cannam@3 107 const Vamp::Plugin::FeatureSet &);
cannam@0 108 };
cannam@0 109
cannam@0 110 extern bool operator==(const Vamp::Plugin::FeatureSet &a,
cannam@0 111 const Vamp::Plugin::FeatureSet &b);
cannam@0 112 extern bool operator==(const Vamp::Plugin::FeatureList &a,
cannam@0 113 const Vamp::Plugin::FeatureList &b);
cannam@0 114 extern bool operator==(const Vamp::Plugin::Feature &a,
cannam@0 115 const Vamp::Plugin::Feature &b);
cannam@0 116
cannam@0 117 #endif
cannam@0 118