annotate vamp-sdk/PluginAdapter.h @ 277:6d355f1b7eaf

* Patch from Richard Ash to make building the host optional, so you can at least build the SDK even if you don't have libsndfile
author cannam
date Thu, 12 Feb 2009 12:01:58 +0000
parents 521734d2b498
children
rev   line source
cannam@3 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@3 2
cannam@3 3 /*
cannam@3 4 Vamp
cannam@3 5
cannam@3 6 An API for audio analysis and feature extraction plugins.
cannam@3 7
cannam@3 8 Centre for Digital Music, Queen Mary, University of London.
cannam@3 9 Copyright 2006 Chris Cannam.
cannam@3 10
cannam@3 11 Permission is hereby granted, free of charge, to any person
cannam@3 12 obtaining a copy of this software and associated documentation
cannam@3 13 files (the "Software"), to deal in the Software without
cannam@3 14 restriction, including without limitation the rights to use, copy,
cannam@3 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@3 16 of the Software, and to permit persons to whom the Software is
cannam@3 17 furnished to do so, subject to the following conditions:
cannam@3 18
cannam@3 19 The above copyright notice and this permission notice shall be
cannam@3 20 included in all copies or substantial portions of the Software.
cannam@3 21
cannam@3 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@3 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@3 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@6 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@3 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@3 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@3 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@3 29
cannam@3 30 Except as contained in this notice, the names of the Centre for
cannam@3 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@3 32 shall not be used in advertising or otherwise to promote the sale,
cannam@3 33 use or other dealings in this Software without prior written
cannam@3 34 authorization.
cannam@3 35 */
cannam@3 36
cannam@5 37 #ifndef _VAMP_PLUGIN_ADAPTER_H_
cannam@5 38 #define _VAMP_PLUGIN_ADAPTER_H_
cannam@3 39
cannam@230 40 #include <map>
cannam@10 41 #include <vamp/vamp.h>
cannam@10 42
cannam@3 43 #include "Plugin.h"
cannam@3 44
cannam@230 45 #include "plugguard.h"
cannam@233 46 _VAMP_SDK_PLUGSPACE_BEGIN(PluginAdapter.h)
cannam@3 47
cannam@3 48 namespace Vamp {
cannam@3 49
cannam@53 50 /**
cannam@76 51 * \class PluginAdapterBase PluginAdapter.h <vamp-sdk/PluginAdapter.h>
cannam@76 52 *
cannam@53 53 * PluginAdapter and PluginAdapterBase provide a wrapper class that a
cannam@53 54 * plugin library can use to make its C++ Vamp::Plugin objects
cannam@53 55 * available through the Vamp C API.
cannam@53 56 *
cannam@53 57 * Almost all Vamp plugin libraries will want to make use of this. To
cannam@53 58 * do so, all they need to do is declare a PluginAdapter<T> for each
cannam@53 59 * plugin class T in their library. It's very simple, and you need to
cannam@53 60 * know absolutely nothing about how it works in order to use it.
cannam@53 61 * Just cut and paste from an existing plugin's discovery function.
cannam@76 62 * \see vampGetPluginDescriptor
cannam@53 63 */
cannam@53 64
cannam@3 65 class PluginAdapterBase
cannam@3 66 {
cannam@3 67 public:
cannam@3 68 virtual ~PluginAdapterBase();
cannam@53 69
cannam@53 70 /**
cannam@53 71 * Return a VampPluginDescriptor describing the plugin that is
cannam@53 72 * wrapped by this adapter.
cannam@53 73 */
cannam@3 74 const VampPluginDescriptor *getDescriptor();
cannam@3 75
cannam@3 76 protected:
cannam@3 77 PluginAdapterBase();
cannam@3 78
cannam@3 79 virtual Plugin *createPlugin(float inputSampleRate) = 0;
cannam@3 80
cannam@76 81 class Impl;
cannam@76 82 Impl *m_impl;
cannam@3 83 };
cannam@3 84
cannam@53 85 /**
cannam@76 86 * \class PluginAdapter PluginAdapter.h <vamp-sdk/PluginAdapter.h>
cannam@76 87 *
cannam@53 88 * PluginAdapter turns a PluginAdapterBase into a specific wrapper for
cannam@53 89 * a particular plugin implementation.
cannam@53 90 *
cannam@53 91 * See PluginAdapterBase.
cannam@53 92 */
cannam@53 93
cannam@3 94 template <typename P>
cannam@3 95 class PluginAdapter : public PluginAdapterBase
cannam@3 96 {
cannam@3 97 public:
cannam@3 98 PluginAdapter() : PluginAdapterBase() { }
cannam@47 99 virtual ~PluginAdapter() { }
cannam@3 100
cannam@3 101 protected:
cannam@3 102 Plugin *createPlugin(float inputSampleRate) {
cannam@3 103 P *p = new P(inputSampleRate);
cannam@3 104 Plugin *plugin = dynamic_cast<Plugin *>(p);
cannam@3 105 if (!plugin) {
cannam@3 106 std::cerr << "ERROR: PluginAdapter::createPlugin: "
cannam@3 107 << "Template type is not a plugin!"
cannam@3 108 << std::endl;
cannam@3 109 delete p;
cannam@3 110 return 0;
cannam@3 111 }
cannam@3 112 return plugin;
cannam@3 113 }
cannam@3 114 };
cannam@3 115
cannam@3 116 }
cannam@3 117
cannam@233 118 _VAMP_SDK_PLUGSPACE_END(PluginAdapter.h)
cannam@230 119
cannam@3 120 #endif
cannam@3 121