diff --git a/send-midi.sh b/send-midi.sh new file mode 100755 index 0000000..25fc8c8 --- /dev/null +++ b/send-midi.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# author: Daniel Sommer +# license: MIT + +dir="$(dirname $(realpath "$0"))" + +. "$dir/config.env" + +function checkVariable() { + [[ -z "$1" ]] && printf "${FONT_BOLD}error: ${FONT_NORMAL}no $2 given\n" && exit 1 + ! [ "$1" -eq "$1" ] 2> /dev/null && printf "${FONT_BOLD}error: ${FONT_NORMAL}given $2 \'$1\' is not a number\n" && exit 1 +} + +checkVariable "$1" "midi channel" +checkVariable "$2" "midi controller" +checkVariable "$3" "value" + +url="$(""$dir"/url.sh" "/midi")" + +printf "> sending POST request to \'$url\'...${FONT_BOLD}" +[ "$(curl -X POST -s -f -w "\n%{http_code}" "$url" -d "channel=$1" -d "controller=$2" -d "value=$3" | tail -n1)" -ne 200 ] && printf " error!\n" || printf " done!\n" \ No newline at end of file