annotate examples/vamp-test-plugin/vamp-test-plugin.cpp @ 65:4a5295555574

Move examples to their own subdirs, tidy up a bit
author Chris Cannam
date Fri, 11 Nov 2016 17:02:33 +0000
parents examples/vamp-test-plugin.cpp@10d4f117a9a8
children
rev   line source
Chris@20 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@20 2 /*
Chris@20 3 Vamp Test Plugin
Chris@20 4 Copyright (c) 2013-2016 Queen Mary, University of London
Chris@20 5
Chris@20 6 Permission is hereby granted, free of charge, to any person
Chris@20 7 obtaining a copy of this software and associated documentation
Chris@20 8 files (the "Software"), to deal in the Software without
Chris@20 9 restriction, including without limitation the rights to use, copy,
Chris@20 10 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@20 11 of the Software, and to permit persons to whom the Software is
Chris@20 12 furnished to do so, subject to the following conditions:
Chris@20 13
Chris@20 14 The above copyright notice and this permission notice shall be
Chris@20 15 included in all copies or substantial portions of the Software.
Chris@20 16
Chris@20 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@20 18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@20 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@20 20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@20 21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@20 22 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@20 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@20 24
Chris@20 25 Except as contained in this notice, the names of the Centre for
Chris@20 26 Digital Music and Queen Mary, University of London shall not be
Chris@20 27 used in advertising or otherwise to promote the sale, use or other
Chris@20 28 dealings in this Software without prior written authorization.
Chris@20 29 */
Chris@20 30
Chris@65 31 #include "PiperExport.h"
Chris@20 32
Chris@20 33 #include "VampTestPlugin.h"
Chris@20 34
Chris@57 35 using piper_vamp_js::PiperAdapter;
Chris@57 36 using piper_vamp_js::PiperAdapterBase;
Chris@57 37 using piper_vamp_js::PiperPluginLibrary;
Chris@20 38
Chris@20 39 static std::string soname("vamp-test-plugin");
Chris@20 40
Chris@65 41 /*
Chris@65 42 This is an example of a library that exports more than one "plugin"
Chris@65 43 from a single C++ class. The VampTestPlugin class is constructed
Chris@65 44 with an argument that determines whether it is a time- or
Chris@65 45 frequency-domain plugin, and the library offers both.
Chris@65 46
Chris@65 47 Where normally a library that offered two plugins would have two
Chris@65 48 static PiperAdapters specialised with the two plugin classes, here
Chris@65 49 we want two static PiperAdapters specialised with the same class
Chris@65 50 but different constructor arguments. This is one way to do that,
Chris@65 51 taking advantage of the fact that PiperAdapterBase exposes
Chris@65 52 createPlugin as a virtual method.
Chris@65 53
Chris@65 54 Note that a very similar mechanism is used in the standard Vamp
Chris@65 55 version of this plugin library.
Chris@65 56 */
Chris@65 57
Chris@43 58 class Adapter : public PiperAdapterBase<VampTestPlugin>
Chris@20 59 {
Chris@20 60 public:
Chris@20 61 Adapter(bool freq) :
Chris@43 62 PiperAdapterBase<VampTestPlugin>(soname),
Chris@20 63 m_freq(freq) { }
Chris@20 64
Chris@20 65 protected:
Chris@20 66 bool m_freq;
Chris@20 67
Chris@20 68 Vamp::Plugin *createPlugin(float inputSampleRate) const {
Chris@20 69 return new VampTestPlugin(inputSampleRate, m_freq);
Chris@20 70 }
Chris@20 71 };
Chris@20 72
Chris@20 73 static Adapter timeAdapter(false);
Chris@20 74 static Adapter freqAdapter(true);
Chris@20 75
Chris@43 76 static PiperPluginLibrary library({
Chris@20 77 &timeAdapter,
Chris@20 78 &freqAdapter
Chris@20 79 });
Chris@20 80
Chris@65 81 PIPER_EXPORT_LIBRARY(library);
Chris@20 82