Push most of LXVSTPlugin and WindowsVSTPlugin up to VSTPlugin parent.
[ardour.git] / libs / ardour / windows_vst_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 "fst.h"
21
22 #include "ardour/windows_vst_plugin.h"
23 #include "ardour/session.h"
24
25 #include "i18n.h"
26
27 using namespace std;
28 using namespace ARDOUR;
29 using namespace PBD;
30
31 WindowsVSTPlugin::WindowsVSTPlugin (AudioEngine& e, Session& session, VSTHandle* h)
32         : VSTPlugin (e, session, h)
33 {
34         if ((_state = fst_instantiate (_handle, Session::vst_callback, this)) == 0) {
35                 throw failed_constructor();
36         }
37
38         set_plugin (_state->plugin);
39 }
40
41 WindowsVSTPlugin::WindowsVSTPlugin (const WindowsVSTPlugin &other)
42         : VSTPlugin (other)
43 {
44         _handle = other._handle;
45
46         if ((_state = fst_instantiate (_handle, Session::vst_callback, this)) == 0) {
47                 throw failed_constructor();
48         }
49         
50         _plugin = _state->plugin;
51 }
52
53 WindowsVSTPlugin::~WindowsVSTPlugin ()
54 {
55         fst_close (_state);
56 }
57
58 PluginPtr
59 WindowsVSTPluginInfo::load (Session& session)
60 {
61         try {
62                 PluginPtr plugin;
63
64                 if (Config->get_use_windows_vst ()) {
65                         VSTHandle* handle;
66
67                         handle = fst_load(path.c_str());
68
69                         if ((int) handle == -1) {
70                                 error << string_compose(_("VST: cannot load module from \"%1\""), path) << endmsg;
71                         } else {
72                                 plugin.reset (new WindowsVSTPlugin (session.engine(), session, handle));
73                         }
74                 } else {
75                         error << _("You asked ardour to not use any VST plugins") << endmsg;
76                         return PluginPtr ((Plugin*) 0);
77                 }
78
79                 plugin->set_info(PluginInfoPtr(new WindowsVSTPluginInfo(*this)));
80                 return plugin;
81         }
82
83         catch (failed_constructor &err) {
84                 return PluginPtr ((Plugin*) 0);
85         }
86 }
87
88 WindowsVSTPluginInfo::WindowsVSTPluginInfo()
89 {
90        type = ARDOUR::Windows_VST;
91 }
92