Advertisement
Meneer_Jansen

midishscript.sh

Jul 6th, 2025 (edited)
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.04 KB | Music | 0 0
  1. #!/bin/bash
  2.  
  3. # midishcscript.sh
  4. # Download this script from: pastebin.com/rRvH5inb
  5. #
  6. # This script lets you program sequences to play with 'midish'. That sequence is saved in a file called "midishtemp" Download midish from:
  7. #
  8. #    https://midish.org
  9. #
  10. # Files/scripts this script also needs
  11. # ====================================
  12. # - midishsong.sh    : song/project script for midish
  13. # - midishchord.sh   : chord script
  14. # - midishcreaterc.sh: add devices to .midishrc
  15. #
  16. # This script REQUIRES!:
  17. # ======================
  18. # - 'Extra RC' for midish by Jeanette C. from:
  19. #   http://juliencoder.de/test/index.php?page=software/index
  20. # - My personal 'midishrc' file because it has additional midish procedures,
  21. #   download from:
  22. #   https://pastebin.com/NcQ3aMaA
  23. #   (deleted due to "abuse reports" and "deemed potentially harmful"!!!???,
  24. #   see e-mail 14-9-'24)
  25. #
  26. # Function list
  27. # =============
  28. # menu           : Main  menu
  29. # help_me        : Help  menu
  30. # other          : Other menu
  31. # song           : Song  menu
  32. # chord          : Chord menu
  33. # list_devices   : Print in- & output devces
  34. # single_note    : Input single note-number via Midi keyboard
  35. # midish_play    : Play a sequence in midish
  36. # noteinput      : Create 16 step sequence (into "midishtemp" file)
  37. # convertnotes   : Convert Midi note-numbers to musical notes or edit them
  38. # connect        : Connect Midi input to output for midish
  39. # play           : Play a synth via midish
  40. # seqplay        : Play a sequence once or in a loop in midish
  41. # kill_midish    : Kill midish processes in the background
  42. # tempo          : Set tempo in BPM
  43. # metronome      : Set metronome on/off
  44. # chord          : Go to chord script
  45. #
  46. # Files this script creates
  47. # =========================
  48. # - midishtemp   : temp/work file with 16 Midi note numbers
  49. #
  50. # To do
  51. # =====
  52. # - Function 'Tempo': make external master clock device work in seq play
  53. #   and loop
  54. # - Write the chord script (chord procedure is already added in .midishrc?)
  55. # - Metronome menu/function.
  56. # - Make exiting play and loop easier.
  57.  
  58.  
  59.  
  60. # Return to Main Menu when pressed Ctrl C
  61. trap "midishscript.sh" 2
  62.  
  63. # Check if tempo is set, if not set it to 100 BPM
  64. if [[ -z $tempo ]]; then
  65.    tempo='100'
  66.    # Save variable for other script
  67.    export tempo
  68. fi
  69.  
  70. # Check if Master clock device is set, if not set it to nil
  71. if [[ -z $masterdevice ]]; then
  72.    masterdevice='nil'
  73. fi
  74.  
  75.  
  76.  
  77. #######################
  78. #  M A I N   M E N U  #
  79. #######################
  80. function menu()
  81. {
  82.    # This function prints the Main menu
  83.    # Reset trap
  84.    trap "exit" 2
  85.    clear              #123456789012345678901234567890123456789012345678#
  86.   #echo -e "\e[37;44;1m――――――――――――◆  M A I N   M E N U  ◆―――――――――――――\e[m"
  87.   #echo -e "\e[37;44;1m :: :: :: ::   M A I N   M E N U   :: :: :: ::  \e[m"
  88.    echo -e "\e[37;44;1m               M A I N   M E N U                \e[m"
  89.    echo -e "\e[1mSequence   \e[0m1. Enter sequence of 16 notes/steps"
  90.    echo              "           2. [E]dit/show notes"
  91.    echo              "           3. Load & save [S]equence menu"
  92.    echo
  93.    echo -e "\e[1mPlayback   \e[0m4. [C]onnect in- and output"
  94.    echo              "           5. [I]nteractively play synth"
  95.    echo              "           6. [P]lay or [L]oop sequence"
  96.    echo
  97.    echo -e "\e[1mSongs      \e[m7. [S]ong menu"
  98.    echo
  99.    echo -e "\e[1mMisc.      \e[0;34m[O] Other menu (tempo, etc.)\e[m"
  100.    echo -e        "           \e[32m[H] Help\e[m"
  101.    echo -e        "           \e[31m[X] Exit\e[m"
  102.    echo -e -n "\n\e[34;1mChoice (Enter to go back to prev. menu/state): \e[0m"; read -N 1 i; echo
  103.    case $i in
  104.       1    ) noteinput;;
  105.       c|4  ) connect;;
  106.       e|2  ) convertnotes;;
  107.       h    ) help_me;;
  108.       i|5  ) play;;
  109.       l|p|6) seqplay;;
  110.       o    ) other;;
  111.       s|3|7) midishsong.sh;;
  112.       x    ) echo; exit
  113.    esac
  114. }
  115.  
  116.  
  117.  
  118. ######################################
  119. #  G E N E R A L  F U N C T I O N S  #
  120. #####################################
  121. function list_devices()
  122. {
  123.    # This function prints in- or outdevices on screen. It is called from/meant to be used in connect().
  124.    #
  125.    # This function NEEDS the following variables to be set:
  126.    #    $devicetype: by the function connect(): inew or onew in- or output
  127.    #                 device type from .midishrc
  128.    #
  129.    # This function sets these varaibles:
  130.    #    $max       : max amount of in- or output devices
  131.    #    $element   : element in array
  132.    #
  133.    # Arrays used:
  134.    #    array[]    : array of device names
  135.  
  136.    # Put elements in an array for awk
  137.    max=$(cat  ~/.midishrc | grep -Ec "$devicetype")
  138.    array=(); array[0]="bogusvalue" # We can now start counting at 1 instead of 0
  139.  
  140.    # Print numbers and in- or ouput devices to choose from and build array of devices
  141.    for (( n=1; n<=$max; n++ ))
  142.    do
  143.       element=$(cat  ~/.midishrc | grep "$devicetype" | \
  144.       awk 'NR=='$n' {print $2}')
  145.       printf "%3s %s\n" $n $element
  146.       array+=("$element")
  147.    done
  148. }
  149.  
  150.  
  151. function connect()
  152. {
  153.    # This function connects input to output.
  154.    #
  155.    # This function NEEDS the function(s):
  156.    #    list_devices: to print in- or output devices on screen
  157.    #
  158.    # This function uses the following array from 'list_devices':
  159.    #    array[]     : array of device names
  160.    #
  161.    # This function sets the variables:
  162.    #    $input      : name of input device in .midishrc
  163.    #    $output     : name of output device in .midishrc
  164.  
  165.    clear
  166.  
  167.    # Choose input device
  168.    devicetype='inew'      # used/needed in list_devices()
  169.    list_devices           # internal function
  170.    # The array "array" from 'list_devices' is used here:
  171.    read -N2 -p "Choose input dev (e.g. keyboard) nr.: " input
  172.    # Convert $input to element from array
  173.    echo "(${array[$input]})"
  174.    input=${array[$input]}
  175.  
  176.    # Choose output device
  177.    devicetype='onew'
  178.    list_devices
  179.    read -N2 -p "Choose output dev (e.g. synth) nr.: " output
  180.    echo "(${array[$output]})"
  181.    output=${array[$output]}
  182.  
  183.    # Save variables for other script
  184.    export input output
  185.    echo -e "\e[34;1mPress enter to return to Menu\e[0m"; read
  186.  
  187.    # Loop
  188.    menu
  189. }
  190.  
  191.  
  192. function single_note()
  193. {
  194.    # This function returns a single Midi note-number input by Midi-keybd.
  195.    #
  196.    # This function is called by the functions:
  197.    #    noteinput()    : enter a seq of 16 notes
  198.    #    convertnotes() : convert Midi note-numbers to musical notes
  199.    #
  200.    # This function NEEDS the following variable(s) to be set:
  201.    #    $portnumber: created by function noteinput()
  202.  
  203.    # Check portnumbers with: 'aseqdump -l'
  204.    aseqdump -p $portnumber | sed \
  205.    -e 's/ '$portnumber':0   Note on                 0, note //'         \
  206.    -e 's/, velocity .*$//'                                              \
  207.    -e '/Note off/d; /Waiting/d; /Source/d; /Polyphonic aftertouch/d'    \
  208.    -e 's/ '$portnumber':0   Control change          0, controller 1, value 127/s /' \
  209.    -e '/ '$portnumber':0   Control change          0, controller 1, value .*$/d'   \
  210.    -e 's/ '$portnumber':0   Pitch bend              0, value -8192/ll/' \
  211.    -e '/ '$portnumber':0   Pitch bend              0, value -.*$/d'     \
  212.    -e 's/ '$portnumber':0   Pitch bend              0, value 8191/l /'  \
  213.    -e '/ '$portnumber':0   Pitch bend              0, value .*$/d'      \
  214.    -e 'q'                                                               \
  215.    | sed -z 's/\n/ /'
  216. }
  217.  
  218.  
  219. function noteinput()
  220. {
  221.    # This function will let you enter a sequence of 16 notes. The numbers: will be saved in the file 'midishtemp'. Opposed to the procedure in my personal ~/.midishc file it does not need the two 's' entries after an 'll'. (note: a 'l' long note doesn't need a [s]ilence at all)
  222.    #
  223.    # This function creates the file(s):
  224.    #    midishtemp    : file with the 16 midi note-numbers
  225.    #
  226.    # This function needs the function(s):
  227.    #    single_note   : returns a single Midi note-number to be saved
  228.    #
  229.    # This function sets the follown variables:
  230.    #    $portnumber   : Midi port-number of keyboard to enter notes with
  231.    #    $max          : number of notes
  232.    #    $n            : counter to count the inputted notes (step)
  233.    #    $m            : $n minus 1 to determine previous step
  234.    #    $i            : counter to count to 2
  235.  
  236.    # Reset trap
  237.    trap "menu" 2
  238.  
  239.    clear
  240.    echo -e "Determine your portnumber from output below:\n"
  241.    # Use sed to remove anything after the 40th character
  242.    aseqdump -l | sed 's/.//40g'
  243.    echo -e "\nInput portnumber and (re)enter your notes. Press Ctrl+C to return to the Menu if you're satisfied with the notes you've entered before."
  244.    read portnumber
  245.  
  246.    rm midishtemp
  247.    max=16
  248.    echo "Steps/notes:"
  249.  
  250.    # Do for all the (16) steps
  251.    for (( n=1; n<=$max; n++ ))
  252.    do
  253.       printf "[%2s]" $n;
  254.       # Use the function single_note
  255.       single_note | \
  256.       tee -a midishtemp
  257.       # Concatenate/remove line ending
  258.       sed -i -z 's/\n/ /g' midishtemp
  259.       # If note = ll, Then the next step is simply the note input.
  260.       # If (step - 2) was ll then the next 2 entries are 's' (= skip)
  261.       # and continue for n=n+2.
  262.       m=$(($n-1))   # m is previous step
  263.       if  [[ $m -gt 0 ]]
  264.          then
  265.          if [[ $(echo "$(awk '{print $'$m'}' midishtemp)") == 'll' ]]
  266.             then
  267.             echo -n "s  s  "  >> midishtemp
  268.             # Print two times on screen the step and [s]ilence
  269.             for (( i=1; i<=2; i++ ))
  270.             do
  271.                # If multple of 4 then new line
  272.                if (( $n % 4 == 0 ));
  273.                   then echo
  274.                fi
  275.                let n++   # you can't use "just" use n++ in Bash
  276.                printf "[%2s]" $n; printf "s  "
  277.             done
  278.          fi
  279.       fi
  280.       # If multple of 4 then new line:
  281.       if (( $n % 4 == 0 ));
  282.          then echo
  283.       fi
  284.    done
  285.  
  286.    # Loop
  287.    echo -e "\n\e[34;1mPress enter to return to Menu\e[0m"; read bogusvalue
  288.    menu
  289. }
  290.  
  291.  
  292. function kill_midish()
  293. {
  294.    killall midish
  295.    echo -e "\e[34;1mPress enter to return to Menu\e[0m"; read bogusvalue
  296.    other
  297. }
  298.  
  299.  
  300. #######################
  301. #  S E Q U E N S E S  #
  302. #######################
  303. function convertnotes()
  304. {
  305.    # This function converts Midi note-numbers from "midishtemp"" to musical notes (to print then in human readable on screen) and offers to edit them or show the Midi note-numbers.
  306.    #
  307.    # This function uses the array(s):
  308.    #    notes         : array containing notes, used to convert note-numbers
  309.    #
  310.    # This function needs the file(s):
  311.    #    midishtemp    : contains the Midi note-numbers, made by noteinput().
  312.    #    midishtemptemp: awk can't do in-line editing (like sed can)
  313.    #
  314.    # This function sets the variable(s):
  315.    #    $max          : number of enries in 'midishtemp'
  316.    #    $n            : counter for the entries in 'midishtemp'
  317.    #    $entry        : entry number $n in 'midishtemp'
  318.    #    $answer       : edit note or not?
  319.    #    $portnumber   : portnumber set in noteinput()
  320.    #    $step         : step in 'midishtemp' to change
  321.    #    $note         : input note by Midi keybd (by noteinput())
  322.    #
  323.    # This function calls the function(s):
  324.    #    single_note   : input a single not with a Midi-keyboard
  325.    #    which depends on:
  326.    #    noteinput()   : create 16 step sequence and set $portnumber
  327.    #
  328.    # To do:
  329.    #    - Get rid of the dirty workaround with -v $note in the awk command.
  330.  
  331.  
  332.    # Below is an array with all music notes. Example: entry 47 is note C3, etc.:
  333.    #      000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 104 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  334.    notes=(C#  D2  D#  E   F   F#  G   G#  A   A#  B   C   C#  D2  D#  E   F   F#  G   G#  A   A#  B   C1  C#1 D21 D#1 E1  F1  F#1 G1  G#1 A1  A#1 B1  C2  C#2 D2  D#2 E2  F2  F#2 G2  G#2 A2  A#2 B2  C3  C#3 D3  D#3 E3  F3  F#3 G3  G#3 A3  A#3 B3  C4  C#4 D4  D#4 E4  F4  F#4 G4  G#4 A4  A#4 B4  C5  C#5 D5  D#5 E5  F5  F#5 G5  G#5 A5  A#5 B5  C6  C#6 D6  D#6 E6  F6  F#6 G6  G#6 A6  A#6 B6  C7  C#7 D7  D#7 E7  F7  F#7 G7  G#7 A7  A#7 B7  C8  C#8 D8  D#8 E8  F8  F#8 G8  G#8 A8  A#8 B8)    
  335.  
  336.    clear
  337.  
  338.    # Show notes
  339.    max=$(awk '{print NF}' midishtemp)
  340.    echo -e "\e[34;1mSteps/beats: \e[0m"
  341.    for (( n=1; n<=$max; n++ ))
  342.    do
  343.       entry=$(awk '{print $'$n'}' midishtemp)
  344.       # If number then convert, if letter (like 'l' for long note) then print
  345.       if [[ $entry =~ [0-9] ]]
  346.          then
  347.          # Print every entry in 8 "spaces"
  348.          #printf "[%2s]" $n; printf "%-4s" ${notes[$entry]}
  349.          printf "[%2s]%-4s" $n ${notes[$entry]}
  350.          else
  351.          printf "[%2s]%-4s" $n $entry
  352.       fi
  353.       # If multple of 4 then new line
  354.       if (( $n % 4 == 0 ));
  355.          then  echo
  356.       fi
  357.    done
  358.  
  359.    # Ask to edit notes or show note-numbers, else back to Menu
  360.    printf "\e[34;1m\nChoose:\n\e[0m"
  361.    printf "    [e] Edit a note.\n"
  362.    printf "[Enter] Show the array of Midi note-numbers to\n        use in midish.\n"
  363.    read -sN 1 answer
  364.    echo
  365.    if [[ $answer != "e" ]]
  366.       then
  367.       cat midishtemp
  368.       echo -e "\e[34;1m\nPress enter to return to Menu\e[0m"; read
  369.       menu
  370.    fi
  371.  
  372.    # Check if port-number has been set already i.e if it is a number. If not then ask for a portnumber.
  373.    if ! [[ $portnumber =~ ^[0-9]+$ ]]
  374.       then
  375.       aseqdump -l | sed 's/.//40g'  
  376.       printf "Port number of Midi keyboard: "
  377.       read portnumber
  378.    fi
  379.  
  380.    printf "Step to change: "
  381.    read step
  382.    printf "Enter note on Midi keyboard:"
  383.    # Use the function 'single_note'. Note: that function needs the var $portnumber. If you haven't called the function 'noteinput' then that $portnumber isn't set.
  384.    # We must use an ugly -v workaround for awk, maybe this can be done differently?
  385.    # With awk replace one note (i.e. one field) in the only record in the file.
  386.    awk -v note=$(single_note) '{ {$'$step'= note} print $0 }' midishtemp > midishtemptemp; mv midishtemptemp midishtemp
  387.    # Concatenate/remove line ending:
  388.    sed -i -z 's/\n/ /g' midishtemp
  389.    # Loop back:
  390.    $FUNCNAME
  391. }
  392.  
  393.  
  394. function play()
  395. {
  396.    # This function lets one play a synth in midish "interactive" mode. Adittionally it can send midish to the background.
  397.    #
  398.    # This function connects previously set $input to $output (from the function connect()) and starts [i]nteractive mode in midish.
  399.  
  400.    trap "menu" 2
  401.  
  402.    function play_my_synth()
  403.    {
  404.       midish -b <<END
  405.       exec "/home/$USER/.midishrc"
  406.       exec "/home/$USER/.midish_extrarc"
  407.       rnew $input $output
  408.       $clock_command
  409.       i
  410. END
  411.    }
  412.  
  413.    read -N 1 -p "Do you want to direct midish to the background [y/n=Enter]? " answer; echo
  414.    if [[ $answer == 'y' ]]
  415.       then
  416.       play_my_synth &>/dev/null &
  417.       echo "Midish is now running in the backround."
  418.       else
  419.       play_my_synth
  420.    fi
  421.    echo -e "\e[34;1mPress enter to return to Menu\e[0m"; read bogusvalue
  422.    menu
  423. }
  424.  
  425.  
  426. function midish_play()
  427. {
  428.    # This function plays a sequence in midish.
  429.    #
  430.    # This function needs the following variable(s) to be set for additional
  431.    # midish commands (loop etc.):
  432.    #
  433.    #    $midish_command: additional midish commands
  434.  
  435.    midish -b <<-END
  436.    print
  437.    print "============================================================================"
  438.    exec "/home/$USER/.midishrc"
  439.    exec "/home/$USER/.midish_extrarc"
  440.    print "============================================================================"
  441.    print
  442.    print
  443.    rnew $input $output
  444.    t $tempo
  445.    sequence $seq
  446.    tcheck
  447.    $clock_command
  448.    print
  449.    print
  450.    print
  451.    print
  452.    print
  453.    print
  454.    print
  455.    print
  456.    print
  457.    print
  458.    print
  459.    print
  460.    print
  461.    print
  462.    print
  463.    print
  464.    print
  465.    print "Starting playback."
  466.    print "Ignore the lines below stating: 'alsa_open: couldn't parse alsa port'."
  467.    $midish_command
  468.    p
  469.     END
  470. }
  471.  
  472.  
  473. function seqplay()
  474. {
  475.    # This function plays a sequence once or in a loop.
  476.    #
  477.    # This function NEEDS the function(s):
  478.    #    midish_play    : to play a sequence
  479.    #
  480.    # This function defines the following variables:
  481.    #    $seq           : sequence between curly braces
  482.    #    $answer        : play or loop?
  483.    #
  484.    # This function sets the following variable(s) for other fu's:
  485.    #    $midish_command: additional commands to use in midish_play()
  486.  
  487.    # Reset trap
  488.    trap "menu" 2
  489.    
  490.    # Check if in- and out put are set
  491.    if [[ -z $output ]]; then
  492.       echo "Connect in- and output first."
  493.       read -p "Press Enter to continue..." bogusvalue
  494.       menu
  495.    fi
  496.  
  497.    # Place midi note-numbers between accoulades and get rid of the bleedin' line ending
  498.    seq=$(printf "{";  sed -z 's/\n//' midishtemp; printf "}")
  499.  
  500.    # Make choice: play or loop
  501.    read -N 1 -p "Choose [p]lay or [l]oop current sequence." answer
  502.    echo
  503.    if [[ $answer == 'p' ]]
  504.       then
  505.       #my
  506.       midish_command=""
  507.       midish_play
  508.       else
  509.       #loop
  510.       # Test if this works:
  511.       midish_command="sel 1; loop"
  512.       midish_play
  513.    fi
  514.  
  515.    # Loop back to menu
  516.    trap "midishscript.sh" 2 # set trap back to "normal"
  517.    echo -e "\e[34;1mPress enter to return to Menu\e[0m"; read bogusvalue
  518.    menu
  519. }
  520.  
  521.  
  522.  
  523. #########################
  524. #  M E N U   O T H E R  #
  525. #########################
  526. function other()
  527. {
  528.    # 'Other' menu.
  529.    # Reset trap:
  530.    trap "exit" 2
  531.    clear
  532.    echo "Other"
  533.    echo "====="
  534.    echo "1. [T]empo: Midi and Master device"
  535.    echo "2. Set metronome on/off"
  536.    echo "3. [K]ill midish in backround"
  537.    echo "4. Chord menu"
  538.    echo "5. Add Midi device to midish"
  539.    echo
  540.    echo "M. Main menu"
  541.  
  542.    echo -e -n "\nChoice (don't press Enter): "; read -N 1 i; echo
  543.    case $i in
  544.       2) metronome;;
  545.       4) chord;;
  546.       5) midishcreaterc.sh;;
  547.       k|3) killall midish; menu;;
  548.       m) menu;;
  549.       t|1) tempo
  550.    esac
  551. }
  552.  
  553.  
  554. function tempo()
  555. {
  556.   # This function sets the tempo and the Master device for the clock (tempo).
  557.    #
  558.    # This function sets the following variable(s):
  559.    #    $tempo        : currenent/new tempo
  560.    #    $tempo_old    : save old value of $tempo for later
  561.    #    $max          : number of devices in .midishrc
  562.    #    $masterdevice : master device for the clock, used to set $clock_command
  563.    #    $new_masterdevice: new master device
  564.    #    $clock_command: used in the other script, in play_chain()
  565.  
  566.    clear
  567.  
  568.    # 1. Set tempo
  569.    echo "Current Midi tempo: $tempo"
  570.    #; tempo_old="$tempo" # save old tempo for later
  571.    read -p "New tempo (press Enter to skip): " new_tempo
  572.    # If NOT pressed Enter (ASCII \0A) then set tempo to new tempo. Else do nothing.
  573.    # https://stackoverflow.com/questions/2612274/bash-shell-scripting-detect-the-enter-key
  574.    if [[ $new_tempo != $'\0A' ]]; then
  575.       tempo=$new_tempo
  576.       # Save variable $tempo for other script
  577.       export tempo
  578.    fi
  579.  
  580.    # 2. Set Master clock device
  581.    echo
  582.    echo -e "Current Master clock device (nil means R. Pi): $masterdevice \nList of Master clock devices:"
  583.    # Print list of midish devices
  584.    max=$(cat  ~/.midishrc | grep -Ec "dnew")
  585.    for (( n=1; n<=$max; n++ ))
  586.    do
  587.       # Use awk twice: first with the standard [F]ield separator <space> for the device number and then with " as FS for the device name.
  588.       cat  ~/.midishrc | grep "dnew" | awk       'NR=='$n' {printf "Device %s = ", $2}'
  589.       cat  ~/.midishrc | grep "dnew" | awk -F'"' 'NR=='$n' {printf "%s\n", $2}'
  590.    done
  591.  
  592.    read -p "New Master clock device (press Enter to skip): " new_masterdevice
  593.  
  594.    # If NOT pressed Enter (ASCII \0A) then set new master device, else skip. Also check if device number is correct because midish won't work w/ a wrong dev.nr.
  595.    # Midish bug? In batch (-b) mode you cannot set 'dclkrx nil' like in normal mode. So IF $masterdevice is nil THEN ...
  596.    if [[ $new_masterdevice != $'\0A' && $new_masterdevice -lt $max ]]; then
  597.       masterdevice=$new_masterdevice
  598.       # Convert $masterdevice into $clock_command
  599.       clock_command="dclkrx $masterdevice"
  600.       # Save variable for other script
  601.       export clock_command
  602.    elif [[ $new_masterdevice -gt $((max-1)) ]]; then
  603.       echo "Wrong device number entered. Try again."; read -p "Press Enter to continue..."
  604.       # Loop
  605.       tempo
  606.    fi
  607.  
  608.    # Loop
  609.    read -p "Press Enter to continue..." bogusvalue
  610.    menu
  611. }
  612.  
  613.  
  614. function metronome()
  615. {
  616.    echo "WiP"
  617. }
  618.  
  619.  
  620. function chord()
  621. {
  622.   # WiP ...
  623.   midishchord.sh
  624.   # 1. Enter chord(s)
  625.   # 2. Chain chords into song (in separate midish track?)
  626.   # 3. Can I use an existing functions or write (a whole lotta) new ones?
  627. }
  628.  
  629.  
  630. ###################
  631. #  H E L P   M E  #
  632. ###################
  633. function help_me()
  634. {
  635.    clear
  636.    echo -e "\e[32m\
  637. 1. This Bash script is meant to be used as a simple old school sequencer. You create bars of 16 steps and chain those into songs. This script uses 'midish' from https://midish.org .
  638.  
  639. 2. Make sure that you've defined your Midi hardware in midish's config file ~.midishrc!
  640.  
  641. 3. This script also uses the 'midish_extrarc' file from http://juliencoder.de/test/index.php?page=software/index .
  642.  
  643. 4. When entering notes for a sequence you can push the mod wheel all the way up and back again to enter a [s]ilence/skip. You can push the pitch wheel all the way up to enter a [l]ong note (of 2 steps) after the 'l'. Or you can push the pitch wheel all the way down to enter a very [ll]ong note (of 4 steps/one beat) after the 'll'.
  644. \e[0m" | more -d
  645.    echo -e "\e[34;1mPress enter to return to Menu\e[0m"; read bogusvalue
  646.    menu
  647. }
  648.  
  649.  
  650. ###################################
  651. #  S T A R T   O F   S C R I P T  #
  652. ###################################
  653. # For use in the other script. If you start this script w/ the commandline option -c then it jumps to the function 'connect'.
  654. if [[ $1 == '-c' ]]; then
  655.    connect
  656. fi
  657. menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement