annotate host/simplehost.cpp @ 1:ad9aa1881a70

* Add most basic load-library-and-list-plugins host
author cannam
date Fri, 31 Mar 2006 15:00:29 +0000
parents
children 8f10d35a4090
rev   line source
cannam@1 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@1 2
cannam@1 3 /*
cannam@1 4 Vamp
cannam@1 5
cannam@1 6 An API for audio analysis and feature extraction plugins.
cannam@1 7
cannam@1 8 Centre for Digital Music, Queen Mary, University of London.
cannam@1 9 Copyright 2006 Chris Cannam.
cannam@1 10
cannam@1 11 Permission is hereby granted, free of charge, to any person
cannam@1 12 obtaining a copy of this software and associated documentation
cannam@1 13 files (the "Software"), to deal in the Software without
cannam@1 14 restriction, including without limitation the rights to use, copy,
cannam@1 15 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@1 16 of the Software, and to permit persons to whom the Software is
cannam@1 17 furnished to do so, subject to the following conditions:
cannam@1 18
cannam@1 19 The above copyright notice and this permission notice shall be
cannam@1 20 included in all copies or substantial portions of the Software.
cannam@1 21
cannam@1 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@1 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@1 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@1 25 NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR
cannam@1 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@1 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@1 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@1 29
cannam@1 30 Except as contained in this notice, the names of the Centre for
cannam@1 31 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@1 32 shall not be used in advertising or otherwise to promote the sale,
cannam@1 33 use or other dealings in this Software without prior written
cannam@1 34 authorization.
cannam@1 35 */
cannam@1 36
cannam@1 37 #include <iostream>
cannam@1 38
cannam@1 39 #include "vamp.h"
cannam@1 40
cannam@1 41 #include "PluginHostAdapter.h"
cannam@1 42
cannam@1 43 #include "system.h"
cannam@1 44
cannam@1 45 /*
cannam@1 46 A very simple Vamp plugin host. So far all this does is load the
cannam@1 47 plugin library given on the command line and dump out the names of
cannam@1 48 the plugins found in it.
cannam@1 49 */
cannam@1 50
cannam@1 51 int main(int argc, char **argv)
cannam@1 52 {
cannam@1 53 if (argc != 2) {
cannam@1 54 std::cerr << "Usage: " << argv[0] << " pluginlibrary.so" << std::endl;
cannam@1 55 return 2;
cannam@1 56 }
cannam@1 57
cannam@1 58 std::cerr << std::endl << argv[0] << ": Running..." << std::endl;
cannam@1 59
cannam@1 60 std::string soname = argv[1];
cannam@1 61
cannam@1 62 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
cannam@1 63
cannam@1 64 if (!libraryHandle) {
cannam@1 65 std::cerr << argv[0] << ": Failed to open plugin library "
cannam@1 66 << soname << std::endl;
cannam@1 67 return 1;
cannam@1 68 }
cannam@1 69
cannam@1 70 std::cout << argv[0] << ": Opened plugin library " << soname << std::endl;
cannam@1 71
cannam@1 72 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
cannam@1 73 DLSYM(libraryHandle, "vampGetPluginDescriptor");
cannam@1 74
cannam@1 75 if (!fn) {
cannam@1 76 std::cerr << argv[0] << ": No Vamp descriptor function in library "
cannam@1 77 << soname << std::endl;
cannam@1 78 DLCLOSE(libraryHandle);
cannam@1 79 return 1;
cannam@1 80 }
cannam@1 81
cannam@1 82 std::cout << argv[0] << ": Found plugin descriptor function" << std::endl;
cannam@1 83
cannam@1 84 int index = 0;
cannam@1 85 const VampPluginDescriptor *descriptor = 0;
cannam@1 86
cannam@1 87 while ((descriptor = fn(index))) {
cannam@1 88
cannam@1 89 Vamp::PluginHostAdapter adapter(descriptor, 48000);
cannam@1 90 std::cout << argv[0] << ": Plugin " << (index+1)
cannam@1 91 << " is \"" << adapter.getName() << "\"" << std::endl;
cannam@1 92
cannam@1 93 ++index;
cannam@1 94 }
cannam@1 95
cannam@1 96 std::cout << argv[0] << ": Done\n" << std::endl;
cannam@1 97
cannam@1 98 DLCLOSE(libraryHandle);
cannam@1 99 return 0;
cannam@1 100 }
cannam@1 101