| 1 | #ifndef _TextGridEditor_h_ |
| 2 | #define _TextGridEditor_h_ |
| 3 | /* TextGridEditor.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2005,2007-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 "FunctionEditor.h" |
| 22 | #include "TextGridArea.h" |
| 23 | #include "LongSoundArea.h" |
| 24 | #include "SoundAnalysisArea.h" |
| 25 | |
| 26 | Thing_define (TextGridEditor, FunctionEditor) { |
| 27 | DEFINE_FunctionArea (1, TextGridArea, textGridArea) |
| 28 | DEFINE_FunctionArea (2, SoundArea, soundArea) |
| 29 | DEFINE_FunctionArea (3, SoundAnalysisArea, soundAnalysisArea) |
| 30 | |
| 31 | TextGrid textGrid() { return static_cast <TextGrid> (our data()); } |
| 32 | |
| 33 | void v_createMenuItems_help (EditorMenu menu) |
| 34 | override; |
| 35 | void v1_dataChanged (Editor sender) override { |
| 36 | Melder_clipRight (& our textGridArea() -> selectedTier, our textGrid() -> tiers->size); // crucial: before v_updateText (bug 2022-07-23)! |
| 37 | our structFunctionEditor :: v1_dataChanged (sender); |
| 38 | our textGridArea() -> functionChanged (our textGrid()); |
| 39 | if (our soundArea()) { |
| 40 | our soundArea() -> functionChanged (nullptr); // BUG: this function has not actually changed |
| 41 | our soundAnalysisArea() -> functionChanged (our soundArea() -> function()); |
| 42 | } |
| 43 | } |
| 44 | void v_distributeAreas () override { |
| 45 | if (our soundArea()) { |
| 46 | const bool showAnalysis = our soundAnalysisArea() -> hasContentToShow(); |
| 47 | const integer numberOfTiers = our textGrid() -> tiers->size; |
| 48 | const integer numberOfVisibleChannels = |
| 49 | Melder_clippedRight (our soundArea() -> soundOrLongSound() -> ny, 8_integer); |
| 50 | const double soundY = numberOfTiers / (2.0 * numberOfVisibleChannels + |
| 51 | numberOfTiers * ( showAnalysis ? 1.8 : 1.3 )); |
| 52 | our textGridArea() -> setGlobalYRange_fraction (0.0, soundY); |
| 53 | if (showAnalysis) { |
| 54 | const double soundY2 = 0.5 * (1.0 + soundY); |
| 55 | our soundAnalysisArea() -> setGlobalYRange_fraction (soundY, soundY2); |
| 56 | our soundArea() -> setGlobalYRange_fraction (soundY2, 1.0); |
| 57 | } else { |
| 58 | our soundAnalysisArea() -> setGlobalYRange_fraction (soundY, soundY); |
| 59 | our soundArea() -> setGlobalYRange_fraction (soundY, 1.0); |
| 60 | } |
| 61 | } else { |
| 62 | our textGridArea() -> setGlobalYRange_fraction (0.0, 1.0); |
| 63 | } |
| 64 | } |
| 65 | void v_draw () override { |
| 66 | if (our soundArea()) { |
| 67 | FunctionArea_prepareCanvas (our soundArea().get()); |
| 68 | if (our soundAnalysisArea() -> instancePref_pulses_show()) |
| 69 | our soundAnalysisArea() -> v_draw_analysis_pulses (); |
| 70 | FunctionArea_drawInside (our soundArea().get()); |
| 71 | if (our soundAnalysisArea() -> hasContentToShow()) { |
| 72 | FunctionArea_prepareCanvas (our soundAnalysisArea().get()); |
| 73 | our soundAnalysisArea() -> v_draw_analysis (); |
| 74 | } |
| 75 | } |
| 76 | FunctionArea_drawOne (our textGridArea().get()); |
| 77 | } |
| 78 | bool v_hasText () override { return true; } |
| 79 | bool v_hasSelectionViewer () override { return true; } |
| 80 | void v_drawSelectionViewer () override { |
| 81 | TextGridArea_drawSelectionViewer (our textGridArea().get()); |
| 82 | } |
| 83 | void v_drawRealTimeSelectionViewer (double /* time */) override { |
| 84 | TextGridArea_drawSelectionViewer (our textGridArea().get()); // avoid discontinuity during play |
| 85 | } |
| 86 | |
| 87 | void v_clickSelectionViewer (double x_fraction, double y_fraction) override { |
| 88 | TextGridArea_clickSelectionViewer (our textGridArea().get(), x_fraction, y_fraction); |
| 89 | } |
| 90 | conststring32 v_selectionViewerName () |
| 91 | override { return U"IPA chart"; } |
| 92 | void v_play (double startTime, double endTime) override { |
| 93 | if (our soundArea()) |
| 94 | SoundArea_play (our soundArea().get(), startTime, endTime); |
| 95 | } |
| 96 | void v_drawLegends () override { |
| 97 | FunctionArea_drawLegend (our textGridArea().get(), |
| 98 | FunctionArea_legend_TEXTGRID U" ##modifiable TextGrid", |
| 99 | DataGui_defaultForegroundColour (our textGridArea().get(), false) |
| 100 | ); |
| 101 | if (our soundArea()) { |
| 102 | const bool pulsesAreVisible = our soundAnalysisArea() -> hasPulsesToShow (); |
| 103 | FunctionArea_drawLegend (our soundArea().get(), |
| 104 | FunctionArea_legend_WAVEFORM U" %%non-modifiable copy of sound", |
| 105 | DataGui_defaultForegroundColour (our soundArea().get(), false), |
| 106 | pulsesAreVisible ? FunctionArea_legend_POLES U" %%derived pulses" : nullptr, |
| 107 | Melder_GREY |
| 108 | ); |
| 109 | SoundAnalysisArea_drawDefaultLegends (our soundAnalysisArea().get()); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #include "TextGridEditor_prefs.h" |
| 114 | }; |
| 115 | |
| 116 | autoTextGridEditor TextGridEditor_create (conststring32 title, TextGrid grid, |
| 117 | SampledXY sound, // either a Sound or a LongSound, or null |
| 118 | SpellingChecker spellingChecker, |
| 119 | conststring32 callbackSocket |
| 120 | ); |
| 121 | |
| 122 | /* End of file TextGridEditor.h */ |
| 123 | #endif |