1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2021 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/ags_pad_editor_callbacks.h>
21 
22 #include <ags/X/ags_machine_editor.h>
23 #include <ags/X/ags_line_editor.h>
24 
25 void
ags_pad_editor_resize_audio_channels_callback(AgsMachine * machine,guint audio_channels,guint audio_channels_old,AgsPadEditor * pad_editor)26 ags_pad_editor_resize_audio_channels_callback(AgsMachine *machine,
27 					      guint audio_channels, guint audio_channels_old,
28 					      AgsPadEditor *pad_editor)
29 {
30   if(audio_channels > audio_channels_old){
31     AgsLineEditor *line_editor;
32 
33     AgsChannel *channel, *next_pad, *next_channel, *nth_channel;
34 
35     guint i;
36 
37     /* get some channel fields */
38     next_pad = ags_channel_next_pad(pad_editor->pad);
39 
40     /* get current last of pad */
41     nth_channel = ags_channel_nth(pad_editor->pad,
42 				  audio_channels_old);
43 
44     channel = nth_channel;
45 
46     next_channel = NULL;
47 
48     while(channel != next_pad && channel != NULL){
49       /* instantiate line editor */
50       line_editor = ags_line_editor_new(channel);
51       line_editor->editor_type_count = pad_editor->editor_type_count;
52       line_editor->editor_type = (GType *) malloc(line_editor->editor_type_count * sizeof(GType));
53 
54       for(i = 0; i < line_editor->editor_type_count; i++){
55 	line_editor->editor_type[i] = pad_editor->editor_type[i];
56       }
57 
58       gtk_box_pack_start(GTK_BOX(pad_editor->line_editor),
59 			 GTK_WIDGET(line_editor),
60 			 FALSE, FALSE,
61 			 0);
62       ags_connectable_connect(AGS_CONNECTABLE(line_editor));
63       gtk_widget_show_all(GTK_WIDGET(line_editor));
64 
65       /* iterate */
66       next_channel = ags_channel_next(channel);
67 
68       g_object_unref(channel);
69 
70       channel = next_channel;
71     }
72 
73     if(next_pad != NULL){
74       g_object_unref(next_pad);
75     }
76 
77     if(next_channel != NULL){
78       g_object_unref(next_channel);
79     }
80   }else{
81     GList *list, *list_next, *list_start;
82 
83     list_start =
84       list = gtk_container_get_children(GTK_CONTAINER(pad_editor->line_editor));
85 
86     list = g_list_nth(list,
87 		      audio_channels);
88 
89     while(list != NULL){
90       list_next = list->next;
91 
92       gtk_widget_destroy(GTK_WIDGET(list->data));
93 
94       list = list_next;
95     }
96 
97     g_list_free(list_start);
98   }
99 }
100