File: melder_info.cpp

package info (click to toggle)
praat 5.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,728 kB
  • sloc: cpp: 333,759; ansic: 237,947; makefile: 731; python: 340
file content (230 lines) | stat: -rw-r--r-- 9,687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* melder_info.cpp
 *
 * Copyright (C) 1992-2011 Paul Boersma
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* pb 2002/03/07 GPL
 * pb 2006/12/08 separated from melder.c
 * pb 2006/12/17 removed Melder_info and made Melder_print safe
 * pb 2006/12/19 all functions number 1 through 9
 * pb 2007/06/11 wchar_t
 * pb 2007/08/14 faster
 * pb 2007/10/05 got rid of MelderStringA_copyW
 * pb 2007/12/13 Melder_writeToConsole
 * pb 2011/04/05 C++
 */

#include "melder.h"
#include "NUM.h"   // NUMundefined

static void defaultInformation (const wchar_t *message) {
	Melder_writeToConsole (message, false);
}

static void (*theInformation) (const wchar_t *) = defaultInformation;

void Melder_setInformationProc (void (*information) (const wchar_t *)) {
	theInformation = information ? information : defaultInformation;
}

static MelderString theForegroundBuffer = { 0 }, *theInfos = & theForegroundBuffer;

void MelderInfo_open (void) {
	MelderString_empty (theInfos);
}

void MelderInfo_write1 (const wchar_t *s1) {
	MelderString_append (theInfos, s1);
}
void MelderInfo_write2 (const wchar_t *s1, const wchar_t *s2) {
	MelderString_append (theInfos, s1, s2);
}
void MelderInfo_write3 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3) {
	MelderString_append (theInfos, s1, s2, s3);
}
void MelderInfo_write4 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4) {
	MelderString_append (theInfos, s1, s2, s3, s4);
}
void MelderInfo_write5 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5);
}
void MelderInfo_write6 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6);
}
void MelderInfo_write7 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7);
}
void MelderInfo_write8 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8);
}
void MelderInfo_write9 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8, const wchar_t *s9) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8, s9);
}

void MelderInfo_writeLine1 (const wchar_t *s1) {
	MelderString_append (theInfos, s1);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine2 (const wchar_t *s1, const wchar_t *s2) {
	MelderString_append (theInfos, s1, s2);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine3 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3) {
	MelderString_append (theInfos, s1, s2, s3);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine4 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4) {
	MelderString_append (theInfos, s1, s2, s3, s4);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine5 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine6 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine7 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine8 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8);
	MelderString_appendCharacter (theInfos, '\n');
}
void MelderInfo_writeLine9 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8, const wchar_t *s9) {
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8, s9);
	MelderString_appendCharacter (theInfos, '\n');
}

void MelderInfo_close (void) {
	if (theInfos == & theForegroundBuffer) {
		/*
			When writing to the Info window or the console, we must add a newline symbol,
			because a subsequent Melder_print call has to start on the next line.
			When writing to a diverted string, we must *not* add a newline symbol,
			because scripts expect returned strings without appended newlines!
		*/
		if (theInfos -> length == 0 || theInfos -> string [theInfos -> length - 1] != '\n') {   // Only if no newline there yet.
			MelderString_appendCharacter (theInfos, '\n');
		}
		theInformation (theInfos -> string ? theInfos -> string : L"");
	}
}

void Melder_informationReal (double value, const wchar_t *units) {
	MelderInfo_open ();
	if (value == NUMundefined)
		MelderInfo_write1 (L"--undefined--");
	else if (units == NULL)
		MelderInfo_write1 (Melder_double (value));
	else
		MelderInfo_write3 (Melder_double (value), L" ", units);
	MelderInfo_close ();
}

void Melder_divertInfo (MelderString *buffer) {
	theInfos = buffer == NULL ? & theForegroundBuffer : buffer;
}

void Melder_clearInfo (void) {
	if (theInfos == & theForegroundBuffer) {
		MelderString_empty (theInfos);
		theInformation (L"");
	}
}

const wchar_t * Melder_getInfo (void) {
	return theInfos -> string ? theInfos -> string : L"";
}

void Melder_print (const wchar_t *s) {
	//Melder_assert (theInfos == & theForegroundBuffer);   // Never diverted.
	/*
	 * This procedure is always called from a script; therefore, this is unlikely to be called when the info is diverted.
	 * Unlikely, but not impossible!
	 * The small possibility occurs when the script, having diverted the info through an assignment command,
	 * causes the progress bar to move. If the user chooses Run while the progress bar moves,
	 * the script will start to run and may call print:
	 *    pitch = To Pitch... 0 75 600
	 * Therefore, we write into the Info window explicitly. The results will still be strange,
	 * and a better solution would be to disallow the script from running (BUG: accept fewer events in waitWhileProgress).
	 */
	if (theInformation == defaultInformation) {
		theInformation ((wchar_t *) s);   // Do not print the previous lines again.
	} else {
		MelderString_append (& theForegroundBuffer, s);
		theInformation (theForegroundBuffer. string);
	}
}

void Melder_information (const wchar_t *s1) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4, s5);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8);
	MelderInfo_close ();
}

void Melder_information (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8, const wchar_t *s9) {
	MelderString_empty (theInfos);
	MelderString_append (theInfos, s1, s2, s3, s4, s5, s6, s7, s8, s9);
	MelderInfo_close ();
}

/* End of file melder_info.cpp */