| 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" |
| 20 |
#include "NUM2.h" |
| 21 |
|
| 22 |
void FormantGrid_draw (FormantGrid me, Graphics g, double xmin, double xmax, double ymin, double ymax, |
| 23 |
bool bandwidths, bool garnish, conststring32 method) |
| 24 |
{ |
| 25 |
OrderedOf<structRealTier>* tiers = ( bandwidths ? & my bandwidths : & my formants ); |
| 26 |
Function_unidirectionalAutowindow (me, & xmin, & xmax); |
| 27 |
if (ymax <= ymin) { |
| 28 |
ymin = 0.0; |
| 29 |
ymax = ( bandwidths ? 1000.0 : 8000.0 ); |
| 30 |
} |
| 31 |
for (integer iformant = 1; iformant <= tiers->size; iformant ++) { |
| 32 |
conststring32 quantity = nullptr; |
| 33 |
bool garnish2 = false; |
| 34 |
const RealTier tier = tiers->at [iformant]; |
| 35 |
if (iformant == my formants.size) { |
| 36 |
quantity = U"Frequency (Hz)"; |
| 37 |
if (garnish) |
| 38 |
garnish2 = true; |
| 39 |
} |
| 40 |
RealTier_draw (tier, g, xmin, xmax, ymin, ymax, garnish2, method, quantity); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
static void FormantGrid_removeFormantTier (FormantGrid me, integer position) { |
| 45 |
if (position < 1 || position > my formants.size) |
| 46 |
return; |
| 47 |
my formants. removeItem (position); |
| 48 |
} |
| 49 |
|
| 50 |
static void FormantGrid_removeBandwidthTier (FormantGrid me, integer position) { |
| 51 |
if (position < 1 || position > my bandwidths.size) |
| 52 |
return; |
| 53 |
my bandwidths. removeItem (position); |
| 54 |
} |
| 55 |
|
| 56 |
void FormantGrid_removeFormantAndBandwidthTiers (FormantGrid me, integer position) { |
| 57 |
FormantGrid_removeFormantTier (me, position); |
| 58 |
FormantGrid_removeBandwidthTier (me, position); |
| 59 |
} |
| 60 |
|
| 61 |
static void FormantGrid_addFormantTier (FormantGrid me, integer position) { |
| 62 |
if (position > my formants.size || position < 1) |
| 63 |
position = my formants.size + 1; |
| 64 |
autoRealTier rt = RealTier_create (my xmin, my xmax); |
| 65 |
my formants. addItemAtPosition_move (rt.move(), position); |
| 66 |
} |
| 67 |
|
| 68 |
static void FormantGrid_addBandwidthTier (FormantGrid me, integer position) { |
| 69 |
if (position > my bandwidths.size || position < 1) |
| 70 |
position = my bandwidths.size + 1; |
| 71 |
autoRealTier rt = RealTier_create (my xmin, my xmax); |
| 72 |
my bandwidths. addItemAtPosition_move (rt.move(), position); |
| 73 |
} |
| 74 |
|
| 75 |
void FormantGrid_addFormantAndBandwidthTiers (FormantGrid me, integer position) { |
| 76 |
try { |
| 77 |
Melder_require (my formants.size == my bandwidths.size, |
| 78 |
U"Number of formants and bandwidths should be equal."); |
| 79 |
|
| 80 |
if (position > my formants.size || position < 1) |
| 81 |
position = my formants.size + 1; |
| 82 |
FormantGrid_addFormantTier (me, position); |
| 83 |
try { |
| 84 |
FormantGrid_addBandwidthTier (me, position); |
| 85 |
} catch (MelderError) { |
| 86 |
FormantGrid_removeFormantTier (me, position); |
| 87 |
throw; |
| 88 |
} |
| 89 |
} catch (MelderError) { |
| 90 |
Melder_throw (me, U": no ties added."); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/* End of file FormantGrid_extensions.cpp */ |