| 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" |
| 20 |
|
| 21 |
#include "oo_DESTROY.h" |
| 22 |
#include "ERP_def.h" |
| 23 |
#include "oo_COPY.h" |
| 24 |
#include "ERP_def.h" |
| 25 |
#include "oo_EQUAL.h" |
| 26 |
#include "ERP_def.h" |
| 27 |
#include "oo_CAN_WRITE_AS_ENCODING.h" |
| 28 |
#include "ERP_def.h" |
| 29 |
#include "oo_WRITE_TEXT.h" |
| 30 |
#include "ERP_def.h" |
| 31 |
#include "oo_READ_TEXT.h" |
| 32 |
#include "ERP_def.h" |
| 33 |
#include "oo_WRITE_BINARY.h" |
| 34 |
#include "ERP_def.h" |
| 35 |
#include "oo_READ_BINARY.h" |
| 36 |
#include "ERP_def.h" |
| 37 |
#include "oo_DESCRIPTION.h" |
| 38 |
#include "ERP_def.h" |
| 39 |
|
| 40 |
/********** class ERPTier **********/ |
| 41 |
|
| 42 |
Thing_implement (ERP, Sound, 2); |
| 43 |
|
| 44 |
integer ERP_getChannelNumber (ERP me, conststring32 channelName) { |
| 45 |
for (integer ichan = 1; ichan <= my ny; ichan ++) { |
| 46 |
if (Melder_equ (my channelNames [ichan].get(), channelName)) |
| 47 |
return ichan; |
| 48 |
} |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
void ERP_drawChannel_number (ERP me, Graphics graphics, integer channelNumber, double tmin, double tmax, double vmin, double vmax, bool garnish) { |
| 53 |
if (channelNumber < 1 || channelNumber > my ny) return; |
| 54 |
/* |
| 55 |
* Automatic domain. |
| 56 |
*/ |
| 57 |
if (tmin == tmax) { |
| 58 |
tmin = my xmin; |
| 59 |
tmax = my xmax; |
| 60 |
} |
| 61 |
/* |
| 62 |
* Domain expressed in sample numbers. |
| 63 |
*/ |
| 64 |
integer ixmin, ixmax; |
| 65 |
Matrix_getWindowSamplesX (me, tmin, tmax, & ixmin, & ixmax); |
| 66 |
/* |
| 67 |
* Automatic vertical range. |
| 68 |
*/ |
| 69 |
if (vmin == vmax) { |
| 70 |
Matrix_getWindowExtrema (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_setInner (graphics); |
| 80 |
Graphics_setWindow (graphics, tmin, tmax, vmin, vmax); |
| 81 |
Graphics_function (graphics, & my z [channelNumber] [0], ixmin, ixmax, Matrix_columnToX (me, ixmin), Matrix_columnToX (me, ixmax)); |
| 82 |
Graphics_unsetInner (graphics); |
| 83 |
if (garnish) { |
| 84 |
Graphics_drawInnerBox (graphics); |
| 85 |
Graphics_textTop (graphics, true, Melder_cat (U"Channel ", my channelNames [channelNumber].get())); |
| 86 |
Graphics_textBottom (graphics, true, U"Time (s)"); |
| 87 |
Graphics_marksBottom (graphics, 2, true, true, false); |
| 88 |
if (0.0 > tmin && 0.0 < tmax) |
| 89 |
Graphics_markBottom (graphics, 0.0, true, true, true, nullptr); |
| 90 |
Graphics_markLeft (graphics, vmin, true, true, false, nullptr); |
| 91 |
Graphics_markLeft (graphics, vmax, true, true, false, nullptr); |
| 92 |
Graphics_markBottom (graphics, 0.0, true, true, true, nullptr); |
| 93 |
if (vmin != 0.0 && vmax != 0.0 && (vmin > 0.0) != (vmax > 0.0)) { |
| 94 |
Graphics_markLeft (graphics, 0.0, true, true, true, nullptr); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
void ERP_drawChannel_name (ERP me, Graphics graphics, conststring32 channelName, double tmin, double tmax, double vmin, double vmax, bool garnish) { |
| 101 |
ERP_drawChannel_number (me, graphics, ERP_getChannelNumber (me, channelName), tmin, tmax, vmin, vmax, garnish); |
| 102 |
} |
| 103 |
|
| 104 |
autoTable ERP_tabulate (ERP me, bool includeSampleNumbers, bool includeTime, int timeDecimals, int voltageDecimals, int units) { |
| 105 |
double voltageScaling = 1.0; |
| 106 |
conststring32 unitText = U"(V)"; |
| 107 |
if (units == 2) { |
| 108 |
voltageDecimals -= 6; |
| 109 |
voltageScaling = 1000000.0; |
| 110 |
unitText = U"(uV)"; |
| 111 |
} |
| 112 |
try { |
| 113 |
autoTable thee = Table_createWithoutColumnNames (my nx, includeSampleNumbers + includeTime + my ny); |
| 114 |
integer icol = 0; |
| 115 |
if (includeSampleNumbers) |
| 116 |
Table_renameColumn_e (thee.get(), ++ icol, U"sample"); |
| 117 |
if (includeTime) |
| 118 |
Table_renameColumn_e (thee.get(), ++ icol, U"time(s)"); |
| 119 |
for (integer ichan = 1; ichan <= my ny; ichan ++) |
| 120 |
Table_renameColumn_e (thee.get(), ++ icol, Melder_cat (my channelNames [ichan].get(), unitText)); |
| 121 |
for (integer isamp = 1; isamp <= my nx; isamp ++) { |
| 122 |
icol = 0; |
| 123 |
if (includeSampleNumbers) |
| 124 |
Table_setNumericValue (thee.get(), isamp, ++ icol, isamp); |
| 125 |
if (includeTime) |
| 126 |
Table_setStringValue (thee.get(), isamp, ++ icol, Melder_fixed (my x1 + (isamp - 1) * my dx, timeDecimals)); |
| 127 |
for (integer ichan = 1; ichan <= my ny; ichan ++) |
| 128 |
Table_setStringValue (thee.get(), isamp, ++ icol, Melder_fixed (voltageScaling * my z [ichan] [isamp], voltageDecimals)); |
| 129 |
} |
| 130 |
return thee; |
| 131 |
} catch (MelderError) { |
| 132 |
Melder_throw (me, U": not converted to Table."); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
autoSound ERP_downto_Sound (ERP me) { |
| 137 |
try { |
| 138 |
autoSound thee = Thing_new (Sound); |
| 139 |
my structSound :: v1_copy (thee.get()); |
| 140 |
return thee; |
| 141 |
} catch (MelderError) { |
| 142 |
Melder_throw (me, U": not converted to Sound."); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/* End of file ERP.cpp */ |