static void readSound (ExperimentMFC me, const char32 *fileNameHead, const char32 *fileNameTail, double medialSilenceDuration, char32 **name, autoSound *sound) { char32 fileNameBuffer [256], *fileNames = & fileNameBuffer [0]; Melder_sprint (fileNameBuffer,256, *name); structMelderFile file = { 0 }; /* * The following conversion is needed when fileNameHead is an absolute path, * and the stimulus names contain slashes for relative paths. * An ugly case, but allowed. */ #if defined (_WIN32) for (;;) { char32 *slash = str32chr (fileNames, U'/'); if (! slash) break; *slash = U'\\'; } #endif sound->reset(); char32 pathName [kMelder_MAXPATH+1]; /* * 'fileNames' can contain commas, which separate partial file names. * The separate files should be concatenated. */ for (;;) { /* * Determine partial file name. */ char32 *comma = str32chr (fileNames, U','); if (comma) *comma = '\0'; /* * Determine complete (relative) file name. */ Melder_sprint (pathName,kMelder_MAXPATH+1, fileNameHead, fileNames, fileNameTail); /* * Make sure we are in the correct directory. */ if (MelderDir_isNull (& my rootDirectory)) { /* * Absolute file name. */ Melder_pathToFile (pathName, & file); } else { /* * Relative or absolute file name. */ MelderDir_relativePathToFile (& my rootDirectory, pathName, & file); if (Melder_debug == 32) { MelderInfo_open (); MelderInfo_writeLine (U"Path name <", pathName, U">"); MelderInfo_writeLine (U"Root directory <", my rootDirectory.path, U">"); MelderInfo_writeLine (U"Full path name <", file.path, U">"); MelderInfo_close (); } } /* * Read the substimulus. */ autoSound substimulus = Data_readFromFile (& file). static_cast_move<structSound>(); if (substimulus -> classInfo != classSound) Melder_throw (U"File ", & file, U" contains a ", Thing_className (substimulus.get()), U" instead of a sound."); /* * Check whether all sounds have the same number of channels. */ if (my numberOfChannels == 0) { my numberOfChannels = substimulus -> ny; } else if (substimulus -> ny != my numberOfChannels) { Melder_throw (U"The sound in file ", & file, U" has a different number of channels than some other sound."); } /* * Check whether all sounds have the same sampling frequency. */ if (my samplePeriod == 0.0) { my samplePeriod = substimulus -> dx; /* This must be the first sound read. */ } else if (substimulus -> dx != my samplePeriod) { Melder_throw (U"The sound in file ", & file, U" has a different sampling frequency than some other sound."); } /* * Append the substimuli, perhaps with silent intervals. */ if (*sound) { *sound = Sounds_append (sound->get(), medialSilenceDuration, substimulus.get()); } else { *sound = substimulus.move(); } /* * Cycle. */ if (! comma) break; fileNames = & comma [1]; } }
static void gui_drawingarea_cb_expose (I, GuiDrawingAreaExposeEvent event) { iam (RunnerMFC); Melder_assert (event -> widget == my d_drawingArea); if (my graphics == NULL) return; // Could be the case in the very beginning. ExperimentMFC experiment = (ExperimentMFC) my data; long iresponse; if (my data == NULL) return; Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); if (experiment -> trial == 0) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> startText); } else if (experiment -> pausing) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> pauseText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } else if (experiment -> trial <= experiment -> numberOfTrials) { const wchar_t *visibleText = experiment -> stimulus [experiment -> stimuli [experiment -> trial]]. visibleText; wchar_t *visibleText_dup = Melder_wcsdup_f (visibleText ? visibleText : L""), *visibleText_p = visibleText_dup; Graphics_setFont (my graphics, kGraphics_font_TIMES); Graphics_setFontSize (my graphics, 10); Graphics_setColour (my graphics, Graphics_BLACK); Graphics_setTextAlignment (my graphics, Graphics_LEFT, Graphics_TOP); Graphics_text3 (my graphics, 0, 1, Melder_integer (experiment -> trial), L" / ", Melder_integer (experiment -> numberOfTrials)); Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_TOP); Graphics_setFontSize (my graphics, 24); /* * The run text. */ if (visibleText_p [0] != '\0') { wchar_t *visibleText_q = wcschr (visibleText_p, '|'); if (visibleText_q) *visibleText_q = '\0'; Graphics_text (my graphics, 0.5, 1.0, visibleText_p [0] != '\0' ? visibleText_p : experiment -> runText); if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += wcslen (visibleText_p); } else { Graphics_text (my graphics, 0.5, 1.0, experiment -> runText); } Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); for (iresponse = 1; iresponse <= experiment -> numberOfDifferentResponses; iresponse ++) { ResponseMFC response = & experiment -> response [iresponse]; wchar_t *textToDraw = response -> label; // can be overridden if (visibleText_p [0] != '\0') { wchar_t *visibleText_q = wcschr (visibleText_p, '|'); if (visibleText_q) *visibleText_q = '\0'; textToDraw = visibleText_p; // override if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += wcslen (visibleText_p); } if (wcsnequ (textToDraw, L"\\FI", 3)) { structMelderFile file; MelderDir_relativePathToFile (& experiment -> rootDirectory, textToDraw + 3, & file); Graphics_imageFromFile (my graphics, Melder_fileToPath (& file), response -> left, response -> right, response -> bottom, response -> top); } else { Graphics_setColour (my graphics, response -> name [0] == '\0' ? Graphics_SILVER : experiment -> responses [experiment -> trial] == iresponse ? Graphics_RED : experiment -> ok_right > experiment -> ok_left || experiment -> responses [experiment -> trial] == 0 ? Graphics_YELLOW : Graphics_SILVER); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setFontSize (my graphics, response -> fontSize ? response -> fontSize : 24); Graphics_text (my graphics, 0.5 * (response -> left + response -> right), 0.5 * (response -> bottom + response -> top), textToDraw); } Graphics_setFontSize (my graphics, 24); } for (iresponse = 1; iresponse <= experiment -> numberOfGoodnessCategories; iresponse ++) { GoodnessMFC goodness = & experiment -> goodness [iresponse]; Graphics_setColour (my graphics, experiment -> responses [experiment -> trial] == 0 ? Graphics_SILVER : experiment -> goodnesses [experiment -> trial] == iresponse ? Graphics_RED : Graphics_YELLOW); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_text (my graphics, 0.5 * (goodness -> left + goodness -> right), 0.5 * (goodness -> bottom + goodness -> top), goodness -> label); } if (experiment -> replay_right > experiment -> replay_left && my numberOfReplays < experiment -> maximumNumberOfReplays) { drawControlButton (me, experiment -> replay_left, experiment -> replay_right, experiment -> replay_bottom, experiment -> replay_top, experiment -> replay_label); } if (experiment -> ok_right > experiment -> ok_left && experiment -> responses [experiment -> trial] != 0 && (experiment -> numberOfGoodnessCategories == 0 || experiment -> goodnesses [experiment -> trial] != 0)) { drawControlButton (me, experiment -> ok_left, experiment -> ok_right, experiment -> ok_bottom, experiment -> ok_top, experiment -> ok_label); } if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } Melder_free (visibleText_dup); } else { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> endText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } }