merge to trunk
[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     $Id$
19 */
20
21 #ifndef __ardour_plugin_h__
22 #define __ardour_plugin_h__
23
24 #include <boost/shared_ptr.hpp>
25 #include <sigc++/signal.h>
26
27 #include <pbd/stateful.h> 
28 #include <pbd/controllable.h>
29
30 #include <jack/types.h>
31 #include <ardour/types.h>
32 #include <ardour/plugin_state.h>
33 #include <ardour/cycles.h>
34
35 #include <vector>
36 #include <set>
37 #include <map>
38
39 using std::string;
40 using std::vector;
41 using std::set;
42 using std::map;
43
44 namespace ARDOUR {
45
46 class AudioEngine;
47 class Session;
48
49 class Plugin;
50
51 typedef boost::shared_ptr<Plugin> PluginPtr;
52
53 class PluginInfo {
54   public:
55         PluginInfo () { }
56         PluginInfo (const PluginInfo &o)
57                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
58                 unique_id(o.unique_id), path (o.path), index(o.index) {}
59         virtual ~PluginInfo () { }
60
61         string name;
62         string category;
63         uint32_t n_inputs;
64         uint32_t n_outputs;
65         ARDOUR::PluginType type;
66
67         long unique_id;
68
69         virtual PluginPtr load (Session& session) = 0;
70
71   protected:
72         friend class PluginManager;
73         string path;
74         uint32_t index;
75 };
76
77 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
78 typedef std::list<PluginInfoPtr> PluginInfoList;
79
80 class Plugin : public Stateful, public sigc::trackable
81
82 {
83   public:
84         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
85         Plugin (const Plugin&);
86         virtual ~Plugin ();
87         
88         struct ParameterDescriptor {
89
90             /* essentially a union of LADSPA and VST info */
91
92             bool integer_step;
93             bool toggled;
94             bool logarithmic;
95             bool sr_dependent;
96             string label;
97             float lower;
98             float upper;
99             float step;
100             float smallstep;
101             float largestep;
102
103                 bool min_unbound;
104                 bool max_unbound;
105         };
106
107         virtual uint32_t unique_id() const = 0;
108         virtual const char * label() const = 0;
109         virtual const char * name() const = 0;
110         virtual const char * maker() const = 0;
111         virtual uint32_t parameter_count () const = 0;
112         virtual float default_value (uint32_t port) = 0;
113         virtual jack_nframes_t latency() const = 0;
114         virtual void set_parameter (uint32_t which, float val) = 0;
115         virtual float get_parameter(uint32_t which) const = 0;
116
117         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
118         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
119         virtual void activate () = 0;
120         virtual void deactivate () = 0;
121         virtual void set_block_size (jack_nframes_t nframes) = 0;
122
123         virtual int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset) = 0;
124         virtual std::set<uint32_t> automatable() const = 0;
125         virtual void store_state (ARDOUR::PluginState&) = 0;
126         virtual void restore_state (ARDOUR::PluginState&) = 0;
127         virtual string describe_parameter (uint32_t) = 0;
128         virtual string state_node_name() const = 0;
129         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
130
131         virtual bool parameter_is_audio(uint32_t) const = 0;
132         virtual bool parameter_is_control(uint32_t) const = 0;
133         virtual bool parameter_is_input(uint32_t) const = 0;
134         virtual bool parameter_is_output(uint32_t) const = 0;
135
136         virtual bool save_preset(string name) = 0;
137         virtual bool load_preset (const string preset_label);
138         virtual std::vector<std::string> get_presets();
139
140         virtual bool has_editor() const = 0;
141
142         sigc::signal<void,uint32_t,float> ParameterChanged;
143         sigc::signal<void,Plugin *> GoingAway;
144         
145         PBD::Controllable *get_nth_control (uint32_t);
146
147         PluginInfoPtr get_info() { return _info; }
148         void set_info (const PluginInfoPtr inf) { _info = inf; }
149
150         ARDOUR::AudioEngine& engine() const { return _engine; }
151         ARDOUR::Session& session() const { return _session; }
152
153         void set_cycles (uint32_t c) { _cycles = c; }
154         cycles_t cycles() const { return _cycles; }
155
156   protected:
157         ARDOUR::AudioEngine& _engine;
158         ARDOUR::Session& _session;
159         PluginInfoPtr _info;
160         uint32_t _cycles;
161         map<string,string>       presets;
162         bool save_preset(string name, string domain /* vst, ladspa etc. */);
163
164         void setup_controls ();
165
166         struct PortControllable : public PBD::Controllable {
167             PortControllable (Plugin&, uint32_t abs_port_id,
168                               float lower, float upper, bool toggled, bool logarithmic);
169
170             void set_value (float);
171             float get_value () const;
172
173             Plugin& plugin;
174             uint32_t absolute_port;
175             float upper;
176             float lower;
177             float range;
178             bool  toggled;
179             bool  logarithmic;
180         };
181
182         vector<PortControllable*> controls;
183 };
184
185 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
186
187 } // namespace ARDOUR
188  
189 #endif /* __ardour_plugin_h__ */