Debian Codegraph @

melder/melder_progress.h

raw symbols SCIP
1 #cxx . . $ `<file>/melder/melder_progress.h`/ifndef _melder_progress_h_
2 #define _melder_progress_h_cxx . . $ `melder/melder_progress.h:2:9`!
3 /* melder_progress.h
4 *
5 * Copyright (C) 1992-2018,2020,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 /*
22 SYNOPSIS
23
24 Melder_progress (double progress, messageArgs...);
25
26 Function:
27 Show the progress of a time-consuming process.
28 Arguments:
29 Any of 'args' may be null.
30 Batch behaviour:
31 Does nothing, always returns 1.
32 Interactive behaviour:
33 Shows the progress of a time-consuming process:
34 - if 'progress' <= 0.0, show a window with text and a Cancel button, and return 1;
35 - if 0.0 < 'progress' < 1.0, show text and a partially filled progress bar,
36 and return 0 if user interrupts, else return 1;
37 - if 'progress' >= 1, hide the window.
38 Usage:
39 - call with 'progress' = 0.0 before the process starts:
40 (void) Melder_progress (0.0, U"Starting work...");
41 - at every turn in your loop, call with 'progress' between 0.0 and 1.0:
42 Melder_progress (i / (n + 1.0), U"Working on part ", i, U" out of ", n, U"...");
43 an exception is thrown if the user clicks Cancel; if you don't want that, catch it:
44 try {
45 Melder_progress (i / (n + 1.0), U"Working on part ", i, U" out of ", n, U"...");
46 } catch (MelderError) {
47 Melder_clearError ();
48 break;
49 }
50 - after the process has finished, call with 'progress' = 1.0:
51 (void) Melder_progress (1.0);
52 - the first and third steps can be automated by autoMelderProgress:
53 autoMelderProgress progress (U"Starting work...");
54
55 void* Melder_monitor (double progress, messageArgs...);
56
57 Function:
58 Show the progress of a time-consuming process.
59 Arguments:
60 Any of 'args' may be null.
61 Batch behaviour:
62 Does nothing, returns null if 'progress' <= 0.0 and a non-null pointer otherwise.
63 Interactive behaviour:
64 Shows the progress of a time-consuming process:
65 - if 'progress' <= 0.0, show a window with text and a Cancel button and
66 room for a square drawing, and return a Graphics;
67 - if 0.0 < 'progress' < 1.0, show text and a partially filled progress bar,
68 and return nullptr if user interrupts, else return a non-null pointer;
69 - if 'progress' >= 1, hide the window.
70 Usage:
71 - call with 'progress' = 0.0 before the process starts.
72 - assign the return value to a Graphics:
73 Graphics graphics = Melder_monitor (0.0, U"Starting work...");
74 - at every turn of your loop, draw something in the Graphics:
75 if (graphics) { // always check; might be batch
76 Graphics_beginMovieFrame (graphics, & Melder_WHITE); // the colour only if you erase all every time
77 Graphics_polyline (graphics, ...);
78 Graphics_text (graphics, ...);
79 Graphics_endMovieFrame (graphics, 0.0);
80 }
81 - immediately after this in your loop, call with 'progress' between 0.0 and 1.0:
82 Melder_monitor (i / (n + 1.0), U"Working on part ", i, U" out of ", n, U"...");
83 an exception is thrown if the user clicks Cancel; if you don't want that, catch it:
84 try {
85 Melder_monitor (i / (n + 1.0), U"Working on part ", i, U" out of ", n, U"...");
86 } catch (MelderError) {
87 Melder_clearError ();
88 break;
89 }
90 - after the process has finished, call with 'progress' = 1.0:
91 (void) Melder_monitor (1.0, nullptr);
92 - showing and hiding can be automated by autoMelderMonitor:
93 autoMelderMonitor monitor ("Starting work...");
94 if (monitor.graphics()) { // always check; might be batch
95 Graphics_beginMovieFrame (graphics, & Melder_WHITE); // the colour only if you erase all every time
96 Graphics_polyline (monitor.graphics(), ...);
97 Graphics_text (monitor.graphics(), ...);
98 Graphics_endMovieFrame (graphics, 0.0);
99 }
100 */
101
102 namespace MelderProgresscxx . . $ MelderProgress/ {
103 extern int _depthcxx . . $ MelderProgress/_depth.;
104 using ProgressProccxx . . $ MelderProgress/ProgressProc# = void (*) (double progress, conststring32cxx . . $ conststring32# message);
105 using MonitorProccxx . . $ MelderProgress/MonitorProc# = void * (*) (double progress, conststring32cxx . . $ conststring32# message);
106 extern ProgressProccxx . . $ MelderProgress/ProgressProc# _p_progressProccxx . . $ MelderProgress/_p_progressProc.;
107 extern MonitorProccxx . . $ MelderProgress/MonitorProc# _p_monitorProccxx . . $ MelderProgress/_p_monitorProc.;
108 void _doProgresscxx . . $ MelderProgress/_doProgress(cd1f800970345287). (double progress, conststring32cxx . . $ conststring32# message);
109 void * _doMonitorcxx . . $ MelderProgress/_doMonitor(7223d092b5bdba8d). (double progress, conststring32cxx . . $ conststring32# message);
110 extern MelderStringcxx . . $ MelderString# _buffercxx . . $ MelderProgress/_buffer.;
111 }
112
113 void Melder_progressOffcxx . . $ Melder_progressOff(49f6e7a06ebc5aa8). ();
114 void Melder_progressOncxx . . $ Melder_progressOn(49f6e7a06ebc5aa8). ();
115
116 inline void Melder_progresscxx . . $ Melder_progress(ba8836b59fb42830). (double progress) {
117 MelderProgresscxx . . $ MelderProgress/::_doProgresscxx . . $ MelderProgress/_doProgress(cd1f800970345287). (progress, U"");
118 }
119 template <typename... Arg>
120 void Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (double progress, const Arg... arg) {
121 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& MelderProgresscxx . . $ MelderProgress/::_buffercxx . . $ MelderProgress/_buffer., arg...);
122 MelderProgresscxx . . $ MelderProgress/::_doProgresscxx . . $ MelderProgress/_doProgress(cd1f800970345287). (progress, MelderProgresscxx . . $ MelderProgress/::_buffercxx . . $ MelderProgress/_buffer..stringcxx . . $ MelderString#string.);
123 }
124 class autoMelderProgresscxx . . $ autoMelderProgress# {
125 public:
126 autoMelderProgresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# message) {
127 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.0, message);
128 }
129 ~cxx . . $ autoMelderProgress#`~autoMelderProgress`(ced63f7c635d850d).autoMelderProgresscxx . . $ autoMelderProgress# () {
130 Melder_progresscxx . . $ Melder_progress(ba8836b59fb42830). (1.0);
131 }
132 };
133
134 inline void * Melder_monitorcxx . . $ Melder_monitor(b05963a489c65be0). (double progress) {
135 return MelderProgresscxx . . $ MelderProgress/::_doMonitorcxx . . $ MelderProgress/_doMonitor(7223d092b5bdba8d). (progress, U"");
136 }
137 template <typename... Arg>
138 void * Melder_monitorcxx . . $ Melder_monitor(71ac93a27c32a1fa). (double progress, const Arg... arg) {
139 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& MelderProgresscxx . . $ MelderProgress/::_buffercxx . . $ MelderProgress/_buffer., arg...);
140 return MelderProgresscxx . . $ MelderProgress/::_doMonitorcxx . . $ MelderProgress/_doMonitor(7223d092b5bdba8d). (progress, MelderProgresscxx . . $ MelderProgress/::_buffercxx . . $ MelderProgress/_buffer..stringcxx . . $ MelderString#string.);
141 }
142
143 typedef class structGraphicscxx . . $ structGraphics# *Graphicscxx . . $ Graphics#;
144 class autoMelderMonitorcxx . . $ autoMelderMonitor# {
145 Graphicscxx . . $ Graphics# _graphicscxx . . $ autoMelderMonitor#_graphics.;
146 public:
147 autoMelderMonitorcxx . . $ autoMelderMonitor#autoMelderMonitor(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# message) {
148 ourcxx . . $ `melder/melder.h:42:9`! _graphicscxx . . $ autoMelderMonitor#_graphics. = (Graphicscxx . . $ Graphics#) Melder_monitorcxx . . $ Melder_monitor(71ac93a27c32a1fa). (0.0, message);
149 }
150 ~cxx . . $ autoMelderMonitor#`~autoMelderMonitor`(ced63f7c635d850d).autoMelderMonitorcxx . . $ autoMelderMonitor# () {
151 Melder_monitorcxx . . $ Melder_monitor(b05963a489c65be0). (1.0);
152 }
153 Graphicscxx . . $ Graphics# graphicscxx . . $ autoMelderMonitor#graphics(f223663f6a7613). () { return _graphicscxx . . $ autoMelderMonitor#_graphics.; }
154 };
155
156 struct autoMelderProgressOffcxx . . $ autoMelderProgressOff# {
157 autoMelderProgressOffcxx . . $ autoMelderProgressOff#autoMelderProgressOff(49f6e7a06ebc5aa8). () {
158 Melder_progressOffcxx . . $ Melder_progressOff(49f6e7a06ebc5aa8). ();
159 }
160 ~cxx . . $ autoMelderProgressOff#`~autoMelderProgressOff`(ced63f7c635d850d).autoMelderProgressOffcxx . . $ autoMelderProgressOff# () {
161 Melder_progressOncxx . . $ Melder_progressOn(49f6e7a06ebc5aa8). ();
162 }
163 };
164
165 void Melder_setProgressProccxx . . $ Melder_setProgressProc(9bcb6c487d44e509). (MelderProgresscxx . . $ MelderProgress/::ProgressProccxx . . $ MelderProgress/ProgressProc# p_proc);
166 void Melder_setMonitorProccxx . . $ Melder_setMonitorProc(1e842e40862c4d17). (MelderProgresscxx . . $ MelderProgress/::MonitorProccxx . . $ MelderProgress/MonitorProc# p_proc);
167
168 /* End of file melder_progress.h */
169 #endif