| 1 | /* FormantGrid_extensions.cpp |
| 2 | * |
| 3 | * Copyright (C) 2009-2019 David Weenink, 2015 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. 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 "FormantGrid_extensions.h"cxx . . $ `<file>/dwtools/FormantGrid_extensions.h`/ |
| 20 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 21 | |
| 22 | void FormantGrid_drawcxx . . $ FormantGrid_draw(332b42685e5cc294). (FormantGridcxx . . $ FormantGrid# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, |
| 23 | bool bandwidths, bool garnish, conststring32cxx . . $ conststring32# method) |
| 24 | { |
| 25 | OrderedOfcxx . . $ OrderedOf#<structRealTiercxx . . $ structRealTier#>* tiers = ( bandwidths ? & mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths. : & mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants. ); |
| 26 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & xmin, & xmax); |
| 27 | if (ymax <= ymin) { |
| 28 | ymin = 0.0; |
| 29 | ymax = ( bandwidths ? 1000.0 : 8000.0 ); |
| 30 | } |
| 31 | for (integercxx . . $ integer# iformant = 1; iformant <= tiers->sizecxx . . $ CollectionOf#size.; iformant ++) { |
| 32 | conststring32cxx . . $ conststring32# quantity = nullptr; |
| 33 | bool garnish2 = false; |
| 34 | const RealTiercxx . . $ RealTier# tier = tiers->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]; |
| 35 | if (iformant == mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size.) { |
| 36 | quantity = U"Frequency (Hz)"; |
| 37 | if (garnish) |
| 38 | garnish2 = true; |
| 39 | } |
| 40 | RealTier_drawcxx . . $ RealTier_draw(91d4c8857589b937). (tier, g, xmin, xmax, ymin, ymax, garnish2, method, quantity); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | static void FormantGrid_removeFormantTiercxx . . $ FormantGrid_removeFormantTier(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 45 | if (position < 1 || position > mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size.) |
| 46 | return; |
| 47 | mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants.. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (position); |
| 48 | } |
| 49 | |
| 50 | static void FormantGrid_removeBandwidthTiercxx . . $ FormantGrid_removeBandwidthTier(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 51 | if (position < 1 || position > mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths..sizecxx . . $ CollectionOf#size.) |
| 52 | return; |
| 53 | mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths.. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (position); |
| 54 | } |
| 55 | |
| 56 | void FormantGrid_removeFormantAndBandwidthTierscxx . . $ FormantGrid_removeFormantAndBandwidthTiers(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 57 | FormantGrid_removeFormantTiercxx . . $ FormantGrid_removeFormantTier(47ebe458dfc3e98c). (me, position); |
| 58 | FormantGrid_removeBandwidthTiercxx . . $ FormantGrid_removeBandwidthTier(47ebe458dfc3e98c). (me, position); |
| 59 | } |
| 60 | |
| 61 | static void FormantGrid_addFormantTiercxx . . $ FormantGrid_addFormantTier(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 62 | if (position > mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size. || position < 1) |
| 63 | position = mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size. + 1; |
| 64 | autoRealTiercxx . . $ autoRealTier# rt = RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 65 | mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants.. addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (rtcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), position); |
| 66 | } |
| 67 | |
| 68 | static void FormantGrid_addBandwidthTiercxx . . $ FormantGrid_addBandwidthTier(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 69 | if (position > mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths..sizecxx . . $ CollectionOf#size. || position < 1) |
| 70 | position = mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths..sizecxx . . $ CollectionOf#size. + 1; |
| 71 | autoRealTiercxx . . $ autoRealTier# rt = RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 72 | mycxx . . $ `melder/melder.h:44:9`! bandwidthscxx . . $ structFormantGrid#bandwidths.. addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (rtcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), position); |
| 73 | } |
| 74 | |
| 75 | void FormantGrid_addFormantAndBandwidthTierscxx . . $ FormantGrid_addFormantAndBandwidthTiers(47ebe458dfc3e98c). (FormantGridcxx . . $ FormantGrid# me, integercxx . . $ integer# position) { |
| 76 | try { |
| 77 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! formants.size == mycxx . . $ `melder/melder.h:44:9`! bandwidths.size, |
| 78 | U"Number of formants and bandwidths should be equal."); |
| 79 | |
| 80 | if (position > mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size. || position < 1) |
| 81 | position = mycxx . . $ `melder/melder.h:44:9`! formantscxx . . $ structFormantGrid#formants..sizecxx . . $ CollectionOf#size. + 1; |
| 82 | FormantGrid_addFormantTiercxx . . $ FormantGrid_addFormantTier(47ebe458dfc3e98c). (me, position); |
| 83 | try { |
| 84 | FormantGrid_addBandwidthTiercxx . . $ FormantGrid_addBandwidthTier(47ebe458dfc3e98c). (me, position); |
| 85 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 86 | FormantGrid_removeFormantTiercxx . . $ FormantGrid_removeFormantTier(47ebe458dfc3e98c). (me, position); |
| 87 | throw; |
| 88 | } |
| 89 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 90 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no ties added."); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /* End of file FormantGrid_extensions.cpp */ |