Merge branch 'selection_fixes' of https://github.com/nmains/ardour into cairocanvas
[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/linux_vst_support.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, int unique_id)
31         : VSTPlugin (e, session, h)
32 {
33         /* Instantiate the plugin and return a VSTState* */
34
35         Session::vst_current_loading_id = unique_id;
36         if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
37                 throw failed_constructor();
38         }
39         Session::vst_current_loading_id = 0;
40
41         set_plugin (_state->plugin);
42 }
43
44 LXVSTPlugin::LXVSTPlugin (const LXVSTPlugin &other)
45         : VSTPlugin (other)
46 {
47         _handle = other._handle;
48
49         Session::vst_current_loading_id = PBD::atoi(other.unique_id());
50         if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
51                 throw failed_constructor();
52         }
53         Session::vst_current_loading_id = 0;
54
55         _plugin = _state->plugin;
56
57         // Plugin::setup_controls ();
58 }
59
60 LXVSTPlugin::~LXVSTPlugin ()
61 {
62         vstfx_close (_state);
63 }
64
65 PluginPtr 
66 LXVSTPluginInfo::load (Session& session)
67 {
68         try {
69                 PluginPtr plugin;
70
71                 if (Config->get_use_lxvst()) {
72                         VSTHandle* handle;
73
74                         handle = vstfx_load(path.c_str());
75
76                         if (handle == NULL) {
77                                 error << string_compose(_("LXVST: cannot load module from \"%1\""), path) << endmsg;
78                         }
79                         else {
80                                 plugin.reset (new LXVSTPlugin (session.engine(), session, handle, PBD::atoi(unique_id)));
81                         }
82                 }
83                 else {
84                         error << _("You asked ardour to not use any LXVST plugins") << endmsg;
85                         return PluginPtr ((Plugin*) 0);
86                 }
87
88                 plugin->set_info(PluginInfoPtr(new LXVSTPluginInfo(*this)));
89                 return plugin;
90         }
91
92         catch (failed_constructor &err) {
93                 return PluginPtr ((Plugin*) 0);
94         }
95 }
96
97 LXVSTPluginInfo::LXVSTPluginInfo()
98 {
99        type = ARDOUR::LXVST;
100 }
101