8. tchoose

tchoose is a triggerable ftable chooser for an ftlist. It takes in a trigger signal and table position as audio-rate parameters. When triggered, it will update the choose ftable one of the ftables from the list based on the index position.

8.1. Node

A new tchoose node is created with node_tchoose. It needs to take in an ftlist as an argument.

<<tchoose_funcdefs>>=
int node_tchoose(gf_node *node, sp_ftlist *ftl);
<<tchoose_funcs>>=
int node_tchoose(gf_node *node, sp_ftlist *ftl)
{
    gf_node_cables_alloc(node, 2);
    gf_node_set_data(node, ftl);
    gf_node_set_compute(node, compute);
    return GF_OK;
}

The computation is reasonably straight forward. Read the trigger and position cables. Any time the trigger is non-zero, run sp_ftlist_choose.

<<tchoose_static_funcdefs>>=
static void compute(gf_node *node);
<<tchoose_funcs>>=
static void compute(gf_node *node)
{
    int blksize;
    gf_cable *trig;
    gf_cable *index;
    sp_ftlist *ftlst;
    int n;

    blksize = gf_node_blksize(node);

    gf_node_get_cable(node, 0, &trig);
    gf_node_get_cable(node, 1, &index);

    ftlst = gf_node_get_data(node);

    sp_ftlist_reset(ftlst);
    for (n = 0; n < blksize; n++) {
        GFFLT t;

        t = gf_cable_get(trig, n);

        if (t != 0) {
            int i;
            i = floor(gf_cable_get(index, n));
            sp_ftlist_choose_sa(ftlst, i, n);
        }
    }
}

8.2. Runt Loader

tchoose is loaded as a runt word using the function load_tchoose.

<<tchoose_funcdefs>>=
int load_tchoose(runt_vm *vm, runt_ptr pw);
<<tchoose_funcs>>=
int load_tchoose(runt_vm *vm, runt_ptr pw)
{
    runt_cell *c;
    runt_keyword_define(vm, "tchoose", 7, rproc_tchoose, &c);
    runt_cell_data(vm, c, pw);
    return runt_is_alive(vm);
}

8.3. Runt Word

<<tchoose_static_funcdefs>>=
static runt_int rproc_tchoose(runt_vm *vm, runt_ptr p);
<<tchoose_funcdefs>>=
static runt_int rproc_tchoose(runt_vm *vm, runt_ptr p)
{
    runt_int rc;
    gf_patch *patch;
    rgf_param trig;
    rgf_param index;
    sp_ftlist *ftlst;
    gf_node *node;

    rc = rgf_get_ftlist(vm, &ftlst);
    RUNT_ERROR_CHECK(rc);

    rc = rgf_get_param(vm, &index);
    RUNT_ERROR_CHECK(rc);

    rc = rgf_get_param(vm, &trig);
    RUNT_ERROR_CHECK(rc);

    patch = rgf_get_patch(p);

    rc = gf_patch_new_node(patch, &node);
    GF_RUNT_ERROR_CHECK(rc);

    node_tchoose(node, ftlst);

    rgf_set_param(vm, node, &trig, 0);
    rgf_set_param(vm, node, &index, 1);

    return RUNT_OK;
}



prev | home | next