From 357956bd992183fd4c431589207c9953832c865b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 3 Nov 2025 12:27:48 -0700 Subject: [PATCH] factor out the platform-specific default clip library path --- libs/ardour/ardour/clip_library.h | 1 + libs/ardour/clip_library.cc | 55 ++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/libs/ardour/ardour/clip_library.h b/libs/ardour/ardour/clip_library.h index a91f1b83b4..e0585f6b55 100644 --- a/libs/ardour/ardour/clip_library.h +++ b/libs/ardour/ardour/clip_library.h @@ -35,6 +35,7 @@ class Region; extern LIBARDOUR_API PBD::Signal LibraryClipAdded; +LIBARDOUR_API std::string platform_default_clip_library_dir (); LIBARDOUR_API std::string clip_library_dir (bool create_if_missing = false); LIBARDOUR_API bool export_to_clip_library (std::shared_ptr r, void* src = NULL); diff --git a/libs/ardour/clip_library.cc b/libs/ardour/clip_library.cc index eecb63f9e3..fd1153b248 100644 --- a/libs/ardour/clip_library.cc +++ b/libs/ardour/clip_library.cc @@ -42,35 +42,44 @@ using namespace PBD; PBD::Signal ARDOUR::LibraryClipAdded; +string +ARDOUR::platform_default_clip_library_dir () +{ + std::string p; + const char* c = nullptr; + + if ((c = getenv ("XDG_DATA_HOME")) != 0) { + /* default: $HOME/.local/share */ + p = c; + p = Glib::build_filename (p, "sounds", "clips"); + } else { +#ifdef __APPLE__ + /* Logic Saves "loops" to '~Library/Audio/Apple Loops/Apple/' + * and "samples" to '~/Library/Application Support/Logic/XYZ/' + * By default the following folders also exist + * '~/Library/Audio/Sounds/Alerts/' + * '~/Library/Audio/Sounds/Banks/' + */ + p = Glib::build_filename (Glib::get_home_dir (), "Library/Audio/Sounds/Clips"); +#elif defined PLATFORM_WINDOWS + /* %localappdata%\ClipLibrary */ + p = Glib::build_filename (Glib::get_user_data_dir (), "Clip Library"); +#else + /* Linux, *BSD: use XDG_DATA_HOME prefix, version-independent app folder */ + p = Glib::build_filename (Glib::get_user_data_dir (), "sounds", "clips"); +#endif + } + + return p; +} + string ARDOUR::clip_library_dir (bool create_if_missing) { std::string p = Config->get_clip_library_dir (); if (p == X_("@default@")) { - const char* c = 0; - if ((c = getenv ("XDG_DATA_HOME")) != 0) { - /* default: $HOME/.local/share */ - p = c; - p = Glib::build_filename (p, "sounds", "clips"); - } else { -#ifdef __APPLE__ - /* Logic Saves "loops" to '~Library/Audio/Apple Loops/Apple/' - * and "samples" to '~/Library/Application Support/Logic/XYZ/' - * By default the following folders also exist - * '~/Library/Audio/Sounds/Alerts/' - * '~/Library/Audio/Sounds/Banks/' - */ - p = Glib::build_filename (Glib::get_home_dir (), "Library/Audio/Sounds/Clips"); -#elif defined PLATFORM_WINDOWS - /* %localappdata%\ClipLibrary */ - p = Glib::build_filename (Glib::get_user_data_dir (), "Clip Library"); -#else - /* Linux, *BSD: use XDG_DATA_HOME prefix, version-independent app folder */ - p = Glib::build_filename (Glib::get_user_data_dir (), "sounds", "clips"); -#endif - } - + p = platform_default_clip_library_dir (); info << string_compose (_("Set Clip Library directory to '%1'"), p) << endmsg; Config->set_clip_library_dir (p); }