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