Merge with 2.0-ongoing R2885.
[ardour.git] / libs / ardour / ardour / ladspa_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_ladspa_plugin_h__
21 #define __ardour_ladspa_plugin_h__
22
23 #include <list>
24 #include <set>
25 #include <vector>
26 #include <string>
27 #include <dlfcn.h>
28
29 #include <sigc++/signal.h>
30
31 #include <pbd/stateful.h> 
32
33 #include <jack/types.h>
34 #include <ardour/ladspa.h>
35 #include <ardour/plugin.h>
36 #include <ardour/ladspa_plugin.h>
37
38 using std::string;
39 using std::vector;
40 using std::list;
41
42 namespace ARDOUR {
43 class AudioEngine;
44 class Session;
45
46 class LadspaPlugin : public ARDOUR::Plugin
47 {
48   public:
49         LadspaPlugin (void *module, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, nframes_t sample_rate);
50         LadspaPlugin (const LadspaPlugin &);
51         ~LadspaPlugin ();
52
53         /* Plugin interface */
54         
55         std::string unique_id() const;
56         const char* label() const           { return _descriptor->Label; }
57         const char* name() const            { return _descriptor->Name; }
58         const char* maker() const           { return _descriptor->Maker; }
59         uint32_t    parameter_count() const { return _descriptor->PortCount; }
60         float       default_value (uint32_t port);
61         nframes_t   signal_latency() const;
62         void        set_parameter (uint32_t port, float val);
63         float       get_parameter (uint32_t port) const;
64         int         get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
65         uint32_t    nth_parameter (uint32_t port, bool& ok) const;
66         
67         std::set<Parameter> automatable() const;
68
69         void activate () { 
70                 if (!_was_activated && _descriptor->activate)
71                         _descriptor->activate (_handle);
72
73                 _was_activated = true;
74         }
75
76         void deactivate () {
77                 if (_was_activated && _descriptor->deactivate)
78                         _descriptor->deactivate (_handle);
79
80                 _was_activated = false;
81         }
82
83         void cleanup () {
84                 activate();
85                 deactivate();
86
87                 if (_descriptor->cleanup)
88                         _descriptor->cleanup (_handle);
89         }
90
91         void set_block_size (nframes_t nframes) {}
92         
93         int connect_and_run (BufferSet& bufs, uint32_t& in, uint32_t& out, nframes_t nframes, nframes_t offset);
94         string describe_parameter (Parameter);
95         string state_node_name() const { return "ladspa"; }
96         void   print_parameter (uint32_t, char*, uint32_t len) const;
97
98         bool parameter_is_audio(uint32_t) const;
99         bool parameter_is_control(uint32_t) const;
100         bool parameter_is_input(uint32_t) const;
101         bool parameter_is_output(uint32_t) const;
102         bool parameter_is_toggled(uint32_t) const;
103
104         XMLNode& get_state();
105         int      set_state(const XMLNode& node);
106         bool     save_preset(string name);
107
108         bool has_editor() const { return false; }
109
110         int require_output_streams (uint32_t);
111         
112         /* LADSPA extras */
113
114         LADSPA_Properties           properties() const                { return _descriptor->Properties; }
115         uint32_t                    index() const                     { return _index; }
116         const char *                copyright() const                 { return _descriptor->Copyright; }
117         LADSPA_PortDescriptor       port_descriptor(uint32_t i) const { return _descriptor->PortDescriptors[i]; }
118         const LADSPA_PortRangeHint* port_range_hints() const          { return _descriptor->PortRangeHints; }
119         const char * const *        port_names() const                { return _descriptor->PortNames; }
120         
121         void set_gain (float gain)                    { _descriptor->set_run_adding_gain (_handle, gain); }
122         void run_adding (uint32_t nsamples)           { _descriptor->run_adding (_handle, nsamples); }
123         void connect_port (uint32_t port, float *ptr) { _descriptor->connect_port (_handle, port, ptr); }
124
125   private:
126         void*                    _module;
127         const LADSPA_Descriptor* _descriptor;
128         LADSPA_Handle            _handle;
129         nframes_t                _sample_rate;
130         LADSPA_Data*             _control_data;
131         LADSPA_Data*             _shadow_data;
132         LADSPA_Data*             _latency_control_port;
133         uint32_t                 _index;
134         bool                     _was_activated;
135
136         void init (void *mod, uint32_t index, nframes_t rate);
137         void run_in_place (nframes_t nsamples);
138         void latency_compute_run ();
139 };
140
141 class LadspaPluginInfo : public PluginInfo {
142   public:       
143         LadspaPluginInfo () { };
144         ~LadspaPluginInfo () { };
145
146         PluginPtr load (Session& session);
147 };
148
149 typedef boost::shared_ptr<LadspaPluginInfo> LadspaPluginInfoPtr;
150
151 } // namespace ARDOUR
152
153 #endif /* __ardour_ladspa_plugin_h__ */