static void do_oops (RunnerMFC me) { ExperimentMFC experiment = (ExperimentMFC) my data; Melder_assert (experiment -> trial >= 2 && experiment -> trial <= experiment -> numberOfTrials + 1); if (experiment -> trial <= experiment -> numberOfTrials) { experiment -> responses [experiment -> trial] = 0; experiment -> goodnesses [experiment -> trial] = 0; } experiment -> trial --; experiment -> responses [experiment -> trial] = 0; experiment -> goodnesses [experiment -> trial] = 0; experiment -> pausing = FALSE; my numberOfReplays = 0; my broadcastDataChanged (); if (experiment -> blankWhilePlaying) { Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); Graphics_flushWs (my graphics); } Graphics_updateWs (my graphics); if (experiment -> stimuliAreSounds) { autoMelderAudioSaveMaximumAsynchronicity saveMaximumAsynchronicity; if (experiment -> blankWhilePlaying) MelderAudio_setOutputMaximumAsynchronicity (kMelder_asynchronicityLevel_SYNCHRONOUS); ExperimentMFC_playStimulus (experiment, experiment -> stimuli [experiment -> trial]); } }
static void do_ok (RunnerMFC me) { ExperimentMFC experiment = (ExperimentMFC) my data; Melder_assert (experiment -> trial >= 1 && experiment -> trial <= experiment -> numberOfTrials); my numberOfReplays = 0; if (experiment -> trial == experiment -> numberOfTrials) { experiment -> trial ++; my broadcastDataChanged (); Graphics_updateWs (my graphics); } else if (experiment -> breakAfterEvery != 0 && experiment -> trial % experiment -> breakAfterEvery == 0) { experiment -> pausing = TRUE; my broadcastDataChanged (); Graphics_updateWs (my graphics); } else { experiment -> trial ++; my broadcastDataChanged (); if (experiment -> blankWhilePlaying) { Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); Graphics_flushWs (my graphics); } Graphics_updateWs (my graphics); if (experiment -> stimuliAreSounds) { autoMelderAudioSaveMaximumAsynchronicity saveMaximumAsynchronicity; if (experiment -> blankWhilePlaying) MelderAudio_setOutputMaximumAsynchronicity (kMelder_asynchronicityLevel_SYNCHRONOUS); ExperimentMFC_playStimulus (experiment, experiment -> stimuli [experiment -> trial]); } } }
static void do_replay (RunnerMFC me) { ExperimentMFC experiment = (ExperimentMFC) my data; Melder_assert (experiment -> trial >= 1 && experiment -> trial <= experiment -> numberOfTrials); my numberOfReplays ++; Editor_broadcastDataChanged (me); if (experiment -> blankWhilePlaying) { Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); Graphics_flushWs (my graphics); } Graphics_updateWs (my graphics); if (experiment -> stimuliAreSounds) { autoMelderAudioSaveMaximumAsynchronicity saveMaximumAsynchronicity; if (experiment -> blankWhilePlaying) MelderAudio_setOutputMaximumAsynchronicity (kMelder_asynchronicityLevel_SYNCHRONOUS); ExperimentMFC_playStimulus (experiment, experiment -> stimuli [experiment -> trial]); } }
static void gui_drawingarea_cb_click (I, GuiDrawingAreaClickEvent event) { iam (RunnerMFC); if (my graphics == NULL) return; // Could be the case in the very beginning. ExperimentMFC experiment = (ExperimentMFC) my data; if (my data == NULL) return; double reactionTime = Melder_clock () - experiment -> startingTime; if (! experiment -> blankWhilePlaying) reactionTime -= experiment -> stimulusInitialSilenceDuration; double x, y; Graphics_DCtoWC (my graphics, event -> x, event -> y, & x, & y); if (experiment -> trial == 0) { // the first click of the experiment experiment -> trial ++; my broadcastDataChanged (); if (experiment -> blankWhilePlaying) { Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); Graphics_flushWs (my graphics); } Graphics_updateWs (my graphics); if (experiment -> stimuliAreSounds) { if (experiment -> numberOfTrials < 1) { Melder_flushError ("There are zero trials in this experiment."); forget (me); return; } autoMelderAudioSaveMaximumAsynchronicity saveMaximumAsynchronicity; if (experiment -> blankWhilePlaying) MelderAudio_setOutputMaximumAsynchronicity (kMelder_asynchronicityLevel_SYNCHRONOUS); ExperimentMFC_playStimulus (experiment, experiment -> stimuli [1]); // works only if there is at least one trial } } else if (experiment -> pausing) { // a click to leave the break if (x > experiment -> oops_left && x < experiment -> oops_right && y > experiment -> oops_bottom && y < experiment -> oops_top && experiment -> trial > 1) { do_oops (me); } else { experiment -> pausing = FALSE; experiment -> trial ++; my broadcastDataChanged (); if (experiment -> blankWhilePlaying) { Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); Graphics_flushWs (my graphics); } Graphics_updateWs (my graphics); if (experiment -> stimuliAreSounds) { autoMelderAudioSaveMaximumAsynchronicity saveMaximumAsynchronicity; if (experiment -> blankWhilePlaying) MelderAudio_setOutputMaximumAsynchronicity (kMelder_asynchronicityLevel_SYNCHRONOUS); ExperimentMFC_playStimulus (experiment, experiment -> stimuli [experiment -> trial]); } } } else if (experiment -> trial <= experiment -> numberOfTrials) { long iresponse; if (x > experiment -> ok_left && x < experiment -> ok_right && y > experiment -> ok_bottom && y < experiment -> ok_top && experiment -> responses [experiment -> trial] != 0 && (experiment -> numberOfGoodnessCategories == 0 || experiment -> goodnesses [experiment -> trial] != 0)) { do_ok (me); } else if (x > experiment -> replay_left && x < experiment -> replay_right && y > experiment -> replay_bottom && y < experiment -> replay_top && my numberOfReplays < experiment -> maximumNumberOfReplays) { do_replay (me); } else if (x > experiment -> oops_left && x < experiment -> oops_right && y > experiment -> oops_bottom && y < experiment -> oops_top && experiment -> trial > 1) { do_oops (me); } else if (experiment -> responses [experiment -> trial] == 0 || experiment -> ok_right > experiment -> ok_left) { for (iresponse = 1; iresponse <= experiment -> numberOfDifferentResponses; iresponse ++) { ResponseMFC response = & experiment -> response [iresponse]; if (x > response -> left && x < response -> right && y > response -> bottom && y < response -> top && response -> name [0] != '\0') { experiment -> responses [experiment -> trial] = iresponse; experiment -> reactionTimes [experiment -> trial] = reactionTime; if (experiment -> responsesAreSounds) { ExperimentMFC_playResponse (experiment, iresponse); } if (experiment -> ok_right <= experiment -> ok_left && experiment -> numberOfGoodnessCategories == 0) { do_ok (me); } else { my broadcastDataChanged (); Graphics_updateWs (my graphics); } } } if (experiment -> responses [experiment -> trial] != 0 && experiment -> ok_right > experiment -> ok_left) { for (iresponse = 1; iresponse <= experiment -> numberOfGoodnessCategories; iresponse ++) { GoodnessMFC cat = & experiment -> goodness [iresponse]; if (x > cat -> left && x < cat -> right && y > cat -> bottom && y < cat -> top) { experiment -> goodnesses [experiment -> trial] = iresponse; my broadcastDataChanged (); Graphics_updateWs (my graphics); } } } } else if (experiment -> responses [experiment -> trial] != 0) { Melder_assert (experiment -> ok_right <= experiment -> ok_left); for (iresponse = 1; iresponse <= experiment -> numberOfGoodnessCategories; iresponse ++) { GoodnessMFC cat = & experiment -> goodness [iresponse]; if (x > cat -> left && x < cat -> right && y > cat -> bottom && y < cat -> top) { experiment -> goodnesses [experiment -> trial] = iresponse; do_ok (me); } } } } else { if (x > experiment -> oops_left && x < experiment -> oops_right && y > experiment -> oops_bottom && y < experiment -> oops_top) { do_oops (me); return; } if (my iexperiment < my experiments -> size) { my iexperiment ++; if (! RunnerMFC_startExperiment (me)) { Melder_flushError (NULL); forget (me); return; } } } }
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); Melder_assert (d_sound.data || d_longSound.data); /* * 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.get(), Graphics_WHITE); Graphics_setWindow (d_graphics.get(), 0.0, 1.0, 0.0, 1.0); Graphics_fillRectangle (d_graphics.get(), 0.0, 1.0, 0.0, 1.0); Graphics_setColour (d_graphics.get(), Graphics_BLACK); Graphics_setTextAlignment (d_graphics.get(), Graphics_CENTRE, Graphics_BOTTOM); Graphics_text (d_graphics.get(), 0.5, 0.5, U"(window longer than ", Melder_float (Melder_single (d_longSound.data -> bufferLength)), U" seconds)"); Graphics_setTextAlignment (d_graphics.get(), Graphics_CENTRE, Graphics_TOP); Graphics_text (d_graphics.get(), 0.5, 0.5, U"(zoom in to see the samples)"); return; } /* Draw sound. */ if (showAnalysis) viewport = Graphics_insetViewport (d_graphics.get(), 0.0, 1.0, 0.5, 1.0); Graphics_setColour (d_graphics.get(), Graphics_WHITE); Graphics_setWindow (d_graphics.get(), 0.0, 1.0, 0.0, 1.0); Graphics_fillRectangle (d_graphics.get(), 0.0, 1.0, 0.0, 1.0); TimeSoundEditor_drawSound (this, d_sound.minimum, d_sound.maximum); Graphics_flushWs (d_graphics.get()); if (showAnalysis) Graphics_resetViewport (d_graphics.get(), viewport); /* Draw analyses. */ if (showAnalysis) { /* Draw spectrogram, pitch, formants. */ viewport = Graphics_insetViewport (d_graphics.get(), 0.0, 1.0, 0.0, 0.5); v_draw_analysis (); Graphics_flushWs (d_graphics.get()); Graphics_resetViewport (d_graphics.get(), viewport); } /* Draw pulses. */ if (p_pulses_show) { if (showAnalysis) viewport = Graphics_insetViewport (d_graphics.get(), 0.0, 1.0, 0.5, 1.0); v_draw_analysis_pulses (); TimeSoundEditor_drawSound (this, d_sound.minimum, d_sound.maximum); // second time, partially across the pulses Graphics_flushWs (d_graphics.get()); if (showAnalysis) Graphics_resetViewport (d_graphics.get(), 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); } }
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); } }