use XML state to store processors in mixer (strips) and fixup crash caused by missing...
[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 #include <glibmm/ustring.h>
26
27 #include <pbd/statefuldestructible.h> 
28 #include <pbd/controllable.h>
29
30 #include <jack/types.h>
31 #include <ardour/types.h>
32 #include <ardour/chan_count.h>
33 #include <ardour/plugin_state.h>
34 #include <ardour/cycles.h>
35 #include <ardour/latent.h>
36 #include <ardour/parameter.h>
37 #include <ardour/plugin_insert.h>
38
39 #include <vector>
40 #include <set>
41 #include <map>
42
43 using std::string;
44 using std::vector;
45 using std::set;
46 using std::map;
47
48 namespace ARDOUR {
49
50 class AudioEngine;
51 class Session;
52 class BufferSet;
53
54 class Plugin;
55
56 typedef boost::shared_ptr<Plugin> PluginPtr;
57
58 class PluginInfo {
59   public:
60         PluginInfo () { }
61         PluginInfo (const PluginInfo &o)
62                 : name(o.name), 
63                 category (o.category), 
64                 creator (o.creator),
65                 path (o.path), 
66                 n_inputs(o.n_inputs), 
67                 n_outputs(o.n_outputs),
68                 unique_id(o.unique_id), 
69                 index(o.index) {}
70         virtual ~PluginInfo () { }
71
72         string name;
73         string category;
74         Glib::ustring creator;
75         Glib::ustring path;
76         ChanCount n_inputs;
77         ChanCount n_outputs;
78         ARDOUR::PluginType type;
79         
80         long unique_id;
81
82         virtual PluginPtr load (Session& session) = 0;
83
84   protected:
85         friend class PluginManager;
86         uint32_t index;
87 };
88
89 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
90 typedef std::list<PluginInfoPtr> PluginInfoList;
91
92 class Plugin : public PBD::StatefulDestructible, public Latent
93 {
94   public:
95         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
96         Plugin (const Plugin&);
97         virtual ~Plugin ();
98         
99         struct ParameterDescriptor {
100
101             /* essentially a union of LADSPA and VST info */
102
103             bool integer_step;
104             bool toggled;
105             bool logarithmic;
106             bool sr_dependent;
107             string label;
108             float lower;
109             float upper;
110             float step;
111             float smallstep;
112             float largestep;
113             bool min_unbound;
114             bool max_unbound;
115         };
116
117         virtual uint32_t unique_id() const = 0;
118         virtual const char * label() const = 0;
119         virtual const char * name() const = 0;
120         virtual const char * maker() const = 0;
121         virtual uint32_t parameter_count () const = 0;
122         virtual float default_value (uint32_t port) = 0;
123         virtual float get_parameter(uint32_t which) const = 0;
124
125         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
126         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
127         virtual void activate () = 0;
128         virtual void deactivate () = 0;
129         virtual void set_block_size (nframes_t nframes) = 0;
130
131         virtual int connect_and_run (BufferSet& bufs, uint32_t& in, uint32_t& out, nframes_t nframes, nframes_t offset) = 0;
132         
133         virtual std::set<Parameter> automatable() const = 0;
134         virtual void store_state (ARDOUR::PluginState&) = 0;
135         virtual void restore_state (ARDOUR::PluginState&) = 0;
136         virtual string describe_parameter (Parameter) = 0;
137         virtual string state_node_name() const = 0;
138         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
139
140         virtual bool parameter_is_audio(uint32_t) const = 0;
141         virtual bool parameter_is_control(uint32_t) const = 0;
142         virtual bool parameter_is_input(uint32_t) const = 0;
143         virtual bool parameter_is_output(uint32_t) const = 0;
144
145         virtual bool save_preset(string name) = 0;
146         virtual bool load_preset (const string preset_label);
147         virtual std::vector<std::string> get_presets();
148
149         virtual bool has_editor() const = 0;
150
151         PluginInfoPtr get_info() { return _info; }
152         void set_info (const PluginInfoPtr inf) { _info = inf; }
153
154         ARDOUR::AudioEngine& engine() const { return _engine; }
155         ARDOUR::Session& session() const { return _session; }
156
157         void set_cycles (uint32_t c) { _cycles = c; }
158         cycles_t cycles() const { return _cycles; }
159
160   protected:
161         friend class PluginInsert;
162         friend struct PluginInsert::PluginControl;
163         virtual void set_parameter (uint32_t which, float val) = 0;
164
165         ARDOUR::AudioEngine& _engine;
166         ARDOUR::Session& _session;
167         PluginInfoPtr _info;
168         uint32_t _cycles;
169         map<string,string>       presets;
170         bool save_preset(string name, string domain /* vst, ladspa etc. */);
171 };
172
173 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
174
175 } // namespace ARDOUR
176  
177 #endif /* __ardour_plugin_h__ */