1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2020 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <ags/X/editor/ags_notation_toolbar_callbacks.h>
21 
22 #include <ags/X/ags_notation_editor.h>
23 
24 #include <math.h>
25 
26 void
ags_notation_toolbar_position_callback(GtkToggleToolButton * toggle_button,AgsNotationToolbar * notation_toolbar)27 ags_notation_toolbar_position_callback(GtkToggleToolButton *toggle_button, AgsNotationToolbar *notation_toolbar)
28 {
29   if(toggle_button == notation_toolbar->selected_edit_mode){
30     if(!gtk_toggle_tool_button_get_active(toggle_button)){
31       gtk_toggle_tool_button_set_active(toggle_button, TRUE);
32     }
33   }else if(gtk_toggle_tool_button_get_active(toggle_button)){
34     GtkToggleToolButton *old_selected_edit_mode;
35 
36     old_selected_edit_mode = notation_toolbar->selected_edit_mode;
37     notation_toolbar->selected_edit_mode = toggle_button;
38     gtk_toggle_tool_button_set_active(old_selected_edit_mode, FALSE);
39   }
40 }
41 
42 void
ags_notation_toolbar_edit_callback(GtkToggleToolButton * toggle_button,AgsNotationToolbar * notation_toolbar)43 ags_notation_toolbar_edit_callback(GtkToggleToolButton *toggle_button, AgsNotationToolbar *notation_toolbar)
44 {
45   if(toggle_button == notation_toolbar->selected_edit_mode){
46     if(!gtk_toggle_tool_button_get_active(toggle_button)){
47       gtk_toggle_tool_button_set_active(toggle_button, TRUE);
48     }
49   }else if(gtk_toggle_tool_button_get_active(toggle_button)){
50     GtkToggleToolButton *old_selected_edit_mode;
51 
52     old_selected_edit_mode = notation_toolbar->selected_edit_mode;
53     notation_toolbar->selected_edit_mode = toggle_button;
54     gtk_toggle_tool_button_set_active(old_selected_edit_mode, FALSE);
55   }
56 }
57 
58 void
ags_notation_toolbar_clear_callback(GtkToggleToolButton * toggle_button,AgsNotationToolbar * notation_toolbar)59 ags_notation_toolbar_clear_callback(GtkToggleToolButton *toggle_button, AgsNotationToolbar *notation_toolbar)
60 {
61   if(toggle_button == notation_toolbar->selected_edit_mode){
62     if(!gtk_toggle_tool_button_get_active(toggle_button)){
63       gtk_toggle_tool_button_set_active(toggle_button, TRUE);
64     }
65   }else if(gtk_toggle_tool_button_get_active(toggle_button)){
66     GtkToggleToolButton *old_selected_edit_mode;
67 
68     old_selected_edit_mode = notation_toolbar->selected_edit_mode;
69     notation_toolbar->selected_edit_mode = toggle_button;
70     gtk_toggle_tool_button_set_active(old_selected_edit_mode, FALSE);
71   }
72 }
73 
74 void
ags_notation_toolbar_select_callback(GtkToggleToolButton * toggle_button,AgsNotationToolbar * notation_toolbar)75 ags_notation_toolbar_select_callback(GtkToggleToolButton *toggle_button, AgsNotationToolbar *notation_toolbar)
76 {
77   if(toggle_button == notation_toolbar->selected_edit_mode){
78     if(!gtk_toggle_tool_button_get_active(toggle_button)){
79       gtk_toggle_tool_button_set_active(toggle_button, TRUE);
80     }
81   }else if(gtk_toggle_tool_button_get_active(toggle_button)){
82     GtkToggleToolButton *old_selected_edit_mode;
83 
84     old_selected_edit_mode = notation_toolbar->selected_edit_mode;
85     notation_toolbar->selected_edit_mode = toggle_button;
86     gtk_toggle_tool_button_set_active(old_selected_edit_mode, FALSE);
87   }
88 }
89 
90 void
ags_notation_toolbar_copy_or_cut_callback(GtkWidget * widget,AgsNotationToolbar * notation_toolbar)91 ags_notation_toolbar_copy_or_cut_callback(GtkWidget *widget, AgsNotationToolbar *notation_toolbar)
92 {
93   AgsNotationEditor *notation_editor;
94 
95   /* add notation to root node */
96   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor(GTK_WIDGET(notation_toolbar),
97 								  AGS_TYPE_NOTATION_EDITOR);
98 
99   if(widget == (GtkWidget *) notation_toolbar->copy){
100     ags_notation_editor_copy(notation_editor);
101   }else{
102     ags_notation_editor_cut(notation_editor);
103   }
104 }
105 
106 void
ags_notation_toolbar_paste_callback(GtkWidget * widget,AgsNotationToolbar * notation_toolbar)107 ags_notation_toolbar_paste_callback(GtkWidget *widget, AgsNotationToolbar *notation_toolbar)
108 {
109   AgsNotationEditor *notation_editor;
110 
111   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor(GTK_WIDGET(notation_toolbar), AGS_TYPE_NOTATION_EDITOR);
112 
113   ags_notation_editor_paste(notation_editor);
114 }
115 
116 void
ags_notation_toolbar_match_audio_channel_callback(GtkWidget * widget,AgsNotationToolbar * notation_toolbar)117 ags_notation_toolbar_match_audio_channel_callback(GtkWidget *widget, AgsNotationToolbar *notation_toolbar)
118 {
119   AgsNotationEditor *notation_editor;
120 
121   notation_editor = AGS_NOTATION_EDITOR(gtk_widget_get_ancestor(GTK_WIDGET(notation_toolbar),
122 								AGS_TYPE_NOTATION_EDITOR));
123 
124   if(gtk_check_menu_item_get_active((GtkCheckMenuItem *) widget)){
125     notation_editor->flags |= AGS_NOTATION_EDITOR_PASTE_MATCH_AUDIO_CHANNEL;
126   }else{
127     notation_editor->flags &= (~AGS_NOTATION_EDITOR_PASTE_MATCH_AUDIO_CHANNEL);
128   }
129 }
130 
131 void
ags_notation_toolbar_no_duplicates_callback(GtkWidget * widget,AgsNotationToolbar * notation_toolbar)132 ags_notation_toolbar_no_duplicates_callback(GtkWidget *widget, AgsNotationToolbar *notation_toolbar)
133 {
134   AgsNotationEditor *notation_editor;
135 
136   notation_editor = AGS_NOTATION_EDITOR(gtk_widget_get_ancestor(GTK_WIDGET(notation_toolbar),
137 								AGS_TYPE_NOTATION_EDITOR));
138 
139   if(gtk_check_menu_item_get_active((GtkCheckMenuItem *) widget)){
140     notation_editor->flags |= AGS_NOTATION_EDITOR_PASTE_NO_DUPLICATES;
141   }else{
142     notation_editor->flags &= (~AGS_NOTATION_EDITOR_PASTE_NO_DUPLICATES);
143   }
144 }
145 
146 void
ags_notation_toolbar_invert_callback(GtkWidget * widget,AgsNotationToolbar * notation_toolbar)147 ags_notation_toolbar_invert_callback(GtkWidget *widget, AgsNotationToolbar *notation_toolbar)
148 {
149   AgsNotationEditor *notation_editor;
150 
151   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor(GTK_WIDGET(notation_toolbar), AGS_TYPE_NOTATION_EDITOR);
152 
153   ags_notation_editor_invert(notation_editor);
154 }
155 
156 void
ags_notation_toolbar_tool_popup_move_note_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)157 ags_notation_toolbar_tool_popup_move_note_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
158 {
159   gtk_widget_show_all((GtkWidget *) notation_toolbar->move_note);
160 }
161 
162 void
ags_notation_toolbar_tool_popup_crop_note_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)163 ags_notation_toolbar_tool_popup_crop_note_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
164 {
165   gtk_widget_show_all((GtkWidget *) notation_toolbar->crop_note);
166 }
167 
168 void
ags_notation_toolbar_tool_popup_select_note_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)169 ags_notation_toolbar_tool_popup_select_note_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
170 {
171   gtk_widget_show_all((GtkWidget *) notation_toolbar->select_note);
172 }
173 
174 void
ags_notation_toolbar_tool_popup_position_cursor_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)175 ags_notation_toolbar_tool_popup_position_cursor_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
176 {
177   gtk_widget_show_all((GtkWidget *) notation_toolbar->position_notation_cursor);
178 }
179 
180 void
ags_notation_toolbar_tool_popup_enable_all_lines_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)181 ags_notation_toolbar_tool_popup_enable_all_lines_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
182 {
183   AgsNotationEditor *notation_editor;
184   AgsNotebook *notebook;
185 
186   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor((GtkWidget *) notation_toolbar,
187 								  AGS_TYPE_NOTATION_EDITOR);
188 
189   /* enable */
190   notebook = notation_editor->notebook;
191 
192   if(notebook != NULL){
193     GList *start_list, *list;
194 
195     list =
196       start_list = g_list_copy(notebook->tab);
197 
198     while(list != NULL){
199       gtk_toggle_button_set_active(AGS_NOTEBOOK_TAB(list->data)->toggle,
200 				   TRUE);
201 
202       list = list->next;
203     }
204 
205     g_list_free(start_list);
206   }
207 }
208 
209 void
ags_notation_toolbar_tool_popup_disable_all_lines_callback(GtkWidget * item,AgsNotationToolbar * notation_toolbar)210 ags_notation_toolbar_tool_popup_disable_all_lines_callback(GtkWidget *item, AgsNotationToolbar *notation_toolbar)
211 {
212   AgsNotationEditor *notation_editor;
213   AgsNotebook *notebook;
214 
215   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor((GtkWidget *) notation_toolbar,
216 								  AGS_TYPE_NOTATION_EDITOR);
217 
218   /* disable */
219   notebook = notation_editor->notebook;
220 
221   if(notebook != NULL){
222     GList *start_list, *list;
223 
224     list =
225       start_list = g_list_copy(notebook->tab);
226 
227     while(list != NULL){
228       gtk_toggle_button_set_active(AGS_NOTEBOOK_TAB(list->data)->toggle,
229 				   FALSE);
230 
231       list = list->next;
232     }
233 
234     g_list_free(start_list);
235   }
236 }
237 
238 void
ags_notation_toolbar_zoom_callback(GtkComboBox * combo_box,AgsNotationToolbar * notation_toolbar)239 ags_notation_toolbar_zoom_callback(GtkComboBox *combo_box, AgsNotationToolbar *notation_toolbar)
240 {
241   AgsNotationEditor *notation_editor;
242   AgsNotationEdit *notation_edit;
243 
244   gdouble old_zoom_factor;
245   gdouble zoom_factor, zoom;
246 
247   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor((GtkWidget *) notation_toolbar,
248 								  AGS_TYPE_NOTATION_EDITOR);
249 
250   notation_edit = notation_editor->notation_edit;
251 
252   /* zoom */
253   old_zoom_factor = exp2(6.0 - (double) notation_toolbar->zoom_history);
254 
255   notation_toolbar->zoom_history = gtk_combo_box_get_active((GtkComboBox *) notation_toolbar->zoom);
256 
257   zoom_factor = exp2(6.0 - (double) notation_toolbar->zoom_history);
258   zoom = exp2((double) gtk_combo_box_get_active((GtkComboBox *) notation_toolbar->zoom) - 2.0);
259 
260   /* reset notation edit */
261   ags_notation_edit_reset_hscrollbar(notation_edit);
262 
263   gtk_range_set_value(GTK_RANGE(notation_edit->hscrollbar),
264 		      gtk_range_get_value(GTK_RANGE(notation_edit->hscrollbar)) * old_zoom_factor / zoom_factor);
265 
266   gtk_widget_queue_draw((GtkWidget *) notation_edit);
267 
268   /* reset ruler */
269   notation_edit->ruler->factor = zoom_factor;
270   notation_edit->ruler->precision = zoom;
271   notation_edit->ruler->scale_precision = 1.0 / zoom;
272 
273   gtk_widget_queue_draw((GtkWidget *) notation_edit->ruler);
274 }
275 
276 void
ags_notation_toolbar_opacity_callback(GtkSpinButton * spin_button,AgsNotationToolbar * notation_toolbar)277 ags_notation_toolbar_opacity_callback(GtkSpinButton *spin_button, AgsNotationToolbar *notation_toolbar)
278 {
279   AgsNotationEditor *notation_editor;
280 
281   notation_editor = (AgsNotationEditor *) gtk_widget_get_ancestor((GtkWidget *) notation_toolbar,
282 								  AGS_TYPE_NOTATION_EDITOR);
283 
284   gtk_widget_queue_draw((GtkWidget *) notation_editor->notation_edit);
285 }
286