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 <glib.h>
21 #include <glib-object.h>
22 
23 #include <CUnit/CUnit.h>
24 #include <CUnit/Automated.h>
25 #include <CUnit/Basic.h>
26 
27 #include <ags/libags.h>
28 #include <ags/libags-audio.h>
29 
30 #include <math.h>
31 
32 int ags_fx_volume_audio_signal_test_init_suite();
33 int ags_fx_volume_audio_signal_test_clean_suite();
34 
35 void ags_fx_volume_audio_signal_test_new();
36 void ags_fx_volume_audio_signal_test_run_inter();
37 
38 /* The suite initialization function.
39  * Opens the temporary file used by the tests.
40  * Returns zero on success, non-zero otherwise.
41  */
42 int
ags_fx_volume_audio_signal_test_init_suite()43 ags_fx_volume_audio_signal_test_init_suite()
44 {
45   return(0);
46 }
47 
48 /* The suite cleanup function.
49  * Closes the temporary file used by the tests.
50  * Returns zero on success, non-zero otherwise.
51  */
52 int
ags_fx_volume_audio_signal_test_clean_suite()53 ags_fx_volume_audio_signal_test_clean_suite()
54 {
55   return(0);
56 }
57 
58 void
ags_fx_volume_audio_signal_test_new()59 ags_fx_volume_audio_signal_test_new()
60 {
61   AgsAudioSignal *audio_signal;
62   AgsFxVolumeAudioSignal *fx_volume_audio_signal;
63 
64   audio_signal = g_object_new(AGS_TYPE_AUDIO_SIGNAL,
65 			      NULL);
66 
67   fx_volume_audio_signal = ags_fx_volume_audio_signal_new(audio_signal);
68 
69   CU_ASSERT(fx_volume_audio_signal != NULL);
70   CU_ASSERT(AGS_RECALL_AUDIO_SIGNAL(fx_volume_audio_signal)->source == audio_signal);
71 }
72 
73 void
ags_fx_volume_audio_signal_test_run_inter()74 ags_fx_volume_audio_signal_test_run_inter()
75 {
76   AgsAudio *audio;
77   AgsChannel *channel;
78   AgsRecycling *recycling;
79   AgsAudioSignal *audio_signal;
80   AgsRecallContainer *recall_container;
81   AgsFxVolumeAudio *fx_volume_audio;
82   AgsFxVolumeAudioProcessor *fx_volume_audio_processor;
83   AgsFxVolumeChannel *fx_volume_channel;
84   AgsFxVolumeChannelProcessor *fx_volume_channel_processor;
85   AgsFxVolumeRecycling *fx_volume_recycling;
86   AgsFxVolumeAudioSignal *fx_volume_audio_signal;
87 
88   GValue value = {0,};
89 
90   /* audio */
91   audio = g_object_new(AGS_TYPE_AUDIO,
92 		       NULL);
93 
94   recall_container = ags_recall_container_new();
95   ags_audio_add_recall_container(audio,
96 				 recall_container);
97 
98   fx_volume_audio = ags_fx_volume_audio_new(audio);
99   ags_recall_set_sound_scope(fx_volume_audio, AGS_SOUND_SCOPE_PLAYBACK);
100   ags_recall_container_add(recall_container,
101 			   fx_volume_audio);
102 
103   CU_ASSERT(fx_volume_audio != NULL);
104 
105   /* audio processor */
106   fx_volume_audio_processor = ags_fx_volume_audio_processor_new(audio);
107   ags_recall_set_sound_scope(fx_volume_audio_processor, AGS_SOUND_SCOPE_PLAYBACK);
108 
109   g_object_set(fx_volume_audio_processor,
110 	       "recall-audio", fx_volume_audio,
111 	       NULL);
112 
113   ags_recall_container_add(recall_container,
114 			   fx_volume_audio_processor);
115 
116   CU_ASSERT(fx_volume_audio_processor != NULL);
117 
118   /* channel */
119   channel = g_object_new(AGS_TYPE_CHANNEL,
120 			 NULL);
121 
122   ags_channel_add_recall_container(channel,
123 				   recall_container);
124 
125   fx_volume_channel = ags_fx_volume_channel_new(channel);
126   ags_recall_set_sound_scope(fx_volume_channel, AGS_SOUND_SCOPE_PLAYBACK);
127 
128   g_object_set(fx_volume_channel,
129 	       "recall-audio", fx_volume_audio,
130 	       NULL);
131 
132   ags_recall_container_add(recall_container,
133 			   fx_volume_channel);
134 
135   CU_ASSERT(fx_volume_channel != NULL);
136 
137   /* channel processor */
138   fx_volume_channel_processor = ags_fx_volume_channel_processor_new(channel);
139   ags_recall_set_sound_scope(fx_volume_channel_processor, AGS_SOUND_SCOPE_PLAYBACK);
140 
141   g_object_set(fx_volume_channel_processor,
142 	       "recall-audio", fx_volume_audio,
143 	       "recall-channel", fx_volume_channel,
144 	       NULL);
145 
146   ags_recall_container_add(recall_container,
147 			   fx_volume_channel_processor);
148 
149   CU_ASSERT(fx_volume_channel_processor != NULL);
150 
151   /* recycling */
152   recycling = g_object_new(AGS_TYPE_RECYCLING,
153 			   NULL);
154 
155   fx_volume_recycling = ags_fx_volume_recycling_new(recycling);
156   ags_recall_set_sound_scope(fx_volume_recycling, AGS_SOUND_SCOPE_PLAYBACK);
157 
158   ags_recall_add_child(fx_volume_channel_processor,
159 		       fx_volume_recycling);
160 
161   CU_ASSERT(fx_volume_recycling != NULL);
162 
163   /* audio signal */
164   audio_signal = g_object_new(AGS_TYPE_AUDIO_SIGNAL,
165 			      NULL);
166 
167   ags_audio_signal_stream_resize(audio_signal,
168 				 3);
169   audio_signal->stream_current = audio_signal->stream;
170 
171   fx_volume_audio_signal = ags_fx_volume_audio_signal_new(audio_signal);
172   ags_recall_set_sound_scope(fx_volume_audio_signal, AGS_SOUND_SCOPE_PLAYBACK);
173 
174   ags_recall_add_child(fx_volume_recycling,
175 		       fx_volume_audio_signal);
176 
177   CU_ASSERT(fx_volume_audio_signal != NULL);
178 
179   /* run inter - attempt #0 */
180   ags_recall_run_inter(fx_volume_audio_signal);
181 
182   /* run inter - attempt #1 */
183   g_value_init(&value, G_TYPE_FLOAT);
184   g_value_set_float(&value, (gfloat) TRUE);
185 
186   ags_port_safe_write(fx_volume_channel->muted,
187 		      &value);
188 
189   ags_recall_run_inter(fx_volume_audio_signal);
190 
191   /* run inter - attempt #2 */
192   ags_port_safe_write(fx_volume_audio->muted,
193 		      &value);
194 
195   ags_recall_run_inter(fx_volume_audio_signal);
196 
197   /* run inter - attempt #3 */
198   audio_signal->stream_current = NULL;
199 
200   ags_recall_run_inter(fx_volume_audio_signal);
201 }
202 
203 int
main(int argc,char ** argv)204 main(int argc, char **argv)
205 {
206   CU_pSuite pSuite = NULL;
207 
208   putenv("LC_ALL=C");
209   putenv("LANG=C");
210 
211   putenv("LADSPA_PATH=\"\"");
212   putenv("DSSI_PATH=\"\"");
213   putenv("LV2_PATH=\"\"");
214 
215   /* initialize the CUnit test registry */
216   if(CUE_SUCCESS != CU_initialize_registry()){
217     return CU_get_error();
218   }
219 
220   /* add a suite to the registry */
221   pSuite = CU_add_suite("AgsFxVolumeAudioSignalTest", ags_fx_volume_audio_signal_test_init_suite, ags_fx_volume_audio_signal_test_clean_suite);
222 
223   if(pSuite == NULL){
224     CU_cleanup_registry();
225 
226     return CU_get_error();
227   }
228 
229   /* add the tests to the suite */
230   if((CU_add_test(pSuite, "test of AgsFxVolumeAudioSignal new", ags_fx_volume_audio_signal_test_new) == NULL) ||
231      (CU_add_test(pSuite, "test of AgsFxVolumeAudioSignal new", ags_fx_volume_audio_signal_test_run_inter) == NULL)){
232     CU_cleanup_registry();
233 
234     return CU_get_error();
235   }
236 
237   /* Run all tests using the CUnit Basic interface */
238   CU_basic_set_mode(CU_BRM_VERBOSE);
239   CU_basic_run_tests();
240 
241   CU_cleanup_registry();
242 
243   return(CU_get_error());
244 }
245