3 gdouble upperRegister
= 200.0;
4 gint intTestCounter
= -1;
7 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
8 gchar
*path
= g_strjoin(NULL
, RECORDPATH
, G_DIR_SEPARATOR_S
, testList
[intTestCounter
], ".wav", NULL
);
9 if (g_access(path
, F_OK
) == 0) {
10 gtk_widget_set_sensitive(buttonPlay
, TRUE
);
12 gtk_widget_set_sensitive(buttonPlay
, FALSE
);
17 gboolean
setButtonsTrue() {
18 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
19 GtkWidget
*buttonExample
= glade_xml_get_widget(xml
, "buttonExample");
21 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
26 gtk_widget_set_sensitive(buttonRecord
, TRUE
);
28 gtk_widget_set_sensitive(buttonExample
, TRUE
);
30 gtk_widget_queue_draw(drawingareaPitch
);
32 feedbackTXT
= g_build_filename(SCRIPTPATH
, G_DIR_SEPARATOR_S
, "feedback.txt", NULL
);
34 if (g_file_get_contents(feedbackTXT
, &contents
, NULL
, NULL
) == TRUE
) {
35 g_debug("Sets label!\n");
36 GtkWidget
*label
= glade_xml_get_widget(xml
, "labelFeedback");
37 gtk_label_set_text(GTK_LABEL(label
), contents
);
38 g_debug("Label set!\n");
39 g_unlink(feedbackTXT
);
46 gboolean
setButtonsFalse() {
47 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
48 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
49 GtkWidget
*buttonExample
= glade_xml_get_widget(xml
, "buttonExample");
50 g_debug("%s welcome!\n", __func__
);
52 gtk_widget_set_sensitive(buttonRecord
, FALSE
);
53 gtk_widget_set_sensitive(buttonPlay
, FALSE
);
54 gtk_widget_set_sensitive(buttonExample
, FALSE
);
56 g_debug("%s bye!\n", __func__
);
61 void on_buttonRecord_clicked(GtkWidget
*widget
, gpointer user_data
) {
62 if (testList
[intTestCounter
] == NULL
) {
63 GtkWidget
*dialog
= gtk_message_dialog_new(NULL
,
67 "Don't have any (more) tests");
68 gtk_dialog_run (GTK_DIALOG (dialog
));
69 gtk_widget_destroy (dialog
);
74 /* Start record Thread */
76 g_debug("%s creates record", __func__
);
78 if (!g_thread_create((GThreadFunc
)record
, NULL
, FALSE
, &error
)) {
80 // g_error ("Failed to create record thread: %s\n", error->message);
83 g_debug("%s is done", __func__
);
87 void on_buttonExample_clicked(GtkWidget
*widget
, gpointer user_data
) {
91 /* Start example Thread */
92 if (!g_thread_create((GThreadFunc
)example
, widget
, FALSE
, &error
)) {
94 g_error ("Failed to create example thread: %s\n", error
->message
);
95 g_error_free (error
) ;
100 void on_buttonPlay_clicked(GtkWidget
*widget
, gpointer user_data
) {
104 /* Start play Thread */
105 if (!g_thread_create((GThreadFunc
)play
, widget
, FALSE
, &error
)) {
107 g_error ("Failed to create play thread: %s\n", error
->message
);
108 g_error_free (error
) ;
113 void on_buttonPrevious_clicked(GtkWidget
*widget
, gpointer user_data
) {
114 GtkWidget
*buttonPrevious
= glade_xml_get_widget(xml
, "buttonPrevious");
115 GtkWidget
*buttonNext
= glade_xml_get_widget(xml
, "buttonNext");
116 GtkWidget
*labelFeedback
= glade_xml_get_widget(xml
, "labelFeedback");
117 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
121 if (testList
[intTestCounter
] != NULL
) {
122 GString
*label
= g_string_new(testList
[intTestCounter
]);
123 g_string_prepend(label
, "<span size=\"xx-large\">");
124 g_string_append(label
, "</span>");
125 gtk_label_set_markup(GTK_LABEL(labelFeedback
), label
->str
);
126 g_string_free(label
, TRUE
);
129 if (intTestCounter
> 0) {
130 gtk_widget_set_sensitive(buttonPrevious
, TRUE
);
131 gtk_widget_set_sensitive(buttonNext
, TRUE
);
133 gtk_widget_set_sensitive(buttonPrevious
, FALSE
);
134 gtk_widget_set_sensitive(buttonNext
, TRUE
);
139 gtk_widget_queue_draw(drawingareaPitch
);
142 void on_buttonNext_clicked(GtkWidget
*widget
, gpointer user_data
) {
143 GtkWidget
*buttonPrevious
= glade_xml_get_widget(xml
, "buttonPrevious");
144 GtkWidget
*buttonNext
= glade_xml_get_widget(xml
, "buttonNext");
145 GtkWidget
*labelFeedback
= glade_xml_get_widget(xml
, "labelFeedback");
146 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
150 if ((intTestCounter
+1) >= g_strv_length(testList
)) {
151 gtk_widget_set_sensitive(buttonNext
, FALSE
);
153 gtk_widget_set_sensitive(buttonNext
, TRUE
);
156 if (testList
[intTestCounter
] != NULL
) {
157 GString
*label
= g_string_new(testList
[intTestCounter
]);
158 g_string_prepend(label
, "<span size=\"xx-large\">");
159 g_string_append(label
, "</span>");
160 gtk_label_set_markup(GTK_LABEL(labelFeedback
), label
->str
);
161 g_string_free(label
, TRUE
);
164 if (intTestCounter
> 0)
165 gtk_widget_set_sensitive(buttonPrevious
, TRUE
);
167 gtk_widget_set_sensitive(buttonPrevious
, FALSE
);
172 gtk_widget_queue_draw(drawingareaPitch
);
175 void on_menuitemHelp_activate(GtkWidget
*widget
, gpointer user_data
) {
176 GtkWidget
*dialogHelp
= glade_xml_get_widget(xml
, "dialogHelp");
177 gtk_dialog_run(GTK_DIALOG(dialogHelp
));
180 void on_menuitemAdd_activate(GtkWidget
*widget
, gpointer user_data
) {
181 GtkWidget
*entryPinyin
= glade_xml_get_widget(xml
, "entryPinyin");
182 GtkWidget
*dialogAdd
= glade_xml_get_widget(xml
, "dialogAdd");
183 gint result
= gtk_dialog_run(GTK_DIALOG(dialogAdd
));
186 case GTK_RESPONSE_OK
:
188 gchar
*pinyin
= pango_trim_string(gtk_entry_get_text(GTK_ENTRY(entryPinyin
)));
190 if (pinyin
!= NULL
&& strlen(pinyin
) > 0) { /* TODO: pinyin check */
191 GtkWidget
*buttonNext
= glade_xml_get_widget(xml
, "buttonNext");
192 guint length
= g_strv_length(testList
);
193 testList
= g_realloc(testList
, (length
+2)*sizeof(gchar
**));
194 testList
[length
] = g_strdup(pinyin
);
195 testList
[length
+1] = NULL
;
196 gtk_entry_set_text(GTK_ENTRY(entryPinyin
), "");
198 gtk_widget_set_sensitive(buttonNext
, TRUE
);
204 gtk_entry_set_text(GTK_ENTRY(entryPinyin
), "");
210 void on_dialogAdd_close(GtkWidget
*button
, gpointer user_data
) {
211 GtkWidget
*buttonAdd
= glade_xml_get_widget(xml
, "buttonAdd");
212 gtk_widget_hide(gtk_widget_get_toplevel(button
));
213 gtk_widget_grab_focus(buttonAdd
);
216 void on_dialogHelp_close(GtkWidget
*button
, gpointer user_data
) {
217 gtk_widget_hide(gtk_widget_get_toplevel(button
));
222 void on_imagemenuitemAbout_activate(GtkWidget
*widget
, gpointer user_data
) {
223 gtk_widget_show(glade_xml_get_widget(xml
, "aboutdialogMain"));
226 void on_close_aboutdialog(GtkWidget
*button
, gpointer user_data
) {
227 gtk_widget_hide(gtk_widget_get_toplevel(button
));
230 void on_menuitemVoice_activate(GtkWidget
*widget
, gpointer user_data
) {
231 const gchar
*name
= gtk_widget_get_name(widget
);
232 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
233 if (g_str_equal(name
, "menuitemVoice_Male_Low") == TRUE
) upperRegister
= 150.0;
234 if (g_str_equal(name
, "menuitemVoice_Male") == TRUE
) upperRegister
= 200.0;
235 if (g_str_equal(name
, "menuitemVoice_Female") == TRUE
) upperRegister
= 300.0;
236 if (g_str_equal(name
, "menuitemVoice_Child") == TRUE
) upperRegister
= 450.0;
237 gtk_widget_queue_draw(drawingareaPitch
);
240 void paint (GtkWidget
*widget
, GdkEventExpose
*eev
, gpointer data
) {
242 GString
*filename
= g_string_sized_new (200);
243 GString
*cmd
= g_string_sized_new (200);
244 GString
*recordedPT
= g_string_sized_new(100);
245 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, testList
[intTestCounter
], upperRegister
);
246 g_string_printf(recordedPT
, "%s%s%s.PitchTier", RECORDPATH
, G_DIR_SEPARATOR_S
, testList
[intTestCounter
]);
248 if (g_access(filename
->str
, F_OK
) == -1) {
249 /* Eigenlijk wil je de system ranzigheid vervangen door een werkende versie van dit,
250 * maar eigenlijk MOET je gewoon de praat scripts naar C omzetten ;)
254 gchar *upper = g_malloc(5);
255 g_ascii_dtostr(upper, 5, upperRegister);
257 argv[1] = testList[intTestCounter];
261 g_spawn_sync((const gchar *) SCRIPTPATH, argv, NULL, (GSpawnFlags)(G_SPAWN_SEARCH_PATH | G_SPAWN_FILE_AND_ARGV_ZERO), NULL, NULL, NULL, NULL, &exit_status, &err);*/
263 g_string_printf(cmd
, "%s DrawToneContour.praat %s %0.f", PRAATBIN
, testList
[intTestCounter
], upperRegister
);
264 g_debug("%s", cmd
->str
);
269 cr
= gdk_cairo_create (widget
->window
);
270 cairo_set_line_width (cr
, 1);
271 cairo_select_font_face (cr
, "Sans", CAIRO_FONT_SLANT_NORMAL
,
272 CAIRO_FONT_WEIGHT_BOLD
);
275 if (g_access(filename
->str
, F_OK
) == 0) {
276 cairo_move_to (cr
, 5, 15);
277 cairo_set_source_rgb (cr
, 0,0,0);
278 cairo_show_text (cr
, "Reference Pitch");
281 drawPitchTier(cr
, filename
->str
,
282 widget
->allocation
.width
,
283 widget
->allocation
.height
, upperRegister
+ 100.0);
286 //g_debug("%s", recordedPT->str);
288 if (g_access(recordedPT
->str
, F_OK
) == 0) {
289 cairo_move_to (cr
, 15, 30);
290 cairo_set_source_rgb (cr
, 1,0,0);
291 cairo_show_text (cr
, "Your Pitch");
293 drawPitchTier(cr
, recordedPT
->str
,
294 widget
->allocation
.width
,
295 widget
->allocation
.height
, upperRegister
+ 100.0);
298 g_string_free(recordedPT
, TRUE
);
300 g_string_free(filename
, TRUE
);