Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 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 script written by oToGamez (www.pro-toolz.net).
- # Define variables.
- # This is your config file:
- cfgfile="`dirname $0`/menuaudio.cfg"
- # Use that file as the source for variables:
- source $cfgfile
- # If received SIGINT (i.e. CTRL C) then reset screen and exit. See "trap -l"
- trap "R;exit" 2
- # This is the menu:
- #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
- M0 () { TPUT 7 2; echo -en "Jack audio daemon: start ";}
- M1 () { TPUT 8 2; echo -en " : kill ";}
- M2 () { TPUT 9 2; echo -en "Check Midi : port numbers ";}
- M3 () { TPUT 10 2; echo -en " : output ";}
- M4 () { TPUT 11 2; echo -en "Check Alsa : device/card numbers ";}
- M5 () { TPUT 12 2; echo -en "Pulseaudio : start ";}
- M6 () { TPUT 13 2; echo -en " : stop ";}
- M7 () { TPUT 14 2; echo -en " : PAVUControl ";}
- M8 () { TPUT 15 2; echo -en "Config file : create/edit ";}
- M9 () { TPUT 16 2; echo -en " : delete ";}
- M10() { TPUT 17 2; echo -en " : view ";}
- M11() { TPUT 18 2; echo -en "\e[32mHelp \e[0m";}
- M12() { TPUT 19 2; echo -en "\e[31mExit \e[0m";}
- # Last Menu item is:
- LM=12
- #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
- # These are some more functions that are needed by the script. You don't ever need to edit this.
- #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
- # 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 Midi 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 if cursur is selected?
- SC(){ REFRESH;MARK;$S;cur=`ARROW`;}
- # ES is the footer:
- ES(){ echo -en "\n\e[31mPress Enter for main menu...\e[0m";read;INIT;};INIT
- #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
- # And now, the actual commands to be executed:
- 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
- ES;fi;;
- # Jack audio daemon stop
- 1) S=M1;SC;if [[ $cur == "" ]]; then R
- pkill -9 jackdbus
- killall jackd
- sleep 1
- ES;fi;;
- ########
- # MIDI #
- ########
- # Check Midi port numbers
- 2) S=M2;SC;if [[ $cur == "" ]]; then R
- aconnect -io
- ES;fi;;
- # Check Midi output:
- 3) S=M3;SC;if [[ $cur == "" ]]; then R
- echo "Type in Midi port number:"
- read portnumber
- aseqdump -p $portnumber
- ES;fi;;
- ########
- # Alsa #
- ########
- 4) S=M4;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:
- 5) S=M5;SC;if [[ $cur == "" ]]; then R
- pulseaudio --start -v
- ES;fi;;
- # Pulse kill:
- 6) S=M6;SC;if [[ $cur == "" ]]; then R
- pulseaudio --kill
- ES;fi;;
- # PA VU Control:
- 7) S=M7;SC;if [[ $cur == "" ]]; then R
- echo -e "\e[34;1mPAVUControl is running. \e[0m"
- pavucontrol
- ES;fi;;
- ###############
- # Config file #
- ###############
- # Create/edit config file:
- 8) S=M8;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
- # Want more variables in it? Do:
- # echo -e "var02=0" >> $cfgfile
- # echo -e "var03=0" >> $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 "Your config file now looks like this: \n"
- cat $cfgfile
- ES;fi;;
- # Delete config file:
- 9) S=M9;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:
- 10) S=M10;SC;if [[ $cur == "" ]]; then R
- echo -e "Your config file is: $cfgfile, and its contents is:\n"
- cat $cfgfile
- ES;fi;;
- ########
- # HELP #
- ########
- 11) S=M11;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 \"VU Meter\" &); sleep 0.1;\
- jack_connect system:capture_1 jmeters:in-1
- 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"
- ES;fi;;
- 12) S=M12;SC;if [[ $cur == "" ]]; then R
- clear
- exit 0
- fi;;
- esac; POS; done; R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement