1 #include "singleword.h"
2 #include <gdk/gdkkeysyms.h>
11 void run_script(gchar
*pinyin
) {
12 if (strlen(pinyin
) > 1) {
13 GString
*cmd
= g_string_sized_new (200);
16 g_string_printf(cmd
, "%s DrawToneContour.praat %s %0.f", PRAATBIN
, pinyin
, upperRegister
);
19 g_string_printf(cmd
, "DrawToneContour.praat %s %0.f", pinyin
, upperRegister
);
20 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
22 Melder_flushError(NULL
);
23 // Melder_clearError();
27 g_string_free(cmd
, TRUE
);
31 static void commit(GtkWidget
*widget
) {
32 if (active
!= NULL
) g_free(active
);
33 active
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
35 g_ascii_strdown(active
, -1);
36 g_strcanon(active
, "#012345abcdefghijklmnopqrstuvwxyz\n", '-');
38 gtk_entry_set_text(GTK_ENTRY(widget
), active
);
42 gtk_widget_queue_draw(glade_xml_get_widget(xml
, "drawingareaPitch"));
46 void entryPinyin_key_release_event_cb(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
) {
47 if (event
!= NULL
&& event
->keyval
== GDK_Return
) {
52 void buttonCommit_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
56 void buttonRecord_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
57 g_thread_create((GThreadFunc
)record
, NULL
, FALSE
, NULL
);
60 void buttonPlay_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
61 g_thread_create((GThreadFunc
)play
, NULL
, FALSE
, NULL
);
64 void buttonHum_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
66 GString
*filename
= g_string_sized_new (200);
67 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, active
, upperRegister
);
69 if (g_access(filename
->str
, F_OK
) == -1) run_script(active
);
71 g_thread_create((GThreadFunc
)playHum
, NULL
, FALSE
, NULL
);
73 g_string_free(filename
, TRUE
);
77 void paint (GtkWidget
*widget
, GdkEventExpose
*eev
, gpointer data
) {
80 GString
*filename
= g_string_sized_new (200);
81 GString
*recordedPT
= g_string_sized_new (200);
83 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, active
, upperRegister
);
84 g_string_printf(recordedPT
, "%s%s%s.PitchTier", RECORDPATH
, G_DIR_SEPARATOR_S
, active
);
86 if (g_access(filename
->str
, F_OK
) == -1) run_script(active
);
88 cr
= gdk_cairo_create (widget
->window
);
89 cairo_set_line_width (cr
, 1);
90 cairo_select_font_face (cr
, "Sans", CAIRO_FONT_SLANT_NORMAL
, CAIRO_FONT_WEIGHT_BOLD
);
91 if (g_access(filename
->str
, F_OK
) == 0) {
92 cairo_move_to (cr
, 5, 15);
93 cairo_set_source_rgb (cr
, 0,0,0);
94 cairo_show_text (cr
, _("Reference Pitch"));
97 drawPitchTier(cr
, filename
->str
,
98 widget
->allocation
.width
,
99 widget
->allocation
.height
, upperRegister
+ 100.0);
101 g_string_free(filename
, TRUE
);
103 if (g_access(recordedPT
->str
, F_OK
) == 0) {
104 cairo_move_to (cr
, 15, 30);
105 cairo_set_source_rgb (cr
, 1,0,0);
106 cairo_show_text (cr
, _("Your Pitch"));
108 drawPitchTier(cr
, recordedPT
->str
,
109 widget
->allocation
.width
,
110 widget
->allocation
.height
, upperRegister
+ 100.0);
113 g_string_free(recordedPT
, TRUE
);
120 void removeRecordings() {
122 gchar
*file
= g_build_filename(SCRIPTPATH
, "lastExample.wav", NULL
);
125 if ((record
= g_dir_open(RECORDPATH
, 0, NULL
)) != NULL
) {
127 while ((name
= g_dir_read_name(record
)) != NULL
) {
128 if (g_str_has_suffix(name
, ".wav") || g_str_has_suffix(name
, ".Pitch") || g_str_has_suffix(name
, ".PitchTier")) {
129 file
= g_build_filename(RECORDPATH
, name
, NULL
);