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