| 1 |
/* melder_progress.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2018,2020,2024 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 |
|
| 19 |
#include "melder.h" |
| 20 |
|
| 21 |
static void defaultProgress (double /*progress*/, conststring32 /*message*/) { |
| 22 |
} |
| 23 |
|
| 24 |
static void * defaultMonitor (double /*progress*/, conststring32 /*message*/) { |
| 25 |
return nullptr; |
| 26 |
} |
| 27 |
|
| 28 |
int MelderProgress::_depth = 0; |
| 29 |
|
| 30 |
MelderProgress::ProgressProc MelderProgress::_p_progressProc = & defaultProgress; |
| 31 |
MelderProgress::MonitorProc MelderProgress::_p_monitorProc = & defaultMonitor; |
| 32 |
|
| 33 |
void Melder_progressOff () { MelderProgress::_depth --; } |
| 34 |
void Melder_progressOn () { MelderProgress::_depth ++; } |
| 35 |
|
| 36 |
void MelderProgress::_doProgress (double progress, conststring32 message) { |
| 37 |
if (! Melder_batch && MelderProgress::_depth >= 0 && ! (Melder_debug == 14)) |
| 38 |
MelderProgress::_p_progressProc (progress, message); |
| 39 |
} |
| 40 |
|
| 41 |
MelderString MelderProgress::_buffer; |
| 42 |
|
| 43 |
void * MelderProgress::_doMonitor (double progress, conststring32 message) { |
| 44 |
if (! Melder_batch && MelderProgress::_depth >= 0) { |
| 45 |
void *result = MelderProgress::_p_monitorProc (progress, message); |
| 46 |
if (result) |
| 47 |
return result; |
| 48 |
} |
| 49 |
return progress <= 0.0 ? nullptr /* no Graphics */ : (void *) -1 /* any non-null pointer */; |
| 50 |
} |
| 51 |
|
| 52 |
void Melder_setProgressProc (MelderProgress::ProgressProc proc) { |
| 53 |
MelderProgress::_p_progressProc = ( proc ? proc : & defaultProgress ); |
| 54 |
} |
| 55 |
|
| 56 |
void Melder_setMonitorProc (MelderProgress::MonitorProc proc) { |
| 57 |
MelderProgress::_p_monitorProc = ( proc ? proc : & defaultMonitor ); |
| 58 |
} |
| 59 |
|
| 60 |
/* End of file melder_progress.cpp */ |