| 1 |
# editorScripts.praat |
| 2 |
# Paul Boersma, 14 May 2026 |
| 3 |
|
| 4 |
exitScript: "Use only “Run selection”." |
| 5 |
|
| 6 |
# From Objects to editor: without “endeditor”. |
| 7 |
# |
| 8 |
# Try to run the following twice. |
| 9 |
# |
| 10 |
# This tests whether a script without “endeditor” cleans up correctly. |
| 11 |
|
| 12 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 13 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 14 |
selectObject: sound, textGrid |
| 15 |
View & Edit |
| 16 |
editor: textGrid |
| 17 |
Select: 0.3, 0.7 |
| 18 |
Zoom: 0.3, 0.7 |
| 19 |
|
| 20 |
# From Objects to editor: with an unknown variable error. |
| 21 |
# |
| 22 |
# Try to run the following twice. |
| 23 |
# |
| 24 |
# This tests whether a script with an error message about an unknown variable cleans up correctly. |
| 25 |
|
| 26 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 27 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 28 |
selectObject: sound, textGrid |
| 29 |
View & Edit |
| 30 |
editor: textGrid |
| 31 |
asserterror Unknown variable: |
| 32 |
fsdlmgslgml |
| 33 |
Select: 0.3, 0.7 |
| 34 |
Zoom: 0.3, 0.7 |
| 35 |
|
| 36 |
# From Objects to editor: with an unknown menu command error. |
| 37 |
# |
| 38 |
# Try to run the following twice. |
| 39 |
# |
| 40 |
# This tests whether a script with an error message about an unknown menu command cleans up correctly. |
| 41 |
|
| 42 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 43 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 44 |
selectObject: sound, textGrid |
| 45 |
View & Edit |
| 46 |
editor: textGrid |
| 47 |
Select: 0.3, 0.7 |
| 48 |
asserterror Command not available in TextGridEditor. |
| 49 |
Zoompppppppppppppp: 0.3, 0.7 |
| 50 |
|
| 51 |
# From Objects to editor: with a command syntax error. |
| 52 |
# |
| 53 |
# Try to run the following twice. |
| 54 |
# |
| 55 |
# This tests whether a script with an error message about command syntax cleans up correctly. |
| 56 |
|
| 57 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 58 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 59 |
selectObject: sound, textGrid |
| 60 |
View & Edit |
| 61 |
editor: textGrid |
| 62 |
Select: 0.3, 0.7 |
| 63 |
asserterror Command requires more than the given 1 arguments: argument “To” not given. |
| 64 |
Zoom: 0.3 |
| 65 |
|
| 66 |
# From Objects to editor: with “endeditor”. |
| 67 |
# |
| 68 |
# Try to run the following twice. |
| 69 |
# |
| 70 |
# This tests whether a script without “Close” returns to the Objects window correctly. |
| 71 |
|
| 72 |
Erase all |
| 73 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 74 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 75 |
selectObject: sound, textGrid |
| 76 |
View & Edit |
| 77 |
editor: textGrid |
| 78 |
Select: 0.3, 0.7 |
| 79 |
Zoom: 0.3, 0.7 |
| 80 |
endeditor |
| 81 |
Draw: 0.0, 0.0, "yes", "yes", "yes" |
| 82 |
|
| 83 |
# From Objects to editor: with “Close”. |
| 84 |
# |
| 85 |
# Try to run the following twice. |
| 86 |
# |
| 87 |
# This tests whether a script without “endeditor” returns to the Objects window correctly. |
| 88 |
|
| 89 |
Erase all |
| 90 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 91 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 92 |
selectObject: sound, textGrid |
| 93 |
View & Edit |
| 94 |
editor: textGrid |
| 95 |
Select: 0.3, 0.7 |
| 96 |
Zoom: 0.3, 0.7 |
| 97 |
Close |
| 98 |
Draw: 0.0, 0.0, "yes", "yes", "yes" |
| 99 |
|
| 100 |
# From Objects to editor: with “pauseScript”. |
| 101 |
# |
| 102 |
# Try to run the following twice (click on Continue when prompted). |
| 103 |
|
| 104 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 105 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 106 |
selectObject: sound, textGrid |
| 107 |
View & Edit |
| 108 |
editor: textGrid |
| 109 |
Select: 0.3, 0.7 |
| 110 |
pauseScript: "Just continue." |
| 111 |
Zoom: 0.3, 0.7 |
| 112 |
endeditor |
| 113 |
removeObject: sound, textGrid |
| 114 |
|
| 115 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 116 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 117 |
selectObject: sound, textGrid |
| 118 |
View & Edit |
| 119 |
editor: textGrid |
| 120 |
Select: 0.3, 0.7 |
| 121 |
beginPause: "Just continue." |
| 122 |
clicked = endPause: "Next", 1 |
| 123 |
Zoom: 0.3, 0.7 |
| 124 |
endeditor |
| 125 |
removeObject: sound, textGrid |
| 126 |
|
| 127 |
# The same, but during the pause, try to close the window (or remove the Sound). |
| 128 |
|
| 129 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 130 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 131 |
selectObject: sound, textGrid |
| 132 |
View & Edit |
| 133 |
editor: textGrid |
| 134 |
Select: 0.3, 0.7 |
| 135 |
pauseScript: "Close the editor window, then continue." |
| 136 |
asserterror Command “Zoom:” not available for current selection. |
| 137 |
Zoom: 0.3, 0.7 |
| 138 |
|
| 139 |
# or this one: |
| 140 |
|
| 141 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 142 |
textGrid = To TextGrid: "Mary John Bell", "bell" |
| 143 |
selectObject: sound, textGrid |
| 144 |
View & Edit |
| 145 |
editor: textGrid |
| 146 |
Select: 0.3, 0.7 |
| 147 |
pause Close the editor window, then continue. |
| 148 |
asserterror Command “Zoom:” not available for current selection. |
| 149 |
Zoom: 0.3, 0.7 |
| 150 |
|
| 151 |
# Entirely by hand: |
| 152 |
|
| 153 |
# 1. Create a Sound |
| 154 |
# 2. Choose View & Edit |
| 155 |
# 3. Choose New editor script: check title |
| 156 |
# 4. Type something: check change in title |
| 157 |
# 5. Remove the Sound: sound editor closes, script editor closes |
| 158 |
|
| 159 |
# Entirely by hand: |
| 160 |
|
| 161 |
# 1. Create a Sound |
| 162 |
# 2. Choose View & Edit |
| 163 |
# 3. Choose New editor script: check title |
| 164 |
# 4. Type something: check change in title |
| 165 |
# 5. Close the sound editor: script editor closes |
| 166 |
|
| 167 |
# Entirely by hand: |
| 168 |
|
| 169 |
# 1. Create a Sound |
| 170 |
# 2. Choose View & Edit |
| 171 |
# 3. Choose Open editor script: check title |
| 172 |
# 4. Type something to make the script window dirty: fdsffg |
| 173 |
# 5. Remove the Sound: editor closes, title changes, and Run menu becomes insensitive |
| 174 |
# 6. Create a Sound |
| 175 |
# 7. Choose View & Edit |
| 176 |
# 8. Choose Open editor script: message "Text file XXX is already open." |
| 177 |
# 9. Remove the Sound: editor closes, title changes, and Run menu becomes insensitive |
| 178 |
|
| 179 |
# Within editor (open this script in an editor window). |
| 180 |
# |
| 181 |
# Try to run the following twice. |
| 182 |
# |
| 183 |
# This should continue to work. |
| 184 |
|
| 185 |
Zoom: 0.3, 0.7 |
| 186 |
|
| 187 |
# Within editor (open this script in an editor window). |
| 188 |
# |
| 189 |
# Try to run the following twice. |
| 190 |
# |
| 191 |
# The following should give an unknown command error. |
| 192 |
|
| 193 |
asserterror Command not available in SoundEditor. |
| 194 |
sound = Create Sound from formula: "sineWithNoise", 1, 0, 1, 44100, "1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)" |
| 195 |
|
| 196 |
# Within editor (open this script in an editor window). |
| 197 |
# |
| 198 |
# Try to run the following twice. |
| 199 |
# |
| 200 |
# The following should give an unknown variable error. |
| 201 |
|
| 202 |
asserterror Unknown variable: |
| 203 |
fdsafshgjh |
| 204 |
|
| 205 |
# Within editor (open this script in an editor window). |
| 206 |
# |
| 207 |
# Try to run the following twice. |
| 208 |
# |
| 209 |
# The following should give a command syntax error. |
| 210 |
|
| 211 |
asserterror Command requires more than the given 1 arguments: argument “To” not given. |
| 212 |
Zoom: 0.3 |
| 213 |
|
| 214 |
# From editor to Objects (open this script in an editor window). |
| 215 |
# |
| 216 |
# Try to run the following twice. |
| 217 |
# |
| 218 |
# This should continue to work. |
| 219 |
|
| 220 |
Select: 0.3, 0.7 |
| 221 |
Extract selected sound (preserve times) |
| 222 |
endeditor |
| 223 |
To Intensity: 100, 0, "yes" |
| 224 |
Info |
| 225 |
editor |
| 226 |
Select: 0.5, 0.6 |
| 227 |
|
| 228 |
# runScript from an editor should pass on the editor |
| 229 |
# |
| 230 |
# This has been automated in: test/script/runScript_GUI_.praat |
| 231 |
|
| 232 |
# Within editor (open this script in an editor window). |
| 233 |
# |
| 234 |
# Type some text here to make this script window dirty: hfgghjfdgffevdfdsfgfsaf |
| 235 |
# During the pause, try to close the window (or remove the Sound). |
| 236 |
|
| 237 |
Select: 0.3, 0.7 |
| 238 |
;asserterror Cannot continue after pause, because the SoundEditor has been closed. |
| 239 |
pauseScript: "Close the editor window, then continue." |
| 240 |
Zoom: 0.5, 0.6 |
| 241 |
# TODO: this crashes |
| 242 |
|
| 243 |
Select: 0.3, 0.7 |
| 244 |
;asserterror Cannot continue after pause, because the SoundEditor has been closed. |
| 245 |
pause Close the editor window, then continue. |
| 246 |
Zoom: 0.5, 0.6 |