c774b7e9dd75de82b44e9f4965ef726b8cffbf43
[terminatorX.git] / src / tX_ui_callbacks.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2016  Alexander K├Ânig
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 */    
19
20 #ifdef HAVE_CONFIG_H
21 #  include <config.h>
22 #endif
23
24 #include <gtk/gtk.h>
25
26 #include "tX_ui_callbacks.h"
27 #include "tX_ui_interface.h"
28 #include "tX_ui_support.h"
29 #include "tX_dialog.h"
30 #include "tX_global.h"
31 #include "tX_mastergui.h"
32 #include "tX_sequencer.h"
33
34 void
35 on_pref_cancel_clicked                 (GtkButton       *button,
36                                         gpointer         user_data)
37 {
38         gtk_widget_destroy(opt_dialog);
39 }
40
41
42 void
43 on_pref_apply_clicked                  (GtkButton       *button,
44                                         gpointer         user_data)
45 {
46         apply_options(opt_dialog);      
47 }
48
49
50 void
51 on_pref_ok_clicked                     (GtkButton       *button,
52                                         gpointer         user_data)
53 {
54         apply_options(opt_dialog);
55         gtk_widget_destroy(opt_dialog);
56 }
57
58
59 void
60 on_tx_options_destroy                  (GObject       *object,
61                                         gpointer         user_data)
62 {
63         opt_dialog=NULL;
64 }
65
66
67 void
68 on_alsa_buffer_time_value_changed      (GtkRange        *range,
69                                         gpointer         user_data)
70 {
71         GtkAdjustment *buffer_time=gtk_range_get_adjustment(GTK_RANGE(user_data));
72         GtkAdjustment *period_time=gtk_range_get_adjustment(GTK_RANGE(range));
73
74
75         gtk_adjustment_set_upper(period_time, gtk_adjustment_get_value(buffer_time));
76         gtk_adjustment_changed(period_time);
77 }
78
79 void
80 on_pref_reset_clicked                  (GtkButton       *button,
81                                         gpointer         user_data)
82 {
83         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_toplevel(opt_dialog)), 
84                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
85                 "Loose all your settings and set default values?");
86         
87         int res=gtk_dialog_run(GTK_DIALOG(dialog));
88         gtk_widget_destroy(dialog);
89                 
90         if (res!=GTK_RESPONSE_YES) {
91                 return;
92         }
93         
94         set_global_defaults();
95         init_tx_options(opt_dialog);
96 }
97
98 void
99 on_del_mode_cancel_clicked             (GtkButton       *button,
100                                         gpointer         user_data)
101 {
102         gtk_widget_destroy(del_dialog);
103         del_dialog=NULL;
104 }
105
106
107 void
108 on_del_mode_ok_clicked                 (GtkButton       *button,
109                                         gpointer         user_data)
110 {
111         tX_sequencer::del_mode mode;
112         
113         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "all_events")))) {
114                 mode=tX_sequencer::DELETE_ALL;
115         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "upto_current")))) {
116                 mode=tX_sequencer::DELETE_UPTO_CURRENT;         
117         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "from_current")))) {
118                 mode=tX_sequencer::DELETE_FROM_CURRENT;         
119         } else {
120                 tX_error("Invalid tX_sequencer::del_mode selected.");
121                 return;
122         }
123         
124         switch(menu_del_mode) {
125                 case ALL_EVENTS_ALL_TURNTABLES:
126                         sequencer.delete_all_events(mode);
127                         break;
128                 case ALL_EVENTS_FOR_TURNTABLE:
129                         sequencer.delete_all_events_for_vtt(del_vtt, mode);
130                         break;
131                 case ALL_EVENTS_FOR_SP:
132                         sequencer.delete_all_events_for_sp(del_sp, mode);
133                         break;
134                 default:
135                         tX_error("Invalid del_mode");
136         }
137         
138         gtk_widget_destroy(del_dialog);
139         del_dialog=NULL;
140 }
141
142 void
143 color_clicked                          (GtkButton       *button,
144                                         gpointer         user_data)
145 {
146         GdkRGBA p;
147         GtkWidget *dialog=create_tX_color_chooser(gtk_widget_get_toplevel(GTK_WIDGET(button)));
148         GtkWidget *sel=lookup_widget(dialog, "tX_color_chooser");
149         g_object_set_data(G_OBJECT(dialog), "Button", button);
150         
151         gdk_rgba_parse(&p, (const char *) g_object_get_data(G_OBJECT(button), "Color"));
152         gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(sel), &p);
153         gtk_widget_show(dialog);
154 }
155
156 void
157 color_response (GtkDialog *dialog, gint       response_id, gpointer   user_data)
158 {
159   if (response_id == GTK_RESPONSE_OK) {
160           char tmp[128];
161           char col[16];
162           GdkRGBA p;
163           
164           GtkWidget *c_but=(GtkWidget *) g_object_get_data(G_OBJECT(dialog), "Button");
165       gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &p);
166       sprintf(col, "#%02X%02X%02X", (int) (p.red * 256.0),  (int) (p.green * 256.0), (int) (p.blue * 256.0));
167       
168       sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", col, col);
169       gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(c_but))->data), tmp);
170   }
171
172   gtk_widget_hide (GTK_WIDGET (dialog));
173   gtk_widget_destroy (GTK_WIDGET (dialog));
174 }