Exemple #1
0
void uisimp_paint(t_uisimp *x, t_object *view)
{
	t_jgraphics *g;
	t_rect rect;
	t_jrgba rgba, textcolor;
	t_jfont *jf;
	t_jtextlayout *jtl;
	char text[16];
	long inset = x->j_inset;
	
	g = (t_jgraphics*) patcherview_get_jgraphics(view); 
	jbox_get_rect_for_view(&x->j_box.b_ob, view, &rect);
	
	if (x->j_shape == EXAMP_SQUARE)
		jgraphics_rectangle(g, inset, inset, rect.width - (inset * 2), rect.height - (inset * 2));
	else if (x->j_shape == EXAMP_CIRCLE) {
		jgraphics_arc(g, rect.width * .5, rect.height * .5, (rect.width * .5) - (inset * 2), 0, JGRAPHICS_2PI);
		jgraphics_close_path(g);
	} else if (x->j_shape == EXAMP_ANGLE) {
		jgraphics_move_to(g, inset * 2, inset);
		jgraphics_line_to(g, rect.width - (inset * 2), inset);
		jgraphics_line_to(g, rect.width - (inset * 2), inset * 2);
		jgraphics_line_to(g, rect.width - (inset * 2), rect.height - (inset * 2));
		jgraphics_line_to(g, rect.width - (inset * 2), rect.height - inset);
		jgraphics_line_to(g, inset * 2, rect.height - (inset * 2));
		jgraphics_line_to(g, inset, rect.height - (inset * 3));
		jgraphics_line_to(g, inset, inset * 2);
		jgraphics_line_to(g, inset * 2, inset);
		jgraphics_close_path(g);
	}
		
	if (x->j_mouse_is_down) {
		jbox_get_color((t_object *)x, &rgba);
		jgraphics_set_source_jrgba(g, &rgba);
	} else
		jgraphics_set_source_rgba(g, 0, 0, 0, 1.0);
	jgraphics_fill(g);
	// draw counter
	jf = jfont_create(jbox_get_fontname((t_object *)x)->s_name, jbox_get_font_slant((t_object *)x), jbox_get_font_weight((t_object *)x), jbox_get_fontsize((t_object *)x));
	jtl = jtextlayout_create();
	sprintf(text,"%d",x->j_mouse_counter);
	
	jtextlayout_set(jtl, text, jf, 5, 5, rect.width - 10, rect.height- 10, JGRAPHICS_TEXT_JUSTIFICATION_CENTERED, JGRAPHICS_TEXTLAYOUT_NOWRAP);
	textcolor.red = textcolor.green = textcolor.blue = 1;
	textcolor.alpha = 1;
	jtextlayout_settextcolor(jtl, &textcolor); 
	jtextlayout_draw(jtl, g);
	jtextlayout_destroy(jtl);
	jfont_destroy(jf);
}
Exemple #2
0
void meter_dopaint_vertical(t_meter *x, t_object *view) {

	t_rect			rect;
	t_jgraphics*	g;
	double			level = TTClip(x->envelope, 0.0f, 1.0f);
	double			position;
	double			peakPosition;
	t_jrgba			c;
	
	if (level > 0.0)
		level = pow(level, kTTGainMidiPowerInv);	// this is taken from the midi conversion in the Gain Dataspace
	
	g = (t_jgraphics*) patcherview_get_jgraphics(view);		// obtain graphics context
	jbox_get_rect_for_view((t_object *)x, view, &rect);		// this is the box rectangle -- but we draw relative to 0 0, and thus only care about width & height
	rect.x = 0;
	rect.y = 0;
	position = rect.height * level * 0.96;
	peakPosition = rect.height * x->peak * 0.96;

	if (level > x->peak)
		x->peak = level;
						
	// TODO: Can we export this from the kernel???	
	//	jgraphics_image_surface_draw_fast(g, x->gradientSurface);
	jgraphics_image_surface_draw(g, x->gradientSurface, x->gradientRect, rect);
	
	jgraphics_set_source_jrgba(g, &x->attrBgColor);
	jgraphics_rectangle_fill_fast(g, 0, 0, rect.width, rect.height-position);

	if (x->envelope > 1.0 || x->peak > 1.0) {
		c.red = 1.0;
		c.green = c.blue = 0.0;
		c.alpha = 1.0;
		jgraphics_set_source_jrgba(g, &c);
		jgraphics_rectangle_fill_fast(g, 0, 0, rect.width, rect.height * .04);
	}
	else {
		c.red = peakPosition / x->gradientRect.height;
		c.green = 1.0;
		c.blue = 0.0;
		c.alpha = 1.0;
		jgraphics_set_source_jrgba(g, &c);
		// TODO: Can we export this from the kernel???	
		// jgraphics_line_draw_fast(g, rect.width * level * 0.96, 0, rect.width * level * 0.96, rect.height, 1.0);
		jgraphics_move_to(g, 0.0, rect.height - peakPosition);
		jgraphics_line_to(g, rect.width, rect.height - peakPosition);
		jgraphics_set_line_width(g, 1.0);
		jgraphics_stroke(g);
	}
}
void draw_separator(t_meter *x,  t_object *view, t_rect *rect)
{
    t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_separator_layer, rect->width, rect->height);
    
	if (g)
	{
        double rotateAngle, channelWidth;
        t_jmatrix transform;
        t_jrgba black = rgba_addContrast(x->f_color_mbg, -0.12);
        
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
		jgraphics_set_matrix(g, &transform);
		
		// skelton separators and leds bg:
		for(int i=0; i < x->f_meter->getNumberOfPlanewaves(); i++)
		{
			channelWidth = radToDeg(x->f_meter->getPlanewaveWidth(i));
            rotateAngle = radToDeg(x->f_meter->getPlanewaveAzimuthMapped(i) + x->f_meter->getPlanewavesRotationX()) - (channelWidth*0.5);
			if (!x->f_rotation)
			{
				rotateAngle += channelWidth;
				rotateAngle *= -1;
			}
			jgraphics_rotate(g, degToRad(rotateAngle));

            // separator
			if (x->f_meter->getNumberOfPlanewaves() > 1)
			{
                jgraphics_set_line_width(g, 1);
                jgraphics_set_source_jrgba(g, &black);
				jgraphics_move_to(g, 0., x->f_rayonInt);
				jgraphics_line_to(g, 0, x->f_rayonExt);
				jgraphics_stroke(g);
			}
			
			jgraphics_rotate(g, degToRad(-rotateAngle));
		}
		
		jbox_end_layer((t_object*)x, view, hoa_sym_separator_layer);
	}
	jbox_paint_layer((t_object *)x, view, hoa_sym_separator_layer, 0., 0.);
}
Exemple #4
0
void draw_harmonics(t_scope *x,  t_object *view, t_rect *rect)
{
    t_jmatrix transform;
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("harmonics_layer"), rect->width, rect->height);
    
	if (g)
	{
        t_jrgba grey  = {0.5, 0.5, 0.5, 1.};
		double factor = (x->f_rayonGlobal * 5. / 6.);
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
        
		if(x->f_viewer->getBiggestContribution() > 0.)
		{
            jgraphics_set_line_width(g, 1.);
            double shadow = 1.;
            double x1;
            double y1;
            
            x1 = x->f_viewer->getAbscisseValue(0) * factor + shadow;
            y1 = x->f_viewer->getOrdinateValue(0) * factor + shadow;
            jgraphics_move_to(g, x1, y1);
            for(int i = 0; i < NUMBEROFCIRCLEPOINTS_UI; i += 2)
			{
                x1 = x->f_viewer->getAbscisseValue(i) * factor + shadow;
                y1 = x->f_viewer->getOrdinateValue(i) * factor  + shadow;
                jgraphics_line_to(g, x1, y1);
            }
            x1 = x->f_viewer->getAbscisseValue(0) * factor + shadow;
            y1 = x->f_viewer->getOrdinateValue(0) * factor + shadow;
            jgraphics_line_to(g, x1, y1);
            //jgraphics_smooth_line(g);
            jgraphics_set_source_jrgba(g, &grey);
            jgraphics_stroke(g);
            
            jgraphics_set_line_width(g, 1.);
            int color = x->f_viewer->getColor(0);
            x1 = x->f_viewer->getAbscisseValue(0) * factor;
            y1 = x->f_viewer->getOrdinateValue(0) * factor;
            jgraphics_move_to(g, x1, y1);
            
			for(int i = 0; i < NUMBEROFCIRCLEPOINTS_UI; i += 2)
			{
                if(x->f_viewer->getColor(i) == color)
                {
                    x1 = x->f_viewer->getAbscisseValue(i) * factor;
                    y1 = x->f_viewer->getOrdinateValue(i) * factor;
                    jgraphics_line_to(g, x1, y1);
                }
                else
                {
                    if(color == 1)
                        jgraphics_set_source_jrgba(g, &x->f_colorPositif);
                    else
                        jgraphics_set_source_jrgba(g, &x->f_colorNegatif);
                    
                    jgraphics_line_to(g, x1, y1);
                    //jgraphics_smooth_line(g);
                    jgraphics_stroke(g);
                    
                    
                    color = x->f_viewer->getColor(i);
                    x1 = x->f_viewer->getAbscisseValue(i) * factor;
                    y1 = x->f_viewer->getOrdinateValue(i) * factor;
                    jgraphics_move_to(g, x1, y1);
                }
            }
            
            x1 = x->f_viewer->getAbscisseValue(0) * factor;
            y1 = x->f_viewer->getOrdinateValue(0) * factor;
            jgraphics_line_to(g, x1, y1);
            if(color == 1)
                jgraphics_set_source_jrgba(g, &x->f_colorPositif);
            else
                jgraphics_set_source_jrgba(g, &x->f_colorNegatif);
            
            //jgraphics_smooth_line(g);
            jgraphics_stroke(g);
		}
		jbox_end_layer((t_object*)x, view, gensym("harmonics_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("harmonics_layer"), 0., 0.);
    
}
Exemple #5
0
void draw_background(t_scope *x,  t_object *view, t_rect *rect)
{
    t_jmatrix transform;
    t_jrgba black, white;
    
    double contrastBlack = 0.14;
    double contrastWhite = 0.06;
    
    black = white = x->f_colorBackground;
    black.red = Tools::clip_min(black.red -= contrastBlack);
    black.green = Tools::clip_min(black.green -= contrastBlack);
    black.blue = Tools::clip_min(black.blue -= contrastBlack);
    
    white.red = Tools::clip_max(white.red += contrastWhite, 1.);
    white.green = Tools::clip_max(white.green += contrastWhite, 1.);
    white.blue = Tools::clip_max(white.blue += contrastWhite, 1.);
    
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("background_layer"), rect->width, rect->height);

	if (g) 
	{
		/* Circles */
		for(int i = 5; i > 0; i--)
		{
            //inner shadow
            jgraphics_set_line_width(g, 1);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_arc(g, long(x->f_center.x)+0.5, long(x->f_center.y)+0.5, (double)i * x->f_rayonCircle,  0., CICM_2PI);
            jgraphics_stroke(g);
            jgraphics_set_line_width(g, 1);
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_arc(g, long(x->f_center.x)-0.5, long(x->f_center.y)-0.5, (double)i * x->f_rayonCircle,  0., CICM_2PI);
            jgraphics_stroke(g);
		}
        
        jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
		double coso, sino, angle, x1, y1, x2, y2, rad1, rad2;
        rad1 = 1. / 6. * x->f_rayonGlobal;
        rad2 = 5. / 6. * x->f_rayonGlobal;
		for(int i = 0; i < (x->f_order * 2 + 2); i++)
		{
            jgraphics_set_source_jrgba(g, &white);
            angle = ( (double)i/(x->f_order * 2 + 2) * CICM_2PI ) - ( 0.5/(x->f_order * 2 + 2) * CICM_2PI );
            coso = cos(angle);
            sino = sin(angle);
            x1 = rad1 * coso;
            y1 = rad1 * sino;
            x2 = rad2 * coso;
            y2 = rad2 * sino;
            
            if(Tools::isInsideDeg(angle / CICM_2PI * 360., 45, 225))
            {
                jgraphics_move_to(g, x1 - 0.5, y1 - 0.5);
                jgraphics_line_to(g, x2 - 0.5, y2 - 0.5);
            }
            else
            {
                jgraphics_move_to(g, x1 + 0.5, y1 + 0.5);
                jgraphics_line_to(g, x2 + 0.5, y2 + 0.5);
            }
            jgraphics_stroke(g);
            
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_move_to(g, x1, y1);
            jgraphics_line_to(g, x2, y2);
            jgraphics_stroke(g);
			
		}
		
		jbox_end_layer((t_object*)x, view, gensym("background_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("background_layer"), 0., 0.);
}
void paramui_paint(t_paramui *x, t_object *view)
{
	t_rect 		rect;
	t_jgraphics *g;
	double		middle;
	double 		border_thickness = 1.5;
	double 		cornersize = 13.0;

	g = (t_jgraphics*) patcherview_get_jgraphics(view);
	jbox_get_rect_for_view((t_object*) &x->box, view, &rect);

	// clear the background
	jgraphics_rectangle_rounded(g,  border_thickness, 
									border_thickness, 
									rect.width - (border_thickness * 2.0), 
									rect.height - (border_thickness * 2.0), 
									cornersize, cornersize); 
	jgraphics_set_source_rgba(g, 0.1, 0.1, 0.1, 1.0);
	jgraphics_fill(g);
		
	// draw the inspector icon

	jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2);
	jgraphics_set_line_width(g, 1.5);
	jgraphics_oval(g,	border_thickness,
						border_thickness, 
						rect.height - (border_thickness * 2.0),
						rect.height - (border_thickness * 2.0));
	jgraphics_fill(g);
	
	jgraphics_rectangle_fill_fast(g,	border_thickness + rect.height / 2 - (border_thickness), 
										border_thickness,
										border_thickness + rect.height / 2, 
										rect.height - (border_thickness * 2.0));

	jgraphics_set_source_rgb(g, 0.4, 0.4, 0.4);
	middle = 6.0;
	jgraphics_move_to(g, 9.5, middle + 4.0);
	jgraphics_line_to(g, 13.0, middle);
	jgraphics_line_to(g, 6.0, middle);
	jgraphics_close_path(g);
	jgraphics_fill(g);


	if(x->attr_dataspace != jps_none) {
		char data[64];	
	
		strncpy(data, x->attr_unitActive->s_name, 64);

		// draw the unit display
		jgraphics_set_source_rgb(g, 0.2, 0.2, 0.2);
		jgraphics_set_line_width(g, 1.5);
		jgraphics_oval(g,	rect.width - (rect.height - (border_thickness * 2.0)) - 2.0, 
							border_thickness, 
							rect.height - (border_thickness * 2.0), 
							rect.height - (border_thickness * 2.0));
		jgraphics_fill(g);
		
		jgraphics_rectangle_fill_fast(g,	rect.width - ((border_thickness + rect.height / 2 - (border_thickness)) * 3.0) - 2.0, 
											border_thickness, 
											border_thickness + rect.height / 1, 
											rect.height - (border_thickness * 2.0));


		jtextlayout_settextcolor(x->layout_unit, &s_light_gray);
		jtextlayout_set(x->layout_unit,
						data,
						jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE),
						rect.width - 28.0, 0.0, 28.0, rect.height - 1.0,
						JGRAPHICS_TEXT_JUSTIFICATION_CENTERED,
						JGRAPHICS_TEXTLAYOUT_USEELLIPSIS);
		jtextlayout_draw(x->layout_unit, g);
	}
	
	{
		char	data[256];
		t_atom	*av = NULL;
		long	ac = 0;

		if(x->obj_parameter){
			object_attr_getvalueof(x->obj_parameter, gensym("value"), &ac, &av);
			if(ac){
				if(x->attr_type == jps_decimal)
					snprintf(data, 256, "%.4f", atom_getfloat(av));
				else if(x->attr_type == jps_integer || x->attr_type == jps_boolean)
					snprintf(data, 256, "%ld", atom_getlong(av));
				else if(x->attr_type == jps_string)
					strcpy(data, atom_getsym(av)->s_name);
				
				jtextlayout_settextcolor(x->layout_value, &s_light_gray);
				jtextlayout_set(x->layout_value,
								data,
								jfont_create(JAMOMA_DEFAULT_FONT, JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, JAMOMA_DEFAULT_FONTSIZE),
								84.0, 2.0, rect.width - 84.0 - 20.0, rect.height - 1.0,
								JGRAPHICS_TEXT_JUSTIFICATION_LEFT,
								JGRAPHICS_TEXTLAYOUT_USEELLIPSIS);
				jtextlayout_draw(x->layout_value, g);
				sysmem_freeptr(av);
			}
		}
	}

	// draw borders
	jgraphics_rectangle_rounded(g,  border_thickness, 
									border_thickness, 
									rect.width - (border_thickness * 2.0), 
									rect.height - (border_thickness * 2.0), 
									cornersize, cornersize); 
	jgraphics_set_source_rgb(g, 0.3, 0.3, 0.3);
	jgraphics_set_line_width(g, 1.5);
	jgraphics_stroke(g);

	jgraphics_set_line_width(g, 1.0);
	jgraphics_move_to(g, border_thickness, 19.5);
	jgraphics_line_to(g, rect.width - (border_thickness * 1.0), 19.5);
	jgraphics_stroke(g);
}
Exemple #7
0
void draw_harmonics(t_space *x,  t_object *view, t_rect *rect)
{
	int pathLength = 0;
	t_pt beginCoord;
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("harmonics_layer"), rect->width, rect->height);

	if (g)
	{
		t_jmatrix transform;
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
		jgraphics_set_line_width(g, 2);
        
		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 / x->f_viewer->getBiggestContribution();
            
            if(x->f_mode == 1)
                normalize = x->f_rotation_max / x->f_viewer->getBiggestContribution();
            
			double factor = (x->f_rayonGlobal * 5. / 6.) * normalize;
			
			jgraphics_set_source_jrgba(g, &x->f_color_harmonics);
			for(int i = 0; i < NUMBEROFCIRCLEPOINTS; i++)
			{
				
				if (i == NUMBEROFCIRCLEPOINTS-1) {
					jgraphics_line_to(g, beginCoord.x, beginCoord.y );
				}
				else if(x->f_viewer->getColor(i) == 1)
				{
					if (pathLength == 0) 
					{
						beginCoord.x = x->f_viewer->getAbscisseValue(i) * factor;
						beginCoord.y = x->f_viewer->getOrdinateValue(i) * factor;
						jgraphics_move_to(g, beginCoord.x, beginCoord.y );
						pathLength++;
					}
                    else
                    {
						jgraphics_line_to(g, x->f_viewer->getAbscisseValue(i) * factor, 
										  x->f_viewer->getOrdinateValue(i) * factor);
					}
				}
			}
			if (pathLength) {
				jgraphics_close_path(g);
				jgraphics_fill_preserve(g);
				jgraphics_stroke(g);
			}
		}
		jbox_end_layer((t_object*)x, view, gensym("harmonics_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("harmonics_layer"), 0., 0.);
}
Exemple #8
0
void draw_background(t_space *x,  t_object *view, t_rect *rect)
{
	int i;
	double y1, y2, rotateAngle;
	t_jmatrix transform;

	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("background_layer"), rect->width, rect->height);
	
	if (g) 
	{
		/* Background ************************************/
		jgraphics_rectangle_rounded(g, 0.5, 0.5, rect->width-1.,  rect->height-1., 12, 12);
		jgraphics_set_source_jrgba(g, &x->f_color_background);
		jgraphics_fill_preserve(g);
		jgraphics_set_source_jrgba(g, &x->f_color_border_box);
		jgraphics_stroke(g);
		
        /* Rotation slider *******************************/
        if (x->f_shadow) {
            /* Inner shadow */
            jgraphics_set_line_width(g, 4);
            jgraphics_set_source_jrgba(g, &x->f_color_circleShadow);
            jgraphics_arc(g, x->f_center.x+0.5, x->f_center.y+0.5, (double)5.5 * x->f_rayonCircle,  0., JGRAPHICS_2PI);
            jgraphics_stroke(g);
            
            jgraphics_set_line_width(g, 4);
            jgraphics_set_source_jrgba(g, &x->f_color_circleShadow);
            jgraphics_arc(g, x->f_center.x+0.5, x->f_center.y+0.5, (double)5.8 * x->f_rayonCircle,  0., JGRAPHICS_2PI);
            jgraphics_stroke(g);
        }
        /* Circle color */
        jgraphics_set_line_width(g, 3);
        jgraphics_set_source_jrgba(g, &x->f_color_circle);
        jgraphics_arc(g, x->f_center.x, x->f_center.y, (double)5.5 * x->f_rayonCircle,  0., JGRAPHICS_2PI);
        jgraphics_stroke(g);
        
        jgraphics_set_line_width(g, 3);
        jgraphics_set_source_jrgba(g, &x->f_color_circle);
        jgraphics_arc(g, x->f_center.x, x->f_center.y, (double)5.8 * x->f_rayonCircle,  0., JGRAPHICS_2PI);
        jgraphics_stroke(g);
        
        /* Gros cercle */
		jgraphics_arc(g, x->f_center.x, x->f_center.y, 5 * x->f_rayonCircle,  0., JGRAPHICS_2PI);
		jgraphics_set_source_jrgba(g, &x->f_color_circleInner);
		jgraphics_fill(g);
		
		/* Circles ***************************************/
		for(i = 5; i > 0; i--)
		{
			if (x->f_shadow) {
				/* Inner shadow */
				jgraphics_set_line_width(g, 2);
				jgraphics_set_source_jrgba(g, &x->f_color_circleShadow);
				jgraphics_arc(g, x->f_center.x+0.5, x->f_center.y+0.5, (double)i * x->f_rayonCircle,  0., JGRAPHICS_2PI);
				jgraphics_stroke(g);
			}
			/* Circle color */
			jgraphics_set_line_width(g, 1);
			jgraphics_set_source_jrgba(g, &x->f_color_circle);
			jgraphics_arc(g, x->f_center.x, x->f_center.y, (double)i * x->f_rayonCircle,  0., JGRAPHICS_2PI);
			jgraphics_stroke(g);
		}

		/* Axes *******************************************/
		jgraphics_set_source_jrgba(g, &x->f_color_circle);
		
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
		for(i = 0; i < x->f_number_of_microphones; i++)
		{
			rotateAngle = (double)i/ (double)x->f_number_of_microphones * JGRAPHICS_2PI - JGRAPHICS_2PI / ((double)x->f_number_of_microphones * 2.);
			jgraphics_rotate(g, rotateAngle);
			
			y1 = 1. / 6. * x->f_rayonGlobal;
			y2 = 5. / 6. * x->f_rayonGlobal;
			
			if (x->f_shadow) 
			{
				if ( (rotateAngle <= JGRAPHICS_PI && rotateAngle > 0.) ) 
				{
					jgraphics_move_to(g, -0.5, y1-0.5);
					jgraphics_line_to(g, -0.5, y2-0.5);
				}
				else 
				{
					jgraphics_move_to(g, 0.5, y1+0.5);
					jgraphics_line_to(g, 0.5, y2+0.5);
				}
				jgraphics_set_line_width(g, 2);
				jgraphics_set_source_jrgba(g, &x->f_color_circleShadow);
				jgraphics_stroke(g);
			}
			
			jgraphics_move_to(g, 0, y1);
			jgraphics_line_to(g, 0, y2);
			jgraphics_set_source_jrgba(g, &x->f_color_circle);
			jgraphics_set_line_width(g, 1);
			jgraphics_stroke(g);
			
			jgraphics_rotate(g, -rotateAngle);
		}
		jbox_end_layer((t_object*)x, view, gensym("background_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("background_layer"), 0., 0.);
}
Exemple #9
0
void draw_harmonics(t_scope *x,  t_object *view, t_rect *rect)
{
	int pathLength = 0;
	t_pt beginCoord;
    t_jpath* posHarmPath = NULL;
    t_jpath* negHarmPath = NULL;
    t_jmatrix transform;
    t_jrgba shadcolor = {0.4, 0.4, 0.4, 0.9};
    double alphaShadow = 1.;
    long posPathLen, negPathLen;
    long precIndex = 0;
    double factor;
    posPathLen = negPathLen = 0;
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("harmonics_layer"), rect->width, rect->height);
    
    if (alphaShadow > x->f_colorPositif.alpha ) alphaShadow = x->f_colorPositif.alpha;
	if (alphaShadow > x->f_colorNegatif.alpha ) alphaShadow = x->f_colorNegatif.alpha;
	alphaShadow -= 0.5;
	if (alphaShadow < 0.) alphaShadow = 0;
	shadcolor.alpha = alphaShadow;
    
	if (g)
	{
		jgraphics_set_line_join(g, JGRAPHICS_LINE_JOIN_ROUND);
        jgraphics_set_line_cap(g, JGRAPHICS_LINE_CAP_ROUND);
		jgraphics_set_line_width(g, 1);
		if(x->f_viewer->getBiggestContribution() > 0.)
		{
            factor = (x->f_rayonGlobal * 5. / 6.);
            if (x->f_viewer->getBiggestContribution() > 1)
                factor /= x->f_viewer->getBiggestContribution();
            
            Tools::clip(&factor, 0., (x->f_rayonGlobal * 5. / 6.));
			
            // positiv harmonics
			for(int i = 0; i < NUMBEROFCIRCLEPOINTS_UI; i++)
			{
				precIndex = i-1;
                if (precIndex < 0) precIndex += NUMBEROFCIRCLEPOINTS_UI;
                
				if (i == NUMBEROFCIRCLEPOINTS_UI-1) {
					jgraphics_line_to(g, beginCoord.x, beginCoord.y );
				}
				else if(x->f_viewer->getColor(i) == 1 || x->f_viewer->getColor(i) == 0)
				{
					if (pathLength == 0)
					{
						beginCoord.x = x->f_viewer->getAbscisseValue(i) * factor;
						beginCoord.y = x->f_viewer->getOrdinateValue(i) * factor;
						jgraphics_move_to(g, beginCoord.x, beginCoord.y );
						pathLength++;
					}
                    else if(x->f_viewer->getColor(precIndex) != 1)
                    {
                        jgraphics_line_to(g, 0, 0);
                        jgraphics_move_to(g, x->f_viewer->getAbscisseValue(i) * factor, x->f_viewer->getOrdinateValue(i) * factor);
                    }
                    else
                    {
						jgraphics_line_to(g, x->f_viewer->getAbscisseValue(i) * factor, x->f_viewer->getOrdinateValue(i) * factor);
					}
				}
			}
			if (pathLength) {
				//jgraphics_close_path(g);
                posHarmPath = jgraphics_copy_path(g);
			}
            posPathLen = pathLength;
			
			pathLength = 0;
			jgraphics_new_path(g);
			for(int i = 0; i < NUMBEROFCIRCLEPOINTS_UI; i++)
			{
				precIndex = i-1;
                if (precIndex < 0) precIndex += NUMBEROFCIRCLEPOINTS_UI;
                
				if (i == NUMBEROFCIRCLEPOINTS_UI-1) {
					jgraphics_line_to(g, beginCoord.x, beginCoord.y );
				}
				else if(x->f_viewer->getColor(i) == -1 || x->f_viewer->getColor(i) == 0)
				{
					if (!pathLength)
					{
						beginCoord.x = x->f_viewer->getAbscisseValue(i) * factor;
						beginCoord.y = x->f_viewer->getOrdinateValue(i) * factor;
						jgraphics_move_to(g, beginCoord.x, beginCoord.y );
						pathLength++;
					}
                    else if(x->f_viewer->getColor(precIndex) != -1)
                    {
                        jgraphics_line_to(g, 0, 0);
                        jgraphics_move_to(g, x->f_viewer->getAbscisseValue(i) * factor, x->f_viewer->getOrdinateValue(i) * factor);
                    }
                    else
                    {
						jgraphics_line_to(g, x->f_viewer->getAbscisseValue(i) * factor, x->f_viewer->getOrdinateValue(i) * factor);
					}
				}
			}
			if (pathLength) {
				//jgraphics_close_path(g);
                negHarmPath = jgraphics_copy_path(g);
			}
            negPathLen = pathLength;
            
            // draw harmonics :
            if (posPathLen || negPathLen) {
                jgraphics_new_path(g);
                jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
                jgraphics_set_matrix(g, &transform);
                
                // shadows
                if (posPathLen) jgraphics_append_path(g, posHarmPath);
                //if (negPathLen) jgraphics_append_path(g, negHarmPath);
                jgraphics_set_source_jrgba(g, &shadcolor);
                jgraphics_stroke(g);
                
                jgraphics_translate(g, 1, 1);
                // harmocolor
                if (posPathLen) jgraphics_append_path(g, posHarmPath);
                jgraphics_set_source_jrgba(g, &x->f_colorPositif);
                jgraphics_stroke(g);
                
                if (negPathLen) jgraphics_append_path(g, negHarmPath);
                jgraphics_set_source_jrgba(g, &x->f_colorNegatif);
                jgraphics_stroke(g);
            }
		}
		jbox_end_layer((t_object*)x, view, gensym("harmonics_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("harmonics_layer"), 0., 0.);
}
Exemple #10
0
void draw_background(t_scope *x,  t_object *view, t_rect *rect)
{
	int i;
	double y1, y2, rotateAngle;
    t_jmatrix transform;
    t_jrgba black, white;
    double contrastBlack = 0.12;
    double contrastWhite = 0.08;
    
    black = white = x->f_colorBackground;
    black.red = Tools::clip_min(black.red -= contrastBlack);
    black.green = Tools::clip_min(black.green -= contrastBlack);
    black.blue = Tools::clip_min(black.blue -= contrastBlack);
    
    white.red = Tools::clip_max(white.red += contrastWhite, 1.);
    white.green = Tools::clip_max(white.green += contrastWhite, 1.);
    white.blue = Tools::clip_max(white.blue += contrastWhite, 1.);
    
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("background_layer"), rect->width, rect->height);

	if (g) 
	{
		/* Background */
        /*
		jgraphics_set_source_jrgba(g, &x->f_colorBackground);
		jgraphics_rectangle_rounded(g, 0., 0., rect->width, rect->height, 6, 6);
		jgraphics_fill(g);
        */
		
		/* Circles */
		for(i = 5; i > 0; i--)
		{
            //inner shadow
            jgraphics_set_line_width(g, 2);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_arc(g, x->f_center.x+0.5, x->f_center.y+0.5, (double)i * x->f_rayonCircle,  0., CICM_2PI);
            jgraphics_stroke(g);
            jgraphics_set_line_width(g, 1);
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_arc(g, x->f_center.x, x->f_center.y, (double)i * x->f_rayonCircle,  0., CICM_2PI);
            jgraphics_stroke(g);
		}
		/* Axes */
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
        jgraphics_set_source_jrgba(g, &black);
		//for(i = 0; i < 12; i++)
        for(i = 0; i < (x->f_order * 2 + 2) ; i++)
		{
            rotateAngle = ( (double)i/(x->f_order * 2 + 2) * CICM_2PI ) - ( 0.5/(x->f_order * 2 + 2) * CICM_2PI );
			jgraphics_rotate(g, rotateAngle);
			
			y1 = 1. / 6. * x->f_rayonGlobal;
			y2 = 5. / 6. * x->f_rayonGlobal;
			
			if ( (rotateAngle <= CICM_PI && rotateAngle > 0.) )
            {
                jgraphics_move_to(g, -0.5, y1-0.5);
                jgraphics_line_to(g, -0.5, y2-0.5);
            }
            else
            {
                jgraphics_move_to(g, 0.5, y1+0.5);
                jgraphics_line_to(g, 0.5, y2+0.5);
            }
            jgraphics_set_line_width(g, 2);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_stroke(g);
            
			jgraphics_move_to(g, 0, y1);
			jgraphics_line_to(g, 0, y2);
            jgraphics_set_source_jrgba(g, &black);
			jgraphics_set_line_width(g, 1);
			jgraphics_stroke(g);
			
			jgraphics_rotate(g, -rotateAngle);
		}
		jbox_end_layer((t_object*)x, view, gensym("background_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("background_layer"), 0., 0.);
}
Exemple #11
0
void draw_harmonics(t_hoa_scope *x,  t_object *view, t_rect *rect)
{
	int pathLength = 0;
	t_pt beginCoord;
    t_jpath* posHarmPath = NULL;
    t_jpath* negHarmPath = NULL;
    t_jmatrix transform;
    t_jrgba shadcolor = {0.4, 0.4, 0.4, 1.};
    long posPathLen = 0, negPathLen = 0, precIndex = 0;

	t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_harmonics_layer, rect->width, rect->height);
    
    if(shadcolor.alpha > x->f_color_nh.alpha)
        shadcolor.alpha = x->f_color_ph.alpha;
    if(shadcolor.alpha > x->f_color_nh.alpha)
        shadcolor.alpha = x->f_color_nh.alpha;
	shadcolor.alpha -= 0.5;
	if(shadcolor.alpha < 0.)
        shadcolor.alpha = 0;
    
	if (g)
	{
        jgraphics_rotate(g, HOA_PI);
		jgraphics_set_line_join(g, JGRAPHICS_LINE_JOIN_ROUND);
        jgraphics_set_line_cap(g, JGRAPHICS_LINE_CAP_ROUND);
		jgraphics_set_line_width(g, 1);
        
        // positiv harmonics
        for(int i = 0; i < x->f_scope->getNumberOfPoints(); i++)
        {
            precIndex = i-1;
            if(precIndex < 0)
                precIndex += x->f_scope->getNumberOfPoints();
            
            if(i == x->f_scope->getNumberOfPoints()-1)
            {
                jgraphics_line_to(g, beginCoord.x, beginCoord.y );
            }
            else if(x->f_scope->getValue(i) >= 0)
            {
                if (pathLength == 0)
                {
                    beginCoord.x = x->f_scope->getAbscissa(i) * x->f_radius;
                    beginCoord.y = x->f_scope->getOrdinate(i) * x->f_radius;
                    jgraphics_move_to(g, beginCoord.x, beginCoord.y );
                    pathLength++;
                }
                else if(x->f_scope->getValue(i) < 0)
                {
                    jgraphics_line_to(g, 0, 0);
                    jgraphics_move_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
                else
                {
                    jgraphics_line_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
            }
        }
        if (pathLength)
        {
            posHarmPath = jgraphics_copy_path(g);
        }
        posPathLen = pathLength;
        
        pathLength = 0;
        jgraphics_new_path(g);
        for(int i = 0; i < x->f_scope->getNumberOfPoints(); i++)
        {
            precIndex = i-1;
            if (precIndex < 0) precIndex += x->f_scope->getNumberOfPoints();
            
            if (i == x->f_scope->getNumberOfPoints()-1)
            {
                jgraphics_line_to(g, beginCoord.x, beginCoord.y );
            }
            else if(x->f_scope->getValue(i) < 0)
            {
                if (!pathLength)
                {
                    beginCoord.x = x->f_scope->getAbscissa(i) * x->f_radius;
                    beginCoord.y = x->f_scope->getOrdinate(i) * x->f_radius;
                    jgraphics_move_to(g, beginCoord.x, beginCoord.y );
                    pathLength++;
                }
                else if(x->f_scope->getValue(precIndex) >= 0)
                {
                    jgraphics_line_to(g, 0, 0);
                    jgraphics_move_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
                else
                {
                    jgraphics_line_to(g, x->f_scope->getAbscissa(i) * x->f_radius, x->f_scope->getOrdinate(i) * x->f_radius);
                }
            }
        }
        if(pathLength)
        {
            negHarmPath = jgraphics_copy_path(g);
        }
        negPathLen = pathLength;
        
        // draw harmonics :
        if(posPathLen || negPathLen)
        {
            jgraphics_new_path(g);
            jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
            jgraphics_set_matrix(g, &transform);
            
            // shadows
            jgraphics_translate(g, 1, 1); // decalage de l'ombre
            if (posPathLen) jgraphics_append_path(g, posHarmPath);
            if (negPathLen) jgraphics_append_path(g, negHarmPath);
            jgraphics_set_source_jrgba(g, &shadcolor);
            jgraphics_stroke(g);
            jgraphics_translate(g, -1, -1); // annulation du decalage
            
            // harmocolor
            if(posPathLen)
            {
                jgraphics_append_path(g, posHarmPath);
                jgraphics_set_source_jrgba(g, &x->f_color_ph);
                jgraphics_stroke(g);
            }
            if(negPathLen)
            {
                jgraphics_append_path(g, negHarmPath);
                jgraphics_set_source_jrgba(g, &x->f_color_nh);
                jgraphics_stroke(g);
            }
        }

		jbox_end_layer((t_object*)x, view, hoa_sym_harmonics_layer);
	}
	jbox_paint_layer((t_object *)x, view, hoa_sym_harmonics_layer, 0., 0.);
}
Exemple #12
0
void draw_background(t_hoa_scope *x,  t_object *view, t_rect *rect)
{
	int i;
	double y1, y2, rotateAngle;
    t_jmatrix transform;
    t_jrgba black, white;
    
    black = white = x->f_color_bg;
    black.red = clip_min(black.red - contrast_black, 0.);
    black.green = clip_min(black.green - contrast_black, 0.);
    black.blue = clip_min(black.blue - contrast_black, 0.);
    
    white.red = clip_max(white.red + contrast_white, 1.);
    white.green = clip_max(white.green + contrast_white, 1.);
    white.blue = clip_max(white.blue + contrast_white, 1.);
    
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_background_layer, rect->width, rect->height);

	if (g) 
	{
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
		jgraphics_set_matrix(g, &transform);

        for(i = 0; i < (x->f_order * 2 + 2) ; i++)
		{
            rotateAngle = ((double)i / (x->f_order * 2 + 2) * HOA_2PI ) - (0.5 / (x->f_order * 2 + 2) * HOA_2PI);
			jgraphics_rotate(g, rotateAngle);
			
			y1 = x->f_radius / 5.;
			y2 = x->f_radius;
            
            if(rotateAngle > HOA_PI2 && rotateAngle < HOA_PI + HOA_PI2)
            {
                jgraphics_move_to(g, -1, long(y1));
                jgraphics_line_to(g, -1, long(y2));
            }
            else
            {
                jgraphics_move_to(g, 1, long(y1));
                jgraphics_line_to(g, 1, long(y2));
            }
            jgraphics_set_line_width(g, 2);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_stroke(g);
            
			jgraphics_move_to(g, 0, y1);
			jgraphics_line_to(g, 0, y2);
            jgraphics_set_source_jrgba(g, &black);
			jgraphics_set_line_width(g, 1);
			jgraphics_stroke(g);
			
			jgraphics_rotate(g, -rotateAngle);
		}
        
        jgraphics_matrix_init(&transform, 1, 0, 0, 1, x->f_center, x->f_center);
		jgraphics_set_matrix(g, &transform);
        
        for(i = 5; i > 0; i--)
		{
            jgraphics_set_line_width(g, 2);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_arc(g, 1, 1, (double)i / 5. * x->f_radius,  0., HOA_2PI);
            jgraphics_stroke(g);
            jgraphics_set_line_width(g, 1);
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_arc(g, 0, 0, (double)i / 5.* x->f_radius,  0., HOA_2PI);
            jgraphics_stroke(g);
		}
        
		jbox_end_layer((t_object*)x, view, hoa_sym_background_layer);
	}
	jbox_paint_layer((t_object *)x, view, hoa_sym_background_layer, 0., 0.);
}
Exemple #13
0
void hoa_space_draw_background(t_hoa_space *x, t_object *view, t_rect *rect)
{
    t_jgraphics *g = jbox_start_layer((t_object *)x, view, gensym("background_layer"), rect->width, rect->height);
	
    if (g)
	{
        t_jmatrix transform;
        jgraphics_matrix_init(&transform, 1, 0, 0, 1, x->f_center.x, x->f_center.y);
		jgraphics_set_matrix(g, &transform);
        
        t_jrgba black  = jrgba_addContrast(x->f_color_inner_circle, -0.12);
        t_jrgba white  = jrgba_addContrast(x->f_color_inner_circle, 0.08);
        
        jgraphics_set_source_jrgba(g, &x->f_color_inner_circle);
		jgraphics_arc(g, 0., 0., x->f_radius_ext_circle,  0.f, JGRAPHICS_2PI);
		jgraphics_fill(g);
		
		for(int i = NUMBER_OF_CIRCLES; i > 0; i--)
		{
            jgraphics_set_line_width(g, 2);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_arc(g, -0.5, -0.5, (double)i * x->f_radius_circle,  0.f, JGRAPHICS_2PI);
            jgraphics_stroke(g);
            
			jgraphics_set_line_width(g, 1);
			jgraphics_set_source_jrgba(g, &black);
			jgraphics_arc(g, 0, 0, (double)i * x->f_radius_circle,  0.f, JGRAPHICS_2PI);
			jgraphics_stroke(g);
		}
        
		double coso, sino, angle, x1, y1, x2, y2, rad1, rad2, offset;
        offset = CICM_PI / (double)x->f_number_of_microphones;
        rad1 = 1. / (double)NUMBER_OF_CIRCLES * x->f_radius_ext_circle;
        rad2 = x->f_radius_ext_circle;
        
		for(int i = 0; i < x->f_number_of_microphones; i++)
		{
            jgraphics_set_source_jrgba(g, &white);
            angle = i * CICM_2PI / (double)x->f_number_of_microphones + offset + CICM_PI2;
            coso = cosf(angle);
            sino = sinf(angle);
            x1 = rad1 * coso;
            y1 = rad1 * sino;
            x2 = rad2 * coso;
            y2 = rad2 * sino;
            
            if(Tools::isInsideDeg(angle / CICM_2PI * 360., 45, 225))
            {
                jgraphics_move_to(g, x1 - 0.5, y1 - 0.5);
                jgraphics_line_to(g, x2 - 0.5, y2 - 0.5);
            }
            else
            {
                jgraphics_move_to(g, x1 + 0.5, y1 + 0.5);
                jgraphics_line_to(g, x2 + 0.5, y2 + 0.5);
            }
            jgraphics_stroke(g);
            
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_move_to(g, x1, y1);
            jgraphics_line_to(g, x2, y2);
            jgraphics_stroke(g);
			
		}
		jbox_end_layer((t_object*)x, view, gensym("background_layer"));
	}
	jbox_paint_layer((t_object *)x, view, gensym("background_layer"), 0., 0.);
}
void draw_harmonics(t_hoa_3d_scope *x, t_object *view, t_rect *rect)
{
	t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_harmonics_layer, rect->width, rect->height);
    
	if (g)
	{
        char pathLength;
        t_jmatrix transform;
        t_jrgba color_pos;
        t_jrgba color_neg;
        t_jrgba black = rgba_addContrast(x->f_color_bg, -contrast_black);
        t_jrgba white = rgba_addContrast(x->f_color_bg, contrast_white);
        
        jgraphics_rotate(g, HOA_PI);
        jgraphics_set_line_width(g, 1);
		jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center);
		jgraphics_set_matrix(g, &transform);
        
        for(ulong j = 0; j < x->f_scope->getNumberOfRows() * 0.5; j++)
        {
            pathLength = 0;
            double constrast = (j - x->f_scope->getNumberOfRows() * 0.5) / (double)x->f_scope->getNumberOfRows();
            color_pos = rgba_addContrast(x->f_color_ph, constrast);
            color_neg = rgba_addContrast(x->f_color_nh, constrast);
            jgraphics_set_source_jrgba(g, &color_pos);
            double elev = x->f_scope->getPointElevation(j);
            
            for(int i = 0; i < x->f_scope->getNumberOfColumns(); i++)
            {
                double azim = x->f_scope->getPointAzimuth(i);
                double value = x->f_scope->getPointValue(j, i);
                if(value >= 0)
                {
                    value *= x->f_radius;
                    if(!pathLength)
                    {
                        jgraphics_move_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                        pathLength++;
                    }
                    else
                    {
                        jgraphics_line_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                    }
                }
            }
            jgraphics_close_path(g);
            if(pathLength)
                jgraphics_fill(g);
            
            pathLength = 0;
            jgraphics_set_source_jrgba(g, &color_neg);
            
            for(int i = 0; i < x->f_scope->getNumberOfColumns(); i++)
            {
                double azim = x->f_scope->getPointAzimuth(i);
                double value = x->f_scope->getPointValue(j, i);
                if(value < 0)
                {
                    value *= -x->f_radius;
                    if(!pathLength)
                    {
                        jgraphics_move_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                        pathLength++;
                    }
                    else
                    {
                        jgraphics_line_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                    }
                }
            }
            jgraphics_close_path(g);
            if(pathLength)
                jgraphics_fill(g);
        }
        
		double angle, x1, x2, y1, y2, cosa, sina;
        for(int i = 0; i < (x->f_order * 2 + 2) ; i++)
		{
            angle = ((double)(i - 0.5) / (x->f_order * 2 + 2) * HOA_2PI);
			cosa = cos(angle);
            sina = sin(angle);
            x1 = cosa * x->f_radius * 0.2;
			y1 = sina * x->f_radius * 0.2;
            x2 = cosa * x->f_radius;
			y2 = sina * x->f_radius;
            
            jgraphics_move_to(g, x1, y1);
			jgraphics_line_to(g, x2, y2);
            jgraphics_set_line_width(g, 3);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_stroke(g);
            jgraphics_set_source_jrgba(g, &black);
			jgraphics_set_line_width(g, 1);
			jgraphics_stroke(g);
		}
        
        for(int i = 5; i > 0; i--)
		{
            jgraphics_set_line_width(g, 3);
            jgraphics_set_source_jrgba(g, &white);
            jgraphics_arc(g, 0, 0, (double)i * 0.2 * x->f_radius,  0., HOA_2PI);
            jgraphics_stroke(g);
            jgraphics_set_line_width(g, 1);
            jgraphics_set_source_jrgba(g, &black);
            jgraphics_stroke(g);
		}
        
        for(ulong j = (ulong)(x->f_scope->getNumberOfRows() * 0.5); j < x->f_scope->getNumberOfRows(); j++)
        {
            // positive harmonics
            pathLength = 0;
            double constrast = (j - x->f_scope->getNumberOfRows() * 0.5) / (double)x->f_scope->getNumberOfRows();
            color_pos = rgba_addContrast(x->f_color_ph, constrast);
            color_neg = rgba_addContrast(x->f_color_nh, constrast);
            jgraphics_set_source_jrgba(g, &color_pos);
            double elev = x->f_scope->getPointElevation(j);
            for(int i = 0; i < x->f_scope->getNumberOfColumns(); i++)
            {
                double azim = x->f_scope->getPointAzimuth(i);
                double value = x->f_scope->getPointValue(j, i);
                if(value >= 0)
                {
                    value *= x->f_radius;
                    if(!pathLength)
                    {
                        jgraphics_move_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                        pathLength++;
                    }
                    else
                    {
                        jgraphics_line_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                    }
                }
            }
            jgraphics_close_path(g);
            if(pathLength)
                jgraphics_fill(g);
            
            pathLength = 0;
            // negative harmonics
            jgraphics_set_source_jrgba(g, &color_neg);
            for(int i = 0; i < x->f_scope->getNumberOfColumns(); i++)
            {
                double azim = x->f_scope->getPointAzimuth(i);
                double value = x->f_scope->getPointValue(j, i);
                if(value < 0)
                {
                    value *= -x->f_radius;
                    if(!pathLength)
                    {
                        jgraphics_move_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                        pathLength++;
                    }
                    else
                    {
                        jgraphics_line_to(g, Math<double>::abscissa(value, azim,elev), Math<double>::ordinate(value, azim, elev));
                    }
                }
            }
            jgraphics_close_path(g);
            if(pathLength)
                jgraphics_fill(g);
        }
		
		jbox_end_layer((t_object*)x, view, hoa_sym_harmonics_layer);
	}
	jbox_paint_layer((t_object *)x, view, hoa_sym_harmonics_layer, 0., 0.);
}
Exemple #15
0
void rd_paint(t_rd *x, t_object *patcherview){
	t_rect rect;
    
	t_jgraphics *g = (t_jgraphics *)patcherview_get_jgraphics(patcherview);
	jbox_get_rect_for_view((t_object *)x, patcherview, &rect);
        
	jgraphics_set_source_jrgba(g, &(x->bordercolor));
	jgraphics_set_line_width(g, 1);
	jgraphics_rectangle(g, 0., 0., rect.width, rect.height);
	jgraphics_stroke(g);
    
	jgraphics_set_source_jrgba(g, &(x->bgcolor));
	jgraphics_rectangle(g, 0., 0., rect.width, rect.height);
	jgraphics_fill(g);

	// data
	{
		jgraphics_set_source_jrgba(g, &(x->datacolor));
		int i;
		if(x->sinusoids){
			t_sin *s = (t_sin *)(x->buffer);
			for(i = 0; i < x->n; i++){
				double xx, yy;
				xx = rd_scale(s[i].f, x->freqmin, x->freqmax, 0, rect.width);
				if(x->log){
					yy = rd_scale((20. * log(s[i].a)) / log(10), x->ampmin_log, x->ampmax_log, rect.height, 0.);
				}else{
					yy = rd_scale(s[i].a, x->ampmin, x->ampmax, rect.height, 0);
				}

				jgraphics_move_to(g, xx, yy);
				jgraphics_line_to(g, xx, rect.height);
				jgraphics_stroke(g);
			}

		}else if(x->mode){
			t_jsurface *s = jgraphics_image_surface_create(JGRAPHICS_FORMAT_ARGB32, rect.width, rect.height);
			//t_jgraphics *gg = jgraphics_create(s);
			t_res *r = (t_res *)(x->buffer);
			int j;
			t_jrgba c;
			for(j = 0; j < rect.width; j++){
				for(i = 0; i < x->n; i++){
					double amp = exp((-j / (rect.width * .1)) * r[i].d);
					c = (t_jrgba){x->datacolor.red * amp, x->datacolor.green * amp, x->datacolor.blue * amp, 1.};
					jgraphics_image_surface_set_pixel(s, j, rd_scale(r[i].f, x->freqmin, x->freqmax, rect.height, 0), c);

					//jgraphics_set_source_jrgba(g, &c);
					//jgraphics_ellipse(g, j, rd_scale(r[i].f, 0., 22050., rect.height, 0), 1, 1);
					//jgraphics_fill(g);
					//jgraphics_move_to(g, 0, yy1);
					//jgraphics_line_to(g, xx, yy2);
				}
			}
			jgraphics_image_surface_draw(g, s, (t_rect){0., 0., rect.width, rect.height}, (t_rect){0., 0., rect.width, rect.height});
		}else{
			t_res *r = (t_res *)(x->buffer);
			for(i = 0; i < x->n; i++){
				double xx, yy1, yy2;
				xx = rd_scale(r[i].f, x->freqmin, x->freqmax, 0, rect.width);
				if(x->log){
					//yy1 = rd_scale((100+20.0*log(r[i].a))/100./log(10), -1., 1., rect.height, 0.);
					yy1 = rd_scale((20.0*log(r[i].a))/log(10), x->ampmin_log, x->ampmax_log, rect.height, 0.);
				}else{
					yy1 = rd_scale(r[i].a, x->ampmin, x->ampmax, rect.height, 0);
				}
				yy2 = fabs((rect.height - yy1) * (.4 / sqrt(r[i].d))) + yy1;

				jgraphics_move_to(g, xx, yy1);
				jgraphics_line_to(g, xx, yy2);
				jgraphics_stroke(g);
			}
		}
	}

	// selection lines
	{
		jgraphics_set_source_jrgba(g, &(x->selectioncolor));
		if(x->mode){
			jgraphics_move_to(g, 0, rd_scale(x->selection.min, x->freqmin, x->freqmax, rect.height, 0));
			jgraphics_line_to(g, rect.width, rd_scale(x->selection.min, x->freqmin, x->freqmax, rect.height, 0));
			jgraphics_move_to(g, 0, rd_scale(x->selection.max, x->freqmin, x->freqmax, rect.height, 0));
			jgraphics_line_to(g, rect.width, rd_scale(x->selection.max, x->freqmin, x->freqmax, rect.height, 0));
		}else{
			jgraphics_move_to(g, rd_scale(x->selection.min, x->freqmin, x->freqmax, 0, rect.width), 0);
			jgraphics_line_to(g, rd_scale(x->selection.min, x->freqmin, x->freqmax, 0, rect.width), rect.height);
			jgraphics_move_to(g, rd_scale(x->selection.max, x->freqmin, x->freqmax, 0, rect.width), 0);
			jgraphics_line_to(g, rd_scale(x->selection.max, x->freqmin, x->freqmax, 0, rect.width), rect.height);
		}
		jgraphics_stroke(g);
	}

	// info
	{
		char buf[128];
		double w, h;
		jgraphics_set_source_jrgba(g, &x->datacolor);
		sprintf(buf, "%0.2f", x->selection.min);
		jgraphics_text_measure(g, buf, &w, &h);
		jgraphics_move_to(g, 0, h);
		jgraphics_show_text(g, buf);

		sprintf(buf, "%0.2f", x->selection.max);
		jgraphics_text_measure(g, buf, &w, &h);
		jgraphics_move_to(g, rect.width - w, h);
		jgraphics_show_text(g, buf);

		sprintf(buf, "%0.2fHz (%0.2fMc) %d/%ld", x->selection.max - x->selection.min, rd_ftom(x->selection.max) - rd_ftom(x->selection.min), x->num_partials_selected, x->n);
		jgraphics_text_measure(g, buf, &w, &h);
		jgraphics_move_to(g, (rect.width / 2) - (w / 2), h);
		jgraphics_show_text(g, buf);
	}
}