97708065e404a17f5fb6c77d3f7a41336c2899e5
[ardour.git] / libs / ardour / ardour / plugin.h
1 /*
2     Copyright (C) 2000 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_ladspa_h__
22 #define __ardour_ladspa_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 PluginInfo {
50   public:
51         enum Type {
52                 AudioUnit,
53                 LADSPA,
54                 VST
55         };
56
57         PluginInfo () { };
58         PluginInfo (const PluginInfo &o)
59                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
60                 unique_id(o.unique_id), path (o.path), index(o.index) {}
61         ~PluginInfo () { };
62         string name;
63         string category;
64         uint32_t n_inputs;
65         uint32_t n_outputs;
66         Type type;
67
68         long unique_id;
69
70   private:
71         friend class PluginManager;
72         string path;
73         uint32_t index;
74 };
75
76 class Plugin : public Stateful, public sigc::trackable
77
78 {
79   public:
80         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
81         Plugin (const Plugin&);
82         ~Plugin ();
83         
84         struct ParameterDescriptor {
85
86             /* essentially a union of LADSPA and VST info */
87
88             bool integer_step;
89             bool toggled;
90             bool logarithmic;
91             bool sr_dependent;
92             string label;
93             float lower;
94             float upper;
95             float step;
96             float smallstep;
97             float largestep;
98
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 jack_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 (jack_nframes_t nframes) = 0;
118
119         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;
120         virtual std::set<uint32_t> automatable() const = 0;
121         virtual void store_state (ARDOUR::PluginState&) = 0;
122         virtual void restore_state (ARDOUR::PluginState&) = 0;
123         virtual string describe_parameter (uint32_t) = 0;
124         virtual string state_node_name() const = 0;
125         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
126
127         virtual bool parameter_is_audio(uint32_t) const = 0;
128         virtual bool parameter_is_control(uint32_t) const = 0;
129         virtual bool parameter_is_input(uint32_t) const = 0;
130         virtual bool parameter_is_output(uint32_t) const = 0;
131
132         virtual bool save_preset(string name) = 0;
133         virtual bool load_preset (const string preset_label);
134         virtual std::vector<std::string> get_presets();
135
136         virtual bool has_editor() const = 0;
137
138         sigc::signal<void,uint32_t,float> ParameterChanged;
139         sigc::signal<void,Plugin *> GoingAway;
140         
141         PBD::Controllable *get_nth_control (uint32_t);
142
143         PluginInfo & get_info() { return _info; }
144         void set_info (const PluginInfo &inf) { _info = inf; }
145
146         ARDOUR::AudioEngine& engine() const { return _engine; }
147         ARDOUR::Session& session() const { return _session; }
148
149         void set_cycles (uint32_t c) { _cycles = c; }
150         cycles_t cycles() const { return _cycles; }
151
152   protected:
153         ARDOUR::AudioEngine& _engine;
154         ARDOUR::Session& _session;
155         PluginInfo _info;
156         uint32_t _cycles;
157         map<string,string>       presets;
158         bool save_preset(string name, string domain /* vst, ladspa etc. */);
159
160         void setup_controls ();
161
162         struct PortControllable : public PBD::Controllable {
163             PortControllable (Plugin&, uint32_t abs_port_id,
164                               float lower, float upper, bool toggled, bool logarithmic);
165
166             void set_value (float);
167             float get_value () const;
168
169             Plugin& plugin;
170             uint32_t absolute_port;
171             float upper;
172             float lower;
173             float range;
174             bool  toggled;
175             bool  logarithmic;
176         };
177
178         vector<PortControllable*> controls;
179 };
180
181 /* this is actually defined in plugin_manager.cc */
182
183 boost::shared_ptr<Plugin> find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type);
184
185 } // namespace ARDOUR
186  
187 #endif /* __ardour_plugin_h__ */