To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / Test.h @ 61:c7fd03f5ae02

History | View | Annotate | Download (4.75 KB)

1 0:f89128a316e7 cannam
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3
/*
4
    Vamp Plugin Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7 42:f1e8e14e9c96 Chris
    Copyright 2009-2014 QMUL.
8 0:f89128a316e7 cannam

9
    This program loads a Vamp plugin and tests its susceptibility to a
10
    number of common pitfalls, including handling of extremes of input
11
    data.  If you can think of any additional useful tests that are
12
    easily added, please send them to me.
13

14
    Permission is hereby granted, free of charge, to any person
15
    obtaining a copy of this software and associated documentation
16
    files (the "Software"), to deal in the Software without
17
    restriction, including without limitation the rights to use, copy,
18
    modify, merge, publish, distribute, sublicense, and/or sell copies
19
    of the Software, and to permit persons to whom the Software is
20
    furnished to do so, subject to the following conditions:
21

22
    The above copyright notice and this permission notice shall be
23
    included in all copies or substantial portions of the Software.
24

25
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
29
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32

33
    Except as contained in this notice, the names of the Centre for
34
    Digital Music; Queen Mary, University of London; and Chris Cannam
35
    shall not be used in advertising or otherwise to promote the sale,
36
    use or other dealings in this Software without prior written
37
    authorization.
38
*/
39
40
#ifndef _TEST_H_
41
#define _TEST_H_
42
43
#include <string>
44
45
#include <vamp-hostsdk/Plugin.h>
46
47
class Test
48
{
49
public:
50
    virtual ~Test();
51 8:3019cb6b538d cannam
52
    enum Option {
53 39:07144cdcbedf Chris
        NoOption           = 0x0,
54
        NonDeterministic   = 0x1,
55
        Verbose            = 0x2,
56
        SingleTest         = 0x4
57 8:3019cb6b538d cannam
    };
58
    typedef int Options;
59 0:f89128a316e7 cannam
60
    class Result {
61
62
    public:
63 3:0f65bb22172b cannam
        enum Code { Success, Note, Warning, Error };
64 0:f89128a316e7 cannam
65 8:3019cb6b538d cannam
        Result() : m_code(Success) { }
66 0:f89128a316e7 cannam
        Result(Code c, std::string m) : m_code(c), m_message(m) { }
67
68 3:0f65bb22172b cannam
        Code code() const { return m_code; }
69
        std::string message() const { return m_message; }
70 8:3019cb6b538d cannam
71 0:f89128a316e7 cannam
    protected:
72
        Code m_code;
73
        std::string m_message;
74
    };
75
76
    static Result success() { return Result(Result::Success, ""); }
77 3:0f65bb22172b cannam
    static Result note(std::string m) { return Result(Result::Note, m); }
78 0:f89128a316e7 cannam
    static Result warning(std::string m) { return Result(Result::Warning, m); }
79
    static Result error(std::string m) { return Result(Result::Error, m); }
80
81
    typedef std::vector<Result> Results;
82
83
    class FailedToLoadPlugin { };
84
85
    // may throw FailedToLoadPlugin
86 8:3019cb6b538d cannam
    virtual Results test(std::string key, Options) = 0;
87 0:f89128a316e7 cannam
88
protected:
89
    Test();
90
91
    // may throw FailedToLoadPlugin
92
    Vamp::Plugin *load(std::string key, float rate = 44100);
93
94 1:d7ef749300ed cannam
    float **createBlock(size_t channels, size_t blocksize);
95
    void destroyBlock(float **blocks, size_t channels);
96
97 3:0f65bb22172b cannam
    float **createTestAudio(size_t channels, size_t blocksize, size_t blocks);
98
    void destroyTestAudio(float **audio, size_t channels);
99
100 4:d8724c5a6d83 cannam
    // use plugin's preferred step/block size, return them:
101 1:d7ef749300ed cannam
    bool initDefaults(Vamp::Plugin *, size_t &channels,
102
                      size_t &step, size_t &block, Results &r);
103
104 4:d8724c5a6d83 cannam
    // use the given step/block size and an adapter:
105 3:0f65bb22172b cannam
    bool initAdapted(Vamp::Plugin *, size_t &channels,
106
                     size_t step, size_t block, Results &r);
107
108 0:f89128a316e7 cannam
    void appendFeatures(Vamp::Plugin::FeatureSet &a,
109
                        const Vamp::Plugin::FeatureSet &b);
110 1:d7ef749300ed cannam
111
    bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf
112 3:0f65bb22172b cannam
113 53:86d8a699dfbe Chris
    bool containsTimestamps(const Vamp::Plugin::FeatureSet &);
114
115 61:c7fd03f5ae02 Chris
    void dumpFeature(const Vamp::Plugin::Feature &, bool showValues,
116
                     const Vamp::Plugin::Feature *other = 0);
117 52:4bd0cd3c60f3 Chris
    void dump(const Vamp::Plugin::FeatureSet &, bool showValues = true);
118
    void dumpTwo(const Result &r,
119
                 const Vamp::Plugin::FeatureSet &,
120
                 const Vamp::Plugin::FeatureSet &);
121
    void dumpDiff(const Result &r,
122
                  const Vamp::Plugin::FeatureSet &,
123
                  const Vamp::Plugin::FeatureSet &);
124 0:f89128a316e7 cannam
};
125
126
extern bool operator==(const Vamp::Plugin::FeatureSet &a,
127
                       const Vamp::Plugin::FeatureSet &b);
128
extern bool operator==(const Vamp::Plugin::FeatureList &a,
129
                       const Vamp::Plugin::FeatureList &b);
130
extern bool operator==(const Vamp::Plugin::Feature &a,
131
                       const Vamp::Plugin::Feature &b);
132
133
#endif