-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp_plot2D.praat
303 lines (278 loc) · 9.8 KB
/
cp_plot2D.praat
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
demoWindowTitle: "cp_plot2D v0.05 Ferragne 2016"
demo Erase all
demo Select inner viewport: 0, 100, 0, 100
demo Axes: 0, 100, 0, 100
demo Font size: 20
demo Paint rectangle: "grey", 25, 75, 50, 70
demo Text: 50, "centre", 60, "half", "Click to choose directory"
while demoWaitForInput()
if demoClickedIn (25, 75, 50, 70)
goto CHOOSEDIR
endif
endwhile
label CHOOSEDIR
dirName$ = chooseDirectory$: "Choose directory"
#dirName$ = "C:\Users\eferragne\Documents\travailEnCours\scriptFormants\demoFormants\outputAuto"
outDir$ = dirName$ + "/figure"
createDirectory: outDir$
Create Strings as file list: "myList", dirName$ + "/*.txt"
#check if "discardedSegments.txt" is in list
nbStrings = Get number of strings
iCheck = 1
while iCheck <= nbStrings
if Strings_myList$[iCheck] = "discardedSegments.txt" or index(Strings_myList$[iCheck], "upDatedFileList") <> 0
Remove string: iCheck
nbStrings = nbStrings - 1
iCheck = iCheck - 1
endif
iCheck = iCheck + 1
endwhile
nbFiles = Get number of strings
Create Table with column names: "formantTable2D", nbFiles, "File Vowel F1 F2"
for fileID to nbFiles
currentFile$ = Strings_myList$[fileID]
Read Table from tab-separated file: dirName$ + "/" + currentFile$
indLastUS = rindex(currentFile$, "_")
indDotText = rindex(currentFile$,".txt")
rawVowel$ = mid$(currentFile$, indLastUS+1, indDotText - indLastUS - 1)
vowelTrigraph$ = replace$(rawVowel$,"-","\",0)
vowelTrigraph$ = replace$(vowelTrigraph$,"#",":",0)
formLength = Get number of rows
whichRow = round(formLength/2)
myF1 = Get value: whichRow, "F1(Hz)"
myF2 = Get value: whichRow, "F2(Hz)"
selectObject: "Table formantTable2D"
Set string value: fileID, "File", currentFile$
Set string value: fileID, "Vowel", vowelTrigraph$
Set numeric value: fileID, "F1", myF1
Set numeric value: fileID, "F2", myF2
endfor
minF1 = Get minimum: "F1"
maxF1 = Get maximum: "F1"
minF2 = Get minimum: "F2"
maxF2 = Get maximum: "F2"
xLower = floor(minF2)-30
xUpper = ceiling(maxF2)+30
yLower = floor(minF1)-30
yUpper = ceiling(maxF1)+30
Down to TableOfReal: "Vowel"
To TableOfReal (means by row labels): "no"
Rename: "formantMean"
select all
minusObject: "Table formantTable2D", "TableOfReal formantMean"
Remove
fontSize = 12
drawAll = 2
pictNb = 1
label DASHBOARD
if drawAll mod 2 = 0
@drawBasic
else
@drawMean
endif
demo Select inner viewport: 0, 100, 0, 100
demo Axes: 0, 100, 0, 100
demo Font size: 16
demo Text: 80, "centre", 90, "half", "Font size"
demo Text: 80, "centre", 85, "half", string$(fontSize)
demo Paint rectangle: "grey", 72, 77, 82.5, 87.5
demo Text: 74.5, "centre", 85, "half", "-"
demo Paint rectangle: "grey", 83, 88, 82.5, 87.5
demo Text: 85.5, "centre", 85, "half", "+"
demo Text: 80, "centre", 70, "half", "F2 lower limit"
demo Text: 80, "centre", 65, "half", string$(xLower)
demo Paint rectangle: "grey", 72, 77, 62.5, 67.5
demo Text: 74.5, "centre", 65, "half", "-"
demo Paint rectangle: "grey", 83, 88, 62.5, 67.5
demo Text: 85.5, "centre", 65, "half", "+"
demo Paint rectangle: "grey", 66, 71, 62.5, 67.5
demo Text: 68.5, "centre", 65, "half", "- -"
demo Paint rectangle: "grey", 89, 94, 62.5, 67.5
demo Text: 91.5, "centre", 65, "half", "+ +"
demo Text: 80, "centre", 55, "half", "F2 upper limit"
demo Text: 80, "centre", 50, "half", string$(xUpper)
demo Paint rectangle: "grey", 72, 77, 47.5, 52.5
demo Text: 74.5, "centre", 50, "half", "-"
demo Paint rectangle: "grey", 83, 88, 47.5, 52.5
demo Text: 85.5, "centre", 50, "half", "+"
demo Paint rectangle: "grey", 66, 71, 47.5, 52.5
demo Text: 68.5, "centre", 50, "half", "- -"
demo Paint rectangle: "grey", 89, 94, 47.5, 52.5
demo Text: 91.5, "centre", 50, "half", "+ +"
demo Text: 80, "centre", 40, "half", "F1 lower limit"
demo Text: 80, "centre", 35, "half", string$(yLower)
demo Paint rectangle: "grey", 72, 77, 32.5, 37.5
demo Text: 74.5, "centre", 35, "half", "-"
demo Paint rectangle: "grey", 83, 88, 32.5, 37.5
demo Text: 85.5, "centre", 35, "half", "+"
demo Paint rectangle: "grey", 66, 71, 32.5, 37.5
demo Text: 68.5, "centre", 35, "half", "- -"
demo Paint rectangle: "grey", 89, 94, 32.5, 37.5
demo Text: 91.5, "centre", 35, "half", "+ +"
demo Text: 80, "centre", 25, "half", "F1 upper limit"
demo Text: 80, "centre", 20, "half", string$(yUpper)
demo Paint rectangle: "grey", 72, 77, 17.5, 22.5
demo Text: 74.5, "centre", 20, "half", "-"
demo Paint rectangle: "grey", 83, 88, 17.5, 22.5
demo Text: 85.5, "centre", 20, "half", "+"
demo Paint rectangle: "grey", 66, 71, 17.5, 22.5
demo Text: 68.5, "centre", 20, "half", "- -"
demo Paint rectangle: "grey", 89, 94, 17.5, 22.5
demo Text: 91.5, "centre", 20, "half", "+ +"
demo Paint rectangle: "grey",10, 25, 10, 20
demo Text: 17.5, "centre", 15, "half", "All/Mean"
demo Paint rectangle: "grey",35, 50, 10, 20
demo Text: 42.5, "centre", 15, "half", "Export to PNG"
demo Paint rectangle: "grey",72.5, 87.5, 0, 10
demo Text: 80, "centre", 5, "half", "RESET"
demoWaitForInput()
if demoClickedIn(35, 50, 10, 20)
@toPNG
goto DASHBOARD
elsif demoClickedIn(10, 25, 10, 20)
drawAll = drawAll + 1
goto DASHBOARD
elsif demoClickedIn(72, 77, 82.5, 87.5)
fontSize = fontSize - 1
goto DASHBOARD
elsif demoClickedIn(83, 88, 82.5, 87.5)
fontSize = fontSize + 1
goto DASHBOARD
elsif demoClickedIn (72, 77, 62.5, 67.5)
xLower = xLower - 1
goto DASHBOARD
elsif demoClickedIn(83, 88, 62.5, 67.5)
xLower = xLower + 1
goto DASHBOARD
elsif demoClickedIn(66, 71, 62.5, 67.5)
xLower = xLower - 10
goto DASHBOARD
elsif demoClickedIn(89, 94, 62.5, 67.5)
xLower = xLower + 10
goto DASHBOARD
elsif demoClickedIn(72, 77, 47.5, 52.5)
xUpper = xUpper - 1
goto DASHBOARD
elsif demoClickedIn(83, 88, 47.5, 52.5)
xUpper = xUpper + 1
goto DASHBOARD
elsif demoClickedIn(66, 71, 47.5, 52.5)
xUpper = xUpper - 10
goto DASHBOARD
elsif demoClickedIn(89, 94, 47.5, 52.5)
xUpper = xUpper + 10
goto DASHBOARD
elsif demoClickedIn(72, 77, 32.5, 37.5)
yLower = yLower - 1
goto DASHBOARD
elsif demoClickedIn(83, 88, 32.5, 37.5)
yLower = yLower + 1
goto DASHBOARD
elsif demoClickedIn(66, 71, 32.5, 37.5)
yLower = yLower - 10
goto DASHBOARD
elsif demoClickedIn(89, 94, 32.5, 37.5)
yLower = yLower + 10
goto DASHBOARD
elsif demoClickedIn(72, 77, 17.5, 22.5)
yUpper = yUpper - 1
goto DASHBOARD
elsif demoClickedIn(83, 88, 17.5, 22.5)
yUpper = yUpper + 1
goto DASHBOARD
elsif demoClickedIn(66, 71, 17.5, 22.5)
yUpper = yUpper - 10
goto DASHBOARD
elsif demoClickedIn(89, 94, 17.5, 22.5)
yUpper = yUpper + 10
goto DASHBOARD
elsif demoClickedIn(72.5, 87.5, 0, 10)
selectObject: "Table formantTable2D"
minF1 = Get minimum: "F1"
maxF1 = Get maximum: "F1"
minF2 = Get minimum: "F2"
maxF2 = Get maximum: "F2"
xLower = floor(minF2)-30
xUpper = ceiling(maxF2)+30
yLower = floor(minF1)-30
yUpper = ceiling(maxF1)+30
goto DASHBOARD
elsif demoKeyPressed()
if demoKey$() = "→"
xLower = xLower - 10
goto DASHBOARD
elsif demoKey$() = "←"
xUpper = xUpper + 10
goto DASHBOARD
elsif demoKey$() = "↑"
yLower = yLower - 10
goto DASHBOARD
elsif demoKey$() = "↓"
yUpper = yUpper + 10
goto DASHBOARD
endif
else
demo Erase all
goto DASHBOARD
endif
procedure drawBasic
demo Erase all
demo Colour: 0
demo Font size: fontSize
demo Select inner viewport: 10, 50, 50, 90
selectObject: "Table formantTable2D"
demo Scatter plot: "F2", xUpper, xLower, "F1", yUpper, yLower, "Vowel", fontSize, "no"
demo Draw inner box
demo Text left: "yes", "F1 (Hz)"
demo Text bottom: "yes", "F2 (Hz)"
demo One mark bottom: xUpper, "yes", "yes", "no", string$(xUpper)
demo One mark bottom: xLower, "yes", "yes", "no", string$(xLower)
demo One mark left: yUpper, "yes", "yes", "no", string$(yUpper)
demo One mark left: yLower, "yes", "yes", "no", string$(yLower)
endproc
procedure drawMean
demo Erase all
demo Colour: 0
demo Font size: fontSize
demo Select inner viewport: 10, 50, 50, 90
selectObject: "TableOfReal formantMean"
demo Draw scatter plot: 3, 2, 0, 0, xUpper, xLower, yUpper, yLower, fontSize, "yes", "", "no"
demo Draw inner box
demo Text left: "yes", "F1 (Hz)"
demo Text bottom: "yes", "F2 (Hz)"
demo One mark bottom: xUpper, "yes", "yes", "no", string$(xUpper)
demo One mark bottom: xLower, "yes", "yes", "no", string$(xLower)
demo One mark left: yUpper, "yes", "yes", "no", string$(yUpper)
demo One mark left: yLower, "yes", "yes", "no", string$(yLower)
endproc
procedure toPNG
Select inner viewport: 0, 6, 0, 4
if drawAll mod 2 = 0
Scatter plot: "F2", xUpper, xLower, "F1", yUpper, yLower, "Vowel", fontSize, "no"
Draw inner box
Text left: "yes", "F1 (Hz)"
Text bottom: "yes", "F2 (Hz)"
One mark bottom: xUpper, "yes", "yes", "no", string$(xUpper)
One mark bottom: xLower, "yes", "yes", "no", string$(xLower)
One mark left: yUpper, "yes", "yes", "no", string$(yUpper)
One mark left: yLower, "yes", "yes", "no", string$(yLower)
Save as 600-dpi PNG file: outDir$ + "/myVowelPlot" + string$(pictNb) + ".png"
else
Draw scatter plot: 3, 2, 0, 0, xUpper, xLower, yUpper, yLower, fontSize, "yes", "", "no"
Draw inner box
Text left: "yes", "F1 (Hz)"
Text bottom: "yes", "F2 (Hz)"
One mark bottom: xUpper, "yes", "yes", "no", string$(xUpper)
One mark bottom: xLower, "yes", "yes", "no", string$(xLower)
One mark left: yUpper, "yes", "yes", "no", string$(yUpper)
One mark left: yLower, "yes", "yes", "no", string$(yLower)
Save as 600-dpi PNG file: outDir$ + "/myVowelPlot" + string$(pictNb) + ".png"
endif
pictNb = pictNb + 1
Erase all
demoShow()
selectObject: "Table formantTable2D"
Formula: "Vowel", "backslashTrigraphsToUnicode$(self$)"
Save as tab-separated file: outDir$ + "/myTable.txt"
demo Erase all
endproc