| 1 | /* TextGrid_and_DurationTier.cpp |
| 2 | * |
| 3 | * Copyright (C) 2017-2019 David Weenink, 2017,2028,2026 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 3 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. See the GNU |
| 13 | * 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 "TextGrid_and_DurationTier.h"cxx . . $ `<file>/dwtools/TextGrid_and_DurationTier.h`/ |
| 20 | #include "Thing.h"cxx . . $ `<file>/sys/Thing.h`/ |
| 21 | |
| 22 | void IntervalTier_DurationTier_scaleTimescxx . . $ IntervalTier_DurationTier_scaleTimes(627e7f0b57862598). (IntervalTiercxx . . $ IntervalTier# me, DurationTiercxx . . $ DurationTier# thee) { |
| 23 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == thycxx . . $ `melder/melder.h:45:9`! xmax, |
| 24 | U"The domains of the IntervalTier and the DurationTier should be equal."); |
| 25 | const double xmax_new = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 26 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! intervalscxx . . $ structIntervalTier#intervals..sizecxx . . $ CollectionOf#size.; i ++) { |
| 27 | const TextIntervalcxx . . $ TextInterval# segment = mycxx . . $ `melder/melder.h:44:9`! intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 28 | const double xmin = RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., segment -> xmincxx . . $ structFunction#xmin.); |
| 29 | const double xmax = RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., segment -> xmaxcxx . . $ structFunction#xmax.); |
| 30 | segment -> xmincxx . . $ structFunction#xmin. = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + xmin; |
| 31 | segment -> xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + xmax; |
| 32 | } |
| 33 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = xmax_new; |
| 34 | } |
| 35 | |
| 36 | void TextTier_DurationTier_scaleTimescxx . . $ TextTier_DurationTier_scaleTimes(ed3b128a8738e9e0). (TextTiercxx . . $ TextTier# me, DurationTiercxx . . $ DurationTier# thee) { |
| 37 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == thycxx . . $ `melder/melder.h:45:9`! xmax, |
| 38 | U"The domains of the TextTier and the DurationTier should be equal."); |
| 39 | const double xmax_new = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 40 | for (integercxx . . $ integer# ipoint = 1; ipoint <= mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structTextTier#points..sizecxx . . $ CollectionOf#size.; ipoint ++) { |
| 41 | const TextPointcxx . . $ TextPoint# point = mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structTextTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint]; |
| 42 | const double time = RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., point -> numbercxx . . $ structSimpleDouble#number.); |
| 43 | point -> numbercxx . . $ structSimpleDouble#number. = time; |
| 44 | } |
| 45 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = xmax_new; |
| 46 | } |
| 47 | |
| 48 | autoTextGridcxx . . $ autoTextGrid# TextGrid_DurationTier_scaleTimescxx . . $ TextGrid_DurationTier_scaleTimes(a6e7eb616d59cfb7). (TextGridcxx . . $ TextGrid# me, DurationTiercxx . . $ DurationTier# thee) { |
| 49 | try { |
| 50 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == thycxx . . $ `melder/melder.h:45:9`! xmax, |
| 51 | U"The domains of the TextGrid and the DurationTier should be equal."); |
| 52 | |
| 53 | const double xmax_new = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + RealTier_getAreacxx . . $ RealTier_getArea(275ea9f7b70e8f4c). (thee, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 54 | autoTextGridcxx . . $ autoTextGrid# him = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 55 | const integercxx . . $ integer# numberOfTiers = mycxx . . $ `melder/melder.h:44:9`! tierscxx . . $ structTextGrid#tiers.->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size.; |
| 56 | for (integercxx . . $ integer# itier = 1; itier <= numberOfTiers; itier ++) { |
| 57 | Functioncxx . . $ Function# anyTier = hiscxx . . $ `melder/melder.h:47:9`! tierscxx . . $ structTextGrid#tiers.->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).itier]; |
| 58 | if (anyTier -> classInfocxx . . $ structThing#classInfo. == classIntervalTiercxx . . $ classIntervalTier.) { |
| 59 | const IntervalTiercxx . . $ IntervalTier# tier = static_cast <IntervalTiercxx . . $ IntervalTier#> (anyTier); |
| 60 | IntervalTier_DurationTier_scaleTimescxx . . $ IntervalTier_DurationTier_scaleTimes(627e7f0b57862598). (tier, thee); |
| 61 | } else { |
| 62 | const TextTiercxx . . $ TextTier# textTier = static_cast <TextTiercxx . . $ TextTier#> (anyTier); |
| 63 | TextTier_DurationTier_scaleTimescxx . . $ TextTier_DurationTier_scaleTimes(ed3b128a8738e9e0). (textTier, thee); |
| 64 | } |
| 65 | } |
| 66 | hiscxx . . $ `melder/melder.h:47:9`! xmaxcxx . . $ structFunction#xmax. = xmax_new; |
| 67 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 68 | |
| 69 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 70 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no time-scaled TextGrid created."); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | autoDurationTiercxx . . $ autoDurationTier# TextGrid_to_DurationTiercxx . . $ TextGrid_to_DurationTier(d3777eec9fff7c4b). (TextGridcxx . . $ TextGrid# me, integercxx . . $ integer# tierNumber, |
| 75 | double timeScalefactor, double leftTransitionDuration, double rightTransitionDuration, kMelder_stringcxx . . $ kMelder_string# which, conststring32cxx . . $ conststring32# criterion) |
| 76 | { |
| 77 | try { |
| 78 | autoDurationTiercxx . . $ autoDurationTier# him = DurationTier_createcxx . . $ DurationTier_create(a86647bd247c7eaf). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 79 | const IntervalTiercxx . . $ IntervalTier# tier = TextGrid_checkSpecifiedTierIsIntervalTiercxx . . $ TextGrid_checkSpecifiedTierIsIntervalTier(45438f647f7429e7). (me, tierNumber); |
| 80 | for (integercxx . . $ integer# i = 1; i <= tier ->intervalscxx . . $ structIntervalTier#intervals..sizecxx . . $ CollectionOf#size.; i ++) { |
| 81 | const TextIntervalcxx . . $ TextInterval# segment = tier -> intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 82 | if (Melder_stringMatchesCriterioncxx . . $ Melder_stringMatchesCriterion(3e677ada61cce709). (segment -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), which, criterion, true)) { |
| 83 | const double xmin = segment -> xmincxx . . $ structFunction#xmin., xmax = segment -> xmaxcxx . . $ structFunction#xmax.; |
| 84 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmin, 1.0); |
| 85 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmin + leftTransitionDuration, timeScalefactor); |
| 86 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmax - rightTransitionDuration, timeScalefactor); |
| 87 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmax, 1.0); |
| 88 | } |
| 89 | } |
| 90 | const integercxx . . $ integer# index = tier ->intervalscxx . . $ structIntervalTier#intervals..sizecxx . . $ CollectionOf#size.; |
| 91 | if (index == 0) |
| 92 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., 1.0); |
| 93 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 94 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 95 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U":cannot create DurationTier."); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /* End of file TextGrid_and_DurationTier.cpp */ |