void TextGrid_Pitch_draw (TextGrid grid, Pitch pitch, Graphics g, long tierNumber, double tmin, double tmax, double fmin, double fmax, double fontSize, int useTextStyles, int horizontalAlignment, int garnish, int speckle, int unit) { try { TextGrid_checkSpecifiedTierNumberWithinRange (grid, tierNumber); double oldFontSize = Graphics_inqFontSize (g); Pitch_draw (pitch, g, tmin, tmax, fmin, fmax, garnish, speckle, unit); if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; autoPitchTier pitchTier = Pitch_to_PitchTier (pitch); if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } Graphics_setTextAlignment (g, horizontalAlignment, Graphics_BOTTOM); Graphics_setInner (g); Graphics_setFontSize (g, fontSize); Graphics_setPercentSignIsItalic (g, useTextStyles); Graphics_setNumberSignIsBold (g, useTextStyles); Graphics_setCircumflexIsSuperscript (g, useTextStyles); Graphics_setUnderscoreIsSubscript (g, useTextStyles); Function anyTier = (Function) grid -> tiers -> item [tierNumber]; if (anyTier -> classInfo == classIntervalTier) { IntervalTier tier = (IntervalTier) anyTier; for (long i = 1; i <= tier -> intervals -> size; i ++) { TextInterval interval = (TextInterval) tier -> intervals -> item [i]; double tleft = interval -> xmin, tright = interval -> xmax, tmid, f0; if (! interval -> text || ! interval -> text [0]) continue; if (tleft < pitch -> xmin) tleft = pitch -> xmin; if (tright > pitch -> xmax) tright = pitch -> xmax; tmid = (tleft + tright) / 2; if (tmid < tmin || tmid > tmax) continue; f0 = Function_convertStandardToSpecialUnit (pitch, RealTier_getValueAtTime (pitchTier.peek(), tmid), Pitch_LEVEL_FREQUENCY, unit); if (f0 < fmin || f0 > fmax) continue; Graphics_text (g, horizontalAlignment == Graphics_LEFT ? tleft : horizontalAlignment == Graphics_RIGHT ? tright : tmid, f0, interval -> text); } } else { TextTier tier = (TextTier) anyTier; for (long i = 1; i <= tier -> points -> size; i ++) { TextPoint point = (TextPoint) tier -> points -> item [i]; double t = point -> number, f0; if (! point -> mark || ! point -> mark [0]) continue; if (t < tmin || t > tmax) continue; f0 = Function_convertStandardToSpecialUnit (pitch, RealTier_getValueAtTime (pitchTier.peek(), t), Pitch_LEVEL_FREQUENCY, unit); if (f0 < fmin || f0 > fmax) continue; Graphics_text (g, t, f0, point -> mark); } } Graphics_setPercentSignIsItalic (g, TRUE); Graphics_setNumberSignIsBold (g, TRUE); Graphics_setCircumflexIsSuperscript (g, TRUE); Graphics_setUnderscoreIsSubscript (g, TRUE); Graphics_setFontSize (g, oldFontSize); Graphics_unsetInner (g); } catch (MelderError) { Melder_throw (grid, " & ", pitch, ": not drawn."); } }
void Pitch_draw (Pitch me, Graphics g, double tmin, double tmax, double fmin, double fmax, bool garnish, bool speckle, int unit) { Graphics_setInner (g); Pitch_drawInside (me, g, tmin, tmax, fmin, fmax, speckle, unit); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_textLeft (g, true, Melder_cat (U"Pitch (", Function_getUnitText (me, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), U")")); if (Function_isUnitLogarithmic (me, Pitch_LEVEL_FREQUENCY, unit)) { Graphics_marksLeftLogarithmic (g, 6, true, true, false); } else { Graphics_marksLeft (g, 2, true, true, false); } } }
void TextGrid_Pitch_drawSeparately (TextGrid grid, Pitch pitch, Graphics g, double tmin, double tmax, double fmin, double fmax, int showBoundaries, int useTextStyles, int garnish, int speckle, int unit) { int ntier = grid -> tiers -> size; if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } if (unit == kPitch_unit_HERTZ_LOGARITHMIC) Pitch_draw (pitch, g, tmin, tmax, pow (10, fmin - 0.25 * (fmax - fmin) * ntier), pow (10, fmax), FALSE, speckle, unit); else Pitch_draw (pitch, g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax, FALSE, speckle, unit); TextGrid_Sound_draw (grid, NULL, g, tmin, tmax, showBoundaries, useTextStyles, FALSE); /* * Restore window for the sake of margin drawing. */ Graphics_setWindow (g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) fmin = pow (10, fmin), fmax = pow (10, fmax); if (garnish) { Graphics_drawInnerBox (g); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) { Graphics_markLeftLogarithmic (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeftLogarithmic (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_logarithmic (g, fmin, fmax, FALSE); } else if (unit == kPitch_unit_SEMITONES_100) { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_semitones (g, fmin, fmax, FALSE); } else { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks (g, fmin, fmax, FALSE); } static MelderString buffer = { 0 }; MelderString_empty (& buffer); MelderString_append (& buffer, L"Pitch (", Function_getUnitText (pitch, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), L")"); Graphics_textLeft (g, true, buffer.string); Graphics_textBottom (g, true, L"Time (s)"); Graphics_marksBottom (g, 2, true, true, true); } }
void Pitch_draw (Pitch me, Graphics g, double tmin, double tmax, double fmin, double fmax, int garnish, int speckle, int unit) { Graphics_setInner (g); Pitch_drawInside (me, g, tmin, tmax, fmin, fmax, speckle, unit); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, TRUE, L"Time (s)"); Graphics_marksBottom (g, 2, TRUE, TRUE, FALSE); static MelderString buffer = { 0 }; MelderString_empty (& buffer); MelderString_append (& buffer, L"Pitch (", Function_getUnitText (me, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), L")"); Graphics_textLeft (g, TRUE, buffer.string); if (Function_isUnitLogarithmic (me, Pitch_LEVEL_FREQUENCY, unit)) { Graphics_marksLeftLogarithmic (g, 6, TRUE, TRUE, FALSE); } else { Graphics_marksLeft (g, 2, TRUE, TRUE, FALSE); } } }
void TextGrid_Pitch_drawSeparately (TextGrid grid, Pitch pitch, Graphics g, double tmin, double tmax, double fmin, double fmax, bool showBoundaries, bool useTextStyles, bool garnish, bool speckle, int unit) { int ntier = grid -> tiers->size; if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } if (unit == kPitch_unit_HERTZ_LOGARITHMIC) Pitch_draw (pitch, g, tmin, tmax, pow (10.0, fmin - 0.25 * (fmax - fmin) * ntier), pow (10.0, fmax), false, speckle, unit); else Pitch_draw (pitch, g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax, false, speckle, unit); TextGrid_Sound_draw (grid, nullptr, g, tmin, tmax, showBoundaries, useTextStyles, false); /* * Restore window for the sake of margin drawing. */ Graphics_setWindow (g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) fmin = pow (10, fmin), fmax = pow (10.0, fmax); if (garnish) { Graphics_drawInnerBox (g); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) { Graphics_markLeftLogarithmic (g, fmin, true, true, false, nullptr); Graphics_markLeftLogarithmic (g, fmax, true, true, false, nullptr); autoMarks_logarithmic (g, fmin, fmax, false); } else if (unit == kPitch_unit_SEMITONES_100) { Graphics_markLeft (g, fmin, true, true, false, nullptr); Graphics_markLeft (g, fmax, true, true, false, nullptr); autoMarks_semitones (g, fmin, fmax, false); } else { Graphics_markLeft (g, fmin, true, true, false, nullptr); Graphics_markLeft (g, fmax, true, true, false, nullptr); autoMarks (g, fmin, fmax, false); } Graphics_textLeft (g, true, Melder_cat (U"Pitch (", Function_getUnitText (pitch, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), U")")); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); } }
static void Sampled_speckleInside (Sampled me, Graphics g, double xmin, double xmax, double ymin, double ymax, double speckle_mm, long ilevel, int unit) { Function_unidirectionalAutowindow (me, & xmin, & xmax); long ixmin, ixmax; Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax); if (Function_isUnitLogarithmic (me, ilevel, unit)) { ymin = Function_convertStandardToSpecialUnit (me, ymin, ilevel, unit); ymax = Function_convertStandardToSpecialUnit (me, ymax, ilevel, unit); } if (ymax <= ymin) return; Graphics_setWindow (g, xmin, xmax, ymin, ymax); for (long ix = ixmin; ix <= ixmax; ix ++) { double value = Sampled_getValueAtSample (me, ix, ilevel, unit); if (NUMdefined (value)) { double x = Sampled_indexToX (me, ix); if (value >= ymin && value <= ymax) { Graphics_fillCircle_mm (g, x, value, speckle_mm); } } } }
void Sampled_drawInside (Sampled me, Graphics g, double xmin, double xmax, double ymin, double ymax, double speckle_mm, long ilevel, int unit) { try { if (speckle_mm != 0.0) { Sampled_speckleInside (me, g, xmin, xmax, ymin, ymax, speckle_mm, ilevel, unit); return; } Function_unidirectionalAutowindow (me, & xmin, & xmax); long ixmin, ixmax, startOfDefinedStretch = -1; Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax); if (Function_isUnitLogarithmic (me, ilevel, unit)) { ymin = Function_convertStandardToSpecialUnit (me, ymin, ilevel, unit); ymax = Function_convertStandardToSpecialUnit (me, ymax, ilevel, unit); } if (ymax <= ymin) return; Graphics_setWindow (g, xmin, xmax, ymin, ymax); autoNUMvector <double> xarray (ixmin - 1, ixmax + 1); autoNUMvector <double> yarray (ixmin - 1, ixmax + 1); double previousValue = Sampled_getValueAtSample (me, ixmin - 1, ilevel, unit); if (NUMdefined (previousValue)) { startOfDefinedStretch = ixmin - 1; xarray [ixmin - 1] = Sampled_indexToX (me, ixmin - 1); yarray [ixmin - 1] = previousValue; } for (long ix = ixmin; ix <= ixmax; ix ++) { double x = Sampled_indexToX (me, ix), value = Sampled_getValueAtSample (me, ix, ilevel, unit); if (NUMdefined (value)) { if (NUMdefined (previousValue)) { xarray [ix] = x; yarray [ix] = value; } else { startOfDefinedStretch = ix - 1; xarray [ix - 1] = x - 0.5 * my dx; yarray [ix - 1] = value; xarray [ix] = x; yarray [ix] = value; } } else if (NUMdefined (previousValue)) { Melder_assert (startOfDefinedStretch >= ixmin - 1); if (ix > ixmin) { xarray [ix] = x - 0.5 * my dx; yarray [ix] = previousValue; if (xarray [startOfDefinedStretch] < xmin) { double phase = (xmin - xarray [startOfDefinedStretch]) / my dx; xarray [startOfDefinedStretch] = xmin; yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch]; } Graphics_polyline (g, ix + 1 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]); } startOfDefinedStretch = -1; } previousValue = value; } if (startOfDefinedStretch > -1) { double x = Sampled_indexToX (me, ixmax + 1), value = Sampled_getValueAtSample (me, ixmax + 1, ilevel, unit); Melder_assert (NUMdefined (previousValue)); if (NUMdefined (value)) { xarray [ixmax + 1] = x; yarray [ixmax + 1] = value; } else { xarray [ixmax + 1] = x - 0.5 * my dx; yarray [ixmax + 1] = previousValue; } if (xarray [startOfDefinedStretch] < xmin) { double phase = (xmin - xarray [startOfDefinedStretch]) / my dx; xarray [startOfDefinedStretch] = xmin; yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch]; } if (xarray [ixmax + 1] > xmax) { double phase = (xarray [ixmax + 1] - xmax) / my dx; xarray [ixmax + 1] = xmax; yarray [ixmax + 1] = phase * yarray [ixmax] + (1.0 - phase) * yarray [ixmax + 1]; } Graphics_polyline (g, ixmax + 2 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]); } } catch (MelderError) { Melder_clearError (); } }