remove StateManager code entirely and more debugging output cruft
[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     $Id$
19 */
20
21 #ifndef __ardour_plugin_h__
22 #define __ardour_plugin_h__
23
24 #include <boost/shared_ptr.hpp>
25 #include <sigc++/signal.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/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 Plugin;
49
50 typedef boost::shared_ptr<Plugin> PluginPtr;
51
52 class PluginInfo {
53   public:
54         PluginInfo () { }
55         PluginInfo (const PluginInfo &o)
56                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
57                 unique_id(o.unique_id), path (o.path), index(o.index) {}
58         virtual ~PluginInfo () { }
59
60         string name;
61         string category;
62         uint32_t n_inputs;
63         uint32_t n_outputs;
64         ARDOUR::PluginType type;
65
66         long unique_id;
67
68         virtual PluginPtr load (Session& session) = 0;
69
70   protected:
71         friend class PluginManager;
72         string path;
73         uint32_t index;
74 };
75
76 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
77 typedef std::list<PluginInfoPtr> PluginInfoList;
78
79 class Plugin : public PBD::StatefulDestructible
80 {
81   public:
82         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
83         Plugin (const Plugin&);
84         virtual ~Plugin ();
85         
86         struct ParameterDescriptor {
87
88             /* essentially a union of LADSPA and VST info */
89
90             bool integer_step;
91             bool toggled;
92             bool logarithmic;
93             bool sr_dependent;
94             string label;
95             float lower;
96             float upper;
97             float step;
98             float smallstep;
99             float largestep;
100             bool min_unbound;
101             bool max_unbound;
102         };
103
104         virtual uint32_t unique_id() const = 0;
105         virtual const char * label() const = 0;
106         virtual const char * name() const = 0;
107         virtual const char * maker() const = 0;
108         virtual uint32_t parameter_count () const = 0;
109         virtual float default_value (uint32_t port) = 0;
110         virtual nframes_t latency() const = 0;
111         virtual void set_parameter (uint32_t which, float val) = 0;
112         virtual float get_parameter(uint32_t which) const = 0;
113
114         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
115         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
116         virtual void activate () = 0;
117         virtual void deactivate () = 0;
118         virtual void set_block_size (nframes_t nframes) = 0;
119
120         virtual int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset) = 0;
121         virtual std::set<uint32_t> automatable() const = 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         
139         PBD::Controllable *get_nth_control (uint32_t);
140
141         PluginInfoPtr get_info() { return _info; }
142         void set_info (const PluginInfoPtr inf) { _info = inf; }
143
144         ARDOUR::AudioEngine& engine() const { return _engine; }
145         ARDOUR::Session& session() const { return _session; }
146
147         void set_cycles (uint32_t c) { _cycles = c; }
148         cycles_t cycles() const { return _cycles; }
149
150   protected:
151         ARDOUR::AudioEngine& _engine;
152         ARDOUR::Session& _session;
153         PluginInfoPtr _info;
154         uint32_t _cycles;
155         map<string,string>       presets;
156         bool save_preset(string name, string domain /* vst, ladspa etc. */);
157
158         void setup_controls ();
159
160         struct PortControllable : public PBD::Controllable {
161             PortControllable (std::string name, Plugin&, uint32_t abs_port_id,
162                               float lower, float upper, bool toggled, bool logarithmic);
163
164             void set_value (float);
165             float get_value () const;
166
167             Plugin& plugin;
168             uint32_t absolute_port;
169             float upper;
170             float lower;
171             float range;
172             bool  toggled;
173             bool  logarithmic;
174         };
175
176         vector<PortControllable*> controls;
177 };
178
179 PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType);
180
181 } // namespace ARDOUR
182  
183 #endif /* __ardour_plugin_h__ */