sohotcall

rtttl.sh -- Play Nokia Composer Music Notation (RTTTL)

Jan 30th, 2026 (edited)
49
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/usr/bin/bash
  2. # rtttl.sh -- Nokia Composer RTTTL Player
  3. # Requirement: SOX Play ($ sudo apt install sox libsox-fmt-all)
  4. # Usage: rtttl.sh "Cola:d=4,o=5,b=125:8f#6,8f#6,8f#6,8f#6,g6,8f#6,e6,8e6,8a6,f#6,d6,2p"
  5. # Usage: rtttl.sh "16e2 16d2 8#f1 8#g1 16c#2 16b1 8d1 8e1 16b1 16a1 8#c1 8e1 16a1"
  6. a=${*//,/ }
  7. d=4
  8. o=1
  9. b=63
  10. if [[ "$a" == *:* ]]; then
  11.     a="${a#*:}"
  12.     for field in ${a%%:*}; do
  13.         case "$field" in
  14.             d=*) d="${field#d=}" ;;
  15.             o=*) o="${field#o=}" ;;
  16.             b=*) b="${field#b=}" ;;
  17.         esac
  18.     done
  19.     a="${a#*:}"
  20. fi
  21. play="/usr/bin/play -n "
  22. for token in $a; do
  23.     if [[ "$token" =~ ^([0-9]*)?(\.?)(#?)([a-gp-])(#?)([0-9]*)$ ]]; then
  24.         dur=$(( $( [[ -n "${BASH_REMATCH[2]}" ]] && echo 360000 || echo 240000 ) / $b / ${BASH_REMATCH[1]:-$d} ))
  25.         dur=$(echo "scale=3; $dur/1000" | bc)
  26.         #echo "(DUR $dur)"
  27.         if [[ ${BASH_REMATCH[4]} == '-' ]] || [[ ${BASH_REMATCH[4]} == 'p' ]]; then
  28.             play="${play} trim 0 ${dur} ':' "
  29.         else
  30.             note="${BASH_REMATCH[4]}${BASH_REMATCH[3]}${BASH_REMATCH[5]}$(( ${BASH_REMATCH[6]:-$o} % 5 + 5))"
  31.             play="${play} synth ${dur} sin '${note^^}' ':' "
  32.         fi
  33.     fi
  34. done
  35. play="${play} trim 0 0"
  36. echo "echo d=$d,o=$o,b=$b; $play"
  37. eval $play
  38.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment