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