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