diff --git a/MidiOSC.sh b/MidiOSC.sh
index e289a0c..ca097c4 100755
--- a/MidiOSC.sh
+++ b/MidiOSC.sh
@@ -49,6 +49,202 @@ function finish {
trap finish EXIT
+function cctapspeed {
+ ccchannel=$1
+ ccnumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $ccchannel control-change $ccnumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum dat
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)*$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ param100=$((100000/$tempo))
+ printf -v param1 "%03d" $param100
+ param=${param1%??}.${param1: -2}
+ b=$(
+ for ((i=0;i<${#param};i++));do printf "%02X " \'"${param:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+done } &
+}
+
+function cctaptime {
+ ccchannel=$1
+ ccnumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $ccchannel control-change $ccnumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum dat
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)/$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ b=$(
+ for ((i=0;i<${#tempo};i++));do printf "%02X " \'"${tempo:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+done } &
+}
+
+function noteontapspeed {
+ notechannel=$1
+ notenumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $notechannel note-on $notenumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum dat
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)*$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ param100=$((100000/$tempo))
+ printf -v param1 "%03d" $param100
+ param=${param1%??}.${param1: -2}
+ b=$(
+ for ((i=0;i<${#param};i++));do printf "%02X " \'"${param:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+done } &
+}
+
+function noteontaptime {
+ notechannel=$1
+ notenumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $notechannel note-on $notenumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum dat
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)/$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ b=$(
+ for ((i=0;i<${#tempo};i++));do printf "%02X " \'"${tempo:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+done } &
+}
+
+function pchtapspeed {
+ pchchannel=$1
+ pchnumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $pchchannel program-change $pchnumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)*$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ param100=$((100000/$tempo))
+ printf -v param1 "%03d" $param100
+ param=${param1%??}.${param1: -2}
+ b=$(
+ for ((i=0;i<${#param};i++));do printf "%02X " \'"${param:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+
+done } &
+}
+
+function pchtaptime {
+ pchchannel=$1
+ pchnumber=$2
+ maxtime=$3
+ oscpath=$4
+
+ oldtime=0
+ if [ $# -gt 4 ]; then mult=$6; else mult=1; fi
+
+ Xpath=$(
+ for ((i=0;i<${#oscpath};i++));do printf "%02X " \'"${oscpath:$i:1}";
+ done
+ )
+
+ { receivemidi ts dev $mididevice channel $pchchannel program-change $pchnumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum
+ do
+ newtime="$((10#$msec+10#$sec*1000+10#$min*60000+10#$hr*3600000))"
+ tempo=$((($newtime - $oldtime)/$mult))
+ if [ $tempo -le $maxtime -a $newtime -gt $oldtime ]
+ then
+ b=$(
+ for ((i=0;i<${#tempo};i++));do printf "%02X " \'"${tempo:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $Xpath 20 $b F7" > $pipe
+ fi
+ oldtime=$newtime
+done } &
+}
+
function cc2param {
ccchannel=$1
ccnumber=$2
@@ -157,6 +353,96 @@ function prgm {
done < "$fn"
fi
}
+
+function global {
+ fn=$1
+ pn=$(basename $fn)
+
+ prgmpids="/tmp/prgm.$pn.$$"
+
+ tmpfiles+=("$prgmpids")
+ while read -r pcmd
+ do
+ if [ "$pcmd" != "" ];
+ then
+ $pcmd
+ echo -n "$(list_descendants $!) $!" >> "$prgmpids"
+ fi
+ done < "$fn"
+}
+
+function load {
+ fn=$1
+ while read -r pcmd
+ do
+ if [ "$pcmd" != "" ];
+ then
+ echo "$pcmd" > $cpipe
+ fi
+ done < "$fn" &
+}
+
+function snapload {
+ sn=$1
+ a="/-snap/load $sn"
+ b=$(
+ for ((i=0;i<${#a};i++));do printf "%02X " \'"${a:$i:1}";
+ done
+ )
+ echo "hex raw F0 00 20 32 32 $b F7" > $pipe
+}
+
+function pch2 {
+ pchchannel=$1
+ pchnumber=$2
+
+ shift 2
+
+ { receivemidi ts dev $mididevice channel $pchchannel program-change $pchnumber |
+ while IFS=":. " read hr min sec msec ch chnum type typenum
+ do
+ echo "$@" > $cpipe
+ done } &
+}
+
+function setlist {
+ setlistindex=-1
+ setlistarray=( "$@" )
+}
+
+function next {
+ case $setlistindex in
+ -1)
+ setlistindex=0
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ ;;
+ $((${#setlistarray[@]}-1)))
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ echo "End of SetList"
+ ;;
+ *)
+ setlistindex=$((setlistindex+1))
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ ;;
+ esac
+}
+
+function previous {
+ case $setlistindex in
+ -1)
+ setlistindex=0
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ ;;
+ 0)
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ echo "Beginning of SetList"
+ ;;
+ *)
+ setlistindex=$((setlistindex-1))
+ echo "prgm ${setlistarray[setlistindex]}" > $cpipe
+ ;;
+ esac
+}
function list {
echo "Number of commands running: ${#proctree[@]} "
@@ -167,24 +453,112 @@ function list {
}
function prune {
- while [ $# -ge 1 ]
- do
- prnarray=( ${proctree[(($1-1))]} )
- case ${prnarray[0]} in
- prgm)
- disown $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
- kill $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
- unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
- ;;
- *)
- tokill="$(list_descendants ${prnarray[0]}) ${prnarray[0]}"
- disown $tokill 2>/dev/null
- kill $tokill 2>/dev/null
- unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
- ;;
- esac
- shift
- done
+ if [ $1 = "all" ]; then
+ for i in ${!proctree[@]} ; do
+ prnarray=( ${proctree[i]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ disown $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
+ kill $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
+ unset 'proctree[i]' 'pausetree[i]'
+ ;;
+ *)
+ tokill="$(list_descendants ${prnarray[0]}) ${prnarray[0]}"
+ disown $tokill 2>/dev/null
+ kill $tokill 2>/dev/null
+ unset 'proctree[i]' 'pausetree[i]'
+ ;;
+ esac
+ done
+ else
+ while [ $# -ge 1 ]
+ do
+ prnarray=( ${proctree[(($1-1))]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ disown $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
+ kill $(cat "/tmp/prgm.${prnarray[1]}.$$") 2>/dev/null
+ unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
+ ;;
+ *)
+ tokill="$(list_descendants ${prnarray[0]}) ${prnarray[0]}"
+ disown $tokill 2>/dev/null
+ kill $tokill 2>/dev/null
+ unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
+ ;;
+ esac
+ shift
+ done
+ fi
+}
+
+function save {
+ fn=$1
+ shift
+ > $fn
+ if [ $1 = "all" ]; then
+ for i in ${!proctree[@]} ; do
+ prnarray=( ${proctree[i]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ *)
+ unset 'prnarray[0]'
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ esac
+ done
+ else
+ while [ $# -ge 1 ]
+ do
+ prnarray=( ${proctree[(($1-1))]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ *)
+ unset 'prnarray[0]'
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ esac
+ shift
+ done
+ fi
+}
+
+function append {
+ fn=$1
+ shift
+ if [ $1 = "all" ]; then
+ for i in ${!proctree[@]} ; do
+ prnarray=( ${proctree[i]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ *)
+ unset 'prnarray[0]'
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ esac
+ done
+ else
+ while [ $# -ge 1 ]
+ do
+ prnarray=( ${proctree[(($1-1))]} )
+ case ${prnarray[0]} in
+ prgm|global)
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ *)
+ unset 'prnarray[0]'
+ echo "${prnarray[@]}" >> $fn
+ ;;
+ esac
+ shift
+ done
+ fi
}
function pause {
@@ -246,9 +620,9 @@ if [ $# -gt 2 ]
"$@"
cmdarray=( "$@" )
case ${cmdarray[0]} in
- list|prune|pause|resume)
+ list|prune|pause|resume|load|snapload|save|append|next|previous|setlist)
;;
- prgm)
+ prgm|global)
exists=0
for i in ${!proctree[@]} ; do
if [ "${proctree[i]}" = "${cmdarray[0]} $pn" ]; then exists=1; fi
@@ -275,27 +649,31 @@ do
then
break
fi
-
- $cmd
- cmdarray=( $cmd )
-case ${cmdarray[0]} in
- list|prune|pause|resume)
- ;;
- prgm)
- exists=0
- for i in ${!proctree[@]} ; do
- if [ "${proctree[i]}" = "${cmdarray[0]} $pn" ]; then exists=1; fi
- done
- if [ $exists = 0 ]; then
- proctree+=( "${cmdarray[0]} $pn" )
- pausetree+=( " " )
- fi
- ;;
- *)
- proctree+=( "$! $cmd" )
- pausetree+=( " " )
- ;;
- esac
+
+ cmdarray=( $cmd )
+ if [[ $(compgen -A function) = *"${cmdarray[0]}"* ]]; then
+ $cmd
+ case ${cmdarray[0]} in
+ list|prune|pause|resume|load|snapload|save|append|next|previous|setlist)
+ ;;
+ prgm|global)
+ exists=0
+ for i in ${!proctree[@]} ; do
+ if [ "${proctree[i]}" = "${cmdarray[0]} $pn" ]; then exists=1; fi
+ done
+ if [ $exists = 0 ]; then
+ proctree+=( "${cmdarray[0]} $pn" )
+ pausetree+=( " " )
+ fi
+ ;;
+ *)
+ proctree+=( "$! $cmd" )
+ pausetree+=( " " )
+ ;;
+ esac
+ else
+ echo "command ${cmdarray[0]} unrecognized"
+ fi
done <> $cpipe &
diff --git a/README.md b/README.md
index be1c2f3..bd45414 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,7 @@ Saves a list of cammands to a file called filename. commands are taken fr
Saves a list of cammands to a file called filename. commands are taken from the current "list" and are designated by their "list" command numbers. If command# is "all", all commands are saved to filename. filename is created if it does not exist and is appended to if it does exist.
### MidiOSC.sh
-**Note: currently MidiOSC.sh is behind NetOSC.sh, and does not support the latest commands. This will be rectified shortly.**
+**Note: currently MidiOSC.sh is updated with all NetOSC.sh commands, but is untested. Please open an issue if you find bugs.**
**MidiOSC.sh** MIDI-input-device-name MIDI-output-device-name [command]