Advertisement
Guest User

menuaudio.sh

a guest
Mar 13th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.01 KB | None | 0 0
  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.  
  5. # Original unmodified script written by oToGamez (www.pro-toolz.net).
  6.  
  7. # Define variables.
  8. # This is your config file:
  9. cfgfile="`dirname $0`/menuaudio.cfg"
  10.  
  11. # Use that file as the source for variables:
  12. source $cfgfile
  13.  
  14. # If received SIGINT (i.e. CTRL C) then reset screen and exit. See "trap -l"
  15. trap "R;exit" 2    
  16.  
  17.  
  18.  
  19. # This is the menu:
  20. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  21.      M0 () { TPUT  7 2; echo -en       "Jack audio daemon: start               ";}
  22.      M1 () { TPUT  8 2; echo -en       "                 : kill                ";}
  23.      M2 () { TPUT  9 2; echo -en       "Check Midi       : port numbers        ";}
  24.      M3 () { TPUT 10 2; echo -en       "                 : output              ";}
  25.      M4 () { TPUT 11 2; echo -en       "Check Alsa       : device/card numbers ";}
  26.      M5 () { TPUT 12 2; echo -en       "Pulseaudio       : start               ";}
  27.      M6 () { TPUT 13 2; echo -en       "                 : stop                ";}
  28.      M7 () { TPUT 14 2; echo -en       "                 : PAVUControl         ";}
  29.      M8 () { TPUT 15 2; echo -en       "Config file      : create/edit         ";}
  30.      M9 () { TPUT 16 2; echo -en       "                 : delete              ";}
  31.      M10() { TPUT 17 2; echo -en       "                 : view                ";}
  32.      M11() { TPUT 18 2; echo -en "\e[32mHelp                                  \e[0m";}
  33.      M12() { TPUT 19 2; echo -en "\e[31mExit                                  \e[0m";}
  34. # Last Menu item is:
  35. LM=12
  36. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. # These are some more functions that are needed by the script. You don't ever need to edit this.
  46. #<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
  47. # Reset: clear screen, clean terminal and no inverse:
  48. R(){ clear;stty sane;echo -en "\e[27m";}
  49.  
  50.    TPUT(){ echo -en "\e[${1};${2}H";}                # Print text starting on line $1 and 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              Midi 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. ES;fi;;
  103.  
  104. #  Jack audio daemon stop
  105. 1) S=M1;SC;if [[ $cur == "" ]]; then R
  106.    pkill -9 jackdbus
  107.    killall jackd
  108.    sleep 1
  109. ES;fi;;
  110.  
  111.  
  112. ########
  113. # MIDI #
  114. ########
  115. #  Check Midi port numbers
  116. 2) S=M2;SC;if [[ $cur == "" ]]; then R
  117.    aconnect -io
  118. ES;fi;;
  119.  
  120. # Check Midi output:
  121. 3) S=M3;SC;if [[ $cur == "" ]]; then R
  122.    echo "Type in Midi port number:"
  123.    read portnumber
  124.    aseqdump -p $portnumber
  125. ES;fi;;
  126.  
  127.  
  128. ########
  129. # Alsa #
  130. ########
  131. 4) S=M4;SC;if [[ $cur == "" ]]; then R
  132.    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"
  133.    echo -en "\e[34m" # Make the following output blue
  134.    cat /proc/asound/cards
  135.    echo -en "\e[0m"
  136. ES;fi;;
  137.  
  138.  
  139. #########
  140. # PULSE #
  141. #########
  142. #  Pulse start:
  143. 5) S=M5;SC;if [[ $cur == "" ]]; then R
  144.    pulseaudio --start -v
  145. ES;fi;;
  146.  
  147. # Pulse kill:
  148. 6) S=M6;SC;if [[ $cur == "" ]]; then R
  149.    pulseaudio --kill
  150. ES;fi;;
  151.  
  152. #  PA VU Control:
  153. 7) S=M7;SC;if [[ $cur == "" ]]; then R
  154.    echo -e "\e[34;1mPAVUControl is running. \e[0m"
  155.    pavucontrol
  156. ES;fi;;
  157.  
  158.  
  159. ###############
  160. # Config file #
  161. ###############
  162. # Create/edit config file:
  163. 8) S=M8;SC;if [[ $cur == "" ]]; then R
  164.    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"
  165.    echo -en "\e[34m" # Make the following output blue
  166.    cat /proc/asound/cards
  167.    echo -en "\n\e[0m" # End of blue text
  168.    # If not exist then create config file and fill it with the variables:
  169.    if [ ! -e $cfgfile ]
  170.       then
  171.          echo -e "=> No config file found that is named $cfgfile. Going to create one...\n"
  172.          touch $cfgfile
  173.          echo -e "sndcrd=0" >> $cfgfile
  174.          # Want more variables in it? Do:
  175.          # echo -e "var02=0" >> $cfgfile
  176.          # echo -e "var03=0" >> $cfgfile
  177.    fi
  178.    echo -e "=> Config file is: $cfgfile"  
  179.    function set_config ()
  180.      {
  181.         sed -i "s/^\($1\s*=\s*\).*\$/\1$2/" $cfgfile
  182.         source $cfgfile
  183.      }
  184.    set_config
  185.    echo -e "\nType in the number of your sound card/audio device:"
  186.    read new_sndcrd
  187.    set_config sndcrd $new_sndcrd
  188.    echo -e "Your config file now looks like this: \n"
  189.    cat $cfgfile
  190. ES;fi;;
  191.  
  192. # Delete config file:
  193. 9) S=M9;SC;if [[ $cur == "" ]]; then R
  194.    echo -e "Delete $cfgfile? (y/n)"
  195.    read choice01
  196.    if [[ $choice01 == "y" ]]
  197.       then
  198.          rm $cfgfile
  199.       else
  200.          echo "You chose n or typed in the wrong letter. Not deleting $cfgfile."
  201.    fi
  202. ES;fi;;
  203.  
  204. # Show config file:
  205. 10) S=M10;SC;if [[ $cur == "" ]]; then R
  206.     echo -e "Your config file is: $cfgfile, and its contents is:\n"
  207.     cat $cfgfile
  208. ES;fi;;
  209.  
  210.  
  211. ########
  212. # HELP #
  213. ########
  214. 11) S=M11;SC;if [[ $cur == "" ]]; then R
  215.     echo -e  "\e[32;1m\e(0lqqqqqqqqqqqqk "
  216.     echo -e          "x\e(B    Help    \e(0x"
  217.     echo -e  "\e[32;1m\e(0mqqqqqqqqqqqqj  \e[0m\e(B"
  218.     echo -e  "\
  219. 1. You can only get audio in Firefox AFTER starting Pulseaudio, not before!
  220.  
  221. 2. Store/restore alsamixer settings for card 2:
  222.  
  223.   sudo alsactl (re)store 2
  224.  
  225. Beware! Store alsa settings *before* switching from input to output (F3 and F4 etc.). Else: no store.
  226.  
  227. 3. Jack VU meter:
  228.  
  229.   (jmeters -t vu \"VU Meter\" &); sleep 0.1;\
  230.   jack_connect system:capture_1 jmeters:in-1
  231.  
  232. Note: the jmeters backround process is killed after closing its window.
  233.  
  234. 4. Stop PA from respwawning. Uncomment the following 2 lines from /etc/pulse/client.conf:
  235.  
  236.   autospawn = no
  237.   daemon-binary = /bin/true"
  238. ES;fi;;
  239.  
  240. 12) S=M12;SC;if [[ $cur == "" ]]; then R
  241.     clear
  242.     exit 0
  243. fi;;
  244.  
  245.  
  246. esac; POS; done; R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement