Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flatpak extension path also for Convolver and RNNoise #3098

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/convolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Convolver : public PluginBase {
auto search_irs_path(const std::string& name) -> std::string;

private:
std::string local_irs_dir;
std::vector<std::string> system_data_irs_dir;
std::string local_dir_irs;
std::vector<std::string> system_data_dir_irs;

bool kernel_is_initialized = false;
bool n_samples_is_power_of_2 = true;
Expand Down
4 changes: 2 additions & 2 deletions include/rnnoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class RNNoise : public PluginBase {
sigc::signal<void(const bool load_error)> model_changed;

private:
std::string local_model_dir;
std::vector<std::string> system_data_model_dir;
std::string local_dir_rnnoise;
std::vector<std::string> system_data_dir_rnnoise;

bool resample = false;
bool notify_latency = false;
Expand Down
16 changes: 10 additions & 6 deletions src/convolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ Convolver::Convolver(const std::string& tag,
do_autogain(g_settings_get_boolean(settings, "autogain") != 0),
ir_width(g_settings_get_int(settings, "ir-width")) {
// Initialize directories for local and community irs
local_irs_dir = std::string{g_get_user_config_dir()} + "/easyeffects/irs";
local_dir_irs = std::string{g_get_user_config_dir()} + "/easyeffects/irs";

const gchar* const* xdg_data_dirs = g_get_system_data_dirs();
// Flatpak specific path (.flatpak-info always present for apps running in the flatpak sandbox)
if (std::filesystem::is_regular_file("/.flatpak-info")) {
system_data_dir_irs.push_back("/app/extensions/Presets/irs");
}

while (*xdg_data_dirs != nullptr) {
// Regular paths
for (const gchar* const* xdg_data_dirs = g_get_system_data_dirs(); *xdg_data_dirs != nullptr;) {
std::string dir = *xdg_data_dirs++;

dir += dir.ends_with("/") ? "" : "/";

system_data_irs_dir.push_back(dir + "easyeffects/irs");
system_data_dir_irs.push_back(dir + "easyeffects/irs");
}

gconnections.push_back(g_signal_connect(settings, "changed::ir-width",
Expand Down Expand Up @@ -295,7 +299,7 @@ auto Convolver::search_irs_path(const std::string& name) -> std::string {
const auto irs_filename = name + irs_ext;

// First check local directory
const auto local_irs_file = std::filesystem::path{local_irs_dir + "/" + irs_filename};
const auto local_irs_file = std::filesystem::path{local_dir_irs + "/" + irs_filename};

if (std::filesystem::exists(local_irs_file)) {
return local_irs_file.c_str();
Expand All @@ -304,7 +308,7 @@ auto Convolver::search_irs_path(const std::string& name) -> std::string {
// If the file is not found locally, try to search it under system directories.
std::string community_irs_file;

for (const auto& xdg_irs_dir : system_data_irs_dir) {
for (const auto& xdg_irs_dir : system_data_dir_irs) {
if (util::search_filename(std::filesystem::path{xdg_irs_dir}, irs_filename, community_irs_file, 3U)) {
break;
}
Expand Down
22 changes: 10 additions & 12 deletions src/presets_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ PresetsManager::PresetsManager()
settings(g_settings_new(tags::app::id)),
soe_settings(g_settings_new(tags::schema::id_output)),
sie_settings(g_settings_new(tags::schema::id_input)) {
// initialize input and output directories for community presets

const gchar* const* xdg_data_dirs = g_get_system_data_dirs();
// Initialize input and output directories for community presets.
// Flatpak specific path (.flatpak-info always present for apps running in the flatpak sandbox).
if (std::filesystem::is_regular_file("/.flatpak-info")) {
system_data_dir_input.push_back("/app/extensions/Presets/input");
system_data_dir_output.push_back("/app/extensions/Presets/output");
system_data_dir_irs.push_back("/app/extensions/Presets/irs");
system_data_dir_rnnoise.push_back("/app/extensions/Presets/rnnoise");
}

while (*xdg_data_dirs != nullptr) {
// Regular paths.
for (const gchar* const* xdg_data_dirs = g_get_system_data_dirs(); *xdg_data_dirs != nullptr;) {
std::string dir = *xdg_data_dirs++;

dir += dir.ends_with("/") ? "" : "/";
Expand All @@ -97,14 +103,6 @@ PresetsManager::PresetsManager()
system_data_dir_rnnoise.push_back(dir + "easyeffects/rnnoise");
}

// flatpak always creates this file for apps running in the flatpak sandbox
if (std::filesystem::is_regular_file("/.flatpak-info")) {
system_data_dir_input.push_back("/app/extensions/Presets/input");
system_data_dir_output.push_back("/app/extensions/Presets/output");
system_data_dir_irs.push_back("/app/extensions/Presets/irs");
system_data_dir_rnnoise.push_back("/app/extensions/Presets/rnnoise");
}

// create user presets directories

create_user_directory(user_input_dir);
Expand Down
16 changes: 10 additions & 6 deletions src/rnnoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ RNNoise::RNNoise(const std::string& tag,
data_tmp.reserve(blocksize);

// Initialize directories for local and community models
local_model_dir = std::string{g_get_user_config_dir()} + "/easyeffects/rnnoise";
local_dir_rnnoise = std::string{g_get_user_config_dir()} + "/easyeffects/rnnoise";

const gchar* const* xdg_data_dirs = g_get_system_data_dirs();
// Flatpak specific path (.flatpak-info always present for apps running in the flatpak sandbox)
if (std::filesystem::is_regular_file("/.flatpak-info")) {
system_data_dir_rnnoise.push_back("/app/extensions/Presets/rnnoise");
}

while (*xdg_data_dirs != nullptr) {
// Regular paths
for (const gchar* const* xdg_data_dirs = g_get_system_data_dirs(); *xdg_data_dirs != nullptr;) {
std::string dir = *xdg_data_dirs++;

dir += dir.ends_with("/") ? "" : "/";

system_data_model_dir.push_back(dir + "easyeffects/rnnoise");
system_data_dir_rnnoise.push_back(dir + "easyeffects/rnnoise");
}

const auto key_v = g_settings_get_double(settings, "wet");
Expand Down Expand Up @@ -314,7 +318,7 @@ auto RNNoise::search_model_path(const std::string& name) -> std::string {
const auto model_filename = name + rnnn_ext;

// First check local directory
const auto local_model_file = std::filesystem::path{local_model_dir + "/" + model_filename};
const auto local_model_file = std::filesystem::path{local_dir_rnnoise + "/" + model_filename};

if (std::filesystem::exists(local_model_file)) {
return local_model_file.c_str();
Expand All @@ -323,7 +327,7 @@ auto RNNoise::search_model_path(const std::string& name) -> std::string {
// If the file is not found locally, try to search it under system directories.
std::string community_model_file;

for (const auto& xdg_model_dir : system_data_model_dir) {
for (const auto& xdg_model_dir : system_data_dir_rnnoise) {
if (util::search_filename(std::filesystem::path{xdg_model_dir}, model_filename, community_model_file, 3U)) {
break;
}
Expand Down
1 change: 1 addition & 0 deletions util/NEWS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Date: UNRELEASED_DATE
Description:
- Features∶
- Community Presets have been implemented. Users can install packages containing multiple Easy Effects presets to be imported and applied inside the application. These packages will be maintained and shipped by volunteers. You can search them on Flathub or the repositories of your favorite distribution.
- Added the ability of collapsing the sidebar to hide the effects list and expand the area of the effects user interface.

- Bug fixes∶
- A change in GTK 4.14.1 prevented to apply the values inserted into the text field of our SpinButton widgets. This issue is now resolved.
Expand Down
Loading