Ik heb om de editor maar een scrollwindow gezet.
[sgc.git] / signals.c
blob0b80b6e83ef2d22eb2ad28277ce2d26bd0574ae2
1 #include "sgc.h"
3 gdouble upperRegister = 200.0;
5 void setButtonPlay() {
6 GtkWidget *buttonPlay = glade_xml_get_widget(xml, "buttonPlay");
7 if (treevalid) {
8 gchar *string;
9 gchar *path;
11 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
12 path = g_strjoin(NULL, RECORDPATH, G_DIR_SEPARATOR_S, string, ".wav", NULL);
14 if (g_access(path, F_OK) == 0) {
15 gtk_widget_set_sensitive(buttonPlay, TRUE);
16 } else {
17 gtk_widget_set_sensitive(buttonPlay, FALSE);
19 g_free(path);
20 g_free(string);
21 } else {
22 gtk_widget_set_sensitive(buttonPlay, FALSE);
26 gboolean setButtonsTrue() {
27 GtkWidget *buttonRecord = glade_xml_get_widget(xml, "buttonRecord");
28 GtkWidget *buttonExample = glade_xml_get_widget(xml, "buttonExample");
30 GtkWidget *drawingareaPitch = glade_xml_get_widget(xml, "drawingareaPitch");
31 gchar *feedbackTXT;
32 gchar *contents;
35 gtk_widget_set_sensitive(buttonRecord, TRUE);
36 setButtonPlay();
37 gtk_widget_set_sensitive(buttonExample, TRUE);
39 gtk_widget_queue_draw(drawingareaPitch);
41 feedbackTXT = g_build_filename(SCRIPTPATH, G_DIR_SEPARATOR_S, "feedback.txt", NULL);
43 if (g_file_get_contents(feedbackTXT, &contents, NULL, NULL) == TRUE) {
44 g_debug("Sets label!\n");
45 GtkWidget *label = glade_xml_get_widget(xml, "labelFeedback");
46 gtk_label_set_text(GTK_LABEL(label), contents);
47 g_debug("Label set!\n");
48 g_unlink(feedbackTXT);
50 g_free(feedbackTXT);
52 return FALSE;
55 gboolean setButtonsFalse() {
56 GtkWidget *buttonRecord = glade_xml_get_widget(xml, "buttonRecord");
57 GtkWidget *buttonPlay = glade_xml_get_widget(xml, "buttonPlay");
58 GtkWidget *buttonExample = glade_xml_get_widget(xml, "buttonExample");
59 g_debug("%s welcome!\n", __func__);
61 gtk_widget_set_sensitive(buttonRecord, FALSE);
62 gtk_widget_set_sensitive(buttonPlay, FALSE);
63 gtk_widget_set_sensitive(buttonExample, FALSE);
65 g_debug("%s bye!\n", __func__);
67 return FALSE;
70 void on_buttonRecord_clicked(GtkWidget *widget, gpointer user_data) {
71 if (treevalid) {
72 gchar *string;
73 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
76 if (string == NULL) {
77 GtkWidget *dialog = gtk_message_dialog_new(NULL,
78 GTK_DIALOG_MODAL,
79 GTK_MESSAGE_WARNING,
80 GTK_BUTTONS_OK,
81 "Don't have any (more) tests");
82 gtk_dialog_run (GTK_DIALOG (dialog));
83 gtk_widget_destroy (dialog);
84 /* Nothing to do? */
85 } else {
86 /* Start record Thread */
88 g_debug("%s creates record", __func__);
90 g_thread_create((GThreadFunc)record, NULL, FALSE, NULL);
92 g_debug("%s is done", __func__);
93 g_free(string);
98 void on_buttonExample_clicked(GtkWidget *widget, gpointer user_data) {
99 /* Play Thread */
100 /* Start example Thread */
101 g_thread_create((GThreadFunc)example, widget, FALSE, NULL);
104 void on_buttonPlay_clicked(GtkWidget *widget, gpointer user_data) {
105 /* Play Thread */
106 /* Start play Thread */
107 g_thread_create((GThreadFunc)play, widget, FALSE, NULL);
110 gboolean prev(GtkWidget *previous) {
111 gboolean ret = FALSE;
112 if (treevalid) {
113 /* Code From anchient Sylpheed */
114 GtkTreePath *path;
115 GtkTreeIter prev;
117 path = gtk_tree_model_get_path(GTK_TREE_MODEL(liststore), &mainIter);
119 if ((ret = gtk_tree_path_prev(path)) == TRUE) {
120 gtk_tree_model_get_iter(GTK_TREE_MODEL(liststore), &prev, path);
121 if (previous != NULL) {
122 mainIter = prev;
127 gtk_tree_path_free(path);
131 return ret;
134 gboolean next(GtkWidget *next) {
135 if (treevalid) {
136 if (next != NULL) {
137 return gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore), &mainIter);
138 } else {
139 GtkTreeIter next = mainIter;
140 return gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore), &next);
142 } else {
143 return FALSE;
147 void updateWidgets() {
148 GtkWidget *labelFeedback = glade_xml_get_widget(xml, "labelFeedback");
150 if (treevalid) {
152 gchar *string;
153 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
154 GString *label = g_string_new(string);
155 g_string_prepend(label, "<span size=\"xx-large\">");
156 g_string_append(label, "</span>");
157 gtk_label_set_markup(GTK_LABEL(labelFeedback), label->str);
158 g_string_free(label, TRUE);
160 g_free(string);
161 } else {
162 gtk_label_set_markup(GTK_LABEL(labelFeedback), "");
165 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "buttonRecord"), treevalid);
166 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "buttonExample"), treevalid);
167 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "imagemenuitemSave"), treevalid);
168 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "imagemenuitemSaveAs"), treevalid);
170 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "buttonPrevious"), prev(NULL));
171 gtk_widget_set_sensitive(glade_xml_get_widget(xml, "buttonNext"), next(NULL));
173 setButtonPlay();
175 gtk_widget_queue_draw(glade_xml_get_widget(xml, "drawingareaPitch"));
178 void on_Save(GtkWidget *chooser, gpointer user_data) {
179 fileSave(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)));
182 void on_dialogAdd_close(GtkWidget *button, gpointer user_data) {
183 GtkWidget *buttonAdd = glade_xml_get_widget(xml, "buttonAdd");
184 gtk_widget_hide(gtk_widget_get_toplevel(button));
185 gtk_widget_grab_focus(buttonAdd);
188 void on_menuitemVoice_activate(GtkWidget *widget, gpointer user_data) {
189 const gchar *name = gtk_widget_get_name(widget);
190 GtkWidget *drawingareaPitch = glade_xml_get_widget(xml, "drawingareaPitch");
191 if (g_str_equal(name, "menuitemVoice_Male_Low") == TRUE) upperRegister = 150.0;
192 if (g_str_equal(name, "menuitemVoice_Male") == TRUE) upperRegister = 200.0;
193 if (g_str_equal(name, "menuitemVoice_Female") == TRUE) upperRegister = 300.0;
194 if (g_str_equal(name, "menuitemVoice_Child") == TRUE) upperRegister = 450.0;
195 gtk_widget_queue_draw(drawingareaPitch);
198 void paint (GtkWidget *widget, GdkEventExpose *eev, gpointer data) {
199 if (treevalid) {
200 gchar *string;
201 gtk_tree_model_get(GTK_TREE_MODEL(liststore), &mainIter, COL_TEXT, &string, -1);
203 if (string != NULL) {
204 cairo_t *cr;
205 GString *filename = g_string_sized_new (200);
206 GString *cmd = g_string_sized_new (200);
207 GString *recordedPT = g_string_sized_new(100);
210 g_string_printf(filename, "%s%s%s-%0.f.PitchTier", PITCHPATH, G_DIR_SEPARATOR_S, string, upperRegister);
211 g_string_printf(recordedPT, "%s%s%s.PitchTier", RECORDPATH, G_DIR_SEPARATOR_S, string);
213 if (g_access(filename->str, F_OK) == -1) {
214 /* Eigenlijk wil je de system ranzigheid vervangen door een werkende versie van dit,
215 * maar eigenlijk MOET je gewoon de praat scripts naar C omzetten ;)
216 * gint exit_status;
217 GError *err = NULL;
218 gchar *argv[4];
219 gchar *upper = g_malloc(5);
220 g_ascii_dtostr(upper, 5, upperRegister);
221 argv[0] = NULL;
222 argv[1] = testList[intTestCounter];
223 argv[2] = upper;
224 argv[3] = NULL;
226 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);*/
227 g_chdir(SCRIPTPATH);
228 g_string_printf(cmd, "%s DrawToneContour.praat %s %0.f", PRAATBIN, string, upperRegister);
229 g_debug("%s", cmd->str);
230 system(cmd->str);
231 g_chdir("..");
234 cr = gdk_cairo_create (widget->window);
235 cairo_set_line_width (cr, 1);
236 cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
237 CAIRO_FONT_WEIGHT_BOLD);
240 if (g_access(filename->str, F_OK) == 0) {
241 cairo_move_to (cr, 5, 15);
242 cairo_set_source_rgb (cr, 0,0,0);
243 cairo_show_text (cr, "Reference Pitch");
246 drawPitchTier(cr, filename->str,
247 widget->allocation.width,
248 widget->allocation.height, upperRegister + 100.0);
251 //g_debug("%s", recordedPT->str);
253 if (g_access(recordedPT->str, F_OK) == 0) {
254 cairo_move_to (cr, 15, 30);
255 cairo_set_source_rgb (cr, 1,0,0);
256 cairo_show_text (cr, "Your Pitch");
258 drawPitchTier(cr, recordedPT->str,
259 widget->allocation.width,
260 widget->allocation.height, upperRegister + 100.0);
263 g_string_free(recordedPT, TRUE);
264 cairo_destroy (cr);
265 g_string_free(filename, TRUE);
267 g_free(string);