manual_programming.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /* manual_programming.cpp
  2. *
  3. * Copyright (C) 1992-2010,2011,2013,2015-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "ManPagesM.h"
  19. void manual_programming_init (ManPages me);
  20. void manual_programming_init (ManPages me) {
  21. MAN_BEGIN (U"Interoperability", U"ppgb", 20151107)
  22. INTRO (U"You can use Praat in workflows that involve other programs.")
  23. ENTRY (U"1. General ways to access Praat from other programs")
  24. NORMAL (U"• To send messages from another program to a running Praat, use @@sendpraat@. "
  25. "This method is used by the programs CHAT (Childes) and Phon to view a sound in a Sound window.")
  26. NORMAL (U"• To execute a Praat script as a subprocess of another program, see @@Scripting 6.9. Calling from the command line@.")
  27. ENTRY (U"2. General ways to access other programs from Praat")
  28. NORMAL (U"• To execute another program as a subprocess of Praat, see @@Scripting 6.5. Calling system commands@.")
  29. ENTRY (U"3. Files")
  30. NORMAL (U"• Many programs read and/or write Praat TextGrid files. If you want create a TextGrid reading or writing procedure, "
  31. "consult @@TextGrid file formats@.")
  32. MAN_END
  33. MAN_BEGIN (U"TextGrid file formats", U"ppgb", 20180821)
  34. INTRO (U"This page describes the syntax and semantics of TextGrid files that Praat can read and/or write.")
  35. ENTRY (U"1. The full text format of a minimal TextGrid")
  36. NORMAL (U"If you record a Sound with a druation of 2.3 seconds, and then do ##To TextGrid...#, "
  37. "you are asked to provide tier names and to say which of these tiers are point tiers. "
  38. "If you click OK without changing the settings from their standard values, "
  39. "you obtain a TextGrid with two interval tiers, called %Mary and %John, and one point tier called %bell. "
  40. "When you save this TextGrid to disk by choosing @@Save as text file...@ from the #New menu, "
  41. "the resulting text file, when opened in a text editor, will look as follows:")
  42. CODE (U"File type = \"ooTextFile\"")
  43. CODE (U"Object class = \"TextGrid\"")
  44. CODE (U"")
  45. CODE (U"xmin = 0")
  46. CODE (U"xmax = 2.3")
  47. CODE (U"tiers? <exists>")
  48. CODE (U"size = 3")
  49. CODE (U"item []:")
  50. CODE1 (U"item [1]:")
  51. CODE2 (U"class = \"IntervalTier\"")
  52. CODE2 (U"name = \"Mary\"")
  53. CODE2 (U"xmin = 0")
  54. CODE2 (U"xmax = 2.3")
  55. CODE2 (U"intervals: size = 1")
  56. CODE2 (U"intervals [1]:")
  57. CODE3 (U"xmin = 0")
  58. CODE3 (U"xmax = 2.3")
  59. CODE3 (U"text = \"\"")
  60. CODE1 (U"item [2]:")
  61. CODE2 (U"class = \"IntervalTier\"")
  62. CODE2 (U"name = \"John\"")
  63. CODE2 (U"xmin = 0")
  64. CODE2 (U"xmax = 2.3")
  65. CODE2 (U"intervals: size = 1")
  66. CODE2 (U"intervals [1]:")
  67. CODE3 (U"xmin = 0")
  68. CODE3 (U"xmax = 2.3")
  69. CODE3 (U"text = \"\"")
  70. CODE1 (U"item [3]:")
  71. CODE2 (U"class = \"TextTier\"")
  72. CODE2 (U"name = \"bell\"")
  73. CODE2 (U"xmin = 0")
  74. CODE2 (U"xmax = 2.3")
  75. CODE2 (U"points: size = 0")
  76. NORMAL (U"This text file contains the following pieces of data, which Praat will use when reading this file from disk "
  77. "and turning it into a TextGrid object again:")
  78. NORMAL (U"• The text \"ooTextFile\", which appears in the first line of any text file that you write with @@Save as text file...@, "
  79. "i.e. not only in text files created from a TextGrid object, but also in text files created from e.g. a Pitch "
  80. "or ExperimentMFC object or from any other of the hundreds of types of objects that Praat can have in its Objects list.")
  81. NORMAL (U"• The text \"TextGrid\", which designates the type of the object that has been saved to this file.")
  82. NORMAL (U"• The real number 0, which is the starting time (in seconds) of this TextGrid.")
  83. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the TextGrid.")
  84. NORMAL (U"• The flag <exists>, which tells us that this TextGrid contains tiers (this value would be <absent> "
  85. "if the TextGrid contained no tiers, in which case the file would end here; however, you cannot really create TextGrid objects "
  86. "without tiers in Praat, so this issue can be ignored).")
  87. NORMAL (U"• The integer number 3, which is the number of tiers that you created.")
  88. NORMAL (U"• The text \"IntervalTier\", which designates the type of the first tier (an interval tier, therefore).")
  89. NORMAL (U"• The text \"Mary\", which is the name you gave to the first tier.")
  90. NORMAL (U"• The real number 0, which is the starting time (in seconds) of the first tier.")
  91. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the first tier. "
  92. "When you create a TextGrid with an interval tier, the time domain of the interval tier is automatically set equal "
  93. "to the time domain of the whole TextGrid.")
  94. NORMAL (U"• The integer number 1, which is the number of intervals in the first tier. "
  95. "Although you did not add any intervals and did not add any text to the first tier, "
  96. "all interval tiers always contain at least one interval, which is created when you create the TextGrid.")
  97. NORMAL (U"• The real number 0, which is the starting time (in seconds) of the first (only) interval of the first tier.")
  98. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the first interval of the first tier. "
  99. "The interval that is automatically created for you when you create a TextGrid with an interval tier, "
  100. "spans the whole tier.")
  101. NORMAL (U"• The text \"\", which is the contents of the interval on the first tier. This text is empty.")
  102. NORMAL (U"• The text \"IntervalTier\", which gives the type of the second tier (again an interval tier).")
  103. NORMAL (U"• The text \"John\", which is the name you gave to the second tier.")
  104. NORMAL (U"• The real number 0, which is the starting time (in seconds) of the second tier.")
  105. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the second tier.")
  106. NORMAL (U"• The integer number 1, which is the number of intervals in the second tier.")
  107. NORMAL (U"• The real number 0, which is the starting time (in seconds) of the first (only) interval of the second tier.")
  108. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the first interval of the second tier.")
  109. NORMAL (U"• The text \"\", which is the contents of the interval on the second tier. This text is empty.")
  110. NORMAL (U"• The text \"TextTier\", which designates the type of the third tier (a point tier this time).")
  111. NORMAL (U"• The text \"bell\", which is the name you gave to the third tier.")
  112. NORMAL (U"• The real number 0, which is the starting time (in seconds) of the third tier.")
  113. NORMAL (U"• The real number 2.3, which is the end time (in seconds) of the third tier.")
  114. NORMAL (U"• The integer number 0, which is the number of points in the third tier. "
  115. "A newly created point tier contains no points yet.")
  116. NORMAL (U"You will have noticed that the file contains a lot of stuff that was not mentioned in this list. "
  117. "All of that stuff are %comments that are present only to help the human reader understand the contents "
  118. "of the file: labels for all tiers (such as $$item [2]$), labels for the starting times of the TextGrid or "
  119. "a tier or an interval ($xmin), labels for end times ($xmax); labels for the number of tiers or "
  120. "intervals or points ($size), and little numbers enclosed in square brackets to tell the reader where they are ($$[2]$).")
  121. NORMAL (U"When reading a text file containing a TextGrid (or any other object), Praat totally ignores these comments, "
  122. "so if you e.g. replace $$[2]$ with $$[4]$ somewhere, Praat will not notice. Praat will consider as data only the following "
  123. "types of information in the file:")
  124. LIST_ITEM (U"• free-standing numbers, such as $$0$ and $$2.3$ above, but not $$[1]$ or $$[3]$;")
  125. LIST_ITEM (U"• free-standing text enclosed within double quotes, such as $$\"TextGrid\"$ and $$\"\"$ above;")
  126. LIST_ITEM (U"• free-standing flags, such as $$<exists>$ above (this is the only flag that appears in TextGrid files; "
  127. "see @ExperimentMFC for a much broader use of flags).")
  128. NORMAL (U"In this list, \"free-standing\" means that the number, text or flag is preceded by the beginning of the file, "
  129. "the beginning of a line, or a space, and that it is followed by the end of the file, the end of a line, or a space.")
  130. ENTRY (U"2. The shortest text format of a minimal TextGrid")
  131. NORMAL (U"From the description above of what in the file is considered data (namely free-standing numbers, texts and flags) "
  132. "and what is not (namely everything else), you can conclude that Praat will be able to read a much shorter version of "
  133. "the file above. And indeed, when you choose @@Save as short text file...@ from the #New menu, your file will consist of "
  134. "the following text, "
  135. "with every piece of data alone on a separate line:")
  136. CODE (U"File type = \"ooTextFile\"")
  137. CODE (U"Object class = \"TextGrid\"")
  138. CODE (U"")
  139. CODE (U"0")
  140. CODE (U"2.3")
  141. CODE (U"<exists>")
  142. CODE (U"3")
  143. CODE (U"\"IntervalTier\"")
  144. CODE (U"\"Mary\"")
  145. CODE (U"0")
  146. CODE (U"2.3")
  147. CODE (U"1")
  148. CODE (U"0")
  149. CODE (U"2.3")
  150. CODE (U"\"\"")
  151. CODE (U"\"IntervalTier\"")
  152. CODE (U"\"John\"")
  153. CODE (U"0")
  154. CODE (U"2.3")
  155. CODE (U"1")
  156. CODE (U"0")
  157. CODE (U"2.3")
  158. CODE (U"\"\"")
  159. CODE (U"\"TextTier\"")
  160. CODE (U"\"bell\"")
  161. CODE (U"0")
  162. CODE (U"2.3")
  163. CODE (U"0")
  164. NORMAL (U"That's much less human-readable than before, but equally computer-readable, at least by Praat. "
  165. "When you write your own TextGrid file recognizer, you should be able to interpret both versions shown above, "
  166. "and also any version that is intermediate between the two, as long as it has the data written as freestanding numbers, "
  167. "texts, and flags. For instance, a human-readable TextGrid file that can be interpreted by Praat could look "
  168. "as follows:")
  169. CODE (U"\"ooTextFile\"")
  170. CODE (U"\"TextGrid\"")
  171. CODE (U"0 2.3 ! time domain of TextGrid")
  172. CODE (U"<exists>")
  173. CODE (U"3 tiers")
  174. CODE (U"\"IntervalTier\" \"Mary\" ! type and name of tier 1")
  175. CODE (U"0 2.3 ! time domain of tier 1")
  176. CODE (U"1 interval coming")
  177. CODE (U"0 2.3 \"\" ! interval 1 on tier 1")
  178. CODE (U"\"IntervalTier\" \"John\" ! type and name of tier 2")
  179. CODE (U"0 2.3 ! time domain of tier 2")
  180. CODE (U"1 interval coming")
  181. CODE (U"0 2.3 \"\" ! interval 1 on tier 2")
  182. CODE (U"\"TextTier\" \"bell\" ! type and name of tier 3")
  183. CODE (U"0 2.3 ! time domain of tier 3")
  184. CODE (U"0 points coming")
  185. NORMAL (U"Here we see that multiple pieces of data can be together on a line, as long as each of them stands free; "
  186. "the only layout requirement is that the text \"ooTextFile\" has to be alone on the first line.")
  187. NORMAL (U"Another thing we see is that there is an additional type of comment: everything that follows an "
  188. "exclamation mark on the same line is considered a comment. Thus, although some lines seem to end in a free-standing "
  189. "number (1, 2, or 3), those numbers do not count as data, because they are part of a comment that follows "
  190. "an exclamation mark.")
  191. ENTRY (U"3. Reading a TextGrid file")
  192. NORMAL (U"Reading the contents of a TextGrid file into your own data structure is fairly easy. "
  193. "For instance, to figure out how many intervals there are in a tier, you do not have to read multiple lines and then backtrack "
  194. "to see where the list of intervals ends. Instead, the number of intervals is given before the intervals are enumerated.")
  195. ENTRY (U"4. Writing a TextGrid file")
  196. NORMAL (U"Writing the contents of a TextGrid file involves deciding on a level of human readability.")
  197. ENTRY (U"5. A TextGrid file with more than the minimal content")
  198. NORMAL (U"The above example was about a rather uninteresting TextGrid object, with no text in it. Suppose instead that "
  199. "the sound was a recording of speaker saying a sentence, and your TextGrid annotates the sentence orthographically "
  200. "as well as phonetically, and also annotates two chimes of the bell:")
  201. SCRIPT (6.0, 3.0, U""
  202. "textgrid = Create TextGrid: 0, 2.3, \"sentence phonemes bell\", \"bell\"\n"
  203. "Set interval text: 1, 1, \"říkej \"\"ahoj\"\" dvakrát\"\n"
  204. "Insert boundary: 2, 0.7\n"
  205. "Insert boundary: 2, 1.6\n"
  206. "Set interval text: 2, 1, \"r̝iːkɛj\"\n"
  207. "Set interval text: 2, 2, \"ʔaɦɔj\"\n"
  208. "Set interval text: 2, 3, \"dʋakraːt\"\n"
  209. "Insert point: 3, 0.9, \"ding\"\n"
  210. "Insert point: 3, 1.3, \"dong\"\n"
  211. "Draw: 0.0, 0.0, 1, 1, 1\n")
  212. NORMAL (U"When you save this as a full text file, it will look as follows:")
  213. CODE (U"File type = \"ooTextFile\"")
  214. CODE (U"Object class = \"TextGrid\"")
  215. CODE (U"")
  216. CODE (U"xmin = 0")
  217. CODE (U"xmax = 2.3")
  218. CODE (U"tiers? <exists>")
  219. CODE (U"size = 3")
  220. CODE (U"item []:")
  221. CODE1 (U"item [1]:")
  222. CODE2 (U"class = \"IntervalTier\"")
  223. CODE2 (U"name = \"sentence\"")
  224. CODE2 (U"xmin = 0")
  225. CODE2 (U"xmax = 2.3")
  226. CODE2 (U"intervals: size = 1")
  227. CODE2 (U"intervals [1]:")
  228. CODE3 (U"xmin = 0")
  229. CODE3 (U"xmax = 2.3")
  230. CODE3 (U"text = \"říkej \"\"ahoj\"\" dvakrát\"")
  231. CODE1 (U"item [2]:")
  232. CODE2 (U"class = \"IntervalTier\"")
  233. CODE2 (U"name = \"phonemes\"")
  234. CODE2 (U"xmin = 0")
  235. CODE2 (U"xmax = 2.3")
  236. CODE2 (U"intervals: size = 3")
  237. CODE2 (U"intervals [1]:")
  238. CODE3 (U"xmin = 0")
  239. CODE3 (U"xmax = 0.7")
  240. CODE3 (U"text = \"r̝iːkɛj\"")
  241. CODE2 (U"intervals [2]:")
  242. CODE3 (U"xmin = 0.7")
  243. CODE3 (U"xmax = 1.6")
  244. CODE3 (U"text = \"ʔaɦɔj\"")
  245. CODE2 (U"intervals [3]:")
  246. CODE3 (U"xmin = 1.6")
  247. CODE3 (U"xmax = 2.3")
  248. CODE3 (U"text = \"dʋakraːt\"")
  249. CODE1 (U"item [3]:")
  250. CODE2 (U"class = \"TextTier\"")
  251. CODE2 (U"name = \"bell\"")
  252. CODE2 (U"xmin = 0")
  253. CODE2 (U"xmax = 2.3")
  254. CODE2 (U"points: size = 2")
  255. CODE2 (U"points [1]:")
  256. CODE3 (U"number = 0.9")
  257. CODE3 (U"mark = \"ding\"")
  258. CODE2 (U"points [2]:")
  259. CODE3 (U"number = 1.3")
  260. CODE3 (U"mark = \"dong\"")
  261. NORMAL (U"We now see how points on a point tier are written: with their time ($number) and their text ($mark). "
  262. "As usual, most of the contents of the file is comments; for instance, older TextGrid files may call "
  263. "the time of the point $time instead of $number, but as these are just comments, Praat will ignore these words "
  264. "when reading the file, and so should anybody who programs a TextGrid file parser.")
  265. NORMAL (U"A thing to note is the doubling of double quotes. The sentence in tier 1 contains double quotes around %ahoj, "
  266. "as you can see in the picture above, and you typed only these two double quotes in the TextGrid window to start with. "
  267. "However, the file format uses double quotes to mark texts, so if a text itself contains a double quote, "
  268. "something special has to be done about it lest Praat think that you're ending the text. The solution that Praat chooses "
  269. "is that a double quote that appears in a text is written as a %doubled double quote in the text file, as above on tier 1.")
  270. ENTRY (U"6. Restrictions in a TextGrid object")
  271. NORMAL (U"TextGrid objects maintain several invariants, some stronger and some weaker.")
  272. NORMAL (U"The two strongest invariants within an interval tier are %%positive duration% and %adjacency. "
  273. "That is, the end time of each interval has to be greater than the starting time of that same interval, "
  274. "and the starting time of each interval (except the first) has to be equal to the end time of the previous interval. "
  275. "As a result, the union of the time domains of the set of intervals in a tier is a contiguous stretch of time, "
  276. "and no intervals overlap. If a TextGrid file violates these invariants, Praat may refuse to read the file and give "
  277. "an error message instead (or Praat may try to repair the TextGrid, but that is not guaranteed).")
  278. NORMAL (U"A weaker invariant is that the starting time of the first interval on a tier equals the starting time of that tier, "
  279. "and the end time of the last interval equals the end time of the tier. When you create a TextGrid with Praat, "
  280. "this invariant is automatically maintained, and most types of modifications also maintain it, except sometimes the commands "
  281. "that combine multiple TextGrid objects with different durations into a new TextGrid. "
  282. "Praat will happily read TextGrid files that do not honour this weak invariant, and will also display such a TextGrid "
  283. "reasonably well in a TextGrid window. It is nevertheless advisable for other programs that create TextGrids "
  284. "to honour this weak invariant.")
  285. NORMAL (U"For a point tier, a strong invariant is that the time of each point (except the first) has to be greater than the time "
  286. "of the previous point. Praat maintains this invariant for instance by refusing to insert a point at the time of an existing "
  287. "point. TextGrid files that violate this invariant may or may not be read by Praat, and may cause strange behaviour in Praat "
  288. "if they are read.")
  289. NORMAL (U"A further weak invariant is that the starting and end times of each tier equal the starting and end times of the whole "
  290. "TextGrid. This can be violated by combining multiple TextGrids into one, but other programs are advised to create TextGrids "
  291. "that honour this invariant, because TextGrids that violate it may look strange to the user.")
  292. ENTRY (U"7. Text encoding")
  293. NORMAL (U"Existing TextGrid text files come in various encodings. When creating a parser for TextGrid text files, "
  294. "you should be prepared for reading it in UTF-8 encoding (without Byte Order Mark), or in UTF-16 encoding "
  295. "(either Big-Endian or Little-Endian, with Byte Order Mark). Pre-Unicode TextGrid text files may have a Latin-1 encoding "
  296. "if they were created on Windows or Linux, or a MacRoman encoding if they were created on a Mac, "
  297. "so it would be good to prepare for such old files as well, although it may be difficult to figure out which is which "
  298. "(line separators, as described below, may help).")
  299. NORMAL (U"When writing a TextGrid text file, you can use UTF-8 encoding (without Byte Order Mark), or UTF-16 encoding "
  300. "(either Big-Endian or Little-Endian, with Byte Order Mark). "
  301. "Please never write a limited encoding such as Latin-1 or MacRoman, which do not support international characters "
  302. "or phonetic characters as in $$\"ʔaɦɔj\"$.")
  303. NORMAL (U"The lines in the file are typically separated by a newline symbol (Linux or modern Mac), "
  304. "or by a Return symbol (old Mac), or by a Return symbol followed by a newline symbol (Windows). "
  305. "When reading a TextGrid text file, you should be prepared for each of these line separators. "
  306. "When writing a TextGrid text file, you can use any of these line separators, because most text editors "
  307. "on all platforms can meanwhile open and view all these versions correctly.")
  308. ENTRY (U"8. Interpreting trigraphs")
  309. NORMAL (U"The example above contains several phonetic symbols, and it is not always easy to type those into a text field. "
  310. "For this reason, Praat provides %trigraphs for most phonetic characters, as well as for many non-ASCII characters "
  311. "used in the languages of the world. For instance, the vowel \"ɔ\" (a \"turned c\") can be typed as \"\\bsct\" into "
  312. "the TextGrid window as well as anywhere else in Praat where you want to draw graphical text "
  313. "(see @@Special symbols@ for all trigraphs). Thus, the file above could have looked as follows:")
  314. CODE (U"File type = \"ooTextFile\"")
  315. CODE (U"Object class = \"TextGrid\"")
  316. CODE (U"")
  317. CODE (U"xmin = 0")
  318. CODE (U"xmax = 2.3")
  319. CODE (U"tiers? <exists>")
  320. CODE (U"size = 3")
  321. CODE (U"item []:")
  322. CODE1 (U"item [1]:")
  323. CODE2 (U"class = \"IntervalTier\"")
  324. CODE2 (U"name = \"sentence\"")
  325. CODE2 (U"xmin = 0")
  326. CODE2 (U"xmax = 2.3")
  327. CODE2 (U"intervals: size = 1")
  328. CODE2 (U"intervals [1]:")
  329. CODE3 (U"xmin = 0")
  330. CODE3 (U"xmax = 2.3")
  331. CODE3 (U"text = \"\\bsr<\\bsi'kej \"\"ahoj\"\" dvakr\\bsa't\"")
  332. CODE1 (U"item [2]:")
  333. CODE2 (U"class = \"IntervalTier\"")
  334. CODE2 (U"name = \"phonemes\"")
  335. CODE2 (U"xmin = 0")
  336. CODE2 (U"xmax = 2.3")
  337. CODE2 (U"intervals: size = 3")
  338. CODE2 (U"intervals [1]:")
  339. CODE3 (U"xmin = 0")
  340. CODE3 (U"xmax = 0.7")
  341. CODE3 (U"text = \"r\\bsT\\^ i\\bs:fk\\bsefj\"")
  342. CODE2 (U"intervals [2]:")
  343. CODE3 (U"xmin = 0.7")
  344. CODE3 (U"xmax = 1.6")
  345. CODE3 (U"text = \"\\bs?ga\\bsh\\^ \\bsctj\"")
  346. CODE2 (U"intervals [3]:")
  347. CODE3 (U"xmin = 1.6")
  348. CODE3 (U"xmax = 2.3")
  349. CODE3 (U"text = \"d\\bsvsakra\\bs:ft\"")
  350. CODE1 (U"item [3]:")
  351. CODE2 (U"class = \"TextTier\"")
  352. CODE2 (U"name = \"bell\"")
  353. CODE2 (U"xmin = 0")
  354. CODE2 (U"xmax = 2.3")
  355. CODE2 (U"points: size = 2")
  356. CODE2 (U"points [1]:")
  357. CODE3 (U"number = 0.9")
  358. CODE3 (U"mark = \"ding\"")
  359. CODE2 (U"points [2]:")
  360. CODE3 (U"number = 1.3")
  361. CODE3 (U"mark = \"dong\"")
  362. NORMAL (U"On the screen, this TextGrid looks the same as before:")
  363. SCRIPT (6.0, 3.0, U""
  364. "textgrid = Create TextGrid: 0, 2.3, \"sentence phonemes bell\", \"bell\"\n"
  365. "Set interval text: 1, 1, \"\\r<\\i'kej \"\"ahoj\"\" dvakr\\a't\"\n"
  366. "Insert boundary: 2, 0.7\n"
  367. "Insert boundary: 2, 1.6\n"
  368. "Set interval text: 2, 1, \"r\\T^i\\:fk\\efj\"\n"
  369. "Set interval text: 2, 2, \"\\?ga\\h^\\ctj\"\n"
  370. "Set interval text: 2, 3, \"d\\vsakra\\:ft\"\n"
  371. "Insert point: 3, 0.9, \"ding\"\n"
  372. "Insert point: 3, 1.3, \"dong\"\n"
  373. "Draw: 0.0, 0.0, 1, 1, 1\n")
  374. NORMAL (U"There are several hundreds of such trigraphs, and a few more might be added in the future. "
  375. "When you create a TextGrid file parser and want to interpret the trigraphs in the correct way, "
  376. "it is advisable to have Praat do the conversion for you: read the TextGrid file into Praat, "
  377. "call the menu command ##Convert to Unicode#, and save the TextGrid as a new text file.")
  378. ENTRY (U"9. The binary TextGrid file format")
  379. NORMAL (U"Besides the TextGrid text file format described above, TextGrid objects can also be saved as binary files "
  380. "with @@Save as binary file...@. If you need a description of this format, we can add it here on request. "
  381. "When you want to create only a TextGrid %text file parser, and still want to support binary TextGrid files, "
  382. "you can have Praat do the conversion for you: read the binary TextGrid file into Praat with @@Read from file...@ "
  383. "and save the resulting TextGrid object as a text file with @@Save as text file...@.")
  384. MAN_END
  385. MAN_BEGIN (U"Programming with Praat", U"ppgb", 20151028)
  386. INTRO (U"You can extend the functionality of the Praat program "
  387. "by adding modules written in C or C++ to it. All of Praat's source code "
  388. "is available under the General Public Licence.")
  389. ENTRY (U"1. Warning")
  390. NORMAL (U"Before trying the task of learning how to write Praat extensions in C or C++, "
  391. "you should be well aware of the possibilities of @scripting. "
  392. "Many built-in commands in Praat have started their "
  393. "lives as Praat scripts, and scripts are easier to write than extensions in C or C++. "
  394. "If you have a set of scripts, you can distribute them as a @@plug-ins|plug-in@.")
  395. ENTRY (U"2. Getting the existing source code")
  396. NORMAL (U"You obtain the Praat source code from GitHub (https://github.com/praat), in a file with a name like "
  397. "##praat5423_sources.zip# or ##praat5423_sources.tar.gz# (depending on the Praat version), and unpack this by double-clicking. "
  398. "The result will be a set of directories "
  399. "called #kar, #num, #external (with #GSL, #glpk, #FLAC, #mp3, #portaudio and #espeak in it), "
  400. "#sys, #dwsys, #stat, #fon, #dwtools, #LPC, #FFNet, #gram, #artsynth, #EEG, #contrib, #main, #makefiles, #test, and #dwtest, "
  401. "plus a makefile and an Xcode project for MacOS X.")
  402. ENTRY (U"3. Building Praat")
  403. NORMAL (U"Consult the README file on GitHub for directions to compile and link Praat for your platform.")
  404. ENTRY (U"4. Extending Praat")
  405. NORMAL (U"To start extending Praat’s functionality, you can edit ##main/main_Praat.cpp#. "
  406. "This example shows you how to create a very simple program with all the functionality "
  407. "of the Praat program, and a single bit more (namely an additional command in the New menu):")
  408. CODE (U"\\# include \"praat.h\"")
  409. CODE (U"")
  410. CODE (U"DIRECT (HelloFromJane)")
  411. CODE1 (U"Melder_information (U\"Hello, I am Jane.\");")
  412. CODE (U"END")
  413. CODE (U"")
  414. CODE (U"int main (int argc, char **argv) {")
  415. CODE1 (U"praat_init (U\"Praat_Jane\", argc, argv);")
  416. CODE1 (U"INCLUDE_LIBRARY (praat_uvafon_init)")
  417. CODE1 (U"praat_addMenuCommand (U\"Objects\", U\"New\", U\"Hello from Jane...\", nullptr, 0, DO_HelloFromJane);")
  418. CODE1 (U"praat_run ();")
  419. CODE1 (U"return 0;")
  420. CODE (U"}")
  421. ENTRY (U"5. Learning how to program")
  422. NORMAL (U"To see how objects are defined, take a look at ##sys/Thing.h#, ##sys/Daata.h#, "
  423. "##sys/oo.h#, the ##XXX_def.h# files in the #fon directory, and the corresponding "
  424. "##XXX.cpp# files in the #fon directory. To see how commands show up on the buttons "
  425. "in the fixed and dynamic menus, take a look at the large interface description file "
  426. "##fon/praat_Fon.cpp#.")
  427. ENTRY (U"6. Using the Praat shell only")
  428. NORMAL (U"For building the Praat shell (the Objects and Picture windows) only, you need only the code in the eight directories "
  429. "#kar, #GSL, #num, ##external/{FLAC,MP3,portaudio}#, #sys, and #dwsys. You delete the inclusion of praat_uvafon_init from #main. "
  430. "You will be able to build a Praat shell, i.e. an Objects and a Picture window, "
  431. "which has no knowledge of the world, i.e., which does not know any objects "
  432. "that can be included in the list of objects. You could use this Praat shell "
  433. "for modelling your own world and defining your own classes of objects. For advanced programmers only.")
  434. MAN_END
  435. }
  436. /* End of file manual_programming.cpp */