void * Melder_realloc_f (void *ptr, int64 size) { void *result; if (size <= 0) Melder_fatal (U"(Melder_realloc_f:) Can never allocate ", Melder_bigInteger (size), U" bytes."); if (sizeof (size_t) < 8 && size > SIZE_MAX) Melder_fatal (U"(Melder_realloc_f:) Can never allocate ", Melder_bigInteger (size), U" bytes."); result = realloc (ptr, (size_t) size); // will not show in the statistics... if (result == NULL) { if (theRainyDayFund != NULL) { free (theRainyDayFund); theRainyDayFund = NULL; } result = realloc (ptr, (size_t) size); if (result != NULL) { Melder_flushError (U"Praat is very low on memory.\nSave your work and quit Praat.\nIf you don't do that, Praat may crash."); } else { Melder_fatal (U"Out of memory. Could not extend room to ", Melder_bigInteger (size), U" bytes."); } } if (ptr == NULL) { // is it like malloc? totalNumberOfAllocations += 1; totalAllocationSize += size; } else if (result != ptr) { // did realloc do a malloc-and-free? totalNumberOfAllocations += 1; totalAllocationSize += size; totalNumberOfDeallocations += 1; totalNumberOfMovingReallocs += 1; } else { totalNumberOfReallocsInSitu += 1; } return result; }
void structScriptEditor :: v_goAway () { if (interpreter -> running) { Melder_flushError (U"Cannot close the script window while the script is running or paused. Please close or continue the pause or demo window."); } else { ScriptEditor_Parent :: v_goAway (); } }
void Picture_print (Picture me) { try { Printer_print (print, me); } catch (MelderError) { Melder_flushError (U"Picture not printed."); } }
void structHyperPage :: v_dataChanged () { int oldError = Melder_hasError (); // this method can be called during error time (void) v_goToPage (currentPageTitle); if (Melder_hasError () && ! oldError) Melder_flushError (NULL); HyperPage_clear (this); updateVerticalScrollBar (this); }
static gboolean _GuiGtkDrawingArea_exposeCallback (GuiObject widget, GdkEventExpose *expose, gpointer void_me) { trace (U"begin"); iam (GuiDrawingArea); Melder_assert (me); // TODO: that helps against the damaged regions outside the rect where the // Graphics drawing is done, but where does that margin come from in the // first place?? Additionally this causes even more flickering //gdk_window_clear_area ((GTK_WIDGET (widget)) -> window, expose->area.x, expose->area.y, expose->area.width, expose->area.height); if (my d_exposeCallback) { struct structGuiDrawingArea_ExposeEvent event { me, 0 }; event. x = expose -> area. x; event. y = expose -> area. y; event. width = expose -> area. width; event. height = expose -> area. height; try { //GdkRectangle rect = { event. x, event. y, event. width, event. height }; //gdk_window_begin_paint_rect ((GTK_WIDGET (widget)) -> window, & rect); trace (U"send the expose callback"); trace (U"locale is ", Melder_peek8to32 (setlocale (LC_ALL, nullptr))); my d_exposeCallback (my d_exposeBoss, & event); trace (U"the expose callback finished"); trace (U"locale is ", Melder_peek8to32 (setlocale (LC_ALL, nullptr))); //gdk_window_end_paint ((GTK_WIDGET (widget)) -> window); //gdk_window_flush ((GTK_WIDGET (widget)) -> window); //gdk_flush (); } catch (MelderError) { Melder_flushError (U"Redrawing not completed"); } trace (U"the expose callback handled drawing"); return true; } trace (U"GTK will handle redrawing"); return false; }
static gboolean _GuiGtkDrawingArea_keyCallback (GuiObject widget, GdkEvent *gevent, gpointer void_me) { iam (GuiDrawingArea); trace (U"begin"); if (my d_keyCallback && gevent -> type == GDK_KEY_PRESS) { struct structGuiDrawingArea_KeyEvent event { me, 0 }; GdkEventKey *gkeyEvent = (GdkEventKey *) gevent; event. key = gkeyEvent -> keyval; /* * Translate with the help of /usr/include/gtk-2.0/gdk/gdkkeysyms.h */ if (event. key == GDK_KEY_Escape) event. key = 27; if (event. key == GDK_KEY_Left) event. key = 0x2190; if (event. key == GDK_KEY_Up) event. key = 0x2191; if (event. key == GDK_KEY_Right) event. key = 0x2192; if (event. key == GDK_KEY_Down) event. key = 0x2193; event. shiftKeyPressed = (gkeyEvent -> state & GDK_SHIFT_MASK) != 0; event. commandKeyPressed = (gkeyEvent -> state & GDK_CONTROL_MASK) != 0; event. optionKeyPressed = (gkeyEvent -> state & GDK_MOD1_MASK) != 0; event. extraControlKeyPressed = false; try { my d_keyCallback (my d_keyBoss, & event); } catch (MelderError) { Melder_flushError (U"Key press not completely handled."); } /* * FIXME: here we should empty the type-ahead buffer */ return true; } return false; // if the drawing area has no keyCallback, the system will send the key press to a text field. }
void * Melder_realloc_f (void *ptr, long size) { void *result; if (size <= 0) Melder_fatal ("(Melder_realloc_f:) Can never allocate %ld bytes.", size); result = realloc (ptr, size); /* Will not show in the statistics... */ if (result == NULL) { if (theRainyDayFund != NULL) free (theRainyDayFund); result = realloc (ptr, size); if (result != NULL) { Melder_flushError ("Praat is very low on memory.\nSave your work and quit Praat.\nIf you don't do that, Praat may crash."); } else { Melder_fatal ("Out of memory. Could not extend room to %ld bytes.", size); } } if (ptr == NULL) { /* Is it like malloc? */ totalNumberOfAllocations += 1; totalAllocationSize += size; } else if (result != ptr) { /* Did realloc do a malloc-and-free? */ totalNumberOfAllocations += 1; totalAllocationSize += size; totalNumberOfDeallocations += 1; totalNumberOfMovingReallocs += 1; } else { totalNumberOfReallocsInSitu += 1; } return result; }
void Pitch_difference (Pitch me, Pitch thee) { long nuvtov = 0, nvtouv = 0, ndfdown = 0, ndfup = 0; if (my nx != thy nx || my dx != thy dx || my x1 != thy x1) { Melder_flushError ("Pitch_difference: these Pitches are not aligned."); return; } for (long i = 1; i <= my nx; i ++) { double myf = my frame [i]. candidate [1]. frequency, thyf = thy frame [i]. candidate [1]. frequency; int myUnvoiced = myf == 0 || myf > my ceiling; int thyUnvoiced = thyf == 0 || thyf > thy ceiling; double t = Sampled_indexToX (me, i); if (myUnvoiced && ! thyUnvoiced) { Melder_casual ("Frame %ld time %f: unvoiced to voiced.", i, t); nuvtov ++; } else if (! myUnvoiced && thyUnvoiced) { Melder_casual ("Frame %ld time %f: voiced to unvoiced.", i, t); nvtouv ++; } else if (! myUnvoiced && ! thyUnvoiced) { if (myf > thyf) { //Melder_casual ("Frame %ld time %f: downward frequency jump from %.5g Hz to %.5g Hz.", i, t, myf, thyf); ndfdown ++; } else if (myf < thyf) { //Melder_casual ("Frame %ld time %f: upward frequency jump from %.5g Hz to %.5g Hz.", i, t, myf, thyf); ndfup ++; } } } MelderInfo_open (); MelderInfo_writeLine (L"Difference between two Pitches:"); MelderInfo_writeLine (L"Unvoiced to voiced: ", Melder_integer (nuvtov), L" frames."); MelderInfo_writeLine (L"Voiced to unvoiced: ", Melder_integer (nvtouv), L" frames."); MelderInfo_writeLine (L"Downward frequency jump: ", Melder_integer (ndfdown), L" frames."); MelderInfo_writeLine (L"Upward frequency jump: ", Melder_integer (ndfup), L" frames."); MelderInfo_close (); }
static void _GuiGtkButton_activateCallback (GuiObject widget, gpointer userData) { GuiButton me = (GuiButton) userData; struct structGuiButtonEvent event { me, false, false, false, false }; if (my d_activateCallback) { try { my d_activateCallback (my d_activateBoss, & event); } catch (MelderError) { Melder_flushError (U"Your click on button \"", Melder_peek8to32 (GTK_WIDGET (widget) -> name), U"\" was not completely handled."); } } }
static void _GuiGtkButton_activateCallback (GuiObject widget, gpointer void_me) { iam (GuiButton); struct structGuiButtonEvent event = { me, 0 }; if (my d_activateCallback != NULL) { try { my d_activateCallback (my d_activateBoss, & event); } catch (MelderError) { Melder_flushError (U"Your click on button \"", Melder_peek8to32 (GTK_WIDGET (widget) -> name), U"\" was not completely handled."); } } }
void UiOutfile::do_ (const wchar_t *defaultName) { wchar_t *outfileName = GuiFileSelect_getOutfileName (NULL, _name, defaultName); if (outfileName == NULL) return; // cancelled if (_allowExecutionHook && ! _allowExecutionHook (_allowExecutionClosure)) { Melder_flushError ("Dialog `%s' cancelled.", _name); return; } Melder_pathToFile (outfileName, & _file); structMelderFile file; MelderFile_copy (& _file, & file); // save, because okCallback could destroy me UiForm::history.write (L"\n"); UiForm::history.write (_invokingButtonTitle); if (! _okCallback (this, NULL, NULL, _invokingButtonTitle, false, _okClosure)) { Melder_error3 (L"File ", MelderFile_messageName (& file), L" not finished."); Melder_flushError (NULL); } UiForm::history.write (L" "); UiForm::history.write (outfileName); Melder_free (outfileName); }
void _GuiWinButton_handleClick (GuiObject widget) { iam_button; if (my activateCallback != NULL) { struct structGuiButtonEvent event = { widget, 0 }; try { my activateCallback (my activateBoss, & event); } catch (MelderError) { Melder_error_ ("Your click on button \"", widget -> name, "\" was not completely handled."); Melder_flushError (NULL); } } }
static void menu_cb_reopen (TextEditor me, EDITOR_ARGS_DIRECT) { if (my name [0]) { try { openDocument (me, & my file); } catch (MelderError) { Melder_flushError (); return; } } else { Melder_throw (U"Cannot reopen from disk, because the text has never been saved yet."); } }
static void menu_cb_save (TextEditor me, EDITOR_ARGS_CMD) { if (my name [0]) { try { saveDocument (me, & my file); } catch (MelderError) { Melder_flushError (); return; } } else { menu_cb_saveAs (me, cmd, nullptr, 0, nullptr, nullptr, nullptr); } }
int main (int argc, char *argv []) { try { praat_setLogo (130, 80, logo); praat_init ("Praat", argc, argv); INCLUDE_LIBRARY (praat_uvafon_init) INCLUDE_LIBRARY (praat_contrib_Ola_KNN_init) praat_run (); } catch (MelderError) { Melder_flushError ("This error message percolated all the way to the top."); // an attempt to catch Apache errors } return 0; }
void _GuiMacDrawingArea_shellResize (GuiObject widget) { iam_drawingarea; if (my resizeCallback) { struct structGuiDrawingAreaResizeEvent event = { widget, 0 }; event. width = widget -> width; event. height = widget -> height; try { my resizeCallback (my resizeBoss, & event); } catch (MelderError) { Melder_flushError ("Window resizing not completely handled."); } } }
void UiInfile::do_ () { SortedSetOfString infileNames = GuiFileSelect_getInfileNames (_parent, _name, _allowMultipleFiles); if (infileNames == NULL) { Melder_flushError (NULL); return; } for (long ifile = 1; ifile <= infileNames -> size; ifile ++) { SimpleString infileName = (structSimpleString*)infileNames -> item [ifile]; Melder_pathToFile (infileName -> string, & _file); UiForm::history.write (L"\n"); UiForm::history.write (_invokingButtonTitle); UiForm::history.write (L" "); UiForm::history.write (infileName -> string); structMelderFile file; MelderFile_copy (& _file, & file); if (! _okCallback (this, NULL, NULL, _invokingButtonTitle, false, _okClosure)) { Melder_error3 (L"File ", MelderFile_messageName (& file), L" not finished."); Melder_flushError (NULL); } } forget (infileNames); }
static void _guiGtkMenuItem_activateCallback (GuiObject widget, gpointer void_me) { iam (GuiMenuItem); if (my d_callbackBlocked) return; if (G_OBJECT_TYPE (widget) == GTK_TYPE_RADIO_MENU_ITEM && ! gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget))) return; struct structGuiMenuItemEvent event { me, false, false, false, false }; if (my d_callback) { try { my d_callback (my d_boss, & event); } catch (MelderError) { Melder_flushError (U"Your choice of menu item \"", Melder_peek8to32 (GTK_WIDGET (widget) -> name), U"\" was not completely handled."); } } }
void _GuiMacDrawingArea_update (GuiObject widget) { iam_drawingarea; if (my exposeCallback) { struct structGuiDrawingAreaExposeEvent event = { widget }; _GuiMac_clipOnParent (widget); try { my exposeCallback (my exposeBoss, & event); } catch (MelderError) { Melder_flushError ("Redrawing not completed"); } GuiMac_clipOff (); } }
static void gui_button_cb_record (Manual me, GuiButtonEvent /* event */) { ManPages manPages = (ManPages) my data; ManPage manPage = ( my path < 1 ? nullptr : manPages -> pages.at [my path] ); GuiThing_setSensitive (my recordButton, false); GuiThing_setSensitive (my playButton, false); GuiThing_setSensitive (my publishButton, false); #if motif XmUpdateDisplay (my d_windowForm -> d_xmShell); #endif if (! Melder_record (manPage == nullptr ? 1.0 : manPage -> recordingTime)) Melder_flushError (); GuiThing_setSensitive (my recordButton, true); GuiThing_setSensitive (my playButton, true); GuiThing_setSensitive (my publishButton, true); }
static void gui_button_cb_saveAndClose (TextEditor me, GuiButtonEvent /* event */) { GuiThing_hide (my dirtyCloseDialog); if (my name [0]) { try { saveDocument (me, & my file); } catch (MelderError) { Melder_flushError (); return; } closeDocument (me); } else { menu_cb_saveAs (me, Editor_getMenuCommand (me, U"File", U"Save as..."), nullptr, 0, nullptr, nullptr, nullptr); } }
static void _GuiGtkScrollBar_valueChangedCallback (GuiObject widget, gpointer void_me) { iam (GuiScrollBar); trace (U"enter: blocked ", my d_blockValueChangedCallbacks); if (my d_blockValueChangedCallbacks) { my d_blockValueChangedCallbacks = false; } else if (my d_valueChangedCallback) { struct structGuiScrollBarEvent event = { me }; try { my d_valueChangedCallback (my d_valueChangedBoss, & event); } catch (MelderError) { Melder_flushError (U"Your action in a scroll bar was not completely handled."); } } }
void _GuiWinDrawingArea_handleClick (GuiObject widget, int x, int y) { iam_drawingarea; if (my clickCallback) { struct structGuiDrawingAreaClickEvent event = { widget, 0 }; event. x = x; event. y = y; event. shiftKeyPressed = GetKeyState (VK_SHIFT) < 0; try { my clickCallback (my clickBoss, & event); } catch (MelderError) { Melder_flushError ("Mouse click not completely handled."); } } }
void _GuiWinDrawingArea_update (GuiObject widget) { iam_drawingarea; PAINTSTRUCT paintStruct; BeginPaint (widget -> window, & paintStruct); if (my exposeCallback) { struct structGuiDrawingAreaExposeEvent event = { widget }; try { my exposeCallback (my exposeBoss, & event); } catch (MelderError) { Melder_flushError ("Redrawing not completed"); } } EndPaint (widget -> window, & paintStruct); }
static void gui_button_cb_record (Manual me, GuiButtonEvent /* event */) { ManPages manPages = (ManPages) my data; ManPage manPage = ( my path < 1 ? nullptr : manPages -> pages.at [my path] ); GuiThing_setSensitive (my recordButton, false); GuiThing_setSensitive (my playButton, false); GuiThing_setSensitive (my publishButton, false); #if defined (_WIN32) GdiFlush (); #endif if (! Melder_record (manPage == nullptr ? 1.0 : manPage -> recordingTime)) Melder_flushError (); GuiThing_setSensitive (my recordButton, true); GuiThing_setSensitive (my playButton, true); GuiThing_setSensitive (my publishButton, true); }
bool _GuiWinButton_tryToHandleShortcutKey (GuiObject widget) { iam_button; if (my activateCallback != NULL) { struct structGuiButtonEvent event = { widget, 0 }; try { my activateCallback (my activateBoss, & event); } catch (MelderError) { Melder_error_ ("Your click on button \"", widget -> name, "\" was not completely handled."); Melder_flushError (NULL); } return true; } return false; }
static void gui_button_cb_saveAndNew (EditorCommand cmd, GuiButtonEvent /* event */) { TextEditor me = (TextEditor) cmd -> d_editor; GuiThing_hide (my dirtyNewDialog); if (my name [0]) { try { saveDocument (me, & my file); } catch (MelderError) { Melder_flushError (); return; } newDocument (me); } else { menu_cb_saveAs (me, cmd, nullptr, 0, nullptr, nullptr, nullptr); } }
int OrderedOfString_difference (OrderedOfString me, OrderedOfString thee, long *ndif, double *fraction) { *ndif = 0; *fraction = 1; if (my size != thy size) { Melder_flushError (U"OrderedOfString_difference: the number of items differ"); return 0; } for (long i = 1; i <= my size; i++) { if (! Data_equal ( (SimpleString) my item[i], (SimpleString) thy item[i])) { (*ndif) ++; } } *fraction = *ndif; *fraction /= my size; return 1; }
static void gui_button_cb_record (I, GuiButtonEvent event) { (void) event; iam (Manual); ManPages manPages = (ManPages) my data; ManPage manPage = (ManPage) (my path < 1 ? NULL : manPages -> pages -> item [my path]); GuiObject_setSensitive (my recordButton, false); GuiObject_setSensitive (my playButton, false); GuiObject_setSensitive (my publishButton, false); #if motif XmUpdateDisplay (my d_windowShell); #endif if (! Melder_record (manPage == NULL ? 1.0 : manPage -> recordingTime)) Melder_flushError (NULL); GuiObject_setSensitive (my recordButton, true); GuiObject_setSensitive (my playButton, true); GuiObject_setSensitive (my publishButton, true); }
static gboolean _GuiGtkDrawingArea_resizeCallback (GuiObject widget, GtkAllocation *allocation, gpointer void_me) { iam (GuiDrawingArea); if (my resizeCallback) { struct structGuiDrawingAreaResizeEvent event = { widget, 0 }; event. width = allocation -> width; event. height = allocation -> height; //g_debug("%d %d", allocation->width, allocation->height); try { my resizeCallback (my clickBoss, & event); } catch (MelderError) { Melder_flushError ("Window resizing not completely handled."); } return TRUE; } return FALSE; }