SHARE
TWEET

menuaudio.sh

a guest Sep 27th, 2019 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # 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".
  4. # Original unmodified example script written by oToGamez (www.pro-toolz.net).
  5.  
  6. # Define variables:
  7. # This is your config file.
  8. cfgfile="`dirname $0`/menuaudio.cfg"
  9. # Use that file as the source for variables:
  10. source $cfgfile
  11.  
  12.  
  13. # If received SIGINT (i.e. CTRL C) then reset screen and exit. See "trap -l"
  14. # (notice that R is a function)
  15. trap "R;exit" 2    
  16.  
  17.  
  18. # This is the menu:
  19. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  20.      M0 () { TPUT  7 2; echo -en       "Jack audio daemon: start               ";}
  21.      M1 () { TPUT  8 2; echo -en       "                 : kill                ";}
  22.      M2 () { TPUT  9 2; echo -en       "Check Midi       : port numbers        ";}
  23.      M3 () { TPUT 10 2; echo -en       "                 : output              ";}
  24.      M4 () { TPUT 11 2; echo -en       "Check Alsa       : device/card numbers ";}
  25.      M5 () { TPUT 12 2; echo -en       "Pulseaudio       : start               ";}
  26.      M6 () { TPUT 13 2; echo -en       "                 : stop                ";}
  27.      M7 () { TPUT 14 2; echo -en       "                 : PAVUControl         ";}
  28.      M8 () { TPUT 15 2; echo -en       "Config file      : create/edit         ";}
  29.      M9 () { TPUT 16 2; echo -en       "                 : delete              ";}
  30.      M10() { TPUT 17 2; echo -en       "                 : view                ";}
  31.      M11() { TPUT 18 2; echo -en "\e[32mHelp                                  \e[0m";}
  32.      M12() { TPUT 19 2; echo -en "\e[31mExit                                  \e[0m";}
  33. # Last Menu item is:
  34.      LM=12
  35. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. # These are some more functions that are needed by the script. You don't ever need to edit this.
  45. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  46. # Reset: clear screen, clean terminal and no inverse:
  47. R(){ clear;stty sane;echo -en "\e[27m";}
  48.  
  49.    TPUT(){ echo -en "\e[${1};${2}H";}                # Print text starting on line $1 and
  50.                                                      # column $2.
  51.    MARK(){ echo -en "\e[7m";}                        # Reverse video characters.
  52.  UNMARK(){ echo -en "\e[27m";}                       # Reset reverse.
  53.    HEAD()
  54.          {
  55.            TPUT 1 1
  56.            echo -e "\e[34;1m\e(0lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk\e(B"
  57.            echo -e     "\e(0x\e(B              Audio menu             \e(0x"
  58.            echo -e         "\e(0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj\e[0m\e(B"
  59.            echo -e "Use ↑ and ↓ keys to select and Enter"
  60.            echo -e "to execute."
  61.          }
  62.   ARROW()
  63.          {
  64.            read -s -n3 key 2>/dev/null >&2
  65.            if [[ $key = $(echo -en "\e")[A ]];then echo up;fi   # Up in a terminal is: "escape char."A.
  66.            if [[ $key = $(echo -en "\e")[B ]];then echo dn;fi;  # Dn in a terminal is: "escape char."B.
  67.          }
  68. # More functions (build menu and catch cursor movement):
  69.    i=0
  70.    MENU(){ for each in $(seq 0 $LM);do M${each};done;}
  71.     POS(){ if [[ $cur == up ]];then ((i--));fi
  72.            if [[ $cur == dn ]];then ((i++));fi
  73.            if [[ $i -lt 0   ]];then i=$LM;fi
  74.            if [[ $i -gt $LM ]];then i=0;fi;}
  75. REFRESH(){ after=$((i+1)); before=$((i-1))
  76.            if [[ $before -lt 0  ]];then before=$LM;fi
  77.            if [[ $after -gt $LM ]];then after=0;fi
  78.            if [[ $j -lt $i      ]];then UNMARK;M$before;else UNMARK;M$after;fi
  79.            if [[ $after -eq 0 ]] || [ $before -eq $LM ];then
  80.            UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}
  81.    INIT(){ R;HEAD;MENU;}
  82. # SC determines if cursur is selected?
  83.      SC(){ REFRESH;MARK;$S;cur=`ARROW`;}                    
  84. # ES is the footer:
  85.      ES(){ echo -en "\n\e[31mPress Enter for main menu...\e[0m";read;INIT;};INIT  
  86. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. # And now, the actual commands to be executed:
  94. while [[ "$O" != " " ]]; do case $i in
  95. ########
  96. # JACK #
  97. ########
  98. #  Jack audio daemon start
  99. 0) S=M0;SC;if [[ $cur == "" ]]; then R
  100.    jackd -d alsa --device hw:$sndcrd &
  101.    sleep 1
  102.    # See https://kx.studio/News 2019-03-22: we'd better kill jackdbus.
  103.    # pkill -9 jackdbus
  104.    # Route Jack via PullseAudio on my 2nd so I can listen to Youtube
  105.    # as well as Jack (restart Chrome!).
  106.    # Handy commands:
  107.    # pactl info
  108.    # pacmd list-sinks
  109.    # Dont use 'pacmd set-default-sink 1' (makes the Trust C-Media PCI default)
  110.    if [[ $jack_sink == "y" ]]
  111.       then
  112.       pactl load-module module-jack-sink &
  113.       pactl set-default-sink jack_out &
  114.       sleep 1
  115.       echo -e "\n\e[34mNow open PAVUcontrol and set 'jack_out' as Chrome's playback device.\e[0m"
  116.    fi
  117.    # Make Alsa's Midi also visible as Jack Midi.
  118.    if [[ $a2j == "y" ]]
  119.       then
  120.       a2j &
  121.       sleep 0.5
  122.    fi
  123. ES;fi;;
  124.  
  125. #  Jack audio daemon stop
  126. 1) S=M1;SC;if [[ $cur == "" ]]; then R
  127.    pkill -9 jackdbus
  128.    killall jackd
  129.    sleep 1
  130. ES;fi;;
  131.  
  132.  
  133. ########
  134. # MIDI #
  135. ########
  136. #  Check Midi port numbers
  137. 2) S=M2;SC;if [[ $cur == "" ]]; then R
  138.    aconnect -io
  139. ES;fi;;
  140.  
  141. # Check Midi output:
  142. 3) S=M3;SC;if [[ $cur == "" ]]; then R
  143.    echo "Type in Midi port number:"
  144.    read portnumber
  145.    aseqdump -p $portnumber
  146. ES;fi;;
  147.  
  148.  
  149.  
  150.  
  151. ########
  152. # Alsa #
  153. ########
  154. 4) S=M4;SC;if [[ $cur == "" ]]; then R
  155.    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"
  156.    echo -en "\e[34m"         # Make the following output blue
  157.    cat /proc/asound/cards
  158.    echo -en "\e[0m"
  159. ES;fi;;
  160.  
  161.  
  162. #########
  163. # PULSE #
  164. #########
  165. #  Pulse start:
  166. 5) S=M5;SC;if [[ $cur == "" ]]; then R
  167.    pulseaudio --start -v
  168. ES;fi;;
  169.  
  170. # Pulse kill:
  171. 6) S=M6;SC;if [[ $cur == "" ]]; then R
  172.    pulseaudio --kill
  173. ES;fi;;
  174.  
  175. #  PA VU Control:
  176. 7) S=M7;SC;if [[ $cur == "" ]]; then R
  177.    echo -e "\e[34;1mPAVUControl is running. \e[0m"
  178.    pavucontrol
  179. ES;fi;;
  180.  
  181.  
  182. ###############
  183. # Config file #
  184. ###############
  185. # Create/edit config file:
  186. 8) S=M8;SC;if [[ $cur == "" ]]; then R
  187.    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"
  188.    echo -en "\e[34m" # Make the following output blue
  189.    cat /proc/asound/cards
  190.    echo -en "\n\e[0m" # End of blue text
  191.    # If not exist then create config file and fill it with the variables:
  192.    if [ ! -e $cfgfile ]
  193.       then
  194.          echo -e "=> No config file found that is named $cfgfile. Going to create one...\n"
  195.          touch $cfgfile
  196.          echo -e "sndcrd=0"    >> $cfgfile
  197.          echo -e "a2j=n"       >> $cfgfile
  198.          echo -e "jack_sink=n" >> $cfgfile
  199.    fi
  200.    echo -e "=> Config file is: $cfgfile"  
  201.       function set_config ()
  202.         {
  203.            sed -i "s/^\($1\s*=\s*\).*\$/\1$2/" $cfgfile
  204.            source $cfgfile
  205.         }
  206.    set_config
  207.    echo -e "\nType in the number of your sound card/audio device:"
  208.       read new_sndcrd
  209.       set_config sndcrd $new_sndcrd
  210.    echo -e "\nWant to make Alsa's Midi also visible as Jack Midi? [y/n]"
  211.       read new_a2j
  212.       set_config a2j $new_a2j
  213.    echo -e "\nWant to sink Jack to PulseAudio? [y/n]"
  214.       read new_jack_sink
  215.       set_config jack_sink $new_jack_sink
  216.    echo -e "Your config file now looks like this: \n"
  217.    cat $cfgfile
  218. ES;fi;;
  219.  
  220. # Delete config file:
  221. 9) S=M9;SC;if [[ $cur == "" ]]; then R
  222.    echo -e "Delete $cfgfile? (y/n)"
  223.    read choice01
  224.    if [[ $choice01 == "y" ]]
  225.       then
  226.          rm $cfgfile
  227.       else
  228.          echo "You chose n or typed in the wrong letter. Not deleting $cfgfile."
  229.    fi
  230. ES;fi;;
  231.  
  232. # Show config file:
  233. 10) S=M10;SC;if [[ $cur == "" ]]; then R
  234.     echo -e "Your config file is: $cfgfile, and its contents is:\n"
  235.     cat $cfgfile
  236. ES;fi;;
  237.  
  238.  
  239.  
  240. ########
  241. # HELP #
  242. ########
  243. 11) S=M11;SC;if [[ $cur == "" ]]; then R
  244.     echo -e  "\e[32;1m\e(0lqqqqqqqqqqqqk "
  245.     echo -e          "x\e(B    Help    \e(0x"
  246.     echo -e  "\e[32;1m\e(0mqqqqqqqqqqqqj  \e[0m\e(B"
  247.     echo -e  "\
  248. 1. You can only get audio in Firefox AFTER starting Pulseaudio, not before!
  249.  
  250. 2. Store/restore alsamixer settings for card 2:
  251.  
  252.   sudo alsactl (re)store 2
  253.  
  254. Beware! Store alsa settings *before* switching from input to output (F3 and F4 etc.). Else: no store.
  255.  
  256. 3. Jack VU meter:
  257.  
  258.   (jmeters -t vu -f mbrl \"Left channel\" \"Right channel\" &); sleep 0.1;\
  259.   jack_connect system:capture_1 jmeters:in-1; jack_connect system:capture_2 jmeters:in-2
  260.  
  261. Note: the jmeters backround process is killed after closing its window.
  262.  
  263. 4. Stop PA from respwawning. Uncomment the following 2 lines from /etc/pulse/client.conf:
  264.  
  265.   autospawn = no
  266.   daemon-binary = /bin/true
  267.  
  268. For newer Linux systems (i.e. Debian 10):
  269.  
  270.   systemctl --user mask pulseaudio.socket
  271.   systemctl --user stop pulseaudio
  272.  
  273. 5. Some handy PulseAudio commands:
  274.  
  275.   pactl info
  276.   pacmd list-sinks
  277. "
  278. ES;fi;;
  279.  
  280. 12) S=M12;SC;if [[ $cur == "" ]]; then R
  281.     clear
  282.     exit 0
  283. fi;;
  284.  
  285.  
  286. esac; POS; done; R
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top