forked from zhanrnl/PyMusAnim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch.sh
executable file
·41 lines (40 loc) · 1004 Bytes
/
batch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#Converts a whole directory of MIDI files in parallel
OUT_DIR=output/
shopt -s nocaseglob
trap 'kill 0' EXIT
if [ ! $1 ]; then
echo "Usage: batch.sh midisDirectory mode [threadsLimit]"
exit 1
fi
if [ ! $2 ]; then
echo "Please inform a mode: either --classic or --dynamic"
exit 1
fi
mkdir $OUT_DIR
files=`ls -1 $1/*.mid*&>/dev/null`
if [ ! $? == 0 ]; then
echo "No files found, aborting."
exit
fi
for m in $1/*.mid*; do #call pymusanim if there is an idle thread
name=`basename $m .${m#*.}`
nice -n19 ./pymusanim.sh $m $OUT_DIR$name $2 &> $OUT_DIR${name}.log&
echo "Starting $name"
threadsLimit=$3
if [ ! $threadsLimit ]; then
threadsLimit=`cat /proc/cpuinfo | grep processor | wc -l`
fi
while [ `jobs|grep Running|wc -l` == $threadsLimit ]; do
sleep 1
done
done
echo "Waiting for last processes to finish..."
while [ `jobs|grep Running|wc -l` != 0 ]; do #wait until end
sleep 1
done
echo "Cleaning..."
wait
echo "Done!"
first=1
./checklogs.sh $OUT_DIR