void TextGrid_Pitch_drawSeparately (TextGrid grid, Pitch pitch, Graphics g, double tmin, double tmax, double fmin, double fmax, int showBoundaries, int useTextStyles, int garnish, int speckle, int unit) { int ntier = grid -> tiers -> size; if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } if (unit == kPitch_unit_HERTZ_LOGARITHMIC) Pitch_draw (pitch, g, tmin, tmax, pow (10, fmin - 0.25 * (fmax - fmin) * ntier), pow (10, fmax), FALSE, speckle, unit); else Pitch_draw (pitch, g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax, FALSE, speckle, unit); TextGrid_Sound_draw (grid, NULL, g, tmin, tmax, showBoundaries, useTextStyles, FALSE); /* * Restore window for the sake of margin drawing. */ Graphics_setWindow (g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) fmin = pow (10, fmin), fmax = pow (10, fmax); if (garnish) { Graphics_drawInnerBox (g); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) { Graphics_markLeftLogarithmic (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeftLogarithmic (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_logarithmic (g, fmin, fmax, FALSE); } else if (unit == kPitch_unit_SEMITONES_100) { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_semitones (g, fmin, fmax, FALSE); } else { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks (g, fmin, fmax, FALSE); } static MelderString buffer = { 0 }; MelderString_empty (& buffer); MelderString_append (& buffer, L"Pitch (", Function_getUnitText (pitch, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), L")"); Graphics_textLeft (g, true, buffer.string); Graphics_textBottom (g, true, L"Time (s)"); Graphics_marksBottom (g, 2, true, true, true); } }
void Pitch_draw (Pitch me, Graphics g, double tmin, double tmax, double fmin, double fmax, int garnish, int speckle, int unit) { Graphics_setInner (g); Pitch_drawInside (me, g, tmin, tmax, fmin, fmax, speckle, unit); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, TRUE, L"Time (s)"); Graphics_marksBottom (g, 2, TRUE, TRUE, FALSE); static MelderString buffer = { 0 }; MelderString_empty (& buffer); MelderString_append (& buffer, L"Pitch (", Function_getUnitText (me, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), L")"); Graphics_textLeft (g, TRUE, buffer.string); if (Function_isUnitLogarithmic (me, Pitch_LEVEL_FREQUENCY, unit)) { Graphics_marksLeftLogarithmic (g, 6, TRUE, TRUE, FALSE); } else { Graphics_marksLeft (g, 2, TRUE, TRUE, FALSE); } } }
static void EEG_setChannelNames_selected (EEG me, const wchar_t *precursor, long *channelNumbers, long numberOfChannels) { autoMelderString name; const wchar_t *zero = L"0"; for (long i = 1; i <= numberOfChannels; i++) { MelderString_append (&name, precursor); if (my d_numberOfChannels > 100) { if (i < 10) { MelderString_append (&name, zero); } if (i < 100) { MelderString_append (&name, zero); } } else if (i < 10) { MelderString_append (&name, zero); } MelderString_append (&name, Melder_integer (i)); my f_setChannelName (channelNumbers[i], name.string); MelderString_empty (&name); } }
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 Graphics_setWsViewport (I, long x1DC, long x2DC, long y1DC, long y2DC) { iam (Graphics); if (x1DC < my x1DCmin || x2DC > my x2DCmax || y1DC < my y1DCmin || y2DC > my y2DCmax) { static MelderString warning = { 0 }; MelderString_empty (& warning); MelderString_append8 (& warning, L"Graphics_setWsViewport: coordinates too large:\n", Melder_integer (x1DC), L"..", Melder_integer (x2DC), L" x ", Melder_integer (y1DC), L"..", Melder_integer (y2DC)); MelderString_append9 (& warning, L" goes outside ", Melder_integer (my x1DCmin), L"..", Melder_integer (my x2DCmax), L" x ", Melder_integer (my y1DCmin), L"..", Melder_integer (my y2DCmax), L"."); Melder_warning1 (warning.string); x1DC = my x1DCmin; x2DC = my x2DCmax; y1DC = my y1DCmin; y2DC = my y2DCmax; } my x1DC = x1DC; my x2DC = x2DC; my y1DC = y1DC; my y2DC = y2DC; widgetToWindowCoordinates (me); #if win if (my screen && my printer) { iam (GraphicsScreen); /* * Map page coordinates to paper coordinates. */ my x1DC -= GetDeviceCaps (my dc, PHYSICALOFFSETX); my x2DC -= GetDeviceCaps (my dc, PHYSICALOFFSETX); my y1DC -= GetDeviceCaps (my dc, PHYSICALOFFSETY); my y2DC -= GetDeviceCaps (my dc, PHYSICALOFFSETY); } #endif computeTrafo (me); }
void Melder_warning3 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3) { if (theWarningDepth < 0) return; MelderString_empty (& theWarningBuffer); MelderString_append3 (& theWarningBuffer, s1, s2, s3); theMelder. warning (theWarningBuffer.string); }
static Strings Strings_createAsFileOrDirectoryList (const wchar_t *path, int type) { #if USE_STAT /* * Initialize. */ DIR *d = NULL; try { autoMelderString filePath, searchDirectory, left, right; /* * Parse the path. * Example: in /Users/paul/sounds/h*.wav", * the search directory is "/Users/paul/sounds", * the left environment is "h", and the right environment is ".wav". */ MelderString_copy (& searchDirectory, path); wchar_t *asterisk = wcsrchr (searchDirectory. string, '*'); if (asterisk != NULL) { *asterisk = '\0'; searchDirectory. length = asterisk - searchDirectory. string; // probably superfluous, but correct wchar_t *lastSlash = wcsrchr (searchDirectory. string, Melder_DIRECTORY_SEPARATOR); if (lastSlash != NULL) { *lastSlash = '\0'; // This fixes searchDirectory. searchDirectory. length = lastSlash - searchDirectory. string; // probably superfluous, but correct MelderString_copy (& left, lastSlash + 1); } else { MelderString_copy (& left, searchDirectory. string); // quickly save... MelderString_empty (& searchDirectory); // ...before destruction } MelderString_copy (& right, asterisk + 1); } char buffer8 [1+kMelder_MAXPATH]; Melder_wcsTo8bitFileRepresentation_inline (searchDirectory. string, buffer8); d = opendir (buffer8 [0] ? buffer8 : "."); if (d == NULL) Melder_throw ("Cannot open directory ", searchDirectory. string, "."); //Melder_casual ("opened"); autoStrings me = Thing_new (Strings); my strings = NUMvector <wchar_t *> (1, 1000000); struct dirent *entry; while ((entry = readdir (d)) != NULL) { MelderString_copy (& filePath, searchDirectory. string [0] ? searchDirectory. string : L"."); MelderString_appendCharacter (& filePath, Melder_DIRECTORY_SEPARATOR); wchar_t bufferW [1+kMelder_MAXPATH]; Melder_8bitFileRepresentationToWcs_inline (entry -> d_name, bufferW); MelderString_append (& filePath, bufferW); //Melder_casual ("read %s", filePath. string); Melder_wcsTo8bitFileRepresentation_inline (filePath. string, buffer8); struct stat stats; if (stat (buffer8, & stats) != 0) { Melder_throw ("Cannot look at file ", filePath. string, "."); //stats. st_mode = -1L; } //Melder_casual ("statted %s", filePath. string); //Melder_casual ("file %s mode %s", filePath. string, Melder_integer (stats. st_mode / 4096)); if ((type == Strings_createAsFileOrDirectoryList_TYPE_FILE && S_ISREG (stats. st_mode)) || (type == Strings_createAsFileOrDirectoryList_TYPE_DIRECTORY && S_ISDIR (stats. st_mode))) { Melder_8bitFileRepresentationToWcs_inline (entry -> d_name, bufferW); unsigned long length = wcslen (bufferW); if (bufferW [0] != '.' && (left. length == 0 || wcsnequ (bufferW, left. string, left. length)) && (right. length == 0 || (length >= right. length && wcsequ (bufferW + (length - right. length), right. string)))) { my strings [++ my numberOfStrings] = Melder_wcsdup (bufferW); } } } closedir (d); Strings_sort (me.peek()); return me.transfer(); } catch (MelderError) { if (d) closedir (d); // "finally" throw; } #elif defined (_WIN32) try { wchar_t searchPath [1+kMelder_MAXPATH]; int len = wcslen (path), hasAsterisk = wcschr (path, '*') != NULL, endsInSeparator = len != 0 && path [len - 1] == '\\'; autoStrings me = Thing_new (Strings); my strings = NUMvector <wchar_t *> (1, 1000000); swprintf (searchPath, 1+kMelder_MAXPATH, L"%ls%ls%ls", path, hasAsterisk || endsInSeparator ? L"" : L"\\", hasAsterisk ? L"" : L"*"); WIN32_FIND_DATAW findData; HANDLE searchHandle = FindFirstFileW (searchPath, & findData); if (searchHandle != INVALID_HANDLE_VALUE) { do { if ((type == Strings_createAsFileOrDirectoryList_TYPE_FILE && (findData. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) || (type == Strings_createAsFileOrDirectoryList_TYPE_DIRECTORY && (findData. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) { if (findData. cFileName [0] != '.') { my strings [++ my numberOfStrings] = Melder_wcsdup (findData. cFileName); } } } while (FindNextFileW (searchHandle, & findData)); FindClose (searchHandle); } Strings_sort (me.peek()); return me.transfer(); } catch (MelderError) { throw; } #endif }
int Melder_progress8 (double progress, const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8) { MelderString_empty (& theProgressBuffer); MelderString_append8 (& theProgressBuffer, s1, s2, s3, s4, s5, s6, s7, s8); //return _Melder_progress (progress, theProgressBuffer.string); }
autoEEG EEG_readFromBdfFile (MelderFile file) { try { autofile f = Melder_fopen (file, "rb"); char buffer [81]; fread (buffer, 1, 8, f); buffer [8] = '\0'; bool is24bit = buffer [0] == (char) 255; fread (buffer, 1, 80, f); buffer [80] = '\0'; trace (U"Local subject identification: \"", Melder_peek8to32 (buffer), U"\""); fread (buffer, 1, 80, f); buffer [80] = '\0'; trace (U"Local recording identification: \"", Melder_peek8to32 (buffer), U"\""); fread (buffer, 1, 8, f); buffer [8] = '\0'; trace (U"Start date of recording: \"", Melder_peek8to32 (buffer), U"\""); fread (buffer, 1, 8, f); buffer [8] = '\0'; trace (U"Start time of recording: \"", Melder_peek8to32 (buffer), U"\""); fread (buffer, 1, 8, f); buffer [8] = '\0'; long numberOfBytesInHeaderRecord = atol (buffer); trace (U"Number of bytes in header record: ", numberOfBytesInHeaderRecord); fread (buffer, 1, 44, f); buffer [44] = '\0'; trace (U"Version of data format: \"", Melder_peek8to32 (buffer), U"\""); fread (buffer, 1, 8, f); buffer [8] = '\0'; long numberOfDataRecords = strtol (buffer, nullptr, 10); trace (U"Number of data records: ", numberOfDataRecords); fread (buffer, 1, 8, f); buffer [8] = '\0'; double durationOfDataRecord = atof (buffer); trace (U"Duration of a data record: ", durationOfDataRecord); fread (buffer, 1, 4, f); buffer [4] = '\0'; long numberOfChannels = atol (buffer); trace (U"Number of channels in data record: ", numberOfChannels); if (numberOfBytesInHeaderRecord != (numberOfChannels + 1) * 256) Melder_throw (U"Number of bytes in header record (", numberOfBytesInHeaderRecord, U") doesn't match number of channels (", numberOfChannels, U")."); autostring32vector channelNames (1, numberOfChannels); for (long ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { fread (buffer, 1, 16, f); buffer [16] = '\0'; // labels of the channels /* * Strip all final spaces. */ for (int i = 15; i >= 0; i --) { if (buffer [i] == ' ') { buffer [i] = '\0'; } else { break; } } channelNames [ichannel] = Melder_8to32 (buffer); trace (U"Channel <<", channelNames [ichannel], U">>"); } bool hasLetters = str32equ (channelNames [numberOfChannels], U"EDF Annotations"); double samplingFrequency = NUMundefined; for (long channel = 1; channel <= numberOfChannels; channel ++) { fread (buffer, 1, 80, f); buffer [80] = '\0'; // transducer type } for (long channel = 1; channel <= numberOfChannels; channel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; // physical dimension of channels } autoNUMvector <double> physicalMinimum (1, numberOfChannels); for (long ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; physicalMinimum [ichannel] = atof (buffer); } autoNUMvector <double> physicalMaximum (1, numberOfChannels); for (long ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; physicalMaximum [ichannel] = atof (buffer); } autoNUMvector <double> digitalMinimum (1, numberOfChannels); for (long ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; digitalMinimum [ichannel] = atof (buffer); } autoNUMvector <double> digitalMaximum (1, numberOfChannels); for (long ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; digitalMaximum [ichannel] = atof (buffer); } for (long channel = 1; channel <= numberOfChannels; channel ++) { fread (buffer, 1, 80, f); buffer [80] = '\0'; // prefiltering } long numberOfSamplesPerDataRecord = 0; for (long channel = 1; channel <= numberOfChannels; channel ++) { fread (buffer, 1, 8, f); buffer [8] = '\0'; // number of samples in each data record long numberOfSamplesInThisDataRecord = atol (buffer); if (samplingFrequency == NUMundefined) { numberOfSamplesPerDataRecord = numberOfSamplesInThisDataRecord; samplingFrequency = numberOfSamplesInThisDataRecord / durationOfDataRecord; } if (numberOfSamplesInThisDataRecord / durationOfDataRecord != samplingFrequency) Melder_throw (U"Number of samples per data record in channel ", channel, U" (", numberOfSamplesInThisDataRecord, U") doesn't match sampling frequency of channel 1 (", samplingFrequency, U")."); } for (long channel = 1; channel <= numberOfChannels; channel ++) { fread (buffer, 1, 32, f); buffer [32] = '\0'; // reserved } double duration = numberOfDataRecords * durationOfDataRecord; autoEEG him = EEG_create (0, duration); his numberOfChannels = numberOfChannels; autoSound me = Sound_createSimple (numberOfChannels, duration, samplingFrequency); Melder_assert (my nx == numberOfSamplesPerDataRecord * numberOfDataRecords); autoNUMvector <unsigned char> dataBuffer (0L, 3 * numberOfSamplesPerDataRecord - 1); for (long record = 1; record <= numberOfDataRecords; record ++) { for (long channel = 1; channel <= numberOfChannels; channel ++) { double factor = channel == numberOfChannels ? 1.0 : physicalMinimum [channel] / digitalMinimum [channel]; if (channel < numberOfChannels - EEG_getNumberOfExtraSensors (him.peek())) factor /= 1000000.0; if (is24bit) { fread (& dataBuffer [0], 3, numberOfSamplesPerDataRecord, f); unsigned char *p = & dataBuffer [0]; for (long i = 1; i <= numberOfSamplesPerDataRecord; i ++) { long sample = i + (record - 1) * numberOfSamplesPerDataRecord; Melder_assert (sample <= my nx); uint8_t lowByte = *p ++, midByte = *p ++, highByte = *p ++; uint32_t externalValue = ((uint32_t) highByte << 16) | ((uint32_t) midByte << 8) | (uint32_t) lowByte; if ((highByte & 128) != 0) // is the 24-bit sign bit on? externalValue |= 0xFF000000; // extend negative sign to 32 bits my z [channel] [sample] = (int32_t) externalValue * factor; } } else { fread (& dataBuffer [0], 2, numberOfSamplesPerDataRecord, f); unsigned char *p = & dataBuffer [0]; for (long i = 1; i <= numberOfSamplesPerDataRecord; i ++) { long sample = i + (record - 1) * numberOfSamplesPerDataRecord; Melder_assert (sample <= my nx); uint8 lowByte = *p ++, highByte = *p ++; uint16 externalValue = (uint16) ((uint16) highByte << 8) | (uint16) lowByte; my z [channel] [sample] = (int16) externalValue * factor; } } } } int numberOfStatusBits = 8; for (long i = 1; i <= my nx; i ++) { unsigned long value = (long) my z [numberOfChannels] [i]; if (value & 0x0000FF00) { numberOfStatusBits = 16; } } autoTextGrid thee; if (hasLetters) { thee = TextGrid_create (0, duration, U"Mark Trigger", U"Mark Trigger"); autoMelderString letters; double time = NUMundefined; for (long i = 1; i <= my nx; i ++) { unsigned long value = (long) my z [numberOfChannels] [i]; for (int byte = 1; byte <= numberOfStatusBits / 8; byte ++) { unsigned long mask = byte == 1 ? 0x000000ff : 0x0000ff00; char32 kar = byte == 1 ? (value & mask) : (value & mask) >> 8; if (kar != U'\0' && kar != 20) { MelderString_appendCharacter (& letters, kar); } else if (letters. string [0] != U'\0') { if (letters. string [0] == U'+') { if (NUMdefined (time)) { try { TextGrid_insertPoint (thee.peek(), 1, time, U""); } catch (MelderError) { Melder_throw (U"Did not insert empty mark (", letters. string, U") on Mark tier."); } time = NUMundefined; // defensive } time = Melder_atof (& letters. string [1]); MelderString_empty (& letters); } else { if (! NUMdefined (time)) { Melder_throw (U"Undefined time for label at sample ", i, U"."); } try { if (Melder_nequ (letters. string, U"Trigger-", 8)) { try { TextGrid_insertPoint (thee.peek(), 2, time, & letters. string [8]); } catch (MelderError) { Melder_clearError (); trace (U"Duplicate trigger at ", time, U" seconds: ", & letters. string [8]); } } else { TextGrid_insertPoint (thee.peek(), 1, time, & letters. string [0]); } } catch (MelderError) { Melder_throw (U"Did not insert mark (", letters. string, U") on Trigger tier."); } time = NUMundefined; // crucial MelderString_empty (& letters); } } } } if (NUMdefined (time)) { TextGrid_insertPoint (thee.peek(), 1, time, U""); time = NUMundefined; // defensive } } else { thee = TextGrid_create (0, duration, numberOfStatusBits == 8 ? U"S1 S2 S3 S4 S5 S6 S7 S8" : U"S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 S14 S15 S16", U""); for (int bit = 1; bit <= numberOfStatusBits; bit ++) { unsigned long bitValue = 1 << (bit - 1); IntervalTier tier = (IntervalTier) thy tiers -> item [bit]; for (long i = 1; i <= my nx; i ++) { unsigned long previousValue = i == 1 ? 0 : (long) my z [numberOfChannels] [i - 1]; unsigned long thisValue = (long) my z [numberOfChannels] [i]; if ((thisValue & bitValue) != (previousValue & bitValue)) { double time = i == 1 ? 0.0 : my x1 + (i - 1.5) * my dx; if (time != 0.0) TextGrid_insertBoundary (thee.peek(), bit, time); if ((thisValue & bitValue) != 0) TextGrid_setIntervalText (thee.peek(), bit, tier -> intervals -> size, U"1"); } } } } f.close (file); his channelNames = channelNames.transfer(); his sound = me.move(); his textgrid = thee.move(); if (EEG_getNumberOfCapElectrodes (him.peek()) == 32) { EEG_setChannelName (him.peek(), 1, U"Fp1"); EEG_setChannelName (him.peek(), 2, U"AF3"); EEG_setChannelName (him.peek(), 3, U"F7"); EEG_setChannelName (him.peek(), 4, U"F3"); EEG_setChannelName (him.peek(), 5, U"FC1"); EEG_setChannelName (him.peek(), 6, U"FC5"); EEG_setChannelName (him.peek(), 7, U"T7"); EEG_setChannelName (him.peek(), 8, U"C3"); EEG_setChannelName (him.peek(), 9, U"CP1"); EEG_setChannelName (him.peek(), 10, U"CP5"); EEG_setChannelName (him.peek(), 11, U"P7"); EEG_setChannelName (him.peek(), 12, U"P3"); EEG_setChannelName (him.peek(), 13, U"Pz"); EEG_setChannelName (him.peek(), 14, U"PO3"); EEG_setChannelName (him.peek(), 15, U"O1"); EEG_setChannelName (him.peek(), 16, U"Oz"); EEG_setChannelName (him.peek(), 17, U"O2"); EEG_setChannelName (him.peek(), 18, U"PO4"); EEG_setChannelName (him.peek(), 19, U"P4"); EEG_setChannelName (him.peek(), 20, U"P8"); EEG_setChannelName (him.peek(), 21, U"CP6"); EEG_setChannelName (him.peek(), 22, U"CP2"); EEG_setChannelName (him.peek(), 23, U"C4"); EEG_setChannelName (him.peek(), 24, U"T8"); EEG_setChannelName (him.peek(), 25, U"FC6"); EEG_setChannelName (him.peek(), 26, U"FC2"); EEG_setChannelName (him.peek(), 27, U"F4"); EEG_setChannelName (him.peek(), 28, U"F8"); EEG_setChannelName (him.peek(), 29, U"AF4"); EEG_setChannelName (him.peek(), 30, U"Fp2"); EEG_setChannelName (him.peek(), 31, U"Fz"); EEG_setChannelName (him.peek(), 32, U"Cz"); } else if (EEG_getNumberOfCapElectrodes (him.peek()) == 64) { EEG_setChannelName (him.peek(), 1, U"Fp1"); EEG_setChannelName (him.peek(), 2, U"AF7"); EEG_setChannelName (him.peek(), 3, U"AF3"); EEG_setChannelName (him.peek(), 4, U"F1"); EEG_setChannelName (him.peek(), 5, U"F3"); EEG_setChannelName (him.peek(), 6, U"F5"); EEG_setChannelName (him.peek(), 7, U"F7"); EEG_setChannelName (him.peek(), 8, U"FT7"); EEG_setChannelName (him.peek(), 9, U"FC5"); EEG_setChannelName (him.peek(), 10, U"FC3"); EEG_setChannelName (him.peek(), 11, U"FC1"); EEG_setChannelName (him.peek(), 12, U"C1"); EEG_setChannelName (him.peek(), 13, U"C3"); EEG_setChannelName (him.peek(), 14, U"C5"); EEG_setChannelName (him.peek(), 15, U"T7"); EEG_setChannelName (him.peek(), 16, U"TP7"); EEG_setChannelName (him.peek(), 17, U"CP5"); EEG_setChannelName (him.peek(), 18, U"CP3"); EEG_setChannelName (him.peek(), 19, U"CP1"); EEG_setChannelName (him.peek(), 20, U"P1"); EEG_setChannelName (him.peek(), 21, U"P3"); EEG_setChannelName (him.peek(), 22, U"P5"); EEG_setChannelName (him.peek(), 23, U"P7"); EEG_setChannelName (him.peek(), 24, U"P9"); EEG_setChannelName (him.peek(), 25, U"PO7"); EEG_setChannelName (him.peek(), 26, U"PO3"); EEG_setChannelName (him.peek(), 27, U"O1"); EEG_setChannelName (him.peek(), 28, U"Iz"); EEG_setChannelName (him.peek(), 29, U"Oz"); EEG_setChannelName (him.peek(), 30, U"POz"); EEG_setChannelName (him.peek(), 31, U"Pz"); EEG_setChannelName (him.peek(), 32, U"CPz"); EEG_setChannelName (him.peek(), 33, U"Fpz"); EEG_setChannelName (him.peek(), 34, U"Fp2"); EEG_setChannelName (him.peek(), 35, U"AF8"); EEG_setChannelName (him.peek(), 36, U"AF4"); EEG_setChannelName (him.peek(), 37, U"AFz"); EEG_setChannelName (him.peek(), 38, U"Fz"); EEG_setChannelName (him.peek(), 39, U"F2"); EEG_setChannelName (him.peek(), 40, U"F4"); EEG_setChannelName (him.peek(), 41, U"F6"); EEG_setChannelName (him.peek(), 42, U"F8"); EEG_setChannelName (him.peek(), 43, U"FT8"); EEG_setChannelName (him.peek(), 44, U"FC6"); EEG_setChannelName (him.peek(), 45, U"FC4"); EEG_setChannelName (him.peek(), 46, U"FC2"); EEG_setChannelName (him.peek(), 47, U"FCz"); EEG_setChannelName (him.peek(), 48, U"Cz"); EEG_setChannelName (him.peek(), 49, U"C2"); EEG_setChannelName (him.peek(), 50, U"C4"); EEG_setChannelName (him.peek(), 51, U"C6"); EEG_setChannelName (him.peek(), 52, U"T8"); EEG_setChannelName (him.peek(), 53, U"TP8"); EEG_setChannelName (him.peek(), 54, U"CP6"); EEG_setChannelName (him.peek(), 55, U"CP4"); EEG_setChannelName (him.peek(), 56, U"CP2"); EEG_setChannelName (him.peek(), 57, U"P2"); EEG_setChannelName (him.peek(), 58, U"P4"); EEG_setChannelName (him.peek(), 59, U"P6"); EEG_setChannelName (him.peek(), 60, U"P8"); EEG_setChannelName (him.peek(), 61, U"P10"); EEG_setChannelName (him.peek(), 62, U"PO8"); EEG_setChannelName (him.peek(), 63, U"PO4"); EEG_setChannelName (him.peek(), 64, U"O2"); } return him; } catch (MelderError) {
void * Melder_monitor1 (double progress, const wchar_t *s1) { MelderString_empty (& theProgressBuffer); MelderString_append1 (& theProgressBuffer, s1); //return _Melder_monitor (progress, theProgressBuffer.string); // FIXME }
void Melder_warning9 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8, const wchar_t *s9) { if (theWarningDepth < 0) return; MelderString_empty (& theWarningBuffer); MelderString_append9 (& theWarningBuffer, s1, s2, s3, s4, s5, s6, s7, s8, s9); theMelder. warning (theWarningBuffer.string); }
static autoStrings Strings_createAsFileOrDirectoryList (const char32 *path /* cattable */, int type) { #if USE_STAT /* * Initialize. */ DIR *d = nullptr; try { autoMelderString filePath, searchDirectory, left, right; /* * Parse the path. * Example: in /Users/paul/sounds/h*.wav", * the search directory is "/Users/paul/sounds", * the left environment is "h", and the right environment is ".wav". */ MelderString_copy (& searchDirectory, path); char32 *asterisk = str32rchr (searchDirectory. string, '*'); if (asterisk) { *asterisk = '\0'; searchDirectory. length = asterisk - searchDirectory. string; // probably superfluous, but correct char32 *lastSlash = str32rchr (searchDirectory. string, Melder_DIRECTORY_SEPARATOR); if (lastSlash) { *lastSlash = '\0'; // This fixes searchDirectory. searchDirectory. length = lastSlash - searchDirectory. string; // probably superfluous, but correct MelderString_copy (& left, lastSlash + 1); } else { MelderString_copy (& left, searchDirectory. string); // quickly save... MelderString_empty (& searchDirectory); // ...before destruction } MelderString_copy (& right, asterisk + 1); } char buffer8 [kMelder_MAXPATH+1]; Melder_str32To8bitFileRepresentation_inline (searchDirectory. string, buffer8); d = opendir (buffer8 [0] ? buffer8 : "."); if (! d) Melder_throw (U"Cannot open directory ", searchDirectory. string, U"."); //Melder_casual (U"opened"); autoStrings me = Thing_new (Strings); my strings = NUMvector <char32 *> (1, 1000000); struct dirent *entry; while (!! (entry = readdir (d))) { MelderString_copy (& filePath, searchDirectory. string [0] ? searchDirectory. string : U"."); MelderString_appendCharacter (& filePath, Melder_DIRECTORY_SEPARATOR); char32 buffer32 [kMelder_MAXPATH+1]; Melder_8bitFileRepresentationToStr32_inline (entry -> d_name, buffer32); MelderString_append (& filePath, buffer32); //Melder_casual (U"read ", filePath. string); Melder_str32To8bitFileRepresentation_inline (filePath. string, buffer8); struct stat stats; if (stat (buffer8, & stats) != 0) { //Melder_throw (U"Cannot look at file ", filePath. string, U"."); //stats. st_mode = -1L; } //Melder_casual (U"statted ", filePath. string); //Melder_casual (U"file ", filePath. string, U" mode ", stats. st_mode / 4096); if ((type == Strings_createAsFileOrDirectoryList_TYPE_FILE && S_ISREG (stats. st_mode)) || (type == Strings_createAsFileOrDirectoryList_TYPE_DIRECTORY && S_ISDIR (stats. st_mode))) { Melder_8bitFileRepresentationToStr32_inline (entry -> d_name, buffer32); int64 length = str32len (buffer32); if (buffer32 [0] != U'.' && (left. length == 0 || str32nequ (buffer32, left. string, left. length)) && (right. length == 0 || (length >= right. length && str32equ (buffer32 + (length - right. length), right. string)))) { my strings [++ my numberOfStrings] = Melder_dup (buffer32); } } } closedir (d); Strings_sort (me.get()); return me; } catch (MelderError) { if (d) closedir (d); // "finally" throw; } #elif defined (_WIN32) try { char32 searchPath [kMelder_MAXPATH+1]; int len = str32len (path); bool hasAsterisk = !! str32chr (path, U'*'); bool endsInSeparator = ( len != 0 && path [len - 1] == U'\\' ); autoStrings me = Thing_new (Strings); my strings = NUMvector <char32 *> (1, 1000000); Melder_sprint (searchPath, kMelder_MAXPATH+1, path, hasAsterisk || endsInSeparator ? U"" : U"\\", hasAsterisk ? U"" : U"*"); WIN32_FIND_DATAW findData; HANDLE searchHandle = FindFirstFileW (Melder_peek32toW (searchPath), & findData); if (searchHandle != INVALID_HANDLE_VALUE) { do { if ((type == Strings_createAsFileOrDirectoryList_TYPE_FILE && (findData. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) || (type == Strings_createAsFileOrDirectoryList_TYPE_DIRECTORY && (findData. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) { if (findData. cFileName [0] != L'.') { my strings [++ my numberOfStrings] = Melder_dup (Melder_peekWto32 (findData. cFileName)); } } } while (FindNextFileW (searchHandle, & findData)); FindClose (searchHandle); } Strings_sort (me.get()); return me; } catch (MelderError) { throw; } #endif }
int Melder_progress4 (double progress, const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4) { MelderString_empty (& theProgressBuffer); MelderString_append4 (& theProgressBuffer, s1, s2, s3, s4); //return _Melder_progress (progress, theProgressBuffer.string); }
void * Melder_monitor2 (double progress, const wchar_t *s1, const wchar_t *s2) { MelderString_empty (& theProgressBuffer); MelderString_append2 (& theProgressBuffer, s1, s2); //return _Melder_monitor (progress, theProgressBuffer.string); }
void Melder_warning1 (const wchar_t *s1) { if (theWarningDepth < 0) return; MelderString_empty (& theWarningBuffer); MelderString_append1 (& theWarningBuffer, s1); theMelder. warning (theWarningBuffer.string); }
void * Melder_monitor9 (double progress, const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6, const wchar_t *s7, const wchar_t *s8, const wchar_t *s9) { MelderString_empty (& theProgressBuffer); MelderString_append9 (& theProgressBuffer, s1, s2, s3, s4, s5, s6, s7, s8, s9); //return _Melder_monitor (progress, theProgressBuffer.string); }
void * Melder_monitor5 (double progress, const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5) { MelderString_empty (& theProgressBuffer); MelderString_append5 (& theProgressBuffer, s1, s2, s3, s4, s5); //return _Melder_monitor (progress, theProgressBuffer.string); }
void Melder_warning6 (const wchar_t *s1, const wchar_t *s2, const wchar_t *s3, const wchar_t *s4, const wchar_t *s5, const wchar_t *s6) { if (theWarningDepth < 0) return; MelderString_empty (& theWarningBuffer); MelderString_append6 (& theWarningBuffer, s1, s2, s3, s4, s5, s6); theMelder. warning (theWarningBuffer.string); }
TableOfReal TableOfReal_readFromHeaderlessSpreadsheetFile (MelderFile file) { try { autostring string = MelderFile_readText (file); long nrow, ncol, nelements; /* * Count columns. */ ncol = 0; wchar_t *p = & string [0]; for (;;) { wchar_t kar = *p++; if (kar == '\n' || kar == '\0') break; if (kar == ' ' || kar == '\t') continue; ncol ++; do { kar = *p++; } while (kar != ' ' && kar != '\t' && kar != '\n' && kar != '\0'); if (kar == '\n' || kar == '\0') break; } ncol --; if (ncol < 1) Melder_throw ("No columns."); /* * Count elements. */ p = & string [0]; nelements = 0; for (;;) { wchar_t kar = *p++; if (kar == '\0') break; if (kar == ' ' || kar == '\t' || kar == '\n') continue; nelements ++; do { kar = *p++; } while (kar != ' ' && kar != '\t' && kar != '\n' && kar != '\0'); if (kar == '\0') break; } /* * Check if all columns are complete. */ if (nelements == 0 || nelements % (ncol + 1) != 0) Melder_throw ("The number of elements (", nelements, ") is not a multiple of the number of columns plus 1 (", ncol + 1, ")."); /* * Create empty table. */ nrow = nelements / (ncol + 1) - 1; autoTableOfReal me = TableOfReal_create (nrow, ncol); /* * Read elements. */ p = & string [0]; while (*p == ' ' || *p == '\t') { Melder_assert (*p != '\0'); p ++; } while (*p != ' ' && *p != '\t') { Melder_assert (*p != '\0'); p ++; } // ignore the header of the zeroth column ("rowLabel" perhaps) for (long icol = 1; icol <= ncol; icol ++) { while (*p == ' ' || *p == '\t') { Melder_assert (*p != '\0'); p ++; } static MelderString buffer = { 0 }; MelderString_empty (& buffer); while (*p != ' ' && *p != '\t' && *p != '\n') { MelderString_appendCharacter (& buffer, *p); p ++; } TableOfReal_setColumnLabel (me.peek(), icol, buffer.string); MelderString_empty (& buffer); } for (long irow = 1; irow <= nrow; irow ++) { while (*p == ' ' || *p == '\t' || *p == '\n') { Melder_assert (*p != '\0'); p ++; } static MelderString buffer = { 0 }; MelderString_empty (& buffer); while (*p != ' ' && *p != '\t') { MelderString_appendCharacter (& buffer, *p); p ++; } TableOfReal_setRowLabel (me.peek(), irow, buffer.string); MelderString_empty (& buffer); for (long icol = 1; icol <= ncol; icol ++) { while (*p == ' ' || *p == '\t' || *p == '\n') { Melder_assert (*p != '\0'); p ++; } MelderString_empty (& buffer); while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0') { MelderString_appendCharacter (& buffer, *p); p ++; } my data [irow] [icol] = Melder_atof (buffer.string); /* If cell contains a string, this will be 0. */ MelderString_empty (& buffer); } } return me.transfer(); } catch (MelderError) { Melder_throw ("TableOfReal: tab-separated file ", file, " not read."); } }