mirror of
https://github.com/AquaMorph/dotfiles.git
synced 2025-06-29 16:52:02 +00:00
Refactored audio scripts to new directory
This commit is contained in:
90
scripts/audio/aquamix.sh
Normal file
90
scripts/audio/aquamix.sh
Normal file
@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to manuage audio mixing the the main audio interface.
|
||||
|
||||
# Import library
|
||||
source $(dirname ${BASH_SOURCE[0]})/audio-lib.sh
|
||||
|
||||
INTERFACE_NAME='Scarlett 18i20'
|
||||
INTERFACE_NUM=$(getCardNumber $INTERFACE_NAME)
|
||||
checkCard $INTERFACE_NAME $INTERFACE_NUM
|
||||
|
||||
# Sets the volume levels of the first mono instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setMonoOne() {
|
||||
setMono $INTERFACE_NUM 1 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the second mono instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setMonoTwo() {
|
||||
setMono $INTERFACE_NUM 2 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the third mono instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setMonoThree() {
|
||||
setMono $INTERFACE_NUM 3 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the first stereo instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setStereoOne() {
|
||||
setStereo $INTERFACE_NUM 5 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the second stereo instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setStereoTwo() {
|
||||
setStereo $INTERFACE_NUM 7 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the studio microphone.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setMic() {
|
||||
setMono $INTERFACE_NUM 4 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of the computer.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setComputerAudio() {
|
||||
setStereo $INTERFACE_NUM 17 $1 $2 $3
|
||||
}
|
||||
|
||||
# Sets the volume levels of all instrument.
|
||||
#
|
||||
# $1 monitor volume
|
||||
# $2 first headphone volume
|
||||
# $3 second headphone volume
|
||||
function setInstruments() {
|
||||
setMonoOne $1 $2 $3
|
||||
setMonoTwo $1 $2 $3
|
||||
setMonoThree $1 $2 $3
|
||||
setStereoOne $1 $2 $3
|
||||
setStereoTwo $1 $2 $3
|
||||
}
|
||||
|
||||
setInstruments $ZERO_DB
|
||||
setMic $MUTE
|
||||
setComputerAudio $ZERO_DB
|
121
scripts/audio/audio-lib.sh
Normal file
121
scripts/audio/audio-lib.sh
Normal file
@ -0,0 +1,121 @@
|
||||
# Mix names
|
||||
MONITOR_LEFT='A'
|
||||
MONITOR_RIGHT='B'
|
||||
HEADPHONE_01_LEFT='C'
|
||||
HEADPHONE_01_RIGHT='D'
|
||||
HEADPHONE_02_LEFT='E'
|
||||
HEADPHONE_02_RIGHT='F'
|
||||
BLANK_LEFT="G"
|
||||
BLANK_RIGHT='H'
|
||||
|
||||
# Level constants
|
||||
MUTE='0'
|
||||
ZERO_DB='0db'
|
||||
|
||||
# Formats a number to match the matrix numbering.
|
||||
function formatMatrixNum() {
|
||||
printf "%02d" $1
|
||||
}
|
||||
|
||||
# Returns audio card number with matching card name.
|
||||
function getCardNumber() {
|
||||
echo $(cat /proc/asound/cards | grep -m 1 $1 | grep -Po '\d{1,2}' | head -1)
|
||||
}
|
||||
|
||||
# Checks if the card exists and if not exits.
|
||||
#
|
||||
# $1 card name
|
||||
# $2 card number
|
||||
function checkCard() {
|
||||
if [ -z "$2" ]; then
|
||||
echo $1 not connected
|
||||
exit 1
|
||||
else
|
||||
echo $1 found at hw:$2
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints a list of all controls for the given sound card.
|
||||
function printControls() {
|
||||
amixer -c $1 controls
|
||||
}
|
||||
|
||||
# Sets a mix to a level.
|
||||
#
|
||||
# $1 card number
|
||||
# $2 matrix number
|
||||
# $3 mix channel
|
||||
function setMix() {
|
||||
amixer -c $1 set "Matrix $(formatMatrixNum $2) Mix $3" $4
|
||||
}
|
||||
|
||||
|
||||
# Sets the volume levels for a mono mix.
|
||||
#
|
||||
# $1 card number
|
||||
# $2 matrix number
|
||||
# $3 mix left channel
|
||||
# $4 mix right channel
|
||||
# $5 volume
|
||||
function setMonoMix() {
|
||||
setMix $1 $2 $3 $5
|
||||
setMix $1 $2 $4 $5
|
||||
}
|
||||
|
||||
# Sets the volume levels for a stereo mix.
|
||||
#
|
||||
# $1 card number
|
||||
# $2 matrix number
|
||||
# $3 mix left channel
|
||||
# $4 mix right channel
|
||||
# $5 volume
|
||||
function setStereoMix() {
|
||||
matrix=$2
|
||||
setMix $1 $matrix $3 $5
|
||||
setMix $1 $matrix $4 $MUTE
|
||||
setMix $1 $((matrix+1)) $3 $MUTE
|
||||
setMix $1 $((matrix+1)) $4 $5
|
||||
}
|
||||
|
||||
|
||||
# Sets the volume levels for a mono mix for several outputs.
|
||||
#
|
||||
# $1 card number
|
||||
# $2 matrix number
|
||||
# $3 mix left channel
|
||||
# $4 mix right channel
|
||||
# $5 monitor volume
|
||||
# $6 first headphone volume
|
||||
# $7 second headphone volume
|
||||
function setMono() {
|
||||
monitor=$3
|
||||
headphone1=$4
|
||||
headphone2=$5
|
||||
if [ -n $headphone1 ]; then headphone1=$monitor; fi
|
||||
if [ -n $headphone2 ]; then headphone2=$monitor; fi
|
||||
setMonoMix $1 $2 $MONITOR_LEFT $MONITOR_RIGHT $monitor
|
||||
setMonoMix $1 $2 $HEADPHONE_01_LEFT $HEADPHONE_01_RIGHT $headphone1
|
||||
setMonoMix $1 $2 $HEADPHONE_02_LEFT $HEADPHONE_02_RIGHT $headphone2
|
||||
setMonoMix $1 $2 $BLANK_LEFT $BLANK_RIGHT $MUTE
|
||||
}
|
||||
|
||||
# Sets the volume levels for a stereo mix for several outputs.
|
||||
#
|
||||
# $1 card number
|
||||
# $2 matrix number
|
||||
# $3 mix left channel
|
||||
# $4 mix right channel
|
||||
# $5 monitor volume
|
||||
# $6 first headphone volume
|
||||
# $7 second headphone volume
|
||||
function setStereo() {
|
||||
monitor=$3
|
||||
headphone1=$4
|
||||
headphone2=$5
|
||||
if [ -n $headphone1 ]; then headphone1=$monitor; fi
|
||||
if [ -n $headphone2 ]; then headphone2=$monitor; fi
|
||||
setStereoMix $1 $2 $MONITOR_LEFT $MONITOR_RIGHT $monitor
|
||||
setStereoMix $1 $2 $HEADPHONE_01_LEFT $HEADPHONE_01_RIGHT $headphone1
|
||||
setStereoMix $1 $2 $HEADPHONE_02_LEFT $HEADPHONE_02_RIGHT $headphone2
|
||||
setStereoMix $1 $2 $BLANK_LEFT $BLANK_RIGHT $MUTE
|
||||
}
|
11
scripts/audio/es8start.sh
Normal file
11
scripts/audio/es8start.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to add another audio interface if available.
|
||||
|
||||
DEVICE_NAME='ES-8'
|
||||
DEVICE_NUM=$(getCardNumber $DEVICE_NAME)
|
||||
checkCard $DEVICE_NAME $DEVICE_NUM
|
||||
|
||||
# Start up audio interface
|
||||
alsa_in -d hw:$DEVICENUM -j "$DEVICENAME In" -q 1 &
|
||||
alsa_out -d hw:$DEVICENUM -j "$DEVICENAME Out" -q 1 &
|
14
scripts/audio/es9start.sh
Normal file
14
scripts/audio/es9start.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to add another audio interface if available.
|
||||
|
||||
# Import library
|
||||
source $(dirname ${BASH_SOURCE[0]})/audio-lib.sh
|
||||
|
||||
DEVICE_NAME='ES-9'
|
||||
DEVICE_NUM=$(getCardNumber $DEVICE_NAME)
|
||||
checkCard $DEVICE_NAME $DEVICE_NUM
|
||||
|
||||
# Start up audio interface
|
||||
alsa_in -d hw:$DEVICE_NUM -j "$DEVICENAME In" -c 16 -q 1 &
|
||||
alsa_out -d hw:$DEVICE_NUM -j "$DEVICENAME Out" -c 16 -q 1 &
|
6
scripts/audio/es9stop.sh
Normal file
6
scripts/audio/es9stop.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to stop ES-9 audio interface
|
||||
|
||||
pkill alsa_in
|
||||
pkill alsa_out
|
60
scripts/audio/system-start-audio.sh
Normal file
60
scripts/audio/system-start-audio.sh
Normal file
@ -0,0 +1,60 @@
|
||||
#! /bin/bash
|
||||
|
||||
# Kill Pulse
|
||||
function killPulse() {
|
||||
systemctl --user stop pulseaudio.socket
|
||||
systemctl --user stop pulseaudio.service
|
||||
pulseaudio -k
|
||||
killall pulseaudio
|
||||
}
|
||||
|
||||
# Start Pulseaudio properly
|
||||
function fixPulse() {
|
||||
PULSE="$(alsamixer 2>&1 | killall alsamixer)"
|
||||
if [[ $PULSE == *'Connection refused'* ]]; then
|
||||
echo 'Fixing Pulseaudio'
|
||||
killPulse
|
||||
sleep 0.1
|
||||
pulseaudio -D
|
||||
fixPulse
|
||||
else
|
||||
echo 'Pulseaudio is working correctly'
|
||||
fi
|
||||
}
|
||||
|
||||
# Start up programs that use audio
|
||||
function launchi3() {
|
||||
if [ -z "$skipi3" ]; then
|
||||
echo Opening i3wm sound workspaces
|
||||
sleep .1 && i3-msg 'workspace 5; exec firefox'
|
||||
sleep 8 && python ~/.config/scripts/start-firefox.py
|
||||
fi
|
||||
}
|
||||
|
||||
# arg parser
|
||||
for arg in "$@"
|
||||
do
|
||||
# Skip commands for i3wm
|
||||
if [[ $arg == *"-s"* ]]; then
|
||||
skipi3=true
|
||||
fi
|
||||
done
|
||||
|
||||
# Close any active audio
|
||||
killPulse
|
||||
|
||||
# Start up jack
|
||||
cadence-session-start --system-start &
|
||||
wait %1 && sleep 1
|
||||
ladish_control sload studio
|
||||
|
||||
# Make start up reliable
|
||||
killPulse
|
||||
fixPulse
|
||||
pulseaudio -D
|
||||
|
||||
# Eurorack audio interface
|
||||
sh ~/.config/scripts/audio/es8start.sh
|
||||
sh ~/.config/scripts/audio/es9start.sh
|
||||
|
||||
launchi3
|
Reference in New Issue
Block a user