- build fixes for OS X.
[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/parameter.h>
36 #include <ardour/plugin_insert.h>
37
38 #include <vector>
39 #include <set>
40 #include <map>
41
42 using std::string;
43 using std::vector;
44 using std::set;
45 using std::map;
46
47 namespace ARDOUR {
48
49 class AudioEngine;
50 class Session;
51 class BufferSet;
52
53 class Plugin;
54
55 typedef boost::shared_ptr<Plugin> PluginPtr;
56
57 class PluginInfo {
58   public:
59         PluginInfo () { }
60         PluginInfo (const PluginInfo &o)
61                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
62                 unique_id(o.unique_id), path (o.path), index(o.index) {}
63         virtual ~PluginInfo () { }
64
65         string name;
66         string category;
67         ChanCount n_inputs;
68         ChanCount n_outputs;
69         ARDOUR::PluginType type;
70
71         long unique_id;
72
73         virtual PluginPtr load (Session& session) = 0;
74
75   protected:
76         friend class PluginManager;
77         string path;
78         uint32_t index;
79 };
80
81 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
82 typedef std::list<PluginInfoPtr> PluginInfoList;
83
84 class Plugin : public PBD::StatefulDestructible, public Latent
85 {
86   public:
87         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
88         Plugin (const Plugin&);
89         virtual ~Plugin ();
90         
91         struct ParameterDescriptor {
92
93             /* essentially a union of LADSPA and VST info */
94
95             bool integer_step;
96             bool toggled;
97             bool logarithmic;
98             bool sr_dependent;
99             string label;
100             float lower;
101             float upper;
102             float step;
103             float smallstep;
104             float largestep;
105             bool min_unbound;
106             bool max_unbound;
107         };
108
109         virtual uint32_t unique_id() const = 0;
110         virtual const char * label() const = 0;
111         virtual const char * name() const = 0;
112         virtual const char * maker() const = 0;
113         virtual uint32_t parameter_count () const = 0;
114         virtual float default_value (uint32_t port) = 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 (nframes_t nframes) = 0;
122
123         virtual int connect_and_run (BufferSet& bufs, uint32_t& in, uint32_t& out, nframes_t nframes, nframes_t offset) = 0;
124         
125         virtual std::set<Parameter> automatable() const = 0;
126         virtual void store_state (ARDOUR::PluginState&) = 0;
127         virtual void restore_state (ARDOUR::PluginState&) = 0;
128         virtual string describe_parameter (Parameter) = 0;
129         virtual string state_node_name() const = 0;
130         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
131
132         virtual bool parameter_is_audio(uint32_t) const = 0;
133         virtual bool parameter_is_control(uint32_t) const = 0;
134         virtual bool parameter_is_input(uint32_t) const = 0;
135         virtual bool parameter_is_output(uint32_t) const = 0;
136
137         virtual bool save_preset(string name) = 0;
138         virtual bool load_preset (const string preset_label);
139         virtual std::vector<std::string> get_presets();
140
141         virtual bool has_editor() const = 0;
142
143         PluginInfoPtr get_info() { return _info; }
144         void set_info (const PluginInfoPtr 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         friend class PluginInsert;
154         friend struct PluginInsert::PluginControl;
155         virtual void set_parameter (uint32_t which, float val) = 0;
156
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
165 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
166
167 } // namespace ARDOUR
168  
169 #endif /* __ardour_plugin_h__ */