| 1 | /* Label.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2007,2011,2012,2015-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 "Label.h"cxx . . $ `<file>/fon/Label.h`/ |
| 20 | |
| 21 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Autosegment, Function, 0); |
| 22 | |
| 23 | void structAutosegmentcxx . . $ structAutosegment# :: v1_copycxx . . $ structAutosegment#v1_copy(42659c2335f2eda7). (Daatacxx . . $ Daata# thee_Daata) const { |
| 24 | Autosegmentcxx . . $ Autosegment# thee = static_cast <Autosegmentcxx . . $ Autosegment#> (thee_Daata); |
| 25 | Autosegment_Parentcxx . . $ Autosegment_Parent# :: v1_copycxx . . $ structFunction#v1_copy(42659c2335f2eda7). (thee); |
| 26 | if (namecxx . . $ structThing#name.) Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (thee, namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 27 | } |
| 28 | |
| 29 | bool structAutosegmentcxx . . $ structAutosegment# :: v1_equalcxx . . $ structAutosegment#v1_equal(de90b88e0a4bb7f7). (Daatacxx . . $ Daata# thee_Daata) { |
| 30 | Autosegmentcxx . . $ Autosegment# thee = static_cast <Autosegmentcxx . . $ Autosegment#> (thee_Daata); |
| 31 | if (! Autosegment_Parentcxx . . $ Autosegment_Parent# :: v1_equalcxx . . $ structFunction#v1_equal(de90b88e0a4bb7f7). (thee)) return false; |
| 32 | if (! ourcxx . . $ `melder/melder.h:42:9`! namecxx . . $ structThing#name. && ! thycxx . . $ `melder/melder.h:45:9`! namecxx . . $ structThing#name.) return true; // shortcut: no names |
| 33 | if (! ourcxx . . $ `melder/melder.h:42:9`! namecxx . . $ structThing#name. || ! thycxx . . $ `melder/melder.h:45:9`! namecxx . . $ structThing#name.) return false; |
| 34 | return str32equcxx . . $ `melder/melder_str32.h:122:9`! (ourcxx . . $ `melder/melder.h:42:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), thycxx . . $ `melder/melder.h:45:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 35 | } |
| 36 | |
| 37 | static struct structData_Descriptioncxx . . $ structData_Description# theAutosegment_descriptioncxx . . $ theAutosegment_description. [] = { |
| 38 | { U"Autosegment", inheritwacxx . . $ `sys/Data.h:354:9`!, 0, sizeof (struct structAutosegmentcxx . . $ structAutosegment#), U"Autosegment", & theClassInfo_Functioncxx . . $ theClassInfo_Function., 0, nullptr, nullptr, nullptr, nullptr }, |
| 39 | { U"name", stringwacxx . . $ `sys/Data.h:346:9`!, Melder_offsetofcxx . . $ `melder/melder.h:108:9`! (Autosegment, name), sizeof (char32cxx . . $ char32# *), nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
| 40 | { } }; |
| 41 | Data_Descriptioncxx . . $ Data_Description# structAutosegmentcxx . . $ structAutosegment# :: s_descriptioncxx . . $ structAutosegment#s_description. = & theAutosegment_descriptioncxx . . $ theAutosegment_description. [0]; |
| 42 | |
| 43 | autoAutosegmentcxx . . $ autoAutosegment# Autosegment_createcxx . . $ Autosegment_create(2559363179d15401). (double tmin, double tmax, conststring32cxx . . $ conststring32# label) { |
| 44 | try { |
| 45 | autoAutosegmentcxx . . $ autoAutosegment# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Autosegment); |
| 46 | Function_initcxx . . $ Function_init(ac72a71dd6ac1bfb). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax); |
| 47 | if (label) { |
| 48 | Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), label); |
| 49 | } |
| 50 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 51 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 52 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Autosegment not created."); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /********** class Tier **********/ |
| 57 | |
| 58 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Tier, Sorted, 0); |
| 59 | |
| 60 | integercxx . . $ integer# Tier_timeToIndexcxx . . $ Tier_timeToIndex(526b277bcb3b0da8). (Tiercxx . . $ Tier# me, double time) { |
| 61 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; i ++) { |
| 62 | Autosegmentcxx . . $ Autosegment# interval = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 63 | if (time >= interval -> xmincxx . . $ structFunction#xmin. && time < interval -> xmaxcxx . . $ structFunction#xmax.) |
| 64 | return i; |
| 65 | } |
| 66 | return 0; // empty tier or very large time |
| 67 | } |
| 68 | |
| 69 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Label, Ordered, 0); |
| 70 | |
| 71 | void Label_addTiercxx . . $ Label_addTier(ef1825dee7b20bc0). (Labelcxx . . $ Label# me) { |
| 72 | autoTiercxx . . $ autoTier# tier = Tier_createcxx . . $ Tier_create(320f4cc6d89ddce4). (); |
| 73 | mycxx . . $ `melder/melder.h:44:9`! addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (tiercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 74 | } |
| 75 | |
| 76 | void Label_suggestDomaincxx . . $ Label_suggestDomain(15016e53206a5452). (Labelcxx . . $ Label# me, double *tmin, double *tmax) { |
| 77 | *tmin = 0.0; |
| 78 | *tmax = 0.0; |
| 79 | for (int itier = 1; itier <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; itier ++) { |
| 80 | Tiercxx . . $ Tier# tier = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).itier]; |
| 81 | if (tier->sizecxx . . $ CollectionOf#size. > 0) { |
| 82 | Autosegmentcxx . . $ Autosegment# seg = tier->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]; |
| 83 | if (seg -> xmincxx . . $ structFunction#xmin. <= *tmin) { |
| 84 | if (seg -> namecxx . . $ structThing#name. && seg -> namecxx . . $ structThing#name. [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]) |
| 85 | *tmin = seg -> xmincxx . . $ structFunction#xmin. - 1.0; |
| 86 | else |
| 87 | *tmin = seg -> xmincxx . . $ structFunction#xmin.; |
| 88 | } |
| 89 | seg = tier->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).tier->sizecxx . . $ CollectionOf#size.]; |
| 90 | if (seg -> xmaxcxx . . $ structFunction#xmax. >= *tmax) |
| 91 | *tmax = seg -> xmaxcxx . . $ structFunction#xmax.; |
| 92 | } |
| 93 | } |
| 94 | *tmax += 1.0; |
| 95 | } |
| 96 | |
| 97 | /* End of file Label.cpp */ |