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_envelope_editor_callbacks.h>
21 
22 #include <ags/X/ags_window.h>
23 #include <ags/X/ags_machine.h>
24 
25 #include <ags/X/editor/ags_envelope_dialog.h>
26 
27 #include <ags/i18n.h>
28 
29 void
ags_envelope_editor_preset_callback(GtkWidget * combo_box,AgsEnvelopeEditor * envelope_editor)30 ags_envelope_editor_preset_callback(GtkWidget *combo_box,
31 				    AgsEnvelopeEditor *envelope_editor)
32 {
33   ags_envelope_editor_reset_control(envelope_editor);
34 }
35 
36 void
ags_envelope_editor_preset_add_callback(GtkWidget * button,AgsEnvelopeEditor * envelope_editor)37 ags_envelope_editor_preset_add_callback(GtkWidget *button,
38 					AgsEnvelopeEditor *envelope_editor)
39 {
40   GtkDialog *dialog;
41   GtkEntry *entry;
42 
43   if(envelope_editor->rename != NULL){
44     return;
45   }
46 
47   envelope_editor->rename =
48     dialog = (GtkDialog *) gtk_dialog_new_with_buttons(i18n("preset name"),
49 						       (GtkWindow *) gtk_widget_get_toplevel(GTK_WIDGET(envelope_editor)),
50 						       GTK_DIALOG_DESTROY_WITH_PARENT,
51 						       i18n("_OK"),
52 						       GTK_RESPONSE_ACCEPT,
53 						       i18n("_Cancel"),
54 						       GTK_RESPONSE_REJECT,
55 						       NULL);
56 
57   entry = (GtkEntry *) gtk_entry_new();
58   gtk_box_pack_start((GtkBox *) gtk_dialog_get_content_area(dialog),
59 		     (GtkWidget *) entry,
60 		     FALSE, FALSE,
61 		     0);
62 
63   gtk_widget_show_all((GtkWidget *) dialog);
64 
65   g_signal_connect((GObject *) dialog, "response",
66 		   G_CALLBACK(ags_envelope_editor_preset_rename_response_callback), (gpointer) envelope_editor);
67 }
68 
69 void
ags_envelope_editor_preset_remove_callback(GtkWidget * button,AgsEnvelopeEditor * envelope_editor)70 ags_envelope_editor_preset_remove_callback(GtkWidget *button,
71 					   AgsEnvelopeEditor *envelope_editor)
72 {
73   AgsEnvelopeDialog *envelope_dialog;
74 
75   envelope_dialog = (AgsEnvelopeDialog *) gtk_widget_get_ancestor((GtkWidget *) envelope_editor,
76 								  AGS_TYPE_ENVELOPE_DIALOG);
77 
78   /* remove preset */
79   ags_envelope_editor_remove_preset(envelope_editor,
80 				    gtk_combo_box_get_active(GTK_COMBO_BOX(envelope_editor->preset)));
81 
82   /* load preset */
83   ags_envelope_dialog_load_preset(envelope_dialog);
84 }
85 
86 void
ags_envelope_editor_preset_rename_response_callback(GtkWidget * widget,gint response,AgsEnvelopeEditor * envelope_editor)87 ags_envelope_editor_preset_rename_response_callback(GtkWidget *widget, gint response,
88 						    AgsEnvelopeEditor *envelope_editor)
89 {
90   if(response == GTK_RESPONSE_ACCEPT){
91     AgsEnvelopeDialog *envelope_dialog;
92 
93     GList *start_list;
94 
95     gchar *text;
96 
97     envelope_dialog = (AgsEnvelopeDialog *) gtk_widget_get_ancestor((GtkWidget *) envelope_editor,
98 								    AGS_TYPE_ENVELOPE_DIALOG);
99 
100     /* get name */
101     start_list = gtk_container_get_children((GtkContainer *) gtk_dialog_get_content_area(GTK_DIALOG(widget)));
102     text = gtk_editable_get_chars(GTK_EDITABLE(start_list->data),
103 				  0, -1);
104 
105     g_list_free(start_list);
106 
107     /* add preset */
108     ags_envelope_editor_add_preset(envelope_editor,
109 				   text);
110 
111     /* load preset */
112     ags_envelope_dialog_load_preset(envelope_dialog);
113   }
114 
115   envelope_editor->rename = NULL;
116   gtk_widget_destroy(widget);
117 
118   return;
119 }
120 
121 void
ags_envelope_editor_attack_x_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)122 ags_envelope_editor_attack_x_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
123 {
124   AgsPreset *preset;
125 
126   AgsComplex *val;
127 
128   gdouble attack_x;
129 
130   GValue value = G_VALUE_INIT;
131 
132   GError *error;
133 
134   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
135     return;
136   }
137 
138   /* get preset */
139   preset = ags_envelope_editor_get_active_preset(envelope_editor);
140 
141   if(preset == NULL){
142     return;
143   }
144 
145   /* get value and update preset */
146   attack_x = gtk_range_get_value((GtkRange *) range);
147 
148   g_value_init(&value,
149 	       AGS_TYPE_COMPLEX);
150 
151   error = NULL;
152   ags_preset_get_parameter(preset,
153 			   "attack", &value,
154 			   &error);
155 
156   if(error != NULL){
157     g_message("%s", error->message);
158 
159     g_error_free(error);
160 
161     return;
162   }
163 
164   val = (AgsComplex *) g_value_get_boxed(&value);
165 
166   /* add parameter */
167   val[0].real = attack_x;
168 
169   ags_preset_add_parameter(preset,
170 			   "attack", &value);
171 
172   /* plot */
173   ags_envelope_editor_plot(envelope_editor);
174 }
175 
176 void
ags_envelope_editor_attack_y_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)177 ags_envelope_editor_attack_y_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
178 {
179   AgsPreset *preset;
180 
181   AgsComplex *val;
182 
183   gdouble attack_y;
184 
185   GValue value = G_VALUE_INIT;
186 
187   GError *error;
188 
189   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
190     return;
191   }
192 
193   /* get preset */
194   preset = ags_envelope_editor_get_active_preset(envelope_editor);
195 
196   if(preset == NULL){
197     return;
198   }
199 
200   /* get value and update preset */
201   attack_y = gtk_range_get_value((GtkRange *) range);
202 
203   g_value_init(&value,
204 	       AGS_TYPE_COMPLEX);
205 
206   error = NULL;
207   ags_preset_get_parameter(preset,
208 			   "attack", &value,
209 			   &error);
210 
211   if(error != NULL){
212     g_message("%s", error->message);
213 
214     g_error_free(error);
215 
216     return;
217   }
218 
219   val = (AgsComplex *) g_value_get_boxed(&value);
220 
221   /* add parameter */
222   val[0].imag = attack_y;
223 
224   ags_preset_add_parameter(preset,
225 			   "attack", &value);
226 
227   /* plot */
228   ags_envelope_editor_plot(envelope_editor);
229 }
230 
231 void
ags_envelope_editor_decay_x_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)232 ags_envelope_editor_decay_x_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
233 {
234   AgsPreset *preset;
235 
236   AgsComplex *val;
237 
238   gdouble decay_x;
239 
240   GValue value = G_VALUE_INIT;
241 
242   GError *error;
243 
244   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
245     return;
246   }
247 
248   /* get preset */
249   preset = ags_envelope_editor_get_active_preset(envelope_editor);
250 
251   if(preset == NULL){
252     return;
253   }
254 
255   /* get value and update preset */
256   decay_x = gtk_range_get_value((GtkRange *) range);
257 
258   g_value_init(&value,
259 	       AGS_TYPE_COMPLEX);
260 
261   error = NULL;
262   ags_preset_get_parameter(preset,
263 			   "decay", &value,
264 			   &error);
265 
266   if(error != NULL){
267     g_message("%s", error->message);
268 
269     g_error_free(error);
270 
271     return;
272   }
273 
274   val = (AgsComplex *) g_value_get_boxed(&value);
275 
276   /* add parameter */
277   val[0].real = decay_x;
278 
279   ags_preset_add_parameter(preset,
280 			   "decay", &value);
281 
282   /* plot */
283   ags_envelope_editor_plot(envelope_editor);
284 }
285 
286 void
ags_envelope_editor_decay_y_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)287 ags_envelope_editor_decay_y_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
288 {
289   AgsPreset *preset;
290 
291   AgsComplex *val;
292 
293   gdouble decay_y;
294 
295   GValue value = G_VALUE_INIT;
296 
297   GError *error;
298 
299   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
300     return;
301   }
302 
303   /* get preset */
304   preset = ags_envelope_editor_get_active_preset(envelope_editor);
305 
306   if(preset == NULL){
307     return;
308   }
309 
310   /* get value and update preset */
311   decay_y = gtk_range_get_value((GtkRange *) range);
312 
313   g_value_init(&value,
314 	       AGS_TYPE_COMPLEX);
315 
316   error = NULL;
317   ags_preset_get_parameter(preset,
318 			   "decay", &value,
319 			   &error);
320 
321   if(error != NULL){
322     g_message("%s", error->message);
323 
324     g_error_free(error);
325 
326     return;
327   }
328 
329   val = (AgsComplex *) g_value_get_boxed(&value);
330 
331   /* add parameter */
332   val[0].imag = decay_y;
333 
334   ags_preset_add_parameter(preset,
335 			   "decay", &value);
336 
337   /* plot */
338   ags_envelope_editor_plot(envelope_editor);
339 }
340 
341 void
ags_envelope_editor_sustain_x_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)342 ags_envelope_editor_sustain_x_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
343 {
344   AgsPreset *preset;
345 
346   AgsComplex *val;
347 
348   gdouble sustain_x;
349 
350   GValue value = G_VALUE_INIT;
351 
352   GError *error;
353 
354   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
355     return;
356   }
357 
358   /* get preset */
359   preset = ags_envelope_editor_get_active_preset(envelope_editor);
360 
361   if(preset == NULL){
362     return;
363   }
364 
365   /* get value and update preset */
366   sustain_x = gtk_range_get_value((GtkRange *) range);
367 
368   g_value_init(&value,
369 	       AGS_TYPE_COMPLEX);
370 
371   error = NULL;
372   ags_preset_get_parameter(preset,
373 			   "sustain", &value,
374 			   &error);
375 
376   if(error != NULL){
377     g_message("%s", error->message);
378 
379     g_error_free(error);
380 
381     return;
382   }
383 
384   val = (AgsComplex *) g_value_get_boxed(&value);
385 
386   /* add parameter */
387   val[0].real = sustain_x;
388 
389   ags_preset_add_parameter(preset,
390 			   "sustain", &value);
391 
392   /* plot */
393   ags_envelope_editor_plot(envelope_editor);
394 }
395 
396 void
ags_envelope_editor_sustain_y_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)397 ags_envelope_editor_sustain_y_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
398 {
399   AgsPreset *preset;
400 
401   AgsComplex *val;
402 
403   gdouble sustain_y;
404 
405   GValue value = G_VALUE_INIT;
406 
407   GError *error;
408 
409   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
410     return;
411   }
412 
413   /* get preset */
414   preset = ags_envelope_editor_get_active_preset(envelope_editor);
415 
416   if(preset == NULL){
417     return;
418   }
419 
420   /* get value and update preset */
421   sustain_y = gtk_range_get_value((GtkRange *) range);
422 
423   g_value_init(&value,
424 	       AGS_TYPE_COMPLEX);
425 
426   error = NULL;
427   ags_preset_get_parameter(preset,
428 			   "sustain", &value,
429 			   &error);
430 
431   if(error != NULL){
432     g_message("%s", error->message);
433 
434     g_error_free(error);
435 
436     return;
437   }
438 
439   val = (AgsComplex *) g_value_get_boxed(&value);
440 
441   /* add parameter */
442   val[0].imag = sustain_y;
443 
444   ags_preset_add_parameter(preset,
445 			   "sustain", &value);
446 
447   /* plot */
448   ags_envelope_editor_plot(envelope_editor);
449 }
450 
451 void
ags_envelope_editor_release_x_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)452 ags_envelope_editor_release_x_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
453 {
454   AgsPreset *preset;
455 
456   AgsComplex *val;
457 
458   gdouble release_x;
459 
460   GValue value = G_VALUE_INIT;
461 
462   GError *error;
463 
464   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
465     return;
466   }
467 
468   /* get preset */
469   preset = ags_envelope_editor_get_active_preset(envelope_editor);
470 
471   if(preset == NULL){
472     return;
473   }
474 
475   /* get value and update preset */
476   release_x = gtk_range_get_value((GtkRange *) range);
477 
478   g_value_init(&value,
479 	       AGS_TYPE_COMPLEX);
480 
481   error = NULL;
482   ags_preset_get_parameter(preset,
483 			   "release", &value,
484 			   &error);
485 
486   if(error != NULL){
487     g_message("%s", error->message);
488 
489     g_error_free(error);
490 
491     return;
492   }
493 
494   val = (AgsComplex *) g_value_get_boxed(&value);
495 
496   /* add parameter */
497   val[0].real = release_x;
498 
499   ags_preset_add_parameter(preset,
500 			   "release", &value);
501 
502   /* plot */
503   ags_envelope_editor_plot(envelope_editor);
504 }
505 
506 void
ags_envelope_editor_release_y_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)507 ags_envelope_editor_release_y_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
508 {
509   AgsPreset *preset;
510 
511   AgsComplex *val;
512 
513   gdouble release_y;
514 
515   GValue value = G_VALUE_INIT;
516 
517   GError *error;
518 
519   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
520     return;
521   }
522 
523   /* get preset */
524   preset = ags_envelope_editor_get_active_preset(envelope_editor);
525 
526   if(preset == NULL){
527     return;
528   }
529 
530   /* get value and update preset */
531   release_y = gtk_range_get_value((GtkRange *) range);
532 
533   g_value_init(&value,
534 	       AGS_TYPE_COMPLEX);
535 
536   error = NULL;
537   ags_preset_get_parameter(preset,
538 			   "release", &value,
539 			   &error);
540 
541   if(error != NULL){
542     g_message("%s", error->message);
543 
544     g_error_free(error);
545 
546     return;
547   }
548 
549   val = (AgsComplex *) g_value_get_boxed(&value);
550 
551   /* add parameter */
552   val[0].imag = release_y;
553 
554   ags_preset_add_parameter(preset,
555 			   "release", &value);
556 
557   /* plot */
558   ags_envelope_editor_plot(envelope_editor);
559 }
560 
561 void
ags_envelope_editor_ratio_callback(GtkWidget * range,AgsEnvelopeEditor * envelope_editor)562 ags_envelope_editor_ratio_callback(GtkWidget *range, AgsEnvelopeEditor *envelope_editor)
563 {
564   AgsPreset *preset;
565 
566   AgsComplex *val;
567 
568   gdouble ratio;
569 
570   GValue value = G_VALUE_INIT;
571 
572   GError *error;
573 
574   if((AGS_ENVELOPE_EDITOR_NO_UPDATE & (envelope_editor->flags)) != 0){
575     return;
576   }
577 
578   /* get preset */
579   preset = ags_envelope_editor_get_active_preset(envelope_editor);
580 
581   if(preset == NULL){
582     return;
583   }
584 
585   /* get value and update preset */
586   ratio = gtk_range_get_value((GtkRange *) range);
587 
588   g_value_init(&value,
589 	       AGS_TYPE_COMPLEX);
590 
591   error = NULL;
592   ags_preset_get_parameter(preset,
593 			   "ratio", &value,
594 			   &error);
595 
596   if(error != NULL){
597     g_message("%s", error->message);
598 
599     g_error_free(error);
600 
601     return;
602   }
603 
604   val = (AgsComplex *) g_value_get_boxed(&value);
605 
606   /* add parameter */
607   val[0].imag = ratio;
608 
609   ags_preset_add_parameter(preset,
610 			   "ratio", &value);
611 
612   /* plot */
613   ags_envelope_editor_plot(envelope_editor);
614 }
615