Clean up plugin preset handling a bit.
[ardour.git] / libs / ardour / ardour / vst_plugin.h
1 /*
2     Copyright (C) 2004 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 <list>
24 #include <map>
25 #include <set>
26 #include <vector>
27 #include <string>
28 #include <dlfcn.h>
29
30 #include "pbd/stateful.h"
31 #include "ardour/plugin.h"
32
33 struct _FSTHandle;
34 struct _FST;
35 typedef struct _FSTHandle FSTHandle;
36 typedef struct _FST FST;
37 class AEffect;
38
39 namespace ARDOUR {
40 class AudioEngine;
41 class Session;
42
43 class VSTPlugin : public ARDOUR::Plugin
44 {
45   public:
46         VSTPlugin (ARDOUR::AudioEngine&, ARDOUR::Session&, FSTHandle* handle);
47         VSTPlugin (const VSTPlugin &);
48         ~VSTPlugin ();
49
50         /* Plugin interface */
51
52         std::string unique_id() const;
53         const char * label() const;
54         const char * name() const;
55         const char * maker() const;
56         uint32_t parameter_count() const;
57         float default_value (uint32_t port);
58         framecnt_t signal_latency() const;
59         void set_parameter (uint32_t port, float val);
60         float get_parameter (uint32_t port) const;
61         int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const;
62         std::set<Evoral::Parameter> automatable() const;
63         uint32_t nth_parameter (uint32_t port, bool& ok) const;
64         void activate ();
65         void deactivate ();
66         int set_block_size (pframes_t);
67
68         int connect_and_run (BufferSet&,
69                         ChanMapping in, ChanMapping out,
70                         pframes_t nframes, framecnt_t offset);
71
72         std::string describe_parameter (Evoral::Parameter);
73         std::string state_node_name() const { return "vst"; }
74         void print_parameter (uint32_t, char*, uint32_t len) const;
75
76         bool parameter_is_audio(uint32_t i) const { return false; }
77         bool parameter_is_control(uint32_t i) const { return true; }
78         bool parameter_is_input(uint32_t i) const { return true; }
79         bool parameter_is_output(uint32_t i) const { return false; }
80
81         bool load_preset (PresetRecord);
82         int first_user_preset_index () const;
83
84         bool has_editor () const;
85
86         int set_state (XMLNode const &, int);
87
88         AEffect * plugin () const { return _plugin; }
89         FST * fst () const { return _fst; }
90
91 private:
92
93         void do_remove_preset (std::string name);
94         std::string do_save_preset (std::string name);
95         gchar* get_chunk (bool) const;
96         int set_chunk (gchar const *, bool);
97         XMLTree * presets_tree () const;
98         std::string presets_file () const;
99         void find_presets ();
100         bool load_user_preset (PresetRecord);
101         bool load_plugin_preset (PresetRecord);
102         void add_state (XMLNode *) const;
103         
104         FSTHandle* handle;
105         FST*       _fst;
106         AEffect*   _plugin;
107         bool        been_resumed;
108 };
109
110 class VSTPluginInfo : public PluginInfo
111 {
112   public:
113         VSTPluginInfo ();
114         ~VSTPluginInfo () {}
115
116         PluginPtr load (Session& session);
117 };
118
119 typedef boost::shared_ptr<VSTPluginInfo> VSTPluginInfoPtr;
120
121 } // namespace ARDOUR
122
123 #endif /* __ardour_vst_plugin_h__ */