1 
2 #include "test.h"
3 #include "fluidsynth.h"
4 #include "fluidsynth_priv.h"
5 #include "fluid_synth.h"
6 #include <string.h>
7 
8 static fluid_list_t* realtime_int_settings = NULL;
9 static fluid_list_t* realtime_str_settings = NULL;
10 static fluid_list_t* realtime_num_settings = NULL;
11 
iter_func(void * data,const char * name,int type)12 void iter_func (void *data, const char *name, int type)
13 {
14     if(fluid_settings_is_realtime(data, name))
15     {
16         switch(type)
17         {
18             case FLUID_INT_TYPE:
19                 realtime_int_settings = fluid_list_prepend(realtime_int_settings, FLUID_STRDUP(name));
20                 break;
21             case FLUID_STR_TYPE:
22                 realtime_str_settings = fluid_list_prepend(realtime_str_settings, FLUID_STRDUP(name));
23                 break;
24             case FLUID_NUM_TYPE:
25                 realtime_num_settings = fluid_list_prepend(realtime_num_settings, FLUID_STRDUP(name));
26                 break;
27             case FLUID_SET_TYPE:
28                 break;
29             default:
30                 TEST_ASSERT(FALSE);
31         }
32     }
33 }
34 
35 // this test should make sure that sample rate changed are handled correctly
main(void)36 int main(void)
37 {
38     fluid_list_t* list;
39     fluid_player_t* player;
40     fluid_synth_t *synth;
41     fluid_settings_t *settings = new_fluid_settings();
42     TEST_ASSERT(settings != NULL);
43 
44     synth = new_fluid_synth(settings);
45     TEST_ASSERT(synth != NULL);
46 
47     player = new_fluid_player(synth);
48     TEST_ASSERT(player != NULL);
49 
50     // see which of the objects above has registered a realtime setting
51     fluid_settings_foreach(settings, settings, iter_func);
52 
53     // delete the objects
54     delete_fluid_player(player);
55     delete_fluid_synth(synth);
56 
57     // and now, start making changes to those realtime settings
58     // Anything below fluidsynth 2.1.5 will crash
59 
60     for(list = realtime_int_settings; list; list = fluid_list_next(list))
61     {
62         int min, max;
63         char* name = fluid_list_get(list);
64         TEST_SUCCESS(fluid_settings_getint_range(settings, name, &min, &max));
65         TEST_SUCCESS(fluid_settings_setint(settings, name, min));
66         FLUID_FREE(name);
67     }
68 
69     delete_fluid_list(realtime_int_settings);
70 
71     for(list = realtime_num_settings; list; list = fluid_list_next(list))
72     {
73         double min, max;
74         char* name = fluid_list_get(list);
75         TEST_SUCCESS(fluid_settings_getnum_range(settings, name, &min, &max));
76         TEST_SUCCESS(fluid_settings_setnum(settings, name, min));
77         FLUID_FREE(name);
78     }
79 
80     delete_fluid_list(realtime_num_settings);
81 
82 
83     for(list = realtime_str_settings; list; list = fluid_list_next(list))
84     {
85         char* name = fluid_list_get(list);
86         TEST_SUCCESS(fluid_settings_setstr(settings, name, "ABCDEFG"));
87         FLUID_FREE(name);
88     }
89 
90     delete_fluid_list(realtime_str_settings);
91 
92     delete_fluid_settings(settings);
93 
94     return EXIT_SUCCESS;
95 }
96