Floating Audio Level Controls - using yad

Moderator: Forum moderators

Post Reply
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Floating Audio Level Controls - using yad

Post by stemsee »

Provides Individual floating, audio level and equaliser (hardware or alsa)controls with mute switches. Each called from a neat six button panel with clear labels. BT, Volume, EQ, Alsa EQ, Mic and Profiles. Each can create many individual controls. Each time you click you select the channel/s to control. BT device must be set as default audio card first using saved Profiles.

1688208774.png
1688208774.png (104.98 KiB) Viewed 697 times

Code: Select all

#!/bin/ash
# Copyright [C] 2023 Marcos M Contant
# by stemsee
CARD=$(aplay -l | grep card | yad --title="$(gettext 'Select Sound Card')" --list --column="$(gettext 'Found Cards')" --geometry=500x300+200+200 | awk '{print $2}' | tr -d ':')
[ "$CARD" ] && export CARD || exit

function volumefn {

STAMER=$(amixer -c $CARD scontrols | yad --list --multiple --column="$(gettext 'Select Master')" --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") ##"'Playback Digital'"

[ ! "$STAMER" ] && exit || export STAMER
cnt=1
echo "$STAMER" | while read MASTER
do
function mutefn {
	amixer -c "$CARD" set "$1"  mute
}; export -f mutefn

function fnunmute {
	amixer -c "$CARD" set "$1"  unmute
}; export -f fnunmute

function volleft {
amixer -c "$CARD" set "$MASTER" frontleft ${2}%
}; export -f volleft

function volright {
amixer -c "$CARD" set "$MASTER" frontright ${2}%
}; export -f volright

export Vol=$(amixer -c $CARD get "$MASTER" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug="$IT" --tabnum=1 --text="$(gettext 'Left Volume')" --scale --vertical --print-partial --value="$Vol" | while read line; do volleft "$MASTER" "$line"; sleep 0.01; done &

yad --plug="$IT" --tabnum=2 --text="$(gettext 'Right Volume')" --scale --vertical --print-partial --value="$Vol" | while read line; do volright "$MASTER" "$line"; sleep 0.01; done &

yad --mouse --title="$MASTER $cnt" --window-icon="$camino/icons/speaker.png" --paned --width=220 --buttons-layout=center --height=340 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=110 --orient=hor --button="+/-$(gettext 'Mute')":"bash -c \"mutefn $MASTER  \"" --button="+/-$(gettext 'Mute')":"bash -c \"fnunmute $MASTER \"" &
cnt=$((cnt + 1))
done

}; export -f volumefn
function aeqfn {
 AEQ=$(amixer -D equal | grep Simple | yad --list --multiple --column=SelectMaster --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") 
[ ! "$AEQ" ] && exit || export AEQ
cnt=1
echo "$AEQ" | while read -r LEFT
read -r RIGHT
do
export LEFT RIGHT

function aeqvolleft {
amixer -D equal  set "$LEFT" ${2}%
}; export -f aeqvolleft

function aeqvolright {
amixer -D equal  set "$RIGHT"  ${2}%
}; export -f aeqvolright

export aeqVolL=$(amixer -D equal  get "$LEFT" | awk -v FS="[[%]" '/%/ {print $2}')
export aeqVolR=$(amixer -D equal  get "${RIGHT}" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"
yad --plug="$IT" --tabnum=1 --text="$LEFT" --scale --vertical --print-partial --value="$aeqVolL" | while read line; do aeqvolleft "$LEFT" "$line"; sleep 0.01; done &
yad --plug="$IT" --tabnum=2 --text="$RIGHT" --scale --vertical --print-partial --value="$aeqVolR" | while read line; do aeqvolright "$RIGHT" "$line"; sleep 0.01; done &
yad --mouse --title="$(gettext 'Alsa Equaliser') $cnt" --window-icon="$camino/icons/speaker.png" --paned --width=220 --buttons-layout=center --height=340 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=110 --orient=hor --no-buttons &
cnt=$((cnt + 1))
done
}; export -f aeqfn

function eqfn {
unset EQ
EQ=$(amixer -c $CARD scontrols | yad --list --multiple --column=SelectMaster --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") ##"'Playback Digital'"
[ ! "$EQ" ] && exit || export EQ
cnt=1
echo "$EQ" | while read -r LEFT
read -r RIGHT
do
export LEFT RIGHT
function eqmutefn {
	amixer -c "$CARD" set 'DAC EQ' unmute
}; export -f eqmutefn

function equnmute {
	amixer -c "$CARD" set 'DAC EQ' mute
}; export -f equnmute

function eqvolleft {
amixer -c "$CARD" set "$LEFT" ${2}%
}; export -f eqvolleft

function eqvolright {
amixer -c "$CARD" set "$RIGHT"  ${2}%
}; export -f eqvolright

export eqVolL=$(amixer -c $CARD get "$LEFT" | awk -v FS="[[%]" '/%/ {print $2}')
export eqVolR=$(amixer -c $CARD get "${RIGHT}" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"
yad --plug="$IT" --tabnum=1 --text="$LEFT" --scale --vertical --print-partial --value="$eqVolL" | while read line; do eqvolleft "$LEFT" "$line"; sleep 0.01; done &
yad --plug="$IT" --tabnum=2 --text="$RIGHT" --scale --vertical --print-partial --value="$eqVolR" | while read line; do eqvolright "$RIGHT" "$line"; sleep 0.01; done &
yad --mouse --title="$(gettext 'Hardware Equaliser') $cnt" --window-icon="$camino/icons/speaker.png" --paned --width=220 --buttons-layout=center --height=340 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=110 --orient=hor --button="+$(gettext 'Mute')":"bash -c \"eqmutefn $LEFT  \"" --button="-$(gettext 'Mute')":"bash -c \"equnmute $RIGHT \"" &
cnt=$((cnt + 1))
done
}; export -f eqfn

function volmicfn {
PHONE=$(amixer -c $CARD scontrols | yad --list --multiple --column=$(gettext 'Select Microphone') --width=300 --height=400 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/")
[ ! "$PHONE" ] && exit || export PHONE
cnt=1
echo "$PHONE" | while read  MIC 
do
export tVolM=$(amixer -c $CARD get "$MIC" | awk -v FS="[[%]" '/%/ {print $2}')
amixer -c '"$CARD"' set "$MIC" ${VolM}%
function tmutefn {
	amixer -c "$CARD" set "$1" toggle
}; export -f tmutefn

function tunmute {
	amixer -c "$CARD" set "$1" toggle
}; export -f tunmute

function tvolleft {
amixer -c "$CARD" set "$1" frontleft ${2}%
}; export -f tvolleft

function tvolright {
amixer -c "$CARD" set "$1" frontright ${2}%
}; export -f tvolright
function doitMICfn {
	amixer -c "$CARD" set "$1" toggle
}; export -f doitMICfn
IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --vertical --print-partial --value="$tVolM" | while read line; do tvolleft "$MIC" "$line"; tvolright "$MIC" "${line}"; sleep 0.01; done &
TEST=$(amixer -c $CARD get "$MIC" | grep off)
[ -z "$TEST" ] && export STATE="$(gettext 'UnMuted')" || export STATE="$(gettext 'Muted')"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitMICfn "$MIC";; Muted|off]) echo 2:UnMuted;doitMICfn "$MIC";; esac "' --field=':RO' "$STATE" &
yad --mouse --title="$MIC $cnt" --window-icon="$camino/icons/speaker.png" --paned --width=110 --height=340 --key=$IT --tab=Vol --tab=mute --splitter=30 --orient=ver --no-buttons &
cnt=$((cnt + 1))
done
}; export -f volmicfn

function volbtfn {
TB=$(amixer -M scontrols | grep -v 'Battery' | yad --list --multiple --column=SelectMaster --width=300 --height=200 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") ##"'Playback Digital'"
[ ! "$TB" ] && exit || export TB
cnt=1
echo "$TB" | while read BT
do
function mutebtfn {
	amixer -M set "$BT" mute
}; export -f mutebtfn

function fnbtunmute {
	amixer -M set "$BT" unmute
}; export -f fnbtunmute

function volleftbt {
	amixer -M set "$BT" frontleft ${2}%
}; export -f volleftbt

function volrightbt {
	amixer -M set "$BT" frontright ${2}%
}; export -f volrightbt

export Vol=$(amixer -M get "$BT" | awk -v FS="[[%]" '/%/ {print $2}')
IT="$(echo $RANDOM)"
yad --plug="$IT" --tabnum=1 --text="$(gettext 'Left Vol')" --scale --vertical --print-partial --value="$Vol" | while read line; do volleftbt "$BT" "$line"; sleep 0.01; done &
yad --plug="$IT" --tabnum=2 --text="$(gettext 'Right Vol')" --scale --vertical --print-partial --value="$Vol" | while read line; do volrightbt "$BT" "$line"; sleep 0.01; done &
yad --mouse --title="$BT $cnt" --window-icon="$camino/icons/speaker.png" --paned --width=220 --buttons-layout=center --height=340 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=110 --orient=hor  --button="+$(gettext 'Mute')":"bash -c mutebtfn" --button="-$(gettext 'Mute')":"bash -c fnbtunmute" &
cnt=$((cnt + 1))
done
}; export -f volbtfn

function profiles {
	ls /root/.config/snapp/profiles/*.asoundrc | yad --title="$(gettext 'Set Default Audio Card')" --geometry="400x140+200+200" --undecorated --skip-taskbar --no-buttons --list --column="$(gettext 'Choose Audio Card Profile')" --select-action="bash -c \"cp -f "%s" /root/.asoundrc \"" &
}; export -f profiles

yad  --on-top --undecorated --button="BT":"bash -c volbtfn" --button="$(gettext 'Volume')":"bash -c volumefn" --button="EQ":"bash -c eqfn"  --button="Alsa EQ":"bash -c aeqfn"  --button="Mic":"bash -c volmicfn" --button="$(gettext 'Profiles')":"bash -c profiles"  --on-top &

Last edited by stemsee on Sat Jul 01, 2023 11:17 am, edited 5 times in total.
User avatar
rockedge
Site Admin
Posts: 6481
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2693 times
Been thanked: 2592 times
Contact:

Re: Floating Audio Level Controls - using yad

Post by rockedge »

interesting little utility! I am going to try it out in some places

User avatar
MochiMoppel
Posts: 1222
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 20 times
Been thanked: 435 times

Re: Floating Audio Level Controls - using yad

Post by MochiMoppel »

Using FP96. None of the buttons works here.

Code: Select all

amixer: Unable to find simple control 'Playback Digital',0
amixer: Unable to find simple control 'Headphone',0
amixer: Unable to find simple control 'Capture Digital',0
amixer: Unable to find simple control 'Mic',0
User avatar
mikewalsh
Moderator
Posts: 6115
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 779 times
Been thanked: 1952 times

Re: Floating Audio Level Controls - using yad

Post by mikewalsh »

@stemsee :-

Neat idea. However, as Mochi has found out, this is very much going to be hardware dependent.

I've even had different Puppies, running on the same machine, that report a given function of the exact same audio chip in a totally different way.....necessitating modified lines in my own QuickAudioSwap utility on a "per-Puppy" basis.

Experimentation - and editing! - will, I strongly suspect, definitely be needed. And as I've discovered for myself - using the man pages - the permutations/combinations of various 'switches' & 'flags' for some aspects of ALSA functionality seem to be ENDLESS. :roll:

NOT criticism, you understand. Just observation, tempered by my own experience....

Mike. ;)

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

@MochiMoppel@mikewalsh Maybe generating a list of selectable controls from 'amixer' might help.

User avatar
mikewalsh
Moderator
Posts: 6115
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 779 times
Been thanked: 1952 times

Re: Floating Audio Level Controls - using yad

Post by mikewalsh »

stemsee wrote: Thu Feb 02, 2023 12:50 pm

@MochiMoppel @mikewalsh Maybe generating a list of selectable controls from 'amixer' might help.

Mm. Yah, sounds like a plan. It would give you a 'baseline' set of controls for the utility to work FROM in each Puppy. Which should make it easier to "initialize", perhaps?

Might also make it possible to enable 'user-selectable' controls, so the individual can generate their own custom 'control panel'. (Just throwing out ideas, here...)

Tell me if I'm getting ahead of myself! :D

Mike. ;)

User avatar
fredx181
Posts: 2997
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 364 times
Been thanked: 1272 times
Contact:

Re: Floating Audio Level Controls - using yad

Post by fredx181 »

For me only Headphones worked.

How can we discourage you from spending your precious time on trying to make this work ? :lol:

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

fredx181 wrote: Thu Feb 02, 2023 9:24 pm

For me only Headphones worked.

How can we discourage you from spending your precious time on trying to make this work ? :lol:

Ah! ... well ... I don't know how!

@mikewalsh
'amixer scontrols' into a yad list.
single click gets selection info with "amixer get '$selection'", maybe 'tree expansion' can be used here....not sure....i never used it.
user decides to create floating control with a doubleclick!
Control is created but, mute and or level might not work as expected!
But every control has either a toggle switch or a level, some have both, but none have neither!!!
Hopefully, the extra control will have no effect .... according to my brief tests it doesn't.

Yad --form with multiple :scl fields cannot work in realtime (without resorting to xdotool or something to read the scale setting), multiple mute switches can. So either individual floating units per control or use another front-end like gtkdialog or qt....but that's beyond my objective and skill.

User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

One motivation for this tool is that alsamixer cannot be used directly with a touch screen only device.

control selection list example, double click to mute!

Code: Select all

 amixer scontrols  | grep -e 'Playback' -e 'Mic' -e 'Speaker' -e 'Headphone' -e 'Headset' -e 'Mixer' -e 'EQ' -e 'Master' -e 'Vol' | grep -v -e 'Filter' -e 'filter' |  cut -f2 -d"'" | yad --list  --columns=1 --column=Selection:txt  --select-action="bash -c \"create_gui "%s" \"" --dclick-action="bash -c \"amixer set "%s" toggle \"" &
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

It's as far as I can go .... problems with quoting!

Code: Select all

#!/bin/sh
# with a snippet of code from step
#

function doitfn {
	amixer set "$1" toggle
}; export -f doitfn

function VolMutefn () {
CTRL="$1 $2 $3 $4"
echo $CTRL > /tmp/test2
CTRL=$(echo $CTRL | sed -e "s/^/'/" -e "s/$/'/")
echo -e $CTRL >> /tmp/test2
export Vol=$(amixer -M get "$CTRL" | awk -v FS="[[%]" '/%/ {print $2}')
amixer sset "$CTRL" ${Vol}%
IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VOL" | while read line; do amixer set "$CTRL" ${line}%; done &
TEST=$(amixer get "$CTRL" | grep off)
[ -z "$TEST" ] && export STATE="Unmuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in Unmuted]) echo 2:Muted;doitfn;; Muted) echo 2:Unmuted;doitfn "$CTRL";; esac"' --field=':RO' "$STATE" &
yad --mouse --title="$CTRL" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f VolMutefn

function create_guifn {
echo "$1" | while read line; do echo -e "--button=\"$line\":\"bash -c 'VolMutefn $line'\"" >> /tmp/test; done
STRING=$(cat /tmp/test | while read line; do echo "$line" | tr '\n' ' ';done)
echo "$STRING" > /tmp/test
yad  --undecorated --on-top $STRING &
}; export -f create_guifn

SELECTED=$(amixer scontrols | grep -e 'Playback' -e 'Mic' -e 'Speaker' -e 'Headphone' -e 'Headset' -e 'Mixer' -e 'EQ' -e 'Master' -e 'Vol' | grep -v -e 'Filter' -e 'filter' | cut -f2 -d"'" | yad --list --multiple --columns=1 --column=Selection:txt --select-action="bash -c \"create_gui "%s" \"" --dclick-action="bash -c \"amixer set "%s" toggle \"" | while read line; do
    echo "$line" | cut -f1 -d'|';done) 
create_guifn "$SELECTED"
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

Here is a huge update!

Four controls for card 0, one controller for card 1 (my bluetooth speaker), and one reset button when wanting to reselect controls for each widget.

The selection bar opens as usual, after clicking on a button a yad list channel select opens to choose which control to pass to the widget. Then the actual widget opens.

The Master Volume widget has two sliders, left and right volume, to give balance control, plus mute and unmute buttons.

Code: Select all

#!/bin/sh
# by stemsee
# Copyright 2023 (C) Marcos M Contant
# gpl3 license applies
# do as you wish with it but attribute credit to the copyright holder
#
[ -f /root/.audio-mixer ] && . /root/.audio-mixer 2>/dev/null

export MASTER
export HEADP
export HEADMIC
export BT
export MIC

function mutefn {
	amixer set "$1" mute
}; export -f mutefn

function fnunmute {
	amixer set "$1" unmute
}; export -f fnunmute

function volleft {
	amixer -c 0 set "$1" frontleft ${2}%
}; export -f volleft

function volright {
	amixer -c 0 set "$1" frontright ${2}%
}; export -f volright

function doitfn {
	amixer set "$1" toggle
}; export -f doitfn

function volumefn {
[ -z "$MASTER" ] && export MASTER=$(amixer -c 0 scontrols | yad --list --column=SelectMaster --width=400 --height=600 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") ##"'Playback Digital'"
[ -z "$MASTER" ] && exit

echo "MASTER=\"$MASTER\"" >> /root/.audio-mixer
export Vol=$(amixer -c 0 -M get "$MASTER" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"
yad --plug="$IT" --tabnum=1 --text="Left Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MASTER" "$line"; sleep 0.02; done &
yad --plug="$IT" --tabnum=2 --text="Right Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volright "$MASTER" "$line"; sleep 0.02; done & 
yad --mouse --title="$MASTER" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=70 --orient=vert --button="+Mute":"bash -c \"mutefn $MASTER \"" --button="-Mute":"bash -c \"fnunmute $MASTER \"" &
}; export -f volumefn

#--columns=1 --field="Balance:sl" --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) doitfn;echo 3:Muted;; Muted|off]) echo 3:UnMuted;doitfn;; esac"' --field=':RO' "$STATE" &

function volmicfn {
[ -z "$MIC" ] && export MIC=$(amixer -c 0 scontrols | yad --list --column=SelectMic --width=400 --height=600 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 
[ -z "$MIC" ] && exit

echo "MIC=\"$MIC\"" >> /root/.audio-mixer
export VolM=$(amixer -c 0 -M get "$MIC" | awk -v FS="[[%]" '/%/ {print $2}')
amixer sset "$MIC" ${VolM}%

IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MIC" "$line"; volright "$MIC" "${line}"; sleep 0.02; done &
TEST=$(amixer -c 0 get "$MIC" | grep off)
[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitfn;; Muted|off]) echo 2:UnMuted;doitfn;; esac"' --field=':RO' "$STATE" &
yad --mouse --title="$MIC" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f volmicfn

function volheadphonesfn {
[ -z "$HEADP" ] && export HEADP=$(amixer -c 0 scontrols | yad --list --column=SelectHeadphone --width=400 --height=600 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 
[ -z "$HEADP" ] && exit

echo "HEADP=\"$HEADP\"" >> /root/.audio-mixer

export VolP=$(amixer -c 0 -M get "$HEADP" | awk -v FS="[[%]" '/%/ {print $2}')
IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VolP" | while read line; do volleft "$HEADP" "${line}"; volright "$HEADP" "$line"; sleep 0.02; done &
TEST=$(amixer -c 0 get "$HEADP" | grep off)
[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;amixer set "$HEADP" toggle;; Muted|off]) echo 2:UnMuted;amixer set "$HEADP" toggle;; esac"' --field=':RO' "$STATE" &
yad --mouse --title="$HEADP" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f volheadphonesfn

function volheadmicfn {
[ -z "$HEADMIC" ] && export HEADMIC=$(amixer -c 0 scontrols | yad --list --column=SelectHeadMic --width=400 --height=600 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 
[ -z "$HEADMIC" ] && exit

echo "HEADMIC=\"$HEADMIC\"" >> /root/.audio-mixer

export VolHM=$(amixer -c 0 -M get "$HEADMIC" | awk -v FS="[[%]" '/%/ {print $2}')
TEST=$(amixer -c 1 -D default get "$HEADMIC" | grep off)
[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitbtfn;; Muted|off]) echo 2:UnMuted;doitbtfn;; esac"' --field=':RO' "$STATE" &

IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VolHM" | while read line; do volleft "$HEADMIC" "${line}"; volright "$HEADMIC" "$line"; sleep 0.02; done &
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitfn "$HEADMIC";; Muted|off]) echo 2:UnMuted;doitfn "$HEADMIC";; esac"' --field=':RO' "$STATE" &
yad --mouse --title="$HEADMIC" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f volheadmicfn
function doitbtfn {
	amixer set "$BT" toggle
}; export -f doitbtfn
function volbtfn {
[ -z "$BT" ] && export BT=$(amixer -c 1 scontrols | yad --list --column=SelectBT --width=400 --height=600 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 
[ -z "$BT" ] && exit
echo "BT=\"$BT\"" >> /root/.audio-mixer
export VolBT=$(amixer -c 1 -M get "$BT" | awk -v FS="[[%]" '/%/ {print $2}')
IT="$(echo $RANDOM)"
yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VolBT" | while read line; do volleft "$BT" "${line}"; volright "$BT" "$line"; sleep 0.02; done &
TEST=$(amixer -c 1 -D default get "$BT" | grep off)
[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"
yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitbtfn;; Muted|off]) echo 2:UnMuted;doitbtfn;; esac"' --field=':RO' "$STATE" &
yad --mouse --title="$BT" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f volbtfn

case "$1" in
	headphones|volheadmicfn) volheadmicfn;;
	headmic|volheadphonesfn) volheadphonesfn;;
	mics|volmicfn) volmicfn;;
	volume|volumefn) volumefn;;
	bt|BTvol|volbtfn) volbtfn;;
esac

yad  --on-top --undecorated --button="Card 1 bt":"bash -c volbtfn" --button="Master Volume":"bash -c volumefn" --button="Headphones":"bash -c volheadphonesfn" --button="Mic":"bash -c volmicfn" --button="Headset Mic":"bash -c volheadmicfn" --button="reset":"bash -c 'rm -f /root/.audio-mixer'" &
audiolevels.png
audiolevels.png (436.07 KiB) Viewed 874 times
Last edited by stemsee on Sat Apr 22, 2023 8:39 am, edited 1 time in total.
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

Bluetooth audio controls is difficult to implement automatically.

For bluetooth, on fatdog at least, it is necessary to connect and set it as the default soundcard. Then you can use

Code: Select all

amixer -M scontrols

to select device controls.

This update handles bluetooth better!

Code: Select all

#!/bin/sh
# by stemsee
# Copyright 2023 (C) Marcos M Contant
# gpl3 license applies
# do as you wish with it but attribute credit to the copyright holder
#
#[ -f /root/.audio-mixer-MIC ] && . /root/.audio-mixer-MIC 2>/dev/null
#[ -f /root/.audio-mixer-MASTER ] && . /root/.audio-mixer-MASTER 2>/dev/null
#[ -f /root/.audio-mixer-HEADMIC ] && . /root/.audio-mixer-HEADMIC 2>/dev/null
#[ -f /root/.audio-mixer-HEADP ] && . /root/.audio-mixer-HEADP 2>/dev/null
#[ -f /root/.audio-mixer-BT ] && . /root/.audio-mixer-BT 2>/dev/null



#
#export HEADP
#export HEADMIC
#export BT
#export MIC



# determine COPY/PASTE command
if [ ! -z `busybox which xsel` ]; then
	export CLIP="xsel -o -p"
elif [ ! -z `busybox which xclip` ]; then
	export CLIP="xclip -o -p"
elif [ ! -z `busybox which clipit` ]; then
	export CLIP="clipit -p"
fi

export CARD=$(aplay -l | grep card | yad --title "Select Sound Card" --list --column="Found Cards" --geometry=500x300+200+200| awk '{print $2}' | tr -d ':')  "$CARD" 
[ "$CARD" ] && export CARD || exit
function mutefn {
	
	amixer -c $CARD set "$1" mute
	
}; export -f mutefn

function fnunmute {
	
	amixer -c $CARD set "$1" unmute
	
}; export -f fnunmute

function volleft {
	
	amixer -c $CARD set "$1" frontleft ${2}%
	
}; export -f volleft

function volright {
	
	amixer -c $CARD set "$1" frontright ${2}%
	
}; export -f volright

function doitfn {
	
	amixer -c $CARD set "$1" toggle
	
}; export -f doitfn
function doitMICfn {
	
	amixer -c $CARD set "$(cat /root/.audio-mixer-MIC)" toggle
	
}; export -f doitMICfn

function volumefn {

[ ! "$MASTER" ] && export MASTER=$(amixer -c $CARD scontrols | yad --list --column=SelectMaster --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") ##"'Playback Digital'"

[ ! "$MASTER" ] && exit || export MASTER
echo "MASTER=\"$MASTER\"" > /root/.audio-mixer-MASTER

export Vol=$(amixer -c $CARD get "$MASTER" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug="$IT" --tabnum=1 --text="Left Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MASTER" "$line"; sleep 0.02; done &

yad --plug="$IT" --tabnum=2 --text="Right Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volright "$MASTER" "$line"; sleep 0.02; done & 

yad --mouse --title="$MASTER" --window-icon="$camino/icons/speaker.png" --paned --width=210 --buttons-layout=center --height=140 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=70 --orient=vert --button="+Mute":"bash -c \"mutefn $MASTER \"" --button="-Mute":"bash -c \"fnunmute $MASTER \"" &

}; export -f volumefn


function volmicfn {

[ ! "$MIC" ] && export MIC=$(amixer -c $CARD scontrols | yad --list --column=SelectMic --width=300 --height=400 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 

[ ! "$MIC" ] && exit || export MIC 

echo "MIC=\"$MIC\"" >> /root/.audio-mixer-MIC

export VolM=$(amixer -c $CARD get "$MIC" | awk -v FS="[[%]" '/%/ {print $2}')

amixer -c $CARD set "$MIC" ${VolM}%

IT="$(echo $RANDOM)"

yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MIC" "$line"; volright "$MIC" "${line}"; sleep 0.02; done &

TEST=$(amixer -c $CARD get "$MIC" | grep off)

[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"

yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c \"case %2 in UnMuted|on]) echo 2:Muted;doitMICfn "$MIC";; Muted|off]) echo 2:UnMuted;doitMICfn "$MIC";; esac \"' --field=':RO' "$STATE" &

yad --mouse --title="$MIC" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &

}; export -f volmicfn

function volheadphonesfn {

[ ! "$MHEADP" ] &&  export HEADP=$(amixer -c $CARD scontrols | yad --list --column=SelectHeadphone --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 

[ ! "$HEADP" ] && export HEADP || exit

echo "HEADP=\"$HEADP\"" > /root/.audio-mixer-HEADP

export VolP=$(amixer -c $CARD get "$HEADP" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VolP" | while read line; do volleft "$HEADP" "${line}"; volright "$HEADP" "$line"; sleep 0.02; done &

TEST=$(amixer -c $CARD get "$HEADP" | grep off)

[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"

yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c \"case %2 in UnMuted|on]) echo 2:Muted;amixer -c $CARD set "$HEADP" toggle;; Muted|off]) echo 2:UnMuted;amixer -c $CARD set "$HEADP" toggle;; esac \"' --field=':RO' "$STATE" &

yad --mouse --title="$HEADP" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &

}; export -f volheadphonesfn

function volheadmicfn {
	
[ ! "$HEADMIC" ] && export HEADMIC=$(amixer -c $CARD scontrols | yad --list --column=SelectHeadMic --width=300 --height=400 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") 

[ "$HEADMIC" ] && export HEADMIC || exit

echo "HEADMIC=\"$HEADMIC\"" > /root/.audio-mixer-HEADMIC

export VolHM=$(amixer -c $CARD get "$HEADMIC" | awk -v FS="[[%]" '/%/ {print $2}')

TEST=$(amixer -c $CARD get "$HEADMIC" | grep off)

[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"

yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitbtfn;; Muted|off]) echo 2:UnMuted;doitbtfn;; esac"' --field=':RO' "$STATE" &

IT="$(echo $RANDOM)"

yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="$VolHM" | while read line; do volleft "$HEADMIC" "${line}"; volright "$HEADMIC" "$line"; sleep 0.02; done &

yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c \"case %2 in UnMuted|on]) echo 2:Muted;doitfn "$HEADMIC";; Muted|off]) echo 2:UnMuted;doitfn "$HEADMIC";; esac \"' --field=':RO' "$STATE" &

yad --mouse --title="$HEADMIC" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &
}; export -f volheadmicfn


function mutebtfn {
	
	amixer -M set "$1" mute
	
}; export -f mutebtfn

function fnbtunmute {
	
	amixer -M set "$1" unmute
	
}; export -f fnbtunmute

function volleftbt {
	
	amixer -M set "$1" frontleft ${2}%
	
}; export -f volleftbt

function volrightbt {
	
	amixer -M set "$1" frontright ${2}%
	
}; export -f volrightbt
function volbtfn {

[ ! "$BT" ] && export BT=$(amixer -M scontrols | yad --list --column=SelectMaster --width=300 --height=200 | cut -f2 -d"'" | sed -e "s/^/\\'/" -e "s/$/\\'/") ##"'Playback Digital'"

[ ! "$BT" ] && exit || export BT

export Vol=$(amixer -M get "$BT" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug="$IT" --tabnum=1 --text="Left Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volleftbt "$BT" "$line"; sleep 0.01; done &

yad --plug="$IT" --tabnum=2 --text="Right Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volrightbt "$BT" "$line"; sleep 0.01; done & 

yad --mouse --title="$MASTER" --window-icon="$camino/icons/speaker.png" --paned --width=210 --buttons-layout=center --height=140 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=70 --orient=vert --button="+Mute":"bash -c \"mutebtfn $BT \"" --button="-Mute":"bash -c \"fnbtunmute $BT \"" &

}; export -f volbtfn


case "$1" in 
	headphones|volheadmicfn) volheadmicfn;;
	headmic|volheadphonesfn) volheadphonesfn;;
	mics|volmicfn) volmicfn;;
	volume|volumefn) volumefn;;
	bt|BTvol|volbtfn) volbtfn;;
esac


yad  --on-top --undecorated --button="BT":"bash -c volbtfn" --button="Master Volume":"bash -c volumefn" --button="Headphones":"bash -c volheadphonesfn" --button="Mic":"bash -c volmicfn" --button="Headset Mic":"bash -c volheadmicfn"  --on-top &
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

updae....see post 1

Code: Select all

#!/bin/sh
# by stemsee
# Copyright (C) 2023  Marcos M Contant
# gpl3 license applies
# do as you wish with it but attribute credit to the copyright holder
#

CARD=$(aplay -l | grep card | yad --title "Select Sound Card" --list --column="Found Cards" --geometry=500x300+200+200 | awk '{print $2}' | tr -d ':')
[ "$CARD" ] && export CARD || exit

function volumefn {

[ ! "$MASTER" ] && export MASTER=$(amixer -c $CARD scontrols | yad --list --column=SelectMaster --width=300 --height=300 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") ##"'Playback Digital'"

[ ! "$MASTER" ] && exit || export MASTER
function mutefn {
	amixer -c "$CARD" set "$MASTER" mute
}; export -f mutefn

function fnunmute {
	amixer -c "$CARD" set "$MASTER" unmute
}; export -f fnunmute

function volleft {
amixer -c "$CARD" set "$MASTER" frontleft ${2}%
}; export -f volleft

function volright {
amixer -c "$CARD" set "$MASTER" frontright ${2}%
}; export -f volright

export Vol=$(amixer -c $CARD get "$MASTER" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug="$IT" --tabnum=1 --text="Left Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MASTER" "$line"; sleep 0.02; done &

yad --plug="$IT" --tabnum=2 --text="Right Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volright "$MASTER" "$line"; sleep 0.02; done &

yad --mouse --title="$MASTER" --window-icon="$camino/icons/speaker.png" --paned --width=210 --buttons-layout=center --height=140 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=70 --orient=vert --button="+Mute":"bash -c "mutefn $MASTER "" --button="-Mute":"bash -c "fnunmute $MASTER "" &

}; export -f volumefn

function volmicfn {

[ ! "$MIC" ] && export MIC=$(amixer -c $CARD scontrols | yad --list --column=SelectMic --width=300 --height=400 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/")

[ ! "$MIC" ] && exit || export MIC

export VolM=$(amixer -c $CARD get "$MIC" | awk -v FS="[[%]" '/%/ {print $2}')

amixer -c '"$CARD"' set "$MIC" ${VolM}%
function mutefn {
	amixer -c "$CARD" set "$MIC" mute
}; export -f mutefn

function fnunmute {
	amixer -c "$CARD" set "$MIC" unmute
}; export -f fnunmute

function volleft {
amixer -c "$CARD" set "$MIC" frontleft ${2}%
}; export -f volleft

function volright {
amixer -c "$CARD" set "$MIC" frontright ${2}%
}; export -f volright
function doitMICfn {
	amixer -c "$CARD" set "$MIC" toggle
}; export -f doitMICfn
IT="$(echo $RANDOM)"

yad --plug=$IT --tabnum=1 --scale --orient=vert --print-partial --value="70" | while read line; do volleft "$MIC" "$line"; volright "$MIC" "${line}"; sleep 0.02; done &

TEST=$(amixer -c $CARD get "$MIC" | grep off)

[ -z "$TEST" ] && export STATE="UnMuted" || export STATE="Muted"

yad --plug=$IT --tabnum=2 --form --columns=1 --field='!gtk-ok!:fbtn' '@sh -c "case %2 in UnMuted|on]) echo 2:Muted;doitMICfn "$MIC";; Muted|off]) echo 2:UnMuted;doitMICfn "$MIC";; esac "' --field=':RO' "$STATE" &

yad --mouse --title="$MIC" --window-icon="$camino/icons/speaker.png" --paned --width=200 --height=140 --key=$IT --tab=Vol --tab=mute --splitter=50 --orient=vert --no-buttons &

}; export -f volmicfn


function volbtfn {

[ ! "$BT" ] && export BT=$(amixer -M scontrols | grep -v 'Battery' | yad --list --column=SelectMaster --width=300 --height=200 | cut -f2 -d"'" | sed -e "s/^/'/" -e "s/$/'/") ##"'Playback Digital'"

[ ! "$BT" ] && exit || export BT

function mutebtfn {
	amixer -M set "$BT" mute
}; export -f mutebtfn

function fnbtunmute {
	amixer -M set "$BT" unmute
}; export -f fnbtunmute

function volleftbt {
	amixer -M set "$BT" frontleft ${2}%
}; export -f volleftbt

function volrightbt {
	amixer -M set "$BT" frontright ${2}%
}; export -f volrightbt

export Vol=$(amixer -M get "$BT" | awk -v FS="[[%]" '/%/ {print $2}')

IT="$(echo $RANDOM)"

yad --plug="$IT" --tabnum=1 --text="Left Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volleftbt "$BT" "$line"; sleep 0.01; done &

yad --plug="$IT" --tabnum=2 --text="Right Vol" --scale --orient=vert --print-partial --value="70" | while read line; do volrightbt "$BT" "$line"; sleep 0.01; done &

yad --mouse --title="$BT" --window-icon="$camino/icons/speaker.png" --paned --width=210 --buttons-layout=center --height=140 --key=$IT --tab="Vol Left" --tab="Vol Right" --splitter=70 --orient=vert  --button="+Mute":"bash -c mutebtfn" --button="-Mute":"bash -c fnbtunmute" &

}; export -f volbtfn

yad  --on-top --undecorated --button="BT":"bash -c volbtfn" --button="Master Volume":"bash -c volumefn" --button="Mic":"bash -c volmicfn"  --on-top &


User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

This is evolving.

Now there is the ability to replace your /root/.asoundrc profile which on fatdog sets your default soundcard, some apps will only play audio through the default system card, like browsers! By copying your .asoundrc for each card and naming*.asoundrc the 'setter' will list them and selecting one will copy it to /root/.asoundrc. It works instantly to set your default profile, so you can set it then start an app. Then set with another profile and start another app which then uses that profile. Control the sound sent to different bluetooth devices and or speakers. I tested with a bluetooth speaker, bluetooth earphones, and builtin sound card. Each time I started a vlc and each one played with the set device. Probably only useful on fatdog. Any way this code will now be included in S.N.ApP

xscreenshot-20230507T121435.png
xscreenshot-20230507T121435.png (53.46 KiB) Viewed 794 times
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

Next update has multiple selections. This primarily helps to create mono or stereo pairs in sequence....my 5 band hardware equalizer now configures with 3dual channel sliders.

1685740287.png
1685740287.png (76.08 KiB) Viewed 757 times
User avatar
stemsee
Posts: 759
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 184 times
Been thanked: 126 times

Re: Floating Audio Level Controls - using yad

Post by stemsee »

Now can provide controls for the alsa equaliser which has 10 bands, actually 20 - 10 left and 10 right, but for now we just use them as 10 pairs.

1688208774.png
1688208774.png (104.98 KiB) Viewed 724 times

See post 1 for script.

Post Reply

Return to “Utilities”