2 Copyright (C) 2004 Paul Davis
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.
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.
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.
20 #include <glibmm/fileutils.h>
21 #include <glibmm/miscutils.h>
23 #include "ardour/filesystem_paths.h"
24 #include "ardour/linux_vst_support.h"
25 #include "ardour/session.h"
26 #include "ardour/lxvst_plugin.h"
31 using namespace ARDOUR;
34 LXVSTPlugin::LXVSTPlugin (AudioEngine& e, Session& session, VSTHandle* h, int unique_id)
35 : VSTPlugin (e, session, h)
37 /* Instantiate the plugin and return a VSTState* */
39 Session::vst_current_loading_id = unique_id;
40 if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
41 throw failed_constructor();
43 Session::vst_current_loading_id = 0;
45 set_plugin (_state->plugin);
48 LXVSTPlugin::LXVSTPlugin (const LXVSTPlugin &other)
51 _handle = other._handle;
53 Session::vst_current_loading_id = PBD::atoi(other.unique_id());
54 if ((_state = vstfx_instantiate (_handle, Session::vst_callback, this)) == 0) {
55 throw failed_constructor();
57 Session::vst_current_loading_id = 0;
59 _plugin = _state->plugin;
61 // Plugin::setup_controls ();
64 LXVSTPlugin::~LXVSTPlugin ()
70 LXVSTPluginInfo::load (Session& session)
75 if (Config->get_use_lxvst()) {
78 handle = vstfx_load(path.c_str());
81 error << string_compose(_("LXVST: cannot load module from \"%1\""), path) << endmsg;
84 plugin.reset (new LXVSTPlugin (session.engine(), session, handle, PBD::atoi(unique_id)));
88 error << _("You asked ardour to not use any LXVST plugins") << endmsg;
89 return PluginPtr ((Plugin*) 0);
92 plugin->set_info(PluginInfoPtr(new LXVSTPluginInfo(*this)));
96 catch (failed_constructor &err) {
97 return PluginPtr ((Plugin*) 0);
101 std::vector<Plugin::PresetRecord>
102 LXVSTPluginInfo::get_presets (bool user_only) const
104 std::vector<Plugin::PresetRecord> p;
105 #ifndef NO_PLUGIN_STATE
106 if (!Config->get_use_lxvst()) {
111 // TODO - cache, instantiating the plugin can be heavy
112 /* Built-in presets */
113 VSTHandle* handle = vstfx_load(path.c_str());
114 Session::vst_current_loading_id = atoi (unique_id);
115 AEffect* plugin = handle->main_entry (Session::vst_callback);
116 Session::vst_current_loading_id = 0;
118 plugin->dispatcher (plugin, effOpen, 0, 0, 0, 0); // :(
119 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0);
121 for (int i = 0; i < plugin->numPrograms; ++i) {
122 Plugin::PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id, i), "", false);
123 if (vst_version >= 2) {
125 if (plugin->dispatcher (plugin, 29, i, 0, buf, 0) == 1) {
128 r.label = string_compose (_("Preset %1"), i);
131 r.label = string_compose (_("Preset %1"), i);
136 plugin->dispatcher (plugin, effMainsChanged, 0, 0, 0, 0);
137 plugin->dispatcher (plugin, effClose, 0, 0, 0, 0); // :(
139 if (handle->plugincnt) {
142 vstfx_unload (handle);
146 XMLTree* t = new XMLTree;
147 std::string pf = Glib::build_filename (ARDOUR::user_config_directory (), "presets", string_compose ("vst-%1", unique_id));
148 if (Glib::file_test (pf, Glib::FILE_TEST_EXISTS)) {
149 t->set_filename (pf);
150 if (t->read ()) { // TODO read names only. skip parsing the actual data
151 XMLNode* root = t->root ();
152 for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) {
153 XMLProperty const * uri = (*i)->property (X_("uri"));
154 XMLProperty const * label = (*i)->property (X_("label"));
155 p.push_back (Plugin::PresetRecord (uri->value(), label->value(), true));
165 LXVSTPluginInfo::LXVSTPluginInfo()
167 type = ARDOUR::LXVST;