Use same VST callback for both Linux and Windows VSTs.
[ardour.git] / libs / ardour / lxvst_plugin.cc
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 #include "ardour/vstfx.h"
21 #include "ardour/session.h"
22 #include "ardour/lxvst_plugin.h"
23
24 #include "i18n.h"
25
26 using namespace std;
27 using namespace ARDOUR;
28 using namespace PBD;
29
30 LXVSTPlugin::LXVSTPlugin (AudioEngine& e, Session& session, VSTHandle* h)
31         : VSTPlugin (e, session, h)
32 {
33         /* Instantiate the plugin and return a VSTState* */
34
35         if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
36                 throw failed_constructor();
37         }
38
39         set_plugin (_state->plugin);
40 }
41
42 LXVSTPlugin::LXVSTPlugin (const LXVSTPlugin &other)
43         : VSTPlugin (other)
44 {
45         _handle = other._handle;
46
47         if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
48                 throw failed_constructor();
49         }
50         _plugin = _state->plugin;
51
52         // Plugin::setup_controls ();
53 }
54
55 LXVSTPlugin::~LXVSTPlugin ()
56 {
57         vstfx_close (_state);
58 }
59
60 PluginPtr 
61 LXVSTPluginInfo::load (Session& session)
62 {
63         try {
64                 PluginPtr plugin;
65
66                 if (Config->get_use_lxvst()) {
67                         VSTHandle* handle;
68
69                         handle = vstfx_load(path.c_str());
70
71                         if (handle == NULL) {
72                                 error << string_compose(_("LXVST: cannot load module from \"%1\""), path) << endmsg;
73                         }
74                         else {
75                                 plugin.reset (new LXVSTPlugin (session.engine(), session, handle));
76                         }
77                 }
78                 else {
79                         error << _("You asked ardour to not use any LXVST plugins") << endmsg;
80                         return PluginPtr ((Plugin*) 0);
81                 }
82
83                 plugin->set_info(PluginInfoPtr(new LXVSTPluginInfo(*this)));
84                 return plugin;
85         }
86
87         catch (failed_constructor &err) {
88                 return PluginPtr ((Plugin*) 0);
89         }
90 }
91
92 LXVSTPluginInfo::LXVSTPluginInfo()
93 {
94        type = ARDOUR::LXVST;
95 }
96