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 menu_cb_editConstraint (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (L"Edit constraint", 0) LABEL (L"constraint", L""); REAL (L"Ranking value", L"100.0"); REAL (L"Disharmony", L"100.0"); REAL (L"Plasticity", L"1.0"); EDITOR_OK OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint; if (my selected < 1 || my selected > ot -> numberOfConstraints) Melder_throw ("Select a constraint first."); constraint = & ot -> constraints [ot -> index [my selected]]; SET_STRING (L"constraint", constraint -> name) SET_REAL (L"Ranking value", constraint -> ranking) SET_REAL (L"Disharmony", constraint -> disharmony) SET_REAL (L"Plasticity", constraint -> plasticity) EDITOR_DO OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint = & ot -> constraints [ot -> index [my selected]]; Editor_save (me, L"Edit constraint"); constraint -> ranking = GET_REAL (L"Ranking value"); constraint -> disharmony = GET_REAL (L"Disharmony"); constraint -> plasticity = GET_REAL (L"Plasticity"); OTGrammar_sort (ot); Graphics_updateWs (my g); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_evaluate_zeroNoise (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); Editor_save (me, L"Evaluate (zero noise)"); OTGrammar_newDisharmonies ((OTGrammar) my data, 0.0); Graphics_updateWs (my g); my broadcastDataChanged (); }
static void gui_button_cb_insert (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; /* * Find the first selected item. */ long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); long position = selected == NULL ? strings -> numberOfStrings + 1 : selected [1]; NUMvector_free (selected, 1); wchar_t *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, position, text); /* * Change the list. */ GuiList_insertItem (my list, text, position); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, position); /* * Clean up. */ Melder_free (text); my broadcastDataChanged (); }
static void menu_cb_addPointAtCursor (EDITOR_ARGS) { EDITOR_IAM (PointEditor); Editor_save (me, L"Add point"); PointProcess_addPoint ((PointProcess) my data, 0.5 * (my d_startSelection + my d_endSelection)); FunctionEditor_redraw (me); my broadcastDataChanged (); }
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 menu_cb_octaveUp (EDITOR_ARGS) { EDITOR_IAM (PitchEditor); Pitch pitch = (Pitch) my data; Editor_save (me, L"Octave up"); Pitch_step (pitch, 2.0, 0.1, my d_startSelection, my d_endSelection); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_fifthDown (EDITOR_ARGS) { EDITOR_IAM (PitchEditor); Pitch pitch = (Pitch) my data; Editor_save (me, L"Fifth down"); Pitch_step (pitch, 1 / 1.5, 0.1, my d_startSelection, my d_endSelection); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_ReverseSelection (EDITOR_ARGS) { EDITOR_IAM (SoundEditor); Editor_save (me, L"Reverse selection"); Sound_reverse ((Sound) my data, my d_startSelection, my d_endSelection); my v_destroy_analysis (); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static int RunnerMFC_startExperiment (RunnerMFC me) { my data = (Data) my experiments -> item [my iexperiment]; Melder_assert (my data -> classInfo == classExperimentMFC); ExperimentMFC_start ((ExperimentMFC) my data); Thing_setName (me, ((ExperimentMFC) my data) -> name); my broadcastDataChanged (); Graphics_updateWs (my graphics); return 1; }
static void menu_cb_addPointAtCursor (EDITOR_ARGS) { EDITOR_IAM (FormantGridEditor); Editor_save (me, L"Add point"); FormantGrid grid = (FormantGrid) my data; Ordered tiers = my editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier tier = (RealTier) tiers -> item [my selectedFormant]; RealTier_addPoint (tier, 0.5 * (my startSelection + my endSelection), my ycursor); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_removePoints (EDITOR_ARGS) { EDITOR_IAM (PointEditor); Editor_save (me, L"Remove point(s)"); if (my d_startSelection == my d_endSelection) PointProcess_removePointNear ((PointProcess) my data, my d_startSelection); else PointProcess_removePointsBetween ((PointProcess) my data, my d_startSelection, my d_endSelection); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void gui_button_cb_remove (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); for (long iselected = numberOfSelected; iselected >= 1; iselected --) { Strings_remove ((Strings) my data, selected [iselected]); } NUMvector_free (selected, 1); updateList (me); my broadcastDataChanged (); }
static void menu_cb_removeConstraint (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint; if (my selected < 1 || my selected > ot -> numberOfConstraints) Melder_throw ("Select a constraint first."); constraint = & ot -> constraints [ot -> index [my selected]]; Editor_save (me, L"Remove constraint"); OTGrammar_removeConstraint (ot, constraint -> name); Graphics_updateWs (my g); my broadcastDataChanged (); }
static void menu_cb_resetAllRankings (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (L"Reset all rankings", 0) REAL (L"Ranking", L"100.0") EDITOR_OK EDITOR_DO Editor_save (me, L"Reset all rankings"); OTGrammar_reset ((OTGrammar) my data, GET_REAL (L"Ranking")); Graphics_updateWs (my g); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_evaluate (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (L"Evaluate", 0) REAL (L"Noise", L"2.0") EDITOR_OK EDITOR_DO Editor_save (me, L"Evaluate"); OTGrammar_newDisharmonies ((OTGrammar) my data, GET_REAL (L"Noise")); Graphics_updateWs (my g); my broadcastDataChanged (); EDITOR_END }
static void gui_button_cb_replace (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); wchar_t *text = GuiText_getString (my text); for (long iselected = 1; iselected <= numberOfSelected; iselected ++) { Strings_replace (strings, selected [iselected], text); GuiList_replaceItem (my list, text, selected [iselected]); } Melder_free (text); my broadcastDataChanged (); }
static void menu_cb_addPointAt (EDITOR_ARGS) { EDITOR_IAM (PointEditor); EDITOR_FORM (L"Add point", 0) REAL (L"Position", L"0.0"); EDITOR_OK SET_REAL (L"Position", 0.5 * (my d_startSelection + my d_endSelection)); EDITOR_DO Editor_save (me, L"Add point"); PointProcess_addPoint ((PointProcess) my data, GET_REAL (L"Position")); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_removePoints (EDITOR_ARGS) { EDITOR_IAM (FormantGridEditor); Editor_save (me, L"Remove point(s)"); FormantGrid grid = (FormantGrid) my data; Ordered tiers = my editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier tier = (RealTier) tiers -> item [my selectedFormant]; if (my startSelection == my endSelection) AnyTier_removePointNear (tier, my startSelection); else AnyTier_removePointsBetween (tier, my startSelection, my endSelection); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_stopBand (EDITOR_ARGS) { EDITOR_IAM (SpectrumEditor); EDITOR_FORM (L"Filter (stop Hann band)", 0) REAL (L"Band smoothing (Hz)", my default_bandSmoothing ()) EDITOR_OK SET_REAL (L"Band smoothing", my p_bandSmoothing) EDITOR_DO my pref_bandSmoothing () = my p_bandSmoothing = GET_REAL (L"Band smoothing"); if (my d_endSelection <= my d_startSelection) Melder_throw (L"To apply a band-stop filter, first make a selection."); Editor_save (me, L"Stop band"); Spectrum_stopHannBand ((Spectrum) my data, my d_startSelection, my d_endSelection, my p_bandSmoothing); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_SetSelectionToZero (EDITOR_ARGS) { EDITOR_IAM (SoundEditor); Sound sound = (Sound) my data; long first, last; Sampled_getWindowSamples (sound, my d_startSelection, my d_endSelection, & first, & last); Editor_save (me, L"Set to zero"); for (long channel = 1; channel <= sound -> ny; channel ++) { for (long i = first; i <= last; i ++) { sound -> z [channel] [i] = 0.0; } } my v_destroy_analysis (); FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_setCeiling (EDITOR_ARGS) { EDITOR_IAM (PitchEditor); EDITOR_FORM (L"Change ceiling", 0) POSITIVE (L"Ceiling (Hz)", L"600") EDITOR_OK Pitch pitch = (Pitch) my data; SET_REAL (L"Ceiling", pitch -> ceiling) EDITOR_DO Pitch pitch = (Pitch) my data; Editor_save (me, L"Change ceiling"); Pitch_setCeiling (pitch, GET_REAL (L"Ceiling")); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }
static void gui_drawingarea_cb_key (I, GuiDrawingAreaKeyEvent 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; if (experiment -> trial == 0) { } else if (experiment -> pausing) { } else if (experiment -> trial <= experiment -> numberOfTrials) { long iresponse; if (experiment -> ok_key != NULL && experiment -> ok_key [0] == event -> key && experiment -> responses [experiment -> trial] != 0 && (experiment -> numberOfGoodnessCategories == 0 || experiment -> goodnesses [experiment -> trial] != 0)) { do_ok (me); } else if (experiment -> replay_key != NULL && experiment -> replay_key [0] == event -> key && my numberOfReplays < experiment -> maximumNumberOfReplays) { do_replay (me); } else if (experiment -> oops_key != NULL && experiment -> oops_key [0] == event -> key) { if (experiment -> trial > 1) { do_oops (me); } } else if (experiment -> responses [experiment -> trial] == 0) { for (iresponse = 1; iresponse <= experiment -> numberOfDifferentResponses; iresponse ++) { ResponseMFC response = & experiment -> response [iresponse]; if (response -> key != NULL && response -> key [0] == event -> key) { 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); } } } } } }
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 }
static void menu_cb_addPointAt (EDITOR_ARGS) { EDITOR_IAM (FormantGridEditor); EDITOR_FORM (L"Add point", 0) REAL (L"Time (s)", L"0.0") POSITIVE (L"Frequency (Hz)", L"200.0") EDITOR_OK SET_REAL (L"Time", 0.5 * (my startSelection + my endSelection)) SET_REAL (L"Frequency", my ycursor) EDITOR_DO Editor_save (me, L"Add point"); FormantGrid grid = (FormantGrid) my data; Ordered tiers = my editingBandwidths ? grid -> bandwidths : grid -> formants; RealTier tier = (RealTier) tiers -> item [my selectedFormant]; RealTier_addPoint (tier, GET_REAL (L"Time"), GET_REAL (L"Frequency")); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }
static void gui_button_cb_append (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; wchar_t *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, 0, text); /* * Change the list. */ GuiList_insertItem (my list, text, 0); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, strings -> numberOfStrings); /* * Clean up. */ Melder_free (text); my broadcastDataChanged (); }
static void menu_cb_voiceless (EDITOR_ARGS) { EDITOR_IAM (PitchEditor); Pitch pitch = (Pitch) my data; long ileft = Sampled_xToHighIndex (pitch, my d_startSelection); long iright = Sampled_xToLowIndex (pitch, my d_endSelection); if (ileft < 1) ileft = 1; if (iright > pitch -> nx) iright = pitch -> nx; Editor_save (me, L"Unvoice"); for (long i = ileft; i <= iright; i ++) { Pitch_Frame frame = & pitch -> frame [i]; for (long cand = 1; cand <= frame -> nCandidates; cand ++) { if (frame -> candidate [cand]. frequency == 0.0) { struct structPitch_Candidate help = frame -> candidate [1]; frame -> candidate [1] = frame -> candidate [cand]; frame -> candidate [cand] = help; } } } FunctionEditor_redraw (me); my broadcastDataChanged (); }
static void menu_cb_learnOneFromPartialOutput (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (L"Learn one from partial adult output", 0) LABEL (L"", L"Partial adult surface form (e.g. overt form):") SENTENCE (L"Partial output", L"") REAL (L"Evaluation noise", L"2.0") OPTIONMENU_ENUM (L"Update rule", kOTGrammar_rerankingStrategy, kOTGrammar_rerankingStrategy_SYMMETRIC_ALL) REAL (L"Plasticity", L"0.1") REAL (L"Rel. plasticity spreading", L"0.1") BOOLEAN (L"Honour local rankings", 1) NATURAL (L"Number of chews", L"1") EDITOR_OK EDITOR_DO Editor_save (me, L"Learn one from partial output"); OTGrammar_learnOneFromPartialOutput ((OTGrammar) my data, GET_STRING (L"Partial output"), GET_REAL (L"Evaluation noise"), GET_ENUM (kOTGrammar_rerankingStrategy, L"Update rule"), GET_INTEGER (L"Honour local rankings"), GET_REAL (L"Plasticity"), GET_REAL (L"Rel. plasticity spreading"), GET_INTEGER (L"Number of chews"), TRUE); OTGrammar_sort ((OTGrammar) my data); Graphics_updateWs (my g); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_learnOne (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (L"Learn one", L"OTGrammar: Learn one...") LABEL (L"", L"Underlying form:") SENTENCE (L"Input string", L"") LABEL (L"", L"Adult surface form:") SENTENCE (L"Output string", L"") REAL (L"Evaluation noise", L"2.0") OPTIONMENU_ENUM (L"Update rule", kOTGrammar_rerankingStrategy, kOTGrammar_rerankingStrategy_SYMMETRIC_ALL) REAL (L"Plasticity", L"0.1") REAL (L"Rel. plasticity spreading", L"0.1") BOOLEAN (L"Honour local rankings", 1) EDITOR_OK EDITOR_DO Editor_save (me, L"Learn one"); OTGrammar_learnOne ((OTGrammar) my data, GET_STRING (L"Input string"), GET_STRING (L"Output string"), GET_REAL (L"Evaluation noise"), GET_ENUM (kOTGrammar_rerankingStrategy, L"Update rule"), GET_INTEGER (L"Honour local rankings"), GET_REAL (L"Plasticity"), GET_REAL (L"Rel. plasticity spreading"), TRUE, TRUE, NULL); OTGrammar_sort ((OTGrammar) my data); Graphics_updateWs (my g); my broadcastDataChanged (); EDITOR_END }
static void menu_cb_pathFinder (EDITOR_ARGS) { EDITOR_IAM (PitchEditor); EDITOR_FORM (L"Path finder", 0) REAL (L"Silence threshold", L"0.03") REAL (L"Voicing threshold", L"0.45") REAL (L"Octave cost", L"0.01") REAL (L"Octave-jump cost", L"0.35") REAL (L"Voiced/unvoiced cost", L"0.14") POSITIVE (L"Ceiling (Hz)", L"600") BOOLEAN (L"Pull formants", 0) EDITOR_OK Pitch pitch = (Pitch) my data; SET_REAL (L"Ceiling", pitch -> ceiling) EDITOR_DO Pitch pitch = (Pitch) my data; Editor_save (me, L"Path finder"); Pitch_pathFinder (pitch, GET_REAL (L"Silence threshold"), GET_REAL (L"Voicing threshold"), GET_REAL (L"Octave cost"), GET_REAL (L"Octave-jump cost"), GET_REAL (L"Voiced/unvoiced cost"), GET_REAL (L"Ceiling"), GET_INTEGER (L"Pull formants")); FunctionEditor_redraw (me); my broadcastDataChanged (); EDITOR_END }