annotate osx/include/vamp-sdk/PluginAdapter.h @ 36:55ece8862b6d

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