コード例 #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 bandwidthFloor : my formantFloor;
	double ymax = my editingBandwidths ? my bandwidthCeiling : my 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 startWindow && t <= my endWindow)
			Graphics_circle_mm (my 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 graphics, t, ymin, t, ymax - Graphics_dyMMtoWC (my graphics, 4.0));
		Graphics_setTextAlignment (my graphics, kGraphics_horizontalAlignment_CENTRE, Graphics_TOP);
		Graphics_text1 (my graphics, t, ymax, Melder_fixed (t, 6));
		Graphics_line (my graphics, my startWindow, y, my endWindow, y);
		Graphics_setTextAlignment (my graphics, Graphics_LEFT, Graphics_BOTTOM);
		Graphics_text1 (my graphics, my startWindow, y, Melder_fixed (y, 6));
	}
}
コード例 #2
0
void HyperPage_initSheetOfPaper (HyperPage me) {
	int reflect = my mirror && (my d_printingPageNumber & 1) == 0;
	wchar_t *leftHeader = reflect ? my outsideHeader : my insideHeader;
	wchar_t *rightHeader = reflect ? my insideHeader : my outsideHeader;
	wchar_t *leftFooter = reflect ? my outsideFooter : my insideFooter;
	wchar_t *rightFooter = reflect ? my insideFooter : my outsideFooter;

	my d_y = PAPER_TOP - TOP_MARGIN;
	my d_x = 0;
	my previousBottomSpacing = 0.0;
	Graphics_setFont (my ps, kGraphics_font_TIMES);
	Graphics_setFontSize (my ps, 12);
	Graphics_setFontStyle (my ps, Graphics_ITALIC);
	if (leftHeader) {
		Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_TOP);
		Graphics_text (my ps, 0.7, PAPER_TOP, leftHeader);
	}
	if (my middleHeader) {
		Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_TOP);
		Graphics_text (my ps, 0.7 + 3, PAPER_TOP, my middleHeader);
	}
	if (rightHeader) {
		Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_TOP);
		Graphics_text (my ps, 0.7 + 6, PAPER_TOP, rightHeader);
	}
	if (leftFooter) {
		Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
		Graphics_text (my ps, 0.7, PAPER_BOTTOM, leftFooter);
	}
	if (my middleFooter) {
		Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_BOTTOM);
		Graphics_text (my ps, 0.7 + 3, PAPER_BOTTOM, my middleFooter);
	}
	if (rightFooter) {
		Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_BOTTOM);
		Graphics_text (my ps, 0.7 + 6, PAPER_BOTTOM, rightFooter);
	}
	Graphics_setFontStyle (my ps, Graphics_NORMAL);
	if (my d_printingPageNumber)
		Graphics_text1 (my ps, 0.7 + ( reflect ? 0 : 6 ), PAPER_BOTTOM, Melder_integer (my d_printingPageNumber));
	Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
}
コード例 #3
0
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);
}
コード例 #4
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);
    }
}
コード例 #5
0
ファイル: SoundEditor.cpp プロジェクト: alekstorm/tala
void SoundEditor::draw () {
	long first, last, selectedSamples;
	Graphics_Viewport viewport;
	int showAnalysis = _spectrogram.show || _pitch.show || _intensity.show || _formant.show;
	Melder_assert (_data != NULL);
	Melder_assert (_sound.data != NULL || _longSound.data != NULL);

	/*
	 * We check beforehand whether the window fits the LongSound buffer.
	 */
	if (_longSound.data && _endWindow - _startWindow > _longSound.data -> bufferLength) {
		Graphics_setColour (_graphics, Graphics_WHITE);
		Graphics_setWindow (_graphics, 0, 1, 0, 1);
		Graphics_fillRectangle (_graphics, 0, 1, 0, 1);
		Graphics_setColour (_graphics, Graphics_BLACK);
		Graphics_setTextAlignment (_graphics, Graphics_CENTRE, Graphics_BOTTOM);
		Graphics_text3 (_graphics, 0.5, 0.5, L"(window longer than ", Melder_float (Melder_single (_longSound.data -> bufferLength)), L" seconds)");
		Graphics_setTextAlignment (_graphics, Graphics_CENTRE, Graphics_TOP);
		Graphics_text1 (_graphics, 0.5, 0.5, L"(zoom in to see the samples)");
		return;
	}

	/* Draw sound. */

	if (showAnalysis)
		viewport = Graphics_insetViewport (_graphics, 0, 1, 0.5, 1);
	Graphics_setColour (_graphics, Graphics_WHITE);
	Graphics_setWindow (_graphics, 0, 1, 0, 1);
	Graphics_fillRectangle (_graphics, 0, 1, 0, 1);
	draw_sound (_sound.minimum, _sound.maximum);
	Graphics_flushWs (_graphics);
	if (showAnalysis)
		Graphics_resetViewport (_graphics, viewport);

	/* Draw analyses. */

	if (showAnalysis) {
		/* Draw spectrogram, pitch, formants. */
		viewport = Graphics_insetViewport (_graphics, 0, 1, 0, 0.5);
		draw_analysis ();
		Graphics_flushWs (_graphics);
		Graphics_resetViewport (_graphics, viewport);
	}

	/* Draw pulses. */

	if (_pulses.show) {
		if (showAnalysis)
			viewport = Graphics_insetViewport (_graphics, 0, 1, 0.5, 1);
		draw_analysis_pulses ();
		draw_sound (_sound.minimum, _sound.maximum);   /* Second time, partially across the pulses. */
		Graphics_flushWs (_graphics);
		if (showAnalysis)
			Graphics_resetViewport (_graphics, viewport);
	}

	/* Update buttons. */

	selectedSamples = Sampled_getWindowSamples (_data, _startSelection, _endSelection, & first, & last);
	updateMenuItems_file ();
	if (_sound.data) {
		GuiObject_setSensitive (_cutButton, selectedSamples != 0 && selectedSamples < _sound.data -> nx);
		GuiObject_setSensitive (_copyButton, selectedSamples != 0);
		GuiObject_setSensitive (_zeroButton, selectedSamples != 0);
		GuiObject_setSensitive (_reverseButton, selectedSamples != 0);
	}
}
コード例 #6
0
ファイル: SoundEditor.cpp プロジェクト: Crisil/praat
void structSoundEditor :: v_draw () {
	Sampled data = (Sampled) this -> data;
	Graphics_Viewport viewport;
	bool showAnalysis = p_spectrogram_show || p_pitch_show || p_intensity_show || p_formant_show;
	Melder_assert (data != NULL);
	Melder_assert (d_sound.data != NULL || d_longSound.data != NULL);

	/*
	 * We check beforehand whether the window fits the LongSound buffer.
	 */
	if (d_longSound.data && d_endWindow - d_startWindow > d_longSound.data -> bufferLength) {
		Graphics_setColour (d_graphics, Graphics_WHITE);
		Graphics_setWindow (d_graphics, 0, 1, 0, 1);
		Graphics_fillRectangle (d_graphics, 0, 1, 0, 1);
		Graphics_setColour (d_graphics, Graphics_BLACK);
		Graphics_setTextAlignment (d_graphics, Graphics_CENTRE, Graphics_BOTTOM);
		Graphics_text3 (d_graphics, 0.5, 0.5, L"(window longer than ", Melder_float (Melder_single (d_longSound.data -> bufferLength)), L" seconds)");
		Graphics_setTextAlignment (d_graphics, Graphics_CENTRE, Graphics_TOP);
		Graphics_text1 (d_graphics, 0.5, 0.5, L"(zoom in to see the samples)");
		return;
	}

	/* Draw sound. */

	if (showAnalysis)
		viewport = Graphics_insetViewport (d_graphics, 0, 1, 0.5, 1);
	Graphics_setColour (d_graphics, Graphics_WHITE);
	Graphics_setWindow (d_graphics, 0, 1, 0, 1);
	Graphics_fillRectangle (d_graphics, 0, 1, 0, 1);
	TimeSoundEditor_drawSound (this, d_sound.minimum, d_sound.maximum);
	Graphics_flushWs (d_graphics);
	if (showAnalysis)
		Graphics_resetViewport (d_graphics, viewport);

	/* Draw analyses. */

	if (showAnalysis) {
		/* Draw spectrogram, pitch, formants. */
		viewport = Graphics_insetViewport (d_graphics, 0, 1, 0, 0.5);
		v_draw_analysis ();
		Graphics_flushWs (d_graphics);
		Graphics_resetViewport (d_graphics, viewport);
	}

	/* Draw pulses. */

	if (p_pulses_show) {
		if (showAnalysis)
			viewport = Graphics_insetViewport (d_graphics, 0, 1, 0.5, 1);
		v_draw_analysis_pulses ();
		TimeSoundEditor_drawSound (this, d_sound.minimum, d_sound.maximum);   // second time, partially across the pulses
		Graphics_flushWs (d_graphics);
		if (showAnalysis)
			Graphics_resetViewport (d_graphics, viewport);
	}

	/* Update buttons. */

	long first, last;
	long selectedSamples = Sampled_getWindowSamples (data, d_startSelection, d_endSelection, & first, & last);
	v_updateMenuItems_file ();
	if (d_sound.data) {
		GuiThing_setSensitive (cutButton     , selectedSamples != 0 && selectedSamples < d_sound.data -> nx);
		GuiThing_setSensitive (copyButton    , selectedSamples != 0);
		GuiThing_setSensitive (zeroButton    , selectedSamples != 0);
		GuiThing_setSensitive (reverseButton , selectedSamples != 0);
	}
}