Example #1
0
void hoa_space_draw_harmonics(t_hoa_space *x, t_object *view, t_rect *rect)
{
	t_elayer *g = ebox_start_layer((t_ebox *)x, gensym("harmonics_layer"), rect->width, rect->height);
    
	if (g)
	{
		t_matrix transform;
		egraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
		egraphics_set_matrix(g, &transform);
		egraphics_set_line_width(g, 1.);

		if(x->f_viewer->getBiggestContribution() != 0.)
		{
            double max = 0.;
            
            double normalize = 1;
            for(int i = 0 ; i < x->f_number_of_microphones; i++)
            {
                if(x->f_microphonesValues[i] > max)
                    max = x->f_microphonesValues[i];
            }
            normalize = max;
            
            if(x->f_mode == 1)
                normalize = x->f_rotation_max;
            
            double factor = x->f_radius_global * normalize;
            
			egraphics_set_color_rgba(g, &x->f_color_harmonics);
            
            egraphics_move_to(g, x->f_viewer->getAbscisseValue(0) * factor, x->f_viewer->getOrdinateValue(0) * factor);
			for(int i = 0; i < NUMBEROFCIRCLEPOINTS_UI; i += 2)
			{
                if(x->f_viewer->getColor(i) == 1)
				egraphics_line_to(g, x->f_viewer->getAbscisseValue(i) * factor, x->f_viewer->getOrdinateValue(i) * factor);
			}
            egraphics_close_path(g);
            egraphics_fill(g);
		}
		ebox_end_layer((t_ebox*)x,  gensym("harmonics_layer"));
	}
	ebox_paint_layer((t_ebox *)x, gensym("harmonics_layer"), 0., 0.);
}
void draw_harmonics(t_hoa_scope *x, t_object *view, t_rect *rect)
{
    char pathLength;
    t_matrix transform;
    t_elayer *g = ebox_start_layer((t_ebox *)x, hoa_sym_harmonics_layer, rect->width, rect->height);

    if(g)
    {
        egraphics_rotate(g, HOA_PI);
        egraphics_set_line_width(g, 1);
        egraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
        egraphics_set_matrix(g, &transform);

        // positive harmonics
        pathLength = 0;
        egraphics_set_color_rgba(g, &x->f_color_ph);
        for(int i = 0; i < x->f_scope->getNumberOfPoints(); i++)
        {
            if(x->f_scope->getValue(i) >= 0)
            {
                if(!pathLength)
                {
                    egraphics_move_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                    pathLength++;
                }
                else
                {
                    egraphics_line_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
            }
        }
        egraphics_close_path(g);
        if(pathLength)
            egraphics_stroke(g);

        // negative harmonics
        pathLength = 0;
        egraphics_set_color_rgba(g, &x->f_color_nh);
        for(int i = 0; i < x->f_scope->getNumberOfPoints(); i++)
        {
            if(x->f_scope->getValue(i) < 0)
            {
                if(!pathLength)
                {
                    egraphics_move_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                    pathLength++;
                }
                else
                {
                    egraphics_line_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
            }
        }
        egraphics_close_path(g);
        if(pathLength)
            egraphics_stroke(g);

        ebox_end_layer((t_ebox *)x, hoa_sym_harmonics_layer);
    }
    ebox_paint_layer((t_ebox *)x, hoa_sym_harmonics_layer, 0., 0.);
}