예제 #1
0
void color_patchline(t_connect *x)
{
	t_object *line, *startobj;
	t_object *jb, *o;
	t_hoa_err err;
	t_jrgba* linecolor = NULL;
	int inletnum, sign;
	short startobj_type;
	t_hoa_boxinfos* startobj_infos = (t_hoa_boxinfos*) malloc( sizeof(t_hoa_boxinfos));
	line = jpatcher_get_firstline(x->f_patcher);
	
	while (line)
	{
		startobj = jbox_get_object(jpatchline_get_box1(line));
		
		if(object_is_hoa(startobj) || is_obj_hoa_exotic(startobj))
		{
			startobj_type = object_is_hoa(startobj);
			
			hoa_boxinfos_init(startobj_infos);
			err = (t_hoa_err) object_method(startobj, hoa_sym_hoa_getinfos, startobj_infos, NULL);
			
			if (err == HOA_ERR_NONE)
			{
				// ambisonics colors (zero | neg | pos) (ex: hoa.encoder~ => hoa.optim~)
				if (startobj_infos->autoconnect_outputs_type == HOA_CONNECT_TYPE_AMBISONICS)
				{
					inletnum = jpatchline_get_inletnum(line);
					
					if (startobj_infos->object_type == HOA_OBJECT_2D)
						sign = x->f_ambi2D->getHarmonicArgument(inletnum);
					if (startobj_infos->object_type == HOA_OBJECT_3D)
						sign = x->f_ambi3D->getHarmonicArgument(inletnum);
					
					if (sign > 0)
						linecolor = &x->f_color_positiv;
					else if (sign < 0)
						linecolor = &x->f_color_negativ;
					else
						linecolor = &x->f_color_zero;
					
					jpatchline_set_color(line, linecolor);
				}
				// planewave color (ex: hoa.projector~ => hoa.recomposer~)
				else if (startobj_infos->autoconnect_outputs_type == HOA_CONNECT_TYPE_PLANEWAVES)
				{
					jpatchline_set_color(line, &x->f_color_plane);
				}
			}
			
			// hoa.plug~ retro compatibility
			else if (object_classname(startobj) == hoa_sym_jpatcher)
			{
				jb = jpatcher_get_firstobject(startobj);
				while(jb)
				{
					o = jbox_get_object(jb);
					if(object_classname(o) == gensym("hoa.plug_script"))
					{
						inletnum = jpatchline_get_inletnum(line);
						
						if (inletnum == 0)
							jpatchline_set_color(line, &x->f_color_zero);
						else if (inletnum % 2 == 1)
							jpatchline_set_color(line, &x->f_color_negativ);
						else
							jpatchline_set_color(line, &x->f_color_positiv);
						break;
					}
					jb = jbox_get_nextobject(jb);
				}
				
			}
		}
		
		line = jpatchline_get_nextline(line);
	}
	
	free(startobj_infos);
}
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();
    }
}
예제 #3
0
void make_patchline(t_connect *x)
{
	int connexions, valid_objects, i, j;
	valid_objects = 0;
	t_object *obj1, *obj2;
	t_hoa_err err[2];
	t_hoa_boxinfos* startobj_infos;
	t_hoa_boxinfos* endobj_infos;
	short startobj_type, endobj_type;
	long outlets, inlets;
	
	if (x->f_nbSelected > 1)
	{
		for (i = 0; i < x->f_nbSelected; i++)
		{
			obj1 = jbox_get_object(x->f_objects[i]);
			if(object_is_hoa(obj1) || is_obj_hoa_exotic(obj1))
				x->f_objects[valid_objects++] = x->f_objects[i]; // ! store BOX objects
		}
		
		if (valid_objects > 1)
		{
			startobj_infos = (t_hoa_boxinfos*) malloc( sizeof(t_hoa_boxinfos));
			endobj_infos = (t_hoa_boxinfos*) malloc( sizeof(t_hoa_boxinfos));
			
			for(i = 1; i < valid_objects; i++)
			{
				obj1 = jbox_get_object(x->f_objects[i-1]);
				obj2 = jbox_get_object(x->f_objects[ i ]);
				
				outlets = inlets = 0;
				
				// referenced object or exotic hoa one;
				startobj_type = object_is_hoa(obj1);
				endobj_type	  = object_is_hoa(obj2);
				
				hoa_boxinfos_init(startobj_infos);
				hoa_boxinfos_init(endobj_infos);
				err[0] = (t_hoa_err) object_method(obj1, hoa_sym_hoa_getinfos, startobj_infos, NULL);
				err[1] = (t_hoa_err) object_method(obj2, hoa_sym_hoa_getinfos, endobj_infos, NULL);
				
				// get number of outlets
				if (startobj_type == 1 && err[0] == HOA_ERR_NONE)
					outlets = startobj_infos->autoconnect_outputs;
				else
					outlets = outlet_count(obj1);
				
				// get number of inlets
				if (endobj_type == 1 && err[1] == HOA_ERR_NONE)
					inlets = endobj_infos->autoconnect_inputs;
				else
					inlets = inlet_count(obj2);
				
				connexions = MIN(outlets, inlets);
				for(j = 0; j < connexions; j++)
					connect_connect(x->f_patcher, x->f_objects[i-1], j, x->f_objects[i], j);
			}
			
			free(startobj_infos);
			free(endobj_infos);
		}
		
		for(i = 0; i < CONNECT_MAX_TAB; i++)
			x->f_objects[i] = NULL;
		
		jpatcher_set_dirty(x->f_patcherview, true);
	}
	x->f_nbSelected = 0;
}