Skip to content

Commit

Permalink
Upgrade to version 0.2 with new README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rippert committed Feb 20, 2018
1 parent 1237a28 commit 6898286
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 55 deletions.
5 changes: 5 additions & 0 deletions MOSClist1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cc2param 1 28 50 127 -90 10 /ch/01/mix/fader
cc2toggle 2 17 0 127 /ch/11/insert/on
cc2param 1 28 50 127 10 -90 /ch/02/mix/fader
cc2toggle 2 18 0 127 /ch/11/preamp/hpon

5 changes: 5 additions & 0 deletions MOSClist2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cc2param 1 28 50 127 -90 10 /ch/03/mix/fader
cc2toggle 2 17 0 127 /ch/11/insert/on
cc2param 1 28 50 127 10 -90 /ch/04/mix/fader
cc2toggle 2 18 0 127 /ch/11/preamp/hpon

106 changes: 78 additions & 28 deletions MidiOSC.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
#!/bin/bash

tmpfiles=()
proctree=()
pausetree=()
prgmlist=()
activeprgm=""

list_descendants ()
{
local children=$(pgrep -P "$1")

for pid in $children
do
list_descendants "$pid"
done

echo "$children"
}


function finish {
rm -f $pipe
kill -- -$(ps -o pgid= $$ | grep -o '[0-9]*')
rm -f $pipe $cpipe "${tmpfiles[@]}" /tmp/prgm.*.$$
kill $(list_descendants $$)
}

trap finish EXIT
Expand All @@ -30,8 +47,7 @@ function cc2param {
paramspan=$(($paramupperbound-$paramlowerbound))

oldtime=0

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))"
Expand All @@ -48,22 +64,21 @@ function cc2param {
echo "hex raw F0 00 20 32 32 $b F7" > $pipe
oldtime=$newtime
fi
done &
}
done < <(receivemidi ts dev $mididevice channel $ccchannel control-change $ccnumber) &
}

function cc2toggle {
ccchannel=$1
ccnumber=$2
onvalue=$3
offvalue=$4
oscpath=$5

receivemidi dev $mididevice channel $ccchannel control-change $ccnumber |

while read ch chnum type typenum dat
do
if [ $dat -eq $onvalue ]
then
a="$xaircommand ON"
a="$oscpath ON"
b=$(
for ((i=0;i<${#a};i++));do printf "%02X " \'"${a:$i:1}";
done
Expand All @@ -78,37 +93,39 @@ function cc2toggle {
)
echo "hex raw F0 00 20 32 32 $b F7" > $pipe
fi
done &
}
done < <(receivemidi dev $mididevice channel $ccchannel control-change $ccnumber) &
}

function prgm {
fn=$1
pn=$(basename $fn)

prgmpids="/tmp/prgm.$fn.$$"
tmpfiles+=("$prgmpids")
prgmpids="/tmp/prgm.$pn.$$"

activeprgm=-1
for i in ${!proctree[@]} ; do
prgmlist=($((i+1)) ${proctree[i]} ${pausetree[i]})
if [ "${prgmlist[1]}" = "prgm" -a "${prgmlist[2]}" = "$fn" ]
if [ "${prgmlist[1]}" = "prgm" -a "${prgmlist[2]}" = "$pn" ]
then
activeprgm="${prgmlist[0]}"
break
elif [ "${prgmlist[1]}" = "prgm" ]
then
pause "${prgmlist[0]}"
prune "${prgmlist[0]}"
rm "/tmp/prgm.${prgmlist[2]}.$$"
break
fi
done
if [ $activeprgm = -1 ]; then
tmpfiles+=("$prgmpids")
while read -r pcmd
do
if [ "$pcmd" != "" ];
then
$pcmd
echo -n "$! " >> "$prgmpids"
echo -n "$(list_descendants $!) $!" >> "$prgmpids"
fi
done < "$fn"
else
resume $activeprgm
fi
}

Expand All @@ -131,8 +148,10 @@ function prune {
unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
;;
*)
kill "${prnarray[0]}"
wait "${prnarray[0]}" 2>/dev/null
tokill="$(list_descendants ${prnarray[0]}) ${prnarray[0]}"
echo $tokill
kill $tokill
wait $tokill 2>/dev/null
unset 'proctree[(($1-1))]' 'pausetree[(($1-1))]'
;;
esac
Expand Down Expand Up @@ -177,11 +196,16 @@ function resume {
}

pipe=/tmp/MidiOSCpipe.$$
cpipe=/tmp/MidiOSCcmd.$$

if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi

if [[ ! -p $cpipe ]]; then
mkfifo $cpipe
fi

mididevice=$1
mididevout=$2 # midi device for sysex OSC output

Expand All @@ -192,14 +216,32 @@ if [ $# -gt 2 ]
then
shift 2
"$@"
proctree+=( "$! $cmd" )
pausetree+=( " " )
cmdarray=( "$@" )
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
fi

HISTFILE=~/.NetOSC_hist
HISTFILE=~/.MidiOSC_hist
HISTFILESIZE=200
history -r
while IFS= read -e -r cmd

while IFS= read -r cmd
do
if [ "$cmd" = "exit" ] || [ "$cmd" = "quit" ]
then
Expand All @@ -209,16 +251,16 @@ do
[ -n "$cmd" ] && history -w
$cmd
cmdarray=( $cmd )
case ${cmdarray[0]} in
case ${cmdarray[0]} in
list|prune|pause|resume)
;;
prgm)
exists=0
for i in ${!proctree[@]} ; do
if [ "${proctree[i]}" = "$cmd" ]; then exists=1; fi
if [ "${proctree[i]}" = "${cmdarray[0]} $pn" ]; then exists=1; fi
done
if [ $exists = 0 ]; then
proctree+=( "$cmd" )
proctree+=( "${cmdarray[0]} $pn" )
pausetree+=( " " )
fi
;;
Expand All @@ -228,7 +270,15 @@ do
;;
esac

done
done <> $cpipe &

while IFS= read -e -r cmd
do
if [ "$cmd" = "exit" ] || [ "$cmd" = "quit" ]
then
break
fi
echo $cmd > $cpipe
done

exit 0
Loading

0 comments on commit 6898286

Please sign in to comment.