fixes for destructive track offsets of various kinds; move from jack_nframes_t -...
[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     $Id$
19 */
20
21 #ifndef __ardour_ladspa_plugin_h__
22 #define __ardour_ladspa_plugin_h__
23
24 #include <list>
25 #include <set>
26 #include <vector>
27 #include <string>
28 #include <dlfcn.h>
29
30 #include <sigc++/signal.h>
31
32 #include <pbd/stateful.h> 
33
34 #include <jack/types.h>
35 #include <ardour/ladspa.h>
36 #include <ardour/plugin_state.h>
37 #include <ardour/plugin.h>
38 #include <ardour/ladspa_plugin.h>
39
40 using std::string;
41 using std::vector;
42 using std::list;
43
44 namespace ARDOUR {
45 class AudioEngine;
46 class Session;
47
48 class LadspaPlugin : public ARDOUR::Plugin
49 {
50   public:
51         LadspaPlugin (void *module, ARDOUR::AudioEngine&, ARDOUR::Session&, uint32_t index, nframes_t sample_rate);
52         LadspaPlugin (const LadspaPlugin &);
53         ~LadspaPlugin ();
54
55         /* Plugin interface */
56         
57         uint32_t unique_id() const                       { return descriptor->UniqueID; }
58         const char * label() const                       { return descriptor->Label; }
59         const char * name() const                        { return descriptor->Name; }
60         const char * maker() const                       { return descriptor->Maker; }
61         uint32_t parameter_count() const                 { return descriptor->PortCount; }
62         float default_value (uint32_t port);
63         nframes_t latency() const;
64         void set_parameter (uint32_t port, float val);
65         float get_parameter (uint32_t port) const;
66         int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
67         std::set<uint32_t> automatable() const;
68         uint32_t nth_parameter (uint32_t port, bool& ok) const;
69         void activate () { 
70                 if (descriptor->activate) {
71                         descriptor->activate (handle);
72                 }
73                 was_activated = true;
74         }
75         void deactivate () {
76                 if (descriptor->deactivate) 
77                         descriptor->deactivate (handle);
78         }
79         void cleanup () {
80                 if (was_activated && descriptor->cleanup) {
81                         descriptor->cleanup (handle);
82                 }
83         }
84         void set_block_size (nframes_t nframes) {}
85         
86         int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset);
87         void store_state (ARDOUR::PluginState&);
88         void restore_state (ARDOUR::PluginState&);
89         string describe_parameter (uint32_t);
90         string state_node_name() const { return "ladspa"; }
91         void print_parameter (uint32_t, char*, uint32_t len) const;
92
93         bool parameter_is_audio(uint32_t) const;
94         bool parameter_is_control(uint32_t) const;
95         bool parameter_is_input(uint32_t) const;
96         bool parameter_is_output(uint32_t) const;
97         bool parameter_is_toggled(uint32_t) const;
98
99         XMLNode& get_state();
100         int set_state(const XMLNode& node);
101         bool save_preset(string name);
102
103         bool has_editor() const { return false; }
104
105         int require_output_streams (uint32_t);
106         
107         /* LADSPA extras */
108
109         LADSPA_Properties properties() const             { return descriptor->Properties; }
110         uint32_t index() const                      { return _index; }
111         const char * copyright() const                   { return descriptor->Copyright; }
112         LADSPA_PortDescriptor port_descriptor(uint32_t i) const { return descriptor->PortDescriptors[i]; }
113         const LADSPA_PortRangeHint * port_range_hints() const { return descriptor->PortRangeHints; }
114         const char * const * port_names() const          { return descriptor->PortNames; }
115         void set_gain (float gain) {
116                 descriptor->set_run_adding_gain (handle, gain);
117         }
118         void run_adding (uint32_t nsamples) {
119                 descriptor->run_adding (handle, nsamples);
120         }
121         void connect_port (uint32_t port, float *ptr) {
122                 descriptor->connect_port (handle, port, ptr);
123         }
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 (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__ */