| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Programming with Praat</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 |
Programming with Praat |
| 13 |
</b></font></table></table> |
| 14 |
<p>You can extend the functionality of the Praat program by adding modules written in C or C++ to it. All of Praat's source code is available under the General Public Licence.</p> |
| 15 |
<h2>1. Warning</h2> |
| 16 |
<p>Before trying the task of learning how to write Praat extensions in C or C++, you should be well aware of the possibilities of <a href="Scripting.html">scripting</a>. Many built-in commands in Praat have started their lives as Praat scripts, and scripts are easier to write than extensions in C or C++. If you have a set of scripts, you can distribute them as a <a href="plug-ins.html">plug-in</a>.</p> |
| 17 |
<h2>2. Getting the existing source code</h2> |
| 18 |
<p>You obtain the Praat source code from GitHub (https://github.com/praat), in a file with a name like <code><font size=+1>praat6499_sources.zip</font></code> or <code><font size=+1>praat6499_sources.tar.gz</font></code> (depending on the Praat version), and unpack this by double-clicking. The result will be a set of directories called <code><font size=+1>kar</font></code>, <code><font size=+1>melder</font></code>, <code><font size=+1>external</font></code> (with <code><font size=+1>clapack</font></code>, <code><font size=+1>gsl</font></code>, <code><font size=+1>glpk</font></code>, <code><font size=+1>flac</font></code>, <code><font size=+1>mp3</font></code>, <code><font size=+1>portaudio</font></code>, <code><font size=+1>espeak</font></code>, <code><font size=+1>vorbis</font></code> and <code><font size=+1>opusfile</font></code> in it), <code><font size=+1>sys</font></code>, <code><font size=+1>dwsys</font></code>, <code><font size=+1>stat</font></code>, <code><font size=+1>fon</font></code>, <code><font size=+1>sensors</font></code>, <code><font size=+1>dwtools</font></code>, <code><font size=+1>LPC</font></code>, <code><font size=+1>FFNet</font></code>, <code><font size=+1>gram</font></code>, <code><font size=+1>artsynth</font></code>, <code><font size=+1>EEG</font></code>, <code><font size=+1>main</font></code>, <code><font size=+1>makefiles</font></code>, <code><font size=+1>test</font></code>, <code><font size=+1>dwtest</font></code>, and <code><font size=+1>generate</font></code>, plus a makefile and Xcode project for macOS and a README.md file.</p> |
| 19 |
<h2>3. Building Praat</h2> |
| 20 |
<p>Consult the README file on GitHub for directions to compile and link Praat for your platform.</p> |
| 21 |
<h2>4. Extending Praat</h2> |
| 22 |
<p>To start extending Praat’s functionality, you can edit <code><font size=+1>main/main_Praat.cpp</font></code>. This example shows you how to create a very simple program with all the functionality of the Praat program, and a single bit more (namely an additional command in the New menu):</p> |
| 23 |
<code> #include "praatM.h" // for macros such as DIRECT and INCLUDE_LIBRARY<br></code> |
| 24 |
<code> <br></code> |
| 25 |
<code> DIRECT (INFO_HelloFromJane) { // a macro to include commands without parameters<br></code> |
| 26 |
<code> Melder_information (U"Hello, I am Jane.");<br></code> |
| 27 |
<code> }<br></code> |
| 28 |
<code> <br></code> |
| 29 |
<code> int main (int argc, char **argv) {<br></code> |
| 30 |
<code> praat_init (<br></code> |
| 31 |
<code> U"Praat_Jane", // the name of your app<br></code> |
| 32 |
<code> U"1.2.01", // the version of your app, as a string<br></code> |
| 33 |
<code> 1201, // the version of your app, as a number<br></code> |
| 34 |
<code> 2025, // the year of your app's version<br></code> |
| 35 |
<code> 9, // the month of your app's version (here: September)<br></code> |
| 36 |
<code> 18, // the day of your app's version (between 1 and 31)<br></code> |
| 37 |
<code> U"jane.doe", // the first part of your contact email address<br></code> |
| 38 |
<code> U"univ.edu", // the second part of your contact email address<br></code> |
| 39 |
<code> argc, // the number of command line arguments (0 if started from GUI)<br></code> |
| 40 |
<code> argv // the command line arguments (empty if started from GUI)<br></code> |
| 41 |
<code> );<br></code> |
| 42 |
<code> INCLUDE_LIBRARY (praat_uvafon_init) // include all Praat functionality <br></code> |
| 43 |
<code> praat_addMenuCommand (<br></code> |
| 44 |
<code> U"Objects", // the window in which this command will appear<br></code> |
| 45 |
<code> U"New", // the menu under which this command will appear<br></code> |
| 46 |
<code> U"Hello from Jane...", // the title of the menu command<br></code> |
| 47 |
<code> nullptr, // to insert after another command (unused here)<br></code> |
| 48 |
<code> 0, // the depth at which this command will appear (0 for top level)<br></code> |
| 49 |
<code> INFO_HelloFromJane // the command defined above<br></code> |
| 50 |
<code> );<br></code> |
| 51 |
<code> praat_run ();<br></code> |
| 52 |
<code> return 0; // obligatory<br></code> |
| 53 |
<code> }<br></code> |
| 54 |
<h2>5. Learning how to program</h2> |
| 55 |
<p>To see how objects are defined, take a look at <code><font size=+1>sys/Thing.h</font></code>, <code><font size=+1>sys/Daata.h</font></code>, <code><font size=+1>sys/oo.h</font></code>, the <code><font size=+1>XXX_def.h</font></code> files in the <code><font size=+1>fon</font></code> folder, and the corresponding <code><font size=+1>XXX.cpp</font></code> files in the <code><font size=+1>fon</font></code> folder. To see how commands show up on the buttons in the fixed and dynamic menus, take a look at the large interface description file <code><font size=+1>fon/praat_Fon.cpp</font></code>.</p> |
| 56 |
<h2>6. Using the Praat shell only</h2> |
| 57 |
<p>For building the Praat shell (the Objects and Picture windows) only, you need only the code in the nine directories <code><font size=+1>kar</font></code>, <code><font size=+1>melder</font></code>, <code><font size=+1>external/{clapack,gsl,flac,mp3,portaudio,lame,opusfile,vorbis}</font></code>, <code><font size=+1>sys</font></code>, and <code><font size=+1>dwsys</font></code>. You delete the inclusion of <code><font size=+1>praat_uvafon_init</font></code> from <code><font size=+1>main</font></code>. You will be able to build a Praat shell, i.e. an Objects and a Picture window, which has no knowledge of the world, i.e., which does not know any objects that can be included in the list of objects. You could use this Praat shell for modelling your own world and defining your own classes of objects. For advanced programmers only.</p> |
| 58 |
<h3>Links to this page</h3> |
| 59 |
<ul> |
| 60 |
<li><a href="Scripting_9__Turning_a_script_into_a_stand-alone_progra.html">Scripting 9. Turning a script into a stand-alone program</a> |
| 61 |
</ul> |
| 62 |
<hr> |
| 63 |
<address> |
| 64 |
<p>© Paul Boersma 2023-04-09, 2024, 2025</p> |
| 65 |
</address> |
| 66 |
</body> |
| 67 |
</html> |