void pictmeter_paint(t_pictmeter *x, t_object *patcherview) { t_rect src, dst, rect; t_jgraphics *g = (t_jgraphics *) patcherview_get_jgraphics(patcherview); // obtain graphics context jbox_get_rect_for_view((t_object *)x, patcherview, &rect); if (!x->p_surface) return; // draw if the value is non zero if (x->p_value) { src.width = jgraphics_image_surface_get_width(x->p_surface); src.height = jgraphics_image_surface_get_height(x->p_surface); src.x = 0; src.y = 0; dst.width = rect.width * x->p_value; dst.height = rect.height * x->p_value; if (dst.width < 1 || dst.height < 1) return; dst.x = 0 + ((rect.width * 0.5) - (dst.width * 0.5)); dst.y = 0 + ((rect.height * 0.5) - (dst.height * 0.5)); jgraphics_image_surface_draw(g, x->p_surface, src, dst); } }
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 jucebox_paint(t_jucebox* x, t_object *patcherview) { t_rect rect, srcRect, destRect; int width, height, imgStride; unsigned char* data; if(x->j_component->isOnDesktop()) { x->j_component->setActive(); if(x->j_component->isContextOk()) { jbox_get_rect_for_view((t_object *)x, patcherview, &rect); t_jgraphics *g = (t_jgraphics *)patcherview_get_jgraphics(patcherview); if(g) { juce::Image openGLSnap = x->j_component->makeScreenshot((t_object *)x, rect.width, rect.height); juce::Image::BitmapData* snapBitmap = new juce::Image::BitmapData(openGLSnap, juce::Image::BitmapData::readOnly); data = snapBitmap->data; width = openGLSnap.getWidth(); height = openGLSnap.getHeight(); imgStride = snapBitmap->lineStride; srcRect.x = 0; destRect.x = 0; srcRect.y = 0; destRect.y = 0; srcRect.width = openGLSnap.getWidth(); srcRect.height = openGLSnap.getHeight(); destRect.width = rect.width; destRect.height = rect.height; t_jsurface* surface = jgraphics_image_surface_create_for_data(data, JGRAPHICS_FORMAT_ARGB32, width, height, imgStride, NULL, NULL); jgraphics_image_surface_draw(g, surface, srcRect, destRect); jgraphics_surface_destroy(surface); } } } }
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); } }