media scwrypts v5 refactor
This commit is contained in:
5
scwrypts/media/audio/audio.module.zsh
Normal file
5
scwrypts/media/audio/audio.module.zsh
Normal file
@ -0,0 +1,5 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
#
|
14
scwrypts/media/audio/play-sfx
Executable file
14
scwrypts/media/audio/play-sfx
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env zsh
|
||||
#####################################################################
|
||||
|
||||
use audio/play-sfx --group media
|
||||
|
||||
#####################################################################
|
||||
|
||||
media.audio.play-sfx.parse.usage
|
||||
|
||||
#####################################################################
|
||||
|
||||
MAIN() {
|
||||
media.audio.play-sfx $@
|
||||
}
|
79
scwrypts/media/audio/play-sfx.module.zsh
Normal file
79
scwrypts/media/audio/play-sfx.module.zsh
Normal file
@ -0,0 +1,79 @@
|
||||
#####################################################################
|
||||
|
||||
use notify
|
||||
use scwrypts/get-realpath
|
||||
|
||||
DEPENDENCIES+=(canberra-gtk-play)
|
||||
REQUIRED_ENV+=(DESKTOP__SFX_PATH)
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}() {
|
||||
local SCWRYPTS_NOTIFICATION_ENGINES=(echo notify.desktop)
|
||||
|
||||
eval "$(utils.parse.autosetup)"
|
||||
|
||||
##########################################
|
||||
|
||||
echo.status 'starting playback'
|
||||
canberra-gtk-play -f "${SFX_FILE}" \
|
||||
&& echo.success "finished output of '${SFX_FILE}'" \
|
||||
|| notify.error "something went wrong playing file '${SFX_FILE}'" \
|
||||
|| return 1
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}.parse() {
|
||||
[[ ${POSITIONAL_ARGS} -eq 0 ]] || return 0
|
||||
|
||||
((POSITIONAL_ARGS+=1))
|
||||
case $1 in
|
||||
( backlight ) SFX_FILE="${DESKTOP__SFX_PATH}/yaru-audio-volume-change.oga" ;;
|
||||
( gamedock ) SFX_FILE="${DESKTOP__SFX_PATH}/gamedock.oga" ;;
|
||||
( homedock ) SFX_FILE="${DESKTOP__SFX_PATH}/homedock.oga" ;;
|
||||
( login ) SFX_FILE="${DESKTOP__SFX_PATH}/yaru-desktop-login.oga" ;;
|
||||
( logout ) SFX_FILE="${DESKTOP__SFX_PATH}/smooth-desktop-login.oga" ;;
|
||||
( mute ) SFX_FILE="${DESKTOP__SFX_PATH}/smooth-dialog-warning.oga" ;;
|
||||
( notify ) SFX_FILE="${DESKTOP__SFX_PATH}/yaru-complete.oga" ;;
|
||||
( undock ) SFX_FILE="${DESKTOP__SFX_PATH}/yaru-desktop-login.oga" ;;
|
||||
( volume ) SFX_FILE="${DESKTOP__SFX_PATH}/yaru-message.oga" ;;
|
||||
|
||||
( * )
|
||||
SFX_FILE="$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse.locals() {
|
||||
local SFX_FILE
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse.usage() {
|
||||
USAGE__description='
|
||||
play the indicated sound effect by mapped name or filename
|
||||
|
||||
mapped names :
|
||||
backlight notify
|
||||
login logout
|
||||
mute volume
|
||||
gamedock homedock undock
|
||||
'
|
||||
|
||||
USAGE__args='
|
||||
\$1 mapped name or filename
|
||||
'
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse.validate() {
|
||||
[ -f "$(scwrypts.get-realpath "${SFX_FILE}")" ] \
|
||||
&& SFX_FILE="$(scwrypts.get-realpath "${SFX_FILE}")" \
|
||||
|| SFX_FILE="${DESKTOP__SFX_PATH}/${SFX_FILE}" \
|
||||
;
|
||||
|
||||
[ -f "${SFX_FILE}" ] \
|
||||
|| notify.error "unable to locate sfx file '$1'" \
|
||||
|| return 1
|
||||
}
|
42
scwrypts/media/audio/pulseaudio/pulseaudio.module.zsh
Normal file
42
scwrypts/media/audio/pulseaudio/pulseaudio.module.zsh
Normal file
@ -0,0 +1,42 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(canberra-gtk-play)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use notify
|
||||
|
||||
#####################################################################
|
||||
|
||||
media.audio.play-sfx() {
|
||||
local SCWRYPTS_NOTIFICATION_ENGINES=(echo notify.desktop)
|
||||
local SFX_FILE
|
||||
case $1 in
|
||||
( volume ) SFX_FILE=$DESKTOP__SFX_PATH/yaru-message.oga ;;
|
||||
( mute ) SFX_FILE=$DESKTOP__SFX_PATH/smooth-dialog-warning.oga ;;
|
||||
( backlight ) SFX_FILE=$DESKTOP__SFX_PATH/yaru-audio-volume-change.oga ;;
|
||||
( login ) SFX_FILE=$DESKTOP__SFX_PATH/yaru-desktop-login.oga ;;
|
||||
( logout ) SFX_FILE=$DESKTOP__SFX_PATH/smooth-desktop-login.oga ;;
|
||||
( notify ) SFX_FILE=$DESKTOP__SFX_PATH/yaru-complete.oga ;;
|
||||
( undock ) SFX_FILE=$DESKTOP__SFX_PATH/yaru-desktop-login.oga ;;
|
||||
( homedock ) SFX_FILE=$DESKTOP__SFX_PATH/homedock.oga ;;
|
||||
( gamedock ) SFX_FILE=$DESKTOP__SFX_PATH/gamedock.oga ;;
|
||||
|
||||
* ) SFX_FILE="$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ ! -f $SFX_FILE ] && SFX_FILE="$DESKTOP__SFX_PATH/$SFX_FILE"
|
||||
|
||||
[ -f $SFX_FILE ] \
|
||||
&& echo.status "detected file '$SFX_FILE'" \
|
||||
|| notify.error "unable to locate sfx file '$1'" \
|
||||
|| return 1 \
|
||||
;
|
||||
|
||||
echo.status 'starting playback'
|
||||
canberra-gtk-play -f "$SFX_FILE" \
|
||||
&& echo.success "finished output of '$SFX_FILE'" \
|
||||
|| notify.error "something went wrong playing file '$SFX_FILE'" \
|
||||
|| return 1 \
|
||||
;
|
||||
}
|
12
scwrypts/media/audio/pulseaudio/volume
Executable file
12
scwrypts/media/audio/pulseaudio/volume
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/zsh
|
||||
#####################################################################
|
||||
|
||||
use audio/pulseaudio/volume --group media
|
||||
|
||||
#####################################################################
|
||||
|
||||
media.audio.pulseaudio.volume.parse.usage
|
||||
|
||||
#####################################################################
|
||||
|
||||
MAIN() { media.audio.pulseaudio.volume $@; }
|
93
scwrypts/media/audio/pulseaudio/volume.module.zsh
Normal file
93
scwrypts/media/audio/pulseaudio/volume.module.zsh
Normal file
@ -0,0 +1,93 @@
|
||||
#!/bin/zsh
|
||||
#####################################################################
|
||||
|
||||
use notify
|
||||
use audio/play-sfx --group media
|
||||
|
||||
DEPENDENCIES+=(pactl)
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}() {
|
||||
local SCWRYPTS_NOTIFICATION_ENGINES=(echo notify.desktop)
|
||||
eval "$(utils.parse.autosetup)"
|
||||
##########################################
|
||||
|
||||
case ${COMMAND} in
|
||||
( up )
|
||||
pactl set-${DEVICE}-volume ${PACTL_DEVICE} +10% \
|
||||
|| notify.error "pactl error with set-${DEVICE}-volume"
|
||||
|
||||
media.audio.play-sfx volume
|
||||
;;
|
||||
|
||||
( down )
|
||||
pactl set-${DEVICE}-volume ${PACTL_DEVICE} -10% \
|
||||
|| notify.error "pactl error with set-${DEVICE}-volume"
|
||||
|
||||
media.audio.play-sfx volume
|
||||
;;
|
||||
|
||||
( mute )
|
||||
pactl set-${DEVICE}-mute ${PACTL_DEVICE} toggle \
|
||||
&& notify.success "default ${DEVICE}" "$(amixer sget ${AMIXER_DEVICE} | grep -q '\[on\]' && echo unmuted || echo muted)" \
|
||||
|| notify.error "pactl error with set-${DEVICE}-mute"
|
||||
|
||||
media.audio.play-sfx mute
|
||||
;;
|
||||
esac
|
||||
|
||||
return ${ERRORS}
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}.parse() { return 0; }
|
||||
${scwryptsmodule}.parse.locals() {
|
||||
local ARGS=()
|
||||
|
||||
local DEVICE
|
||||
local AMIXER_DEVICE
|
||||
local PACTL_DEVICE
|
||||
local COMMAND
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse.usage() {
|
||||
USAGE__description='
|
||||
simplified pactl for volume up/down/mute on default sink and source
|
||||
'
|
||||
|
||||
USAGE__args='
|
||||
\$1 target device : one of (sink source)
|
||||
\$2 volume command : one of (up down mute)
|
||||
'
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse.validate() {
|
||||
DEVICE="${ARGS[1]}"
|
||||
[ "${DEVICE}" ] \
|
||||
|| notify.error 'missing device'
|
||||
|
||||
COMMAND="${ARGS[2]}"
|
||||
[ "${COMMAND}" ] \
|
||||
|| notify.error 'missing command'
|
||||
|
||||
[ "${DEVICE}" ] && [ "${COMMAND}" ] || return
|
||||
|
||||
case ${DEVICE} in
|
||||
( sink ) AMIXER_DEVICE=Master ;;
|
||||
( source ) AMIXER_DEVICE=Capture ;;
|
||||
( * )
|
||||
notify.error "unsupported device '${DEVICE}'"
|
||||
;;
|
||||
esac
|
||||
|
||||
case ${COMMAND} in
|
||||
( up | down | mute ) ;;
|
||||
( * )
|
||||
notify.error "unsupported command '${COMMAND}'"
|
||||
;;
|
||||
esac
|
||||
|
||||
PACTL_DEVICE="@DEFAULT_$(echo ${DEVICE} | tr '[:lower:]' '[:upper:]')@"
|
||||
}
|
Reference in New Issue
Block a user