Пример #1
0
void sys_setchsr(int chin, int chout, int sr)
{
    int inbytes = (chin ? chin : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample));
    int outbytes = (chout ? chout : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample));

    if (STUFF->st_soundin)
        freebytes(STUFF->st_soundin,
            (STUFF->st_inchannels? STUFF->st_inchannels : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample)));
    if (STUFF->st_soundout)
        freebytes(STUFF->st_soundout,
            (STUFF->st_outchannels? STUFF->st_outchannels : 2) *
                (DEFDACBLKSIZE*sizeof(t_sample)));
    STUFF->st_inchannels = chin;
    STUFF->st_outchannels = chout;
    STUFF->st_dacsr = sr;
    sys_advance_samples = (sys_schedadvance * STUFF->st_dacsr) / (1000000.);
    if (sys_advance_samples < DEFDACBLKSIZE)
        sys_advance_samples = DEFDACBLKSIZE;

    STUFF->st_soundin = (t_sample *)getbytes(inbytes);
    memset(STUFF->st_soundin, 0, inbytes);

    STUFF->st_soundout = (t_sample *)getbytes(outbytes);
    memset(STUFF->st_soundout, 0, outbytes);

    if (sys_verbose)
        post("input channels = %d, output channels = %d",
            STUFF->st_inchannels, STUFF->st_outchannels);
    canvas_resume_dsp(canvas_suspend_dsp());
}
Пример #2
0
t_pd_err channels_set(t_hoa_meter *x, void *attr, long argc, t_atom *argv)
{
    t_atom* av;
    if(argc && argv)
    {
        if(atom_gettype(argv) == A_FLOAT)
        {
            long d = pd_clip_minmax(atom_getfloat(argv), 1, MAX_SPEAKER);
            if(d != x->f_meter->getNumberOfChannels())
            {
                int dspState = canvas_suspend_dsp();
                delete x->f_meter;
                x->f_meter = new Meter(d);
                delete x->f_vector;
                x->f_vector = new Vector(d);
                
                av = new t_atom[x->f_meter->getNumberOfChannels()];
                for(int i = 0; i < x->f_meter->getNumberOfChannels(); i++)
                {
                    atom_setfloat(av+i, x->f_meter->getChannelAzimuth(i) / HOA_2PI * 360.);
                    x->f_over_leds[i] = 0;
                }
                angles_set(x, NULL, x->f_meter->getNumberOfChannels(), av);
                
                eobj_resize_inputs((t_ebox *)x, x->f_meter->getNumberOfChannels());
                
                canvas_resume_dsp(dspState);
            }
        }
    }
    return NULL;
}
Пример #3
0
t_max_err scope_setattr_order(t_scope *x, t_object *attr, long ac, t_atom *av)
{
	if (ac && av)
    {
        if (atom_gettype(av) == A_LONG)
        {
            long d = Tools::clip_min(long(atom_getlong(av)), long(1));
            if (d != x->f_order)
            {
                int dspState = canvas_suspend_dsp();
                
                free(x->f_harmonicsValues);
                free(x->f_averageHarmo);
                delete x->f_viewer;
                x->f_viewer = new AmbisonicViewer(d);
                x->f_order = x->f_viewer->getOrder();
                x->f_harmonicsValues    = new double[x->f_order * 2 + 1];
                x->f_averageHarmo       = new double[x->f_order * 2 + 1];
                jbox_resize_inputs((t_jbox *)x, x->f_order * 2 + 1);
                
                canvas_resume_dsp(dspState);
            }
        }
	}
	return 0;
}
Пример #4
0
static void dsp_tilde_start(t_dsp_tilde *x)
{
    canvas_resume_dsp(1);
    x->f_state = 1;
    ebox_invalidate_layer((t_ebox *)x, cream_sym_background_layer);
    ebox_redraw((t_ebox *)x);
}
Пример #5
0
void canvas_undo_redo(t_canvas *x)
{
    int dspwas;
    t_undo *udo = canvas_undo_get(x);
    if (!udo) return;
    dspwas = canvas_suspend_dsp();
    if (udo->u_queue && udo->u_last->next)
    {
        char *undo_action, *redo_action;
        udo->u_doing = 1;
        udo->u_last = udo->u_last->next;
        canvas_editmode(x, 1);
        glist_noselect(x);
        canvas_undo_set_name(udo->u_last->name);

        if(UNDO_SEQUENCE_START == udo->u_last->type)
        {
            int sequence_depth = 1;
            while(udo->u_last->next && (udo->u_last = udo->u_last->next))
            {
                DEBUG_UNDO(post("%s:sequence[%d] %d", __FUNCTION__, sequence_depth, udo->u_last->type));
                switch(udo->u_last->type)
                {
                case UNDO_SEQUENCE_END:
                    sequence_depth--;
                    break;
                case UNDO_SEQUENCE_START:
                    sequence_depth++;
                    break;
                default:
                    canvas_undo_doit(x, udo->u_last, UNDO_REDO, __FUNCTION__);
                }
                if (sequence_depth < 1)
                    break;
            }
            if (sequence_depth < 0)
                bug("undo sequence end without start");
            else if (sequence_depth > 0)
                bug("undo sequence start without end");
        }

        canvas_undo_doit(x, udo->u_last, UNDO_REDO, __FUNCTION__);
        undo_action = udo->u_last->name;
        redo_action = (udo->u_last->next ? udo->u_last->next->name : "no");
        udo->u_doing = 0;
        /* here we call updating of all unpaired hubs and nodes since their
           regular call will fail in case their position needed to be updated
           by undo/redo first to reflect the old one */
        if (glist_isvisible(x) && glist_istoplevel(x))
        {
            if (glist_isvisible(x) && glist_istoplevel(x))
                sys_vgui("pdtk_undomenu .x%lx %s %s\n", x, undo_action, redo_action);
        }
        canvas_dirty(x, canvas_undo_isdirty(x));
    }
    canvas_resume_dsp(dspwas);
}
Пример #6
0
int sys_load_lib(t_canvas *canvas, char *classname)
{
    int dspstate = canvas_suspend_dsp();
    int ok = 0;
    loader_queue_t *q;
    for(q = &loaders; q; q = q->next)
        if (ok = q->loader(canvas, classname)) break;
    canvas_resume_dsp(dspstate);
    return ok;
}
Пример #7
0
OSStatus sysAudioOpen(AudioCallbackFn *inCallback) {
    if (gIsAudioOpen)
        return kPdLibErrAlreadyInitialized;
    
    canvas_resume_dsp(canvas_suspend_dsp());
    
    gCoreAudioHelper = new CoreAudioHelper(inCallback);
    
    // everything worked, continue!
    gIsAudioOpen = gCoreAudioHelper->unitIsRunning;
    
    if (gIsAudioOpen) {
        return noErr;
    } else {
        return kPdLibErrCoreAudio;
    }
}
Пример #8
0
int sys_load_lib(t_canvas *canvas, const char *classname)
{
    int dspstate = canvas_suspend_dsp();
    struct _loadlib_data data;
    data.canvas = canvas;
    data.ok = 0;

    if (sys_onloadlist(classname))
    {
        verbose(1, "%s: already loaded", classname);
        return (1);
    }
        /* if classname is absolute, try this first */
    if (sys_isabsolutepath(classname))
    {
            /* this is just copied from sys_open_absolute()
               LATER avoid code duplication */
        char dirbuf[MAXPDSTRING], *z = strrchr(classname, '/');
        int dirlen;
        if (!z)
            return (0);
        dirlen = (int)(z - classname);
        if (dirlen > MAXPDSTRING-1)
            dirlen = MAXPDSTRING-1;
        strncpy(dirbuf, classname, dirlen);
        dirbuf[dirlen] = 0;
        data.classname=classname+(dirlen+1);
        sys_loadlib_iter(dirbuf, &data);
    }
    data.classname = classname;
    if(!data.ok)
        canvas_path_iterate(canvas, (t_canvas_path_iterator)sys_loadlib_iter,
            &data);

    /* if loaders failed so far, we try a last time without a PATH
     * let the loaders search wherever they want */
    if (!data.ok)
        sys_loadlib_iter(0, &data);

    if(data.ok)
      sys_putonloadlist(classname);


    canvas_resume_dsp(dspstate);
    return data.ok;
}
Пример #9
0
void canvas_undo_rebranch(t_canvas *x)
{
    int dspwas = canvas_suspend_dsp();
    t_undo_action *a1, *a2;
    t_undo *udo = canvas_undo_get(x);
    if (!udo) return;
    if (udo->u_last->next)
    {
        a1 = udo->u_last->next;
        while(a1)
        {
            canvas_undo_doit(x, a1, UNDO_FREE, __FUNCTION__);
            a2 = a1->next;
            freebytes(a1, sizeof(*a1));
            a1 = a2;
        }
    }
    canvas_resume_dsp(dspwas);
}
Пример #10
0
/* remove every object from a glist.  Experimental. */
void glist_clear(t_glist *x)
{
    t_gobj *y, *y2;
    int dspstate = 0, suspended = 0;
    t_symbol *dspsym = gensym("dsp");
    while (y = x->gl_list)
    {
        /* to avoid unnecessary DSP resorting, we suspend DSP
        only if we hit a patchable object. */
        if (!suspended && pd_checkobject(&y->g_pd) && zgetfn(&y->g_pd, dspsym))
        {
            dspstate = canvas_suspend_dsp();
            suspended = 1;
        }
        /* here's the real deletion. */
        glist_delete(x, y);
    }
    if (suspended)
        canvas_resume_dsp(dspstate);
}
Пример #11
0
static void sys_setchsr(int chin, int chout, int sr)
{
#ifndef ROCKBOX
    int nblk;
#endif
    int inbytes = (chin ? chin : 2) * (DEFDACBLKSIZE*sizeof(float));
    int outbytes = (chout ? chout : 2) * (DEFDACBLKSIZE*sizeof(float));

    sys_inchannels = chin;
    sys_outchannels = chout;
    sys_dacsr = sr;
    sys_advance_samples = (sys_schedadvance * sys_dacsr) / (1000000.);
    if (sys_advance_samples < 3 * DEFDACBLKSIZE)
    	sys_advance_samples = 3 * DEFDACBLKSIZE;

    if (sys_soundin)
    	free(sys_soundin);
#ifdef ROCKBOX
    sys_soundin = (t_sample*) malloc(inbytes);
#else
    sys_soundin = (t_float *)malloc(inbytes);
#endif
    memset(sys_soundin, 0, inbytes);

    if (sys_soundout)
    	free(sys_soundout);
#ifdef ROCKBOX
    sys_soundout = (t_sample*) malloc(outbytes);
#else
    sys_soundout = (t_float *)malloc(outbytes);
#endif
    memset(sys_soundout, 0, outbytes);

    if (sys_verbose)
    	post("input channels = %d, output channels = %d",
    	    sys_inchannels, sys_outchannels);
    canvas_resume_dsp(canvas_suspend_dsp());
}
t_pd_err set_order(t_hoa_scope *x, t_object *attr, long ac, t_atom *av)
{
    long order;
    if (ac && av && atom_gettype(av) == A_LONG)
    {
        order = atom_getlong(av);
        if(order != x->f_scope->getDecompositionOrder() && order > 0)
        {
            int dspState = canvas_suspend_dsp();

            delete x->f_scope;
            delete [] x->f_signals;
            x->f_scope      = new Hoa2D::Scope(order, NUMBEROFCIRCLEPOINTS_UI);
            x->f_order      = x->f_scope->getDecompositionOrder();
            x->f_signals    = new t_float[x->f_scope->getNumberOfHarmonics() * SYS_MAXBLKSIZE];

            eobj_resize_inputs((t_ebox *)x, x->f_scope->getNumberOfHarmonics());
            canvas_update_dsp();
            canvas_resume_dsp(dspState);
        }
    }

    return 0;
}
Пример #13
0
void eobj_save(t_gobj* x, t_binbuf *b)
{
    int i, state;
    int      argc = 0;
    t_atom*  argv    = NULL;
    t_binbuf* d;
    t_object* z = (t_object *)x;
    t_ebox*   y = (t_ebox *)z;
    t_eclass* c = eobj_getclass(x);
    char buffer[MAXPDSTRING];
    if(x && b)
    {
        if(eobj_isbox(x))
        {
            
            if(c && b)
            {
                state = canvas_suspend_dsp();
                binbuf_addv(b, (char *)"ssiis", &s__X, s_cream_obj, (t_int)z->te_xpix, (t_int)z->te_ypix, eobj_getclassname(x));
                for(i = 0; i < c->c_nattr; i++)
                {
                    if(c->c_attr[i] && c->c_attr[i]->save && c->c_attr[i]->name)
                    {
                        eobj_attr_getvalueof(x, c->c_attr[i]->name, &argc, &argv);
                        if(argc && argv)
                        {
                            if(!(argc == 1 && atom_gettype(argv) == A_SYMBOL && !is_valid_symbol(atom_getsymbol(argv))))
                            {
                                snprintf(buffer, MAXPDSTRING, "@%s", c->c_attr[i]->name->s_name);
                                binbuf_append_attribute(b, gensym(buffer), argc, argv);
                            }
                            argc = 0;
                            free(argv);
                            argv = NULL;
                        }
                    }
                }
                argv = (t_atom *)malloc(3 * sizeof(t_atom));
                if(argv)
                {
                    for(i = 0; i < y->b_nparams; i++)
                    {
                        if(y->b_params[i])
                        {
                            snprintf(buffer, MAXPDSTRING, "@param%i", i);
                            atom_setsym(argv, y->b_params[i]->p_name);
                            atom_setsym(argv+1, y->b_params[i]->p_label);
                            atom_setfloat(argv+2, y->b_params[i]->p_index);
                            binbuf_append_attribute(b, gensym(buffer), 3, argv);
                        }
                    }
                }
                
                if(c->c_widget.w_save != NULL)
                {
                    c->c_widget.w_save(x, b);
                }
                
                binbuf_addv(b, (char *)";");
                canvas_resume_dsp(state);
            }
        }
        else
        {
            binbuf_addv(b, (char *)"ssii", &s__X, s_cream_obj, (t_int)z->te_xpix, (t_int)z->te_ypix);
            d = z->te_binbuf;
            if(d)
            {
                binbuf_addbinbuf(b, d);
            }
            if(c->c_widget.w_save != NULL)
            {
                c->c_widget.w_save(x, b);
            }
            binbuf_addv(b, (char *)";");
        }
    }
}
Пример #14
0
static void glob_compatibility(t_pd *dummy, t_floatarg level)
{
    int dspwas = canvas_suspend_dsp();
    pd_compatibilitylevel = 0.5 + 100. * level;
    canvas_resume_dsp(dspwas);
}