void meterCacheSurface(t_meter* x) { t_jrgba color; t_jbox* box = (t_jbox*)x; int i, j; x->gradientRect.x = 0; x->gradientRect.y = 0; // horizontal mode if (x->effectOrientation) { x->gradientRect.width = box->b_patching_rect.width * 0.96; x->gradientRect.height = box->b_patching_rect.height; } // vertical mode else { x->gradientRect.width = box->b_patching_rect.width; x->gradientRect.height = box->b_patching_rect.height * 0.96; } if (x->gradientSurface) jgraphics_surface_destroy(x->gradientSurface); x->gradientSurface = jgraphics_image_surface_create(JGRAPHICS_FORMAT_ARGB32, x->gradientRect.width, x->gradientRect.height); color.red = 0.0; color.green = 1.0; color.blue = 0.0; color.alpha = 1.0; // horizontal mode if (x->effectOrientation) { for (i=0; i < x->gradientRect.width; i++) { color.red = i / x->gradientRect.width; for (j=0; j < x->gradientRect.height; j++) jgraphics_image_surface_set_pixel(x->gradientSurface, i, j, color); } } else { for (j=0; j < x->gradientRect.height; j++) { color.red = 1. - (j / x->gradientRect.height); for (i=0; i < x->gradientRect.width; i++) jgraphics_image_surface_set_pixel(x->gradientSurface, i, j, color); } } }
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); } }