Optimize Plugin connect & run API, use const maps
[ardour.git] / libs / ardour / ardour / vst_plugin.h
1 /*
2     Copyright (C) 2010 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_vst_plugin_h__
21 #define __ardour_vst_plugin_h__
22
23 #include <pbd/signals.h>
24 #include "ardour/plugin.h"
25
26 struct _AEffect;
27 typedef struct _AEffect AEffect;
28 struct _VSTHandle;
29 typedef struct _VSTHandle VSTHandle;
30 struct _VSTState;
31 typedef struct _VSTState VSTState;
32
33 #include "ardour/vestige/vestige.h"
34
35 namespace ARDOUR {
36
37 class PluginInsert;
38
39 /** Parent class for VST plugins of both Windows and Linux varieties */
40 class LIBARDOUR_API VSTPlugin : public Plugin
41 {
42 public:
43         friend class Session;
44         VSTPlugin (AudioEngine &, Session &, VSTHandle *);
45         VSTPlugin (const VSTPlugin& other);
46         virtual ~VSTPlugin ();
47
48         void activate ();
49         void deactivate ();
50
51         int set_block_size (pframes_t);
52         bool requires_fixed_sized_buffers () const;
53         bool inplace_broken() const { return true; }
54         float default_value (uint32_t port);
55         float get_parameter (uint32_t port) const;
56         uint32_t nth_parameter (uint32_t port, bool& ok) const;
57         void set_parameter (uint32_t port, float val);
58         void set_parameter_automated (uint32_t port, float val);
59         bool load_preset (PresetRecord);
60         int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
61         std::string describe_parameter (Evoral::Parameter);
62         samplecnt_t signal_latency() const;
63         std::set<Evoral::Parameter> automatable() const;
64
65         PBD::Signal0<void> LoadPresetProgram;
66         PBD::Signal0<void> VSTSizeWindow;
67
68         bool parameter_is_audio (uint32_t) const { return false; }
69         bool parameter_is_control (uint32_t) const { return true; }
70         bool parameter_is_input (uint32_t) const { return true; }
71         bool parameter_is_output (uint32_t) const { return false; }
72
73         uint32_t designated_bypass_port ();
74
75         int connect_and_run (BufferSet&,
76                         samplepos_t start, samplepos_t end, double speed,
77                         ChanMapping const& in, ChanMapping const& out,
78                         pframes_t nframes, samplecnt_t offset
79                         );
80
81         std::string unique_id () const;
82         const char * label () const;
83         const char * name () const;
84         const char * maker () const;
85         int32_t version () const;
86         uint32_t parameter_count () const;
87         void print_parameter (uint32_t, char*, uint32_t len) const;
88
89         bool has_editor () const;
90
91         AEffect * plugin () const { return _plugin; }
92         VSTState * state () const { return _state; }
93         MidiBuffer * midi_buffer () const { return _midi_out_buf; }
94
95         int set_state (XMLNode const &, int);
96
97         int first_user_preset_index () const;
98
99         void set_insert (PluginInsert* pi, uint32_t num) { _pi = pi; _num = num; }
100         PluginInsert* plugin_insert () const { return _pi; }
101         uint32_t plugin_number () const { return _num; }
102         VstTimeInfo* timeinfo () { return &_timeInfo; }
103         samplepos_t transport_sample () const { return _transport_sample; }
104         float transport_speed () const { return _transport_speed; }
105
106
107 protected:
108         void parameter_changed_externally (uint32_t which, float val);
109         virtual void open_plugin ();
110         void init_plugin ();
111         gchar* get_chunk (bool) const;
112         int set_chunk (gchar const *, bool);
113         void add_state (XMLNode *) const;
114         bool load_user_preset (PresetRecord);
115         bool load_plugin_preset (PresetRecord);
116         std::string do_save_preset (std::string name);
117         void do_remove_preset (std::string name);
118         XMLTree * presets_tree () const;
119         std::string presets_file () const;
120         void find_presets ();
121
122         VSTHandle* _handle;
123         VSTState*  _state;
124         AEffect*   _plugin;
125         PluginInsert* _pi;
126         uint32_t      _num;
127
128         MidiBuffer* _midi_out_buf;
129         VstTimeInfo _timeInfo;
130
131         samplepos_t _transport_sample;
132         float      _transport_speed;
133         mutable std::map <uint32_t, float> _parameter_defaults;
134         bool       _eff_bypassed;
135 };
136
137 }
138
139 #endif