Пример #1
0
void HoaDecode_reconnect_outlet(t_HoaDecode *x)
{
	t_object *patcher;
	t_object *decoder;
    t_object *object;
    t_object *line;
	t_max_err err;
    
	err = object_obex_lookup(x, gensym("#P"), (t_object **)&patcher);
	if (err != MAX_ERR_NONE)
		return;
	
	err = object_obex_lookup(x, gensym("#B"), (t_object **)&decoder);
	if (err != MAX_ERR_NONE)
		return;
	
    for (line = jpatcher_get_firstline(patcher); line; line = jpatchline_get_nextline(line))
    {
        if (jpatchline_get_box1(line) == decoder)
        {
            object = jpatchline_get_box2(line);
            
            for(int i = 0; jbox_getinlet((t_jbox *)object, i) != NULL && i < x->f_AmbisonicsDecoder->getNumberOfOutputs(); i++)
            {
                t_atom msg[4];
                t_atom rv;
                    
                atom_setobj(msg, decoder);
                atom_setlong(msg + 1, i);
                atom_setobj(msg + 2, object);
                atom_setlong(msg + 3, i);
                    
                object_method_typed(patcher , gensym("connect"), 4, msg, &rv);
            }
        }
    }
}
void hoa_gain_tometer(t_hoa_gain *x, t_symbol *s, long ac, t_atom *av)
{
    if(ac && av)
    {
        t_object *patcher;
        t_object *gain;
        t_object *line;
        t_max_err err;
        t_atom rv;
        t_atom msg[4];
        
        err = object_obex_lookup(x, hoa_sym_pound_P, (t_object **)&patcher);
        if (err != MAX_ERR_NONE)
            return;
        
        err = object_obex_lookup(x, hoa_sym_pound_B, (t_object **)&gain);
        if (err != MAX_ERR_NONE)
            return;
        
        vector<t_jbox *> boxes;
        
        for (line = jpatcher_get_firstline(patcher); line; line = jpatchline_get_nextline(line))
        {
            if (jpatchline_get_box1(line) == gain)
            {
                t_jbox *box = (t_jbox*)jpatchline_get_box2(line);
                t_object *obj = jbox_get_object((t_object*)box);
                t_symbol* classname = object_classname(obj);
                
                if (find(boxes.begin(), boxes.end(), box) == boxes.end())
                {
                    if(classname == hoa_sym_hoa_2d_meter ||
                       classname == hoa_sym_hoa_2d_vector ||
                       classname == hoa_sym_hoa_gain)
                    {
                        object_method_typed(obj, s, ac, av, NULL);
                        boxes.push_back(box);
                    }
                    else if(classname == hoa_sym_dac || (object_is_hoa(obj) && classname != hoa_sym_hoa_pi && classname != hoa_sym_hoa_pi_tilde))
                    {
                        boxes.push_back(box);
                    }
                }
            }
        }
        
        for(auto box : boxes)
        {
            // re-connect patchlines
            for(int i = 0; jbox_getinlet(box, i) != NULL && i < x->f_number_of_channels; i++)
            {
                atom_setobj(msg, gain);
                atom_setlong(msg + 1, i);
                atom_setobj(msg + 2, box);
                atom_setlong(msg + 3, i);
                object_method_typed(patcher , hoa_sym_connect, 4, msg, &rv);
            }
        }
        boxes.clear();
    }
}