예제 #1
0
파일: p.c 프로젝트: aure/Sporth
int sporth_palias(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    char *name;
    int id;
    SPFLOAT *foo;

    switch(pd->mode) {
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_PALIAS, NULL);
            if(sporth_check_args(stack, "sf") != SPORTH_OK) {
                fprintf(stderr,"palias: Not enough arguments\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            id = floor(sporth_stack_pop_float(stack));
            name = sporth_stack_pop_string(stack);
            foo = &pd->p[id];
            plumber_ftmap_delete(pd, 0);
            plumber_set_var(pd, name, foo);
            plumber_ftmap_delete(pd, 1);
            break;
        case PLUMBER_INIT:
            sporth_stack_pop_float(stack);
            sporth_stack_pop_string(stack);
            break;
        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;
        default:
            break;
    }

    return PLUMBER_OK;
}
예제 #2
0
파일: ref.c 프로젝트: 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;
}
예제 #3
0
int sporth_print(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sporth_print_d *prnt;
    char *str = NULL; 
    SPFLOAT val = 0;
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "print: Creating\n");
#endif
            prnt = malloc(sizeof(sporth_print_d));
            plumber_add_ugen(pd, SPORTH_PRINT, prnt);
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for print\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            str = sporth_stack_pop_string(stack);
            val = sporth_stack_pop_float(stack);
            
            strncpy(prnt->label, str, 128);
            prnt->pval = val; 
            prnt->init = 1;
            sporth_stack_push_float(stack, val);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            fprintf(stderr, "print: Initialising\n");
#endif
            prnt = pd->last->ud;
            str = sporth_stack_pop_string(stack);
            val = sporth_stack_pop_float(stack);
            sporth_stack_push_float(stack, val);
            break;
        case PLUMBER_COMPUTE:
            prnt = pd->last->ud;
            val = sporth_stack_pop_float(stack);
            if(val != prnt->pval || prnt->init) {
                prnt->pval = val;
                prnt->init = 0;
                printf("%s: %g\n", prnt->label, val);
            }
            sporth_stack_push_float(stack, val);
            break;
        case PLUMBER_DESTROY:
            prnt = pd->last->ud;
            free(prnt);
            break;
        default:
            fprintf(stderr, "print: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
예제 #4
0
int sporth_fexec(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sporth_fload_d *fexec;
    sporth_fload_d *fload;
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "fexec: creating\n");
#endif
            fexec = malloc(sizeof(sporth_fload_d));
            plumber_add_ugen(pd, SPORTH_FEXEC, fexec);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for fclose\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            fexec->name = sporth_stack_pop_string(stack);
           
            if(plumber_ftmap_search_userdata(pd, fexec->name, (void *)&fload) == PLUMBER_NOTOK) {
                stack->error++;
                return PLUMBER_NOTOK;
            }
            fexec->fun = fload->fun;
            fexec->fun(pd, stack, &fexec->ud);
            break;
        case PLUMBER_INIT:

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

            fexec->fun(pd, stack, &fexec->ud);
            break;

        case PLUMBER_COMPUTE:
            fexec = pd->last->ud;
            fexec->fun(pd, stack, &fexec->ud);
            break;

        case PLUMBER_DESTROY:
            fexec = pd->last->ud;
            fexec->fun(pd, stack, &fexec->ud);
            free(fexec);
            break;
        default:
            fprintf(stderr, "fexec: unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
예제 #5
0
파일: gen_line.c 프로젝트: Luckyncl/3rd
int sporth_gen_line(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    int size;
    sp_ftbl *ft;
    char *str;
    char *args;

    switch(pd->mode){
        case PLUMBER_CREATE:
#ifdef DEBUG_MODE
            fprintf(stderr, "gen_line: create mode\n");
#endif
            plumber_add_ugen(pd, SPORTH_GEN_LINE, NULL);
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_line\n");
                return PLUMBER_NOTOK;
            }
            args = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
#ifdef DEBUG_MODE
            fprintf(stderr, "Creating line table %s of size %d\n", str, size);
#endif
            sp_ftbl_create(pd->sp, &ft, size);
            if(sp_gen_line(pd->sp, ft, args) == SP_NOT_OK) {
                fprintf(stderr, "There was an issue creating the line ftable \"%s\".\n", str);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            plumber_ftmap_add(pd, str, ft);
            break;

        case PLUMBER_INIT:

            args = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
예제 #6
0
int sporth_sget(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    uint32_t index = 0;
    slist_d *sl;
    char **str = NULL;
    switch(pd->mode){
        case PLUMBER_CREATE:
            str = malloc(sizeof(char *));
            plumber_add_ugen(pd, SPORTH_SGET, str);
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
               plumber_print(pd,"Not enough arguments for sget\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            index = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search_userdata(pd,ftname, (void *)&sl) != 
                    PLUMBER_OK) {
                plumber_print(pd, "Could not find ftable %s\n", ftname);
                return PLUMBER_NOTOK;
            }
            if(index > sl->len - 1) {
                plumber_print(pd, "Index %d exceeds slist length %d\n",
                        index, sl->len);
                return PLUMBER_NOTOK;
            }
            *str = sl->list[index];
            sporth_stack_push_string(stack, &sl->list[index]);
            break;

        case PLUMBER_INIT:
            str = pd->last->ud;
            sporth_stack_pop_string(stack);
            sporth_stack_pop_float(stack);
            sporth_stack_push_string(stack, str);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            str = pd->last->ud;
            free(str);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #7
0
int sporth_fclose(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sporth_fclose_d *fclose;
    sporth_fload_d *fload;
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            fprintf(stderr, "fclose: creating\n");
#endif
            fclose = malloc(sizeof(sporth_fclose_d));
            plumber_add_ugen(pd, SPORTH_FCLOSE, fclose);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                fprintf(stderr,"Not enough arguments for fclose\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            fclose->name = sporth_stack_pop_string(stack);
           
            if(plumber_ftmap_search_userdata(pd, fclose->name, (void *)&fload) == PLUMBER_NOTOK) {
                stack->error++;
                return PLUMBER_NOTOK;
            }
            fclose->handle = fload->handle;
            break;
        case PLUMBER_INIT:

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

            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
#ifdef DEBUG_MODE
            fprintf(stderr, "fclose: destroying\n");
#endif
            fclose= pd->last->ud;
            dlclose(fclose->handle);
            free(fclose);
            break;
        default:
            fprintf(stderr, "fclose: unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
예제 #8
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;
}
예제 #9
0
파일: gen_file.c 프로젝트: Luckyncl/3rd
int sporth_gen_file(sporth_stack *stack, void *ud)
{
#ifndef NO_LIBSNDFILE
    plumber_data *pd = ud;

    sp_ftbl *ft;
    char *str;
    char *filename;
    int size;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_FILE, NULL);
            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_file\n");
                return PLUMBER_NOTOK;
            }

            filename = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            sp_ftbl_create(pd->sp, &ft, size);
            if(sp_gen_file(pd->sp, ft, filename) == SP_NOT_OK) {
                fprintf(stderr, "There was an issue creating the ftable \"%s\".\n", str);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            plumber_ftmap_add(pd, str, ft);
            break;

        case PLUMBER_INIT:
            filename = sporth_stack_pop_string(stack);
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
#else
    return PLUMBER_NOTOK;
#endif
}
예제 #10
0
int sporth_gen_composite(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    uint32_t size;
    sp_ftbl *ft;
    char *str, *args;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_COMPOSITE, NULL);

            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
               fprintf(stderr,"composite: not enough arguments for gen_vals\n");
                return PLUMBER_NOTOK;
            }

            args = sporth_stack_pop_string(stack);
            size = (uint32_t)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);

            sp_ftbl_create(pd->sp, &ft, size);

            sp_gen_composite(pd->sp, ft, args);

            plumber_ftmap_add(pd, str, ft);

            free(args);
            free(str);
            break;

        case PLUMBER_INIT:
            args = sporth_stack_pop_string(stack);
            size = (uint32_t)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            free(str);
            free(args);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
          fprintf(stderr,"Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
예제 #11
0
파일: t.c 프로젝트: PaulBatchelor/AudioKit
int sporth_tset(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sporth_tbl_d *td;
    char *ftname;

    switch(pd->mode){
        case PLUMBER_CREATE:
            td = malloc(sizeof(sporth_tbl_d));
            plumber_add_ugen(pd, SPORTH_TSET, td);
            if(sporth_check_args(stack, "ffs") != SPORTH_OK) {
               plumber_print(pd,"Init: not enough arguments for tset\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search(pd, ftname, &td->ft) == PLUMBER_NOTOK) {
                plumber_print(pd, "tset: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            td->ft->tbl[td->index] = td->val;
            break;

        case PLUMBER_INIT:
            td = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            td->index = floor(sporth_stack_pop_float(stack));
            td->val = sporth_stack_pop_float(stack);
            td->ft->tbl[td->index] = td->val;
            break;

        case PLUMBER_COMPUTE:
            td = pd->last->ud;
            td->index = (unsigned int) floor(sporth_stack_pop_float(stack)) % td->ft->size;
            td->val = sporth_stack_pop_float(stack);
            td->ft->tbl[td->index] = td->val;
            break;

        case PLUMBER_DESTROY:
            td = pd->last->ud;
            free(td);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #12
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;
}
예제 #13
0
파일: t.c 프로젝트: BillGrim/AudioKit
int sporth_tblsize(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    sp_ftbl *ft;
    size_t *tsize;

    switch(pd->mode){
        case PLUMBER_CREATE:
            tsize = malloc(sizeof(uint32_t));
            plumber_add_ugen(pd, SPORTH_TBLSIZE, tsize);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
               fprintf(stderr,"Init: not enough arguments for tblsize\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            if(plumber_ftmap_search(pd, ftname, &ft) == PLUMBER_NOTOK) {
                fprintf(stderr, "tblsize: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            *tsize = ft->size;
            free(ftname);
            sporth_stack_push_float(stack, *tsize);
            break;

        case PLUMBER_INIT:
            tsize = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            *tsize = ft->size;
            free(ftname);
            sporth_stack_push_float(stack, *tsize);
            break;

        case PLUMBER_COMPUTE:
            tsize = pd->last->ud;
            sporth_stack_push_float(stack, (SPFLOAT) *tsize);
            break;

        case PLUMBER_DESTROY:
            tsize = pd->last->ud;
            free(tsize);
            break;

        default:
            fprintf(stderr,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #14
0
파일: t.c 프로젝트: PaulBatchelor/AudioKit
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;
}
예제 #15
0
int sporth_load(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    plumbing *pipes;

    FILE *tmp, *fp;
    char *filename;
    int rc = PLUMBER_OK;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_LOAD, NULL);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                plumber_print(pd, "Not enough arguments for load.\n");
                return PLUMBER_NOTOK;
            }

            filename = sporth_stack_pop_string(stack);
            fp = fopen(filename, "r");
            if(fp == NULL) {
                plumber_print(pd, 
                        "There was an issue opening the file \"%s\"\n",
                        filename);
                return PLUMBER_NOTOK;
            }
            tmp = pd->fp;
            pd->fp = fp;
            pipes = plumber_get_pipes(pd);
            rc = plumbing_parse(pd, pipes);
            fclose(fp);
            pd->fp = tmp;
            return rc;

        case PLUMBER_INIT:
            filename = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
예제 #16
0
int sporth_slick(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    uint32_t index = 0;
    slist_d *sl;
    char **str = NULL;
    switch(pd->mode){
        case PLUMBER_CREATE:
            str = malloc(sizeof(char *));
            plumber_add_ugen(pd, SPORTH_SLICK, str);

            if(sporth_check_args(stack, "s") != SPORTH_OK) {
               plumber_print(pd,"Not enough arguments for slick\n");
                return PLUMBER_NOTOK;
            }

            ftname = sporth_stack_pop_string(stack);
            if(plumber_ftmap_search_userdata(pd,ftname, (void *)&sl) != 
                    PLUMBER_OK) {
                plumber_print(pd, "Could not find ftable %s\n", ftname);
                return PLUMBER_NOTOK;
            }
            index = (uint32_t)(((SPFLOAT)sp_rand(pd->sp) / SP_RANDMAX) * sl->len);
            *str = sl->list[index];
            sporth_stack_push_string(stack, &sl->list[index]);
            break;

        case PLUMBER_INIT:
            str = pd->last->ud;
            sporth_stack_pop_string(stack);
            sporth_stack_push_string(stack, str);
            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            str = pd->last->ud;
            free(str);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #17
0
int sporth_set(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    SPFLOAT **var;
    SPFLOAT val;
    switch(pd->mode){
        case PLUMBER_CREATE:
            var = malloc(sizeof(SPFLOAT *));
            plumber_add_ugen(pd, SPORTH_SET, var);
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
               fprintf(stderr,"Not enough arguments for get\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            val = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search_userdata(pd, ftname, (void **)var) == PLUMBER_NOTOK) {
                fprintf(stderr, "set: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            **var = val;
            break;

        case PLUMBER_INIT:
            var = pd->last->ud;
            sporth_stack_pop_string(stack);
            val = sporth_stack_pop_float(stack);
            **var = val;
            break;

        case PLUMBER_COMPUTE:
            var = pd->last->ud;
            val = sporth_stack_pop_float(stack);
            **var = val;
            break;

        case PLUMBER_DESTROY:
            var = pd->last->ud;
            free(var);
            break;

        default:
            fprintf(stderr,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #18
0
파일: t.c 프로젝트: PaulBatchelor/AudioKit
int sporth_tbldur(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    char *ftname;
    sp_ftbl *ft;
    SPFLOAT *tlen;

    switch(pd->mode){
        case PLUMBER_CREATE:
            tlen = malloc(sizeof(SPFLOAT));
            plumber_add_ugen(pd, SPORTH_TBLDUR, tlen);
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
               plumber_print(pd,"Init: not enough arguments for tget\n");
                return PLUMBER_NOTOK;
            }
            ftname = sporth_stack_pop_string(stack);
            if(plumber_ftmap_search(pd, ftname, &ft) == PLUMBER_NOTOK) {
                plumber_print(pd, "tblen: could not find table '%s'\n", ftname);
                stack->error++;
                return PLUMBER_NOTOK;
            }
            *tlen = (SPFLOAT) ft->size / pd->sp->sr;
            sporth_stack_push_float(stack, (SPFLOAT) *tlen);
            break;

        case PLUMBER_INIT:
            tlen = pd->last->ud;
            ftname = sporth_stack_pop_string(stack);
            sporth_stack_push_float(stack, (SPFLOAT) *tlen);
            break;

        case PLUMBER_COMPUTE:
            tlen = pd->last->ud;
            sporth_stack_push_float(stack, (SPFLOAT) *tlen);
            break;

        case PLUMBER_DESTROY:
            tlen = pd->last->ud;
            free(tlen);
            break;

        default:
            plumber_print(pd,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #19
0
파일: oscmorph.c 프로젝트: Luckyncl/3rd
static void get_strings(sporth_stack *stack, sporth_oscmorph *om)
{
    int n;
    for(n = 0; n < om->nft; n++) {
        om->ftname[om->nft - 1 - n] = sporth_stack_pop_string(stack);
    }
}
예제 #20
0
int sporth_gen_sine(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    int size;
    sp_ftbl *ft;
    char *str;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_SINE, NULL);

            if(sporth_check_args(stack, "sf") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_sine\n");
                return PLUMBER_NOTOK;
            }
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
#ifdef DEBUG_MODE
            fprintf(stderr, "Creating sine table %s of size %d\n", str, size);
#endif
            sp_ftbl_create(pd->sp, &ft, size);
            sp_gen_sine(pd->sp, ft);
            plumber_ftmap_add(pd, str, ft);
            free(str);
            break;

        case PLUMBER_INIT:
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            free(str);
            break;

        case PLUMBER_COMPUTE:
            size = (int)sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
예제 #21
0
파일: scrambler.c 프로젝트: Luckyncl/3rd
int sporth_scrambler(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sp_ftbl *ft_s, *ft_d;
    char *src, *dst;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_SCRAMBLER, NULL);
            if(sporth_check_args(stack, "ss") != SPORTH_OK) {
                fprintf(stderr, "Init: not enough arguments for gen_line\n");
                return PLUMBER_NOTOK;
            }

            src = sporth_stack_pop_string(stack);
            dst = sporth_stack_pop_string(stack);

            if(plumber_ftmap_search(pd, src, &ft_s) != PLUMBER_OK) {
                fprintf(stderr, 
                    "scrambler: could not find ftable %s",
                    src);
            }

            sp_gen_scrambler(pd->sp, ft_s, &ft_d);
            plumber_ftmap_add(pd, dst, ft_d);
            break;

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

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           break;
    }
    return PLUMBER_OK;
}
예제 #22
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;
}
예제 #23
0
파일: zeros.c 프로젝트: andreamazz/AudioKit
int sporth_zeros(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    int size;
    sp_ftbl *ft;
    const char *str;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_ZEROS, NULL);
            if(sporth_check_args(stack, "sf") != SPORTH_OK) {
                plumber_print(pd, "Init: not enough arguments for zeros\n");
                return PLUMBER_NOTOK;
            }
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
#ifdef DEBUG_MODE
            plumber_print(pd, "Zeros: creating table %s of size %d\n", str, size);
#endif
            sp_ftbl_create(pd->sp, &ft, size);
            plumber_ftmap_add(pd, str, ft);
            break;

        case PLUMBER_INIT:
            size = (int)sporth_stack_pop_float(stack);
            str = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            size = (int)sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           plumber_print(pd, "Error: Unknown mode!\n");
           break;
    }
    return PLUMBER_OK;
}
예제 #24
0
int sporth_writecode(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    const char *file;
    FILE *fp;
    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_WRITECODE, NULL);

            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                plumber_print(pd, "writecode: not enough arguments\n");
                return PLUMBER_NOTOK;
            }

            file = sporth_stack_pop_string(stack);
            fp = fopen(file, "w");
            if(fp == NULL) {
                plumber_print(pd, "There was a problem opening %s", file);
                return PLUMBER_NOTOK;
            }
            plumber_write_code(pd, fp);
            fclose(fp);

            break;

        case PLUMBER_INIT:
            sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            break;

        default:
           break;
    }
    return PLUMBER_OK;
}
예제 #25
0
파일: prop.c 프로젝트: OpenDAWN/Sporth
int sporth_prop(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    SPFLOAT bpm;
    SPFLOAT out;
    sp_prop *data;
    char *str;
    switch(pd->mode){
        case PLUMBER_CREATE:
            sp_prop_create(&data);
            plumber_add_module(pd, SPORTH_PROP, sizeof(sp_prop), data);
            break;
        case PLUMBER_INIT:
            if(sporth_check_args(stack, "fs") != SPORTH_OK) {
                fprintf(stderr, "Not enough arguments for prop\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            data = pd->last->ud;
            str = sporth_stack_pop_string(stack);
            bpm = sporth_stack_pop_float(stack);
            if(sp_prop_init(pd->sp, data, str) == SP_NOT_OK) {
                stack->error++;
                free(str);
                return PLUMBER_NOTOK;
            }
            sporth_stack_push_float(stack, 0);
            free(str);
            break;
        case PLUMBER_COMPUTE:
            if(sporth_check_args(stack, "f") != SPORTH_OK) {
                fprintf(stderr, "Not enough arguments for prop\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            bpm = sporth_stack_pop_float(stack);
            data = pd->last->ud;
            data->bpm = bpm;
            sp_prop_compute(pd->sp, data, NULL, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            data = pd->last->ud;
            sp_prop_destroy(&data);
            break;
        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_NOTOK;
}
예제 #26
0
static int sporth_huion(plumber_data *pd, sporth_stack *stack, void **ud)
{
    huion_d *hd;
    char *str;
    switch(pd->mode) {
        case PLUMBER_CREATE:
            fprintf(stderr, "Creating our custom gain plugin!\n");
            if(sporth_check_args(stack, "s") != SPORTH_OK) {
                fprintf(stderr,"Incorrect arguments for huion\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            /* malloc and assign address to user data */
            str = sporth_stack_pop_string(stack);
            hd = malloc(sizeof(huion_d));
            *ud = hd;
            sp_ftbl_create(pd->sp, &hd->data, P_MAX);
            plumber_ftmap_add(pd, str, hd->data);
            huion_start(hd);
            break;
        case PLUMBER_INIT:
            str = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            break;

        case PLUMBER_DESTROY:
            hd = *ud;
            huion_stop(hd);
            free(hd);
            break;
        default:
            fprintf(stderr, "Huion: unknown mode %d\n", pd->mode);
            break;
    }
    return PLUMBER_OK;
}
예제 #27
0
int sporth_gen_eval(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    plumber_data my_pd;

    uint32_t size;
    sp_data *sp;
    sp_ftbl *ft;
    char *ftname;
    char *str;
    uint32_t n;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_EVAL, NULL);

            if(sporth_check_args(stack, "sfs") != SPORTH_OK) {
                plumber_print(pd, "Init: not enough arguments for gen_sine\n");
                return PLUMBER_NOTOK;
            }
            str = sporth_stack_pop_string(stack);
            size = (uint32_t) sporth_stack_pop_float(stack);
            ftname = sporth_stack_pop_string(stack);
            sp_ftbl_create(pd->sp, &ft, size);
            plumber_ftmap_add(pd, ftname, ft);
#ifdef DEBUG_MODE
            plumber_print(pd, "gen_sporth: compiling file %s to table of size %d\n", 
                    filename, size);
#endif
            plumber_register(&my_pd);
            plumber_init(&my_pd);
            sp_create(&sp);
            sp->sr = pd->sp->sr;
            sp_srand(sp, pd->seed);
            my_pd.sp = sp;
            my_pd.sp->len = size;
            if(plumber_parse_string(&my_pd, str) == PLUMBER_OK) {
                plumber_compute(&my_pd, PLUMBER_INIT);
                for(n = 0; n < ft->size; n++) {
                    plumber_compute(&my_pd, PLUMBER_COMPUTE);
                    ft->tbl[n] = sporth_stack_pop_float(&my_pd.sporth.stack);
                }
            }
            plumber_clean(&my_pd);
            sp_destroy(&sp);
            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:
            break;

        default:
           printf("Error: Unknown mode!");
           break;
    }
    return PLUMBER_OK;
}
예제 #28
0
파일: gen_padsynth.c 프로젝트: Luckyncl/3rd
int sporth_gen_padsynth(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;

    sp_ftbl *ft, *amps;
    char *ftname, *ampname;
    uint32_t size;
    SPFLOAT freq, bw;

    switch(pd->mode){
        case PLUMBER_CREATE:
            plumber_add_ugen(pd, SPORTH_GEN_PADSYNTH, NULL);
            if(sporth_check_args(stack, "sfffs") != SPORTH_OK) {
                fprintf(stderr,"Padsynth: not enough arguments for gen_padsynth\n");
                return PLUMBER_NOTOK;
            }
            ampname = sporth_stack_pop_string(stack);
            bw = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            size = (uint32_t)sporth_stack_pop_float(stack);
            ftname = sporth_stack_pop_string(stack);

            if(plumber_ftmap_search(pd, ampname, &amps) == PLUMBER_NOTOK) {
                stack->error++;
                return PLUMBER_NOTOK;
            }
            

            sp_ftbl_create(pd->sp, &ft, size);

#ifdef DEBUG_MODE
            fprintf(stderr,"Running padsynth function\n");
#endif
            sp_gen_padsynth(pd->sp, ft, amps, freq, bw);

            plumber_ftmap_add(pd, ftname, ft);
            break;

        case PLUMBER_INIT:
            ampname = sporth_stack_pop_string(stack);
            bw = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            size = (uint32_t)sporth_stack_pop_float(stack);
            ftname = sporth_stack_pop_string(stack);
            break;

        case PLUMBER_COMPUTE:
            sporth_stack_pop_float(stack);
            sporth_stack_pop_float(stack);
            sporth_stack_pop_float(stack);
            break;

        case PLUMBER_DESTROY:
            break;

        default:
            fprintf(stderr,"Error: Unknown mode!");
            break;
    }
    return PLUMBER_OK;
}
예제 #29
0
파일: posc3.c 프로젝트: andreamazz/AudioKit
int sporth_posc3(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    SPFLOAT out;
    sp_ftbl *tbl;
    const char *str;
    SPFLOAT freq;
    SPFLOAT amp;
    sp_posc3 *posc3;

    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            plumber_print(pd, "posc3: Creating\n");
#endif

            sp_posc3_create(&posc3);
            plumber_add_ugen(pd, SPORTH_POSC3, posc3);
            if(sporth_check_args(stack, "ffs") != SPORTH_OK) {
                plumber_print(pd,"Not enough arguments for posc3\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            str = sporth_stack_pop_string(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            if(plumber_ftmap_search(pd, str, &tbl) == PLUMBER_NOTOK) {
                stack->error++;
                return PLUMBER_NOTOK;
            }
            sp_posc3_init(pd->sp, posc3, tbl);
            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            plumber_print(pd, "posc3: Initialising\n");
#endif

            str = sporth_stack_pop_string(stack);
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            posc3 = pd->last->ud;

            sporth_stack_push_float(stack, 0);
            break;
        case PLUMBER_COMPUTE:
            amp = sporth_stack_pop_float(stack);
            freq = sporth_stack_pop_float(stack);
            posc3 = pd->last->ud;
            posc3->freq = freq;
            posc3->amp = amp;
            sp_posc3_compute(pd->sp, posc3, NULL, &out);
            sporth_stack_push_float(stack, out);
            break;
        case PLUMBER_DESTROY:
            posc3 = pd->last->ud;
            sp_posc3_destroy(&posc3);
            break;
        default:
            plumber_print(pd, "posc3: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}
예제 #30
0
int sporth_prints(sporth_stack *stack, void *ud)
{
    plumber_data *pd = ud;
    sporth_print_d *prnt;
    const char *str;
    SPFLOAT val = 0;
    const char *sval; 
    sporth_stack_val *stackval; 
    switch(pd->mode) {
        case PLUMBER_CREATE:

#ifdef DEBUG_MODE
            plumber_print(pd, "print: Creating\n");
#endif
            prnt = malloc(sizeof(sporth_print_d));
            plumber_add_ugen(pd, SPORTH_PRINT, prnt);
            if(sporth_check_args(stack, "ns") != SPORTH_OK) {
                plumber_print(pd,"Not enough arguments for print\n");
                stack->error++;
                return PLUMBER_NOTOK;
            }
            str = sporth_stack_pop_string(stack);
            stackval = sporth_stack_get_last(stack);
            prnt->type = stackval->type;

            if(prnt->type == SPORTH_FLOAT) {
                val = sporth_stack_pop_float(stack);
                prnt->pval = val; 
                sporth_stack_push_float(stack, val);
            } else if(prnt->type == SPORTH_STRING) {
                sval = sporth_stack_pop_string(stack);
                prnt->sval = sval;
                sporth_stack_push_string(stack, (char **)&sval);
            } else {
                plumber_print(pd, "Print: unknown type\n");
                return PLUMBER_NOTOK;
            }
            
            strncpy(prnt->label, str, 128);
            prnt->init = 1;
            break;
        case PLUMBER_INIT:

#ifdef DEBUG_MODE
            plumber_print(pd, "print: Initialising\n");
#endif
            prnt = pd->last->ud;
            str = sporth_stack_pop_string(stack);

            if(prnt->type == SPORTH_FLOAT) {
                val = sporth_stack_pop_float(stack);
                sporth_stack_push_float(stack, val);
            } else if(prnt->type == SPORTH_STRING) {
                sval = sporth_stack_pop_string(stack);
                sporth_stack_push_string(stack, (char **)&sval);
            }

            break;
        case PLUMBER_COMPUTE:
            prnt = pd->last->ud;
            if(prnt->type == SPORTH_FLOAT) {
                val = sporth_stack_pop_float(stack);
                if(prnt->init) {
                    prnt->init = 0;
                    plumber_print(pd, "%s: \"%g\",\n", prnt->label, val);
                    prnt->pval = val;
                } else if(val != prnt->pval && prnt->init == 0) {
                    prnt->pval = val;
                    plumber_print(pd, "%s: \"%g\",\n", prnt->label, val);
                } 
                sporth_stack_push_float(stack, val);
            } 
            break;
        case PLUMBER_DESTROY:
            prnt = pd->last->ud;
            free(prnt);
            break;
        default:
            plumber_print(pd, "print: Unknown mode!\n");
            break;
    }
    return PLUMBER_OK;
}