melder_progress.cpp 2.1 KB

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