| 1 | #ifndef _FormantPathEditor_h_ |
| 2 | #define _FormantPathEditor_h_ |
| 3 | /* FormantPathEditor.h |
| 4 | * |
| 5 | * Copyright (C) 2020-2023 David Weenink, 2022 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 2 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 "FormantPathArea.h" |
| 22 | #include "SoundArea.h" |
| 23 | #include "TextGridArea.h" |
| 24 | |
| 25 | Thing_define (FormantPathEditor, FunctionEditor) { |
| 26 | DEFINE_FunctionArea (1, FormantPathArea, formantPathArea) |
| 27 | DEFINE_FunctionArea (2, SoundArea, soundArea) |
| 28 | DEFINE_FunctionArea (3, TextGridArea, textGridArea) |
| 29 | |
| 30 | FormantPath formantPath() { return static_cast <FormantPath> (our data()); } |
| 31 | autoFormant previousFormant; |
| 32 | Graphics_Viewport selectionViewer_viewport; |
| 33 | integer selectedCandidate = 0; |
| 34 | GuiMenuItem navigateSettingsButton, navigateNextButton, navigatePreviousButton; |
| 35 | |
| 36 | void v1_info () |
| 37 | override; |
| 38 | void v_createMenus () |
| 39 | override; |
| 40 | void v_createMenuItems_help (EditorMenu menu) |
| 41 | override; |
| 42 | void v1_dataChanged (Editor sender) override { |
| 43 | FormantPathEditor_Parent :: v1_dataChanged (sender); |
| 44 | if (our soundArea()) |
| 45 | our soundArea() -> functionChanged (nullptr); |
| 46 | our formantPathArea() -> functionChanged (nullptr); |
| 47 | our formantPathArea() -> d_formant = FormantPath_extractFormant (our formantPath()); // BUG: also on window changed |
| 48 | if (our textGridArea()) |
| 49 | our textGridArea() -> functionChanged (nullptr); |
| 50 | } |
| 51 | void v_distributeAreas () override { |
| 52 | if (our soundArea() && our textGridArea()) { |
| 53 | our soundArea() -> setGlobalYRange_fraction (0.7, 1.0); |
| 54 | our formantPathArea() -> setGlobalYRange_fraction (0.2, 0.7); |
| 55 | our textGridArea() -> setGlobalYRange_fraction (0.0, 0.2); |
| 56 | } else if (our soundArea()) { |
| 57 | our soundArea() -> setGlobalYRange_fraction (0.6, 1.0); |
| 58 | our formantPathArea() -> setGlobalYRange_fraction (0.0, 0.6); |
| 59 | } else if (our textGridArea()) { |
| 60 | our formantPathArea() -> setGlobalYRange_fraction (0.3, 1.0); |
| 61 | our textGridArea() -> setGlobalYRange_fraction (0.0, 0.3); |
| 62 | } else { |
| 63 | our formantPathArea() -> setGlobalYRange_fraction (0.1, 1.0); |
| 64 | } |
| 65 | } |
| 66 | void v_draw () override { |
| 67 | if (our soundArea()) { |
| 68 | FunctionArea_prepareCanvas (our soundArea().get()); |
| 69 | if (our formantPathArea() -> instancePref_pulses_show()) |
| 70 | our formantPathArea() -> v_draw_analysis_pulses (); |
| 71 | FunctionArea_drawInside (our soundArea().get()); |
| 72 | if (our formantPathArea() -> hasContentToShow()) { |
| 73 | FunctionArea_prepareCanvas (our formantPathArea().get()); |
| 74 | our formantPathArea() -> v_draw_analysis (); |
| 75 | } |
| 76 | } else { |
| 77 | FunctionArea_prepareCanvas (our formantPathArea().get()); |
| 78 | our formantPathArea() -> v_draw_analysis_formants (); |
| 79 | } |
| 80 | if (our textGridArea()) |
| 81 | FunctionArea_drawOne (our textGridArea().get()); |
| 82 | } |
| 83 | bool v_hasSelectionViewer () override { return true; } |
| 84 | void v_drawSelectionViewer () |
| 85 | override; |
| 86 | void v_drawRealTimeSelectionViewer (double /* time */) override { |
| 87 | v_drawSelectionViewer (); // avoid discontinuity during play |
| 88 | } |
| 89 | void v_clickSelectionViewer (double xWC, double yWC) |
| 90 | override; |
| 91 | void v_play (double startTime, double endTime) |
| 92 | override; |
| 93 | bool v_hasText () |
| 94 | override { return false; } |
| 95 | void v_updateText () |
| 96 | override { }; |
| 97 | conststring32 v_selectionViewerName () |
| 98 | override { return U"Formant candidates"; } |
| 99 | void v_drawLegends () override { |
| 100 | FormantPathArea you = our formantPathArea().get(); |
| 101 | const bool showAnalyses = ( your endWindow() - your startWindow() <= your instancePref_longestAnalysis() ); |
| 102 | if (showAnalyses) |
| 103 | FunctionArea_drawLegend (our formantPathArea().get(), |
| 104 | your instancePref_spectrogram_show() ? FunctionArea_legend_GREYS U" %%derived spectrogram" : U"", |
| 105 | 1.2 * Melder_BLACK, |
| 106 | your instancePref_intensity_show() ? FunctionArea_legend_LINES U" %%derived intensity" : U"", |
| 107 | 1.2 * Melder_GREEN, |
| 108 | your instancePref_pitch_show() ? FunctionArea_legend_LINES_SPECKLES U" %%derived pitch" : U"", |
| 109 | 1.2 * Melder_BLUE, |
| 110 | FunctionArea_legend_SPECKLES U" ##modifiable FormantPath", |
| 111 | 1.2 * Melder_RED |
| 112 | ); |
| 113 | if (our soundArea()) |
| 114 | FunctionArea_drawLegend (our soundArea().get(), |
| 115 | FunctionArea_legend_WAVEFORM U" %%non-modifiable copy of sound", |
| 116 | DataGui_defaultForegroundColour (our soundArea().get(), false) |
| 117 | ); |
| 118 | if (our textGridArea()) |
| 119 | FunctionArea_drawLegend (our textGridArea().get(), |
| 120 | FunctionArea_legend_TEXTGRID U" %%non-modifiable copy of TextGrid", |
| 121 | DataGui_defaultForegroundColour (our textGridArea().get(), false) |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | #include "FormantPathEditor_prefs.h" |
| 126 | }; |
| 127 | |
| 128 | autoFormantPathEditor FormantPathEditor_create (conststring32 title, FormantPath formantPath, Sound sound, TextGrid textgrid); |
| 129 | |
| 130 | /* End of file FormantPathEditor.h */ |
| 131 | #endif |