diff --git a/libs/ardour/ardour/vst3_plugin.h b/libs/ardour/ardour/vst3_plugin.h index 69e162a667..8a71aa5bc7 100644 --- a/libs/ardour/ardour/vst3_plugin.h +++ b/libs/ardour/ardour/vst3_plugin.h @@ -390,8 +390,6 @@ private: void forward_resize_view (int w, int h); void parameter_change_handler (Steinberg::VST3PI::ParameterChange, uint32_t, float); - PBD::Searchpath preset_search_path () const; - Steinberg::VST3PI* _plug; PBD::ScopedConnectionList _connections; @@ -413,6 +411,7 @@ public: PluginPtr load (Session& session); std::vector get_presets (bool user_only) const; bool is_instrument () const; + PBD::Searchpath preset_search_path () const; boost::shared_ptr m; }; diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index 5eb35d2453..7b115e3e1a 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -803,8 +803,11 @@ VST3Plugin::load_preset (PresetRecord r) std::string VST3Plugin::do_save_preset (std::string name) { - assert (!preset_search_path ().empty ()); - std::string dir = preset_search_path ().front (); + boost::shared_ptr nfo = boost::dynamic_pointer_cast (get_info ()); + PBD::Searchpath psp = nfo->preset_search_path (); + assert (!psp.empty ()); + + std::string dir = psp.front (); std::string fn = Glib::build_filename (dir, legalize_for_universal_path (name) + ".vstpreset"); if (g_mkdir_with_parents (dir.c_str (), 0775)) { @@ -832,8 +835,11 @@ VST3Plugin::do_save_preset (std::string name) void VST3Plugin::do_remove_preset (std::string name) { - assert (!preset_search_path ().empty ()); - std::string dir = preset_search_path ().front (); + boost::shared_ptr nfo = boost::dynamic_pointer_cast (get_info ()); + PBD::Searchpath psp = nfo->preset_search_path (); + assert (!psp.empty ()); + + std::string dir = psp.front (); std::string fn = Glib::build_filename (dir, legalize_for_universal_path (name) + ".vstpreset"); ::g_unlink (fn.c_str ()); std::string uri = string_compose (X_("VST3-S:%1:%2"), unique_id (), PBD::basename_nosuffix (fn)); @@ -919,7 +925,9 @@ VST3Plugin::find_presets () // TODO check _plug->unit_data() // IUnitData: programDataSupported -> setUnitProgramData (IBStream) - PBD::Searchpath psp = preset_search_path (); + boost::shared_ptr info = boost::dynamic_pointer_cast (get_info ()); + PBD::Searchpath psp = info->preset_search_path (); + std::vector preset_files; find_paths_matching_filter (preset_files, psp, vst3_preset_filter, 0, false, true, false); @@ -936,42 +944,6 @@ VST3Plugin::find_presets () } } -PBD::Searchpath -VST3Plugin::preset_search_path () const -{ - boost::shared_ptr nfo = boost::dynamic_pointer_cast (get_info ()); - - std::string vendor = legalize_for_universal_path (nfo->creator); - std::string name = legalize_for_universal_path (nfo->name); - - /* first listed is used to save custom user-presets */ - PBD::Searchpath preset_path; -#ifdef __APPLE__ - preset_path += Glib::build_filename (Glib::get_home_dir (), "Library/Audio/Presets", vendor, name); - preset_path += Glib::build_filename ("/Library/Audio/Presets", vendor, name); -#elif defined PLATFORM_WINDOWS - std::string documents = PBD::get_win_special_folder_path (CSIDL_PERSONAL); - if (!documents.empty ()) { - preset_path += Glib::build_filename (documents, "VST3 Presets", vendor, name); - preset_path += Glib::build_filename (documents, "vst3 presets", vendor, name); - } - - preset_path += Glib::build_filename (Glib::get_user_data_dir (), "VST3 Presets", vendor, name); - - std::string appdata = PBD::get_win_special_folder_path (CSIDL_APPDATA); - if (!appdata.empty ()) { - preset_path += Glib::build_filename (appdata, "VST3 Presets", vendor, name); - preset_path += Glib::build_filename (appdata, "vst3 presets", vendor, name); - } -#else - preset_path += Glib::build_filename (Glib::get_home_dir (), ".vst3", "presets", vendor, name); - preset_path += Glib::build_filename ("/usr/share/vst3/presets", vendor, name); - preset_path += Glib::build_filename ("/usr/local/share/vst3/presets", vendor, name); -#endif - - return preset_path; -} - /* ****************************************************************************/ VST3PluginInfo::VST3PluginInfo () @@ -1000,9 +972,32 @@ VST3PluginInfo::load (Session& session) } std::vector -VST3PluginInfo::get_presets (bool /*user_only*/) const +VST3PluginInfo::get_presets (bool user_only) const { std::vector p; + + /* This only returns user-presets, which is sufficient for the time + * being. So far only Mixer_UI::sync_treeview_from_favorite_order() + * uses PluginInfo to query presets. + * + * see also VST3Plugin::find_presets + */ + assert (user_only); + + PBD::Searchpath psp = preset_search_path (); + std::vector preset_files; + find_paths_matching_filter (preset_files, psp, vst3_preset_filter, 0, false, true, false); + + for (std::vector::iterator i = preset_files.begin (); i != preset_files.end (); ++i) { + bool is_user = PBD::path_is_within (psp.front (), *i); + std::string preset_name = PBD::basename_nosuffix (*i); + std::string uri = string_compose (X_("VST3-S:%1:%2"), unique_id, preset_name); + if (!is_user) { + continue; + } + p.push_back (Plugin::PresetRecord (uri, preset_name, is_user)); + } + return p; } @@ -1016,6 +1011,40 @@ VST3PluginInfo::is_instrument () const return PluginInfo::is_instrument (); } +PBD::Searchpath +VST3PluginInfo::preset_search_path () const +{ + std::string vendor = legalize_for_universal_path (creator); + std::string pname = legalize_for_universal_path (name); + + /* first listed is used to save custom user-presets */ + PBD::Searchpath preset_path; +#ifdef __APPLE__ + preset_path += Glib::build_filename (Glib::get_home_dir (), "Library/Audio/Presets", vendor, pname); + preset_path += Glib::build_filename ("/Library/Audio/Presets", vendor, pname); +#elif defined PLATFORM_WINDOWS + std::string documents = PBD::get_win_special_folder_path (CSIDL_PERSONAL); + if (!documents.empty ()) { + preset_path += Glib::build_filename (documents, "VST3 Presets", vendor, pname); + preset_path += Glib::build_filename (documents, "vst3 presets", vendor, pname); + } + + preset_path += Glib::build_filename (Glib::get_user_data_dir (), "VST3 Presets", vendor, pname); + + std::string appdata = PBD::get_win_special_folder_path (CSIDL_APPDATA); + if (!appdata.empty ()) { + preset_path += Glib::build_filename (appdata, "VST3 Presets", vendor, pname); + preset_path += Glib::build_filename (appdata, "vst3 presets", vendor, pname); + } +#else + preset_path += Glib::build_filename (Glib::get_home_dir (), ".vst3", "presets", vendor, pname); + preset_path += Glib::build_filename ("/usr/share/vst3/presets", vendor, pname); + preset_path += Glib::build_filename ("/usr/local/share/vst3/presets", vendor, pname); +#endif + + return preset_path; +} + /* ****************************************************************************/ VST3PI::VST3PI (boost::shared_ptr m, std::string unique_id)