0

I'm at a loss at the moment with a problem regarding my bash script trying to convert midi input into key strokes using xdotool.

#!/bin/bash
aseqdump -p "USB MIDI cable" | \
while IFS=" ," read src ev1 ev2 ch label1 data1 label2 data2 rest; do
    case "$ev1 $ev2 $data1" in
        "Note on 48" ) if[$octave=0] 
                         then 
                           xdotool key 9; octave=1 
                       elif[$octave=1] 
                         then xdotool key 1 
                       else 
                           xdotool key 0; octave=1 
                       fi ;;
        "Note on 36" ) xdotool key 9; octave=0 ;;

    esac
done

for my problem: If I understand creating variables correctly, then pressing the key responsible for "Note 36" should set octave to 0 though the if statement on "Note 48" doesn't recognize it. in Addition even using a simpler

if[$octave=1] then xdotool key 1 fi ;;

Does not work with the variable provided.

sooo in the end what the script is supposed to do is convert midi input from a device to keystrokes though depending on the keys pressed beforehand the same key is supposed to output different keystrokes.

Additional Information

  • I am currently running on Ubuntu 22.04
  • The Keys are so far read and translated correctly, only the variable creates issues
Naori
  • 1
  • 2
    Multiple issues with your script. Try running it through [shellcheck](https://www.shellcheck.net/) first and then coming back with any additional questions. – doneal24 Jun 15 '22 at 17:11
  • 2
    `if[$octave=0]` should give you an error. Something like `if[0=0]: command not found`, depending on the value of the variable – ilkkachu Jun 15 '22 at 17:33
  • 1
    also see [Why is my variable local in one 'while read' loop, but not in another seemingly similar loop?](https://unix.stackexchange.com/q/9954/170373) (or [In bash, read after a pipe is not setting values](https://unix.stackexchange.com/q/143958/170373)) – ilkkachu Jun 15 '22 at 17:34
  • @ilkkachu Without the whitespace between `if` and `[`, you should get an `unexpected token` error. – doneal24 Jun 15 '22 at 17:44
  • @doneal24, right, you'd get that for the `then` first. – ilkkachu Jun 15 '22 at 17:52

0 Answers0