1 #include "singleword.h"
2 #include <gdk/gdkkeysyms.h>
8 void run_script(gchar
*pinyin
) {
9 if (strlen(pinyin
) > 1) {
13 active
= strdup(pinyin
);
15 GString
*cmd
= g_string_sized_new (200);
16 g_string_printf(cmd
, "DrawToneContour.praat %s %0.f", pinyin
, upperRegister
);
18 praat_executeScriptFromFileNameWithArguments(cmd
->str
);
19 Melder_clearError(NULL
);
21 g_string_free(cmd
, TRUE
);
25 void entryPinyin_key_release_event_cb(GtkWidget
*widget
, GdkEventKey
*event
, gpointer user_data
) {
26 if (event
!= NULL
&& event
->keyval
== GDK_Return
) {
27 gchar
*pinyin
= g_strdup(gtk_entry_get_text(GTK_ENTRY(widget
)));
29 g_ascii_strdown(pinyin
, -1);
30 g_strcanon(pinyin
, "#012345abcdefghijklmnopqrstuvwxyz\n", '-');
32 gtk_entry_set_text(GTK_ENTRY(widget
), pinyin
);
37 gtk_widget_queue_draw(glade_xml_get_widget(xml
, "drawingareaPitch"));
41 void buttonRecord_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
42 g_thread_create((GThreadFunc
)record
, NULL
, FALSE
, NULL
);
45 void buttonPlay_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
46 g_thread_create((GThreadFunc
)play
, NULL
, FALSE
, NULL
);
49 void buttonHum_clicked_cb(GtkWidget
*widget
, gpointer user_data
) {
51 GString
*filename
= g_string_sized_new (200);
52 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, active
, upperRegister
);
54 if (g_access(filename
->str
, F_OK
) == -1) run_script(active
);
56 g_thread_create((GThreadFunc
)playHum
, NULL
, FALSE
, NULL
);
58 g_string_free(filename
, TRUE
);
62 void paint (GtkWidget
*widget
, GdkEventExpose
*eev
, gpointer data
) {
65 GString
*filename
= g_string_sized_new (200);
66 GString
*recordedPT
= g_string_sized_new (200);
68 g_string_printf(filename
, "%s%s%s-%0.f.PitchTier", PITCHPATH
, G_DIR_SEPARATOR_S
, active
, upperRegister
);
69 g_string_printf(recordedPT
, "%s%s%s.PitchTier", RECORDPATH
, G_DIR_SEPARATOR_S
, "singleword.wav");
71 if (g_access(filename
->str
, F_OK
) == -1) run_script(active
);
73 cr
= gdk_cairo_create (widget
->window
);
74 cairo_set_line_width (cr
, 1);
75 cairo_select_font_face (cr
, "Sans", CAIRO_FONT_SLANT_NORMAL
, CAIRO_FONT_WEIGHT_BOLD
);
76 if (g_access(filename
->str
, F_OK
) == 0) {
77 cairo_move_to (cr
, 5, 15);
78 cairo_set_source_rgb (cr
, 0,0,0);
79 cairo_show_text (cr
, _("Reference Pitch"));
82 drawPitchTier(cr
, filename
->str
,
83 widget
->allocation
.width
,
84 widget
->allocation
.height
, upperRegister
+ 100.0);
86 g_string_free(filename
, TRUE
);
88 if (g_access(recordedPT
->str
, F_OK
) == 0) {
89 cairo_move_to (cr
, 15, 30);
90 cairo_set_source_rgb (cr
, 1,0,0);
91 cairo_show_text (cr
, _("Your Pitch"));
93 drawPitchTier(cr
, recordedPT
->str
,
94 widget
->allocation
.width
,
95 widget
->allocation
.height
, upperRegister
+ 100.0);
98 g_string_free(recordedPT
, TRUE
);