Debian Codegraph @

docs/manual/Scripting_3_7__Layout.html

raw symbols SCIP
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>Scripting 3.7. Layout</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b>
12 Scripting 3.7. Layout
13 </b></font></table></table>
14 <p>This chapter handles the way you use white space, comments, and continuation lines in a Praat script.</p>
15 <h2>White space</h2>
16 <p>Praat ignores all white space (spaces and tabs) that you put at the beginning of lines. The indentation that you saw on the <a href="Scripting_3_6___For__loops.html">previous page</a> was therefore used solely for readability. You are advised to use indenting, though, with three or four spaces for each level, as in the following example, which loops over all tiers and intervals of a TextGrid:</p>
17 <code> writeInfoLine: “The texts in all tiers and intervals:”<br></code>
18 <code> numberOfTiers = Get number of tiers<br></code>
19 <code> for tierNumber from 1 to numberOfTiers<br></code>
20 <code> numberOfIntervals = Get number of intervals: tierNumber<br></code>
21 <code> for intervalNumber from 1 to numberOfIntervals<br></code>
22 <code> text$ = Get label of interval: tierNumber, intervalNumber<br></code>
23 <code> appendInfoLine: “Tier ”, tierNumber, “, interval ”, intervalNumber, “: ”, text$<br></code>
24 <code> endfor<br></code>
25 <code> endfor<br></code>
26 <p>Praat also ignores lines that are empty or consist solely of white space, so you use those to structure your script visually.</p>
27 <h2>Comments</h2>
28 <p>Comments are lines that start with &#8220;<code><font size=+1>#</font></code>&#8221; or &#8220;<code><font size=+1>;</font></code>&#8221;. Praat ignores these lines when your script is running:</p>
29 <code> # Create 1 second of a sine wave with a frequency of 100 Hertz,<br></code>
30 <code> # sampled at 44100 Hz:<br></code>
31 <code> Create Sound from formula: “sine”, 1, 0, 1, 44100, ~ sin (2*pi*100*x)<br></code>
32 <p>Because of its visibility, you are advised to use &#8220;<code><font size=+1>#</font></code>&#8221; for comments that structure your script, and &#8220;;&#8221; perhaps only for &#8220;commenting out&#8221; a statement, i.e. to temporarily put it before a line that you don&#8217;t want to execute.</p>
33 <h2>Continuation lines</h2>
34 <p>There is normally one line per statement, and one statement per line. But some statements are very long, such as this one on a previous page:</p>
35 <code> appendInfoLine: “Interval ”, intervalNumber, “ is ”, duration, “ seconds long and contains the text: ”, text$<br></code>
36 <p>By making the current window wider, you can see that I really put this whole statement on a single line. I could have distributed it over two lines in the following way, by using three dots (an <i>ellipsis</i>):</p>
37 <code> appendInfoLine: “Interval ”, intervalNumber, “ is ”, duration, “ seconds long<br></code>
38 <code> ... and contains the text: ”, text$<br></code>
39 <p>Here is another common type of example:</p>
40 <code> Create Sound from formula: “windowedSine”, 1, 0, 1, 44100,<br></code>
41 <code> ... ~ 0.5 * sin(2*pi*1000*x) * exp(-0.5*((x-0.5)/0.1)^2)<br></code>
42 <p>You will normally want to follow such an ellipsis with a space, unless you want to concatenate the parts of a long word:</p>
43 <code> Select outer viewport: 0, 10, 0, 4<br></code>
44 <code> Text top: “yes”, “It’s a long way to Llanfairpwllgwyngyll<br></code>
45 <code> ...gogerychwyrndrobwllllantysiliogogogoch,<br></code>
46 <code> ... unless you start from Tyddyn-y-felin.”<br></code>
47 <h3>Links to this page</h3>
48 <ul>
49 <li><a href="Scripting.html">Scripting</a>
50 <li><a href="Scripting_3__Simple_language_elements.html">Scripting 3. Simple language elements</a>
51 </ul>
52 <hr>
53 <address>
54 <p>© ppgb 20170904</p>
55 </address>
56 </body>
57 </html>