It's 2020...
[terminatorX.git] / src / tX_ui_callbacks.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2020  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 }
77
78 void
79 on_pref_reset_clicked                  (GtkButton       *button,
80                                         gpointer         user_data)
81 {
82         GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_toplevel(opt_dialog)), 
83                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
84                 "Loose all your settings and set default values?");
85         
86         int res=gtk_dialog_run(GTK_DIALOG(dialog));
87         gtk_widget_destroy(dialog);
88                 
89         if (res!=GTK_RESPONSE_YES) {
90                 return;
91         }
92         
93         set_global_defaults();
94         init_tx_options(opt_dialog);
95 }
96
97 void
98 on_del_mode_cancel_clicked             (GtkButton       *button,
99                                         gpointer         user_data)
100 {
101         gtk_widget_destroy(del_dialog);
102         del_dialog=NULL;
103 }
104
105
106 void
107 on_del_mode_ok_clicked                 (GtkButton       *button,
108                                         gpointer         user_data)
109 {
110         tX_sequencer::del_mode mode;
111         
112         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "all_events")))) {
113                 mode=tX_sequencer::DELETE_ALL;
114         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "upto_current")))) {
115                 mode=tX_sequencer::DELETE_UPTO_CURRENT;         
116         } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(del_dialog, "from_current")))) {
117                 mode=tX_sequencer::DELETE_FROM_CURRENT;         
118         } else {
119                 tX_error("Invalid tX_sequencer::del_mode selected.");
120                 return;
121         }
122         
123         switch(menu_del_mode) {
124                 case ALL_EVENTS_ALL_TURNTABLES:
125                         sequencer.delete_all_events(mode);
126                         break;
127                 case ALL_EVENTS_FOR_TURNTABLE:
128                         sequencer.delete_all_events_for_vtt(del_vtt, mode);
129                         break;
130                 case ALL_EVENTS_FOR_SP:
131                         sequencer.delete_all_events_for_sp(del_sp, mode);
132                         break;
133                 default:
134                         tX_error("Invalid del_mode");
135         }
136         
137         gtk_widget_destroy(del_dialog);
138         del_dialog=NULL;
139 }
140
141 void
142 color_clicked                          (GtkButton       *button,
143                                         gpointer         user_data)
144 {
145         GdkRGBA p;
146         GtkWidget *dialog=create_tX_color_chooser(gtk_widget_get_toplevel(GTK_WIDGET(button)));
147         GtkWidget *sel=lookup_widget(dialog, "tX_color_chooser");
148         g_object_set_data(G_OBJECT(dialog), "Button", button);
149         
150         gdk_rgba_parse(&p, (const char *) g_object_get_data(G_OBJECT(button), "Color"));
151         gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(sel), &p);
152         gtk_widget_show(dialog);
153 }
154
155 void
156 color_response (GtkDialog *dialog, gint       response_id, gpointer   user_data)
157 {
158         if (response_id == GTK_RESPONSE_OK) {
159                 char tmp[128];
160                 GtkWidget *c_but=(GtkWidget *) g_object_get_data(G_OBJECT(dialog), "Button");
161                 char *col = (char *) g_object_get_data(G_OBJECT(c_but), "Color");
162                 GdkRGBA p;
163           
164                 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &p);
165                 sprintf(col, "#%02X%02X%02X", (int) (p.red * 255.0),  (int) (p.green * 255.0), (int) (p.blue * 255.0));
166                 sprintf(tmp, "<span foreground=\"%s\"><b>%s</b></span>", col, col);
167                 gtk_label_set_markup(GTK_LABEL(gtk_container_get_children(GTK_CONTAINER(c_but))->data), tmp);
168   }
169
170   gtk_widget_hide (GTK_WIDGET (dialog));
171   gtk_widget_destroy (GTK_WIDGET (dialog));
172 }