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/ags_dssi_browser.h>
21 #include <ags/X/ags_dssi_browser_callbacks.h>
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 
29 #include <dssi.h>
30 
31 #include <ags/i18n.h>
32 
33 void ags_dssi_browser_class_init(AgsDssiBrowserClass *dssi_browser);
34 void ags_dssi_browser_init(AgsDssiBrowser *dssi_browser);
35 void ags_dssi_browser_connectable_interface_init(AgsConnectableInterface *connectable);
36 void ags_dssi_browser_applicable_interface_init(AgsApplicableInterface *applicable);
37 void ags_dssi_browser_connect(AgsConnectable *connectable);
38 void ags_dssi_browser_disconnect(AgsConnectable *connectable);
39 void ags_dssi_browser_set_update(AgsApplicable *applicable, gboolean update);
40 void ags_dssi_browser_apply(AgsApplicable *applicable);
41 void ags_dssi_browser_reset(AgsApplicable *applicable);
42 
43 /**
44  * SECTION:ags_dssi_browser
45  * @short_description: A composite to select dssi effect.
46  * @title: AgsDssiBrowser
47  * @section_id:
48  * @include: ags/X/ags_dssi_browser.h
49  *
50  * #AgsDssiBrowser is a composite widget to select dssi plugin and the desired
51  * effect.
52  */
53 
54 GType
ags_dssi_browser_get_type(void)55 ags_dssi_browser_get_type(void)
56 {
57   static volatile gsize g_define_type_id__volatile = 0;
58 
59   if(g_once_init_enter (&g_define_type_id__volatile)){
60     GType ags_type_dssi_browser = 0;
61 
62     static const GTypeInfo ags_dssi_browser_info = {
63       sizeof (AgsDssiBrowserClass),
64       NULL, /* base_init */
65       NULL, /* base_finalize */
66       (GClassInitFunc) ags_dssi_browser_class_init,
67       NULL, /* class_finalize */
68       NULL, /* class_data */
69       sizeof (AgsDssiBrowser),
70       0,    /* n_preallocs */
71       (GInstanceInitFunc) ags_dssi_browser_init,
72     };
73 
74     static const GInterfaceInfo ags_connectable_interface_info = {
75       (GInterfaceInitFunc) ags_dssi_browser_connectable_interface_init,
76       NULL, /* interface_finalize */
77       NULL, /* interface_data */
78     };
79 
80     static const GInterfaceInfo ags_applicable_interface_info = {
81       (GInterfaceInitFunc) ags_dssi_browser_applicable_interface_init,
82       NULL, /* interface_finalize */
83       NULL, /* interface_data */
84     };
85 
86     ags_type_dssi_browser = g_type_register_static(GTK_TYPE_BOX,
87 						   "AgsDssiBrowser", &ags_dssi_browser_info,
88 						   0);
89 
90     g_type_add_interface_static(ags_type_dssi_browser,
91 				AGS_TYPE_CONNECTABLE,
92 				&ags_connectable_interface_info);
93 
94     g_type_add_interface_static(ags_type_dssi_browser,
95 				AGS_TYPE_APPLICABLE,
96 				&ags_applicable_interface_info);
97 
98     g_once_init_leave(&g_define_type_id__volatile, ags_type_dssi_browser);
99   }
100 
101   return g_define_type_id__volatile;
102 }
103 
104 void
ags_dssi_browser_class_init(AgsDssiBrowserClass * dssi_browser)105 ags_dssi_browser_class_init(AgsDssiBrowserClass *dssi_browser)
106 {
107   /* empty */
108 }
109 
110 void
ags_dssi_browser_connectable_interface_init(AgsConnectableInterface * connectable)111 ags_dssi_browser_connectable_interface_init(AgsConnectableInterface *connectable)
112 {
113   connectable->is_ready = NULL;
114   connectable->is_connected = NULL;
115   connectable->connect = ags_dssi_browser_connect;
116   connectable->disconnect = ags_dssi_browser_disconnect;
117 }
118 
119 void
ags_dssi_browser_applicable_interface_init(AgsApplicableInterface * applicable)120 ags_dssi_browser_applicable_interface_init(AgsApplicableInterface *applicable)
121 {
122   applicable->set_update = ags_dssi_browser_set_update;
123   applicable->apply = ags_dssi_browser_apply;
124   applicable->reset = ags_dssi_browser_reset;
125 }
126 
127 void
ags_dssi_browser_init(AgsDssiBrowser * dssi_browser)128 ags_dssi_browser_init(AgsDssiBrowser *dssi_browser)
129 {
130   GtkComboBoxText *combo_box;
131   GtkLabel *label;
132 
133   AgsDssiManager *dssi_manager;
134 
135   gchar **filenames, **filenames_start;
136 
137   gtk_orientable_set_orientation(GTK_ORIENTABLE(dssi_browser),
138 				 GTK_ORIENTATION_VERTICAL);
139 
140   dssi_browser->flags = 0;
141 
142   dssi_manager = ags_dssi_manager_get_instance();
143 
144   /* plugin */
145   dssi_browser->plugin = (GtkBox *) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
146 						0);
147   gtk_box_pack_start((GtkBox *) dssi_browser,
148 		     (GtkWidget *) dssi_browser->plugin,
149 		     FALSE, FALSE,
150 		     0);
151 
152   label = (GtkLabel *) gtk_label_new(i18n("filename: "));
153   gtk_box_pack_start((GtkBox *) dssi_browser->plugin,
154 		     (GtkWidget *) label,
155 		     FALSE, FALSE,
156 		     0);
157 
158   dssi_browser->filename = (GtkComboBox *) gtk_combo_box_text_new();
159   combo_box = (GtkComboBoxText *) dssi_browser->filename;
160   gtk_box_pack_start((GtkBox *) dssi_browser->plugin,
161 		     (GtkWidget *) combo_box,
162 		     FALSE, FALSE,
163 		     0);
164 
165   dssi_browser->path = NULL;
166 
167   ags_dssi_manager_load_default_directory(dssi_manager);
168 
169   filenames =
170     filenames_start = ags_dssi_manager_get_filenames(dssi_manager);
171 
172   while(*filenames != NULL){
173     gtk_combo_box_text_append_text(combo_box,
174 				   *filenames);
175 
176     filenames++;
177   }
178 
179   g_strfreev(filenames_start);
180 
181   label = (GtkLabel *) gtk_label_new(i18n("effect: "));
182   gtk_box_pack_start((GtkBox *) dssi_browser->plugin,
183 		     (GtkWidget *) label,
184 		     FALSE, FALSE,
185 		     0);
186 
187   dssi_browser->effect = (GtkComboBox *) gtk_combo_box_text_new();
188   combo_box = (GtkComboBoxText *) dssi_browser->effect;
189   gtk_box_pack_start((GtkBox *) dssi_browser->plugin,
190 		     (GtkWidget *) combo_box,
191 		     FALSE, FALSE,
192 		     0);
193 
194   /* description */
195   dssi_browser->description = (GtkBox *) gtk_box_new(GTK_ORIENTATION_VERTICAL,
196 						     0);
197   gtk_box_pack_start((GtkBox *) dssi_browser,
198 		     (GtkWidget *) dssi_browser->description,
199 		     FALSE, FALSE,
200 		     0);
201 
202   dssi_browser->label =
203     label = (GtkLabel *) g_object_new(GTK_TYPE_LABEL,
204 				      "xalign", 0.0,
205 				      "label", i18n("Label: "),
206 				      NULL);
207   gtk_box_pack_start((GtkBox *) dssi_browser->description,
208 		     (GtkWidget *) label,
209 		     FALSE, FALSE,
210 		     0);
211 
212   dssi_browser->maker =
213     label = (GtkLabel *) g_object_new(GTK_TYPE_LABEL,
214 				      "xalign", 0.0,
215 				      "label", i18n("Maker: "),
216 				      NULL);
217   gtk_box_pack_start((GtkBox *) dssi_browser->description,
218 		     (GtkWidget *) label,
219 		     FALSE, FALSE,
220 		     0);
221 
222   dssi_browser->copyright =
223     label = (GtkLabel *) g_object_new(GTK_TYPE_LABEL,
224 				      "xalign", 0.0,
225 				      "label", i18n("Copyright: "),
226 				      NULL);
227   gtk_box_pack_start((GtkBox *) dssi_browser->description,
228 		     (GtkWidget *) label,
229 		     FALSE, FALSE,
230 		     0);
231 
232   label = (GtkLabel *) g_object_new(GTK_TYPE_LABEL,
233 				    "xalign", 0.0,
234 				    "label", i18n("Ports: "),
235 				    NULL);
236   gtk_box_pack_start((GtkBox *) dssi_browser->description,
237 		     (GtkWidget *) label,
238 		     FALSE, FALSE,
239 		     0);
240 
241   dssi_browser->port_grid = (GtkGrid *) gtk_grid_new();
242   gtk_box_pack_start((GtkBox *) dssi_browser->description,
243 		     (GtkWidget *) dssi_browser->port_grid,
244 		     FALSE, FALSE,
245 		     0);
246 
247   dssi_browser->preview = NULL;
248 }
249 
250 void
ags_dssi_browser_connect(AgsConnectable * connectable)251 ags_dssi_browser_connect(AgsConnectable *connectable)
252 {
253   AgsDssiBrowser *dssi_browser;
254 
255   dssi_browser = AGS_DSSI_BROWSER(connectable);
256 
257   if((AGS_DSSI_BROWSER_CONNECTED & (dssi_browser->flags)) != 0){
258     return;
259   }
260 
261   dssi_browser->flags |= AGS_DSSI_BROWSER_CONNECTED;
262 
263   g_signal_connect_after(G_OBJECT(dssi_browser->filename), "changed",
264 			 G_CALLBACK(ags_dssi_browser_plugin_filename_callback), dssi_browser);
265 
266   g_signal_connect_after(G_OBJECT(dssi_browser->effect), "changed",
267 			 G_CALLBACK(ags_dssi_browser_plugin_effect_callback), dssi_browser);
268 }
269 
270 void
ags_dssi_browser_disconnect(AgsConnectable * connectable)271 ags_dssi_browser_disconnect(AgsConnectable *connectable)
272 {
273   AgsDssiBrowser *dssi_browser;
274 
275   dssi_browser = AGS_DSSI_BROWSER(connectable);
276 
277   if((AGS_DSSI_BROWSER_CONNECTED & (dssi_browser->flags)) == 0){
278     return;
279   }
280 
281   dssi_browser->flags &= (~AGS_DSSI_BROWSER_CONNECTED);
282 
283   g_object_disconnect(G_OBJECT(dssi_browser->filename),
284 		      "any_signal::changed",
285 		      G_CALLBACK(ags_dssi_browser_plugin_filename_callback),
286 		      dssi_browser,
287 		      NULL);
288 
289   g_object_disconnect(G_OBJECT(dssi_browser->effect),
290 		      "any_signal::changed",
291 		      G_CALLBACK(ags_dssi_browser_plugin_effect_callback),
292 		      dssi_browser,
293 		      NULL);
294 }
295 
296 void
ags_dssi_browser_set_update(AgsApplicable * applicable,gboolean update)297 ags_dssi_browser_set_update(AgsApplicable *applicable, gboolean update)
298 {
299   /* empty */
300 }
301 
302 void
ags_dssi_browser_apply(AgsApplicable * applicable)303 ags_dssi_browser_apply(AgsApplicable *applicable)
304 {
305   /* empty */
306 }
307 
308 void
ags_dssi_browser_reset(AgsApplicable * applicable)309 ags_dssi_browser_reset(AgsApplicable *applicable)
310 {
311   AgsDssiBrowser *dssi_browser;
312   GtkComboBoxText *filename;
313 
314   GList *list;
315 
316   dssi_browser = AGS_DSSI_BROWSER(applicable);
317 
318   list = gtk_container_get_children(GTK_CONTAINER(dssi_browser->plugin));
319 
320   filename = GTK_COMBO_BOX_TEXT(list->next->data);
321   g_list_free(list);
322 
323   gtk_combo_box_set_active((GtkComboBox *) filename,
324 			   0);
325 }
326 
327 /**
328  * ags_dssi_browser_get_plugin_filename:
329  * @dssi_browser: the #AgsDssiBrowser
330  *
331  * Retrieve selected dssi plugin filename.
332  *
333  * Returns: the active dssi filename
334  *
335  * Since: 3.0.0
336  */
337 gchar*
ags_dssi_browser_get_plugin_filename(AgsDssiBrowser * dssi_browser)338 ags_dssi_browser_get_plugin_filename(AgsDssiBrowser *dssi_browser)
339 {
340   if(!AGS_IS_DSSI_BROWSER(dssi_browser)){
341     return(NULL);
342   }
343 
344   return(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(dssi_browser->filename)));
345 }
346 
347 /**
348  * ags_dssi_browser_get_plugin_effect:
349  * @dssi_browser: the #AgsDssiBrowser
350  *
351  * Retrieve selected dssi effect.
352  *
353  * Returns: the active dssi effect
354  *
355  * Since: 3.0.0
356  */
357 gchar*
ags_dssi_browser_get_plugin_effect(AgsDssiBrowser * dssi_browser)358 ags_dssi_browser_get_plugin_effect(AgsDssiBrowser *dssi_browser)
359 {
360   if(!AGS_IS_DSSI_BROWSER(dssi_browser)){
361     return(NULL);
362   }
363 
364   return(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(dssi_browser->effect)));
365 }
366 
367 /**
368  * ags_dssi_browser_combo_box_controls_new:
369  *
370  * Creates a #GtkComboBox containing suitable widgets as controls.
371  *
372  * Returns: a new #GtkComboBox
373  *
374  * Since: 3.0.0
375  */
376 GtkWidget*
ags_dssi_browser_combo_box_controls_new()377 ags_dssi_browser_combo_box_controls_new()
378 {
379   GtkComboBoxText *combo_box;
380 
381   combo_box = (GtkComboBoxText *) gtk_combo_box_text_new();
382 
383   gtk_combo_box_text_append_text(combo_box,
384 				 "spin button");
385   gtk_combo_box_text_append_text(combo_box,
386 				 "dial");
387   gtk_combo_box_text_append_text(combo_box,
388 				 "vertical scale");
389   gtk_combo_box_text_append_text(combo_box,
390 				 "horizontal scale");
391 
392   gtk_combo_box_set_active((GtkComboBox *) combo_box,
393 			   1);
394 
395   return((GtkWidget *) combo_box);
396 }
397 
398 GtkWidget*
ags_dssi_browser_preview_new()399 ags_dssi_browser_preview_new()
400 {
401   GtkWidget *preview;
402 
403   preview = NULL;
404 
405   //TODO:JK: implement me
406 
407   return(preview);
408 }
409 
410 /**
411  * ags_dssi_browser_new:
412  *
413  * Create a new instance of #AgsDssiBrowser
414  *
415  * Returns: the new #AgsDssiBrowser
416  *
417  * Since: 3.0.0
418  */
419 AgsDssiBrowser*
ags_dssi_browser_new()420 ags_dssi_browser_new()
421 {
422   AgsDssiBrowser *dssi_browser;
423 
424   dssi_browser = (AgsDssiBrowser *) g_object_new(AGS_TYPE_DSSI_BROWSER,
425 						 "homogeneous", FALSE,
426 						 "spacing", 0,
427 						 NULL);
428 
429   return(dssi_browser);
430 }
431