void praat_reportSystemProperties () { #define xstr(s) str(s) #define str(s) #s MelderInfo_open (); MelderInfo_writeLine (U"System properties of this edition of Praat on this computer:\n"); #ifdef _WIN32 MelderInfo_writeLine (U"_WIN32 is \"" xstr (_WIN32) "\"."); #endif #ifdef WINVER MelderInfo_writeLine (U"WINVER is \"" xstr (WINVER) "\"."); #endif #ifdef _WIN32_WINNT MelderInfo_writeLine (U"_WIN32_WINNT is \"" xstr (_WIN32_WINNT) "\"."); #endif #ifdef _WIN32_IE MelderInfo_writeLine (U"_WIN32_IE is \"" xstr (_WIN32_IE) "\"."); #endif #ifdef UNICODE MelderInfo_writeLine (U"UNICODE is \"" xstr (UNICODE) "\"."); #endif #ifdef _FILE_OFFSET_BITS MelderInfo_writeLine (U"_FILE_OFFSET_BITS is \"" xstr (_FILE_OFFSET_BITS) "\"."); #endif #ifdef macintosh MelderInfo_writeLine (U"macintosh is \"" xstr (macintosh) "\"."); #endif #ifdef linux MelderInfo_writeLine (U"linux is \"" xstr (linux) "\"."); #endif MelderInfo_close (); }
void praat_reportGraphicalProperties () { MelderInfo_open (); MelderInfo_writeLine (U"Graphical properties of this edition of Praat on this computer:\n"); double x, y, width, height; Gui_getWindowPositioningBounds (& x, & y, & width, & height); MelderInfo_writeLine (U"Window positioning area: x = ", x, U", y = ", y, U", width = ", width, U", height = ", height); #if defined (macintosh) CGDirectDisplayID screen = CGMainDisplayID (); CGSize screenSize_mm = CGDisplayScreenSize (screen); double diagonal_mm = sqrt (screenSize_mm. width * screenSize_mm. width + screenSize_mm. height * screenSize_mm. height); double diagonal_inch = diagonal_mm / 25.4; MelderInfo_writeLine (U"\nScreen size: ", screenSize_mm. width, U" x ", screenSize_mm. height, U" mm (diagonal ", Melder_fixed (diagonal_mm, 1), U" mm = ", Melder_fixed (diagonal_inch, 1), U" inch)"); size_t screenWidth_pixels = CGDisplayPixelsWide (screen); size_t screenHeight_pixels = CGDisplayPixelsHigh (screen); MelderInfo_writeLine (U"Screen \"resolution\": ", screenWidth_pixels, U" x ", screenHeight_pixels, U" pixels"); double resolution = 25.4 * screenWidth_pixels / screenSize_mm. width; MelderInfo_writeLine (U"Screen resolution: ", Melder_fixed (resolution, 1), U" pixels/inch"); #elif defined (_WIN32) /*for (int i = 0; i <= 88; i ++) MelderInfo_writeLine (U"System metric ", i, U": ", GetSystemMetrics (i));*/ #endif MelderInfo_close (); }
int Praat_tests (int itest, wchar_t *arg1, wchar_t *arg2, wchar_t *arg3, wchar_t *arg4) { long i, n = wcstol (arg1, NULL, 10); double x; (void) arg1; (void) arg2; (void) arg3; (void) arg4; Melder_clearInfo (); Melder_stopwatch (); switch (itest) { case kPraatTests_CHECK_RANDOM_1009_2009: { NUMrandomRestart (310952); for (i = 1; i <= 1009 * 2009 - 100 + 1; i ++) x = NUMrandomFraction (); MelderInfo_writeLine1 (Melder_double (x)); } break; case kPraatTests_TIME_RANDOM_FRACTION: { for (i = 1; i <= n; i ++) (void) NUMrandomFraction (); } break; case kPraatTests_TIME_SORT: { long m = wcstol (arg2, NULL, 10); long *array = NUMlvector (1, m); for (i = 1; i <= m; i ++) array [i] = NUMrandomInteger (1, 100); Melder_stopwatch (); for (i = 1; i <= n; i ++) NUMsort_l (m, array); NUMlvector_free (array, 1); } break; } MelderInfo_writeLine2 (Melder_single (Melder_stopwatch () / n * 1e9), L" nanoseconds"); MelderInfo_close (); return 1; }
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 (); }
void praat_library_createC (bool isInHeaderFile, bool includeCreateAPI, bool includeReadAPI, bool includeSaveAPI, bool includeQueryAPI, bool includeModifyAPI, bool includeToAPI, bool includeRecordAPI, bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI, bool /* includeDemoAPI */) { MelderInfo_open (); MelderInfo_writeLine (U"/* praatlib.h"); MelderInfo_writeLine (U" *"); MelderInfo_writeLine (U" * Copyright (C) 2016 Paul Boersma"); MelderInfo_writeLine (U" *"); MelderInfo_writeLine (U" * This code is free software; you can redistribute it and/or modify"); MelderInfo_writeLine (U" * it under the terms of the GNU General Public License as published by"); MelderInfo_writeLine (U" * the Free Software Foundation; either version 3 of the License, or (at"); MelderInfo_writeLine (U" * your option) any later version."); MelderInfo_writeLine (U" *"); MelderInfo_writeLine (U" * This code is distributed in the hope that it will be useful, but"); MelderInfo_writeLine (U" * WITHOUT ANY WARRANTY; without even the implied warranty of"); MelderInfo_writeLine (U" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); MelderInfo_writeLine (U" * See the GNU General Public License for more details."); MelderInfo_writeLine (U" *"); MelderInfo_writeLine (U" * You should have received a copy of the GNU General Public License"); MelderInfo_writeLine (U" * along with this work. If not, see <http://www.gnu.org/licenses/>."); MelderInfo_writeLine (U" */"); praat_menuCommands_writeC (true, includeCreateAPI, includeReadAPI, includeRecordAPI, includePlayAPI, includeDrawAPI, includeHelpAPI, includeWindowAPI); //praat_actions_writeAsCHeader (includeSaveAPI, // includeQueryAPI, includeModifyAPI, includeToAPI, // includePlayAPI, includeDrawAPI, includeHelpAPI, includeWindowAPI); MelderInfo_close (); }
void Thing_infoWithId (I, unsigned long id) { iam (Thing); Melder_clearInfo (); MelderInfo_open (); if (id != 0) MelderInfo_writeLine2 (L"Object id: ", Melder_integer (id)); our info (me); /* This calls a set of MelderInfo_writeXXX. */ MelderInfo_close (); }
void Thing_infoWithIdAndFile (Thing me, unsigned long id, MelderFile file) { //Melder_assert (me); Melder_clearInfo (); MelderInfo_open (); if (id != 0) MelderInfo_writeLine (U"Object id: ", id); if (! MelderFile_isNull (file)) MelderInfo_writeLine (U"Associated file: ", Melder_fileToPath (file)); my v_info (); MelderInfo_close (); }
long Thing_listReadableClasses () { Melder_clearInfo (); MelderInfo_open (); for (long iclass = 1; iclass <= theNumberOfReadableClasses; iclass ++) { ClassInfo klas = theReadableClasses [iclass]; MelderInfo_writeLine (klas -> sequentialUniqueIdOfReadableClass, U"\t", klas -> className); } MelderInfo_close (); return theNumberOfReadableClasses; }
void praat_reportTextProperties () { MelderInfo_open (); MelderInfo_writeLine (U"Text properties of this edition of Praat on this computer:\n"); MelderInfo_writeLine (U"Locale: ", Melder_peek8to32 (setlocale (LC_ALL, nullptr))); MelderInfo_writeLine (U"A \"char\" is ", 8, U" bits."); MelderInfo_writeLine (U"A \"char16_t\" is ", sizeof (char16_t) * 8, U" bits."); MelderInfo_writeLine (U"A \"wchar_t\" is ", sizeof (wchar_t) * 8, U" bits."); MelderInfo_writeLine (U"A \"char32_t\" is ", sizeof (char32_t) * 8, U" bits."); MelderInfo_close (); }
long Thing_listReadableClasses (void) { Melder_clearInfo (); MelderInfo_open (); for (long iclass = 1; iclass <= numberOfReadableClasses; iclass ++) { Thing_Table klas = (structThing_Table*)readableClasses [iclass]; MelderInfo_writeLine3 (Melder_integer (klas -> sequentialUniqueIdOfReadableClass), L"\t", klas -> _className); } MelderInfo_close (); return numberOfReadableClasses; }
void praat_reportIntegerProperties () { MelderInfo_open (); MelderInfo_writeLine (U"Integer properties of this edition of Praat on this computer:\n"); MelderInfo_writeLine (U"A \"short integer\" is ", sizeof (short) * 8, U" bits."); MelderInfo_writeLine (U"An \"integer\" is ", sizeof (int) * 8, U" bits."); MelderInfo_writeLine (U"A \"long integer\" is ", sizeof (long) * 8, U" bits."); MelderInfo_writeLine (U"A \"long long integer\" is ", sizeof (long long) * 8, U" bits."); MelderInfo_writeLine (U"A pointer is ", sizeof (void *) * 8, U" bits."); MelderInfo_writeLine (U"A memory object size is ", sizeof (size_t) * 8, U" bits."); MelderInfo_writeLine (U"A file offset is ", sizeof (off_t) * 8, U" bits."); MelderInfo_close (); }
static HENHMETAFILE copyToMetafile (Picture me) { RECT rect; HDC dc; PRINTDLG defaultPrinter; int resolution; memset (& defaultPrinter, 0, sizeof (PRINTDLG)); defaultPrinter. lStructSize = sizeof (PRINTDLG); defaultPrinter. Flags = PD_RETURNDEFAULT | PD_RETURNDC; PrintDlg (& defaultPrinter); SetRect (& rect, my selx1 * 2540, (12 - my sely2) * 2540, my selx2 * 2540, (12 - my sely1) * 2540); dc = CreateEnhMetaFile (defaultPrinter. hDC, nullptr, & rect, L"Praat\0"); if (! dc) Melder_throw (U"Cannot create Windows metafile."); resolution = GetDeviceCaps (dc, LOGPIXELSX); // Virtual PC: 360; Parallels Desktop: 600 //Melder_fatal (U"resolution ", resolution); if (Melder_debug == 6) { DEVMODE *devMode = * (DEVMODE **) defaultPrinter. hDevMode; MelderInfo_open (); MelderInfo_writeLine (U"DEVICE CAPS:"); MelderInfo_writeLine (U"aspect x ", GetDeviceCaps (dc, ASPECTX), U" y ", GetDeviceCaps (dc, ASPECTY)); MelderInfo_writeLine (U"res(pixels) hor ", GetDeviceCaps (dc, HORZRES), U" vert ", GetDeviceCaps (dc, VERTRES)); MelderInfo_writeLine (U"size(mm) hor ", GetDeviceCaps (dc, HORZSIZE), U" vert ", GetDeviceCaps (dc, VERTSIZE)); MelderInfo_writeLine (U"pixels/inch hor ", GetDeviceCaps (dc, LOGPIXELSX), U" vert ", GetDeviceCaps (dc, LOGPIXELSY)); MelderInfo_writeLine (U"physicalOffset(pixels) hor ", GetDeviceCaps (dc, PHYSICALOFFSETX), U" vert ", GetDeviceCaps (dc, PHYSICALOFFSETY)); MelderInfo_writeLine (U"PRINTER:"); MelderInfo_writeLine (U"dmFields ", devMode -> dmFields); if (devMode -> dmFields & DM_YRESOLUTION) MelderInfo_writeLine (U"y resolution ", devMode -> dmYResolution); if (devMode -> dmFields & DM_PRINTQUALITY) MelderInfo_writeLine (U"print quality ", devMode -> dmPrintQuality); if (devMode -> dmFields & DM_PAPERWIDTH) MelderInfo_writeLine (U"paper width ", devMode -> dmPaperWidth); if (devMode -> dmFields & DM_PAPERLENGTH) MelderInfo_writeLine (U"paper length ", devMode -> dmPaperLength); if (devMode -> dmFields & DM_PAPERSIZE) MelderInfo_writeLine (U"paper size ", devMode -> dmPaperSize); if (devMode -> dmFields & DM_ORIENTATION) MelderInfo_writeLine (U"orientation ", devMode -> dmOrientation); MelderInfo_close (); } autoGraphics pictGraphics = Graphics_create_screen ((void *) dc, nullptr, resolution); Graphics_setWsViewport (pictGraphics.peek(), 0, WIN_WIDTH * resolution, 0, WIN_HEIGHT * resolution); Graphics_setWsWindow (pictGraphics.peek(), 0.0, WIN_WIDTH, 12.0 - WIN_HEIGHT, 12.0); Graphics_play (my graphics.get(), pictGraphics.peek()); HENHMETAFILE metafile = CloseEnhMetaFile (dc); return metafile; }
void praat_reportMemoryUse () { MelderInfo_open (); MelderInfo_writeLine (U"Memory use by Praat:\n"); MelderInfo_writeLine (U"Currently in use:\n" U" Strings: ", MelderString_allocationCount () - MelderString_deallocationCount ()); MelderInfo_writeLine (U" Arrays: ", NUM_getTotalNumberOfArrays ()); MelderInfo_writeLine (U" Things: ", Thing_getTotalNumberOfThings (), U" (objects in list: ", theCurrentPraatObjects -> n, U")"); long numberOfMotifWidgets = #if motif Gui_getNumberOfMotifWidgets (); MelderInfo_writeLine (U" Motif widgets: ", numberOfMotifWidgets); #else 0; #endif MelderInfo_writeLine (U" Other: ", Melder_allocationCount () - Melder_deallocationCount () - Thing_getTotalNumberOfThings () - NUM_getTotalNumberOfArrays () - (MelderString_allocationCount () - MelderString_deallocationCount ()) - numberOfMotifWidgets); MelderInfo_writeLine ( U"\nMemory history of this session:\n" U" Total created: ", Melder_bigInteger (Melder_allocationCount ()), U" (", Melder_bigInteger (Melder_allocationSize ()), U" bytes)"); MelderInfo_writeLine (U" Total deleted: ", Melder_bigInteger (Melder_deallocationCount ())); MelderInfo_writeLine (U" Reallocations: ", Melder_bigInteger (Melder_movingReallocationsCount ()), U" moving, ", Melder_bigInteger (Melder_reallocationsInSituCount ()), U" in situ"); MelderInfo_writeLine ( U" Strings created: ", Melder_bigInteger (MelderString_allocationCount ()), U" (", Melder_bigInteger (MelderString_allocationSize ()), U" bytes)"); MelderInfo_writeLine ( U" Strings deleted: ", Melder_bigInteger (MelderString_deallocationCount ()), U" (", Melder_bigInteger (MelderString_deallocationSize ()), U" bytes)"); MelderInfo_writeLine (U"\nHistory of all sessions from ", statistics.dateOfFirstSession, U" until today:"); MelderInfo_writeLine (U" Sessions: ", statistics.interactiveSessions, U" interactive, ", statistics.batchSessions, U" batch"); MelderInfo_writeLine (U" Total memory use: ", Melder_bigInteger ((int64) statistics.memory + Melder_allocationSize ()), U" bytes"); MelderInfo_writeLine (U"\nNumber of fixed menu commands: ", praat_getNumberOfMenuCommands ()); MelderInfo_writeLine (U"Number of dynamic menu commands: ", praat_getNumberOfActions ()); MelderInfo_close (); }
int Praat_tests (int itest, char32 *arg1, char32 *arg2, char32 *arg3, char32 *arg4) { int64 n = Melder_atoi (arg1); double t = 0.0; (void) arg1; (void) arg2; (void) arg3; (void) arg4; Melder_clearInfo (); Melder_stopwatch (); switch (itest) { case kPraatTests_TIME_RANDOM_FRACTION: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomFraction (); t = Melder_stopwatch (); } break; case kPraatTests_TIME_RANDOM_GAUSS: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomGauss (0.0, 1.0); t = Melder_stopwatch (); } break; case kPraatTests_TIME_SORT: { long m = Melder_atoi (arg2); long *array = NUMvector <long> (1, m); for (int64 i = 1; i <= m; i ++) array [i] = NUMrandomInteger (1, 100); Melder_stopwatch (); for (int64 i = 1; i <= n; i ++) NUMsort_l (m, array); t = Melder_stopwatch (); NUMvector_free (array, 1); } break; case kPraatTests_TIME_INTEGER: { int64 sum = 0; for (int64 i = 1; i <= n; i ++) sum += i * (i - 1) * (i - 2); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT: { double sum = 0.0, fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += fi * (fi - 1.0) * (fi - 2.0); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_BUILTIN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32) fi; t = Melder_stopwatch (); // 2.59 // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_EXTERN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32) ((int32) (fi - 2147483648.0) + 2147483647L + 1); t = Melder_stopwatch (); // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_BUILTIN: { double sum = 0.0; uint32 nu = (uint32) n; for (uint32 iu = 1; iu <= nu; iu ++) sum += (double) iu; t = Melder_stopwatch (); // 1.35 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_EXTERN: { double sum = 0.0; uint32 nu = (uint32) n; for (uint32 iu = 1; iu <= nu; iu ++) sum += (double) (int32) (iu - 2147483647L - 1) + 2147483648.0; t = Melder_stopwatch (); // 0.96 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_STRING_MELDER_32: { autoMelderString string; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { MelderString_copy (& string, word); for (int j = 1; j <= 30; j ++) MelderString_append (& string, word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_MELDER_32_ALLOC: { char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { autoMelderString string; MelderString_copy (& string, word); for (int j = 1; j <= 30; j ++) MelderString_append (& string, word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_S: { std::string s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_C: { std::basic_string<char> s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WS: { std::wstring s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WC: { std::basic_string<wchar_t> s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_32: { std::basic_string<char32_t> s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_U32STRING: { std::u32string s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRCPY: { char buffer [100]; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { strcpy (buffer, word); for (int j = 1; j <= 30; j ++) strcpy (buffer + strlen (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (Melder_peek8to32 (buffer)); } break; case kPraatTests_TIME_WCSCPY: { wchar_t buffer [100]; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { wcscpy (buffer, word); for (int j = 1; j <= 30; j ++) wcscpy (buffer + wcslen (buffer), word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STR32CPY: { char32 buffer [100]; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { str32cpy (buffer, word); for (int j = 1; j <= 30; j ++) str32cpy (buffer + str32len (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (buffer); } break; case kPraatTests_TIME_GRAPHICS_TEXT_TOP: { autoPraatPicture picture; for (int64 i = 1; i <= n; i ++) { Graphics_textTop (GRAPHICS, false, U"hello world"); } t = Melder_stopwatch (); } break; case kPraatTests_THING_AUTO: { int numberOfThingsBefore = theTotalNumberOfThings; { Melder_casual (U"1\n"); autoDaata data = Thing_new (Daata); Thing_setName (data.get(), U"hello"); Melder_casual (U"2\n"); testData (data.get()); testAutoData (data.move()); autoDaata data18 = Thing_new (Daata); testAutoData (data18.move()); fprintf (stderr, "3\n"); autoDaata data2 = newAutoData (); fprintf (stderr, "4\n"); autoDaata data3 = newAutoData (); fprintf (stderr, "5\n"); //data2 = data; // disabled l-value copy assignment from same class fprintf (stderr, "6\n"); autoOrdered ordered = Thing_new (Ordered); fprintf (stderr, "7\n"); //data = ordered; // disabled l-value copy assignment from subclass data = ordered.move(); //ordered = data; // disabled l-value copy assignment from superclass //ordered = data.move(); // assignment from superclass to subclass is rightfully refused by compiler fprintf (stderr, "8\n"); data2 = newAutoData (); fprintf (stderr, "8a\n"); autoDaata data5 = newAutoData (); fprintf (stderr, "8b\n"); data2 = data5.move(); fprintf (stderr, "9\n"); //ordered = data; // rightfully refused by compiler fprintf (stderr, "10\n"); //autoOrdered ordered2 = Thing_new (Daata); // rightfully refused by compiler fprintf (stderr, "11\n"); autoDaata data4 = Thing_new (Ordered); // constructor fprintf (stderr, "12\n"); //autoDaata data6 = data4; // disabled l-value copy constructor from same class fprintf (stderr, "13\n"); autoDaata data7 = data4.move(); fprintf (stderr, "14\n"); autoOrdered ordered3 = Thing_new (Ordered); autoDaata data8 = ordered3.move(); fprintf (stderr, "15\n"); //autoDaata data9 = ordered; // disabled l-value copy constructor from subclass fprintf (stderr, "16\n"); autoDaata data10 = data7.move(); fprintf (stderr, "17\n"); autoDaata data11 = Thing_new (Daata); // constructor, move assignment, null destructor fprintf (stderr, "18\n"); data11 = Thing_new (Ordered); fprintf (stderr, "19\n"); testAutoDataRef (data11); fprintf (stderr, "20\n"); //data11 = nullptr; // disabled implicit assignment of pointer to autopointer fprintf (stderr, "21\n"); } int numberOfThingsAfter = theTotalNumberOfThings; fprintf (stderr, "Number of things: before %d, after %d\n", numberOfThingsBefore, numberOfThingsAfter); #if 1 MelderCallback<void,structDaata>::FunctionType f; typedef void (*DataFunc) (Daata); typedef void (*OrderedFunc) (Ordered); DataFunc dataFun; OrderedFunc orderedFun; MelderCallback<void,structDaata> dataFun2 (dataFun); MelderCallback<void,structOrdered> orderedFun2 (orderedFun); MelderCallback<void,structDaata> dataFun3 (orderedFun); //MelderCallback<void,structOrdered> orderedFun3 (dataFun); // rightfully refused by compiler autoDaata data = Thing_new (Daata); dataFun3 (data.get()); #endif } break; } MelderInfo_writeLine (Melder_single (t / n * 1e9), U" nanoseconds"); MelderInfo_close (); return 1; }
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]; } }
int Praat_tests (int itest, char32 *arg1, char32 *arg2, char32 *arg3, char32 *arg4) { int64 n = Melder_atoi (arg1); double t; (void) arg1; (void) arg2; (void) arg3; (void) arg4; Melder_clearInfo (); Melder_stopwatch (); switch (itest) { case kPraatTests_TIME_RANDOM_FRACTION: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomFraction (); t = Melder_stopwatch (); } break; case kPraatTests_TIME_RANDOM_GAUSS: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomGauss (0.0, 1.0); t = Melder_stopwatch (); } break; case kPraatTests_TIME_SORT: { long m = Melder_atoi (arg2); long *array = NUMvector <long> (1, m); for (int64 i = 1; i <= m; i ++) array [i] = NUMrandomInteger (1, 100); Melder_stopwatch (); for (int64 i = 1; i <= n; i ++) NUMsort_l (m, array); t = Melder_stopwatch (); NUMvector_free (array, 1); } break; case kPraatTests_TIME_INTEGER: { double sum = 0; for (int64 i = 1; i <= n; i ++) sum += i * (i - 1) * (i - 2); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT: { double sum = 0.0, fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += fi * (fi - 1.0) * (fi - 2.0); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_BUILTIN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32_t) fi; t = Melder_stopwatch (); // 2.59 // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_EXTERN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32_t) ((int32_t) (fi - 2147483648.0) + 2147483647L + 1); t = Melder_stopwatch (); // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_BUILTIN: { double sum = 0.0; uint32_t nu = (uint32_t) n; for (uint32_t iu = 1; iu <= nu; iu ++) sum += (double) iu; t = Melder_stopwatch (); // 1.35 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_EXTERN: { double sum = 0.0; uint32_t nu = (uint32_t) n; for (uint32_t iu = 1; iu <= nu; iu ++) sum += (double) (int32_t) (iu - 2147483647L - 1) + 2147483648.0; t = Melder_stopwatch (); // 0.96 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_STRING_MELDER_32: { autoMelderString string; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { MelderString_copy (& string, word); for (int j = 1; j <= 30; j ++) MelderString_append (& string, word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_S: { std::string s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_C: { std::basic_string<char> s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WS: { std::wstring s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WC: { std::basic_string<wchar_t> s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_32: { std::basic_string<char32_t> s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_U32STRING: { #if ! defined (macintosh) || ! useCarbon std::u32string s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } #endif t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRCPY: { char buffer [100]; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { strcpy (buffer, word); for (int j = 1; j <= 30; j ++) strcpy (buffer + strlen (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (Melder_peek8to32 (buffer)); } break; case kPraatTests_TIME_WCSCPY: { wchar_t buffer [100]; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { wcscpy (buffer, word); for (int j = 1; j <= 30; j ++) wcscpy (buffer + wcslen (buffer), word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STR32CPY: { char32 buffer [100]; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { str32cpy (buffer, word); for (int j = 1; j <= 30; j ++) str32cpy (buffer + str32len (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (buffer); } break; case kPraatTests_TIME_GRAPHICS_TEXT_TOP: { autoPraatPicture picture; for (int64 i = 1; i <= n; i ++) { Graphics_textTop (GRAPHICS, false, U"hello world"); } t = Melder_stopwatch (); } break; } MelderInfo_writeLine (Melder_single (t / n * 1e9), U" nanoseconds"); MelderInfo_close (); return 1; }
int Printer_print (void (*draw) (void *boss, Graphics g), void *boss) { #if defined (UNIX) structMelderFile tempFile = { 0 }; char tempPath_utf8 [] = "/tmp/picXXXXXX"; close (mkstemp (tempPath_utf8)); Melder_pathToFile (Melder_peekUtf8ToWcs (tempPath_utf8), & tempFile); thePrinter. graphics = Graphics_create_postscriptjob (& tempFile, thePrinter. resolution, thePrinter. spots, thePrinter. paperSize, thePrinter. orientation, thePrinter. magnification); if (! thePrinter. graphics) return Melder_error1 (L"Cannot create temporary PostScript file for printing."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); char command [500]; sprintf (command, Melder_peekWcsToUtf8 (Site_getPrintCommand ()), tempPath_utf8); system (command); MelderFile_delete (& tempFile); #elif defined (_WIN32) int postScriptCode = POSTSCRIPT_PASSTHROUGH; DOCINFO docInfo; DEVMODE *devMode; initPrinter (); if (! theWinPrint. hDevMode) { memset (& theWinPrint, 0, sizeof (PRINTDLG)); theWinPrint. lStructSize = sizeof (PRINTDLG); theWinPrint. Flags = PD_RETURNDEFAULT; if (! PrintDlg (& theWinPrint)) return Melder_error1 (L"Cannot initialize printer."); } if (Melder_backgrounding) { theWinPrint. Flags = PD_RETURNDEFAULT | PD_RETURNDC; if (! PrintDlg (& theWinPrint) || theWinPrint. hDC == NULL) { return Melder_error1 (L"Cannot print from a script on this computer."); } } else { theWinPrint. Flags &= ~ PD_RETURNDEFAULT; theWinPrint. Flags |= PD_RETURNDC; if (! PrintDlg (& theWinPrint)) return 1; } theWinDC = theWinPrint. hDC; thePrinter. postScript = thePrinter. allowDirectPostScript && Escape (theWinDC, QUERYESCSUPPORT, sizeof (int), (LPSTR) & postScriptCode, NULL); /* * The HP colour inkjet printer returns in dmFields: * 0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 23, 24, 25, 26 = DM_ORIENTATION | * DM_PAPERSIZE | DM_COPIES | DM_DEFAULTSOURCE | DM_PRINTQUALITY | * DM_COLOR | DM_DUPLEX | DM_YRESOLUTION | DM_TTOPTION | DM_COLLATE | * DM_ICMMETHOD | DM_ICMINTENT | DM_MEDIATYPE | DM_DITHERTYPE */ devMode = * (DEVMODE **) theWinPrint. hDevMode; thePrinter. resolution = devMode -> dmFields & DM_YRESOLUTION ? devMode -> dmYResolution : devMode -> dmFields & DM_PRINTQUALITY ? ( devMode -> dmPrintQuality > 0 ? devMode -> dmPrintQuality : 300 ) : 300; if (devMode -> dmFields & DM_PAPERWIDTH) { thePrinter. paperWidth = devMode -> dmPaperWidth * thePrinter. resolution / 254; thePrinter. paperHeight = devMode -> dmPaperLength * thePrinter. resolution / 254; } else if (devMode -> dmFields & DM_PAPERSIZE) { static struct { float width, height; } sizes [] = { { 0, 0 }, { 8.5, 11 }, { 8.5, 11 }, { 11, 17 }, { 17, 11 }, { 8.5, 14 }, { 5.5, 8.5 }, { 7.25, 10.5 }, { 297/25.4, 420/25.4 }, { 210/25.4, 297/25.4 }, { 210/25.4, 297/25.4 }, { 148.5/25.4, 210/25.4 }, { 250/25.4, 354/25.4 }, { 182/25.4, 257/25.4 }, { 8.5, 13 }, { 215/25.4, 275/25.4 }, { 10, 14 }, { 11, 17 }, { 8.5, 11 }, { 3.875, 8.875 }, { 4.125, 9.5 }, { 4.5, 10.375 } }; int paperSize = devMode -> dmPaperSize; if (paperSize <= 0 || paperSize > 21) paperSize = 1; thePrinter. paperWidth = sizes [paperSize]. width * thePrinter. resolution; thePrinter. paperHeight = sizes [paperSize]. height * thePrinter. resolution; if (devMode -> dmOrientation == DMORIENT_LANDSCAPE) { long dummy = thePrinter. paperWidth; thePrinter. paperWidth = thePrinter. paperHeight; thePrinter. paperHeight = dummy; } } else { thePrinter. paperWidth = 1000; thePrinter. paperHeight = 1000; } EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), FALSE); SetAbortProc (theWinDC, AbortFunc); memset (& docInfo, 0, sizeof (DOCINFO)); docInfo. cbSize = sizeof (DOCINFO); docInfo. lpszDocName = L"Praatjes"; docInfo. lpszOutput = NULL; if (thePrinter. postScript) { StartDoc (theWinDC, & docInfo); StartPage (theWinDC); initPostScriptPage (); thePrinter. graphics = Graphics_create_postscriptprinter (); if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); exitPostScriptPage (); EndPage (theWinDC); EndDoc (theWinDC); } else { StartDoc (theWinDC, & docInfo); StartPage (theWinDC); thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theWinDC); if (! thePrinter. graphics) return Melder_error1 (L"Cannot open printer."); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); if (EndPage (theWinDC) < 0) { Melder_error1 (L"Cannot print page."); } else { EndDoc (theWinDC); } } EnableWindow ((HWND) XtWindow (theCurrentPraatApplication -> topShell), TRUE); DeleteDC (theWinDC), theWinDC = NULL; #elif defined (macintosh) Boolean result; initPrinter (); if (Melder_backgrounding) { PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result); PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result); } else { Boolean accepted; PMSessionPrintDialog (theMacPrintSession, theMacPrintSettings, theMacPageFormat, & accepted); if (! accepted) return 1; /* Normal cancelled return. */ } PMSessionValidatePageFormat (theMacPrintSession, theMacPageFormat, & result); PMSessionValidatePrintSettings (theMacPrintSession, theMacPrintSettings, & result); PMResolution res; PMGetResolution (theMacPageFormat, & res); thePrinter. resolution = res. hRes; PMGetAdjustedPaperRect (theMacPageFormat, & paperSize); thePrinter. paperWidth = paperSize. right - paperSize. left; thePrinter. paperHeight = paperSize. bottom - paperSize. top; Boolean isPostScriptDriver = FALSE; //PMSessionIsDocumentFormatSupported (theMacPrintSession, // kPMDocumentFormatPICTPS, & isPostScriptDriver); CFArrayRef supportedFormats; PMSessionGetDocumentFormatGeneration (theMacPrintSession, & supportedFormats); CFIndex numberOfSupportedFormats = CFArrayGetCount (supportedFormats); if (Melder_debug == 21) { MelderInfo_open (); MelderInfo_writeLine1 (L"Supported document formats:"); } for (CFIndex i = 0; i < numberOfSupportedFormats; i ++) { CFStringRef supportedFormat = CFArrayGetValueAtIndex (supportedFormats, i); if (CFStringCompare (supportedFormat, kPMDocumentFormatPICTPS, 0) == 0) { isPostScriptDriver = TRUE; } if (Melder_debug == 21) { MelderInfo_writeLine3 (Melder_integer (i), L": ", Melder_peekUtf8ToWcs (CFStringGetCStringPtr (supportedFormat, kCFStringEncodingUTF8))); } } if (Melder_debug == 21) { MelderInfo_close (); } CFRelease (supportedFormats); isPostScriptDriver = FALSE; // OVERRIDE, because from 10.4 on we have something better: we'll be sending PDF thePrinter. postScript = thePrinter. allowDirectPostScript && isPostScriptDriver; if (thePrinter. postScript) { CFStringRef strings [1]; strings [0] = kPMGraphicsContextQuickdraw; CFArrayRef array = CFArrayCreate (kCFAllocatorDefault, (const void **) strings, 1, & kCFTypeArrayCallBacks); OSStatus err = PMSessionSetDocumentFormatGeneration (theMacPrintSession, kPMDocumentFormatPICTPS, array, NULL); CFRelease (array); if (err != 0) { return Melder_error2 (L"PMSessionSetDocumentFormatGeneration: error ", Melder_integer (err)); } } PMOrientation orientation; PMGetOrientation (theMacPageFormat, & orientation); thePrinter. orientation = orientation == kPMLandscape || orientation == kPMReverseLandscape ? kGraphicsPostscript_orientation_LANDSCAPE : kGraphicsPostscript_orientation_PORTRAIT; PMSessionBeginDocument (theMacPrintSession, theMacPrintSettings, theMacPageFormat); PMSessionBeginPage (theMacPrintSession, theMacPageFormat, NULL); PMSessionGetGraphicsContext (theMacPrintSession, kPMGraphicsContextQuickdraw, (void **) & theMacPort); /* * On PostScript, the point (0, 0) is the bottom left corner of the paper, which is fine. * On the screen, however, the point (0, 0) is the top left corner of the writable page. * Since we want paper-related margins, not writable-page-related margins, * we require that this point gets the coordinates (250, 258) or so, * so that the top left corner of the paper gets coordinates (0, 0). * The "left" and "top" attributes of rPaper are negative values (e.g. -250 and -258), * so multiply them by -1. * * Under Carbon, the port has to be set inside the page. */ SetPort (theMacPort); if (! thePrinter. postScript) SetOrigin (- paperSize. left, - paperSize. top); if (thePrinter. postScript) { if (! openPostScript ()) error1 (L"Cannot print PostScript.") thePrinter. graphics = Graphics_create_postscriptprinter (); if (! thePrinter. graphics) goto end; draw (boss, thePrinter. graphics); forget (thePrinter. graphics); closePostScript (); } else { thePrinter. graphics = Graphics_create_screenPrinter (NULL, (unsigned long) theMacPort); draw (boss, thePrinter. graphics); forget (thePrinter. graphics); } end: if (theMacPort) { PMSessionEndPage (theMacPrintSession); PMSessionEndDocument (theMacPrintSession); theMacPort = NULL; } #endif iferror return 0; return 1; }