Exemplo n.º 1
0
Arquivo: ref.c Projeto: Luckyncl/3rd
int sporth_ref(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    char *str;
    switch(pd->mode) {
        case PLUMBER_CREATE: 
            plumber_add_ugen(pd, SPORTH_REF, NULL);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                stack->error++;
                fprintf(stderr, "ref: Invalid arguments.");
                return PLUMBER_NOTOK;
            }
            sporth_stack_pop_string(stack);
            break;
        case PLUMBER_INIT: 
            str = sporth_stack_pop_string(stack);
            plumber_ftmap_delete(pd, 0);
            /* get reference of the *next* pipe in the plumbing */
            plumber_ftmap_add_userdata(pd, str, pd->next->ud);
            plumber_ftmap_delete(pd, 1);
            break;
        case PLUMBER_COMPUTE: 
            break;
        case PLUMBER_DESTROY: 
            break;
    }
    return PLUMBER_OK;
}
Exemplo n.º 2
0
int plumber_create_var(plumber_data *pd, char *name, SPFLOAT **var)
{
    SPFLOAT *ptr = malloc(sizeof(SPFLOAT));
    plumber_ftmap_add_userdata(pd, name, ptr);
    *var = ptr;
    return PLUMBER_OK;
}
Exemplo n.º 3
0
int sporth_slist(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    char *filename;
    uint32_t size;
    slist_d *sl;

    switch(pd->mode){
        case PLUMBER_CREATE:
            sl = malloc(sizeof(slist_d));
            sl->list = NULL;
            plumber_add_ugen(pd, SPORTH_SLIST, sl);
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
               plumber_print(pd,"Not enough arguments for slist\n");
                return PLUMBER_NOTOK;
            }
            filename = sporth_stack_pop_string(stack);
            size = sporth_stack_pop_float(stack);
            ftname = sporth_stack_pop_string(stack);
            if(slist_parse(sl, filename, size) != PLUMBER_OK) {
                plumber_print(pd, 
                        "slist: could not load file %s\n",
                        filename);
                return PLUMBER_NOTOK;
            }
            plumber_ftmap_add_userdata(pd, ftname, sl);

            break;

        case PLUMBER_INIT:
            sporth_stack_pop_string(stack);
            sporth_stack_pop_float(stack);
            sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            sl = pd->last->ud;
            slist_destroy(sl);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
Exemplo n.º 4
0
int sporth_fload(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sporth_fload_d *fload;
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "fload: creating\n");
#endif
            fload = malloc(sizeof(sporth_fload_d));
            plumber_add_ugen(pd, SPORTH_FLOAD, fload);
            if(sporth_check_args(stack, "ss") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for fload\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            fload->filename= sporth_stack_pop_string(stack);
            fload->name = sporth_stack_pop_string(stack);
           
            fload->handle = dlopen(fload->filename, RTLD_NOW);
            if(fload->handle == NULL) {
                fprintf(stderr, "Error loading %s: %s\n", fload->name, dlerror());
                return PLUMBER_NOTOK;
            }

            fload->getter = dlsym(fload->handle, "sporth_return_ugen");
            fload->fun = fload->getter();
            plumber_ftmap_add_userdata(pd, fload->name, (void *)fload);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            fprintf(stderr, "fload: initialising\n");
#endif
            fload = pd->last->ud;
            fload->filename= sporth_stack_pop_string(stack);
            fload->name = sporth_stack_pop_string(stack);

            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            break;
        default:
            fprintf(stderr, "fload: unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
Exemplo n.º 5
0
int sporth_talias(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    char *varname;
    uint32_t index;
    SPFLOAT *var;
    sp_ftbl *ft;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_TALIAS, NULL);
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
               plumber_print(pd,"Init: incorrect arguments for talias\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            index = sporth_stack_pop_float(stack);
            varname = sporth_stack_pop_string(stack);

            if(plumber_ftmap_search(pd, ftname, &ft) == PLUMBER_NOTOK) {
                plumber_print(pd, "talias: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
           
            var = &ft->tbl[index];

            plumber_ftmap_delete(pd, 0);
            plumber_ftmap_add_userdata(pd, varname, var);
            plumber_ftmap_delete(pd, 1);

            break;

        case PLUMBER_INIT:
            ftname = sporth_stack_pop_string(stack);
            index = sporth_stack_pop_float(stack);
            varname = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;
    }
    return PLUMBER_OK;
}
Exemplo n.º 6
0
int sporth_varset(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    SPFLOAT *var;
    SPFLOAT val;
    char *str;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_VARSET, NULL);
            if(sporth_check_args(stack, "sf") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for varset\n");
                return PLUMBER_NOTOK;
            }
            val = sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
#ifdef DEBUG_MODE
            fprintf(stderr, "var: creating table %s\n", str);
#endif
            var = malloc(sizeof(SPFLOAT));
            *var = val;
            plumber_ftmap_add_userdata(pd, str, var);
            break;

        case PLUMBER_INIT:
            sporth_stack_pop_float(stack);
            sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           fprintf(stderr, "Error: Unknown mode!\n");
           break;
    }
    return PLUMBER_OK;
}