Add linked_count parameter to fluid_list_check_linked_mod()

1)@param linked_count, number of modulators in linked_mod:
      - If > 0, the function assumes that linked_mod contains a table provided
        by the caller. The function returns linked modulators directly in
	this table which is faster because it doesn't allocate memory.
        This is appropriate when the function is called from fluid_voice_add_mod2().
      - If 0, the function makes internal allocation and returns the list in
        linked_mod. This is appropriate when the function is called from
        the soundfont loader as the list of linked modulators must exist during the
	life of the preset it belongs to. NULL is returned in linked_mod if there is
	no linked modulators in list_mod.

   2) Test 10 is added to test_modulator_links.c allowing to test this new  parameter.
This commit is contained in:
jjceresa 2019-09-17 04:05:47 +02:00
parent a0bd115e18
commit 22f94f84d9
2 changed files with 287 additions and 61 deletions

View File

@ -1703,6 +1703,11 @@ fluid_check_linked_mod_path(char *list_name, fluid_mod_t *list_mod,
*
* @param linked_mod, address of pointer on linked modulators list returned
* if any linked modulators exist.
* @param linked_count, number of modulators in linked_mod:
* - If > 0, the function assumes that linked_mod contains a table provided
* by the caller. The function returns linked modulators directly in this table.
* - If 0, the function makes internal allocation and returns the list in
* linked_mod.
*
* @return
* - number of linked modulators returned in linked_mod if any valid
@ -1713,7 +1718,8 @@ fluid_check_linked_mod_path(char *list_name, fluid_mod_t *list_mod,
static int
fluid_list_copy_linked_mod(const fluid_mod_t *list_mod, int dest_idx, int new_idx,
const unsigned char path[],
fluid_mod_t **linked_mod)
fluid_mod_t **linked_mod,
int linked_count)
{
int total_linked_count = 0; /* number of linked modulator to return */
int linked_idx = new_idx; /* Last added modulator index in linked_mod */
@ -1737,41 +1743,67 @@ fluid_list_copy_linked_mod(const fluid_mod_t *list_mod, int dest_idx, int new_id
if (is_mod_dst_only || is_mod_src)
{
/* Make a copy of this modulator */
fluid_mod_t *mod_cpy = new_fluid_mod(); /* next field is set to NULL */
if(mod_cpy == NULL)
{
delete_fluid_list_mod(*linked_mod); /* freeing */
*linked_mod = NULL;
return FLUID_FAILED;
fluid_mod_t *mod_cpy;
if(linked_count <= 0) /* linked_mod must be allocated internally */
{
mod_cpy = new_fluid_mod(); /* next field is set to NULL */
if(mod_cpy == NULL)
{
delete_fluid_list_mod(*linked_mod); /* freeing */
*linked_mod = NULL;
return FLUID_FAILED;
}
}
/* adding mod_cpy in linked_mod */
if (linked_idx == 0) /* the list is empty */
{
if(linked_count <= 0) /* list is allocated internally */
{
/* puts mod_cpy at the begin of linked list */
*linked_mod = mod_cpy;
}
else /* list is external given by linked_mod table */
{
/* get first entry from external linked_mod table */
mod_cpy = *linked_mod;
mod_cpy->next = NULL;
}
}
else /* the list isn't empty */
{
/* Find the last modulator in the list */
fluid_mod_t * last_mod = *linked_mod;
int count = 1;
while (last_mod->next != NULL)
{
last_mod = last_mod->next;
count++;
}
if(linked_count > 0) /* list is external */
{
/* check if external table length is exceeded */
if(count >= linked_count)
{
return FLUID_FAILED;
}
mod_cpy = last_mod + 1; /* next entry in table */
mod_cpy->next = NULL;
}
/* puts mod_cpy at the end of linked list */
last_mod->next = mod_cpy;
}
fluid_mod_clone(mod_cpy, mod);
/* updates destination field of mod_cpy (but ending modulator) */
/* updates destination field of mod_cpy (except ending modulator) */
if (is_mod_src)
{
/* new destination field must be an index 0 based. */
mod_cpy->dest = FLUID_MOD_LINK_DEST | (new_idx - 1);
}
/* adding mod_cpy in linked_mod */
if (linked_idx == 0)
{
/* puts mod_cpy at the begin of linked list */
*linked_mod = mod_cpy;
}
else
{
/* puts mod_cpy at the end of linked list */
fluid_mod_t * last_mod = *linked_mod;
/* Find the end of the list */
while (last_mod->next != NULL){ last_mod = last_mod->next; }
last_mod->next = mod_cpy;
}
/* force index of ending modulator to 0 */
if (is_mod_dst_only)
else /* mod is an ending modulator */
{
linked_idx = 0;
linked_idx = 0; /* force index of ending modulator to 0 */
}
linked_idx++; /* updates count of linked mod */
@ -1780,7 +1812,8 @@ fluid_list_copy_linked_mod(const fluid_mod_t *list_mod, int dest_idx, int new_id
{ /* search a modulator with output linked to mod */
linked_idx = fluid_list_copy_linked_mod(list_mod,
mod_idx | FLUID_MOD_LINK_DEST,
linked_idx, path, linked_mod);
linked_idx, path,
linked_mod, linked_count);
if(linked_idx == FLUID_FAILED)
{
return FLUID_FAILED;
@ -1828,8 +1861,17 @@ fluid_list_copy_linked_mod(const fluid_mod_t *list_mod, int dest_idx, int new_id
* to 0.
*
* @param linked_mod, if not NULL, address of pointer on linked modulators
* list returned. NULL is returned in this pointer if linked
* modulators doesn't exist in list_mod.
* list returned.
* @param linked_count, number of modulators in linked_mod:
* - If > 0, the function assumes that linked_mod contains a table provided
* by the caller. The function returns linked modulators directly in this table
* which is faster because it doesn't allocate memory.
* This is appropriate when the function is called from fluid_voice_add_mod2().
* - If 0, the function makes internal allocation and returns the list in
* linked_mod. This is appropriate when the function is called from the
* soundfont loader as the list of linked modulators must exist during the
* life of the preset it belongs to. NULL is returned in linked_mod if there is
* no linked modulators in list_mod.
* @return
* - the number of linked modulators if any valid linked path exists.
* - 0 if no linked path exists.
@ -1837,7 +1879,8 @@ fluid_list_copy_linked_mod(const fluid_mod_t *list_mod, int dest_idx, int new_id
*/
int
fluid_list_check_linked_mod(char *list_name, fluid_mod_t *list_mod,
fluid_mod_t **linked_mod)
fluid_mod_t **linked_mod,
int linked_count)
{
int result;
/* path is a flags table state to register valid modulators belonging
@ -1918,13 +1961,17 @@ fluid_list_check_linked_mod(char *list_name, fluid_mod_t *list_mod,
/* clone of linked modulators if requested */
if(linked_mod)
{
*linked_mod = NULL; /* Initialize linked modulator list to NULL */
if(linked_count <= 0)
{
*linked_mod = NULL; /* Initialize linked modulator list to NULL */
}
/* does one or more valid linked modulators exists ? */
if(result)
{
/* one or more linked modulators paths exists */
/* clone valid linked modulator paths from list_mod to linked_mod.*/
result = fluid_list_copy_linked_mod(list_mod, -1, 0, path, linked_mod);
result = fluid_list_copy_linked_mod(list_mod, -1, 0, path,
linked_mod, linked_count);
}
}
@ -2043,9 +2090,10 @@ fluid_zone_check_mod(char *zone_name, fluid_mod_t **list_mod,
/* Checks linked modulators paths from a zone modulators list list_mod.
Because the function is called by the soundfont loader it is a good pratice
to do full check which is requested by given a zone name not NULL.
Then, clone valid linked modulators paths from list_mod to linked_mod.
Then, clone valid linked modulators paths from list_mod to linked_mod
(The linked modulators list is allocated and returned in linked_mod).
*/
if(fluid_list_check_linked_mod(zone_name, *list_mod, linked_mod) == FLUID_FAILED)
if(fluid_list_check_linked_mod(zone_name, *list_mod, linked_mod, 0) == FLUID_FAILED)
{
return FLUID_FAILED;
}

View File

@ -4,10 +4,21 @@
#include "synth/fluid_mod.h"
#include "utils/fluid_sys.h"
int fluid_list_check_linked_mod(char *zone_name, fluid_mod_t *list_mod,
fluid_mod_t **linked_mod);
//----------------------------------------------------------------------------
/* external functions */
int
fluid_list_check_linked_mod(char *list_name, fluid_mod_t *list_mod,
fluid_mod_t **linked_mod,
int linked_count);
void delete_fluid_list_mod(fluid_mod_t *list_mod);
int fluid_get_count_mod(const fluid_mod_t *mod);
//----------------------------------------------------------------------------
static fluid_mod_t * fluid_build_list(fluid_mod_t mod_table[], int count_mod);
int fluid_list_test_identity(fluid_mod_t *list_mod1, fluid_mod_t *list_mod2);
// tests the linked "nature" of modulators, i.e. fluid_list_check_linked_mod()
int main(void)
{
@ -44,7 +55,7 @@ int main(void)
fluid_mod_set_dest (mod2, GEN_ATTENUATION);
// Return must be 0
linked_count = fluid_list_check_linked_mod("test zone with simple modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with simple modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
// order of modulators remains the same
@ -69,7 +80,7 @@ int main(void)
// - NULL must be returned in linked_mod
// - 0 must be returned in linked_count
linked_mod = mod0; // initialize linked_mod to non NULL.
linked_count = fluid_list_check_linked_mod("test zone with simple modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with simple modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(linked_mod == NULL);
}
@ -102,7 +113,7 @@ int main(void)
fluid_mod_set_dest (mod2, FLUID_MOD_LINK_DEST | 0);
// Return must be 3
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 3);
// order not changed
@ -127,7 +138,7 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 3 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 3);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
@ -146,7 +157,7 @@ int main(void)
list_of_mods = mod0;
// Return must be 3
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 3);
TEST_ASSERT(list_of_mods == mod0);
@ -170,7 +181,7 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 3 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 3);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
@ -195,7 +206,7 @@ int main(void)
list_of_mods = mod0;
// Return must be 3
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 3);
TEST_ASSERT(list_of_mods == mod0);
@ -221,7 +232,7 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 3 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 3);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
@ -244,7 +255,7 @@ int main(void)
list_of_mods = mod0;
// Return must be 4
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 4);
TEST_ASSERT(list_of_mods == mod0);
@ -270,7 +281,7 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 4 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 4);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
@ -294,7 +305,7 @@ int main(void)
list_of_mods = mod0;
// Return must be 2
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(list_of_mods == mod0);
@ -333,7 +344,7 @@ int main(void)
mod0->next = mod1;
list_of_mods = mod0;
// It remains at least one linked path : mod2->mod0. Return must be 2
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(list_of_mods == mod0);
@ -359,7 +370,7 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 2 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
@ -391,7 +402,7 @@ int main(void)
// Circular path is: CC->mod2, mod0, mod1.
// Remaining path CC->mod3-> is without destination.
// It remains no linked path : mod2->mod0. Return must be 0
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(list_of_mods == mod0);
@ -417,7 +428,7 @@ int main(void)
// - NULL must be returned in linked_mod
// - 0 must be returned in linked_count
linked_mod = mod0; // initialize linked_mod to not NULL.
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(linked_mod == NULL);
}
@ -452,7 +463,7 @@ int main(void)
fluid_mod_set_dest (mod3, FLUID_MOD_LINK_DEST | 2);
// return must be 0
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(list_of_mods == mod0);
@ -498,7 +509,7 @@ int main(void)
fluid_mod_set_dest (mod3, FLUID_MOD_LINK_DEST | 1);
// return must be 0
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(list_of_mods == mod0);
@ -545,7 +556,7 @@ int main(void)
fluid_mod_set_dest (mod3, FLUID_MOD_LINK_DEST | 1);
// return must be 0
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
TEST_ASSERT(list_of_mods == mod0);
@ -594,7 +605,7 @@ int main(void)
fluid_mod_set_dest (mod3, FLUID_MOD_LINK_DEST | 1);
// return must be 2
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with circular linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(list_of_mods == mod0);
@ -640,7 +651,7 @@ int main(void)
fluid_mod_set_dest (mod2, FLUID_MOD_LINK_DEST | 0);
// return must be 0
linked_count = fluid_list_check_linked_mod("test zone with invalid linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with invalid linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 0);
// order is not changed
@ -684,7 +695,7 @@ int main(void)
fluid_mod_set_dest (mod2, FLUID_MOD_LINK_DEST | 0);
// return must be 2
linked_count = fluid_list_check_linked_mod("test zone with invalid linked modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with invalid linked modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 2);
// order is not changed
@ -733,7 +744,7 @@ int main(void)
list_of_mods = mod0;
// return must be 2
linked_count = fluid_list_check_linked_mod("test zone with isolated modulators", list_of_mods, NULL);
linked_count = fluid_list_check_linked_mod("test zone with isolated modulators", list_of_mods, NULL, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(list_of_mods == mod0);
@ -759,12 +770,115 @@ int main(void)
// - not NULL must be returned in linked_mod
// - 2 must be returned in linked_count
linked_mod = NULL; // initialize linked_mod to NULL.
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod);
linked_count = fluid_list_check_linked_mod("test zone with linked modulators", list_of_mods, &linked_mod, 0);
TEST_ASSERT(linked_count == 2);
TEST_ASSERT(linked_mod != NULL);
delete_fluid_list_mod(linked_mod);
}
// Test 10: getting a list of linked modulators in table.
// Check a same valid complex modulateur 2 times but returned in two distinct.
// linked list (linked_mod1, linked_mod2).
// - linked_mod1 is allocated internally.
// - linked_mod2 is a table given by the caller.
// Both linked_mod1 and linked_mod2 are compared and expected to be identic.
printf("\nTest 10: getting a list of linked modulators in table\n");
{
/* One valid complex modulators with 5 members */
/* table : att<-m0<-m1<-m2<- */
/* m0<-m3<-m4<- */
fluid_mod_t mod_table[] =
{
/* Gen<-mod0-link<- */
{
// dest , src1 , flags1 , src2 , flags2
GEN_VOLENVHOLD , FLUID_MOD_LINK_SRC, FLUID_MOD_GC , FLUID_MOD_NONE , FLUID_MOD_GC,
// amount, link, next
1.0 , 0.0 , NULL
},
/* mod0<-mod1<- */
{
// dest , src1 , flags1 , src2 , flags2
0|FLUID_MOD_LINK_DEST, FLUID_MOD_LINK_SRC, FLUID_MOD_GC , FLUID_MOD_VELOCITY, FLUID_MOD_GC,
// amount, link, next
2.0 , 0.0 , NULL
},
/* mod1<-mod2<- */
{
// dest , src1 , flags1 , src2 , flags2
1|FLUID_MOD_LINK_DEST, 2 , FLUID_MOD_CC , FLUID_MOD_NONE , FLUID_MOD_GC,
// amount, link, next
3.0 , 0.0 , NULL
},
/* mod0<-mod3<- */
{
// dest , src1 , flags1 , src2 , flags2
0|FLUID_MOD_LINK_DEST, FLUID_MOD_LINK_SRC, FLUID_MOD_GC , FLUID_MOD_NONE , FLUID_MOD_GC,
// amount, link, next
4.0 , 0.0 , NULL
},
/* mod3<-mod4<- */
{
// dest , src1 , flags1 , src2 , flags2
3|FLUID_MOD_LINK_DEST, 2 , FLUID_MOD_CC , FLUID_MOD_NONE , FLUID_MOD_GC,
// amount, link, next
5.0 , 0.0 , NULL
}
};
//--- Input list build from the table mod_table
int mod_count; // number of modulators in table mod_table.
fluid_mod_t * list_mod1; // first input list, build from mod_table.
fluid_mod_t * list_mod2; // second input list, build from mod_table.
//--- first output list of linked modulators (allocated internally)
fluid_mod_t * linked_mod1; // first output list of linked modulators
int linked_count1_out; // count of modulators returned in linked_mod1
//--- second output list of linked modulators. The table is given by the caller
fluid_mod_t * linked_mod2; // second output list of linked modulators (in table)
int linked_count2_in; // length of linked_mod2 table
int linked_count2_out; // count of modulators returned in linked_mod2
//---------------------------------------------
// build input list list_mod1, list_mod2
mod_count = sizeof(mod_table) / sizeof(fluid_mod_t);
TEST_ASSERT(mod_count == 5);
list_mod1 = fluid_build_list(mod_table, mod_count);
TEST_ASSERT(list_mod1 != NULL);
TEST_ASSERT(fluid_get_count_mod(list_mod1) == 5);
//
list_mod2 = fluid_build_list(mod_table, mod_count);
TEST_ASSERT(list_mod2 != NULL);
TEST_ASSERT(fluid_get_count_mod(list_mod2) == 5);
// compare input list list_mod1, and list_mod2.
TEST_ASSERT(fluid_list_test_identity(list_mod1, list_mod2) == TRUE);
//---------------------------------------------
// building output linked list linked_mod1
// linked_mod1 allocated internally.
linked_mod1 = NULL;
linked_count1_out = fluid_list_check_linked_mod("linked_mod1(internal)",
list_mod1, &linked_mod1, 0);
// linked_mod1 must be not NULL and linked_count1_out must be equal to 5
TEST_ASSERT(linked_mod1 != NULL);
TEST_ASSERT(linked_count1_out == 5);
//---------------------------------------------
// building output linked list linked_mod2
// linked_mod1 allocated externally on (stack).
linked_count2_in = fluid_get_count_mod(list_mod2);
linked_mod2 = alloca( linked_count2_in * sizeof(fluid_mod_t));
// linked_mod1 must be not NULL and linked_count1_out must be equal to 5
TEST_ASSERT(linked_mod2 != NULL);
linked_count2_out = fluid_list_check_linked_mod("linked_mod2(external)",
list_mod2, &linked_mod2,
linked_count2_in);
TEST_ASSERT(linked_count2_out == 5);
// compare output list linked_mod1, and linked_mod2.
TEST_ASSERT(fluid_list_test_identity(linked_mod1, linked_mod2) == TRUE);
// freeing
delete_fluid_list_mod(list_mod1);
delete_fluid_list_mod(list_mod2);
delete_fluid_list_mod(linked_mod1);
}
delete_fluid_mod(mod0);
delete_fluid_mod(mod1);
delete_fluid_mod(mod2);
@ -772,3 +886,67 @@ int main(void)
return EXIT_SUCCESS;
}
/*
A convenience function that builds a list of modulators from a modulator table
mod_table (duplicated in test_fluid_zone_check_mod.c).
*/
static fluid_mod_t * fluid_build_list(fluid_mod_t mod_table[], int count_mod)
{
int i;
fluid_mod_t * prev;
fluid_mod_t *list_mod = NULL;
/* build list_mod containing test modulators from mod_table */
for(i = 0; i < count_mod; i++)
{
/* Make a copy of this modulator */
fluid_mod_t * mod = new_fluid_mod();
if(mod == NULL)
{
FLUID_LOG(FLUID_ERR, "Out of memory");
delete_fluid_list_mod(list_mod);
return NULL;
}
fluid_mod_clone(mod, &mod_table[i]);
mod->next = NULL;
/* add to list_mode */
if(i == 0)
{
list_mod = mod;
}
else
{
prev->next = mod;
}
prev =mod;
}
return list_mod;
}
/**
* Return TRUE if list list_mod1 is identic to list list_mod2,
* FALSE otherwise.
*/
int fluid_list_test_identity(fluid_mod_t *list_mod1, fluid_mod_t *list_mod2)
{
int count1 = fluid_get_count_mod(list_mod1);
int count2 = fluid_get_count_mod(list_mod2);
if (count1 != count2)
{
return FALSE;
}
while(list_mod1)
{
if( ! fluid_mod_test_identity(list_mod1, list_mod2) ||
list_mod1->amount != list_mod2->amount)
{
return FALSE;
}
list_mod1 = list_mod1->next;
list_mod2 = list_mod2->next;
}
return TRUE;
}