Added support for Kawai CA49 BLE Midi with added virtual midi compatible with any DAW
This commit is contained in:
parent
5f9b13a7a3
commit
7b83933c6f
4 changed files with 97 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ in
|
||||||
./modules/ld-fix.nix
|
./modules/ld-fix.nix
|
||||||
./modules/programs.nix
|
./modules/programs.nix
|
||||||
./modules/bluetooth.nix
|
./modules/bluetooth.nix
|
||||||
|
./modules/KawaiCA49.nix
|
||||||
./cachix.nix
|
./cachix.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -71,6 +72,12 @@ in
|
||||||
|
|
||||||
loader.timeout = 0;
|
loader.timeout = 0;
|
||||||
loader.systemd-boot.consoleMode = "auto";
|
loader.systemd-boot.consoleMode = "auto";
|
||||||
|
|
||||||
|
# Add a midi bridge for BLE MIDI devices
|
||||||
|
kernelModules = [ "snd-virmidi" ];
|
||||||
|
extraModprobeConfig = ''
|
||||||
|
options snd-virmidi midi_devs=1
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -182,6 +189,11 @@ in
|
||||||
jack.enable = true;
|
jack.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hardware.kawaiCA49 = {
|
||||||
|
enable = true;
|
||||||
|
user = "nicole";
|
||||||
|
};
|
||||||
|
|
||||||
# ISO mounting utils #
|
# ISO mounting utils #
|
||||||
programs.cdemu.enable = true;
|
programs.cdemu.enable = true;
|
||||||
|
|
||||||
|
|
|
||||||
81
etc/nixos/modules/KawaiCA49.nix
Normal file
81
etc/nixos/modules/KawaiCA49.nix
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.hardware.kawaiCA49;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.hardware.kawaiCA49 = {
|
||||||
|
enable = mkEnableOption "Kawai CA49 Bluetooth MIDI support";
|
||||||
|
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "User to run the MIDI connection service as";
|
||||||
|
};
|
||||||
|
|
||||||
|
virtualMidiDevice = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "Virtual Raw MIDI";
|
||||||
|
description = "Virtual MIDI device name to connect to";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
# Load virtual MIDI kernel module
|
||||||
|
boot.kernelModules = [ "snd-virmidi" ];
|
||||||
|
boot.extraModprobeConfig = ''
|
||||||
|
options snd-virmidi midi_devs=1
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Create a system service that runs as the user
|
||||||
|
systemd.services.midi-connect-ca49 = {
|
||||||
|
description = "Monitor and connect CA49 Piano to Virtual MIDI";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "sound.target" "bluetooth.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
User = cfg.user;
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "5s";
|
||||||
|
ExecStart = pkgs.writeShellScript "monitor-ca49-midi" ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
connect_ca49() {
|
||||||
|
# Find CA49 client number (not port number)
|
||||||
|
CA49_CLIENT=$(${pkgs.alsa-utils}/bin/aconnect -l | grep -oP "client \K[0-9]+(?=:.*CA49)" || true)
|
||||||
|
|
||||||
|
# Find Virtual MIDI client number
|
||||||
|
VIRMIDI_CLIENT=$(${pkgs.alsa-utils}/bin/aconnect -l | grep -oP "client \K[0-9]+(?=:.*${cfg.virtualMidiDevice})" || true)
|
||||||
|
|
||||||
|
if [ -z "$CA49_CLIENT" ] || [ -z "$VIRMIDI_CLIENT" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if already connected
|
||||||
|
if ${pkgs.alsa-utils}/bin/aconnect -l | grep -q "$CA49_CLIENT:0.*Connecting To:.*$VIRMIDI_CLIENT:0"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try to connect
|
||||||
|
if ${pkgs.alsa-utils}/bin/aconnect "$CA49_CLIENT:0" "$VIRMIDI_CLIENT:0" 2>/dev/null; then
|
||||||
|
echo "Connected CA49 (client $CA49_CLIENT) to Virtual MIDI (client $VIRMIDI_CLIENT)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initial connection attempt
|
||||||
|
sleep 2
|
||||||
|
connect_ca49
|
||||||
|
|
||||||
|
# Monitor for new ALSA sequencer events
|
||||||
|
${pkgs.alsa-utils}/bin/aseqdump -p 0:1 | while read -r line; do
|
||||||
|
if echo "$line" | grep -q "Port subscribed\|Port start"; then
|
||||||
|
sleep 1
|
||||||
|
connect_ca49
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
hardware.bluetooth = {
|
hardware.bluetooth = {
|
||||||
enable = true;
|
enable = true;
|
||||||
powerOnBoot = true;
|
powerOnBoot = true;
|
||||||
|
package = pkgs.bluez;
|
||||||
settings.General = {
|
settings.General = {
|
||||||
experimental = true; # show battery
|
experimental = true; # show battery
|
||||||
Privacy = "device";
|
Privacy = "device";
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@
|
||||||
gcc
|
gcc
|
||||||
uv
|
uv
|
||||||
nodejs_24
|
nodejs_24
|
||||||
|
dbgate
|
||||||
|
|
||||||
# GAMING #
|
# GAMING #
|
||||||
mangohud
|
mangohud
|
||||||
|
|
@ -153,6 +154,7 @@
|
||||||
yabridgectl
|
yabridgectl
|
||||||
alsa-scarlett-gui
|
alsa-scarlett-gui
|
||||||
qjackctl
|
qjackctl
|
||||||
|
alsa-utils
|
||||||
|
|
||||||
# WINE #
|
# WINE #
|
||||||
wineWowPackages.stable
|
wineWowPackages.stable
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue