4 gdouble upperRegister
= 200.0;
6 gchar
* voicepath(gchar
*string
) {
7 gchar
*path
= g_strjoin(NULL
, base
, G_DIR_SEPARATOR_S
, string
, ".wav", NULL
);
8 if (g_access(path
, F_OK
) != 0) {
10 path
= g_strjoin(NULL
, g_getenv(STORAGE
), G_DIR_SEPARATOR_S
, STOREAS
, G_DIR_SEPARATOR_S
, PINYINPATH
, G_DIR_SEPARATOR_S
, string
, ".wav", NULL
);
15 static void setButtonByFileExists(GtkWidget
*button
, gchar
*path
) {
16 if (g_access(path
, F_OK
) == 0) {
17 gtk_widget_set_sensitive(button
, TRUE
);
19 gtk_widget_set_sensitive(button
, FALSE
);
24 static void setButtonExample() {
25 GtkWidget
*buttonExample
= glade_xml_get_widget(xml
, "buttonExample");
27 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemExampleHum");
28 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
32 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
33 path
= voicepath(string
);
35 setButtonByFileExists(buttonExample
, path
);
40 gtk_widget_set_sensitive(buttonExample
, TRUE
);
43 gtk_widget_set_sensitive(buttonExample
, FALSE
);
47 gchar
* pathToPlay() {
50 path
= g_build_filename(SCRIPTPATH
, "lastExample.wav", NULL
);
54 GString
*filename
= g_string_sized_new(128);
55 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
56 g_string_printf(filename
, "%s.wav", string
);
57 path
= g_build_filename(RECORDPATH
, filename
->str
, NULL
);
58 g_string_free(filename
, TRUE
);
64 static void setButtonPlay() {
65 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
66 gchar
*path
= pathToPlay();
68 setButtonByFileExists(buttonPlay
, path
);
73 gboolean
setButtonsTrue() {
74 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
76 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
81 gtk_widget_set_sensitive(buttonRecord
, TRUE
);
85 gtk_widget_queue_draw(drawingareaPitch
);
87 feedbackTXT
= g_build_filename(SCRIPTPATH
, G_DIR_SEPARATOR_S
, "feedback.txt", NULL
);
89 if (g_file_get_contents(feedbackTXT
, &contents
, NULL
, NULL
) == TRUE
) {
90 // g_debug("Sets label!\n");
91 GtkWidget
*label
= glade_xml_get_widget(xml
, "labelFeedback");
92 gtk_label_set_text(GTK_LABEL(label
), contents
);
93 // g_debug("Label set!\n");
94 g_unlink(feedbackTXT
);
101 gboolean
setButtonsFalse() {
102 GtkWidget
*buttonRecord
= glade_xml_get_widget(xml
, "buttonRecord");
103 GtkWidget
*buttonPlay
= glade_xml_get_widget(xml
, "buttonPlay");
104 GtkWidget
*buttonExample
= glade_xml_get_widget(xml
, "buttonExample");
105 // g_debug("%s welcome!\n", __func__);
107 gtk_widget_set_sensitive(buttonRecord
, FALSE
);
108 gtk_widget_set_sensitive(buttonPlay
, FALSE
);
109 gtk_widget_set_sensitive(buttonExample
, FALSE
);
111 // g_debug("%s bye!\n", __func__);
116 void on_buttonRecord_clicked(GtkWidget
*widget
, gpointer user_data
) {
119 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
122 if (string
== NULL
) {
123 GtkWidget
*dialog
= gtk_message_dialog_new(NULL
,
127 _("Don't have any (more) tests"));
128 gtk_dialog_run (GTK_DIALOG (dialog
));
129 gtk_widget_destroy (dialog
);
132 /* Start record Thread */
134 // g_debug("%s creates record", __func__);
136 g_thread_create((GThreadFunc
)record
, NULL
, FALSE
, NULL
);
138 // g_debug("%s is done", __func__);
144 void on_buttonExample_clicked(GtkWidget
*widget
, gpointer user_data
) {
146 /* Start example Thread */
147 g_thread_create((GThreadFunc
)example
, widget
, FALSE
, NULL
);
150 void on_buttonPlay_clicked(GtkWidget
*widget
, gpointer user_data
) {
152 /* Start play Thread */
153 g_thread_create((GThreadFunc
)play
, widget
, FALSE
, NULL
);
156 gboolean
prev(GtkWidget
*previous
) {
157 gboolean ret
= FALSE
;
159 /* Code From anchient Sylpheed */
163 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(liststore
), &mainIter
);
165 if ((ret
= gtk_tree_path_prev(path
)) == TRUE
) {
166 gtk_tree_model_get_iter(GTK_TREE_MODEL(liststore
), &prev
, path
);
167 if (previous
!= NULL
) {
173 gtk_tree_path_free(path
);
180 gboolean
next(GtkWidget
*next
) {
183 return gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore
), &mainIter
);
185 GtkTreeIter next
= mainIter
;
186 return gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore
), &next
);
193 void updateWidgets() {
194 GtkWidget
*labelFeedback
= glade_xml_get_widget(xml
, "labelFeedback");
198 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
199 GString
*label
= g_string_new(string
);
201 g_string_prepend(label
, "<span size=\"xx-large\">");
202 g_string_append(label
, "</span>");
203 gtk_label_set_markup(GTK_LABEL(labelFeedback
), label
->str
);
204 g_string_free(label
, TRUE
);
207 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(xml
, "treeviewWords"))), &mainIter
);
209 gtk_label_set_markup(GTK_LABEL(labelFeedback
), "");
212 gtk_widget_set_sensitive(glade_xml_get_widget(xml
, "buttonRecord"), treevalid
);
213 gtk_widget_set_sensitive(glade_xml_get_widget(xml
, "imagemenuitemSave"), treevalid
);
214 gtk_widget_set_sensitive(glade_xml_get_widget(xml
, "imagemenuitemSaveAs"), treevalid
);
216 gtk_widget_set_sensitive(glade_xml_get_widget(xml
, "buttonPrevious"), prev(NULL
));
217 gtk_widget_set_sensitive(glade_xml_get_widget(xml
, "buttonNext"), next(NULL
));
222 gtk_widget_queue_draw(glade_xml_get_widget(xml
, "drawingareaPitch"));
225 void on_Save(GtkWidget
*chooser
, gpointer user_data
) {
226 fileSave(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser
)));
229 void on_dialogAdd_close(GtkWidget
*button
, gpointer user_data
) {
230 GtkWidget
*buttonAdd
= glade_xml_get_widget(xml
, "buttonAdd");
231 gtk_widget_hide(gtk_widget_get_toplevel(button
));
232 gtk_widget_grab_focus(buttonAdd
);
235 void on_menuitemVoice_activate(GtkWidget
*widget
, gpointer user_data
) {
236 const gchar
*name
= gtk_widget_get_name(widget
);
237 GtkWidget
*drawingareaPitch
= glade_xml_get_widget(xml
, "drawingareaPitch");
238 if (g_str_equal(name
, "menuitemVoice_Male_Low") == TRUE
) upperRegister
= 150.0;
239 if (g_str_equal(name
, "menuitemVoice_Male") == TRUE
) upperRegister
= 200.0;
240 if (g_str_equal(name
, "menuitemVoice_Female") == TRUE
) upperRegister
= 300.0;
241 if (g_str_equal(name
, "menuitemVoice_Child") == TRUE
) upperRegister
= 450.0;
242 gtk_widget_queue_draw(drawingareaPitch
);
245 void paint (GtkWidget
*widget
, GdkEventExpose
*eev
, gpointer data
) {
248 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
250 if (string
!= NULL
) {
252 GString
*filename
= g_string_sized_new (200);
253 GString
*cmd
= g_string_sized_new (200);
254 GString
*recordedPT
= g_string_sized_new(100);
257 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, string
, upperRegister
);
258 g_string_printf(recordedPT
, "%s%s%s.PitchTier", RECORDPATH
, G_DIR_SEPARATOR_S
, string
);
260 g_string_printf(filename
, "%s%s%s-%0.f.Pitch", PITCHPATH
, G_DIR_SEPARATOR_S
, string
, upperRegister
);
261 g_string_printf(recordedPT
, "%s%s%s.Pitch", RECORDPATH
, G_DIR_SEPARATOR_S
, string
);
264 if (g_access(filename
->str
, F_OK
) == -1) {
267 g_string_printf(cmd
, "%s DrawToneContour.praat %s %0.f", PRAATBIN
, string
, upperRegister
);
268 // g_debug("%s", cmd->str);
271 g_string_printf(cmd
, "DrawToneContour.praat %s %0.f", string
, upperRegister
);
272 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
279 cr
= gdk_cairo_create (widget
->window
);
280 cairo_set_line_width (cr
, 1);
281 cairo_select_font_face (cr
, "Sans", CAIRO_FONT_SLANT_NORMAL
,
282 CAIRO_FONT_WEIGHT_BOLD
);
285 if (g_access(filename
->str
, F_OK
) == 0) {
286 cairo_move_to (cr
, 5, 15);
287 cairo_set_source_rgb (cr
, 0,0,0);
288 cairo_show_text (cr
, _("Reference Pitch"));
291 drawPitchTier(cr
, filename
->str
,
292 widget
->allocation
.width
,
293 widget
->allocation
.height
, upperRegister
+ 100.0);
295 g_string_free(filename
, TRUE
);
296 // g_debug("%s", recordedPT->str);
298 if (g_access(recordedPT
->str
, F_OK
) == 0) {
299 cairo_move_to (cr
, 15, 30);
300 cairo_set_source_rgb (cr
, 1,0,0);
301 cairo_show_text (cr
, _("Your Pitch"));
303 drawPitchTier(cr
, recordedPT
->str
,
304 widget
->allocation
.width
,
305 widget
->allocation
.height
, upperRegister
+ 100.0);
308 g_string_free(recordedPT
, TRUE
);
315 void on_menuitemShuffle_activate(GtkWidget
*menuitem
, gpointer data
) {
318 gint amount
= gtk_tree_model_iter_n_children(GTK_TREE_MODEL(liststore
), NULL
) - 1;
320 for (i
= 0; i
<= amount
; i
++) {
321 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(liststore
),
323 g_random_int_range(0, amount
));
324 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(liststore
),
326 g_random_int_range(0, amount
));
327 gtk_list_store_swap(GTK_LIST_STORE(liststore
), &a
, &b
);
329 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);