void structPitchEditor :: v_draw () { Pitch pitch = (Pitch) our data; long it, it1, it2; double dyUnv, dyIntens; Graphics_setWindow (our d_graphics, 0, 1, 0, 1); Graphics_setColour (our d_graphics, Graphics_WHITE); Graphics_fillRectangle (our d_graphics, 0, 1, 0, 1); Graphics_setColour (our d_graphics, Graphics_BLACK); Graphics_rectangle (our d_graphics, 0, 1, 0, 1); dyUnv = Graphics_dyMMtoWC (our d_graphics, HEIGHT_UNV); dyIntens = Graphics_dyMMtoWC (our d_graphics, HEIGHT_INTENS); Sampled_getWindowSamples (pitch, our d_startWindow, our d_endWindow, & it1, & it2); /* * Show pitch. */ { long df = pitch -> ceiling > 10000 ? 2000 : pitch -> ceiling > 5000 ? 1000 : pitch -> ceiling > 2000 ? 500 : pitch -> ceiling > 800 ? 200 : pitch -> ceiling > 400 ? 100 : 50; double radius; Graphics_Viewport previous; previous = Graphics_insetViewport (our d_graphics, 0, 1, dyUnv, 1 - dyIntens); Graphics_setWindow (our d_graphics, our d_startWindow, our d_endWindow, 0, pitch -> ceiling); radius = Graphics_dxMMtoWC (our d_graphics, RADIUS); /* Horizontal hair at current pitch. */ if (our d_startSelection == our d_endSelection && our d_startSelection >= our d_startWindow && our d_startSelection <= our d_endWindow) { double f = Pitch_getValueAtTime (pitch, our d_startSelection, kPitch_unit_HERTZ, Pitch_LINEAR); if (NUMdefined (f)) { Graphics_setColour (our d_graphics, Graphics_RED); Graphics_line (our d_graphics, our d_startWindow - radius, f, our d_endWindow, f); Graphics_setTextAlignment (our d_graphics, Graphics_RIGHT, Graphics_HALF); Graphics_text1 (our d_graphics, our d_startWindow - radius, f, Melder_fixed (f, 2)); } } /* Horizontal scaling lines. */ Graphics_setColour (our d_graphics, Graphics_BLUE); Graphics_setLineType (our d_graphics, Graphics_DOTTED); Graphics_setTextAlignment (our d_graphics, Graphics_LEFT, Graphics_HALF); for (long f = df; f <= pitch -> ceiling; f += df) { Graphics_line (our d_graphics, our d_startWindow, f, our d_endWindow, f); Graphics_text2 (our d_graphics, our d_endWindow + radius/2, f, Melder_integer (f), L" Hz"); } Graphics_setLineType (our d_graphics, Graphics_DRAWN); /* Show candidates. */ for (it = it1; it <= it2; it ++) { Pitch_Frame frame = & pitch -> frame [it]; double t = Sampled_indexToX (pitch, it); double f = frame -> candidate [1]. frequency; if (f > 0.0 && f < pitch -> ceiling) { Graphics_setColour (our d_graphics, Graphics_MAGENTA); Graphics_fillCircle_mm (our d_graphics, t, f, RADIUS * 2); } Graphics_setColour (our d_graphics, Graphics_BLACK); Graphics_setTextAlignment (our d_graphics, Graphics_CENTRE, Graphics_HALF); for (int icand = 1; icand <= frame -> nCandidates; icand ++) { int strength = (int) floor (10 * frame -> candidate [icand]. strength + 0.5); f = frame -> candidate [icand]. frequency; if (strength > 9) strength = 9; if (f > 0 && f <= pitch -> ceiling) Graphics_text1 (our d_graphics, t, f, Melder_integer (strength)); } } Graphics_resetViewport (our d_graphics, previous); } /* * Show intensity. */ { Graphics_Viewport previous = Graphics_insetViewport (our d_graphics, 0, 1, 1 - dyIntens, 1); Graphics_setWindow (our d_graphics, our d_startWindow, our d_endWindow, 0, 1); Graphics_setColour (our d_graphics, Graphics_BLACK); Graphics_setTextAlignment (our d_graphics, Graphics_RIGHT, Graphics_HALF); Graphics_text (our d_graphics, our d_startWindow, 0.5, L"intens"); Graphics_setTextAlignment (our d_graphics, Graphics_LEFT, Graphics_HALF); Graphics_text (our d_graphics, our d_endWindow, 0.5, L"intens"); Graphics_setTextAlignment (our d_graphics, Graphics_CENTRE, Graphics_HALF); for (it = it1; it <= it2; it ++) { Pitch_Frame frame = & pitch -> frame [it]; double t = Sampled_indexToX (pitch, it); int strength = (int) floor (10 * frame -> intensity + 0.5); // map 0.0-1.0 to 0-9 if (strength > 9) strength = 9; Graphics_text1 (our d_graphics, t, 0.5, Melder_integer (strength)); } Graphics_resetViewport (our d_graphics, previous); } if (it1 > 1) it1 -= 1; if (it2 < pitch -> nx) it2 += 1; /* * Show voicelessness. */ { Graphics_Viewport previous = Graphics_insetViewport (our d_graphics, 0, 1, 0, dyUnv); Graphics_setColour (our d_graphics, Graphics_BLUE); Graphics_line (our d_graphics, our d_startWindow, 1, our d_endWindow, 1); Graphics_setTextAlignment (our d_graphics, Graphics_RIGHT, Graphics_HALF); Graphics_text (our d_graphics, our d_startWindow, 0.5, L"Unv"); Graphics_setTextAlignment (our d_graphics, Graphics_LEFT, Graphics_HALF); Graphics_text (our d_graphics, our d_endWindow, 0.5, L"Unv"); for (it = it1; it <= it2; it ++) { Pitch_Frame frame = & pitch -> frame [it]; double t = Sampled_indexToX (pitch, it), tleft = t - 0.5 * pitch -> dx, tright = t + 0.5 * pitch -> dx; double f = frame -> candidate [1]. frequency; if ((f > 0.0 && f < pitch -> ceiling) || tright <= our d_startWindow || tleft >= our d_endWindow) continue; if (tleft < our d_startWindow) tleft = our d_startWindow; if (tright > our d_endWindow) tright = our d_endWindow; Graphics_fillRectangle (our d_graphics, tleft, tright, 0, 1); } Graphics_setColour (our d_graphics, Graphics_BLACK); Graphics_resetViewport (our d_graphics, previous); } }
void structFormantGridEditor :: v_draw () { FormantGrid grid = (FormantGrid) data; Ordered tiers = editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier selectedTier = (RealTier) tiers -> item [selectedFormant]; double ymin = editingBandwidths ? bandwidthFloor : formantFloor; double ymax = editingBandwidths ? bandwidthCeiling : formantCeiling; Graphics_setColour (graphics, Graphics_WHITE); Graphics_setWindow (graphics, 0, 1, 0, 1); Graphics_fillRectangle (graphics, 0, 1, 0, 1); Graphics_setWindow (graphics, startWindow, endWindow, ymin, ymax); Graphics_setColour (graphics, Graphics_RED); Graphics_line (graphics, startWindow, ycursor, endWindow, ycursor); Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF); Graphics_text1 (graphics, startWindow, ycursor, Melder_float (Melder_half (ycursor))); Graphics_setColour (graphics, Graphics_BLUE); Graphics_setTextAlignment (graphics, Graphics_LEFT, Graphics_TOP); Graphics_text2 (graphics, endWindow, ymax, Melder_float (Melder_half (ymax)), L" Hz"); Graphics_setTextAlignment (graphics, Graphics_LEFT, Graphics_HALF); Graphics_text2 (graphics, endWindow, ymin, Melder_float (Melder_half (ymin)), L" Hz"); Graphics_setLineWidth (graphics, 1); Graphics_setColour (graphics, Graphics_GREY); for (long iformant = 1; iformant <= grid -> formants -> size; iformant ++) if (iformant != selectedFormant) { RealTier tier = (RealTier) tiers -> item [iformant]; long imin = AnyTier_timeToHighIndex (tier, startWindow); long imax = AnyTier_timeToLowIndex (tier, endWindow); long n = tier -> points -> size; if (n == 0) { } else if (imax < imin) { double yleft = RealTier_getValueAtTime (tier, startWindow); double yright = RealTier_getValueAtTime (tier, endWindow); Graphics_line (graphics, startWindow, yleft, endWindow, yright); } else for (long i = imin; i <= imax; i ++) { RealPoint point = (RealPoint) tier -> points -> item [i]; double t = point -> number, y = point -> value; Graphics_fillCircle_mm (graphics, t, y, 2); if (i == 1) Graphics_line (graphics, startWindow, y, t, y); else if (i == imin) Graphics_line (graphics, t, y, startWindow, RealTier_getValueAtTime (tier, startWindow)); if (i == n) Graphics_line (graphics, t, y, endWindow, y); else if (i == imax) Graphics_line (graphics, t, y, endWindow, RealTier_getValueAtTime (tier, endWindow)); else { RealPoint pointRight = (RealPoint) tier -> points -> item [i + 1]; Graphics_line (graphics, t, y, pointRight -> number, pointRight -> value); } } } Graphics_setColour (graphics, Graphics_BLUE); long ifirstSelected = AnyTier_timeToHighIndex (selectedTier, startSelection); long ilastSelected = AnyTier_timeToLowIndex (selectedTier, endSelection); long n = selectedTier -> points -> size; long imin = AnyTier_timeToHighIndex (selectedTier, startWindow); long imax = AnyTier_timeToLowIndex (selectedTier, endWindow); Graphics_setLineWidth (graphics, 2); if (n == 0) { Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF); Graphics_text (graphics, 0.5 * (startWindow + endWindow), 0.5 * (ymin + ymax), L"(no points in selected formant tier)"); } else if (imax < imin) { double yleft = RealTier_getValueAtTime (selectedTier, startWindow); double yright = RealTier_getValueAtTime (selectedTier, endWindow); Graphics_line (graphics, startWindow, yleft, endWindow, yright); } else for (long i = imin; i <= imax; i ++) { RealPoint point = (RealPoint) selectedTier -> points -> item [i]; double t = point -> number, y = point -> value; if (i >= ifirstSelected && i <= ilastSelected) Graphics_setColour (graphics, Graphics_RED); Graphics_fillCircle_mm (graphics, t, y, 3); Graphics_setColour (graphics, Graphics_BLUE); if (i == 1) Graphics_line (graphics, startWindow, y, t, y); else if (i == imin) Graphics_line (graphics, t, y, startWindow, RealTier_getValueAtTime (selectedTier, startWindow)); if (i == n) Graphics_line (graphics, t, y, endWindow, y); else if (i == imax) Graphics_line (graphics, t, y, endWindow, RealTier_getValueAtTime (selectedTier, endWindow)); else { RealPoint pointRight = (RealPoint) selectedTier -> points -> item [i + 1]; Graphics_line (graphics, t, y, pointRight -> number, pointRight -> value); } } Graphics_setLineWidth (graphics, 1); Graphics_setColour (graphics, Graphics_BLACK); }
void structERP :: f_drawScalp (Graphics graphics, double tmin, double tmax, double vmin, double vmax, bool garnish) { Graphics_setInner (graphics); Graphics_setWindow (graphics, -1.0, 1.0, -1.0, 1.0); //Graphics_setGrey (graphics, 1.0); //Graphics_fillRectangle (graphics, -1.1, 1.1, -1.01, 1.19); //Graphics_setColour (graphics, Graphics_BLACK); long numberOfDrawableChannels = this -> ny >= 64 && Melder_wcsequ (this -> d_channelNames [64], L"O2") ? 64 : this -> ny >= 32 && Melder_wcsequ (this -> d_channelNames [32], L"Cz") ? 32 : 0; BiosemiLocationData *biosemiLocationData = numberOfDrawableChannels == 64 ? biosemiCapCoordinates64 : numberOfDrawableChannels == 32 ? biosemiCapCoordinates32 : 0; for (long ichan = 1; ichan <= numberOfDrawableChannels; ichan ++) { double inclination = (double) biosemiLocationData [ichan]. inclination; double azimuth = (double) biosemiLocationData [ichan]. azimuth; bool rightHemisphere = inclination >= 0.0; double r = fabs (inclination / 115.0); double theta = rightHemisphere ? azimuth * (NUMpi / 180.0) : (azimuth + 180.0) * (NUMpi / 180.0); biosemiLocationData [ichan]. topX = r * cos (theta); biosemiLocationData [ichan]. topY = r * sin (theta); } long n = 201; double d = 2.0 / (n - 1); autoNUMvector <double> mean (1, numberOfDrawableChannels); for (long ichan = 1; ichan <= numberOfDrawableChannels; ichan ++) { mean [ichan] = tmin == tmax ? Sampled_getValueAtX (this, tmin, ichan, 0, true) : Vector_getMean (this, tmin, tmax, ichan); } autoNUMmatrix <double> image (1, n, 1, n); for (long irow = 1; irow <= n; irow ++) { double y = -1.0 + (irow - 1) * d; for (long icol = 1; icol <= n; icol ++) { double x = -1.0 + (icol - 1) * d; if (x * x + y * y <= 1.0) { double value = NUMundefined, sum = 0.0, weight = 0.0; for (long ichan = 1; ichan <= numberOfDrawableChannels; ichan ++) { double dx = x - biosemiLocationData [ichan]. topX; double dy = y - biosemiLocationData [ichan]. topY; double distance = sqrt (dx * dx + dy * dy); if (distance < 1e-12) { value = mean [ichan]; break; } distance = distance * distance * distance * distance * distance * distance; sum += mean [ichan] / distance; weight += 1.0 / distance; } if (value == NUMundefined) value = ( sum == 0.0 ? 0.0 : sum / weight ); image [irow] [icol] = value; } } } for (long irow = 1; irow <= n; irow ++) { double y = -1.0 + (irow - 1) * d; for (long icol = 1; icol <= n; icol ++) { double x = -1.0 + (icol - 1) * d; if (x * x + y * y > 1.0) { image [irow] [icol] = vmin; } } } Graphics_image (graphics, image.peek(), 1, n, -1.0-0.5/n, 1.0+0.5/n, 1, n, -1.0-0.5/n, 1.0+0.5/n, vmin, vmax); Graphics_setLineWidth (graphics, 2.0); /* * Nose. */ Graphics_setGrey (graphics, 0.5); {// scope double x [3] = { -0.08, 0.0, 0.08 }, y [3] = { 0.99, 1.18, 0.99 }; Graphics_fillArea (graphics, 3, x, y); } Graphics_setColour (graphics, Graphics_BLACK); Graphics_line (graphics, -0.08, 0.99, 0.0, 1.18); Graphics_line (graphics, 0.08, 0.99, 0.0, 1.18); /* * Ears. */ Graphics_setGrey (graphics, 0.5); Graphics_fillRectangle (graphics, -1.09, -1.00, -0.08, 0.08); Graphics_fillRectangle (graphics, 1.09, 1.00, -0.08, 0.08); Graphics_setColour (graphics, Graphics_BLACK); Graphics_line (graphics, -0.99, 0.08, -1.09, 0.08); Graphics_line (graphics, -1.09, 0.08, -1.09, -0.08); Graphics_line (graphics, -1.09, -0.08, -0.99, -0.08); Graphics_line (graphics, 0.99, 0.08, 1.09, 0.08); Graphics_line (graphics, 1.09, 0.08, 1.09, -0.08); Graphics_line (graphics, 1.09, -0.08, 0.99, -0.08); /* * Scalp. */ Graphics_ellipse (graphics, -1.0, 1.0, -1.0, 1.0); Graphics_setLineWidth (graphics, 1.0); Graphics_unsetInner (graphics); if (garnish) { autoNUMmatrix <double> legend (1, n, 1, 2); for (long irow = 1; irow <= n; irow ++) { for (long icol = 1; icol <= 2; icol ++) { legend [irow] [icol] = (irow - 1) / (n - 1.0); } } Graphics_image (graphics, legend.peek(), 1, 2, 0.78, 0.98, 1, n, -0.8, +0.8, 0.0, 1.0); Graphics_rectangle (graphics, 0.78, 0.98, -0.8, +0.8); Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_TOP); Graphics_text2 (graphics, 1.0, -0.8, Melder_double (vmin * 1e6), L" \\muV"); Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_BOTTOM); Graphics_text2 (graphics, 1.0, +0.8, Melder_double (vmax * 1e6), L" \\muV"); } }