1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Sonic Visualiser
5     An audio file viewer and annotation editor.
6     Centre for Digital Music, Queen Mary, University of London.
7     This file copyright 2006 Chris Cannam.
8 
9     This program is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License as
11     published by the Free Software Foundation; either version 2 of the
12     License, or (at your option) any later version.  See the file
13     COPYING included with this distribution for more information.
14 */
15 
16 /*
17    This is a modified version of a source file from the
18    Rosegarden MIDI and audio sequencer and notation editor.
19    This file copyright 2000-2006 Chris Cannam.
20 */
21 
22 #ifndef SV_REALTIME_PLUGIN_FACTORY_H
23 #define SV_REALTIME_PLUGIN_FACTORY_H
24 
25 #include <QString>
26 #include <vector>
27 
28 #include "base/Debug.h"
29 #include "base/BaseTypes.h"
30 
31 class RealTimePluginInstance;
32 
33 class RealTimePluginDescriptor
34 {
35 public:
36     std::string name;
37     std::string label;
38     std::string maker;
39     std::string copyright;
40     std::string category;
41     bool isSynth;
42     unsigned int parameterCount;
43     unsigned int audioInputPortCount;
44     unsigned int audioOutputPortCount;
45     unsigned int controlOutputPortCount;
46     std::vector<std::string> controlOutputPortNames;
47 };
48 
49 class RealTimePluginFactory
50 {
51 public:
52     virtual ~RealTimePluginFactory();
53 
54     static RealTimePluginFactory *instance(QString pluginType);
55     static RealTimePluginFactory *instanceFor(QString identifier);
56     static std::vector<QString> getAllPluginIdentifiers();
57     static void enumerateAllPlugins(std::vector<QString> &);
58 
setSampleRate(sv_samplerate_t sampleRate)59     static void setSampleRate(sv_samplerate_t sampleRate) { m_sampleRate = sampleRate; }
60 
61     /**
62      * Look up the plugin path and find the plugins in it.  Called
63      * automatically after construction of a factory.
64      */
65     virtual void discoverPlugins() = 0;
66 
67     /**
68      * Return a reference to a list of all plugin identifiers that can
69      * be created by this factory.
70      */
71     virtual const std::vector<QString> &getPluginIdentifiers() const = 0;
72 
73     /**
74      * Append to the given list descriptions of all the available
75      * plugins and their ports.  This is in a standard format, see
76      * the LADSPA implementation for details.
77      */
78     virtual void enumeratePlugins(std::vector<QString> &list) = 0;
79 
80     /**
81      * Get some basic information about a plugin (rapidly).
82      */
83     virtual const RealTimePluginDescriptor *getPluginDescriptor(QString identifier) const = 0;
84 
85     /**
86      * Instantiate a plugin.
87      */
88     virtual RealTimePluginInstance *instantiatePlugin(QString identifier,
89                                                       int clientId,
90                                                       int position,
91                                                       sv_samplerate_t sampleRate,
92                                                       int blockSize,
93                                                       int channels) = 0;
94 
95     /**
96      * Get category metadata about a plugin (without instantiating it).
97      */
98     virtual QString getPluginCategory(QString identifier) = 0;
99 
100     /**
101      * Get the full file path (including both directory and filename)
102      * of the library file that provides a given plugin
103      * identifier. Note getPluginIdentifiers() must have been called
104      * before this has access to the necessary information.
105      */
106     virtual QString getPluginLibraryPath(QString identifier) = 0;
107 
108 protected:
RealTimePluginFactory()109     RealTimePluginFactory() { }
110 
111     // for call by RealTimePluginInstance dtor
112     virtual void releasePlugin(RealTimePluginInstance *, QString identifier) = 0;
113     friend class RealTimePluginInstance;
114 
115     static sv_samplerate_t m_sampleRate;
116 };
117 
118 #endif
119