|
9 | 9 |
|
10 | 10 | cfg = config.services.easyeffects; |
11 | 11 |
|
12 | | - presetOpts = lib.optionalString (cfg.preset != "") "--load-preset ${cfg.preset}"; |
| 12 | + isSplitPreset = builtins.isAttrs cfg.preset; |
| 13 | + |
| 14 | + selectedPresets = |
| 15 | + if isSplitPreset then lib.filterAttrs (_: preset: preset != "") cfg.preset else { }; |
| 16 | + |
| 17 | + presetOpts = lib.optionalString ( |
| 18 | + !isSplitPreset && cfg.preset != "" |
| 19 | + ) "--load-preset ${lib.escapeShellArg cfg.preset}"; |
13 | 20 |
|
14 | 21 | olderThan8 = lib.versionOlder cfg.package.version "8.0.0"; # This version introduces breaking changes and this check is used to stay backwards compatible |
15 | 22 |
|
| 23 | + olderThan8_0_9 = lib.versionOlder cfg.package.version "8.0.9"; |
| 24 | + |
16 | 25 | jsonFormat = pkgs.formats.json { }; |
17 | 26 |
|
| 27 | + splitPresetType = types.submodule { |
| 28 | + options = { |
| 29 | + input = mkOption { |
| 30 | + type = types.str; |
| 31 | + default = ""; |
| 32 | + description = "Input preset to load when starting EasyEffects."; |
| 33 | + }; |
| 34 | + |
| 35 | + output = mkOption { |
| 36 | + type = types.str; |
| 37 | + default = ""; |
| 38 | + description = "Output preset to load when starting EasyEffects."; |
| 39 | + }; |
| 40 | + }; |
| 41 | + }; |
| 42 | + |
| 43 | + splitPresetCommands = lib.concatStringsSep "\n" ( |
| 44 | + lib.mapAttrsToList ( |
| 45 | + pipeline: preset: "printf '%s\\n' ${lib.escapeShellArg "load_preset:${pipeline}:${preset}"}" |
| 46 | + ) selectedPresets |
| 47 | + ); |
| 48 | + |
| 49 | + loadSplitPresets = pkgs.writeShellScript "easyeffects-load-presets" '' |
| 50 | + preset_socket=$1 |
| 51 | +
|
| 52 | + for _ in {1..100}; do |
| 53 | + if [[ -S "$preset_socket" ]]; then |
| 54 | + if { |
| 55 | + : |
| 56 | + ${splitPresetCommands} |
| 57 | + } | ${pkgs.socat}/bin/socat -u -T 1 - UNIX-CONNECT:"$preset_socket"; then |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | + fi |
| 61 | +
|
| 62 | + ${pkgs.coreutils}/bin/sleep 0.1 |
| 63 | + done |
| 64 | +
|
| 65 | + exit 1 |
| 66 | + ''; |
| 67 | + |
18 | 68 | settingType = types.nullOr ( |
19 | 69 | types.oneOf [ |
20 | 70 | types.bool |
|
142 | 192 | package = lib.mkPackageOption pkgs "easyeffects" { }; |
143 | 193 |
|
144 | 194 | preset = mkOption { |
145 | | - type = types.str; |
| 195 | + type = types.either types.str splitPresetType; |
146 | 196 | default = ""; |
| 197 | + example = literalExpression '' |
| 198 | + { |
| 199 | + input = "voice"; |
| 200 | + output = "music"; |
| 201 | + } |
| 202 | + ''; |
147 | 203 | description = '' |
148 | | - Which preset to use when starting easyeffects. |
149 | | - Will likely need to launch easyeffects to initially create preset. |
| 204 | + Preset to load when starting EasyEffects. |
| 205 | +
|
| 206 | + A string loads every input or output preset having that name. An |
| 207 | + attribute set selects input and output presets independently and |
| 208 | + requires EasyEffects 8.0.9 or later. An empty string leaves that |
| 209 | + pipeline unchanged. |
| 210 | +
|
| 211 | + You will likely need to launch EasyEffects to initially create presets. |
150 | 212 | ''; |
151 | 213 | }; |
152 | 214 |
|
|
179 | 241 | assertion = !hasSettings || !olderThan8; |
180 | 242 | message = "${settingsOption} requires EasyEffects 8.0.0 or later."; |
181 | 243 | } |
| 244 | + { |
| 245 | + assertion = !isSplitPreset || !olderThan8_0_9; |
| 246 | + message = "Structured `services.easyeffects.preset` requires EasyEffects 8.0.9 or later."; |
| 247 | + } |
| 248 | + { |
| 249 | + assertion = !isSplitPreset || selectedPresets != { }; |
| 250 | + message = "Structured `services.easyeffects.preset` must select at least one input or output preset."; |
| 251 | + } |
182 | 252 | ]; |
183 | 253 |
|
184 | 254 | home.packages = with pkgs; lib.optional olderThan8 at-spi2-core ++ [ cfg.package ]; # Only include if easyeffects version is below 8.0.0 |
|
222 | 292 | // lib.optionalAttrs hasSettings { |
223 | 293 | ExecStartPre = settingsScript; |
224 | 294 | } |
| 295 | + // lib.optionalAttrs isSplitPreset { |
| 296 | + ExecStartPost = "-${loadSplitPresets} %t/EasyEffectsServer"; |
| 297 | + } |
225 | 298 | // ( |
226 | 299 | if olderThan8 then |
227 | 300 | { |
|
0 commit comments