Put plugin-note-off code in the right place.
[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 */
19
20 #ifndef __ardour_plugin_h__
21 #define __ardour_plugin_h__
22
23 #include <boost/shared_ptr.hpp>
24 #include <string>
25
26 #include "pbd/statefuldestructible.h"
27 #include "pbd/controllable.h"
28
29 #include <jack/types.h>
30 #include "ardour/chan_count.h"
31 #include "ardour/chan_mapping.h"
32 #include "ardour/cycles.h"
33 #include "ardour/latent.h"
34 #include "ardour/plugin_insert.h"
35 #include "ardour/types.h"
36 #include "ardour/midi_state_tracker.h"
37
38 #include <vector>
39 #include <set>
40 #include <map>
41
42 namespace ARDOUR {
43
44 class AudioEngine;
45 class Session;
46 class BufferSet;
47
48 class Plugin;
49
50 typedef boost::shared_ptr<Plugin> PluginPtr;
51
52 class PluginInfo {
53   public:
54         PluginInfo () { }
55         virtual ~PluginInfo () { }
56
57         std::string name;
58         std::string category;
59         std::string creator;
60         std::string path;
61         ChanCount n_inputs;
62         ChanCount n_outputs;
63         ARDOUR::PluginType type;
64
65         std::string unique_id;
66
67         virtual PluginPtr load (Session& session) = 0;
68
69   protected:
70         friend class PluginManager;
71         uint32_t index;
72 };
73
74 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
75 typedef std::list<PluginInfoPtr> PluginInfoList;
76
77 class Plugin : public PBD::StatefulDestructible, public Latent
78 {
79   public:
80         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
81         Plugin (const Plugin&);
82         virtual ~Plugin ();
83
84         struct ParameterDescriptor {
85
86                 /* essentially a union of LADSPA and VST info */
87
88                 bool integer_step;
89                 bool toggled;
90                 bool logarithmic;
91                 bool sr_dependent;
92                 std::string label;
93                 float lower;
94                 float upper;
95                 float step;
96                 float smallstep;
97                 float largestep;
98                 bool min_unbound;
99                 bool max_unbound;
100         };
101
102         virtual std::string unique_id() const = 0;
103         virtual const char * label() const = 0;
104         virtual const char * name() const = 0;
105         virtual const char * maker() const = 0;
106         virtual uint32_t parameter_count () const = 0;
107         virtual float default_value (uint32_t port) = 0;
108         virtual float get_parameter(uint32_t which) const = 0;
109
110         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
111         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
112         virtual void activate () = 0;
113         virtual void deactivate () = 0;
114         virtual void flush () { deactivate(); activate(); }
115
116         virtual int set_block_size (pframes_t nframes) = 0;
117
118         virtual int connect_and_run (BufferSet& bufs,
119                                      ChanMapping in, ChanMapping out,
120                                      pframes_t nframes, framecnt_t offset);
121
122         virtual std::set<Evoral::Parameter> automatable() const = 0;
123         virtual std::string describe_parameter (Evoral::Parameter) = 0;
124         virtual std::string state_node_name() const = 0;
125         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
126
127         virtual bool parameter_is_audio(uint32_t) const = 0;
128         virtual bool parameter_is_control(uint32_t) const = 0;
129         virtual bool parameter_is_input(uint32_t) const = 0;
130         virtual bool parameter_is_output(uint32_t) const = 0;
131
132         void realtime_handle_transport_stopped ();
133
134         bool save_preset (std::string);
135         void remove_preset (std::string);
136         virtual bool load_preset (const std::string& uri) = 0;
137
138         struct PresetRecord {
139                 PresetRecord (const std::string& u, const std::string& l) : uri(u), label(l) {}
140                 std::string uri;
141                 std::string label;
142         };
143
144         const PresetRecord * preset_by_label (const std::string &);
145         const PresetRecord * preset_by_uri (const std::string &);
146
147         /** Return this plugin's presets; should add them to _presets */
148         virtual std::vector<PresetRecord> get_presets () = 0;
149         virtual std::string current_preset () const { return std::string(); }
150
151         /** Emitted when a preset is added or removed, respectively */
152         PBD::Signal0<void> PresetAdded;
153         PBD::Signal0<void> PresetRemoved;
154         
155         /* XXX: no-one listens to this */
156         static PBD::Signal0<bool> PresetFileExists;
157
158         virtual bool has_editor() const = 0;
159
160         PBD::Signal2<void,uint32_t,float> ParameterChanged;
161
162         /* NOTE: this block of virtual methods looks like the interface
163            to a Processor, but Plugin does not inherit from Processor.
164            It is therefore not required that these precisely match
165            the interface, but it is likely that they will evolve together.
166         */
167
168         /* this returns true if the plugin can change its inputs or outputs on demand.
169            LADSPA, LV2 and VST plugins cannot do this. AudioUnits can.
170         */
171
172         virtual bool reconfigurable_io() const { return false; }
173
174         /* this is only called if reconfigurable_io() returns true */
175         virtual bool configure_io (ChanCount /*in*/, ChanCount /*out*/) { return true; }
176
177         /* specific types of plugins can overload this. As of September 2008, only
178            AUPlugin does this.
179         */
180         virtual bool can_support_io_configuration (const ChanCount& /*in*/, ChanCount& /*out*/) const { return false; }
181         virtual ChanCount output_streams() const;
182         virtual ChanCount input_streams() const;
183
184         PluginInfoPtr get_info() const { return _info; }
185         void set_info (const PluginInfoPtr inf) { _info = inf; }
186
187         ARDOUR::AudioEngine& engine() const { return _engine; }
188         ARDOUR::Session& session() const { return _session; }
189
190         void set_cycles (uint32_t c) { _cycles = c; }
191         cycles_t cycles() const { return _cycles; }
192
193 protected:
194         
195         friend class PluginInsert;
196         friend struct PluginInsert::PluginControl;
197
198         virtual void set_parameter (uint32_t which, float val) = 0;
199
200         /** Do the actual saving of the current plugin settings to a preset of the provided name.
201          *  Should return a URI on success, or an empty string on failure.
202          */
203         virtual std::string do_save_preset (std::string) = 0;
204         /** Do the actual removal of a preset of the provided name */
205         virtual void do_remove_preset (std::string) = 0;
206
207         ARDOUR::AudioEngine&     _engine;
208         ARDOUR::Session&         _session;
209         PluginInfoPtr            _info;
210         uint32_t                 _cycles;
211         std::map<std::string, PresetRecord> _presets;
212
213 private:
214         
215         MidiStateTracker _tracker;
216         BufferSet _pending_stop_events;
217         bool _have_pending_stop_events;
218 };
219
220 PluginPtr find_plugin(ARDOUR::Session&, std::string unique_id, ARDOUR::PluginType);
221
222 } // namespace ARDOUR
223
224 #endif /* __ardour_plugin_h__ */