Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Script to ad a Midi device to the RC file of midish. Download from:
- # https://pastebin.com/edit/Q1xS8Ep8
- # Variables:
- # $homedir Home directory.
- # $rcfile RC file for midish.
- # $port Port Number of Midi device to be added.
- # $clientname Client Name of Midi device to be added.
- # $maxdevice Highest dnew number.
- # $linenum Line number with $maxdevice.
- # $lineinput Line after which to insert Midi input device.
- # $lineoutput Line after which to insert Midi output device.
- # Arrays:
- # dnewarray[] Array with dnew numbers.
- # Files:
- # tempaseqdump Tempfile with aseqdump output.
- # To do:
- # - make the script 48 cols wide for use on the Pi screen
- homedir=/home/$USER
- rcfile=$homedir/.midishrc
- # Quit this script, remove it from backgroud and return to main menu
- trap "killall $(basename $0); midishscript.sh" EXIT
- # List currenty connected Midi devices and choose one.
- printf "Choose client number of Midi device to add to midish's RC file:\n\n"
- # Use sed to print only first 40 characters
- aseqdump -l | sed 's/.//40g'
- aseqdump -l > tempaseqdump
- echo
- read -p "Choice: " port
- # Determine Client Name
- # ---------------------
- # Select line containing $port
- clientname=$(awk '/'$port'/' tempaseqdump)
- printf "$clientname" > tempaseqdump
- #printf " Debug: client name is: $clientname.\n"
- # Use awk to select column 2 (= Client Name) and sed to remove trailing spaces.
- # Define field widths for awk as 9, 33 and 41:
- # see: https://stackoverflow.com/questions/26842477/awk-to-use-multiple-spaces-as-delimiter
- # Use sed to remove trailing spaces.
- # If the client name is in there twice (e.g. Korg Monologue) because the client has two ports - one for input and one for output - then remove 2nd line and the carriage return. Use: sed '2d'.
- clientname=$(awk -v FIELDWIDTHS="9 33 41" '{print $2}' tempaseqdump | sed 's/[ ]*$//' | sed '2d')
- # Determine max device number
- # ---------------------------
- # Match line that (starts) with "dnew"; print column/field 2
- dnewarray=( $(awk '{if ($1 == "dnew") print $2}' $rcfile) )
- maxdevice=0
- for x in ${dnewarray[@]}; do
- if (( $x > $maxdevice ))
- then maxdevice=$x
- fi
- done
- # Insert the correct $clientname line into midishrc after $maxdevice number.
- # Use awk to determine number of line/record starting with "dnew $maxdevice".
- # Use sed to insert a new line after the one starting with "dnew $maxdevice".
- linenum=$(awk '/^dnew '$maxdevice'/ {print NR}' $rcfile)
- sed -i "$((linenum + 1))i dnew $((maxdevice + 1)) \"${clientname}\" rw" $rcfile
- # Add $clientname as i or o to midishrc
- # -------------------------------------
- # Replace spaces by undersores in client name:
- clientname="${clientname// /_}"
- # Look for the remark line starting with "# Inputs", if not create it. And determine its line number. Finally insert stuff.
- lineinput=$(awk '/^# Inputs/ {print NR}' $rcfile)
- if [[ -z $lineinput ]]
- then
- sed -i "$((linenum + 3))i # Inputs" $rcfile
- fi
- sed -i "$((lineinput + 1))i inew $clientname {$((maxdevice + 1)) 0}" $rcfile
- # Do the same for output
- lineoutput=$(awk '/^# Outputs/ {print NR}' $rcfile)
- if [[ -z $lineoutput ]]
- then
- sed -i "$((linenum + 6))i # Outputs" $rcfile
- fi
- sed -i "$((lineoutput + 1))i onew $clientname {$((maxdevice + 1)) 0}" $rcfile
- # Cleanup & exit
- rm tempaseqdump
- clear
- printf "Done. Your RC file is:
- \e[34m%s\e[0m
- I created for the Midi client named:
- \e[34m%s\e[0m
- a 'dnew' device number:
- \e[34m%d\e[0m
- which is now defined as Midi input and output on Midi channel 0. You can check this in midish with the command: \"ilist; olist\".\n" $rcfile $clientname $((maxdevice +1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement