vtl: mark session dirty if video position-lock or timeline height changes
[ardour.git] / libs / vamp-sdk / vamp-hostsdk / PluginSummarisingAdapter.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     Vamp
5
6     An API for audio analysis and feature extraction plugins.
7
8     Centre for Digital Music, Queen Mary, University of London.
9     Copyright 2006-2009 Chris Cannam and QMUL.
10   
11     Permission is hereby granted, free of charge, to any person
12     obtaining a copy of this software and associated documentation
13     files (the "Software"), to deal in the Software without
14     restriction, including without limitation the rights to use, copy,
15     modify, merge, publish, distribute, sublicense, and/or sell copies
16     of the Software, and to permit persons to whom the Software is
17     furnished to do so, subject to the following conditions:
18
19     The above copyright notice and this permission notice shall be
20     included in all copies or substantial portions of the Software.
21
22     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
26     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30     Except as contained in this notice, the names of the Centre for
31     Digital Music; Queen Mary, University of London; and Chris Cannam
32     shall not be used in advertising or otherwise to promote the sale,
33     use or other dealings in this Software without prior written
34     authorization.
35 */
36
37 #ifndef _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
38 #define _VAMP_PLUGIN_SUMMARISING_ADAPTER_H_
39
40 #include "hostguard.h"
41 #include "PluginWrapper.h"
42
43 #include <set>
44
45 _VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.h)
46
47 namespace Vamp {
48
49 namespace HostExt {
50
51 /**
52  * \class PluginSummarisingAdapter PluginSummarisingAdapter.h <vamp-hostsdk/PluginSummarisingAdapter.h>
53  *
54  * PluginSummarisingAdapter is a Vamp plugin adapter that provides
55  * summarisation methods such as mean and median averages of output
56  * features, for use in any context where an available plugin produces
57  * individual values but the result that is actually needed is some
58  * sort of aggregate.
59  *
60  * To make use of PluginSummarisingAdapter, the host should configure,
61  * initialise and run the plugin through the adapter interface just as
62  * normal.  Then, after the process and getRemainingFeatures methods
63  * have been properly called and processing is complete, the host may
64  * call getSummaryForOutput or getSummaryForAllOutputs to obtain
65  * summarised features: averages, maximum values, etc, depending on
66  * the SummaryType passed to the function.
67  *
68  * By default PluginSummarisingAdapter calculates a single summary of
69  * each output's feature across the whole duration of processed audio.
70  * A host needing summaries of sub-segments of the whole audio may
71  * call setSummarySegmentBoundaries before retrieving the summaries,
72  * providing a list of times such that one summary will be provided
73  * for each segment between two consecutive times.
74  *
75  * PluginSummarisingAdapter is straightforward rather than fast.  It
76  * calculates all of the summary types for all outputs always, and
77  * then returns only the ones that are requested.  It is designed on
78  * the basis that, for most features, summarising and storing
79  * summarised results is far cheaper than calculating the results in
80  * the first place.  If this is not true for your particular feature,
81  * PluginSummarisingAdapter may not be the best approach for you.
82  *
83  * \note This class was introduced in version 2.0 of the Vamp plugin SDK.
84  */
85
86 class PluginSummarisingAdapter : public PluginWrapper
87 {
88 public:
89     /**
90      * Construct a PluginSummarisingAdapter wrapping the given plugin.
91      * The adapter takes ownership of the plugin, which will be
92      * deleted when the adapter is deleted.
93      */
94     PluginSummarisingAdapter(Plugin *plugin); 
95     virtual ~PluginSummarisingAdapter();
96
97     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
98
99     void reset();
100
101     FeatureSet process(const float *const *inputBuffers, RealTime timestamp);
102     FeatureSet getRemainingFeatures();
103
104     typedef std::set<RealTime> SegmentBoundaries;
105
106     /**
107      * Specify a series of segment boundaries, such that one summary
108      * will be returned for each of the contiguous intra-boundary
109      * segments.  This function must be called before
110      * getSummaryForOutput or getSummaryForAllOutputs.
111      * 
112      * Note that you cannot retrieve results with multiple different
113      * segmentations by repeatedly calling this function followed by
114      * one of the getSummary functions.  The summaries are all
115      * calculated at the first call to any getSummary function, and
116      * once the summaries have been calculated, they remain
117      * calculated.
118      */
119     void setSummarySegmentBoundaries(const SegmentBoundaries &);
120
121     enum SummaryType {
122         Minimum            = 0,
123         Maximum            = 1,
124         Mean               = 2,
125         Median             = 3,
126         Mode               = 4,
127         Sum                = 5,
128         Variance           = 6,
129         StandardDeviation  = 7,
130         Count              = 8,
131
132         UnknownSummaryType = 999
133     };
134
135     /**
136      * AveragingMethod indicates how the adapter should handle
137      * average-based summaries of features whose results are not
138      * equally spaced in time.
139      *
140      * If SampleAverage is specified, summary types based on averages
141      * will be calculated by treating each result individually without
142      * regard to its time: for example, the mean will be the sum of
143      * all values divided by the number of values.
144      *
145      * If ContinuousTimeAverage is specified, each feature will be
146      * considered to have a duration, either as specified in the
147      * feature's duration field, or until the following feature: thus,
148      * for example, the mean will be the sum of the products of values
149      * and durations, divided by the total duration.
150      *
151      * Although SampleAverage is useful for many types of feature,
152      * ContinuousTimeAverage is essential for some situations, for
153      * example finding the result that spans the largest proportion of
154      * the input given a feature that emits a new result only when the
155      * value changes (the modal value integrated over time).
156      */
157     enum AveragingMethod {
158         SampleAverage         = 0,
159         ContinuousTimeAverage = 1
160     };
161
162     /**
163      * Return summaries of the features that were returned on the
164      * given output, using the given SummaryType and AveragingMethod.
165      *
166      * The plugin must have been fully run (process() and
167      * getRemainingFeatures() calls all made as appropriate) before
168      * this function is called.
169      */
170     FeatureList getSummaryForOutput(int output,
171                                     SummaryType type,
172                                     AveragingMethod method = SampleAverage);
173
174     /**
175      * Return summaries of the features that were returned on all of
176      * the plugin's outputs, using the given SummaryType and
177      * AveragingMethod.
178      *
179      * The plugin must have been fully run (process() and
180      * getRemainingFeatures() calls all made as appropriate) before
181      * this function is called.
182      */
183     FeatureSet getSummaryForAllOutputs(SummaryType type,
184                                        AveragingMethod method = SampleAverage);
185
186 protected:
187     class Impl;
188     Impl *m_impl;
189 };
190
191 }
192
193 }
194
195 _VAMP_SDK_HOSTSPACE_END(PluginSummarisingAdapter.h)
196
197 #endif