From d91a6af9ace6b740fa228beba5a2da30d496e365 Mon Sep 17 00:00:00 2001
From: "Lukas F. Hartmann" <lukas@mntre.com>
Date: Fri, 26 Feb 2021 22:23:42 +0100
Subject: [PATCH] userland: add pulseaudio profile

---
 reform2-imx8mq/mkuserland-new.sh              |  8 ++
 .../pulse/analog-input-reform.conf            | 98 +++++++++++++++++++
 .../template-etc/pulse/default.conf           | 24 +++++
 3 files changed, 130 insertions(+)
 create mode 100644 reform2-imx8mq/template-etc/pulse/analog-input-reform.conf
 create mode 100644 reform2-imx8mq/template-etc/pulse/default.conf

diff --git a/reform2-imx8mq/mkuserland-new.sh b/reform2-imx8mq/mkuserland-new.sh
index 22d1e6c..0f76a51 100755
--- a/reform2-imx8mq/mkuserland-new.sh
+++ b/reform2-imx8mq/mkuserland-new.sh
@@ -35,6 +35,9 @@ cp $ETC/reform* target-userland/etc
 cp $ETC/hostname target-userland/etc
 cp $ETC/hosts target-userland/etc
 
+# copy pulse config files that will be moved inside the target fs later
+cp $ETC/pulse/* target-userland/
+
 # mesa etc. patches
 mkdir -p target-userland/root/src
 cp -Rv template-userland/patches-mesa target-userland/root/src/patches-mesa
@@ -71,6 +74,11 @@ apt update
 
 apt install -y sway grim slurp xwayland xterm xfce4-terminal rofi arc-theme thunar policykit-1 libblockdev-dm2 libblockdev-crypto2 gnome-disk-utility cryptsetup  gnome-system-monitor eog evince mpv gedit engrampa connman-gtk gnome-icon-theme breeze-icon-theme fonts-noto-color-emoji lxpolkit mesa-utils w3m man-db pulseaudio pavucontrol python3-psutil
 
+# move pulse config in place
+# FIXME: this is brittle and should go into a .deb
+mv /analog-input-reform.conf /usr/share/pulseaudio/alsa-mixer/paths/
+mv /default.conf /usr/share/pulseaudio/alsa-mixer/profile-sets/
+
 # install applications
 
 apt install -y libreoffice libreoffice-gtk3 inkscape firefox-esr emacs gimp wmaker
diff --git a/reform2-imx8mq/template-etc/pulse/analog-input-reform.conf b/reform2-imx8mq/template-etc/pulse/analog-input-reform.conf
new file mode 100644
index 0000000..e2147f0
--- /dev/null
+++ b/reform2-imx8mq/template-etc/pulse/analog-input-reform.conf
@@ -0,0 +1,98 @@
+# This file is part of PulseAudio.
+#
+# PulseAudio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# PulseAudio is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
+
+; Analog input path for MNT Reform, which has a headset mic input
+; that is only on the left channel (mono).
+
+[General]
+priority = 100
+
+[Element Capture]
+switch = mute
+volume = ignore
+
+[Element Mic]
+required-absent = any
+
+[Element Mic Boost]
+required-absent = any
+
+[Element Dock Mic]
+required-absent = any
+
+[Element Dock Mic Boost]
+required-absent = any
+
+[Element Front Mic]
+required-absent = any
+
+[Element Front Mic Boost]
+required-absent = any
+
+[Element Int Mic]
+required-absent = any
+
+[Element Int Mic Boost]
+required-absent = any
+
+[Element Internal Mic]
+required-absent = any
+
+[Element Internal Mic Boost]
+required-absent = any
+
+[Element Rear Mic]
+required-absent = any
+
+[Element Rear Mic Boost]
+required-absent = any
+
+[Element Headset]
+required-absent = any
+
+[Element Headset Mic]
+required-absent = any
+
+[Element Headset Mic Boost]
+required-absent = any
+
+[Element Headphone Mic]
+required-absent = any
+
+[Element Headphone Mic Boost]
+required-absent = any
+
+[Element Line]
+required-absent = any
+
+[Element Line Boost]
+required-absent = any
+
+[Element Aux]
+required-absent = any
+
+[Element Video]
+required-absent = any
+
+[Element Mic/Line]
+required-absent = any
+
+[Element TV Tuner]
+required-absent = any
+
+[Element FM]
+required-absent = any
+
+.include analog-input.conf.common
diff --git a/reform2-imx8mq/template-etc/pulse/default.conf b/reform2-imx8mq/template-etc/pulse/default.conf
new file mode 100644
index 0000000..603aab1
--- /dev/null
+++ b/reform2-imx8mq/template-etc/pulse/default.conf
@@ -0,0 +1,24 @@
+[General]
+auto-profiles = yes
+
+[Mapping stereo-out]
+device-strings = hw:0
+fallback = yes
+channel-map = left,right
+paths-output = analog-output analog-output-speaker analog-output-headphones
+direction = output
+priority = 1
+
+[Mapping headset-mono-in]
+device-strings = hw:0
+fallback = yes
+channel-map = mono
+paths-input = analog-input-reform
+direction = input
+priority = 1
+
+[Profile output:stereo-out+input:mono-in]
+description = MNT Reform
+output-mappings = stereo-out
+input-mappings = headset-mono-in
+
-- 
GitLab