Another not-quite-there-but-better commit.
[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/chan_count.h>
32 #include <ardour/plugin_state.h>
33 #include <ardour/cycles.h>
34 #include <ardour/latent.h>
35 #include <ardour/param_id.h>
36
37 #include <vector>
38 #include <set>
39 #include <map>
40
41 using std::string;
42 using std::vector;
43 using std::set;
44 using std::map;
45
46 namespace ARDOUR {
47
48 class AudioEngine;
49 class Session;
50 class BufferSet;
51
52 class Plugin;
53
54 typedef boost::shared_ptr<Plugin> PluginPtr;
55
56 class PluginInfo {
57   public:
58         PluginInfo () { }
59         PluginInfo (const PluginInfo &o)
60                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
61                 unique_id(o.unique_id), path (o.path), index(o.index) {}
62         virtual ~PluginInfo () { }
63
64         string name;
65         string category;
66         ChanCount n_inputs;
67         ChanCount n_outputs;
68         ARDOUR::PluginType type;
69
70         long unique_id;
71
72         virtual PluginPtr load (Session& session) = 0;
73
74   protected:
75         friend class PluginManager;
76         string path;
77         uint32_t index;
78 };
79
80 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
81 typedef std::list<PluginInfoPtr> PluginInfoList;
82
83 class Plugin : public PBD::StatefulDestructible, public Latent
84 {
85   public:
86         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
87         Plugin (const Plugin&);
88         virtual ~Plugin ();
89         
90         struct ParameterDescriptor {
91
92             /* essentially a union of LADSPA and VST info */
93
94             bool integer_step;
95             bool toggled;
96             bool logarithmic;
97             bool sr_dependent;
98             string label;
99             float lower;
100             float upper;
101             float step;
102             float smallstep;
103             float largestep;
104             bool min_unbound;
105             bool max_unbound;
106         };
107
108         virtual uint32_t unique_id() const = 0;
109         virtual const char * label() const = 0;
110         virtual const char * name() const = 0;
111         virtual const char * maker() const = 0;
112         virtual uint32_t parameter_count () const = 0;
113         virtual float default_value (uint32_t port) = 0;
114         virtual float get_parameter(uint32_t which) const = 0;
115
116         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
117         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
118         virtual void activate () = 0;
119         virtual void deactivate () = 0;
120         virtual void set_block_size (nframes_t nframes) = 0;
121
122         virtual int connect_and_run (BufferSet& bufs, uint32_t& in, uint32_t& out, nframes_t nframes, nframes_t offset) = 0;
123         
124         virtual std::set<ParamID> automatable() const = 0;
125         virtual void store_state (ARDOUR::PluginState&) = 0;
126         virtual void restore_state (ARDOUR::PluginState&) = 0;
127         virtual string describe_parameter (ParamID) = 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         PluginInfoPtr get_info() { return _info; }
143         void set_info (const PluginInfoPtr inf) { _info = inf; }
144
145         ARDOUR::AudioEngine& engine() const { return _engine; }
146         ARDOUR::Session& session() const { return _session; }
147
148         void set_cycles (uint32_t c) { _cycles = c; }
149         cycles_t cycles() const { return _cycles; }
150
151   protected:
152         friend class PluginInsert;
153         virtual void set_parameter (uint32_t which, float val) = 0;
154
155         ARDOUR::AudioEngine& _engine;
156         ARDOUR::Session& _session;
157         PluginInfoPtr _info;
158         uint32_t _cycles;
159         map<string,string>       presets;
160         bool save_preset(string name, string domain /* vst, ladspa etc. */);
161 };
162
163 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
164
165 } // namespace ARDOUR
166  
167 #endif /* __ardour_plugin_h__ */