void structTube :: v_info () { structData :: v_info (); MelderInfo_writeLine5 (L"Time domain: ", Melder_double (xmin), L" to ", Melder_double (xmax), L" seconds"); MelderInfo_writeLine2 (L"Maximum number of segments: ", Melder_integer (maxnSegments)); MelderInfo_writeLine2 (L"Number of frames: ", Melder_integer (nx)); MelderInfo_writeLine3 (L"Time step: ", Melder_double (dx), L" seconds"); MelderInfo_writeLine3 (L"First frame at: ", Melder_double (x1), L" seconds"); }
void structSpectrumTier :: v_info () { structData :: v_info (); MelderInfo_writeLine1 (L"Frequency domain:"); MelderInfo_writeLine3 (L" Lowest frequency: ", Melder_double (xmin), L" Hz"); MelderInfo_writeLine3 (L" Highest frequency: ", Melder_double (xmax), L" Hz"); MelderInfo_writeLine3 (L" Total bandwidth: ", Melder_double (xmax - xmin), L" Hz"); MelderInfo_writeLine2 (L"Number of points: ", Melder_integer (points -> size)); MelderInfo_writeLine3 (L"Minimum power value: ", Melder_double (RealTier_getMinimumValue (this)), L" dB/Hz"); MelderInfo_writeLine3 (L"Maximum power value: ", Melder_double (RealTier_getMaximumValue (this)), L" dB/Hz"); }
void structCC :: v_info () { structData :: v_info (); MelderInfo_writeLine5 (L"Time domain:", Melder_double (xmin), L" to ", Melder_double (xmax), L" seconds"); MelderInfo_writeLine2 (L"Number of frames: ", Melder_integer (nx)); MelderInfo_writeLine3 (L"Time step: ", Melder_double (dx), L" seconds"); MelderInfo_writeLine3 (L"First frame at: ", Melder_double (x1), L" seconds"); MelderInfo_writeLine2 (L"Number of coefficients: ", Melder_integer (maximumNumberOfCoefficients)); MelderInfo_writeLine3 (L"Minimum frequency: ", Melder_double (fmin), L" Hz"); MelderInfo_writeLine3 (L"Maximum frequency: ", Melder_double (fmax), L" Hz"); }
void structPitchTier :: v_info () { structData :: v_info (); MelderInfo_writeLine1 (L"Time domain:"); MelderInfo_writeLine3 (L" Start time: ", Melder_double (xmin), L" seconds"); MelderInfo_writeLine3 (L" End time: ", Melder_double (xmax), L" seconds"); MelderInfo_writeLine3 (L" Total duration: ", Melder_double (xmax - xmin), L" seconds"); MelderInfo_writeLine2 (L"Number of points: ", Melder_integer (points -> size)); MelderInfo_writeLine3 (L"Minimum pitch value: ", Melder_double (RealTier_getMinimumValue (this)), L" Hz"); MelderInfo_writeLine3 (L"Maximum pitch value: ", Melder_double (RealTier_getMaximumValue (this)), L" Hz"); }
void structFormant :: v_info () { structData :: v_info (); MelderInfo_writeLine1 (L"Time domain:"); MelderInfo_writeLine3 (L" Start time: ", Melder_double (xmin), L" seconds"); MelderInfo_writeLine3 (L" End time: ", Melder_double (xmax), L" seconds"); MelderInfo_writeLine3 (L" Total duration: ", Melder_double (xmax - xmin), L" seconds"); MelderInfo_writeLine1 (L"Time sampling:"); MelderInfo_writeLine2 (L" Number of frames: ", Melder_integer (nx)); MelderInfo_writeLine3 (L" Time step: ", Melder_double (dx), L" seconds"); MelderInfo_writeLine3 (L" First frame centred at: ", Melder_double (x1), L" seconds"); }
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 FilesInMemory_showAsCode (FilesInMemory me, const wchar_t *name, long numberOfBytesPerLine) { autoMelderString one_fim; autoMelderString all_fims; MelderInfo_writeLine1 (L"#include \"Collection.h\""); MelderInfo_writeLine1 (L"#include \"FileInMemory.h\""); MelderInfo_writeLine1 (L"#include \"melder.h\"\n"); MelderInfo_writeLine3 (L"FilesInMemory create_", name, L" () {"); MelderInfo_writeLine1 (L"\ttry {"); MelderInfo_writeLine1 (L"\t\tautoFilesInMemory me = FilesInMemory_create ();"); for (long ifile = 1; ifile <= my size; ifile++) { FileInMemory fim = (FileInMemory) my item[ifile]; MelderString_append (&one_fim, name, Melder_integer (ifile)); FileInMemory_showAsCode (fim, one_fim.string, numberOfBytesPerLine); MelderInfo_writeLine3 (L"\t\tCollection_addItem (me.peek(), ", one_fim.string, L".transfer());\n"); MelderString_empty (&one_fim); } MelderInfo_writeLine1 (L"\t\treturn me.transfer();"); MelderInfo_writeLine1 (L"\t} catch (MelderError) {"); MelderInfo_writeLine1 (L"\t\tMelder_throw (L\"FilesInMemory not created.\");"); MelderInfo_writeLine1 (L"\t}"); MelderInfo_writeLine1 (L"}\n\n"); }
void FilesInMemory_showOneFileAsCode (FilesInMemory me, long index, const wchar_t *name, long numberOfBytesPerLine) { if (index < 1 || index > my size) return; MelderInfo_writeLine1 (L"#include \"FileInMemory.h\""); MelderInfo_writeLine1 (L"#include \"melder.h\"\n"); MelderInfo_writeLine1 (L"static FileInMemory create_new_object () {"); MelderInfo_writeLine1 (L"\ttry {"); autoMelderString one_fim; FileInMemory fim = (FileInMemory) my item[index]; MelderString_append (&one_fim, name, Melder_integer (index)); FileInMemory_showAsCode (fim, L"me", numberOfBytesPerLine); MelderInfo_writeLine1 (L"\t\treturn me.transfer();"); MelderInfo_writeLine1 (L"\t} catch (MelderError) {"); MelderInfo_writeLine1 (L"\t\tMelder_throw (L\"FileInMemory not created.\");"); MelderInfo_writeLine1 (L"\t}"); MelderInfo_writeLine1 (L"}\n\n"); MelderInfo_writeLine3 (L"FileInMemory ", name, L" = create_new_object ();"); }
void structLtas :: v_info () { double meanPowerDensity; structData :: v_info (); MelderInfo_writeLine1 (L"Frequency domain:"); MelderInfo_writeLine3 (L" Lowest frequency: ", Melder_double (xmin), L" Hz"); MelderInfo_writeLine3 (L" Highest frequency: ", Melder_double (xmax), L" Hz"); MelderInfo_writeLine3 (L" Total frequency domain: ", Melder_double (xmax - xmin), L" Hz"); MelderInfo_writeLine1 (L"Frequency sampling:"); MelderInfo_writeLine2 (L" Number of frequency bands: ", Melder_integer (nx)); MelderInfo_writeLine3 (L" Width of each band: ", Melder_double (dx), L" Hz"); MelderInfo_writeLine3 (L" First band centred at: ", Melder_double (x1), L" Hz"); meanPowerDensity = Sampled_getMean (this, xmin, xmax, 0, 1, FALSE); MelderInfo_writeLine3 (L"Total SPL: ", Melder_single (10.0 * log10 (meanPowerDensity * (xmax - xmin))), L" dB"); }
static void info (I) { iam (Ltas); double meanPowerDensity; classData -> info (me); MelderInfo_writeLine1 (L"Frequency domain:"); MelderInfo_writeLine3 (L" Lowest frequency: ", Melder_double (my xmin), L" Hz"); MelderInfo_writeLine3 (L" Highest frequency: ", Melder_double (my xmax), L" Hz"); MelderInfo_writeLine3 (L" Total frequency domain: ", Melder_double (my xmax - my xmin), L" Hz"); MelderInfo_writeLine1 (L"Frequency sampling:"); MelderInfo_writeLine2 (L" Number of frequency bands: ", Melder_integer (my nx)); MelderInfo_writeLine3 (L" Width of each band: ", Melder_double (my dx), L" Hz"); MelderInfo_writeLine3 (L" First band centred at: ", Melder_double (my x1), L" Hz"); meanPowerDensity = Sampled_getMean (me, my xmin, my xmax, 0, 1, FALSE); MelderInfo_writeLine3 (L"Total SPL: ", Melder_single (10 * log10 (meanPowerDensity * (my xmax - my xmin))), L" dB"); }
void structEditDistanceTable :: v_info () { EditDistanceTable_Parent :: v_info (); MelderInfo_writeLine3 (L"Target:", Melder_integer (numberOfRows), L" symbols."); MelderInfo_writeLine3 (L"Source:", Melder_integer (numberOfColumns), L" symbols."); }
static void info (I) { iam (Sound); const double rho_c = 400; /* rho = 1.14 kg m-3; c = 353 m s-1; [rho c] = kg m-2 s-1 */ long numberOfSamples = my nx; double minimum = my z [1] [1], maximum = minimum; classData -> info (me); MelderInfo_writeLine3 (L"Number of channels: ", Melder_integer (my ny), my ny == 1 ? L" (mono)" : my ny == 2 ? L" (stereo)" : L""); MelderInfo_writeLine1 (L"Time domain:"); MelderInfo_writeLine3 (L" Start time: ", Melder_double (my xmin), L" seconds"); MelderInfo_writeLine3 (L" End time: ", Melder_double (my xmax), L" seconds"); MelderInfo_writeLine3 (L" Total duration: ", Melder_double (my xmax - my xmin), L" seconds"); MelderInfo_writeLine1 (L"Time sampling:"); MelderInfo_writeLine2 (L" Number of samples: ", Melder_integer (my nx)); MelderInfo_writeLine3 (L" Sampling period: ", Melder_double (my dx), L" seconds"); MelderInfo_writeLine3 (L" Sampling frequency: ", Melder_single (1.0 / my dx), L" Hz"); MelderInfo_writeLine3 (L" First sample centred at: ", Melder_double (my x1), L" seconds"); double sum = 0.0, sumOfSquares = 0.0; for (long channel = 1; channel <= my ny; channel ++) { double *amplitude = my z [channel]; for (long i = 1; i <= numberOfSamples; i ++) { double value = amplitude [i]; sum += value; sumOfSquares += value * value; if (value < minimum) minimum = value; if (value > maximum) maximum = value; } } MelderInfo_writeLine1 (L"Amplitude:"); MelderInfo_writeLine3 (L" Minimum: ", Melder_single (minimum), L" Pascal"); MelderInfo_writeLine3 (L" Maximum: ", Melder_single (maximum), L" Pascal"); double mean = sum / (my nx * my ny); MelderInfo_writeLine3 (L" Mean: ", Melder_single (mean), L" Pascal"); MelderInfo_writeLine3 (L" Root-mean-square: ", Melder_single (sqrt (sumOfSquares / (my nx * my ny))), L" Pascal"); double penergy = sumOfSquares * my dx / my ny; /* Pa2 s = kg2 m-2 s-3 */ MelderInfo_write3 (L"Total energy: ", Melder_single (penergy), L" Pascal\u00B2 sec"); double energy = penergy / rho_c; /* kg s-2 = Joule m-2 */ MelderInfo_writeLine3 (L" (energy in air: ", Melder_single (energy), L" Joule/m\u00B2)"); double power = energy / (my dx * my nx); /* kg s-3 = Watt/m2 */ MelderInfo_write3 (L"Mean power (intensity) in air: ", Melder_single (power), L" Watt/m\u00B2"); if (power != 0.0) { MelderInfo_writeLine3 (L" = ", Melder_half (10 * log10 (power / 1e-12)), L" dB"); } else { MelderInfo_writeLine1 (L""); } if (my nx > 1) { for (long channel = 1; channel <= my ny; channel ++) { double *amplitude = my z [channel]; double sum = 0.0; for (long i = 1; i <= numberOfSamples; i ++) { double value = amplitude [i]; sum += value; } double mean = sum / my nx, stdev = 0.0; for (long i = 1; i <= numberOfSamples; i ++) { double value = amplitude [i] - mean; stdev += value * value; } stdev = sqrt (stdev / (my nx - 1)); MelderInfo_writeLine5 (L"Standard deviation in channel ", Melder_integer (channel), L": ", Melder_single (stdev), L" Pascal"); } } }
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; }