Skip to content

Commit

Permalink
easyeffects: add option to import presets
Browse files Browse the repository at this point in the history
added options to import presets
added tests
added hausken as maintainer
  • Loading branch information
hauskens committed Jan 5, 2025
1 parent 11ab085 commit f50c5ca
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 1 deletion.
9 changes: 9 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,15 @@ in {
speed, features, or native UIs. Ghostty provides all three.
'';
}

{
time = "2025-01-04T18:10:56+00:00";
condition = config.services.easyeffects.enable;
message = ''
The Easyeffects module now supports adding json formatted presets
under '$XDG_CONFIG_HOME/easyeffects/{input,output}/'.
'';
}
];
};
}
56 changes: 55 additions & 1 deletion modules/services/easyeffects.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,53 @@ let

presetOpts = optionalString (cfg.preset != "") "--load-preset ${cfg.preset}";

jsonFormat = pkgs.formats.json { };

presetType = let baseType = types.attrsOf jsonFormat.type;
in baseType // {
check = v:
baseType.check v && elem (head (attrNames v)) [ "input" "output" ];
description = "EasyEffects input or output JSON preset";
};

presetOptionType = mkOption {
type = types.nullOr (types.attrsOf presetType);
default = { };
description = ''
List of presets to import to easyeffects.
Presets are written to input and output folder in `$XDG_CONFIG_HOME/easyeffects`.
Top level block (input/output) determines the folder the file is written to.
See community presets at:
https://github.com/wwmm/easyeffects/wiki/Community-Presets
'';
example = literalExpression ''
{
my-preset = {
input = {
blocklist = [
];
"plugins_order" = [
"rnnoise#0"
];
"rnnoise#0" = {
bypass = false;
"enable-vad" = false;
"input-gain" = 0.0;
"model-path" = "";
"output-gain" = 0.0;
release = 20.0;
"vad-thres" = 50.0;
wet = 0.0;
};
};
};
};
'';
};
in {
meta.maintainers = [ maintainers.fufexan ];
meta.maintainers = with maintainers; [ fufexan hausken ];

options.services.easyeffects = {
enable = mkEnableOption ''
Expand All @@ -35,6 +80,8 @@ in {
Will likely need to launch easyeffects to initially create preset.
'';
};

extraPresets = presetOptionType;
};

config = mkIf cfg.enable {
Expand All @@ -47,6 +94,13 @@ in {
# "AT-SPI: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files"
home.packages = with pkgs; [ cfg.package at-spi2-core ];

xdg.configFile = mkIf (cfg.extraPresets != { }) (lib.mapAttrs' (k: v:
# assuming only one of either input or output block is defined, having both in same file not seem to be supported by the application since it separates it by folder
let folder = builtins.head (builtins.attrNames v);
in lib.nameValuePair "easyeffects/${folder}/${k}.json" {
source = jsonFormat.generate "${folder}-${k}.json" v;
}) cfg.extraPresets);

systemd.user.services.easyeffects = {
Unit = {
Description = "Easyeffects daemon";
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ in import nmtSrc {
./modules/services/darkman
./modules/services/devilspie2
./modules/services/dropbox
./modules/services/easyeffects
./modules/services/emacs
./modules/services/espanso
./modules/services/flameshot
Expand Down
4 changes: 4 additions & 0 deletions tests/modules/services/easyeffects/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
easyeffects-service = ./service.nix;
easyeffects-example-preset = ./example-preset.nix;
}
18 changes: 18 additions & 0 deletions tests/modules/services/easyeffects/example-preset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"input": {
"blocklist": [],
"plugins_order": [
"rnnoise#0"
],
"rnnoise#0": {
"bypass": false,
"enable-vad": false,
"input-gain": 0.0,
"model-path": "",
"output-gain": 0.0,
"release": 20.0,
"vad-thres": 50.0,
"wet": 0.0
}
}
}
36 changes: 36 additions & 0 deletions tests/modules/services/easyeffects/example-preset.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ ... }:

{
services.easyeffects = {
enable = true;
extraPresets = {
example-preset = {
input = {
blocklist = [

];
"plugins_order" = [ "rnnoise#0" ];
"rnnoise#0" = {
bypass = false;
"enable-vad" = false;
"input-gain" = 0.0;
"model-path" = "";
"output-gain" = 0.0;
release = 20.0;
"vad-thres" = 50.0;
wet = 0.0;
};
};
};
};
};

test.stubs.easyeffects = { };

nmt.script = ''
assertFileContent \
home-files/.config/easyeffects/input/example-preset.json "${
./example-preset.json
}"
'';
}
14 changes: 14 additions & 0 deletions tests/modules/services/easyeffects/service.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ ... }:

{
services.easyeffects = { enable = true; };

test.stubs.easyeffects = { };

nmt.script = ''
serviceFile=home-files/.config/systemd/user/easyeffects.service
assertFileExists $serviceFile
assertFileRegex $serviceFile 'ExecStart=.*/bin/easyeffects'
'';
}

0 comments on commit f50c5ca

Please sign in to comment.