Commit 3aadb226163387087eae5344f062d8499e705b71

Authored by Jean-François Rey
1 parent 6aa891c900
Exists in master

update

Showing 1 changed file with 3 additions and 0 deletions Inline Diff

main_tools/RecomposePass.sh
1 #!/bin/bash 1 #!/bin/bash
2 2
3 ##################################################### 3 #####################################################
4 # File : RecomposePass.sh # 4 # File : RecomposePass.sh #
5 # Brief : Get missing res pass from previous pass # 5 # Brief : Get missing res pass from previous pass #
6 # Author : Jean-François Rey # 6 # Author : Jean-François Rey #
7 # Version : 1.0 # 7 # Version : 1.0 #
8 # Date : 25/07/13 # 8 # Date : 25/07/13 #
9 ##################################################### 9 #####################################################
10 10
11 echo "### RecomposePass.sh ###" 11 echo "### RecomposePass.sh ###"
12 12
13 13
14 # Check OTMEDIA_HOME env var 14 # Check OTMEDIA_HOME env var
15 if [ -z ${OTMEDIA_HOME} ] 15 if [ -z ${OTMEDIA_HOME} ]
16 then 16 then
17 OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) 17 OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0)))
18 export OTMEDIA_HOME=$OTMEDIA_HOME 18 export OTMEDIA_HOME=$OTMEDIA_HOME
19 fi 19 fi
20 20
21 # where is RecomposePass.sh 21 # where is RecomposePass.sh
22 MAIN_SCRIPT_PATH=$(dirname $(readlink -e $0)) 22 MAIN_SCRIPT_PATH=$(dirname $(readlink -e $0))
23 23
24 # Scripts Path 24 # Scripts Path
25 SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts 25 SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts
26 26
27 # Include scripts 27 # Include scripts
28 . $SCRIPT_PATH"/Tools.sh" 28 . $SCRIPT_PATH"/Tools.sh"
29 . $SCRIPT_PATH"/CheckSecondPass.sh" 29 . $SCRIPT_PATH"/CheckSecondPass.sh"
30 30
31 # where is RescomposePass.cfg 31 # where is RescomposePass.cfg
32 RECOMPOSEPASS_CONFIG_FILE=$OTMEDIA_HOME"/cfg/RecomposePass.cfg" 32 RECOMPOSEPASS_CONFIG_FILE=$OTMEDIA_HOME"/cfg/RecomposePass.cfg"
33 if [ -e $RECOMPOSEPASS_CONFIG_FILE ] 33 if [ -e $RECOMPOSEPASS_CONFIG_FILE ]
34 then 34 then
35 . $RECOMPOSEPASS_CONFIG_FILE 35 . $RECOMPOSEPASS_CONFIG_FILE
36 else 36 else
37 echo "ERROR : Can't find configuration file $RECOMPOSEPASS_CONFIG_FILE" >&2 37 echo "ERROR : Can't find configuration file $RECOMPOSEPASS_CONFIG_FILE" >&2
38 exit 1 38 exit 1
39 fi 39 fi
40 40
41 #---------------# 41 #---------------#
42 # Parse Options # 42 # Parse Options #
43 #---------------# 43 #---------------#
44 while getopts ":hDv:" opt 44 while getopts ":hDv:" opt
45 do 45 do
46 case $opt in 46 case $opt in
47 h) 47 h)
48 echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n" 48 echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n"
49 echo -e "\t Options:" 49 echo -e "\t Options:"
50 echo -e "\t\t-h :\tprint this message" 50 echo -e "\t\t-h :\tprint this message"
51 echo -e "\t\t-D :\tDEBUG mode on" 51 echo -e "\t\t-D :\tDEBUG mode on"
52 echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" 52 echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode"
53 exit 1 53 exit 1
54 ;; 54 ;;
55 D) 55 D)
56 DEBUG=1 56 DEBUG=1
57 ;; 57 ;;
58 v) 58 v)
59 VERBOSE=$OPTARG 59 VERBOSE=$OPTARG
60 ;; 60 ;;
61 :) 61 :)
62 echo "Option -$OPTARG requires an argument." >&2 62 echo "Option -$OPTARG requires an argument." >&2
63 exit 1 63 exit 1
64 ;; 64 ;;
65 \?) 65 \?)
66 echo "BAD USAGE : unknow opton -$OPTARG" 66 echo "BAD USAGE : unknow opton -$OPTARG"
67 #exit 1 67 #exit 1
68 ;; 68 ;;
69 esac 69 esac
70 done 70 done
71 71
72 # mode debug enable 72 # mode debug enable
73 if [ $DEBUG -eq 1 ] 73 if [ $DEBUG -eq 1 ]
74 then 74 then
75 set -x 75 set -x
76 echo -e "## Mode DEBUG ON ##" 76 echo -e "## Mode DEBUG ON ##"
77 fi 77 fi
78 78
79 # mode verbose enable 79 # mode verbose enable
80 if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi 80 if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi
81 81
82 # Check USAGE by arguments number 82 # Check USAGE by arguments number
83 if [ $(($#-($OPTIND-1))) -ne 1 ] 83 if [ $(($#-($OPTIND-1))) -ne 1 ]
84 then 84 then
85 echo "BAD USAGE : RecomposePass.sh [OPTIONS] <PASS_DIR>" 85 echo "BAD USAGE : RecomposePass.sh [OPTIONS] <PASS_DIR>"
86 echo "$0 -h for more info" 86 echo "$0 -h for more info"
87 exit 1 87 exit 1
88 fi 88 fi
89 89
90 shift $((OPTIND-1)) 90 shift $((OPTIND-1))
91 # check Pass directory - First argument 91 # check Pass directory - First argument
92 if [ -e $1 ] && [ -d $1 ] 92 if [ -e $1 ] && [ -d $1 ]
93 then 93 then
94 PASS_DIR=$(readlink -e $1) 94 PASS_DIR=$(readlink -e $1)
95 else 95 else
96 print_error "can't find $1 directory" 96 print_error "can't find $1 directory"
97 exit 1 97 exit 1
98 fi 98 fi
99 99
100 #-------------# 100 #-------------#
101 # GLOBAL VARS # 101 # GLOBAL VARS #
102 #-------------# 102 #-------------#
103 BASENAME=$(basename $PASS_DIR) 103 BASENAME=$(basename $PASS_DIR)
104 OUTPUT_DIR_BASENAME=$PASS_DIR 104 OUTPUT_DIR_BASENAME=$PASS_DIR
105 RES_DIR="$PASS_DIR/res_all" 105 RES_DIR="$PASS_DIR/res_all"
106 LOGFILE=$PASS_DIR"/info_recpass.log" 106 LOGFILE=$PASS_DIR"/info_recpass.log"
107 ERRORFILE=$PASS_DIR"/error_recpass.log" 107 ERRORFILE=$PASS_DIR"/error_recpass.log"
108 108
109 THIRDPASS_CONFIG_FILE="$PASS_DIR/ThirdPass.cfg" 109 THIRDPASS_CONFIG_FILE="$PASS_DIR/ThirdPass.cfg"
110 if [ -e $THIRDPASS_CONFIG_FILE ] 110 if [ -e $THIRDPASS_CONFIG_FILE ]
111 then 111 then
112 RES_P3=$(cat $THIRDPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=") 112 RES_P3=$(cat $THIRDPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=")
113 else 113 else
114 print_warn "[${BASENAME}] can't find $THIRDPASS_CONFIG_FILE file" 2 114 print_warn "[${BASENAME}] can't find $THIRDPASS_CONFIG_FILE file" 2
115 #exit 1 115 #exit 1
116 fi 116 fi
117 SECONDPASS_CONFIG_FILE="$PASS_DIR/SecondPass.cfg" 117 SECONDPASS_CONFIG_FILE="$PASS_DIR/SecondPass.cfg"
118 if [ -e $SECONDPASS_CONFIG_FILE ] 118 if [ -e $SECONDPASS_CONFIG_FILE ]
119 then 119 then
120 RES_P2=$(cat $SECONDPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=") 120 RES_P2=$(cat $SECONDPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=")
121 else 121 else
122 print_warn "[${BASENAME}] can't find $SECONDPASS_CONFIG_FILE file" 2 122 print_warn "[${BASENAME}] can't find $SECONDPASS_CONFIG_FILE file" 2
123 #exit 1 123 #exit 1
124 fi 124 fi
125 FIRSTPASS_CONFIG_FILE="$PASS_DIR/FirstPass.cfg" 125 FIRSTPASS_CONFIG_FILE="$PASS_DIR/FirstPass.cfg"
126 if [ -e $FIRSTPASS_CONFIG_FILE ] 126 if [ -e $FIRSTPASS_CONFIG_FILE ]
127 then 127 then
128 RES_P1=$(cat $FIRSTPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=") 128 RES_P1=$(cat $FIRSTPASS_CONFIG_FILE | grep "^RES_DIR=" | cut -f2 -d"=")
129 else 129 else
130 print_warn "[${BASENAME}] can't find $FIRSTPASS_CONFIG_FILE file" 2 130 print_warn "[${BASENAME}] can't find $FIRSTPASS_CONFIG_FILE file" 2
131 #exit 1 131 #exit 1
132 fi 132 fi
133 133
134 if ( [ -z "$RES_P1" ] && [ -z "$RES_P2" ] ) || [ -z $RES_P3 ] 134 if ( [ -z "$RES_P1" ] && [ -z "$RES_P2" ] ) || [ -z $RES_P3 ]
135 then 135 then
136 print_error "[${BASENAME}] No configuration pass files in $PASS_DIR -> exit" 136 print_error "[${BASENAME}] No configuration pass files in $PASS_DIR -> exit"
137 if [ $CHECK -eq 1 ]; then print_log_file $ERROFILE "No configuration pass files in $PASS_DIR -> exit";fi 137 if [ $CHECK -eq 1 ]; then print_log_file $ERROFILE "No configuration pass files in $PASS_DIR -> exit";fi
138 exit 1 138 exit 1
139 fi 139 fi
140 140
141 print_info "[${BASENAME}] => RecomposePass start | $(date +'%d/%m/%y %H:%M:%S')" 1 141 print_info "[${BASENAME}] => RecomposePass start | $(date +'%d/%m/%y %H:%M:%S')" 1
142 142
143 #------------------# 143 #------------------#
144 # Create WORKSPACE # 144 # Create WORKSPACE #
145 #------------------# 145 #------------------#
146 146
147 # Lock directory 147 # Lock directory
148 if [ -e $OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock ] && [ $RERUN -eq 0 ] 148 if [ -e $OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock ] && [ $RERUN -eq 0 ]
149 then 149 then
150 print_warn "[${BASENAME}] RECOMPOSEPASS is locked -> exit" 2 150 print_warn "[${BASENAME}] RECOMPOSEPASS is locked -> exit" 2
151 exit 1 151 exit 1
152 fi 152 fi
153 rm "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.unlock" > /dev/null 2>&1 153 rm "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.unlock" > /dev/null 2>&1
154 touch "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock" > /dev/null 2>&1 154 touch "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock" > /dev/null 2>&1
155 155
156 if [ $RERUN -eq 0 ]; then rm -r $RES_DIR > /dev/null 2>&1; fi 156 if [ $RERUN -eq 0 ]; then rm -r $RES_DIR > /dev/null 2>&1; fi
157 mkdir -p $RES_DIR 2> /dev/null 157 mkdir -p $RES_DIR 2> /dev/null
158 print_info "Make directory $RES_DIR" 3 158 print_info "Make directory $RES_DIR" 3
159 159
160 #--------------------# 160 #--------------------#
161 # Save configuration # 161 # Save configuration #
162 #--------------------# 162 #--------------------#
163 cp $RECOMPOSEPASS_CONFIG_FILE $OUTPUT_DIR_BASENAME/RecomposePass.cfg 163 cp $RECOMPOSEPASS_CONFIG_FILE $OUTPUT_DIR_BASENAME/RecomposePass.cfg
164 echo "RES_ALL=$RES_DIR" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg 164 echo "RES_ALL=$RES_DIR" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg
165 echo "RES_P1=$RES_P1" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg 165 echo "RES_P1=$RES_P1" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg
166 echo "RES_P2=$RES_P2" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg 166 echo "RES_P2=$RES_P2" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg
167 echo "RES_P3=$RES_P3" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg 167 echo "RES_P3=$RES_P3" >> $OUTPUT_DIR_BASENAME/RecomposePass.cfg
168 print_info "[${BASENAME}] Save config in $OUTPUT_DIR_BASENAME/RecomposePass.cfg" 1 168 print_info "[${BASENAME}] Save config in $OUTPUT_DIR_BASENAME/RecomposePass.cfg" 1
169 169
170 #--------------------------------------------------# 170 #--------------------------------------------------#
171 # Recompose Pass using previous pass # 171 # Recompose Pass using previous pass #
172 #--------------------------------------------------# 172 #--------------------------------------------------#
173 print_info "[${BASENAME}] Launch Recompose Pass" 1 173 print_info "[${BASENAME}] Launch Recompose Pass" 1
174 174
175 ## Check seg in p3 175 ## Check seg in p3
176 print_info "cp res_p3 into res_all" 3
176 cp $RES_P3/*.res $RES_DIR 177 cp $RES_P3/*.res $RES_DIR
177 ls $RES_P3/*.res | sed -e "s|$RES_P3\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p3.tmp 178 ls $RES_P3/*.res | sed -e "s|$RES_P3\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p3.tmp
178 ls $RES_P2/*.res | sed -e "s|$RES_P2\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p2.tmp 179 ls $RES_P2/*.res | sed -e "s|$RES_P2\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p2.tmp
179 ls $RES_P1/*.res | sed -e "s|$RES_P1\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p1.tmp 180 ls $RES_P1/*.res | sed -e "s|$RES_P1\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_p1.tmp
180 diff_3_2=$(diff ${OUTPUT_DIR_BASENAME}/res_p3.tmp ${OUTPUT_DIR_BASENAME}/res_p2.tmp | grep -e "^> " | sed -e "s/> //") 181 diff_3_2=$(diff ${OUTPUT_DIR_BASENAME}/res_p3.tmp ${OUTPUT_DIR_BASENAME}/res_p2.tmp | grep -e "^> " | sed -e "s/> //")
182 print_info "cp missing res_p2 into res_all" 3
181 for res in $diff_3_2 183 for res in $diff_3_2
182 do 184 do
183 cp $RES_P2/$res.res $RES_DIR 185 cp $RES_P2/$res.res $RES_DIR
184 done 186 done
185 ls $RES_DIR/*.res | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_all.tmp 187 ls $RES_DIR/*.res | sed -e "s|$RES_DIR\/||g" | sed -e 's/\.res//' | sort > ${OUTPUT_DIR_BASENAME}/res_all.tmp
186 diff_3_1=$(diff ${OUTPUT_DIR_BASENAME}/res_all.tmp ${OUTPUT_DIR_BASENAME}/res_p1.tmp | grep -e "^> " | sed -e "s/> //") 188 diff_3_1=$(diff ${OUTPUT_DIR_BASENAME}/res_all.tmp ${OUTPUT_DIR_BASENAME}/res_p1.tmp | grep -e "^> " | sed -e "s/> //")
189 print_info "cp missing res_p1 into res_all" 3
187 for res in $diff_3_1 190 for res in $diff_3_1
188 do 191 do
189 cp $RES_P1/$res.res $RES_DIR 192 cp $RES_P1/$res.res $RES_DIR
190 done 193 done
191 194
192 rm ${OUTPUT_DIR_BASENAME}/res_p3.tmp ${OUTPUT_DIR_BASENAME}/res_p2.tmp ${OUTPUT_DIR_BASENAME}/res_p1.tmp ${OUTPUT_DIR_BASENAME}/res_all.tmp 2> /dev/null 195 rm ${OUTPUT_DIR_BASENAME}/res_p3.tmp ${OUTPUT_DIR_BASENAME}/res_p2.tmp ${OUTPUT_DIR_BASENAME}/res_p1.tmp ${OUTPUT_DIR_BASENAME}/res_all.tmp 2> /dev/null
193 196
194 #---------------# 197 #---------------#
195 # Convert res # 198 # Convert res #
196 #---------------# 199 #---------------#
197 200
198 print_info "[${BASENAME}] Convert .res into .ctm" 1 201 print_info "[${BASENAME}] Convert .res into .ctm" 1
199 # .res => .ctm 202 # .res => .ctm
200 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format CTM --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.ctm 203 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format CTM --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.ctm
201 print_info "[${BASENAME}] Convert .res into .trs" 1 204 print_info "[${BASENAME}] Convert .res into .trs" 1
202 # .res => .trs 205 # .res => .trs
203 echo -e "name $AUTHOR\nfileName ${BASENAME}\nfileExt wav\nsegFile ${OUTPUT_DIR_BASENAME}/${BASENAME}.seg" > ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg 206 echo -e "name $AUTHOR\nfileName ${BASENAME}\nfileExt wav\nsegFile ${OUTPUT_DIR_BASENAME}/${BASENAME}.seg" > ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg
204 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TRS --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.trs --trs_config ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg 207 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TRS --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.trs --trs_config ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg
205 rm ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg 208 rm ${OUTPUT_DIR_BASENAME}/${BASENAME}.trs_cfg
206 print_info "[${BASENAME}] Convert .res into .txt" 1 209 print_info "[${BASENAME}] Convert .res into .txt" 1
207 # .res => .txt 210 # .res => .txt
208 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TXT --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.txt 211 $SCRIPT_PATH/res2out.pl --dir $RES_DIR --format TXT --ignore $RULES/asupp --out ${OUTPUT_DIR_BASENAME}/${BASENAME}.allpass.txt
209 212
210 213
211 print_info "[${BASENAME}] <= RecomposePass End | $(date +'%d/%m/%y %H:%M:%S')" 1 214 print_info "[${BASENAME}] <= RecomposePass End | $(date +'%d/%m/%y %H:%M:%S')" 1
212 215
213 # unlock directory 216 # unlock directory
214 mv "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock" "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.unlock" 217 mv "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.lock" "$OUTPUT_DIR_BASENAME/RECOMPOSEPASS.unlock"
215 218
216 219