melder_play.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* melder_play.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. #ifdef _WIN32
  20. #include <windows.h>
  21. #endif
  22. #ifdef macintosh
  23. #include "macport_on.h"
  24. #include <AudioToolbox/AudioToolbox.h>
  25. #include "macport_off.h"
  26. #endif
  27. static int defaultRecord (double duration) {
  28. (void) duration;
  29. return 0; // nothing recorded
  30. }
  31. static int defaultRecordFromFile (MelderFile file) {
  32. (void) file;
  33. return 0; // nothing recorded
  34. }
  35. static void defaultPlay () {}
  36. static void defaultPlayReverse () {}
  37. static int defaultPublishPlayed () {
  38. return 0; // nothing published
  39. }
  40. void Melder_beep () {
  41. #ifdef macintosh
  42. AudioServicesPlayAlertSound (kSystemSoundID_UserPreferredAlert);
  43. #else
  44. fprintf (stderr, "\a");
  45. #endif
  46. }
  47. /********** Current message methods: initialize to default (batch) behaviour. **********/
  48. static struct {
  49. int (*record) (double duration);
  50. int (*recordFromFile) (MelderFile file);
  51. void (*play) ();
  52. void (*playReverse) ();
  53. int (*publishPlayed) ();
  54. }
  55. theMelderFunctions = {
  56. defaultRecord, defaultRecordFromFile, defaultPlay, defaultPlayReverse, defaultPublishPlayed
  57. };
  58. int Melder_record (double duration) {
  59. return theMelderFunctions. record (duration);
  60. }
  61. int Melder_recordFromFile (MelderFile file) {
  62. return theMelderFunctions. recordFromFile (file);
  63. }
  64. void Melder_play () {
  65. theMelderFunctions. play ();
  66. }
  67. void Melder_playReverse () {
  68. theMelderFunctions. playReverse ();
  69. }
  70. int Melder_publishPlayed () {
  71. return theMelderFunctions. publishPlayed ();
  72. }
  73. /********** Procedures to override message methods (e.g., to enforce interactive behaviour). **********/
  74. void Melder_setRecordProc (int (*record) (double))
  75. { theMelderFunctions. record = record ? record : defaultRecord; }
  76. void Melder_setRecordFromFileProc (int (*recordFromFile) (MelderFile))
  77. { theMelderFunctions. recordFromFile = recordFromFile ? recordFromFile : defaultRecordFromFile; }
  78. void Melder_setPlayProc (void (*play) ())
  79. { theMelderFunctions. play = play ? play : defaultPlay; }
  80. void Melder_setPlayReverseProc (void (*playReverse) ())
  81. { theMelderFunctions. playReverse = playReverse ? playReverse : defaultPlayReverse; }
  82. void Melder_setPublishPlayedProc (int (*publishPlayed) ())
  83. { theMelderFunctions. publishPlayed = publishPlayed ? publishPlayed : defaultPublishPlayed; }
  84. /* End of file melder_play.cpp */