| 1 | /* ERP.cpp |
| 2 | * |
| 3 | * Copyright (C) 2011-2012,2014-2018,2022 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "ERP.h"cxx . . $ `<file>/EEG/ERP.h`/ |
| 20 | |
| 21 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 22 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 23 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 24 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 25 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 26 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 27 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 28 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 29 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 30 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 31 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 32 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 33 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 34 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 35 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 36 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 37 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 38 | #include "ERP_def.h"cxx . . $ `<file>/EEG/ERP_def.h`/ |
| 39 | |
| 40 | /********** class ERPTier **********/ |
| 41 | |
| 42 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (ERP, Sound, 2); |
| 43 | |
| 44 | integercxx . . $ integer# ERP_getChannelNumbercxx . . $ ERP_getChannelNumber(48e02d78e18ac71e). (ERP me, conststring32cxx . . $ conststring32# channelName) { |
| 45 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 46 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (mycxx . . $ `melder/melder.h:44:9`! channelNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ichan].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), channelName)) |
| 47 | return ichan; |
| 48 | } |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | void ERP_drawChannel_numbercxx . . $ ERP_drawChannel_number(e4907e8bdfb24433). (ERP me, Graphicscxx . . $ Graphics# graphics, integercxx . . $ integer# channelNumber, double tmin, double tmax, double vmin, double vmax, bool garnish) { |
| 53 | if (channelNumber < 1 || channelNumber > mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) return; |
| 54 | /* |
| 55 | * Automatic domain. |
| 56 | */ |
| 57 | if (tmin == tmax) { |
| 58 | tmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 59 | tmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 60 | } |
| 61 | /* |
| 62 | * Domain expressed in sample numbers. |
| 63 | */ |
| 64 | integercxx . . $ integer# ixmin, ixmax; |
| 65 | Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (me, tmin, tmax, & ixmin, & ixmax); |
| 66 | /* |
| 67 | * Automatic vertical range. |
| 68 | */ |
| 69 | if (vmin == vmax) { |
| 70 | Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (me, ixmin, ixmax, channelNumber, channelNumber, & vmin, & vmax); |
| 71 | if (vmin == vmax) { |
| 72 | vmin -= 1.0; |
| 73 | vmax += 1.0; |
| 74 | } |
| 75 | } |
| 76 | /* |
| 77 | * Set coordinates for drawing. |
| 78 | */ |
| 79 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (graphics); |
| 80 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (graphics, tmin, tmax, vmin, vmax); |
| 81 | Graphics_functioncxx . . $ Graphics_function(1c6279e2c8b8beb1). (graphics, & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channelNumber] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0], ixmin, ixmax, Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmin), Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmax)); |
| 82 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (graphics); |
| 83 | if (garnish) { |
| 84 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (graphics); |
| 85 | Graphics_textTopcxx . . $ Graphics_textTop(48cf1f690ec61203). (graphics, true, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"Channel ", mycxx . . $ `melder/melder.h:44:9`! channelNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).channelNumber].getcxx . . $ _autostring#get(5a2a78a048fb49a8).())); |
| 86 | Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (graphics, true, U"Time (s)"); |
| 87 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (graphics, 2, true, true, false); |
| 88 | if (0.0 > tmin && 0.0 < tmax) |
| 89 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (graphics, 0.0, true, true, true, nullptr); |
| 90 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (graphics, vmin, true, true, false, nullptr); |
| 91 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (graphics, vmax, true, true, false, nullptr); |
| 92 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (graphics, 0.0, true, true, true, nullptr); |
| 93 | if (vmin != 0.0 && vmax != 0.0 && (vmin > 0.0) != (vmax > 0.0)) { |
| 94 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (graphics, 0.0, true, true, true, nullptr); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | |
| 100 | void ERP_drawChannel_namecxx . . $ ERP_drawChannel_name(8e781d072ceb8a09). (ERP me, Graphicscxx . . $ Graphics# graphics, conststring32cxx . . $ conststring32# channelName, double tmin, double tmax, double vmin, double vmax, bool garnish) { |
| 101 | ERP_drawChannel_numbercxx . . $ ERP_drawChannel_number(e4907e8bdfb24433). (me, graphics, ERP_getChannelNumbercxx . . $ ERP_getChannelNumber(48e02d78e18ac71e). (me, channelName), tmin, tmax, vmin, vmax, garnish); |
| 102 | } |
| 103 | |
| 104 | autoTablecxx . . $ autoTable# ERP_tabulatecxx . . $ ERP_tabulate(2ad0010ecbc64a6a). (ERP me, bool includeSampleNumbers, bool includeTime, int timeDecimals, int voltageDecimals, int units) { |
| 105 | double voltageScaling = 1.0; |
| 106 | conststring32cxx . . $ conststring32# unitText = U"(V)"; |
| 107 | if (units == 2) { |
| 108 | voltageDecimals -= 6; |
| 109 | voltageScaling = 1000000.0; |
| 110 | unitText = U"(uV)"; |
| 111 | } |
| 112 | try { |
| 113 | autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., includeSampleNumbers + includeTime + mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 114 | integercxx . . $ integer# icol = 0; |
| 115 | if (includeSampleNumbers) |
| 116 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"sample"); |
| 117 | if (includeTime) |
| 118 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"time(s)"); |
| 119 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 120 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (mycxx . . $ `melder/melder.h:44:9`! channelNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ichan].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), unitText)); |
| 121 | for (integercxx . . $ integer# isamp = 1; isamp <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; isamp ++) { |
| 122 | icol = 0; |
| 123 | if (includeSampleNumbers) |
| 124 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), isamp, ++ icol, isamp); |
| 125 | if (includeTime) |
| 126 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), isamp, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (isamp - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., timeDecimals)); |
| 127 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 128 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), isamp, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (voltageScaling * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp], voltageDecimals)); |
| 129 | } |
| 130 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 131 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 132 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Table."); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | autoSoundcxx . . $ autoSound# ERP_downto_Soundcxx . . $ ERP_downto_Sound(9cb5e864147fedf1). (ERP me) { |
| 137 | try { |
| 138 | autoSoundcxx . . $ autoSound# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Sound); |
| 139 | mycxx . . $ `melder/melder.h:44:9`! structSoundcxx . . $ structSound# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 140 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 141 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 142 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Sound."); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* End of file ERP.cpp */ |