merged with 1697 revision of trunk (which is post-rc1 but pre-rc2
[ardour.git] / libs / ardour / ardour / plugin.h
1 /*
2     Copyright (C) 2000-2006 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_plugin_h__
21 #define __ardour_plugin_h__
22
23 #include <boost/shared_ptr.hpp>
24 #include <sigc++/signal.h>
25
26 #include <pbd/statefuldestructible.h> 
27 #include <pbd/controllable.h>
28
29 #include <jack/types.h>
30 #include <ardour/types.h>
31 #include <ardour/cycles.h>
32
33 #include <vector>
34 #include <set>
35 #include <map>
36
37 using std::string;
38 using std::vector;
39 using std::set;
40 using std::map;
41
42 namespace ARDOUR {
43
44 class AudioEngine;
45 class Session;
46
47 class Plugin;
48
49 typedef boost::shared_ptr<Plugin> PluginPtr;
50
51 class PluginInfo {
52   public:
53         PluginInfo () { }
54         PluginInfo (const PluginInfo &o)
55                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
56                 unique_id(o.unique_id), path (o.path), index(o.index) {}
57         virtual ~PluginInfo () { }
58
59         string name;
60         string category;
61         uint32_t n_inputs;
62         uint32_t n_outputs;
63         ARDOUR::PluginType type;
64
65         long unique_id;
66
67         virtual PluginPtr load (Session& session) = 0;
68
69   protected:
70         friend class PluginManager;
71         string path;
72         uint32_t index;
73 };
74
75 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
76 typedef std::list<PluginInfoPtr> PluginInfoList;
77
78 class Plugin : public PBD::StatefulDestructible
79 {
80   public:
81         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
82         Plugin (const Plugin&);
83         virtual ~Plugin ();
84         
85         struct ParameterDescriptor {
86
87             /* essentially a union of LADSPA and VST info */
88
89             bool integer_step;
90             bool toggled;
91             bool logarithmic;
92             bool sr_dependent;
93             string label;
94             float lower;
95             float upper;
96             float step;
97             float smallstep;
98             float largestep;
99             bool min_unbound;
100             bool max_unbound;
101         };
102
103         virtual uint32_t unique_id() const = 0;
104         virtual const char * label() const = 0;
105         virtual const char * name() const = 0;
106         virtual const char * maker() const = 0;
107         virtual uint32_t parameter_count () const = 0;
108         virtual float default_value (uint32_t port) = 0;
109         virtual nframes_t latency() const = 0;
110         virtual void set_parameter (uint32_t which, float val) = 0;
111         virtual float get_parameter(uint32_t which) const = 0;
112
113         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
114         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
115         virtual void activate () = 0;
116         virtual void deactivate () = 0;
117         virtual void set_block_size (nframes_t nframes) = 0;
118
119         virtual int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset) = 0;
120         virtual std::set<uint32_t> automatable() const = 0;
121         virtual string describe_parameter (uint32_t) = 0;
122         virtual string state_node_name() const = 0;
123         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
124
125         virtual bool parameter_is_audio(uint32_t) const = 0;
126         virtual bool parameter_is_control(uint32_t) const = 0;
127         virtual bool parameter_is_input(uint32_t) const = 0;
128         virtual bool parameter_is_output(uint32_t) const = 0;
129
130         virtual bool save_preset(string name) = 0;
131         virtual bool load_preset (const string preset_label);
132         virtual std::vector<std::string> get_presets();
133
134         virtual bool has_editor() const = 0;
135
136         sigc::signal<void,uint32_t,float> ParameterChanged;
137         
138         PBD::Controllable *get_nth_control (uint32_t);
139
140         PluginInfoPtr get_info() { return _info; }
141         void set_info (const PluginInfoPtr inf) { _info = inf; }
142
143         ARDOUR::AudioEngine& engine() const { return _engine; }
144         ARDOUR::Session& session() const { return _session; }
145
146         void set_cycles (uint32_t c) { _cycles = c; }
147         cycles_t cycles() const { return _cycles; }
148
149   protected:
150         ARDOUR::AudioEngine& _engine;
151         ARDOUR::Session& _session;
152         PluginInfoPtr _info;
153         uint32_t _cycles;
154         map<string,string>       presets;
155         bool save_preset(string name, string domain /* vst, ladspa etc. */);
156
157         void setup_controls ();
158
159         struct PortControllable : public PBD::Controllable {
160             PortControllable (std::string name, Plugin&, uint32_t abs_port_id,
161                               float lower, float upper, bool toggled, bool logarithmic);
162
163             void set_value (float);
164             float get_value () const;
165
166             Plugin& plugin;
167             uint32_t absolute_port;
168             float upper;
169             float lower;
170             float range;
171             bool  toggled;
172             bool  logarithmic;
173         };
174
175         vector<PortControllable*> controls;
176 };
177
178 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
179
180 } // namespace ARDOUR
181  
182 #endif /* __ardour_plugin_h__ */