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 gui_button_cb_addTarget (ArtwordEditor me, GuiButtonEvent /* event */) { Artword artword = (Artword) my data; char32 *timeText = GuiText_getString (my time); double tim = Melder_atof (timeText); char32 *valueText = GuiText_getString (my value); double value = Melder_atof (valueText); ArtwordData a = & artword -> data [my feature]; int i = 1, oldCount = a -> numberOfTargets; Melder_free (timeText); Melder_free (valueText); Artword_setTarget (artword, my feature, tim, value); /* Optimization instead of "updateList (me)". */ if (tim < 0) tim = 0; if (tim > artword -> totalTime) tim = artword -> totalTime; while (tim != a -> times [i]) { i ++; Melder_assert (i <= a -> numberOfTargets); // can fail if tim is in an extended precision register } const char32 *itemText = Melder_cat (Melder_single (tim), U" ", Melder_single (value)); if (a -> numberOfTargets == oldCount) { GuiList_replaceItem (my list, itemText, i); } else { GuiList_insertItem (my list, itemText, i); } Graphics_updateWs (my graphics.get()); Editor_broadcastDataChanged (me); }
static void menu_cb_evaluate_noise_2_0 (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); Editor_save (me, U"Evaluate (noise 2.0)"); OTMulti_newDisharmonies ((OTMulti) my data, 2.0); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
static void menu_cb_evaluate_tinyNoise (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); Editor_save (me, U"Evaluate (tiny noise)"); OTMulti_newDisharmonies ((OTMulti) my data, 1e-9); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
static void menu_cb_editRanking (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); EDITOR_FORM (U"Edit ranking", 0) LABEL (U"constraint", U""); REAL (U"Ranking value", U"100.0"); REAL (U"Disharmony", U"100.0"); EDITOR_OK OTMulti grammar = (OTMulti) my data; OTConstraint constraint; if (my selectedConstraint < 1 || my selectedConstraint > grammar -> numberOfConstraints) Melder_throw (U"Select a constraint first."); constraint = & grammar -> constraints [grammar -> index [my selectedConstraint]]; SET_STRING (U"constraint", constraint -> name) SET_REAL (U"Ranking value", constraint -> ranking) SET_REAL (U"Disharmony", constraint -> disharmony) EDITOR_DO OTMulti grammar = (OTMulti) my data; OTConstraint constraint = & grammar -> constraints [grammar -> index [my selectedConstraint]]; Editor_save (me, U"Edit ranking"); constraint -> ranking = GET_REAL (U"Ranking value"); constraint -> disharmony = GET_REAL (U"Disharmony"); OTMulti_sort (grammar); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); EDITOR_END }
static void menu_cb_editConstraint (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); EDITOR_FORM (U"Edit constraint", 0) LABEL (U"constraint", U""); REAL (U"Ranking value", U"100.0"); REAL (U"Disharmony", U"100.0"); REAL (U"Plasticity", U"1.0"); EDITOR_OK OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint; if (my selected < 1 || my selected > ot -> numberOfConstraints) Melder_throw (U"Select a constraint first."); constraint = & ot -> constraints [ot -> index [my selected]]; SET_STRING (U"constraint", constraint -> name) SET_REAL (U"Ranking value", constraint -> ranking) SET_REAL (U"Disharmony", constraint -> disharmony) SET_REAL (U"Plasticity", constraint -> plasticity) EDITOR_DO OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint = & ot -> constraints [ot -> index [my selected]]; Editor_save (me, U"Edit constraint"); constraint -> ranking = GET_REAL (U"Ranking value"); constraint -> disharmony = GET_REAL (U"Disharmony"); constraint -> plasticity = GET_REAL (U"Plasticity"); OTGrammar_sort (ot); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); EDITOR_END }
static void menu_cb_evaluate_zeroNoise (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); Editor_save (me, U"Evaluate (zero noise)"); OTGrammar_newDisharmonies ((OTGrammar) my data, 0.0); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
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_evaluate_tinyNoise (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); Editor_save (me, L"Evaluate (tiny noise)"); OTGrammar_newDisharmonies ((OTGrammar) my data, 1e-9); Graphics_updateWs (my g); my broadcastDataChanged (); }
static void do_limit (OTMultiEditor me) { Melder_free (my form1); Melder_free (my form2); my form1 = GuiText_getString (my form1Text); my form2 = GuiText_getString (my form2Text); Graphics_updateWs (my g); }
void structTableEditor :: v_dataChanged () { Table table = static_cast<Table> (our data); if (topRow > table -> rows.size) topRow = table -> rows.size; if (leftColumn > table -> numberOfColumns) leftColumn = table -> numberOfColumns; updateVerticalScrollBar (this); updateHorizontalScrollBar (this); Graphics_updateWs (our graphics.get()); }
static void gui_drawingarea_cb_resize (I, GuiDrawingAreaResizeEvent event) { iam (RunnerMFC); if (my graphics == NULL) return; Graphics_setWsViewport (my graphics, 0, event -> width, 0, event -> height); Graphics_setWsWindow (my graphics, 0, event -> width, 0, event -> height); Graphics_setViewport (my graphics, 0, event -> width, 0, event -> height); Graphics_updateWs (my graphics); }
static void gui_drawingarea_cb_resize (I, GuiDrawingAreaResizeEvent event) { iam (HyperPage); if (my g == NULL) return; Graphics_setWsViewport (my g, 0, event -> width, 0, event -> height); Graphics_setWsWindow (my g, 0.0, my rightMargin = event -> width / resolution, PAGE_HEIGHT - event -> height / resolution, PAGE_HEIGHT); Graphics_updateWs (my g); updateVerticalScrollBar (me); }
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 updateList (ArtwordEditor me) { Artword artword = (Artword) my data; ArtwordData a = & artword -> data [my feature]; GuiList_deleteAllItems (my list); for (int i = 1; i <= a -> numberOfTargets; i ++) { GuiList_insertItem (my list, Melder_cat (Melder_single (a -> times [i]), U" ", Melder_single (a -> targets [i])), i); } Graphics_updateWs (my graphics.get()); }
static void menu_cb_removeConstraint (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); OTMulti grammar = (OTMulti) my data; if (my selectedConstraint < 1 || my selectedConstraint > grammar -> numberOfConstraints) Melder_throw (U"Select a constraint first."); OTConstraint constraint = & grammar -> constraints [grammar -> index [my selectedConstraint]]; Editor_save (me, U"Remove constraint"); OTMulti_removeConstraint (grammar, constraint -> name); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
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_removeConstraint (EDITOR_ARGS) { EDITOR_IAM (OTGrammarEditor); OTGrammar ot = (OTGrammar) my data; OTGrammarConstraint constraint; if (my selected < 1 || my selected > ot -> numberOfConstraints) Melder_throw (U"Select a constraint first."); constraint = & ot -> constraints [ot -> index [my selected]]; Editor_save (me, U"Remove constraint"); OTGrammar_removeConstraint (ot, constraint -> name); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); }
static void gui_cb_scrollHorizontal (TableEditor me, GuiScrollBarEvent event) { int value = GuiScrollBar_getValue (event -> scrollBar); if (value != my leftColumn) { my leftColumn = value; #if cocoa || gtk || motif Graphics_updateWs (my graphics.get()); // wait for expose event #else Graphics_clearWs (my graphics.get()); my v_draw (); // do not wait for expose event #endif } }
static void updateList (ArtwordEditor me) { Artword artword = (Artword) my data; ArtwordData a = & artword -> data [my feature]; GuiList_deleteAllItems (my list); for (int i = 1; i <= a -> numberOfTargets; i ++) { static MelderString itemText = { 0 }; MelderString_empty (& itemText); MelderString_append (& itemText, Melder_single (a -> times [i]), L" ", Melder_single (a -> targets [i])); GuiList_insertItem (my list, itemText.string, i); } Graphics_updateWs (my graphics); }
static void menu_cb_preferences (TableEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"TableEditor preferences", nullptr); OPTIONMENU (U"The symbols %#_^ in labels", my default_useTextStyles () + 1) OPTION (U"are shown as typed") OPTION (U"mean italic/bold/sub/super") EDITOR_OK SET_INTEGER (U"The symbols %#_^ in labels", my p_useTextStyles + 1) EDITOR_DO my pref_useTextStyles () = my p_useTextStyles = GET_INTEGER (U"The symbols %#_^ in labels") - 1; Graphics_updateWs (my graphics.get()); EDITOR_END }
static void gui_drawingarea_cb_click (Picture me, GuiDrawingArea_ClickEvent event) { int xstart = event -> x; int ystart = event -> y; double xWC, yWC; int ixstart, iystart, ix, iy, oldix = 0, oldiy = 0; Graphics_DCtoWC (my selectionGraphics.get(), xstart, ystart, & xWC, & yWC); ix = ixstart = 1 + floor (xWC * SQUARES / SIDE); iy = iystart = SQUARES - floor (yWC * SQUARES / SIDE); if (ixstart < 1 || ixstart > SQUARES || iystart < 1 || iystart > SQUARES) return; if (event -> shiftKeyPressed) { int ix1 = 1 + floor (my selx1 * SQUARES / SIDE); int ix2 = floor (my selx2 * SQUARES / SIDE); int iy1 = SQUARES + 1 - floor (my sely2 * SQUARES / SIDE); int iy2 = SQUARES - floor (my sely1 * SQUARES / SIDE); ixstart = ix < (ix1 + ix2) / 2 ? ix2 : ix1; iystart = iy < (iy1 + iy2) / 2 ? iy2 : iy1; } //while (Graphics_mouseStillDown (my selectionGraphics)) { do { Graphics_getMouseLocation (my selectionGraphics.get(), & xWC, & yWC); ix = 1 + floor (xWC * SQUARES / SIDE); iy = SQUARES - floor (yWC * SQUARES / SIDE); if (ix >= 1 && ix <= SQUARES && iy >= 1 && iy <= SQUARES && (ix != oldix || iy != oldiy)) { int ix1, ix2, iy1, iy2; if (ix < ixstart) { ix1 = ix; ix2 = ixstart; } else { ix1 = ixstart; ix2 = ix; } if (iy < iystart) { iy1 = iy; iy2 = iystart; } else { iy1 = iystart; iy2 = iy; } if (my mouseSelectsInnerViewport) { int fontSize = Graphics_inqFontSize (my graphics.get()); double xmargin = fontSize * 4.2 / 72.0, ymargin = fontSize * 2.8 / 72.0; if (xmargin > ix2 - ix1 + 1) xmargin = ix2 - ix1 + 1; if (ymargin > iy2 - iy1 + 1) ymargin = iy2 - iy1 + 1; Picture_setSelection (me, 0.5 * (ix1 - 1) - xmargin, 0.5 * ix2 + xmargin, 0.5 * (SQUARES - iy2) - ymargin, 0.5 * (SQUARES + 1 - iy1) + ymargin, false); } else { Picture_setSelection (me, 0.5 * (ix1 - 1), 0.5 * ix2, 0.5 * (SQUARES - iy2), 0.5 * (SQUARES + 1 - iy1), false); } oldix = ix; oldiy = iy; } } while (Graphics_mouseStillDown (my selectionGraphics.get())); // } #if cocoa Graphics_updateWs (my selectionGraphics.get()); // to change the dark red back into black #endif if (my selectionChangedCallback) { //Melder_casual (U"selectionChangedCallback from gui_drawingarea_cb_click"); my selectionChangedCallback (me, my selectionChangedClosure, my selx1, my selx2, my sely1, my sely2); } }
static void gui_cb_scrollVertical (TableEditor me, GuiScrollBarEvent event) { int value = GuiScrollBar_getValue (event -> scrollBar); if (value != my topRow) { my topRow = value; #if cocoa || gtk || win Graphics_updateWs (my graphics.get()); // wait for expose event #else Graphics_clearWs (my graphics.get()); my v_draw (); // do not wait for expose event #endif } }
static void menu_cb_evaluate (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); EDITOR_FORM (U"Evaluate", 0) REAL (U"Evaluation noise", U"2.0") EDITOR_OK EDITOR_DO Editor_save (me, U"Evaluate"); OTMulti_newDisharmonies ((OTMulti) my data, GET_REAL (U"Evaluation noise")); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); 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 menu_cb_resetAllRankings (EDITOR_ARGS) { EDITOR_IAM (OTMultiEditor); EDITOR_FORM (U"Reset all rankings", 0) REAL (U"Ranking", U"100.0") EDITOR_OK EDITOR_DO Editor_save (me, U"Reset all rankings"); OTMulti_reset ((OTMulti) my data, GET_REAL (U"Ranking")); Graphics_updateWs (my g); Editor_broadcastDataChanged (me); EDITOR_END }
static void menu_cb_font (EDITOR_ARGS) { EDITOR_IAM (HyperPage); EDITOR_FORM (L"Font", 0) RADIO (L"Font", 1) RADIOBUTTON (L"Times") RADIOBUTTON (L"Helvetica") EDITOR_OK SET_INTEGER (L"Font", my font == kGraphics_font_TIMES ? 1 : my font == kGraphics_font_HELVETICA ? 2 : my font == kGraphics_font_PALATINO ? 3 : 1); EDITOR_DO int font = GET_INTEGER (L"Font"); prefs_font = my font = font == 1 ? kGraphics_font_TIMES : kGraphics_font_HELVETICA; if (my g) Graphics_updateWs (my g); 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); } } } } } }
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]); } }
void Picture_readFromPraatPictureFile (Picture me, MelderFile file) { try { autofile f = Melder_fopen (file, "rb"); char line [200]; int n = fread (line, 1, 199, f); line [n] = '\0'; const char *tag = "PraatPictureFile"; char *end = strstr (line, tag); if (! end) Melder_throw (U"This is not a Praat picture file."); *end = '\0'; rewind (f); fread (line, 1, end - line + strlen (tag), f); Graphics_readRecordings (my graphics.get(), f); Graphics_updateWs (my graphics.get()); f.close (file); } catch (MelderError) { Melder_throw (U"Praat picture not read from file ", file); } }