Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Pastebin: pastebin.com/zRL7gz5c
- # Menuaudio.sh is a shell script to start/stop Jack and do some audio things.
- # It uses/creates a settings file thats callled "menuaudio.cfg".
- # Original unmodified example script written by oToGamez (www.pro-toolz.net).
- # This is your config file:
- cfgfile="`dirname $0`/menuaudio.cfg"
- # Use config file as the source for variables:
- source $cfgfile
- # If received SIGINT (i.e. Ctrl + C) then reset screen and exit.
- # See "trap -l" (notice that R is a function).
- trap "R;exit" 2
- # This is the menu:
- ###############################################################################
- M0 (){ TPUT 7 2; echo -en "Jack audio : start " ;}
- M1 (){ TPUT 8 2; echo -en " : kill " ;}
- M2 (){ TPUT 9 2; echo -en " : check status " ;}
- M3 (){ TPUT 10 2; echo -en "Midi : output port numbers " ;}
- M4 (){ TPUT 11 2; echo -en " : output " ;}
- M5 (){ TPUT 12 2; echo -en "Alsa : device/card numbers " ;}
- M6 (){ TPUT 13 2; echo -en "PulseAudio : start " ;}
- M7 (){ TPUT 14 2; echo -en " : stop " ;}
- M8 (){ TPUT 15 2; echo -en " : check status " ;}
- M9 (){ TPUT 16 2; echo -en "Config file : create/edit " ;}
- M10(){ TPUT 17 2; echo -en " : delete " ;}
- M11(){ TPUT 18 2; echo -en " : view " ;}
- M12(){ TPUT 19 2; echo -en "\e[32mHelp \e[0m";}
- M13(){ TPUT 20 2; echo -en "\e[31mExit \e[0m";}
- # Last Menu item is:
- LM=13
- ###############################################################################
- # These are some more functions that are needed by the script. You don't ever
- # need to edit this.
- ################################################################################
- # R = Reset = clear screen, clean terminal and no inverse:
- R(){ clear;stty sane;echo -en "\e[27m";}
- TPUT(){ echo -en "\e[${1};${2}H"; } # Print text starting on line $1 and column $2.
- MARK(){ echo -en "\e[7m"; } # Reverse video characters.
- UNMARK(){ echo -en "\e[27m"; } # Reset reverse.
- HEAD(){ TPUT 1 1
- echo -e "\e[34;1m\e(0lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk\e(B"
- echo -e "\e(0x\e(B Audio menu \e(0x"
- echo -e "\e(0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj\e[0m\e(B"
- echo -e "Use ↑ and ↓ keys to select and Enter"
- echo -e "to execute." ;}
- ARROW(){ read -s -n3 key 2>/dev/null >&2
- if [[ $key = $(echo -en "\e")[A ]];then echo up;fi # Up in a terminal is:
- # "escape char"A.
- if [[ $key = $(echo -en "\e")[B ]];then echo dn;fi; # Dn in a terminal is:
- # "escape char"B.
- }
- # More functions (build menu and catch cursor movement):
- i=0
- MENU(){ for each in $(seq 0 $LM);do M${each}; done ;}
- POS(){ if [[ $cur == up ]]; then ((i--)); fi
- if [[ $cur == dn ]]; then ((i++)); fi
- if [[ $i -lt 0 ]]; then i=$LM; fi
- if [[ $i -gt $LM ]]; then i=0; fi ;}
- REFRESH(){ after=$((i+1)); before=$((i-1))
- if [[ $before -lt 0 ]]; then before=$LM; fi
- if [[ $after -gt $LM ]]; then after=0; fi
- if [[ $j -lt $i ]]; then UNMARK; M$before; else UNMARK; M$after; fi
- if [[ $after -eq 0 ]] || [ $before -eq $LM ]; then
- UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}
- INIT(){ R;HEAD;MENU;}
- # SC determines status of cursor (i.e. up or dn):
- SC(){ REFRESH;MARK;$S;cur=`ARROW`;}
- # ES is the footer (Exit Signal, End Sentence?):
- ES(){ echo -en "\n\e[31mPress Enter for main menu...\e[0m"; read; INIT;}
- ################################################################################
- # And now, the actual commands to be executed:
- INIT
- while [[ "$O" != " " ]]; do case $i in
- #.__________________.
- #| |
- #| JACK |
- #|__________________|
- # Jack audio daemon start
- # -----------------------
- 0) S=M0;SC;if [[ $cur == "" ]]; then R
- jackd -d alsa --device hw:$sndcrd &
- sleep 1
- # Jack sink to PA:
- # Dont use 'pacmd set-default-sink 1' (makes the Trust C-Media PCI default)
- # Route Jack via PulseAudio on my 2nd so I can listen to Youtube
- # as well as Jack (restart Chrome!).
- if [[ $jack_sink == "y" ]]
- then
- echo " |"
- echo " V"
- echo "Starting Jack sink module ..."
- pactl load-module module-jack-sink &
- echo " |"
- echo " V"
- echo "Setting Jack sink as default sink ..."
- echo "If you get the \"No such entity\" error check with qjackctl"
- pactl set-default-sink jack_out &
- sleep 1
- echo -e "\n\e[34mNow open PAVUcontrol and set 'jack_out' as Chrome's playback device.\e[0m"
- fi
- # Alsa to Jack MIDI:
- # Make Alsa's Midi also visible as Jack Midi.
- if [[ $a2j == "y" ]]
- then
- echo -en "\e[34m \n" # Make the following output blue
- echo "Starting Alsa to Jack Midi bridge:"
- echo " |"
- echo -en " V \e[0m \n"
- # Make sure a2jmidid does not stop after closing the window in which this script runs.
- nohup a2jmidid -e &
- sleep 1
- fi
- ES;fi;;
- # Jack audio daemon stop
- # -----------------------
- 1) S=M1;SC;if [[ $cur == "" ]]; then R
- pkill -9 jackdbus
- killall jackd
- sleep 1
- ES;fi;;
- # Check status
- # ------------
- 2) S=M2;SC;if [[ $cur == "" ]]; then R
- echo "Jack audio status:"
- echo " "
- # Append stderr to stdout and show lines of no more than 80 chars
- jack_lsp -A 2>&1 | sed 's/.//80g'
- echo ""
- echo "Jack processes:"
- echo ""
- ps aux | grep jackd | grep -v grep | awk '{for(i=11;i<=NF;++i)printf $i " "; printf "\n"}'
- # Old, show QJackCtl:
- # qjackctl > /dev/null 2>&1 &
- ES;fi;;
- # _________________
- #| |
- #| MIDI |
- #|_________________|
- # Check Midi port numbers
- # -----------------------
- 3) S=M3;SC;if [[ $cur == "" ]]; then R
- # old:
- # aconnect -io
- aseqdump -l
- ES;fi;;
- # Check Midi output
- # -----------------
- 4) S=M4;SC;if [[ $cur == "" ]]; then R
- # Use trap to return to Menu:
- trap "echo \" => Process interrupted... (press Enter)\"" 2
- aseqdump -l
- echo
- echo "Type in Midi port number:"
- read portnumber
- aseqdump -p $portnumber
- # Reset trap:
- trap "R;exit" 2
- ES;fi;;
- # _________________
- #| |
- #| ALSA |
- #|_________________|
- 5) S=M5;SC;if [[ $cur == "" ]]; then R
- echo -e "Determine the number of your soundcards/audio devices. Watch the output in blue below. It's the first number in the line. Numbering starts with 0. So if you have two sound cards then the number of your second card is 1. \n"
- echo -en "\e[34m" # Make the following output blue
- cat /proc/asound/cards
- echo -en "\e[0m"
- ES;fi;;
- # __________________
- #| |
- #| PULSE |
- #|__________________|
- # Pulse start
- # ------------
- 6) S=M6;SC;if [[ $cur == "" ]]; then R
- pulseaudio --start -v
- ES;fi;;
- # Pulse kil
- # ---------
- 7) S=M7;SC;if [[ $cur == "" ]]; then R
- pulseaudio --kill
- ES;fi;;
- # Check status
- # ------------
- 8) S=M8;SC;if [[ $cur == "" ]]; then R
- # Old, PA VU Control:
- # echo -e "\e[34;1mPAVUControl is running. \e[0m"
- # pavucontrol &
- echo "PulseAdio status:"
- echo
- pactl info
- ES;fi;;
- # ________________
- #| |
- #| Config file |
- #|________________|
- # Create/edit config file
- # -----------------------
- 9) S=M9;SC;if [[ $cur == "" ]]; then R
- echo -e "Determine the number of your soundcards/audio devices. Watch the output in blue below. It's the first number in the line. Numbering starts with 0. So if you have two sound cards then the number of your second card is 1. \n"
- echo -en "\e[34m" # Make the following output blue
- cat /proc/asound/cards
- echo -en "\n\e[0m" # End of blue text
- # If not exist then create config file and fill it with the variables:
- if [ ! -e $cfgfile ]
- then
- echo -e "=> No config file found that is named $cfgfile. Going to create one...\n"
- touch $cfgfile
- echo -e "sndcrd=0" >> $cfgfile
- echo -e "a2j=n" >> $cfgfile
- echo -e "jack_sink=n" >> $cfgfile
- fi
- echo -e "=> Config file is: $cfgfile"
- function set_config ()
- {
- sed -i "s/^\($1\s*=\s*\).*\$/\1$2/" $cfgfile
- source $cfgfile
- }
- set_config
- echo -e "\nType in the number of your sound card/audio device:"
- read new_sndcrd
- set_config sndcrd $new_sndcrd
- echo -e "\nWant to make Alsa's Midi also visible as Jack Midi? [y/n]"
- read new_a2j
- set_config a2j $new_a2j
- echo -e "\nWant to sink Jack to PulseAudio? [y/n]"
- read new_jack_sink
- set_config jack_sink $new_jack_sink
- echo -e "Your config file now looks like this: \n"
- cat $cfgfile
- ES;fi;;
- # Delete config file
- # ------------------
- 10) S=M10;SC;if [[ $cur == "" ]]; then R
- echo -e "Delete $cfgfile? (y/n)"
- read choice01
- if [[ $choice01 == "y" ]]
- then
- rm $cfgfile
- else
- echo "You chose n or typed in the wrong letter. Not deleting $cfgfile."
- fi
- ES;fi;;
- # Show config file
- # -----------------
- 11) S=M11;SC;if [[ $cur == "" ]]; then R
- echo -e "Your config file is: $cfgfile. Notice:\n"
- echo -e " sndcrd = Alsa's sound device number (starts at 0).
- a2j = Alsa Midi to Jack Midi (you'll see A's Midi in J's Midi
- tab in Qjackctl).
- jack_sink = Sink Jack to PulseAudio (in PAVUcontrol set 'jack_out'
- as Chrome's playback device)."
- echo -e "\nContents of your config file is:\n"
- # Old:
- # cat $cfgfile
- # Add indent to output:
- echo " `sed -n 1p $cfgfile`
- `sed -n 2p $cfgfile`
- `sed -n 3p $cfgfile`"
- ES;fi;;
- # ______________
- #| |
- #| Help |
- #|______________|
- 12) S=M12;SC;if [[ $cur == "" ]]; then R
- echo -e "\e[32;1m\e(0lqqqqqqqqqqqqk "
- echo -e "x\e(B Help \e(0x"
- echo -e "\e[32;1m\e(0mqqqqqqqqqqqqj \e[0m\e(B"
- echo -e "\
- 1. You can only get audio in Firefox AFTER starting Pulseaudio, not before!
- 2. Store/restore alsamixer settings for card 2:
- sudo alsactl (re)store 2
- Beware! Store alsa settings *before* switching from input to output
- (F3 and F4 etc.). Else: no store.
- 3. Jack VU meter:
- (jmeters -t vu -f mbrl \"Left channel\" \"Right channel\" &);\\
- sleep 0.1;\\
- jack_connect system:capture_1 jmeters:in-1;\\
- jack_connect system:capture_2 jmeters:in-2
- Note: the jmeters backround process is killed after closing its window.
- 4. Stop PA from respwawning. Uncomment the following 2 lines
- from /etc/pulse/client.conf:
- autospawn = no
- daemon-binary = /bin/true
- For newer Linux systems (i.e. Debian 10):
- systemctl --user mask pulseaudio.socket
- systemctl --user mask pulseaudio.service
- And/or:
- systemctl --user stop pulseaudio.socket
- systemctl --user stop pulseaudio.service
- 5. Some handy PulseAudio commands:
- pacmd list-sinks
- 6. Some handy Jack commands:
- jack_lsp (list processes, check status, use -A for more info)
- 7. Config file:
- jack_sink = Sink Jack's audio to PulseAudio (in PAVUcontrol set
- 'jack_out' as Chrome's playback device).
- a2j = Make Alsa's Midi also visible as Jack Midi
- 8. Check Midi in AND outputs:
- aconnect -io
- 9. The option '--driver' (i.e. ALSA) for jackd does NOT work, you must use '-d'. And for the device on must use '--device' and NOT '-d'. The man page is wrong, what a SNAFU!
- "
- ES;fi;;
- 13) S=M13;SC;if [[ $cur == "" ]]; then R
- clear
- exit 0
- fi;;
- esac; POS; done; R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement