File: ags_input.c

package info (click to toggle)
gsequencer 8.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 74,272 kB
  • sloc: ansic: 1,195,333; xml: 31,048; cpp: 9,749; sh: 5,798; makefile: 4,024; perl: 536; sed: 16; python: 11
file content (891 lines) | stat: -rw-r--r-- 19,607 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
/* GSequencer - Advanced GTK Sequencer
 * Copyright (C) 2005-2019 Joël Krähemann
 *
 * This file is part of GSequencer.
 *
 * GSequencer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GSequencer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <ags/audio/ags_input.h>

#include <ags/audio/ags_recycling.h>
#include <ags/audio/ags_audio_signal.h>
#include <ags/audio/ags_synth_generator.h>

#include <ags/audio/file/ags_audio_file_link.h>
#include <ags/audio/file/ags_audio_container.h>
#include <ags/audio/file/ags_audio_file.h>
#include <ags/audio/file/ags_sound_container.h>
#include <ags/audio/file/ags_sound_resource.h>
#include <ags/audio/file/ags_ipatch.h>

#include <ags/i18n.h>

#include <math.h>

void ags_input_class_init (AgsInputClass *input_class);
void ags_input_set_property(GObject *gobject,
			    guint prop_id,
			    const GValue *value,
			    GParamSpec *param_spec);
void ags_input_get_property(GObject *gobject,
			    guint prop_id,
			    GValue *value,
			    GParamSpec *param_spec);
void ags_input_init (AgsInput *input);
void ags_input_dispose(GObject *gobject);
void ags_input_finalize(GObject *gobject);

void ags_input_notify_samplerate_callback(GObject *gobject,
					  GParamSpec *pspec,
					  gpointer user_data);
void ags_input_notify_buffer_size_callback(GObject *gobject,
					   GParamSpec *pspec,
					   gpointer user_data);
void ags_input_notify_format_callback(GObject *gobject,
				      GParamSpec *pspec,
				      gpointer user_data);

/**
 * SECTION:ags_input
 * @short_description: Input of #AgsAudio
 * @title: AgsInput
 * @section_id:
 * @include: ags/audio/ags_input.h
 *
 * #AgsInput represents an input channel of #AgsAudio.
 */

static gpointer ags_input_parent_class = NULL;

enum{
  PROP_0,
  PROP_FILE_LINK,
  PROP_SYNTH_GENERATOR,
};

GType
ags_input_get_type (void)
{
  static gsize g_define_type_id__static = 0;

  if(g_once_init_enter(&g_define_type_id__static)){
    GType ags_type_input = 0;

    static const GTypeInfo ags_input_info = {
      sizeof (AgsInputClass),
      (GBaseInitFunc) NULL, /* base_init */
      (GBaseFinalizeFunc) NULL, /* base_finalize */
      (GClassInitFunc) ags_input_class_init,
      NULL, /* class_finalize */
      NULL, /* class_data */
      sizeof (AgsInput),
      0,    /* n_preallocs */
      (GInstanceInitFunc) ags_input_init,
    };

    ags_type_input = g_type_register_static(AGS_TYPE_CHANNEL,
					    "AgsInput",
					    &ags_input_info,
					    0);

    g_once_init_leave(&g_define_type_id__static, ags_type_input);
  }

  return(g_define_type_id__static);
}

void
ags_input_class_init(AgsInputClass *input)
{
  GObjectClass *gobject;
  GParamSpec *param_spec;

  ags_input_parent_class = g_type_class_peek_parent(input);
  
  gobject = (GObjectClass *) input;

  gobject->set_property = ags_input_set_property;
  gobject->get_property = ags_input_get_property;

  gobject->dispose = ags_input_dispose;
  gobject->finalize = ags_input_finalize;
  
  /* properties */
  /**
   * AgsInput:file-link:
   *
   * The file containing audio data.
   * 
   * Since: 3.0.0
   */
  param_spec = g_param_spec_object("file-link",
				   i18n_pspec("file link assigned to"),
				   i18n_pspec("The file link to read from"),
				   AGS_TYPE_FILE_LINK,
				   G_PARAM_READABLE | G_PARAM_WRITABLE);
  g_object_class_install_property(gobject,
				  PROP_FILE_LINK,
				  param_spec);

  /**
   * AgsInput:synth-generator: (type GList(AgsSynthGenerator)) (transfer full)
   *
   * The synth generators assigned with this input.
   * 
   * Since: 3.0.0
   */
  param_spec = g_param_spec_pointer("synth-generator",
				    i18n_pspec("the synth generator"),
				    i18n_pspec("The synth generator to be used"),
				    G_PARAM_READABLE | G_PARAM_WRITABLE);
  g_object_class_install_property(gobject,
				  PROP_SYNTH_GENERATOR,
				  param_spec);
}

void
ags_input_init(AgsInput *input)
{
  g_signal_connect_after(input, "notify::samplerate",
			 G_CALLBACK(ags_input_notify_samplerate_callback), NULL);
  g_signal_connect_after(input, "notify::buffer-size",
			 G_CALLBACK(ags_input_notify_buffer_size_callback), NULL);
  g_signal_connect_after(input, "notify::format",
			 G_CALLBACK(ags_input_notify_format_callback), NULL);

  input->file_link = NULL;

  input->synth_generator = NULL;
}

void
ags_input_set_property(GObject *gobject,
		       guint prop_id,
		       const GValue *value,
		       GParamSpec *param_spec)
{
  AgsInput *input;
  
  GRecMutex *channel_mutex;

  input = AGS_INPUT(gobject);

  /* get channel mutex */
  channel_mutex = AGS_CHANNEL_GET_OBJ_MUTEX(input);

  switch(prop_id){
  case PROP_FILE_LINK:
    {
      AgsFileLink *file_link;

      file_link = (AgsFileLink *) g_value_get_object(value);

      g_rec_mutex_lock(channel_mutex);

      if(input->file_link == (GObject *) file_link){
	g_rec_mutex_unlock(channel_mutex);

	return;
      }
      
      if(input->file_link != NULL){
	g_object_unref(G_OBJECT(input->file_link));
      }

      if(file_link != NULL){
	g_object_ref(G_OBJECT(file_link));
      }

      input->file_link = (GObject *) file_link;

      g_rec_mutex_unlock(channel_mutex);
    }
    break;
  case PROP_SYNTH_GENERATOR:
    {
      AgsSynthGenerator *synth_generator;

      synth_generator = (AgsSynthGenerator *) g_value_get_pointer(value);

      g_rec_mutex_lock(channel_mutex);

      if(g_list_find(input->synth_generator, synth_generator) != NULL){
	g_rec_mutex_unlock(channel_mutex);
	
	return;
      }

      g_rec_mutex_unlock(channel_mutex);
      
      ags_input_add_synth_generator(input, (GObject *) synth_generator);
    }
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
    break;
  }
}

void
ags_input_get_property(GObject *gobject,
		       guint prop_id,
		       GValue *value,
		       GParamSpec *param_spec)
{
  AgsInput *input;

  GRecMutex *channel_mutex;

  input = AGS_INPUT(gobject);

  /* get channel mutex */
  channel_mutex = AGS_CHANNEL_GET_OBJ_MUTEX(input);

  switch(prop_id){
  case PROP_FILE_LINK:
    {
      g_rec_mutex_lock(channel_mutex);

      g_value_set_object(value, input->file_link);

      g_rec_mutex_unlock(channel_mutex);
    }
    break;
  case PROP_SYNTH_GENERATOR:
    {
      g_rec_mutex_lock(channel_mutex);

      g_value_set_pointer(value, g_list_copy_deep(input->synth_generator,
						  (GCopyFunc) g_object_ref,
						  NULL));

      g_rec_mutex_unlock(channel_mutex);
    }
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
    break;
  }
}

void
ags_input_dispose(GObject *gobject)
{
  AgsInput *input;

  GList *list, *list_next;
  
  input = AGS_INPUT(gobject);

  /* file link */
  if(input->file_link != NULL){
    g_object_run_dispose(G_OBJECT(input->file_link));

    g_object_unref(G_OBJECT(input->file_link));
    
    input->file_link = NULL;
  }

  /* synth generator */
  if(input->synth_generator != NULL){
    list = input->synth_generator;
    
    while(list != NULL){
      list_next = list->next;

      g_object_run_dispose(list->data);

      list = list_next;
    }

    g_list_free_full(input->synth_generator,
		     g_object_unref);
    
    input->synth_generator = NULL;
  }

  /* finalize */
  G_OBJECT_CLASS(ags_input_parent_class)->dispose(gobject);
}

void
ags_input_finalize(GObject *gobject)
{
  AgsInput *input;

  input = AGS_INPUT(gobject);

  /* file link */
  if(input->file_link != NULL){
    g_object_unref(G_OBJECT(input->file_link));
  }

  /* synth generator */
  g_list_free_full(input->synth_generator,
		   g_object_unref);

  /* finalize */
  G_OBJECT_CLASS(ags_input_parent_class)->finalize(gobject);
}

void
ags_input_notify_samplerate_callback(GObject *gobject,
				     GParamSpec *pspec,
				     gpointer user_data)
{
  AgsInput *input;

  GList *start_list, *list;
  
  guint samplerate;
  
  input = AGS_INPUT(gobject);
  
  g_object_get(gobject,
	       "samplerate", &samplerate,
	       "synth-generator", &start_list,
	       NULL);

  /* apply to synth generator */
  list = start_list;

  while(list != NULL){
    g_object_set(list->data,
		 "samplerate", samplerate,
		 NULL);

    list = list->next;
  }

  g_list_free(start_list);
}

void
ags_input_notify_buffer_size_callback(GObject *gobject,
				      GParamSpec *pspec,
				      gpointer user_data)
{
  AgsInput *input;

  GList *start_list, *list;
  
  guint buffer_size;
  
  input = AGS_INPUT(gobject);
  
  g_object_get(gobject,
	       "buffer-size", &buffer_size,
	       "synth-generator", &start_list,
	       NULL);

  /* apply to synth generator */
  list = start_list;

  while(list != NULL){
    g_object_set(list->data,
		 "buffer-size", buffer_size,
		 NULL);

    list = list->next;
  }

  g_list_free(start_list);
}

void
ags_input_notify_format_callback(GObject *gobject,
				 GParamSpec *pspec,
				 gpointer user_data)
{
  AgsInput *input;

  GList *start_list, *list;
  
  guint format;
  
  input = AGS_INPUT(gobject);
  
  g_object_get(gobject,
	       "format", &format,
	       "synth-generator", &start_list,
	       NULL);

  /* apply to synth generator */
  list = start_list;

  while(list != NULL){
    g_object_set(list->data,
		 "format", format,
		 NULL);

    list = list->next;
  }

  g_list_free(start_list);
}

/**
 * ags_input_is_active:
 * @input: the #AgsInput
 * @recycling_context: the #AgsRecyclingContext to check
 * 
 * Check if @input is active and needs processing.
 * 
 * Returns: %TRUE if has a need to be processed, else %FALSE
 * 
 * Since: 3.0.0
 */
gboolean
ags_input_is_active(AgsInput *input,
		    GObject *recycling_context)
{
  AgsChannel *channel;
  AgsRecycling *first_recycling, *last_recycling;
  AgsRecycling *recycling, *next_recycling, *end_recycling;
  AgsAudioSignal *audio_signal;
  AgsRecyclingContext *active_context;
  
  GList *start_list, *list;

  gboolean success;
  
  if(!AGS_IS_INPUT(input) ||
     !AGS_IS_RECYCLING_CONTEXT(recycling_context)){
    return(FALSE);
  }
  
  channel = (AgsChannel *) input;
    
  /* get recycling */
  g_object_get(channel,
	       "first-recycling", &first_recycling,
	       "last-recycling", &last_recycling,
	       NULL);
  
  if(first_recycling == NULL){
    return(FALSE);
  }

  /* get active recycling context */
  active_context = (AgsRecyclingContext *) recycling_context;

  /* get end recycling */
  end_recycling = ags_recycling_next(last_recycling);

  /* check if active */
  recycling = first_recycling;
  g_object_ref(recycling);

  success = FALSE;
  
  while(recycling != end_recycling){
    /* get audio signal */
    g_object_get(recycling,
		 "audio-signal", &start_list,
		 NULL);

    list = start_list;
    
    while(list != NULL){
      AgsRecallID *current_recall_id;
      AgsRecyclingContext *current_recycling_context;

      audio_signal = list->data;

      /* get recall id */
      g_object_get(audio_signal,
		   "recall-id", &current_recall_id,
		   NULL);
      
      if(current_recall_id == NULL){
	list = list->next;
	
	continue; 
      }

      /* get recycling context */
      g_object_get(current_recall_id,
		   "recycling-context", &current_recycling_context,
		   NULL);

      success = (current_recycling_context == active_context) ? TRUE: FALSE;

      if(current_recycling_context != NULL){
	g_object_unref(current_recycling_context);
      }
      
      if(success){
	g_list_free_full(start_list,
			 g_object_unref);
	
	goto ags_input_is_active_END;
      }

      list = list->next;
    }

    g_list_free_full(start_list,
		     g_object_unref);
    
    /* iterate */
    next_recycling = ags_recycling_next(recycling);

    g_object_unref(recycling);

    recycling = next_recycling;
  }

ags_input_is_active_END:
  g_object_unref(first_recycling);
  g_object_unref(last_recycling);

  if(end_recycling != NULL){
    g_object_unref(end_recycling);
  }
  
  return(success);
}

/**
 * ags_input_next_active:
 * @input: the #AgsInput
 * @recycling_context: the #AgsRecyclingContext to check
 * 
 * Find next #AgsInput needed to be processed.
 * 
 * Returns: (transfer full): next active #AgsInput, else %NULL if non available
 * 
 * Since: 3.0.0
 */
AgsInput*
ags_input_next_active(AgsInput *input,
		      GObject *recycling_context)
{
  AgsChannel *channel, *next_pad_channel;
  AgsInput *retval;
  AgsRecycling *first_recycling, *last_recycling;
  AgsRecycling *recycling, *next_recycling, *end_recycling;
  AgsAudioSignal *audio_signal;  
  AgsRecyclingContext *active_context;

  GList *start_list, *list;  

  gboolean success;
  
  if(!AGS_IS_INPUT(input) ||
     !AGS_IS_RECYCLING_CONTEXT(recycling_context)){
    return(NULL);
  }

  channel = (AgsChannel *) input;
  g_object_ref(channel);
  
  retval = NULL;
  
  /* check if active */
  while(channel != NULL){
    /* get recycling */
    g_object_get(channel,
		 "first-recycling", &first_recycling,
		 "last-recycling", &last_recycling,
		 NULL);
  
    if(first_recycling == NULL){
      /* iterate */
      next_pad_channel = ags_channel_next_pad(channel);

      g_object_unref(channel);

      channel = next_pad_channel;
      
      continue;
    }

    /* get active recycling context */
    active_context = (AgsRecyclingContext *) recycling_context;

    /* get end recycling */
    end_recycling = ags_recycling_next(last_recycling);
    
    /* check recycling */
    recycling = first_recycling;
    g_object_ref(recycling);
    
    while(recycling != end_recycling){
      /* get audio signal */
      g_object_get(recycling,
		   "audio-signal", &start_list,
		   NULL);

      /* check audio signal */
      list = start_list;
      
      while(list != NULL){
	AgsRecallID *current_recall_id;
	AgsRecyclingContext *current_recycling_context;

	audio_signal = list->data;

	/* get recall id */
	g_object_get(audio_signal,
		     "recall-id", &current_recall_id,
		     NULL);
      
	if(current_recall_id == NULL){
	  list = list->next;
	
	  continue; 
	}

	/* get recycling context */
	g_object_get(current_recall_id,
		     "recycling-context", &current_recycling_context,
		     NULL);

	success = (current_recycling_context == active_context) ? TRUE: FALSE;
	
	if(success){
	  g_list_free_full(start_list,
			   g_object_unref);

	  retval = (AgsInput *) channel;

	  goto ags_input_next_active_END;
	}

	list = list->next;
      }

      g_list_free_full(start_list,
		       g_object_unref);

      /* iterate */
      next_recycling = ags_recycling_next(recycling);

      g_object_unref(recycling);

      recycling = next_recycling;
    }

  ags_input_next_active_END:
    g_object_unref(first_recycling);
    g_object_unref(last_recycling);

    if(end_recycling != NULL){
      g_object_unref(end_recycling);
    }

    if(recycling != NULL){
      g_object_unref(recycling);
    }

    if(retval != NULL){
      break;
    }
    
    /* iterate */
    next_pad_channel = ags_channel_next_pad(channel);

    g_object_unref(channel);

    channel = next_pad_channel;
  }
  
  return(retval);
}

/**
 * ags_input_add_synth_generator:
 * @input: the #AgsInput
 * @synth_generator: the #AgsSynthGenerator
 * 
 * Add @synth_generator to @input.
 * 
 * Since: 3.0.0
 */
void
ags_input_add_synth_generator(AgsInput *input,
			      GObject *synth_generator)
{
  if(!AGS_IS_INPUT(input) ||
     !AGS_IS_SYNTH_GENERATOR(synth_generator)){
    return;
  }

  g_object_ref(synth_generator);
  input->synth_generator = g_list_prepend(input->synth_generator,
					  synth_generator);
}

/**
 * ags_input_remove_synth_generator:
 * @input: the #AgsInput
 * @synth_generator: the #AgsSynthGenerator
 * 
 * Remove @synth_generator from @input.
 * 
 * Since: 3.0.0
 */
void
ags_input_remove_synth_generator(AgsInput *input,
				 GObject *synth_generator)
{
  if(!AGS_IS_INPUT(input) ||
     !AGS_IS_SYNTH_GENERATOR(synth_generator)){
    return;
  }

  if(g_list_find(input->synth_generator,
		 synth_generator) != NULL){
    input->synth_generator = g_list_remove(input->synth_generator,
					   synth_generator);
    g_object_unref(synth_generator);
  }
}

/**
 * ags_input_open_file:
 * @input: the #AgsInput
 * @filename: the filename as string
 * @preset: the preset to open
 * @instrument: the instrument to open
 * @sample: the sample to open
 * @audio_channel: the audio channel to read
 * 
 * Open @filename and assign @audio_channel's data as AGS_AUDIO_SIGNAL_TEMPLATE
 * audio signal to @input's own recycling.
 * 
 * Returns: %TRUE if open was successful, else %FALSE
 * 
 * Since: 3.0.0
 */
gboolean
ags_input_open_file(AgsInput *input,
		    gchar *filename,
		    gchar *preset,
		    gchar *instrument,
		    gchar *sample,
		    guint audio_channel)
{
  AgsRecycling *recycling;
  AgsFileLink *file_link;
  
  GList *audio_signal;

  gboolean success;

  if(!AGS_IS_INPUT(input)){
    return(FALSE);
  }
  
  audio_signal = NULL;
  success = FALSE;

  if(ags_audio_file_check_suffix(filename)){
    AgsAudioFile *audio_file;

    success = TRUE;

    preset = NULL;
    instrument = NULL;
    
    /* open audio file and read audio signal */
    audio_file = ags_audio_file_new(filename,
				    AGS_CHANNEL(input)->output_soundcard,
				    audio_channel);
    
    ags_audio_file_open(audio_file);
    ags_audio_file_read_audio_signal(audio_file);

    audio_signal = audio_file->audio_signal;
    //    g_object_unref(audio_file);
#if defined(AGS_WITH_LIBINSTPATCH)
  }else if(ags_ipatch_check_suffix(filename)){
    AgsAudioContainer *audio_container;

    success = TRUE;

    preset = NULL;
    instrument = NULL;
    
    /* open audio container and read audio signal */
    audio_container = ags_audio_container_new(filename,
					      preset,
					      instrument,
					      sample,
					      AGS_CHANNEL(input)->output_soundcard,
					      audio_channel);
    
    ags_audio_container_open(audio_container);
    ags_audio_container_read_audio_signal(audio_container);

    audio_signal = audio_container->audio_signal;
    //    g_object_unref(audio_container);
#endif
  }

  if(success){
    if(audio_signal != NULL){
      file_link = g_object_new(AGS_TYPE_AUDIO_FILE_LINK,
			       "filename", filename,
			       "preset", preset,
			       "instrument", instrument,
			       "sample", sample,
			       "audio-channel", audio_channel,
			       NULL);
      g_object_set(input,
		   "file-link", file_link,
		   NULL);
    
      /* mark as template */
      AGS_AUDIO_SIGNAL(audio_signal->data)->flags |= AGS_AUDIO_SIGNAL_TEMPLATE;
    
      /* add as template */
      g_object_get(input,
		   "first-recycling", &recycling,
		   NULL);
      ags_recycling_add_audio_signal(recycling,
				     AGS_AUDIO_SIGNAL(audio_signal->data));

      g_object_unref(recycling);
    }else{
      success = FALSE;
    }
  }
  
  return(success);
}

/**
 * ags_input_new:
 * @audio: the #AgsAudio
 *
 * Creates a #AgsInput, linking tree to @audio.
 *
 * Returns: a new #AgsInput
 *
 * Since: 3.0.0
 */
AgsInput*
ags_input_new(GObject *audio)
{
  AgsInput *input;

  input = (AgsInput *) g_object_new(AGS_TYPE_INPUT,
				    "audio", audio,
				    NULL);

  return(input);
}