Beispiel #1
0
static void drawWhileDragging (FormantGridEditor me, double xWC, double yWC, long first, long last, double dt, double dy) {
	FormantGrid grid = (FormantGrid) my data;
	Ordered tiers = my editingBandwidths ? grid -> bandwidths : grid -> formants;
	RealTier tier = (RealTier) tiers -> item [my selectedFormant];
	double ymin = my editingBandwidths ? my p_bandwidthFloor   : my p_formantFloor;
	double ymax = my editingBandwidths ? my p_bandwidthCeiling : my p_formantCeiling;
	(void) xWC;
	(void) yWC;

	/*
	 * Draw all selected points as magenta empty circles, if inside the window.
	 */
	for (long i = first; i <= last; i ++) {
		RealPoint point = (RealPoint) tier -> points -> item [i];
		double t = point -> number + dt, y = point -> value + dy;
		if (t >= my d_startWindow && t <= my d_endWindow)
			Graphics_circle_mm (my d_graphics, t, y, 3);
	}

	if (last == first) {
		/*
		 * Draw a crosshair with time and y.
		 */
		RealPoint point = (RealPoint) tier -> points -> item [first];
		double t = point -> number + dt, y = point -> value + dy;
		Graphics_line (my d_graphics, t, ymin, t, ymax - Graphics_dyMMtoWC (my d_graphics, 4.0));
		Graphics_setTextAlignment (my d_graphics, kGraphics_horizontalAlignment_CENTRE, Graphics_TOP);
		Graphics_text (my d_graphics, t, ymax, Melder_fixed (t, 6));
		Graphics_line (my d_graphics, my d_startWindow, y, my d_endWindow, y);
		Graphics_setTextAlignment (my d_graphics, Graphics_LEFT, Graphics_BOTTOM);
		Graphics_text (my d_graphics, my d_startWindow, y, Melder_fixed (y, 6));
	}
}
Beispiel #2
0
void Transition_drawAsNumbers (I, Graphics g, int iformat, int precision) {
	iam (Transition);
	double maxTextWidth = 0, maxTextHeight = 0;
	Graphics_setInner (g);
	Graphics_setWindow (g, 0.5, my numberOfStates + 0.5, 0, 1);
	double leftMargin = Graphics_dxMMtoWC (g, 1);
	double lineSpacing = Graphics_dyMMtoWC (g, 1.5 * Graphics_inqFontSize (g) * 25.4 / 72);
	Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_BOTTOM);
	for (long col = 1; col <= my numberOfStates; col ++) {
		if (my stateLabels && my stateLabels [col] && my stateLabels [col] [0]) {
			Graphics_text (g, col, 1, my stateLabels [col]);
			if (! maxTextHeight) maxTextHeight = lineSpacing;
		}
	}
	for (long row = 1; row <= my numberOfStates; row ++) {
		double y = 1 - lineSpacing * (row - 1 + 0.7);
		Graphics_setTextAlignment (g, Graphics_RIGHT, Graphics_HALF);
		if (my stateLabels && my stateLabels [row]) {
			double textWidth = Graphics_textWidth (g, my stateLabels [row]);
			if (textWidth > maxTextWidth) maxTextWidth = textWidth;
			Graphics_text (g, 0.5 - leftMargin, y, my stateLabels [row]);
		}
		Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF);
		for (long col = 1; col <= my numberOfStates; col ++) {
			wchar text [40];
			print4 (text, my data [row] [col], iformat, 0, precision);
			Graphics_text (g, col, y, text);
		}
	}
	if (maxTextWidth)
		Graphics_line (g, 0.5 - maxTextWidth - leftMargin, 1, my numberOfStates + 0.5, 1);
	if (maxTextHeight)
		Graphics_line (g, 0.5, 1 + maxTextHeight, 0.5, 1 - lineSpacing * (my numberOfStates + 0.2));
	Graphics_unsetInner (g);
}
Beispiel #3
0
int structPitchEditor :: v_click (double xWC, double yWC, bool dummy) {
    Pitch pitch = (Pitch) our data;
    double dyUnv = Graphics_dyMMtoWC (d_graphics, HEIGHT_UNV);
    double dyIntens = Graphics_dyMMtoWC (d_graphics, HEIGHT_INTENS);
    double frequency = (yWC - dyUnv) / (1 - dyIntens - dyUnv) * pitch -> ceiling, tmid;
    double minimumDf = 1e30;
    int cand, bestCandidate = -1;

    long ibestFrame;
    Pitch_Frame bestFrame;
    ibestFrame = Sampled_xToNearestIndex (pitch, xWC);
    if (ibestFrame < 1) ibestFrame = 1;
    if (ibestFrame > pitch -> nx) ibestFrame = pitch -> nx;
    bestFrame = & pitch -> frame [ibestFrame];

    tmid = Sampled_indexToX (pitch, ibestFrame);
    for (cand = 1; cand <= bestFrame -> nCandidates; cand ++) {
        double df = frequency - bestFrame -> candidate [cand]. frequency;
        if (fabs (df) < minimumDf) {
            minimumDf = fabs (df);
            bestCandidate = cand;
        }
    }
    if (bestCandidate != -1) {
        double bestFrequency = bestFrame -> candidate [bestCandidate]. frequency;
        double distanceWC = (frequency - bestFrequency) / pitch -> ceiling * (1 - dyIntens - dyUnv);
        double dx_mm = Graphics_dxWCtoMM (our d_graphics, xWC - tmid), dy_mm = Graphics_dyWCtoMM (our d_graphics, distanceWC);
        if (bestFrequency < pitch -> ceiling &&   // above ceiling: ignore
                ((bestFrequency <= 0.0 && fabs (xWC - tmid) <= 0.5 * pitch -> dx && frequency <= 0.0) ||   // voiceless: click within frame
                 (bestFrequency > 0.0 && dx_mm * dx_mm + dy_mm * dy_mm <= RADIUS * RADIUS)))   // voiced: click within circle
        {
            struct structPitch_Candidate help = bestFrame -> candidate [1];
            Editor_save (this, L"Change path");
            bestFrame -> candidate [1] = bestFrame -> candidate [bestCandidate];
            bestFrame -> candidate [bestCandidate] = help;
            FunctionEditor_redraw (this);
            our broadcastDataChanged ();
            our d_startSelection = our d_endSelection = tmid;   // cursor will snap to candidate
            return 1;
        } else {
            return PitchEditor_Parent :: v_click (xWC, yWC, dummy);   // move cursor or drag selection
        }
    }
    return PitchEditor_Parent :: v_click (xWC, yWC, dummy);   // move cursor or drag selection
}
Beispiel #4
0
static double getLineSpacing (Graphics graphics) {
    return Graphics_dyMMtoWC (graphics, 1.5 * Graphics_inqFontSize (graphics) * 25.4 / 72);
}
Beispiel #5
0
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);
    }
}