Debian Codegraph @

sys/praat.h

raw symbols SCIP
1 #ifndef _praat_h_
2 #define _praat_h_
3 /* praat.h
4 *
5 * Copyright (C) 1992-2025 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "ScriptEditor.h"
22 #include "Manual.h"
23 #include "Preferences.h"
24
25 /*
26 The explanations in this header file assume
27 that you put your extra commands in praat_Sybil.cpp
28 and the main() function in main_Sybil.cpp,
29 but these files may have different names if you are not Sybil.
30 Linking with the rest of Praat will create an executable
31 that has all the functionality of the basic Praat,
32 plus everything that you made available in praat_Sybil.cpp.
33 */
34
35 /* Program example:
36 // File main_Sybil.cpp: //
37 int main (int argc, char **argv)
38 {
39 praat_init (U"Praat_Sybil", U"6.4.20", 6420, 2024, 9, 18, U"sybil", U"sybil.org", argc, argv); // obligatory
40 INCLUDE_LIBRARY (praat_uvafon_init) // optional: inherit phonetic stuff
41 INCLUDE_LIBRARY (praat_Sybil_init) // optional: add Sybil's things
42 INCLUDE_MANPAGES (manual_Sybil)
43 praat_run ();
44 return 0; // obligatory
45 }
46 // File praat_Sybil.cpp: //
47 void praat_Sybil (void)
48 {
49 ...
50 ...
51 }
52 The dots consist of, in any order:
53 Thing_recognizeClassesByName (...);
54 Data_recognizeFileType (...);
55 praat_addMenuCommand (...);
56 praat_addAction1 (...);
57 All of these statements are optional and may occur more than once.
58 To make any class string-readable, use Thing_recognizeClassesByName ().
59 String-readable classes are known by Thing_newFromClassName () and can therefore
60 be read by Data_readFromTextFile () and Data_readFromBinaryFile ().
61 */
62 void praat_init (conststring32 title,
63 conststring32 versionText, integer versionNumber,
64 integer year, integer month, integer day,
65 conststring32 firstPartOfEmailAddress, conststring32 secondPartOfEmailAddress, // skip '@' to not include the full address in our binary
66 int argc, char **argv
67 );
68 void praat_run ();
69 void praat_setStandAloneScriptText (conststring32 text); // call before praat_init if you want to create a stand-alone application without Objects and Picture window
70 extern "C" void praatlib_init (); // for use in an application that uses Praatlib
71
72 #define praat_addAction1(c1,n1,t,a,f,c) praat_addAction1_ (c1, n1, t, a, f, c, U"" #c)
73 #define praat_addAction2(c1,n1,c2,n2,t,a,f,c) praat_addAction2_ (c1, n1, c2, n2, t, a, f, c, U"" #c)
74 #define praat_addAction3(c1,n1,c2,n2,c3,n3,t,a,f,c) praat_addAction3_ (c1, n1, c2, n2, c3, n3, t, a, f, c, U"" #c)
75 #define praat_addAction4(c1,n1,c2,n2,c3,n3,c4,n4,t,a,f,c) praat_addAction4_ (c1, n1, c2, n2, c3, n3, c4, n4, t, a, f, c, U"" #c)
76
77 void praat_addAction1_ (ClassInfo class1, integer n1,
78 conststring32 title, conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback);
79 void praat_addAction2_ (ClassInfo class1, integer n1, ClassInfo class2, integer n2,
80 conststring32 title, conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback);
81 void praat_addAction3_ (ClassInfo class1, integer n1, ClassInfo class2, integer n2, ClassInfo class3, integer n3,
82 conststring32 title, conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback);
83 void praat_addAction4_ (ClassInfo class1, integer n1, ClassInfo class2, integer n2, ClassInfo class3, integer n3, ClassInfo class4, integer n4,
84 conststring32 title, conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback);
85 /*
86 'title' is the name that will appear in the dynamic menu,
87 and also the command that is used in command files;
88 this title is deep-copied.
89 'callback' refers to a function prototyped like this:
90 static void DO_Class_action (UiForm sendingForm, int narg, Stackel args, conststring32 sendingString,
91 Interpreter interpreter, conststring32 invokingButtonTitle, bool modified, void *closure);
92 this function should throw an exception if the command failed;
93 this function will be called by 'praat' when the user clicks a menu command,
94 in which case 'sendingForm', 'args' and 'sendingString' and 'closure' will be null;
95 it is also called by scripts,
96 in which case 'args[1..n]' or 'sendingString' is the argument list (after the dots).
97 When called by Ui (after UiForm_create), 'sendingForm' is the UiForm, and 'closure'
98 is the closure you passed to UiForm_create (which may be an editor).
99
100 The availability of the dynamic commands depends on
101 the current selection: e.g., if the user has selected three objects
102 of type Matrix and nothing else, the commands registered with
103 praat_addAction1 (classMatrix, n, "xxx", "xxxx", x, DO_xxx) are visible,
104 and those with n=0 or n=3 are executable (the buttons are sensitive)
105 and, if chosen, performed on each of these three objects;
106 if the user has selected one object of type Artword and one of type
107 Speaker, the commands from praat_addAction2 (classArtword, 1, classSpeaker, 1, ...) are executable.
108 You may want to restrict the availability to one object for commands that write objects to file,
109 commands that present information in a dialog, or the View & Edit command.
110 */
111
112 void praat_removeAction (ClassInfo class1, ClassInfo class2, ClassInfo class3, conststring32 title);
113 /* 'class2' and 'class3' may be null. */
114 /* 'title' may be null; reference-copied. */
115
116 #define praat_addMenuCommand(w,m,t,a,f,c) praat_addMenuCommand_ (w, m, t, a, f, c, U"" #c)
117 GuiMenuItem praat_addMenuCommand_ (conststring32 window, conststring32 menu, conststring32 title /* cattable */,
118 conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback);
119 /* All strings are reference-copied; 'title', 'after', and 'callback' may be null. */
120
121 #define praat_MAXNUM_EDITORS 5
122 #include "Ui.h"
123 typedef struct structPraat_Object {
124 ClassInfo klas; // the class
125 Daata object; // the instance
126 autostring32 name; // the name of the object as it appears in the List
127 structMelderFile file; // is this Object associated with a file?
128 integer id; // the unique number of the object
129 bool isSelected; // is the name of the object inverted in the list?
130 Editor editors [praat_MAXNUM_EDITORS]; // are there editors open with this Object in it?
131 bool isBeingCreated;
132 } *praat_Object;
133
134 #define praat_MAXNUM_OBJECTS 10000 /* Maximum number of objects in the list. */
135 typedef struct structPraatApplication { // read-only (for interface files)
136 MelderString batchName; // the name of the command file when called from batch
137 bool batch; // was the program called from the command line?
138 GuiWindow topShell; // the application shell: parent of standard dialogs
139 ManPages manPages;
140 } *PraatApplication;
141 typedef struct structPraatObjects { // read-only (for interface files)
142 integer n; // the current number of objects in the list
143 structPraat_Object list [1 + praat_MAXNUM_OBJECTS]; // the list of objects: list [1..n]
144 integer totalSelection; // the total number of selected objects, <= n
145 static constexpr integer MAXNUM_DATA_CLASSES = 1000;
146 integer numberOfSelected [1 + MAXNUM_DATA_CLASSES]; // for each (readable) class
147 integer totalBeingCreated;
148 integer sequentialUniqueIdOfLatestObjectInList;
149 void reset () {
150 for (integer iobject = our n; iobject >= 1; iobject --) {
151 our list [iobject]. name. reset();
152 forget (our list [iobject]. object);
153 }
154 #if 0
155 memset (this, 0, sizeof (structPraatObjects));
156 #else
157 our n = 0;
158 our totalSelection = 0;
159 for (integer i = 1; i <= MAXNUM_DATA_CLASSES; i ++)
160 our numberOfSelected [i] = 0;
161 #endif
162 }
163 } *PraatObjects;
164 typedef struct structPraatPicture { // read-only (for interface files)
165 Graphics graphics; // the Graphics associated with the Picture window
166 kGraphics_font font;
167 int lineType;
168 double fontSize;
169 MelderColour colour;
170 double lineWidth, arrowSize, speckleSize, x1NDC, x2NDC, y1NDC, y2NDC;
171 } *PraatPicture;
172 /*
173 The following six cannot be "inline",
174 because that would cost 42 MB (per architecture)
175 on the Mac or on Windows (though nothing on Linux),
176 i.e. a full copy of all three structures.
177 (ppgb 2021-04-15)
178 */
179 extern structPraatApplication theForegroundPraatApplication;
180 extern PraatApplication theCurrentPraatApplication;
181 extern structPraatObjects theForegroundPraatObjects;
182 extern PraatObjects theCurrentPraatObjects;
183 extern structPraatPicture theForegroundPraatPicture;
184 extern PraatPicture theCurrentPraatPicture;
185 /* The global objects containing the state of the application; only reachable from interface files. */
186 bool praat_commandsWithExternalSideEffectsAreAllowed ();
187
188 char32 *praat_name (integer iobject);
189 void praat_write_do (UiForm dia, conststring32 extension);
190 void praat_new (autoDaata me);
191 void praat_new (autoDaata me, const MelderArg& arg);
192 void praat_new (autoDaata me, const MelderArg& arg1, const MelderArg& arg2,
193 const MelderArg& arg3 = U"", const MelderArg& arg4 = U"", const MelderArg& arg5 = U"");
194 void praat_newWithFile (autoDaata me, MelderFile file, conststring32 name);
195 void praat_name2 (char32 *name, ClassInfo klas1, ClassInfo klas2);
196
197 #define iam_LOOP(klas) klas me = static_cast<klas> (OBJECT)
198 #define WHERE(condition) for (IOBJECT = 1; IOBJECT <= theCurrentPraatObjects -> n; IOBJECT ++) if (condition)
199 #define WHERE_DOWN(condition) for (IOBJECT = theCurrentPraatObjects -> n; IOBJECT > 0; IOBJECT --) if (condition)
200 #define SELECTED (theCurrentPraatObjects -> list [IOBJECT]. isSelected)
201 #define LOOP for (IOBJECT = 1; IOBJECT <= theCurrentPraatObjects -> n; IOBJECT ++) if (SELECTED)
202 #define CLASS (theCurrentPraatObjects -> list [IOBJECT]. klas)
203 #define OBJECT (theCurrentPraatObjects -> list [IOBJECT]. object)
204 #define GRAPHICS theCurrentPraatPicture -> graphics
205 #define FULL_NAME (theCurrentPraatObjects -> list [IOBJECT]. name.get())
206 #define ID (theCurrentPraatObjects -> list [IOBJECT]. id)
207 #define ID_AND_FULL_NAME Melder_cat (ID, U". ", FULL_NAME)
208 #define NAME praat_name (IOBJECT)
209
210 /* Used by praat_Sybil.cpp, if you put an Editor on the screen: */
211 void praat_installEditor (Editor editor, integer iobject);
212 /* This routine adds a reference to a new editor (unless it is null) to the screen object
213 which is in the list at position 'iobject'.
214 It sets the destroyCallback and dataChangedCallback as appropriate for Praat:
215 the destroyCallback will set the now dangling reference to nullptr,
216 so that a subsequent click on the "View & Edit" button will create a new editor;
217 the dataChangedCallback will notify an open DataEditor with the same data,
218 after that data will have changed.
219 */
220 void praat_installEditor2 (Editor editor, integer iobject1, integer iobject2);
221 void praat_installEditor3 (Editor editor, integer iobject1, integer iobject2, integer iobject3);
222 void praat_installEditorN (Editor editor, DaataList objects);
223
224 void praat_dataChanged (Daata object);
225 /* Call this after changing a screen object. */
226 /* Associated editors and data editors will be notified (with Editor_dataChanged). */
227
228 /* Used by praat.cpp, praat_Basic.cpp, and praat_Sybil.cpp; defined in praat_picture.cpp.
229 */
230 void praat_picture_open ();
231 void praat_picture_close ();
232 /* These two routines should bracket drawing commands. */
233 /* However, they usually do so RAII-wise by being packed into autoPraatPictureOpen (see GRAPHICS_EACH). */
234
235 /* For main.cpp */
236
237 #define INCLUDE_LIBRARY(praat_xxx_init) \
238 { extern void praat_xxx_init (); praat_xxx_init (); }
239 #define INCLUDE_MANPAGES(manual_xxx_init) \
240 { extern void manual_xxx_init (ManPages me); manual_xxx_init (theCurrentPraatApplication -> manPages); }
241
242 /* For text-only applications that do not want to see that irritating Picture window. */
243 /* Works only if called before praat_init. */
244 /* The program will crash if you still try to use drawing routines. */
245 void praat_dontUsePictureWindow ();
246
247 /* Before praat_init: */
248 void praat_setLogo (double width_mm, double height_mm, void (*draw) (Graphics g));
249
250 /* Removing objects from the list. */
251 /* To remove the selected objects of class Klas from the list: */
252 /*
253 for (i = praat.n; i >= 1; i --) // Down!
254 if (praat.list[i].selected && Thing_isa (praat.list[i].object, classKlas)
255 praat_removeObject (i);
256 praat_show (); // Needed because the selection has changed.
257 */
258 void praat_removeObject (integer i); // i = 1..praat.n
259 void praat_show (); // forces an update of the dynamic menu
260 void praat_updateSelection ();
261 /* If you require the correct selection immediately after calling praat_new. */
262
263 void praat_addCommandsToEditor (Editor me);
264
265 autoCollection praat_getSelectedObjects ();
266
267 struct autoPraatPictureOpen {
268 autoPraatPictureOpen () { praat_picture_open (); }
269 ~autoPraatPictureOpen () { praat_picture_close (); }
270 };
271
272 #if defined (_WIN32)
273 #define main wingwmain
274 #endif
275
276 /* End of file praat.h */
277 #endif