<br><br><div class="gmail_quote">On Fri, Nov 14, 2008 at 3:29 AM, Michael T. Dean <span dir="ltr"><<a href="mailto:mtdean@thirdcontact.com">mtdean@thirdcontact.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On 11/14/2008 01:41 AM, Nick Morrott wrote:<br>
> One way to accomplish this across all of MythTV is to disable "Use<br>
> internal volume controls" in the particular mythfrontend's<br>
> configuration. You can bind your VOL+/VOL- remote keys to scripts<br>
> which control the ALSA system/PCM volume using amixer directly.<br>
><br>
> A script which increases the ALSA PCM volume by 5% each time it is<br>
> called could be:<br>
><br>
> #!/bin/bash<br>
> /path/to/amixer - c 0 set PCM 5%+<br>
><br>
<br>
</div>Though an approach like this will have issues when running up against<br>
the limits (i.e. 0% or 100%) and can get "stuck" due to rounding error,<br>
depending on the card/resolution of the volume slider. I posted a<br>
script a while ago (<br>
<a href="http://www.gossamer-threads.com/lists/mythtv/users/216149#216149" target="_blank">http://www.gossamer-threads.com/lists/mythtv/users/216149#216149</a> ) that<br>
handles these and many other issues, and have improved it since (see<br>
attached).<br>
<div class="Ih2E3d"><br>
> The amixer manpage contains the details. These will not show anything<br>
> on the screen (so not trigger the OSD)<br>
<br>
</div>The script I posted will (the current one using either mythtvosd or<br>
xosd's osd_cat). ;)<br>
<br>
You'll need to configure the script by editing the variable values at<br>
the top as described in the comments.<br>
<br>
Mike<br>
<br>#!/bin/bash<br>
# volume<br>
#<br>
# Copyright 2007, Michael T. Dean (mtdean at thirdcontact dt com)<br>
#<br>
# This program is free software; you can redistribute it and/or modify it under<br>
# the terms of the GNU General Public License as published by the Free Software<br>
# Foundation; either version 2 of the License, or (at your option) any later<br>
# version.<br>
#<br>
# This program is distributed in the hope that it will be useful, but WITHOUT<br>
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS<br>
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more<br>
# details.<br>
#<br>
# You should have received a copy of the GNU General Public License along with<br>
# this program; if not, write to the Free Software Foundation, Inc., 51<br>
# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br>
#<br>
# Description:<br>
# This script can be used to adjust the volume of any control provided by your<br>
# sound card and can optionally display a message using either xosd or<br>
# mythtvosd. The script is useful to MythTV users whose sound cards require<br>
# changing some volume control other than PCM or Master (the only two choices<br>
# MythTV supports) or who wish to modify multiple controls; or to anyone<br>
# wishing to add a low-dependency volume control with OSD to any system using,<br>
# for example, multimedia keys (i.e. XF86AudioRaiseVolume,<br>
# XF86AudioLowerVolume, XF86AudioMute) or LIRC.<br>
#<br>
# Version: 0.2<br>
#<br>
# Revision History:<br>
# 0.2 (20070310): complete rewrite; added support for xosd; added volume<br>
# control override; added mute toggle; changed script to use<br>
# control limits (rather than percents--which pose rounding<br>
# problems); each control is modified relative to current<br>
# value (instead of setting all to the same value); removed<br>
# usage of linefeed IFS; added error checking and defaults<br>
# for robustness; put some code in functions<br>
# 0.1 (20060123): initial version<br>
#<br>
# Quickstart:<br>
# Verify your amixer reports sane values as described in the first paragraph<br>
# of "Usage" below. Then, run the script as shown below:<br>
# ./volume up PCM<br>
# ./volume down PCM<br>
# ./volume mute PCM<br>
# ./volume unmute PCM<br>
# ./volume toggle PCM<br>
#<br>
# Usage:<br>
# volume {up|down|mute|unmute|toggle} [control1 [control2 [...]]]<br>
#<br>
# First, verify that amixer reports sane values for the control limits and<br>
# current volume. Control limits must be specified in the format " Limits:<br>
# Playback 0 - 31" in any line of output. Current volume must be specified<br>
# in the format "<anything>: Playback 28 [90%]" in any line of output.<br>
# Please test that your version of amixer does this for each control you've<br>
# specified in VOLUME_CONTROLS or you may blow out your speakers.<br>
#<br>
# Then, modify the default values specified below to allow usage of the<br>
# script in most cases without listing control names in the command line<br>
# (i.e. ./volume {up|down|mute|unmute|toggle}).<br>
#<br>
# To use with multimedia keys or other keyboard controls, map the appropriate<br>
# commands to the desired keys in your window manager's or some other key<br>
# handler's keybindings.<br>
#<br>
# To use with LIRC, you must run irexec (i.e. add the lines, "killall irexec"<br>
# and "irexec -d" (no quotes)--and in the order given)--to your X start<br>
# script (i.e. ~/.xinitrc). Then, add the following lines to your LIRC<br>
# configuration (i.e. ~/.lircrc) and adjust button names and config path as<br>
# appropriate:<br>
#<br>
# begin<br>
# prog = irexec<br>
# button = volume-up<br>
# config = /path/to/volume up &<br>
# repeat = 2<br>
# end<br>
# begin<br>
# prog = irexec<br>
# button = volume-down<br>
# config = /path/to/volume down &<br>
# repeat = 2<br>
# end<br>
# begin<br>
# prog = irexec<br>
# button = mute<br>
# config = /path/to/volume mute &<br>
# config = /path/to/volume unmute &<br>
# repeat = 0<br>
# end<br>
#<br>
<br>
# Modify the following default values as appropriate for your system.<br>
<br>
# Set the VOLUME_CONTROLS to the array of volume controls you want the script<br>
# to adjust. Place spaces (no commas) between elements of the array. Use<br>
# single quotes around elements with spaces, and optionally on elements without<br>
# spaces).<br>
# The list of volume controls may be overriden by specifying the names of<br>
# controls to modify at the end of the command-line. When overriding the<br>
# volume controls, each control will be adjusted by only 1 unit. See, also,<br>
# MIXER_ADJ_AMOUNT, below.<br>
#VOLUME_CONTROLS=('PCM' 'Surround' 'Center' 'LFE' 'Analog Front')<br>
#VOLUME_CONTROLS=('PCM')<br>
VOLUME_CONTROLS=('Master')<br>
<br>
# Set the MIXER_ADJ_AMOUNT to the array of the desired number of units by which<br>
# you want to adjust the volume of each control specified in VOLUME_CONTROLS.<br>
# You should specify the same number of adjustments as you specified controls<br>
# in VOLUME_CONTROLS.<br>
# The units used are specific to the sound card control. The range of<br>
# available values is reported by "amixer sget <control>" on the line that<br>
# starts with " Limits:" and may differ for the controls you've specified.<br>
# By choosing appropriate values, you can ensure all controls change by the<br>
# same relative volume.<br>
# If not specified, all controls will be adjusted by 1 unit.<br>
#MIXER_ADJ_AMOUNT=(1 1 1 1 1)<br>
#MIXER_ADJ_AMOUNT=(1)<br>
<br>
# Set the OSD_VOLUME_CONTROL to the name of the ALSA control whose volume<br>
# should be reported when using the OSD.<br>
# This control must be included in VOLUME_CONTROLS above or the volume will<br>
# always be set to the same value;<br>
# If not specified, the first value in VOLUME_CONTROLS will be used.<br>
#OSD_VOLUME_CONTROL='Center'<br>
#OSD_VOLUME_CONTROL='PCM'<br>
#OSD_VOLUME_CONTROL='Master'<br>
<br>
# Display the current volume using the specified OSD application (Currently,<br>
# only 'xosd' and 'mythtvosd' are supported). Use '' or comment out if you do<br>
# not want to display the volume<br>
# Note that if using mythtvosd, the volume message will only be displayed when<br>
# using Myth's internal player to play back videos. When using xosd, the<br>
# volume message will be displayed whether playing back videos or in the<br>
# frontend menus (or anywhere else in X).<br>
USE_OSD='xosd'<br>
#USE_OSD='mythtvosd'<br>
#USE_OSD=''<br>
<br>
# OSD application executables.<br>
# Provide the full path to the executable if it is not in your PATH.<br>
XOSD='osd_cat'<br>
MYTHTVOSD='mythtvosd'<br>
<br>
# Arguments to pass to xosd (do not specify -b, -P, and -T).<br>
# This is the location at which to specify font, position, alignment, offset,<br>
# delay, lines, shadow, and color<br>
XOSD_ARGS='-f -adobe-helvetica-bold-r-normal-*-*-240-100-100-p-*-iso8859-1 -p bottom -A center -o 80 -d 1 -l 1 -s 2 -c Green'<br>
<br>
# xosd barmode to use--either percentage or slider<br>
XOSD_BARMODE=percentage<br>
#XOSD_BARMODE=slider<br>
<br>
# Set the BROADCAST_ADDRESS to the address of the frontend on which you want to<br>
# display the volume OSD when using mythtvosd.<br>
# Using <a href="http://127.0.0.1" target="_blank">127.0.0.1</a> will generally work.<br>
BROADCAST_ADDRESS='<a href="http://127.0.0.1" target="_blank">127.0.0.1</a>'<br>
<br>
# No changes should be required below this line.<br>
<br>
ACTION=$1<br>
shift<br>
<br>
if [ $# -gt 0 ]; then<br>
unset VOLUME_CONTROLS MIXER_ADJ_AMOUNT OSD_VOLUME_CONTROL<br>
for INDEX in `seq 0 $(($# - 1))`; do<br>
VOLUME_CONTROLS[${INDEX}]="$1"<br>
shift<br>
done<br>
fi<br>
<br>
if [ "x${OSD_VOLUME_CONTROL}" = "x" ]; then<br>
OSD_VOLUME_CONTROL=${VOLUME_CONTROLS[0]}<br>
fi<br>
<br>
NUM_CONTROLS=$((${#VOLUME_CONTROLS[*]} - 1))<br>
<br>
set_volume() {<br>
for INDEX in `seq 0 ${NUM_CONTROLS}`; do<br>
unset CONTROL RANGE VOLUME ADJUST_AMOUNT<br>
CONTROL=${VOLUME_CONTROLS[$INDEX]}<br>
<br>
if [ "x${CONTROL}" = "x" ]; then<br>
continue<br>
fi<br>
<br>
# Relies on amixer reporting limits in the format<br>
# " Limits: Playback 0 - 31" in any line of output. Please test that<br>
# your version of amixer does this for each control you've specified in<br>
# VOLUME_CONTROLS or you may blow out your speakers.<br>
RANGE=(`amixer sget "${CONTROL}" | awk '/Limits/ {split($0,a); print a[3] " " a[5]; exit }'`)<br>
<br>
if [ "x${RANGE[0]}" = "x" -o "x${RANGE[1]}" = "x" ]; then<br>
# Couldn't get the range. Skip this control<br>
continue<br>
fi<br>
<br>
# Relies on amixer reporting volume in the format<br>
# "<anything>: Playback 28 [90%]" in any line of output. Please test<br>
# that your version of amixer does this for each control you've specified<br>
# in VOLUME_CONTROLS or you may blow out your speakers.<br>
VOLUME=`amixer sget "${CONTROL}" | awk '/[%]/ {split($0,a,":"); split(a[2],a); print a[2]; exit}'`<br>
<br>
if [ "x${VOLUME}" = "x" ]; then<br>
# Couldn't get the volume. Skip this control<br>
continue<br>
fi<br>
<br>
ADJUST_AMOUNT=${MIXER_ADJ_AMOUNT[$INDEX]}<br>
if [ "x${ADJUST_AMOUNT}" = "x" ]; then<br>
ADJUST_AMOUNT=1<br>
fi<br>
if [ "x$1" != "xup" ]; then<br>
ADJUST_AMOUNT=-${ADJUST_AMOUNT}<br>
fi<br>
NEW_VOLUME="$((${VOLUME} + ${ADJUST_AMOUNT}))"<br>
if [ ${NEW_VOLUME} -lt ${RANGE[0]} ]; then<br>
NEW_VOLUME=${RANGE[0]}<br>
elif [ ${NEW_VOLUME} -gt ${RANGE[1]} ]; then<br>
NEW_VOLUME=${RANGE[1]}<br>
fi<br>
amixer -q set ${CONTROL} ${NEW_VOLUME} &<br>
done<br>
}<br>
<br>
simple_message() {<br>
MESSAGE=$1<br>
if [ "x${MESSAGE}" = "x" ]; then<br>
return<br>
fi<br>
if [ "x${USE_OSD}" = "xxosd" ]; then<br>
if [ "x${XOSD}" != "x" -a "x${DISPLAY}" != "x" ]; then<br>
# Kill any running xosd processes (to clear the previous message)<br>
killall -q ${XOSD} > /dev/null 2>&1<br>
echo ${MESSAGE} | ${XOSD} ${XOSD_ARGS} > /dev/null 2>&1 &<br>
fi<br>
elif [ "x${USE_OSD}" = "xmythtvosd" ]; then<br>
if [ "x${MYTHTVOSD}" != "x" ]; then<br>
${MYTHTVOSD} --bcastaddr="${BROADCAST_ADDRESS}" \<br>
--template='alert' \<br>
--alert_text="${MESSAGE}" > /dev/null 2>&1 &<br>
fi<br>
fi<br>
}<br>
<br>
show_percent() {<br>
if [ "x${USE_OSD}" = "xxosd" ]; then<br>
# Relies on amixer reporting volume in the format "[90%]" in any line of<br>
# output.<br>
NEW_VOLUME_PCT=`amixer sget "${OSD_VOLUME_CONTROL}" | awk '/[%]/ {split($0,a,"["); split(a[2],a,"%"); print a[1]; exit}'`<br>
if [ "x${NEW_VOLUME_PCT}" = "x" ]; then<br>
# Couldn't get the volume. Do not display the OSD.<br>
return<br>
fi<br>
if [ "x${XOSD}" != "x" -a "x${DISPLAY}" != "x" ]; then<br>
# Kill any running xosd processes (to clear the previous message)<br>
killall -q ${XOSD} > /dev/null 2>&1<br>
${XOSD} -b ${XOSD_BARMODE} -P ${NEW_VOLUME_PCT} \<br>
-T "${OSD_VOLUME_CONTROL} Volume: ${NEW_VOLUME_PCT}%" ${XOSD_ARGS} > /dev/null 2>&1 &<br>
fi<br>
elif [ "x${USE_OSD}" = "xmythtvosd" ]; then<br>
if [ "x${MYTHTVOSD}" != "x" ]; then<br>
${MYTHTVOSD} --bcastaddr="${BROADCAST_ADDRESS}" \<br>
--template='alert' \<br>
--alert_text="${OSD_VOLUME_CONTROL} Volume: ${NEW_VOLUME_PCT}%" \<br>
> /dev/null 2>&1 &<br>
fi<br>
fi<br>
}<br>
<br>
case "${ACTION}" in<br>
up|down)<br>
set_volume "${ACTION}"<br>
show_percent<br>
;;<br>
mute|unmute)<br>
for INDEX in `seq 0 ${NUM_CONTROLS}`; do<br>
unset CONTROL<br>
CONTROL=${VOLUME_CONTROLS[$INDEX]}<br>
amixer -q set ${CONTROL} ${ACTION} &<br>
done<br>
MESSAGE=`echo "${ACTION}" | tr [:lower:] [:upper:]` > /dev/null 2>&1<br>
simple_message ${MESSAGE}<br>
;;<br>
toggle)<br>
for INDEX in `seq 0 ${NUM_CONTROLS}`; do<br>
unset CONTROL CURRENT_STATE<br>
CONTROL=${VOLUME_CONTROLS[$INDEX]}<br>
# Relies on amixer reporting mute state in the format<br>
# "<anything>[90%] [7.50dB] [on]" in any line of output. Please test<br>
# that your version of amixer does this for each control you've specified<br>
# in VOLUME_CONTROLS.<br>
CURRENT_STATE=`amixer sget "${CONTROL}" | awk '/[%]/ {split($0,a,"["); split(a[4],a,"]"); print a[1]; exit}'`<br>
if [ "x${CURRENT_STATE}" = "x" ]; then<br>
# Couldn't get the mute state. Skip this control.<br>
continue<br>
fi<br>
if [ "x${CURRENT_STATE}" = "xoff" ]; then<br>
MUTE=unmute<br>
else<br>
MUTE=mute<br>
fi<br>
amixer -q set ${CONTROL} ${MUTE} &<br>
done<br>
# Assume the mute state of all controls is the same as that of the<br>
# last successfully set control. Using toggle with multiple controls<br>
# in different states doesn't make much sense.<br>
MESSAGE=`echo "${MUTE}" | tr [:lower:] [:upper:]` > /dev/null 2>&1<br>
simple_message ${MESSAGE}<br>
;;<br>
*)<br>
echo "Usage: $0 {up|down|mute|unmute|toggle} [control1 [control2 [...]]]"<br>
exit 1<br>
;;<br>
esac<br>
<br>
<br>_______________________________________________<br>
mythtv-users mailing list<br>
<a href="mailto:mythtv-users@mythtv.org">mythtv-users@mythtv.org</a><br>
<a href="http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users" target="_blank">http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users</a><br>
<br></blockquote><div><br>Wow, thanks, Nick, thanks Mike.<br><br> These look like what the doctor ordered. So far, I had added<br>a button to my frontend for a shell script to toggle the "status"<br>portion of the OSD, but both these look like more what I had in<br>
mind. I had also installed xosd to give me some feedback from<br>the shell script, looks like that will come in more handy with Mike's<br>script.<br><br>Pat<br></div></div>