+
+#ifdef LXVST_SUPPORT
+
+void
+PluginManager::lxvst_refresh ()
+{
+ if (_lxvst_plugin_info) {
+ _lxvst_plugin_info->clear ();
+ } else {
+ _lxvst_plugin_info = new ARDOUR::PluginInfoList();
+ }
+
+ if (lxvst_path.length() == 0) {
+ lxvst_path = "/usr/local/lib64/lxvst:/usr/local/lib/lxvst:/usr/lib64/lxvst:/usr/lib/lxvst";
+ }
+
+ lxvst_discover_from_path (lxvst_path);
+}
+
+int
+PluginManager::add_lxvst_directory (string path)
+{
+ if (lxvst_discover_from_path (path) == 0) {
+ lxvst_path += ':';
+ lxvst_path += path;
+ return 0;
+ }
+ return -1;
+}
+
+static bool lxvst_filter (const string& str, void *arg)
+{
+ /* Not a dotfile, has a prefix before a period, suffix is "so" */
+
+ return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
+}
+
+int
+PluginManager::lxvst_discover_from_path (string path)
+{
+ PathScanner scanner;
+ vector<string *> *plugin_objects;
+ vector<string *>::iterator x;
+ int ret = 0;
+
+ info << "Discovering linuxVST plugins along " << path << endmsg;
+
+ plugin_objects = scanner (lxvst_path, lxvst_filter, 0, true, true);
+
+ if (plugin_objects) {
+ for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
+ lxvst_discover (**x);
+ }
+ }
+
+ info << "Done linuxVST discover" << endmsg;
+
+ vector_delete (plugin_objects);
+ return ret;
+}
+
+int
+PluginManager::lxvst_discover (string path)
+{
+ VSTFXInfo* finfo;
+ char buf[32];
+
+ if ((finfo = vstfx_get_info (const_cast<char *> (path.c_str()))) == 0) {
+ warning << "Cannot get linuxVST information from " << path << endmsg;
+ return -1;
+ }
+
+ if (!finfo->canProcessReplacing) {
+ warning << string_compose (_("linuxVST plugin %1 does not support processReplacing, and so cannot be used in ardour at this time"),
+ finfo->name)
+ << endl;
+ }
+
+ PluginInfoPtr info(new LXVSTPluginInfo);
+
+ if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
+ info->name = PBD::basename_nosuffix (path);
+ } else {
+ info->name = finfo->name;
+ }
+
+
+ snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
+ info->unique_id = buf;
+ info->category = "linuxVSTs";
+ info->path = path;
+ info->creator = finfo->creator;
+ info->index = 0;
+ info->n_inputs.set_audio (finfo->numInputs);
+ info->n_outputs.set_audio (finfo->numOutputs);
+ info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
+ info->type = ARDOUR::LXVST;
+
+ _lxvst_plugin_info->push_back (info);
+ vstfx_free_info (finfo);
+
+ return 0;
+}
+
+#endif // LXVST_SUPPORT
+
+
+PluginManager::PluginStatusType
+PluginManager::get_status (const PluginInfoPtr& pi)
+{
+ PluginStatus ps (pi->type, pi->unique_id);
+ PluginStatusList::const_iterator i = find (statuses.begin(), statuses.end(), ps);
+ if (i == statuses.end() ) {
+ return Normal;
+ } else {
+ return i->status;
+ }
+}
+
+void
+PluginManager::save_statuses ()
+{
+ ofstream ofs;
+ sys::path path = user_config_directory();
+ path /= "plugin_statuses";
+
+ ofs.open (path.to_string().c_str(), ios_base::openmode (ios::out|ios::trunc));
+
+ if (!ofs) {
+ return;
+ }
+
+ for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
+ switch ((*i).type) {
+ case LADSPA:
+ ofs << "LADSPA";
+ break;
+ case AudioUnit:
+ ofs << "AudioUnit";
+ break;
+ case LV2:
+ ofs << "LV2";
+ break;
+ case VST:
+ ofs << "VST";
+ break;
+ case LXVST:
+ ofs << "LXVST";
+ break;
+ }
+
+ ofs << ' ';
+
+ switch ((*i).status) {
+ case Normal:
+ ofs << "Normal";
+ break;
+ case Favorite:
+ ofs << "Favorite";
+ break;
+ case Hidden:
+ ofs << "Hidden";
+ break;
+ }
+
+ ofs << ' ';
+ ofs << (*i).unique_id;;
+ ofs << endl;
+ }
+
+ ofs.close ();
+}
+
+void
+PluginManager::load_statuses ()
+{
+ sys::path path = user_config_directory();
+ path /= "plugin_statuses";
+ ifstream ifs (path.to_string().c_str());
+
+ if (!ifs) {
+ return;
+ }
+
+ std::string stype;
+ std::string sstatus;
+ std::string id;
+ PluginType type;
+ PluginStatusType status;
+ char buf[1024];
+
+ while (ifs) {
+
+ ifs >> stype;
+ if (!ifs) {
+ break;
+
+ }
+
+ ifs >> sstatus;
+ if (!ifs) {
+ break;
+
+ }
+
+ /* rest of the line is the plugin ID */
+
+ ifs.getline (buf, sizeof (buf), '\n');
+ if (!ifs) {
+ break;
+ }
+
+ if (sstatus == "Normal") {
+ status = Normal;
+ } else if (sstatus == "Favorite") {
+ status = Favorite;
+ } else if (sstatus == "Hidden") {
+ status = Hidden;
+ } else {
+ error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
+ << endmsg;
+ statuses.clear ();
+ break;
+ }
+
+ if (stype == "LADSPA") {
+ type = LADSPA;
+ } else if (stype == "AudioUnit") {
+ type = AudioUnit;
+ } else if (stype == "LV2") {
+ type = LV2;
+ } else if (stype == "VST") {
+ type = VST;
+ } else if (stype == "LXVST") {
+ type = LXVST;
+ } else {
+ error << string_compose (_("unknown plugin type \"%1\" - ignored"), stype)
+ << endmsg;
+ continue;
+ }
+
+ id = buf;
+ strip_whitespace_edges (id);
+ set_status (type, id, status);
+ }
+
+ ifs.close ();
+}
+
+void
+PluginManager::set_status (PluginType t, string id, PluginStatusType status)
+{
+ PluginStatus ps (t, id, status);
+ statuses.erase (ps);
+
+ if (status == Normal) {
+ return;
+ }
+
+ statuses.insert (ps);
+}
+
+ARDOUR::PluginInfoList&
+PluginManager::vst_plugin_info ()
+{
+#ifdef VST_SUPPORT
+ if (!_vst_plugin_info)
+ vst_refresh();
+ return *_vst_plugin_info;
+#else
+ return _empty_plugin_info;
+#endif
+}
+
+ARDOUR::PluginInfoList&
+PluginManager::lxvst_plugin_info ()
+{
+#ifdef LXVST_SUPPORT
+ if (!_lxvst_plugin_info)
+ lxvst_refresh();
+ return *_lxvst_plugin_info;
+#else
+ return _empty_plugin_info;
+#endif
+}
+
+ARDOUR::PluginInfoList&
+PluginManager::ladspa_plugin_info ()
+{
+ if (!_ladspa_plugin_info)
+ ladspa_refresh();
+ return *_ladspa_plugin_info;
+}
+
+ARDOUR::PluginInfoList&
+PluginManager::lv2_plugin_info ()
+{
+#ifdef LV2_SUPPORT
+ if (!_lv2_plugin_info)
+ lv2_refresh();
+ return *_lv2_plugin_info;
+#else
+ return _empty_plugin_info;
+#endif
+}
+
+ARDOUR::PluginInfoList&
+PluginManager::au_plugin_info ()
+{
+#ifdef HAVE_AUDIOUNITS
+ if (!_au_plugin_info)
+ au_refresh();
+ return *_au_plugin_info;
+#else
+ return _empty_plugin_info;
+#endif
+}