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/audio/task/ags_remove_audio.h>
21
22 #include <ags/libags.h>
23
24 #include <ags/audio/ags_sound_provider.h>
25
26 #include <ags/i18n.h>
27
28 void ags_remove_audio_class_init(AgsRemoveAudioClass *remove_audio);
29 void ags_remove_audio_init(AgsRemoveAudio *remove_audio);
30 void ags_remove_audio_set_property(GObject *gobject,
31 guint prop_id,
32 const GValue *value,
33 GParamSpec *param_spec);
34 void ags_remove_audio_get_property(GObject *gobject,
35 guint prop_id,
36 GValue *value,
37 GParamSpec *param_spec);
38 void ags_remove_audio_dispose(GObject *gobject);
39 void ags_remove_audio_finalize(GObject *gobject);
40
41 void ags_remove_audio_launch(AgsTask *task);
42
43 /**
44 * SECTION:ags_remove_audio
45 * @short_description: remove audio of application context
46 * @title: AgsRemoveAudio
47 * @section_id:
48 * @include: ags/audio/task/ags_remove_audio.h
49 *
50 * The #AgsRemoveAudio task removes #AgsAudio of #AgsApplicationContext.
51 */
52
53 static gpointer ags_remove_audio_parent_class = NULL;
54
55 enum{
56 PROP_0,
57 PROP_AUDIO,
58 };
59
60 GType
ags_remove_audio_get_type()61 ags_remove_audio_get_type()
62 {
63 static volatile gsize g_define_type_id__volatile = 0;
64
65 if(g_once_init_enter (&g_define_type_id__volatile)){
66 GType ags_type_remove_audio = 0;
67
68 static const GTypeInfo ags_remove_audio_info = {
69 sizeof(AgsRemoveAudioClass),
70 NULL, /* base_init */
71 NULL, /* base_finalize */
72 (GClassInitFunc) ags_remove_audio_class_init,
73 NULL, /* class_finalize */
74 NULL, /* class_data */
75 sizeof(AgsRemoveAudio),
76 0, /* n_preallocs */
77 (GInstanceInitFunc) ags_remove_audio_init,
78 };
79
80 ags_type_remove_audio = g_type_register_static(AGS_TYPE_TASK,
81 "AgsRemoveAudio",
82 &ags_remove_audio_info,
83 0);
84
85 g_once_init_leave(&g_define_type_id__volatile, ags_type_remove_audio);
86 }
87
88 return g_define_type_id__volatile;
89 }
90
91 void
ags_remove_audio_class_init(AgsRemoveAudioClass * remove_audio)92 ags_remove_audio_class_init(AgsRemoveAudioClass *remove_audio)
93 {
94 GObjectClass *gobject;
95 AgsTaskClass *task;
96
97 GParamSpec *param_spec;
98
99 ags_remove_audio_parent_class = g_type_class_peek_parent(remove_audio);
100
101 /* gobject */
102 gobject = (GObjectClass *) remove_audio;
103
104 gobject->set_property = ags_remove_audio_set_property;
105 gobject->get_property = ags_remove_audio_get_property;
106
107 gobject->dispose = ags_remove_audio_dispose;
108 gobject->finalize = ags_remove_audio_finalize;
109
110 /* properties */
111 /**
112 * AgsRemoveAudio:audio:
113 *
114 * The assigned #AgsAudio
115 *
116 * Since: 3.0.0
117 */
118 param_spec = g_param_spec_object("audio",
119 i18n_pspec("audio of remove audio"),
120 i18n_pspec("The audio of remove audio task"),
121 AGS_TYPE_AUDIO,
122 G_PARAM_READABLE | G_PARAM_WRITABLE);
123 g_object_class_install_property(gobject,
124 PROP_AUDIO,
125 param_spec);
126
127 /* task */
128 task = (AgsTaskClass *) remove_audio;
129
130 task->launch = ags_remove_audio_launch;
131 }
132
133 void
ags_remove_audio_init(AgsRemoveAudio * remove_audio)134 ags_remove_audio_init(AgsRemoveAudio *remove_audio)
135 {
136 remove_audio->audio = NULL;
137 }
138
139 void
ags_remove_audio_set_property(GObject * gobject,guint prop_id,const GValue * value,GParamSpec * param_spec)140 ags_remove_audio_set_property(GObject *gobject,
141 guint prop_id,
142 const GValue *value,
143 GParamSpec *param_spec)
144 {
145 AgsRemoveAudio *remove_audio;
146
147 remove_audio = AGS_REMOVE_AUDIO(gobject);
148
149 switch(prop_id){
150 case PROP_AUDIO:
151 {
152 AgsAudio *audio;
153
154 audio = (AgsAudio *) g_value_get_object(value);
155
156 if(remove_audio->audio == audio){
157 return;
158 }
159
160 if(remove_audio->audio != NULL){
161 g_object_unref(remove_audio->audio);
162 }
163
164 if(audio != NULL){
165 g_object_ref(audio);
166 }
167
168 remove_audio->audio = audio;
169 }
170 break;
171 default:
172 G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
173 break;
174 }
175 }
176
177 void
ags_remove_audio_get_property(GObject * gobject,guint prop_id,GValue * value,GParamSpec * param_spec)178 ags_remove_audio_get_property(GObject *gobject,
179 guint prop_id,
180 GValue *value,
181 GParamSpec *param_spec)
182 {
183 AgsRemoveAudio *remove_audio;
184
185 remove_audio = AGS_REMOVE_AUDIO(gobject);
186
187 switch(prop_id){
188 case PROP_AUDIO:
189 {
190 g_value_set_object(value, remove_audio->audio);
191 }
192 break;
193 default:
194 G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
195 break;
196 }
197 }
198
199 void
ags_remove_audio_dispose(GObject * gobject)200 ags_remove_audio_dispose(GObject *gobject)
201 {
202 AgsRemoveAudio *remove_audio;
203
204 remove_audio = AGS_REMOVE_AUDIO(gobject);
205
206 if(remove_audio->audio != NULL){
207 g_object_unref(remove_audio->audio);
208
209 remove_audio->audio = NULL;
210 }
211
212 /* call parent */
213 G_OBJECT_CLASS(ags_remove_audio_parent_class)->dispose(gobject);
214 }
215
216 void
ags_remove_audio_finalize(GObject * gobject)217 ags_remove_audio_finalize(GObject *gobject)
218 {
219 AgsRemoveAudio *remove_audio;
220
221 remove_audio = AGS_REMOVE_AUDIO(gobject);
222
223 if(remove_audio->audio != NULL){
224 g_object_unref(remove_audio->audio);
225 }
226
227 /* call parent */
228 G_OBJECT_CLASS(ags_remove_audio_parent_class)->finalize(gobject);
229 }
230
231 void
ags_remove_audio_launch(AgsTask * task)232 ags_remove_audio_launch(AgsTask *task)
233 {
234 AgsRemoveAudio *remove_audio;
235
236 AgsApplicationContext *application_context;
237
238 GList *start_list, *list;
239
240 remove_audio = AGS_REMOVE_AUDIO(task);
241
242 application_context = ags_application_context_get_instance();
243
244 g_return_if_fail(AGS_IS_SOUND_PROVIDER(application_context));
245 g_return_if_fail(AGS_IS_AUDIO(remove_audio->audio));
246
247 /* remove audio */
248 list =
249 start_list = ags_sound_provider_get_audio(AGS_SOUND_PROVIDER(application_context));
250
251 if(g_list_find(start_list,
252 remove_audio->audio) != NULL){
253 /* remove to sound provider */
254 start_list = g_list_remove(start_list,
255 remove_audio->audio);
256 ags_sound_provider_set_audio(AGS_SOUND_PROVIDER(application_context),
257 start_list);
258
259 /* AgsAudio */
260 ags_connectable_disconnect(AGS_CONNECTABLE(remove_audio->audio));
261
262 g_object_unref(remove_audio->audio);
263 }else{
264 g_list_free_full(start_list,
265 (GDestroyNotify) g_object_unref);
266 }
267 }
268
269 /**
270 * ags_remove_audio_new:
271 * @audio: the #AgsAudio to remove
272 *
273 * Create a new instance of #AgsRemoveAudio.
274 *
275 * Returns: the new #AgsRemoveAudio
276 *
277 * Since: 3.0.0
278 */
279 AgsRemoveAudio*
ags_remove_audio_new(AgsAudio * audio)280 ags_remove_audio_new(AgsAudio *audio)
281 {
282 AgsRemoveAudio *remove_audio;
283
284 remove_audio = (AgsRemoveAudio *) g_object_new(AGS_TYPE_REMOVE_AUDIO,
285 "audio", audio,
286 NULL);
287
288 return(remove_audio);
289 }
290