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.); }
void draw_leds(t_meter *x, t_object *view, t_rect *rect) { t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_leds_layer, rect->width, rect->height); if (g) { int i, j, nbLed, tepidLimit, warmLimit, hotLimit; long nLoudSpeak = x->f_meter->getNumberOfPlanewaves(); double deg1, deg2, rotateAngle, ledContainerSize, ledMargin, ledOffset, meter_dB, min_dB_to_display, channelWidth; double tmpdeg1, tmpdeg2, tmprad; t_jrgba ledColor; t_jmatrix transform; deg1 = HOA_PI2; nbLed = x->f_numleds+1; ledContainerSize = x->f_rayonExt - x->f_rayonInt - 4; ledOffset = ledContainerSize / nbLed; ledMargin = ledOffset * 0.50; hotLimit = x->f_numleds - x->f_nhotleds; warmLimit = hotLimit - x->f_nwarmleds; tepidLimit = warmLimit - x->f_ntepidleds; min_dB_to_display = -1 * ( (x->f_numleds * x->f_dbperled) - (x->f_dbperled * 0.5) ); jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center); jgraphics_set_matrix(g, &transform); jgraphics_set_line_cap(g, JGRAPHICS_LINE_CAP_BUTT); for(i = 0; i < nLoudSpeak; i++) { // dB (negatif) de -240 à 0; meter_dB = x->f_meter->getPlanewaveEnergy(i); channelWidth = radToDeg(x->f_meter->getPlanewaveWidth(i)); deg2 = degToRad(90+(channelWidth)); 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)); if ( meter_dB > min_dB_to_display ) // si on est en dessous pas la peine de dessiner { // leds : jgraphics_set_line_width(g, ledMargin); for(j=0; j<nbLed-1; j++) { if ( ( j < nbLed-1 ) && ( meter_dB > min_dB_to_display + (x->f_dbperled * j) ) ) { if ( j < tepidLimit ) ledColor = x->f_color_cold; else if ( j < warmLimit ) ledColor = x->f_color_tepid; else if ( j < hotLimit ) ledColor = x->f_color_warm; else ledColor = x->f_color_hot; jgraphics_set_source_jrgba(g, &ledColor); jgraphics_set_line_width(g, ledMargin); if (nLoudSpeak > 1) { if ( nLoudSpeak < 24 && (channelWidth > 14.5 )) { tmpdeg1 = 0, tmpdeg2 = 0, tmprad = 0; if (x->f_direction == 0) // inside { tmpdeg1 = deg1 + (0.01 * (j+4) * x->f_metersize); tmpdeg2 = deg2 - (0.01 * (j+4) * x->f_metersize); tmprad = x->f_rayonExt - (j*ledOffset) - ledMargin - 2; } else // outside { tmpdeg1 = deg1 + (0.01 * (nbLed+3-(j)) * x->f_metersize); tmpdeg2 = deg2 - (0.01 * (nbLed+3-(j)) * x->f_metersize); tmprad = x->f_rayonInt + (j*ledOffset) + ledMargin + 2; } if (tmpdeg1 < tmpdeg2) jgraphics_arc(g, 0, 0, tmprad, tmpdeg1, tmpdeg2); else jgraphics_arc(g, 0, 0, tmprad, tmpdeg2, tmpdeg1); } else { if (x->f_direction == 0) jgraphics_arc_negative(g, 0, 0, x->f_rayonExt-(j*ledOffset) - ledMargin - 2, deg2, deg1); else jgraphics_arc_negative(g, 0, 0, x->f_rayonInt+(j*ledOffset) + ledMargin + 2, deg2, deg1); } } else { if (x->f_direction == 0) jgraphics_arc(g, 0, 0, x->f_rayonExt-(j*ledOffset) - ledMargin - 2, 0, HOA_2PI); else jgraphics_arc(g, 0, 0, x->f_rayonInt+(j*ledOffset) + ledMargin + 2, 0, HOA_2PI); } jgraphics_stroke(g); } else { break; } } } if(x->f_meter->getPlanewaveOverLed(i)) { jgraphics_set_source_jrgba(g, &x->f_color_over); jgraphics_set_line_width(g, ledMargin); if (nLoudSpeak > 1) { if ( nLoudSpeak < 24 && (channelWidth > 14.5 )) { double tmpdeg1 = 0, tmpdeg2 = 0, tmprad = 0; if (x->f_direction == 0) // inside { tmpdeg1 = deg1 + (0.01 * (nbLed+1) * x->f_metersize); tmpdeg2 = deg2 - (0.01 * (nbLed+1) * x->f_metersize); tmprad = x->f_rayonInt + ledMargin + 1; } else // outside { tmpdeg1 = deg1+(0.008 * 3 * x->f_metersize); tmpdeg2 = deg2-(0.008 * 3 * x->f_metersize); tmprad = x->f_rayonExt - ledMargin - 1; } if (tmpdeg1 < tmpdeg2) jgraphics_arc(g, 0, 0, tmprad, tmpdeg1, tmpdeg2); else jgraphics_arc_negative(g, 0, 0, tmprad, tmpdeg1, tmpdeg2); } else { if (x->f_direction == 0) // inside jgraphics_arc_negative(g, 0, 0, x->f_rayonInt + ledMargin + 1, deg2, deg1); else // outside jgraphics_arc_negative(g, 0, 0, x->f_rayonExt - ledMargin - 1, deg2, deg1); } } else { if (x->f_direction == 0) jgraphics_arc(g, 0, 0, x->f_rayonInt + ledMargin, 0, HOA_2PI); else jgraphics_arc(g, 0, 0, x->f_rayonExt - ledMargin, 0, HOA_2PI); } jgraphics_stroke(g); } jgraphics_rotate(g, degToRad(-rotateAngle)); } jbox_end_layer((t_object*)x, view, hoa_sym_leds_layer); } jbox_paint_layer((t_object *)x, view, hoa_sym_leds_layer, 0., 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.); }
void draw_skeleton(t_meter *x, t_object *view, t_rect *rect) { t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_skeleton_layer, rect->width, rect->height); if (g) { double deg1, deg2, rotateAngle, ledContainerSize, ledStroke, ledMargin, ledOffset, channelWidth; t_jmatrix transform; deg1 = HOA_PI2; ledContainerSize = x->f_rayonExt - x->f_rayonInt - (1*4); ledOffset = ledContainerSize / (x->f_numleds+1); ledStroke = ledOffset * 0.75; ledMargin = ledOffset * 0.5; t_jrgba black = rgba_addContrast(x->f_color_mbg, -0.12); // Background : jgraphics_rectangle(g, 0., 0., rect->width, rect->height); jgraphics_set_source_jrgba(g, &x->f_color_bg); jgraphics_fill_preserve(g); // Border : jgraphics_set_source_jrgba(g, &black); jgraphics_set_line_width(g, 1); jgraphics_stroke(g); // Meter Background : jgraphics_set_source_jrgba(g, &x->f_color_mbg); jgraphics_set_line_width(g, (x->f_rayonExt - x->f_rayonInt) - 0.5); jgraphics_arc(g, x->f_center, x->f_center, x->f_rayonExt*0.5+(x->f_rayonInt*0.5), 0., HOA_2PI); jgraphics_stroke(g); jgraphics_arc_negative(g, x->f_center, x->f_center, x->f_rayonExt*0.5+(x->f_rayonInt*0.5), HOA_PI, -HOA_2PI); // due to a stroke bug ! jgraphics_stroke(g); // skelton circles : if (x->f_drawmborder == 1 || x->f_drawmborder == 3) { jgraphics_set_source_jrgba(g, &black); jgraphics_set_line_width(g, 1); jgraphics_arc(g, x->f_center, x->f_center, x->f_rayonExt, 0., HOA_2PI); jgraphics_stroke(g); jgraphics_arc(g, x->f_center, x->f_center, x->f_rayonInt, 0., HOA_2PI); jgraphics_stroke(g); } if (x->f_drawledsbg) { 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(ulong i = 0; i < x->f_meter->getNumberOfPlanewaves(); i++) { channelWidth = radToDeg(x->f_meter->getPlanewaveWidth(i)); deg2 = degToRad(90. + channelWidth); 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)); // leds Background : jgraphics_set_line_width(g, ledStroke); jgraphics_set_line_cap(g, JGRAPHICS_LINE_CAP_BUTT); jgraphics_set_source_jrgba(g, &x->f_color_ledbg); for(ulong j=0; j < x->f_numleds; j++ ) { if (x->f_meter->getNumberOfPlanewaves() > 1) { if ( x->f_meter->getNumberOfPlanewaves() < 24 && (channelWidth > 14.5)) { double tmpdeg1 = 0, tmpdeg2 = 0, tmprad = 0; if (x->f_direction == 0) // inside { tmpdeg1 = deg1 + (0.008 * (j+4) * x->f_metersize); tmpdeg2 = deg2 - (0.008 * (j+4) * x->f_metersize); tmprad = x->f_rayonExt - (j*ledOffset) - ledMargin - 2; } else // outside { tmpdeg1 = deg1 + (0.008 * (x->f_numleds+3-(j)) * x->f_metersize); tmpdeg2 = deg2 - (0.008 * (x->f_numleds+3-(j)) * x->f_metersize); tmprad = x->f_rayonInt + (j*ledOffset) + ledMargin + 2; } if (tmpdeg1 < tmpdeg2) jgraphics_arc(g, 0, 0, tmprad, tmpdeg1, tmpdeg2); else jgraphics_arc(g, 0, 0, tmprad, tmpdeg2, tmpdeg1); } else { if (x->f_direction == 0) jgraphics_arc_negative(g, 0, 0, x->f_rayonExt-(j*ledOffset) - ledMargin - 2, deg2, deg1); else jgraphics_arc_negative(g, 0, 0, x->f_rayonInt+(j*ledOffset) + ledMargin + 2, deg2, deg1); } } else // mono { if (x->f_direction == 0) jgraphics_arc(g, 0, 0, x->f_rayonExt - (j*ledOffset) - ledMargin - 2, 0, HOA_2PI); else jgraphics_arc(g, 0, 0, x->f_rayonInt + (j*ledOffset) + ledMargin + 2, 0, HOA_2PI); } jgraphics_stroke(g); } jgraphics_rotate(g, degToRad(-rotateAngle)); } } jbox_end_layer((t_object*)x, view, hoa_sym_skeleton_layer); } jbox_paint_layer((t_object *)x, view, hoa_sym_skeleton_layer, 0., 0.); }