| 1 | #ifndef _TextGrid_h_ |
| 2 | #define _TextGrid_h_ |
| 3 | /* TextGrid.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2012,2014-2018,2020,2021,2024,2025 Paul Boersma |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "AnyTier.h" |
| 22 | #include "Label.h" |
| 23 | #include "Graphics.h" |
| 24 | #include "TableOfReal.h" |
| 25 | #include "Table.h" |
| 26 | |
| 27 | #include "TextGrid_def.h" |
| 28 | |
| 29 | autoTextPoint TextPoint_create (double time, conststring32 mark); |
| 30 | |
| 31 | void TextPoint_setText (TextPoint me, conststring32 text); |
| 32 | |
| 33 | autoTextInterval TextInterval_create (double tmin, double tmax, conststring32 text); |
| 34 | |
| 35 | void TextInterval_setText (TextInterval me, conststring32 text); |
| 36 | |
| 37 | autoTextTier TextTier_create (double tmin, double tmax); |
| 38 | |
| 39 | void TextTier_addPoint (TextTier me, double time, conststring32 mark); |
| 40 | autoPointProcess TextTier_getPoints (TextTier me, conststring32 text); |
| 41 | |
| 42 | autoIntervalTier IntervalTier_create_raw (double tmin, double tmax); |
| 43 | |
| 44 | TextInterval /* reference */ IntervalTier_addInterval_raw ( |
| 45 | IntervalTier me, // the tier to which the new interval shall be added |
| 46 | double tmin, // the starting time of the new interval |
| 47 | double tmax, // the end time of the new interval |
| 48 | conststring32 text // the label of the new interval |
| 49 | ); |
| 50 | /* |
| 51 | This attempts to add a new interval to an existing tier. |
| 52 | Because the intervals in an IntervalTier form a sorted set, |
| 53 | the attempt will fail if there is already an interval with the same starting interval. |
| 54 | |
| 55 | This function is called "raw" because no attempt is made to keep the IntervalTier |
| 56 | in a valid state. Most notably, the caller will have to make sure |
| 57 | that after a series of calls to this function |
| 58 | the invariants of the IntervalTier (i.e. adjacent time ranges) will have to be restored. |
| 59 | |
| 60 | The return value is a reference to the new TextInterval, |
| 61 | or null of the attempt failed. |
| 62 | */ |
| 63 | |
| 64 | void IntervalTier_haveAtLeastOneInterval (IntervalTier me); |
| 65 | |
| 66 | autoIntervalTier IntervalTier_create (double tmin, double tmax); |
| 67 | |
| 68 | integer IntervalTier_timeToLowIndex (IntervalTier me, double t); |
| 69 | integer IntervalTier_timeToIndex (IntervalTier me, double t); // obsolete |
| 70 | integer IntervalTier_timeToHighIndex (IntervalTier me, double t); |
| 71 | integer IntervalTier_hasTime (IntervalTier me, double t); |
| 72 | integer IntervalTier_hasBoundary (IntervalTier me, double t); |
| 73 | autoPointProcess IntervalTier_getStartingPoints (IntervalTier me, conststring32 text); |
| 74 | autoPointProcess IntervalTier_getEndPoints (IntervalTier me, conststring32 text); |
| 75 | autoPointProcess IntervalTier_getCentrePoints (IntervalTier me, conststring32 text); |
| 76 | autoPointProcess IntervalTier_PointProcess_startToCentre (IntervalTier tier, PointProcess point, double phase); |
| 77 | autoPointProcess IntervalTier_PointProcess_endToCentre (IntervalTier tier, PointProcess point, double phase); |
| 78 | void IntervalTier_removeLeftBoundary (IntervalTier me, integer intervalNumber); |
| 79 | void IntervalTier_moveLeftBoundary (IntervalTier me, integer interval, double newTime); |
| 80 | void IntervalTier_moveRightBoundary (IntervalTier me, integer interval, double newTime); |
| 81 | |
| 82 | void TextTier_removePoint (TextTier me, integer pointNumber); |
| 83 | |
| 84 | autoTextGrid TextGrid_createWithoutTiers (double tmin, double tmax); |
| 85 | autoTextGrid TextGrid_create (double tmin, double tmax, conststring32 tierNames, conststring32 pointTiers); |
| 86 | |
| 87 | integer TextGrid_countLabels (TextGrid me, integer itier, conststring32 text); |
| 88 | integer TextGrid_countIntervalsWhere (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 89 | integer TextGrid_countPointsWhere (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 90 | autoPointProcess TextGrid_getStartingPoints (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 91 | autoPointProcess TextGrid_getEndPoints (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 92 | autoPointProcess TextGrid_getCentrePoints (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 93 | autoPointProcess TextGrid_getPoints (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 94 | autoPointProcess TextGrid_getPoints_preceded (TextGrid me, integer tierNumber, |
| 95 | kMelder_string which, conststring32 criterion, |
| 96 | kMelder_string precededBy, conststring32 criterion_precededBy); |
| 97 | autoPointProcess TextGrid_getPoints_followed (TextGrid me, integer tierNumber, |
| 98 | kMelder_string which, conststring32 criterion, |
| 99 | kMelder_string followedBy, conststring32 criterion_followedBy); |
| 100 | |
| 101 | Function TextGrid_checkSpecifiedTierNumberWithinRange (TextGrid me, integer tierNumber); |
| 102 | IntervalTier TextGrid_checkSpecifiedTierIsIntervalTier (TextGrid me, integer tierNumber); |
| 103 | TextTier TextGrid_checkSpecifiedTierIsPointTier (TextGrid me, integer tierNumber); |
| 104 | void AnyTextGridTier_identifyClass (Function anyTextGridTier, IntervalTier *intervalTier, TextTier *textTier); |
| 105 | |
| 106 | void TextGrid_addTier_copy (TextGrid me, Function tier); |
| 107 | void TextGrid_addTier_move (TextGrid me, autoFunction tier); |
| 108 | |
| 109 | autoTextGrid TextGrids_merge (OrderedOf <structTextGrid>* textGrids, bool equalizeDomains); |
| 110 | /* |
| 111 | Merge two or more textGrids. |
| 112 | The new domain will run from |
| 113 | min (textGrids[] -> xmin) |
| 114 | to |
| 115 | max (textGrids[] -> xmax) |
| 116 | |
| 117 | If `equalizeDomains`: |
| 118 | - All tiers will have this same domain. |
| 119 | - All interval tiers will have intervals that border on the edges of this domain; |
| 120 | this implies that a new empty interval can be added at the beginning and/or end of a tier. |
| 121 | */ |
| 122 | |
| 123 | autoTextGrid TextGrid_extractPart (TextGrid me, double tmin, double tmax, bool preserveTimes); |
| 124 | |
| 125 | autoTextGrid Label_to_TextGrid (Label me, double duration); |
| 126 | autoTextGrid Label_Function_to_TextGrid (Label me, Function function); |
| 127 | |
| 128 | autoTextTier PointProcess_upto_TextTier (PointProcess me, conststring32 text); |
| 129 | autoTableOfReal IntervalTier_downto_TableOfReal (IntervalTier me, conststring32 label); |
| 130 | autoTableOfReal IntervalTier_downto_TableOfReal_any (IntervalTier me); |
| 131 | autoTableOfReal TextTier_downto_TableOfReal (TextTier me, conststring32 label); |
| 132 | autoTableOfReal TextTier_downto_TableOfReal_any (TextTier me); |
| 133 | |
| 134 | autoTextGrid PointProcess_to_TextGrid_vuv (PointProcess me, double maxT, double meanT); |
| 135 | |
| 136 | integer TextInterval_labelLength (TextInterval me); |
| 137 | integer TextPoint_labelLength (TextPoint me); |
| 138 | integer IntervalTier_maximumLabelLength (IntervalTier me); |
| 139 | integer TextTier_maximumLabelLength (TextTier me); |
| 140 | integer TextGrid_maximumLabelLength (TextGrid me); |
| 141 | void TextGrid_convertToBackslashTrigraphs (TextGrid me); |
| 142 | void TextGrid_convertToUnicode (TextGrid me); |
| 143 | |
| 144 | void TextInterval_removeText (TextInterval me); |
| 145 | void TextPoint_removeText (TextPoint me); |
| 146 | void IntervalTier_removeText (IntervalTier me); |
| 147 | void TextTier_removeText (TextTier me); |
| 148 | |
| 149 | void TextTier_removePoints (TextTier me, kMelder_string which, conststring32 criterion); |
| 150 | void TextGrid_removePoints (TextGrid me, integer tierNumber, kMelder_string which, conststring32 criterion); |
| 151 | |
| 152 | void TextGrid_insertBoundary (TextGrid me, integer tierNumber, double t); |
| 153 | void TextGrid_removeBoundaryAtTime (TextGrid me, integer tierNumber, double t); |
| 154 | void TextGrid_setIntervalText (TextGrid me, integer tierNumber, integer intervalNumber, conststring32 text); |
| 155 | void TextGrid_insertPoint (TextGrid me, integer tierNumber, double t, conststring32 mark); |
| 156 | void TextGrid_setPointText (TextGrid me, integer tierNumber, integer pointNumber, conststring32 text); |
| 157 | |
| 158 | autoTable TextGrid_downto_Table (TextGrid me, bool includeLineNumbers, integer timeDecimals, bool includeTierNames, bool includeEmptyIntervals); |
| 159 | autoTable TextGrid_tabulateOccurrences (TextGrid me, constVEC searchTiers, |
| 160 | kMelder_string which, conststring32 criterion, bool caseSensitive); |
| 161 | void TextGrid_list (TextGrid me, bool includeLineNumbers, integer timeDecimals, bool includeTierNames, |
| 162 | bool includeEmptyIntervals); |
| 163 | |
| 164 | void TextGrid_correctRoundingErrors (TextGrid me); |
| 165 | autoTextGrid TextGrids_concatenate (OrderedOf<structTextGrid>* me); |
| 166 | |
| 167 | /* |
| 168 | Defined in TextGrid_files.cpp |
| 169 | */ |
| 170 | |
| 171 | autoTextGrid TextGrid_readFromEspsLabelFile ( |
| 172 | MelderFile file, |
| 173 | bool tiersArePointTiers, |
| 174 | integer overrideNumberOfTiers // 0 means don't override |
| 175 | ); |
| 176 | void IntervalTier_writeToXwaves (IntervalTier me, MelderFile file); |
| 177 | |
| 178 | void TextGrid_writeToChronologicalTextFile (TextGrid me, MelderFile file); |
| 179 | autoTextGrid TextGrid_readFromChronologicalTextFile (MelderFile file); |
| 180 | autoTextGrid TextGrid_readFromCgnSyntaxFile (MelderFile file); |
| 181 | |
| 182 | autoIntervalTier IntervalTier_readFromTimitLabelFile (MelderFile file, bool hasPhones); |
| 183 | autoTextGrid TextGrid_readFromTimitLabelFile (MelderFile file, bool hasPhones); |
| 184 | /* |
| 185 | Read TIMIT label file with the following structure: |
| 186 | samplenumber1 samplenumber2 label1 |
| 187 | samplenumber3 samplenumber4 label2 |
| 188 | ... |
| 189 | samplenumber2n-1 samplenumber2n labeln |
| 190 | |
| 191 | The first tier of TextGrid will contain the TIMIT labels. |
| 192 | If phnFile == true, the second tier will contain the translation of the |
| 193 | TIMIT labels into IPA labels. |
| 194 | For the translation from sample number to time a default sampling |
| 195 | frequency of 16000 Hz is assumed. |
| 196 | */ |
| 197 | |
| 198 | autoDaata TextGrid_TIMITLabelFileRecognizer (integer nread, const char *header, MelderFile file); |
| 199 | /* |
| 200 | There are two types of TIMIT label files. One with phonetic labels, these |
| 201 | files have '.phn' as file extension. The other contains word labels and has |
| 202 | '.wrd' as extension. Since these extensions are only valid on the CDROM we can |
| 203 | not use them for filetype recognition. Both TIMIT label files do not have a |
| 204 | self-describing format. For filetype recognition we make use of the fact that |
| 205 | both files are text files and always have three items on each line: two numbers |
| 206 | followed by a string. The numbers increase in a monotone way. |
| 207 | The recognizer only checks the first two lines and it tests whether |
| 208 | 0 <= number 1] < number [2] <= number [3] < number [4] |
| 209 | (A number of .wrd files do not obey the monotonocity constraint for |
| 210 | number [4] and number [5] !) |
| 211 | The decision whether it is a .phn or .wrd file is: |
| 212 | .phn if string [1] == 'h#' AND string [2] is a TIMIT phonetic label |
| 213 | .wrd if (string [1] == 'h#' AND string [2] is a valid word) OR |
| 214 | string [1] and string [2] are both valid words. |
| 215 | A valid word is a string with contains the lowercase characters [a-z] and [']. |
| 216 | */ |
| 217 | |
| 218 | void TextGrid_checkInvariants_e (const constTextGrid me, const bool includeWeakInvariants); |
| 219 | |
| 220 | void TextGrid_scaleTimes_e (mutableTextGrid me, double xminfrom, double xmaxfrom, double xminto, double xmaxto); |
| 221 | |
| 222 | /* End of file TextGrid.h */ |
| 223 | #endif |