211b00d0bbe43cb786de62218d4c9454f0e6d589
[ardour.git] / libs / ardour / ardour / plugin.h
1 /*
2     Copyright (C) 2000 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_h__
22 #define __ardour_ladspa_h__
23
24 #include <midi++/controllable.h>
25 #include <sigc++/signal.h>
26
27 #include <jack/types.h>
28 #include <ardour/types.h>
29 #include <ardour/stateful.h>
30 #include <ardour/plugin_state.h>
31 #include <ardour/cycles.h>
32
33 #include <vector>
34 #include <set>
35 #include <map>
36
37 using std::string;
38 using std::vector;
39 using std::set;
40 using std::map;
41
42 namespace ARDOUR {
43
44 class AudioEngine;
45 class Session;
46
47 class PluginInfo {
48   public:
49         enum Type {
50                 AudioUnit,
51                 LADSPA,
52                 VST
53         };
54
55         PluginInfo () { };
56         PluginInfo (const PluginInfo &o)
57                 : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs),
58                 unique_id(o.unique_id), path (o.path), index(o.index) {}
59         ~PluginInfo () { };
60         string name;
61         string category;
62         uint32_t n_inputs;
63         uint32_t n_outputs;
64         Type type;
65
66         long unique_id;
67
68   private:
69         friend class PluginManager;
70         string path;
71         uint32_t index;
72 };
73
74 class Plugin : public Stateful, public sigc::trackable
75
76 {
77   public:
78         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
79         Plugin (const Plugin&);
80         ~Plugin ();
81         
82         struct ParameterDescriptor {
83
84             /* essentially a union of LADSPA and VST info */
85
86             bool integer_step;
87             bool toggled;
88             bool logarithmic;
89             bool sr_dependent;
90             string label;
91             float lower;
92             float upper;
93             float step;
94             float smallstep;
95             float largestep;
96
97                 bool min_unbound;
98                 bool max_unbound;
99         };
100
101         virtual uint32_t unique_id() const = 0;
102         virtual const char * label() const = 0;
103         virtual const char * name() const = 0;
104         virtual const char * maker() const = 0;
105         virtual uint32_t parameter_count () const = 0;
106         virtual float default_value (uint32_t port) = 0;
107         virtual jack_nframes_t latency() const = 0;
108         virtual void set_parameter (uint32_t which, float val) = 0;
109         virtual float get_parameter(uint32_t which) const = 0;
110
111         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
112         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
113         virtual void activate () = 0;
114         virtual void deactivate () = 0;
115         virtual void set_block_size (jack_nframes_t nframes) = 0;
116
117         virtual int connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset) = 0;
118         virtual std::set<uint32_t> automatable() const = 0;
119         virtual void store_state (ARDOUR::PluginState&) = 0;
120         virtual void restore_state (ARDOUR::PluginState&) = 0;
121         virtual string describe_parameter (uint32_t) = 0;
122         virtual string state_node_name() const = 0;
123         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
124
125         virtual bool parameter_is_audio(uint32_t) const = 0;
126         virtual bool parameter_is_control(uint32_t) const = 0;
127         virtual bool parameter_is_input(uint32_t) const = 0;
128         virtual bool parameter_is_output(uint32_t) const = 0;
129
130         virtual bool save_preset(string name) = 0;
131         virtual bool load_preset (const string preset_label);
132         virtual std::vector<std::string> get_presets();
133
134         virtual bool has_editor() const = 0;
135
136         sigc::signal<void,uint32_t,float> ParameterChanged;
137         sigc::signal<void,Plugin *> GoingAway;
138         
139         void reset_midi_control (MIDI::Port*, bool);
140         void send_all_midi_feedback ();
141         MIDI::byte* write_midi_feedback (MIDI::byte*, int32_t& bufsize);
142         MIDI::Controllable *get_nth_midi_control (uint32_t);
143
144         PluginInfo & get_info() { return _info; }
145         void set_info (const PluginInfo &inf) { _info = inf; }
146
147         ARDOUR::AudioEngine& engine() const { return _engine; }
148         ARDOUR::Session& session() const { return _session; }
149
150         void set_cycles (uint32_t c) { _cycles = c; }
151         cycles_t cycles() const { return _cycles; }
152
153   protected:
154         ARDOUR::AudioEngine& _engine;
155         ARDOUR::Session& _session;
156         PluginInfo _info;
157         uint32_t _cycles;
158         map<string,string>       presets;
159         bool save_preset(string name, string domain /* vst, ladspa etc. */);
160
161         void setup_midi_controls ();
162
163
164         struct MIDIPortControl : public MIDI::Controllable {
165             MIDIPortControl (Plugin&, uint32_t abs_port_id, MIDI::Port *,
166                              float lower, float upper, bool toggled, bool logarithmic);
167
168             void set_value (float);
169             void send_feedback (float);
170             MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, float val, bool force = false);
171
172             Plugin& plugin;
173             uint32_t absolute_port;
174             float upper;
175             float lower;
176             float range;
177             bool  toggled;
178             bool  logarithmic;
179
180             bool setting;
181             float last_written;
182         };
183
184         vector<MIDIPortControl*> midi_controls;
185
186         
187 };
188
189 /* this is actually defined in plugin_manager.cc */
190
191 Plugin * find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type);
192
193 } // namespace ARDOUR
194  
195 #endif /* __ardour_plugin_h__ */