Nederlandse vertaling II
[sgc.git] / praat.c
blobfe87dd1f68ff91f43005b4bdfc9d8b8926681023
1 #include "sgc.h"
2 #include <unistd.h> /* F_OK ?? */
4 #include "melder.h"
5 #include "NUMmachar.h"
6 #include "gsl_errno.h"
8 #include "site.h"
9 #include "machine.h"
10 #include "Strings.h"
11 #include "Sound.h"
12 #include "Vector.h"
13 #include "Thing.h"
14 #include "Pitch_to_Sound.h"
15 #include "Data.h"
18 gpointer sound_init(void *args)
20 Sound melderSoundFromMic;
22 NUMmachar ();
23 gsl_set_error_handler_off ();
24 Melder_setMaximumAsynchronicity (Melder_SYNCHRONOUS);
26 melderSoundFromMic = Sound_recordFixedTime (1, 1.0, 0.5, 44100, 1.0);
27 forget(melderSoundFromMic);
28 Melder_clearError();
29 // Melder_flushError (NULL);
30 g_thread_exit(NULL);
33 void playInPraat(gchar *path) {
34 if (g_access(path, F_OK) == 0) {
35 structMelderFile file;
36 Sound melderSoundFromFile;
37 Melder_pathToFile(path, & file);
38 melderSoundFromFile = Sound_readFromSoundFile (& file);
39 if (! melderSoundFromFile) {
40 g_warning(_("Praat cannot open the file!"));
41 } else {
42 Sound_play(melderSoundFromFile, NULL, NULL);
43 forget(melderSoundFromFile);
45 } else {
46 g_warning(_("The file %s just don't exist!"), path);
48 Melder_clearError();
49 // Melder_flushError (NULL);
53 void playVoice() {
54 if (treevalid) {
55 gchar *string;
56 gchar *path;
57 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
58 path = voicepath(string);
60 playInPraat(path);
61 g_free(path);
62 g_free(string);
66 void playHum() {
67 if (treevalid) {
68 gchar *string;
69 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
70 gchar *path;
71 gchar *upper = g_malloc(4);
72 g_ascii_dtostr(upper, 4, upperRegister);
73 #ifdef WINCOMPAT
74 path = g_strjoin(NULL, PITCHPATH, G_DIR_SEPARATOR_S, string, "-", upper, ".wav", NULL);
75 #else
76 path = g_strjoin(NULL, PITCHPATH, G_DIR_SEPARATOR_S, string, "-", upper, ".Pitch", NULL);
77 #endif
78 g_free(upper);
80 #ifdef WINCOMPAT
81 playInPraat(path);
82 #else
83 if (g_access(path, F_OK) == 0) {
84 structMelderFile file;
85 Pitch melderPitchFromFile;
86 #ifdef MINGW
87 __declspec(dllimport) Pitch_Table classPitch;
88 #endif
89 Thing_recognizeClassesByName (classPitch, NULL);
90 Melder_pathToFile(path, & file);
91 melderPitchFromFile = Data_readFromTextFile (& file);
92 if (melderPitchFromFile != NULL) {
93 Pitch_hum(melderPitchFromFile, 0, 0);
94 forget(melderPitchFromFile);
95 } else {
96 g_debug("PITCH IS NULL!");
99 #endif
100 g_free(path);
101 g_free(string);
102 Melder_flushError (NULL);
107 void playBefore() {
108 GtkWidget *gimiVoice = glade_xml_get_widget(xml, "checkmenuitemBeforeVoice");
109 GtkWidget *gimiHum = glade_xml_get_widget(xml, "checkmenuitemBeforeHum");
111 /* Check play Example */
112 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice))) {
113 /* Play Voice */
114 playVoice();
117 /* Play Hum */
118 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum))) {
119 playHum();
123 gpointer example(void *args) {
124 GtkWidget *gimiVoice = glade_xml_get_widget(xml, "checkmenuitemExampleVoice");
125 GtkWidget *gimiHum = glade_xml_get_widget(xml, "checkmenuitemExampleHum");
127 g_idle_add(setButtonsFalse, NULL);
129 /* Check play Example */
130 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice))) {
131 /* Play Voice */
132 playVoice();
135 /* Play Hum */
136 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum))) {
137 playHum();
140 g_idle_add(setButtonsTrue, NULL);
141 g_thread_exit(NULL);
144 gpointer play(void *args) {
145 if (treevalid) {
146 playVoice();
147 g_idle_add(setButtonsTrue, NULL);
148 g_thread_exit(NULL);
153 gpointer record(void *args) {
154 if (treevalid) {
155 gchar *string;
156 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
157 // g_debug("%s %d welcome!\n\n\n", __func__, rand());
158 g_idle_add(setButtonsFalse, NULL);
159 playBefore();
160 if (g_access(RECORDPATH, F_OK) == 0) {
161 Sound melderSoundFromMic = Sound_recordFixedTime (1, 1.0, 0.5, 44100, 5.0);
163 if (! melderSoundFromMic) {
164 g_warning(_("No sound from praat!"));
165 } else {
166 GString *filename = g_string_sized_new(128);
167 GString *cmd = g_string_sized_new(128);
168 gchar *path;
169 structMelderFile file;
171 g_string_printf(filename, "%s.wav", string);
173 path = g_build_filename(RECORDPATH, filename->str, NULL);
174 g_string_free(filename, TRUE);
176 Vector_scale(melderSoundFromMic, 0.99);
177 Melder_pathToFile(path, &file);
178 Sound_writeToAudioFile16 (melderSoundFromMic, &file, Melder_WAV);
179 forget(melderSoundFromMic);
181 g_chdir(SCRIPTPATH);
182 g_string_printf(cmd, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN, G_DIR_SEPARATOR_S, path, string, upperRegister);
183 g_free(path);
184 g_debug(cmd->str);
185 // g_debug("EXECUTES! ");
186 system(cmd->str);
187 // g_debug("DONE!\n");
188 g_chdir("..");
189 g_string_free(cmd, TRUE);
191 } else {
192 g_warning(_("Missing recording directory %s."), RECORDPATH);
194 g_free(string);
195 Melder_clearError();
196 // Melder_flushError (NULL);
197 g_idle_add(setButtonsTrue, NULL);
198 // g_debug("%s bye!\n", __func__);
199 g_thread_exit(NULL);