| 1 |
/* TextGridArea.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2026 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 3 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 "TextGridArea.h" |
| 20 |
#include "TextGrid_Sound.h" |
| 21 |
#include "SpeechSynthesizer_and_TextGrid.h" |
| 22 |
#include "LongSoundArea.h" // for drawing TextGrid and Sound, or for aligning TextGrid to Sound |
| 23 |
#include "SoundAnalysisArea.h" // for drawing TextGrid and Pitch |
| 24 |
#include "EditorM.h" |
| 25 |
#include "SpeechRecognizer.h" |
| 26 |
|
| 27 |
Thing_implement (TextGridArea, FunctionArea, 0); |
| 28 |
|
| 29 |
#include "enums_getText.h" |
| 30 |
#include "TextGridArea_enums.h" |
| 31 |
#include "enums_getValue.h" |
| 32 |
#include "TextGridArea_enums.h" |
| 33 |
|
| 34 |
#include "Prefs_define.h" |
| 35 |
#include "TextGridArea_prefs.h" |
| 36 |
#include "Prefs_install.h" |
| 37 |
#include "TextGridArea_prefs.h" |
| 38 |
#include "Prefs_copyToInstance.h" |
| 39 |
#include "TextGridArea_prefs.h" |
| 40 |
|
| 41 |
/* |
| 42 |
* The main invariant of the TextGridArea is that the selected interval |
| 43 |
* always has the cursor in it, and that the cursor always selects an interval |
| 44 |
* if the selected tier is an interval tier. |
| 45 |
*/ |
| 46 |
|
| 47 |
static void checkTierSelection (constTextGridArea me, conststring32 verbPhrase) { |
| 48 |
if (my selectedTier < 1 || my selectedTier > my textGrid() -> tiers->size) |
| 49 |
Melder_throw (U"To ", verbPhrase, U", first select a tier by clicking anywhere inside it."); |
| 50 |
} |
| 51 |
static integer getSelectedInterval (constTextGridArea me) { |
| 52 |
Melder_assert (my selectedTier >= 1 || my selectedTier <= my textGrid() -> tiers->size); |
| 53 |
const IntervalTier tier = (IntervalTier) my textGrid() -> tiers->at [my selectedTier]; |
| 54 |
Melder_assert (tier -> classInfo == classIntervalTier); |
| 55 |
return IntervalTier_timeToIndex (tier, my startSelection()); |
| 56 |
} |
| 57 |
|
| 58 |
static integer getSelectedLeftBoundary (constTextGridArea me) { |
| 59 |
Melder_assert (my selectedTier >= 1 || my selectedTier <= my textGrid() -> tiers->size); |
| 60 |
const IntervalTier tier = (IntervalTier) my textGrid() -> tiers->at [my selectedTier]; |
| 61 |
Melder_assert (tier -> classInfo == classIntervalTier); |
| 62 |
return IntervalTier_hasBoundary (tier, my startSelection()); |
| 63 |
} |
| 64 |
static integer getSelectedPoint (constTextGridArea me) { |
| 65 |
Melder_assert (my selectedTier >= 1 || my selectedTier <= my textGrid() -> tiers->size); |
| 66 |
const TextTier tier = (TextTier) my textGrid() -> tiers->at [my selectedTier]; |
| 67 |
Melder_assert (tier -> classInfo == classTextTier); |
| 68 |
Melder_assert (isdefined (my startSelection())); |
| 69 |
return AnyTier_hasPoint (tier->asAnyTier(), my startSelection()); |
| 70 |
} |
| 71 |
|
| 72 |
static void timeToInterval (TextGridArea me, double t, integer tierNumber, |
| 73 |
double *out_tmin, double *out_tmax) |
| 74 |
{ |
| 75 |
Melder_assert (isdefined (t)); |
| 76 |
const Function tier = my textGrid() -> tiers->at [tierNumber]; |
| 77 |
IntervalTier intervalTier; |
| 78 |
TextTier textTier; |
| 79 |
AnyTextGridTier_identifyClass (tier, & intervalTier, & textTier); |
| 80 |
if (intervalTier) { |
| 81 |
integer iinterval = IntervalTier_timeToIndex (intervalTier, t); |
| 82 |
if (iinterval == 0) { |
| 83 |
if (t < my tmin()) { |
| 84 |
iinterval = 1; |
| 85 |
} else { |
| 86 |
iinterval = intervalTier -> intervals.size; |
| 87 |
} |
| 88 |
} |
| 89 |
Melder_assert (iinterval >= 1); |
| 90 |
Melder_assert (iinterval <= intervalTier -> intervals.size); |
| 91 |
const TextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 92 |
*out_tmin = interval -> xmin; |
| 93 |
*out_tmax = interval -> xmax; |
| 94 |
} else { |
| 95 |
const integer n = textTier -> points.size; |
| 96 |
if (n == 0) { |
| 97 |
*out_tmin = my tmin(); |
| 98 |
*out_tmax = my tmax(); |
| 99 |
} else { |
| 100 |
integer ipointleft = AnyTier_timeToLowIndex (textTier->asAnyTier(), t); |
| 101 |
*out_tmin = ( ipointleft == 0 ? my tmin() : textTier -> points.at [ipointleft] -> number ); |
| 102 |
*out_tmax = ( ipointleft == n ? my tmax() : textTier -> points.at [ipointleft + 1] -> number ); |
| 103 |
} |
| 104 |
} |
| 105 |
Melder_clipLeft (my tmin(), out_tmin); |
| 106 |
Melder_clipRight (out_tmax, my tmax()); |
| 107 |
} |
| 108 |
|
| 109 |
static void insertBoundaryOrPoint (TextGridArea me, integer itier, double t1, double t2, bool insertSecond) { |
| 110 |
const integer numberOfTiers = my textGrid() -> tiers->size; |
| 111 |
if (itier < 1 || itier > numberOfTiers) |
| 112 |
Melder_throw (U"No tier ", itier, U"."); |
| 113 |
IntervalTier intervalTier; |
| 114 |
TextTier textTier; |
| 115 |
AnyTextGridTier_identifyClass (my textGrid() -> tiers->at [itier], & intervalTier, & textTier); |
| 116 |
Melder_assert (t1 <= t2); |
| 117 |
|
| 118 |
if (intervalTier) { |
| 119 |
autoTextInterval rightNewInterval, midNewInterval; |
| 120 |
const bool t1IsABoundary = IntervalTier_hasTime (intervalTier, t1); |
| 121 |
const bool t2IsABoundary = IntervalTier_hasTime (intervalTier, t2); |
| 122 |
if (t1 == t2 && t1IsABoundary) |
| 123 |
Melder_throw (U"Cannot add a boundary at ", Melder_fixed (t1, 6), U" seconds, because there is already a boundary there."); |
| 124 |
if (t1IsABoundary && t2IsABoundary) |
| 125 |
Melder_throw (U"Cannot add boundaries at ", Melder_fixed (t1, 6), U" and ", Melder_fixed (t2, 6), U" seconds, because there are already boundaries there."); |
| 126 |
const integer iinterval = IntervalTier_timeToIndex (intervalTier, t1); |
| 127 |
const integer iinterval2 = t1 == t2 ? iinterval : IntervalTier_timeToIndex (intervalTier, t2); |
| 128 |
if (iinterval == 0 || iinterval2 == 0) |
| 129 |
Melder_throw (U"The selection is outside the time domain of the intervals."); |
| 130 |
const integer correctedIinterval2 = ( t2IsABoundary && iinterval2 == intervalTier -> intervals.size ? iinterval2 + 1 : iinterval2 ); |
| 131 |
if (correctedIinterval2 > iinterval + 1 || (correctedIinterval2 > iinterval && ! t2IsABoundary)) |
| 132 |
Melder_throw (U"The selection straddles a boundary."); |
| 133 |
const TextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 134 |
|
| 135 |
if (t1 == t2) { |
| 136 |
FunctionArea_save (me, U"Add boundary"); |
| 137 |
} else { |
| 138 |
FunctionArea_save (me, U"Add interval"); |
| 139 |
} |
| 140 |
|
| 141 |
if (itier == my selectedTier) { |
| 142 |
/* |
| 143 |
Divide up the label text into left, mid and right, depending on where the text selection is. |
| 144 |
*/ |
| 145 |
integer left, right; |
| 146 |
autostring32 text = GuiText_getStringAndSelectionPosition (my functionEditor() -> textArea, & left, & right); |
| 147 |
const bool wholeTextIsSelected = ( right - left == Melder_length (text.get()) ); |
| 148 |
rightNewInterval = TextInterval_create (t2, interval -> xmax, text.get() + right); |
| 149 |
text [right] = U'\0'; |
| 150 |
midNewInterval = TextInterval_create (t1, t2, text.get() + left); |
| 151 |
if (! wholeTextIsSelected || t1 != t2) |
| 152 |
text [left] = U'\0'; |
| 153 |
TextInterval_setText (interval, text.get()); |
| 154 |
} else { |
| 155 |
/* |
| 156 |
Move the text to the left of the boundary. |
| 157 |
*/ |
| 158 |
rightNewInterval = TextInterval_create (t2, interval -> xmax, U""); |
| 159 |
midNewInterval = TextInterval_create (t1, t2, U""); |
| 160 |
} |
| 161 |
if (t1IsABoundary) { |
| 162 |
/* |
| 163 |
Merge mid with left interval. |
| 164 |
*/ |
| 165 |
if (interval -> xmin != t1) |
| 166 |
Melder_crash (U"Boundary unequal: ", interval -> xmin, U" versus ", t1, U"."); |
| 167 |
interval -> xmax = t2; |
| 168 |
TextInterval_setText (interval, Melder_cat (interval -> text.get(), midNewInterval -> text.get())); |
| 169 |
} else if (t2IsABoundary) { |
| 170 |
/* |
| 171 |
Merge mid and right interval. |
| 172 |
*/ |
| 173 |
if (interval -> xmax != t2) |
| 174 |
Melder_crash (U"Boundary unequal: ", interval -> xmax, U" versus ", t2, U"."); |
| 175 |
interval -> xmax = t1; |
| 176 |
Melder_assert (rightNewInterval -> xmin == t2); |
| 177 |
Melder_assert (rightNewInterval -> xmax == t2); |
| 178 |
rightNewInterval -> xmin = t1; |
| 179 |
TextInterval_setText (rightNewInterval.get(), Melder_cat (midNewInterval -> text.get(), rightNewInterval -> text.get())); |
| 180 |
} else { |
| 181 |
interval -> xmax = t1; |
| 182 |
if (t1 != t2) |
| 183 |
intervalTier -> intervals. addItem_move (midNewInterval.move()); |
| 184 |
} |
| 185 |
intervalTier -> intervals. addItem_move (rightNewInterval.move()); |
| 186 |
if (insertSecond && numberOfTiers >= 2 && t1 == t2) { |
| 187 |
/* |
| 188 |
Find the last time before t on another tier. |
| 189 |
*/ |
| 190 |
double tlast = interval -> xmin; |
| 191 |
for (integer jtier = 1; jtier <= numberOfTiers; jtier ++) { |
| 192 |
if (jtier != itier) { |
| 193 |
double startInterval, endInterval; |
| 194 |
timeToInterval (me, t1, jtier, & startInterval, & endInterval); |
| 195 |
if (startInterval > tlast) |
| 196 |
tlast = startInterval; |
| 197 |
} |
| 198 |
} |
| 199 |
if (tlast > interval -> xmin && tlast < t1) { |
| 200 |
autoTextInterval newInterval = TextInterval_create (tlast, t1, U""); |
| 201 |
interval -> xmax = tlast; |
| 202 |
intervalTier -> intervals. addItem_move (newInterval.move()); |
| 203 |
} |
| 204 |
} |
| 205 |
} else { |
| 206 |
Melder_assert (isdefined (t1)); |
| 207 |
if (AnyTier_hasPoint (textTier->asAnyTier(), t1)) |
| 208 |
Melder_throw (U"Cannot add a point at ", Melder_fixed (t1, 6), U" seconds, because there is already a point there."); |
| 209 |
|
| 210 |
FunctionArea_save (me, U"Add point"); |
| 211 |
|
| 212 |
autoTextPoint newPoint = TextPoint_create (t1, U""); |
| 213 |
textTier -> points. addItem_move (newPoint.move()); |
| 214 |
} |
| 215 |
my setSelection (t1, t1); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
#pragma mark - TextGridArea info |
| 220 |
|
| 221 |
void structTextGridArea :: v1_info () { |
| 222 |
MelderInfo_writeLine (U"Selected tier: ", our selectedTier); |
| 223 |
MelderInfo_writeLine (U"TextGrid uses text styles: ", our instancePref_useTextStyles()); |
| 224 |
MelderInfo_writeLine (U"TextGrid font size: ", our instancePref_fontSize()); |
| 225 |
MelderInfo_writeLine (U"TextGrid alignment: ", kGraphics_horizontalAlignment_getText (our instancePref_alignment())); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
#pragma mark - TextGridArea drawing |
| 230 |
|
| 231 |
void structTextGridArea :: v_specializedHighlightBackground () const { |
| 232 |
Melder_assert (our textGrid()); |
| 233 |
const integer numberOfTiers = our textGrid() -> tiers->size; |
| 234 |
for (integer itier = 1; itier <= numberOfTiers; itier ++) { |
| 235 |
const Function anyTier = our textGrid() -> tiers->at [itier]; |
| 236 |
if (anyTier -> classInfo != classIntervalTier) |
| 237 |
continue; |
| 238 |
IntervalTier tier = (IntervalTier) anyTier; |
| 239 |
/* |
| 240 |
Highlight interval: yellow (selected) or green (matching label). |
| 241 |
*/ |
| 242 |
const integer selectedInterval = ( itier == our selectedTier ? getSelectedInterval (this) : 0 ); |
| 243 |
const integer numberOfIntervals = tier -> intervals.size; |
| 244 |
for (integer iinterval = 1; iinterval <= numberOfIntervals; iinterval ++) { |
| 245 |
const TextInterval interval = tier -> intervals.at [iinterval]; |
| 246 |
/* mutable clip */ double startInterval = interval -> xmin, endInterval = interval -> xmax; |
| 247 |
if (endInterval > our startWindow() && startInterval < our endWindow()) { // interval visible? |
| 248 |
const bool intervalIsSelected = ( iinterval == selectedInterval ); |
| 249 |
const bool labelDoesMatch = Melder_stringMatchesCriterion (interval -> text.get(), |
| 250 |
our instancePref_greenMethod(), our instancePref_greenString(), true); |
| 251 |
Melder_clipLeft (our startWindow(), & startInterval); |
| 252 |
Melder_clipRight (& endInterval, our endWindow()); |
| 253 |
const double bottom = 1.0 - double (itier) / numberOfTiers; |
| 254 |
const double top = 1.0 - double (itier - 1) / numberOfTiers; |
| 255 |
if (labelDoesMatch) { |
| 256 |
Graphics_setColour (our graphics(), Melder_LIME); |
| 257 |
Graphics_fillRectangle (our graphics(), startInterval, endInterval, bottom, top); |
| 258 |
} |
| 259 |
if (intervalIsSelected) { |
| 260 |
Graphics_setColour (our graphics(), Melder_YELLOW); |
| 261 |
Graphics_fillRectangle (our graphics(), |
| 262 |
labelDoesMatch ? 0.85 * startInterval + 0.15 * endInterval : startInterval, |
| 263 |
labelDoesMatch ? 0.15 * startInterval + 0.85 * endInterval : endInterval, |
| 264 |
labelDoesMatch ? 0.85 * bottom + 0.15 * top : bottom, |
| 265 |
labelDoesMatch ? 0.15 * bottom + 0.85 * top : top |
| 266 |
); |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
Graphics_setColour (our graphics(), Melder_BLACK); |
| 272 |
} |
| 273 |
static void do_drawIntervalTier (TextGridArea me, IntervalTier tier, integer itier) { |
| 274 |
#if gtk || defined (macintosh) |
| 275 |
constexpr bool platformUsesAntiAliasing = true; |
| 276 |
#else |
| 277 |
constexpr bool platformUsesAntiAliasing = false; |
| 278 |
#endif |
| 279 |
integer x1DC, x2DC, yDC; |
| 280 |
Graphics_WCtoDC (my graphics(), my startWindow(), 0.0, & x1DC, & yDC); |
| 281 |
Graphics_WCtoDC (my graphics(), my endWindow(), 0.0, & x2DC, & yDC); |
| 282 |
Graphics_setPercentSignIsItalic (my graphics(), my instancePref_useTextStyles()); |
| 283 |
Graphics_setNumberSignIsBold (my graphics(), my instancePref_useTextStyles()); |
| 284 |
Graphics_setCircumflexIsSuperscript (my graphics(), my instancePref_useTextStyles()); |
| 285 |
Graphics_setUnderscoreIsSubscript (my graphics(), my instancePref_useTextStyles()); |
| 286 |
|
| 287 |
const integer selectedInterval = ( itier == my selectedTier ? getSelectedInterval (me) : 0 ); |
| 288 |
const integer numberOfIntervals = tier -> intervals.size; |
| 289 |
|
| 290 |
/* |
| 291 |
Draw a grey bar and a selection button at the cursor position. |
| 292 |
*/ |
| 293 |
if (my startSelection() == my endSelection() && my startSelection() >= my startWindow() && my startSelection() <= my endWindow()) { |
| 294 |
/* mutable search */ bool cursorAtBoundary = false; |
| 295 |
for (integer iinterval = 2; iinterval <= numberOfIntervals; iinterval ++) { |
| 296 |
const TextInterval interval = tier -> intervals.at [iinterval]; |
| 297 |
if (interval -> xmin == my startSelection()) |
| 298 |
cursorAtBoundary = true; |
| 299 |
} |
| 300 |
if (! cursorAtBoundary) { |
| 301 |
const double dy = Graphics_dyMMtoWC (my graphics(), 1.5); |
| 302 |
Graphics_setGrey (my graphics(), 0.8); |
| 303 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 6.0 : 5.0); |
| 304 |
Graphics_line (my graphics(), my startSelection(), 0.0, my startSelection(), 1.0); |
| 305 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 306 |
if (my editable()) { |
| 307 |
Graphics_setColour (my graphics(), Melder_BLUE); |
| 308 |
Graphics_circle_mm (my graphics(), my startSelection(), 1.0 - dy, 3.0); |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
Graphics_setTextAlignment (my graphics(), my instancePref_alignment(), Graphics_HALF); |
| 314 |
for (integer iinterval = 1; iinterval <= numberOfIntervals; iinterval ++) { |
| 315 |
const TextInterval interval = tier -> intervals.at [iinterval]; |
| 316 |
/* mutable clip */ double startInterval = interval -> xmin, endInterval = interval -> xmax; |
| 317 |
Melder_clipLeft (my tmin(), & startInterval); |
| 318 |
Melder_clipRight (& endInterval, my tmax()); |
| 319 |
if (startInterval >= endInterval) |
| 320 |
continue; |
| 321 |
const bool intervalIsSelected = ( selectedInterval == iinterval ); |
| 322 |
|
| 323 |
/* |
| 324 |
Draw left boundary. |
| 325 |
*/ |
| 326 |
if (startInterval >= my startWindow() && startInterval <= my endWindow() && iinterval > 1) { |
| 327 |
const bool boundaryIsSelected = ( my selectedTier == itier && startInterval == my startSelection() ); |
| 328 |
Graphics_setColour (my graphics(), DataGui_defaultForegroundColour (me, boundaryIsSelected)); |
| 329 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 6.0 : 5.0); |
| 330 |
Graphics_line (my graphics(), startInterval, 0.0, startInterval, 1.0); |
| 331 |
|
| 332 |
/* |
| 333 |
Show alignment with cursor. |
| 334 |
*/ |
| 335 |
if (startInterval == my startSelection()) { |
| 336 |
Graphics_setColour (my graphics(), Melder_YELLOW); |
| 337 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 2.0 : 1.0); |
| 338 |
Graphics_line (my graphics(), startInterval, 0.0, startInterval, 1.0); |
| 339 |
} |
| 340 |
} |
| 341 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 342 |
|
| 343 |
/* |
| 344 |
Draw label text. |
| 345 |
*/ |
| 346 |
if (interval -> text && endInterval >= my startWindow() && startInterval <= my endWindow()) { |
| 347 |
const double t1 = std::max (my startWindow(), startInterval); |
| 348 |
const double t2 = std::min (my endWindow(), endInterval); |
| 349 |
Graphics_setColour (my graphics(), DataGui_defaultForegroundColour (me, intervalIsSelected)); |
| 350 |
Graphics_rectangleText_wrapAndTruncate (my graphics(), t1, t2, 0.0, 1.0, interval -> text.get()); |
| 351 |
Graphics_setColour (my graphics(), Melder_BLACK); |
| 352 |
} |
| 353 |
|
| 354 |
} |
| 355 |
Graphics_setPercentSignIsItalic (my graphics(), true); |
| 356 |
Graphics_setNumberSignIsBold (my graphics(), true); |
| 357 |
Graphics_setCircumflexIsSuperscript (my graphics(), true); |
| 358 |
Graphics_setUnderscoreIsSubscript (my graphics(), true); |
| 359 |
} |
| 360 |
|
| 361 |
static void do_drawTextTier (TextGridArea me, TextTier tier, integer itier) { |
| 362 |
#if gtk || defined (macintosh) |
| 363 |
constexpr bool platformUsesAntiAliasing = true; |
| 364 |
#else |
| 365 |
constexpr bool platformUsesAntiAliasing = false; |
| 366 |
#endif |
| 367 |
const integer numberOfPoints = tier -> points.size; |
| 368 |
Graphics_setPercentSignIsItalic (my graphics(), my instancePref_useTextStyles()); |
| 369 |
Graphics_setNumberSignIsBold (my graphics(), my instancePref_useTextStyles()); |
| 370 |
Graphics_setCircumflexIsSuperscript (my graphics(), my instancePref_useTextStyles()); |
| 371 |
Graphics_setUnderscoreIsSubscript (my graphics(), my instancePref_useTextStyles()); |
| 372 |
|
| 373 |
/* |
| 374 |
Draw a grey bar and a selection button at the cursor position. |
| 375 |
*/ |
| 376 |
if (my startSelection() == my endSelection() && my startSelection() >= my startWindow() && my startSelection() <= my endWindow()) { |
| 377 |
bool cursorAtPoint = false; |
| 378 |
for (integer ipoint = 1; ipoint <= numberOfPoints; ipoint ++) { |
| 379 |
const TextPoint point = tier -> points.at [ipoint]; |
| 380 |
if (point -> number == my startSelection()) |
| 381 |
cursorAtPoint = true; |
| 382 |
} |
| 383 |
if (! cursorAtPoint) { |
| 384 |
const double dy = Graphics_dyMMtoWC (my graphics(), 1.5); |
| 385 |
Graphics_setGrey (my graphics(), 0.8); |
| 386 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 6.0 : 5.0); |
| 387 |
Graphics_line (my graphics(), my startSelection(), 0.0, my startSelection(), 1.0); |
| 388 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 389 |
if (my editable()) { |
| 390 |
Graphics_setColour (my graphics(), DataGuiColour_EDITABLE); |
| 391 |
Graphics_circle_mm (my graphics(), my startSelection(), 1.0 - dy, 3.0); |
| 392 |
} |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
Graphics_setTextAlignment (my graphics(), Graphics_CENTRE, Graphics_HALF); |
| 397 |
for (integer ipoint = 1; ipoint <= numberOfPoints; ipoint ++) { |
| 398 |
const TextPoint point = tier -> points.at [ipoint]; |
| 399 |
const double t = point -> number; |
| 400 |
if (t >= my startWindow() && t <= my endWindow()) { |
| 401 |
const bool pointIsSelected = ( itier == my selectedTier && t == my startSelection() ); |
| 402 |
Graphics_setColour (my graphics(), DataGui_defaultForegroundColour (me, pointIsSelected)); |
| 403 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 6.0 : 5.0); |
| 404 |
Graphics_line (my graphics(), t, 0.0, t, 0.2); |
| 405 |
Graphics_line (my graphics(), t, 0.8, t, 1); |
| 406 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 407 |
|
| 408 |
/* |
| 409 |
Wipe out the cursor where the text is going to be. |
| 410 |
*/ |
| 411 |
if (my startSelection() == t || my endSelection() == t) { |
| 412 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 413 |
Graphics_setColour (my graphics(), DataGuiColour_AREA_BACKGROUND); |
| 414 |
Graphics_line (my graphics(), t, 0.2, t, 0.8); |
| 415 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 416 |
} |
| 417 |
|
| 418 |
/* |
| 419 |
Show alignment with cursor. |
| 420 |
*/ |
| 421 |
if (my startSelection() == my endSelection() && t == my startSelection()) { |
| 422 |
Graphics_setColour (my graphics(), Melder_YELLOW); |
| 423 |
Graphics_setLineWidth (my graphics(), platformUsesAntiAliasing ? 2.0 : 1.0); |
| 424 |
Graphics_line (my graphics(), t, 0.0, t, 0.2); |
| 425 |
Graphics_line (my graphics(), t, 0.8, t, 1.0); |
| 426 |
Graphics_setLineWidth (my graphics(), 1.0); |
| 427 |
} |
| 428 |
Graphics_setColour (my graphics(), DataGui_defaultForegroundColour (me, pointIsSelected)); |
| 429 |
if (point -> mark) |
| 430 |
Graphics_text (my graphics(), t, 0.5, point -> mark.get()); |
| 431 |
} |
| 432 |
} |
| 433 |
Graphics_setPercentSignIsItalic (my graphics(), true); |
| 434 |
Graphics_setNumberSignIsBold (my graphics(), true); |
| 435 |
Graphics_setCircumflexIsSuperscript (my graphics(), true); |
| 436 |
Graphics_setUnderscoreIsSubscript (my graphics(), true); |
| 437 |
} |
| 438 |
void structTextGridArea :: v_drawInside () { |
| 439 |
Graphics_Viewport vp2; |
| 440 |
const integer numberOfTiers = our textGrid() -> tiers->size; |
| 441 |
const enum kGraphics_font oldFont = Graphics_inqFont (our graphics()); |
| 442 |
const double oldFontSize = Graphics_inqFontSize (our graphics()); |
| 443 |
Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), 0.0, 1.0); |
| 444 |
const double xleft = our functionViewerLeft_WC(); |
| 445 |
const double xright = our functionViewerRight_WC(); |
| 446 |
for (integer itier = 1; itier <= numberOfTiers; itier ++) { |
| 447 |
const Function anyTier = our textGrid() -> tiers->at [itier]; |
| 448 |
const bool tierIsSelected = ( itier == our selectedTier ); |
| 449 |
const bool isIntervalTier = ( anyTier -> classInfo == classIntervalTier ); |
| 450 |
vp2 = Graphics_insetViewport (our graphics(), 0.0, 1.0, |
| 451 |
1.0 - (double) itier / (double) numberOfTiers, |
| 452 |
1.0 - (double) (itier - 1) / (double) numberOfTiers |
| 453 |
); |
| 454 |
Graphics_setColour (our graphics(), Melder_BLACK); |
| 455 |
if (itier != 1) |
| 456 |
Graphics_line (our graphics(), our startWindow(), 1.0, our endWindow(), 1.0); |
| 457 |
|
| 458 |
/* |
| 459 |
Show which tier is selected. |
| 460 |
*/ |
| 461 |
if (tierIsSelected) { |
| 462 |
MelderColour oldColour = Graphics_inqColour (our graphics()); |
| 463 |
Graphics_setColour (our graphics(), Melder_YELLOW); |
| 464 |
Graphics_fillRectangle (our graphics(), xleft, our startWindow(), 0.0, 1.0); |
| 465 |
Graphics_fillRectangle (our graphics(), our endWindow(), xright, 0.0, 1.0); |
| 466 |
Graphics_setColour (our graphics(), oldColour); |
| 467 |
} |
| 468 |
/* |
| 469 |
Show the name of the tier. |
| 470 |
*/ |
| 471 |
Graphics_setColour (our graphics(), DataGui_defaultForegroundColour (this, tierIsSelected)); |
| 472 |
Graphics_setFont (our graphics(), oldFont); |
| 473 |
Graphics_setFontSize (our graphics(), 14); |
| 474 |
if (anyTier -> name && anyTier -> name [0]) { |
| 475 |
Graphics_setTextAlignment (our graphics(), Graphics_LEFT, Graphics_HALF); |
| 476 |
Graphics_rectangleText_maximalFit (our graphics(), our endWindow(), xright, 0.05, 0.5, |
| 477 |
0.0, 1.0, 0.01, 0.1, anyTier -> name.get()); |
| 478 |
} |
| 479 |
/* |
| 480 |
Show the number of the tier. |
| 481 |
*/ |
| 482 |
Graphics_setTextAlignment (our graphics(), Graphics_RIGHT, Graphics_HALF); |
| 483 |
if (our instancePref_showNumberOf() == kTextGridArea_showNumberOf::NOTHING) { |
| 484 |
Graphics_rectangleText_maximalFit (our graphics(), xleft, our startWindow(), 0.05, 0.5, |
| 485 |
0.0, 1.0, 0.01, 0.1, Melder_cat (U"##", itier)); |
| 486 |
} else { |
| 487 |
const conststring32 units = ( isIntervalTier ? U" int" : U" pts" ); |
| 488 |
if (our instancePref_showNumberOf() == kTextGridArea_showNumberOf::INTERVALS_OR_POINTS) { |
| 489 |
const integer count = ( isIntervalTier ? ((IntervalTier) anyTier) -> intervals.size : ((TextTier) anyTier) -> points.size ); |
| 490 |
const integer position = ( itier == our selectedTier ? ( isIntervalTier ? getSelectedInterval (this) : getSelectedPoint (this) ) : 0 ); |
| 491 |
if (position) |
| 492 |
Graphics_rectangleText_maximalFit (our graphics(), xleft, our startWindow(), 0.05, 0.5, |
| 493 |
0.0, 1.0, 0.01, 0.1, Melder_cat (tierIsSelected ? U"\\s{(" : U" \\s{(", position, U"/", count, units, U")} ##", itier)); |
| 494 |
else |
| 495 |
Graphics_rectangleText_maximalFit (our graphics(), xleft, our startWindow(), 0.05, 0.5, |
| 496 |
0.0, 1.0, 0.01, 0.1, Melder_cat (tierIsSelected ? U"\\s{(" : U" \\s{(", count, units, U")} ##", itier)); |
| 497 |
} else { |
| 498 |
Melder_assert (our instancePref_showNumberOf() == kTextGridArea_showNumberOf::NONEMPTY_INTERVALS_OR_POINTS); |
| 499 |
integer count = 0; |
| 500 |
if (isIntervalTier) { |
| 501 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 502 |
const integer numberOfIntervals = tier -> intervals.size; |
| 503 |
for (integer iinterval = 1; iinterval <= numberOfIntervals; iinterval ++) { |
| 504 |
const TextInterval interval = tier -> intervals.at [iinterval]; |
| 505 |
if (interval -> text && interval -> text [0] != U'\0') |
| 506 |
count ++; |
| 507 |
} |
| 508 |
} else { |
| 509 |
const TextTier tier = (TextTier) anyTier; |
| 510 |
const integer numberOfPoints = tier -> points.size; |
| 511 |
for (integer ipoint = 1; ipoint <= numberOfPoints; ipoint ++) { |
| 512 |
const TextPoint point = tier -> points.at [ipoint]; |
| 513 |
if (point -> mark && point -> mark [0] != U'\0') |
| 514 |
count ++; |
| 515 |
} |
| 516 |
} |
| 517 |
Graphics_rectangleText_maximalFit (our graphics(), xleft, our startWindow(), 0.05, 0.5, |
| 518 |
0.0, 1.0, 0.01, 0.1, Melder_cat (tierIsSelected ? U"\\s{(##" : U" \\s{(##", count, units, U"#)} ##", itier)); |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
Graphics_setColour (our graphics(), Melder_BLACK); |
| 523 |
Graphics_setFont (our graphics(), kGraphics_font::TIMES); |
| 524 |
Graphics_setFontSize (our graphics(), our instancePref_fontSize()); |
| 525 |
if (isIntervalTier) |
| 526 |
do_drawIntervalTier (this, (IntervalTier) anyTier, itier); |
| 527 |
else |
| 528 |
do_drawTextTier (this, (TextTier) anyTier, itier); |
| 529 |
Graphics_resetViewport (our graphics(), vp2); |
| 530 |
} |
| 531 |
Graphics_setColour (our graphics(), Melder_BLACK); |
| 532 |
Graphics_setFont (our graphics(), oldFont); |
| 533 |
Graphics_setFontSize (our graphics(), oldFontSize); |
| 534 |
|
| 535 |
if (isdefined (our draggingTime) && hasBeenDraggedBeyondVicinityRadiusAtLeastOnce) { |
| 536 |
Graphics_xorOn (our graphics(), Melder_MAROON); |
| 537 |
for (integer itier = 1; itier <= numberOfTiers; itier ++) { |
| 538 |
if (our draggingTiers [itier]) { |
| 539 |
const double ymin = 1.0 - (double) itier / numberOfTiers; |
| 540 |
const double ymax = 1.0 - (double) (itier - 1) / numberOfTiers; |
| 541 |
Graphics_setLineWidth (our graphics(), 7.0); |
| 542 |
Graphics_line (our graphics(), our draggingTime, ymin, our draggingTime, ymax); |
| 543 |
} |
| 544 |
} |
| 545 |
our functionEditor() -> viewDataAsWorldByFraction (); |
| 546 |
Graphics_setLineWidth (our graphics(), 1.0); |
| 547 |
Graphics_line (our graphics(), our draggingTime, 0.0, our draggingTime, 1.0); |
| 548 |
Graphics_text (our graphics(), our draggingTime, 1.0, Melder_fixed (our draggingTime, 6)); |
| 549 |
Graphics_xorOff (our graphics()); |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
#pragma mark - TextGridArea tracking |
| 555 |
|
| 556 |
static integer localY_fraction_toTier (TextGridArea me, double localY_fraction) { |
| 557 |
const integer numberOfTiers = my textGrid() -> tiers->size; |
| 558 |
integer tierNumber = numberOfTiers - Melder_ifloor (localY_fraction * (double) numberOfTiers); |
| 559 |
Melder_clip (1_integer, & tierNumber, numberOfTiers); |
| 560 |
return tierNumber; |
| 561 |
} |
| 562 |
|
| 563 |
bool structTextGridArea :: v_mouse (GuiDrawingArea_MouseEvent event, double x_world, double localY_fraction) { |
| 564 |
const integer numberOfTiers = our textGrid() -> tiers->size; |
| 565 |
const integer oldSelectedTier = our selectedTier; |
| 566 |
|
| 567 |
constexpr double clickingVicinityRadius_mm = 1.0; |
| 568 |
constexpr double draggingVicinityRadius_mm = clickingVicinityRadius_mm + 0.2; // must be greater than `clickingVicinityRadius_mm` |
| 569 |
constexpr double droppingVicinityRadius_mm = 1.5; |
| 570 |
|
| 571 |
const integer mouseTier = localY_fraction_toTier (this, localY_fraction); |
| 572 |
|
| 573 |
our draggingTime = undefined; // information to next expose event |
| 574 |
if (event -> isClick()) { |
| 575 |
if (isdefined (our anchorTime)) // sanity check for the fixed order click-drag-drop |
| 576 |
return false; |
| 577 |
Melder_assert (our clickedLeftBoundary == 0); |
| 578 |
Melder_assert (! our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce); |
| 579 |
our draggingTiers. reset(); |
| 580 |
/* |
| 581 |
The user clicked in the grid part. |
| 582 |
We select the tier in which they clicked. |
| 583 |
*/ |
| 584 |
our selectedTier = mouseTier; |
| 585 |
double startInterval, endInterval; |
| 586 |
timeToInterval (this, x_world, our selectedTier, & startInterval, & endInterval); |
| 587 |
|
| 588 |
if (event -> optionKeyPressed != event -> commandKeyPressed) { |
| 589 |
if (event -> isLeftBottomFunctionKeyPressed()) { |
| 590 |
our setSelection (x_world - startInterval < endInterval - x_world ? startInterval : endInterval, our endSelection()); // to nearest boundary |
| 591 |
return FunctionEditor_UPDATE_NEEDED; |
| 592 |
} |
| 593 |
if (event -> isRightBottomFunctionKeyPressed()) { |
| 594 |
our setSelection (our startSelection(), x_world - startInterval < endInterval - x_world ? startInterval : endInterval); |
| 595 |
return FunctionEditor_UPDATE_NEEDED; |
| 596 |
} |
| 597 |
} |
| 598 |
Melder_assert (! our functionEditor() -> clickWasModifiedByOptionKey && ! our functionEditor() -> clickWasModifiedByCommandKey || |
| 599 |
our functionEditor() -> clickWasModifiedByOptionKey && our functionEditor() -> clickWasModifiedByCommandKey); // either neither or both |
| 600 |
|
| 601 |
IntervalTier selectedIntervalTier; |
| 602 |
TextTier selectedTextTier; |
| 603 |
AnyTextGridTier_identifyClass (our textGrid() -> tiers->at [our selectedTier], & selectedIntervalTier, & selectedTextTier); |
| 604 |
|
| 605 |
if (x_world <= our startWindow() || x_world >= our endWindow()) |
| 606 |
return FunctionEditor_UPDATE_NEEDED; |
| 607 |
|
| 608 |
/* |
| 609 |
Get the time of the nearest boundary or point. |
| 610 |
*/ |
| 611 |
if (selectedIntervalTier) { |
| 612 |
const integer clickedIntervalNumber = IntervalTier_timeToIndex (selectedIntervalTier, x_world); |
| 613 |
const bool theyClickedOutsidetheTimeDomainOfTheIntervals = ( clickedIntervalNumber == 0 ); |
| 614 |
if (theyClickedOutsidetheTimeDomainOfTheIntervals) |
| 615 |
return FunctionEditor_UPDATE_NEEDED; |
| 616 |
const TextInterval interval = selectedIntervalTier -> intervals.at [clickedIntervalNumber]; |
| 617 |
if (x_world > 0.5 * (interval -> xmin + interval -> xmax)) { |
| 618 |
our anchorTime = interval -> xmax; |
| 619 |
our clickedLeftBoundary = clickedIntervalNumber + 1; |
| 620 |
} else { |
| 621 |
our anchorTime = interval -> xmin; |
| 622 |
our clickedLeftBoundary = clickedIntervalNumber; |
| 623 |
} |
| 624 |
} else { |
| 625 |
const integer clickedPointNumber = AnyTier_timeToNearestIndex (selectedTextTier->asAnyTier(), x_world); |
| 626 |
if (clickedPointNumber != 0) { |
| 627 |
const TextPoint point = selectedTextTier -> points.at [clickedPointNumber]; |
| 628 |
our anchorTime = point -> number; |
| 629 |
} |
| 630 |
} |
| 631 |
Melder_assert (! (selectedIntervalTier && our clickedLeftBoundary == 0)); |
| 632 |
|
| 633 |
const bool nearBoundaryOrPoint = ( isdefined (our anchorTime) && |
| 634 |
fabs (Graphics_dxWCtoMM (our graphics(), x_world - our anchorTime)) < 1.5 ); |
| 635 |
Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), 0.0, 1.0); |
| 636 |
const double distanceToCursorCircle = ( our startSelection() != our endSelection() ? undefined : |
| 637 |
Graphics_distanceWCtoMM (our graphics(), x_world, localY_fraction, |
| 638 |
our startSelection(), |
| 639 |
(numberOfTiers + 1 - our selectedTier) / double (numberOfTiers) - |
| 640 |
Graphics_dyMMtoWC (our graphics(), 1.5)) |
| 641 |
); |
| 642 |
trace (localY_fraction, U" ", distanceToCursorCircle); |
| 643 |
const bool nearCursorCircle = ( distanceToCursorCircle < 1.5 ); |
| 644 |
|
| 645 |
if (nearBoundaryOrPoint) { |
| 646 |
/* |
| 647 |
Possibility 1: the user clicked near a boundary or point. |
| 648 |
Perhaps drag it. |
| 649 |
*/ |
| 650 |
bool boundaryOrPointIsMovable = true; |
| 651 |
if (selectedIntervalTier) { |
| 652 |
const bool isLeftEdgeOfFirstInterval = ( our clickedLeftBoundary <= 1 ); |
| 653 |
const bool isRightEdgeOfLastInterval = ( our clickedLeftBoundary > selectedIntervalTier -> intervals.size ); |
| 654 |
boundaryOrPointIsMovable = ! isLeftEdgeOfFirstInterval && ! isRightEdgeOfLastInterval; |
| 655 |
} |
| 656 |
/* |
| 657 |
If the user clicked on an unselected boundary or point, we extend or shrink the selection to it. |
| 658 |
*/ |
| 659 |
const bool rubberBanding = our functionEditor() -> clickWasModifiedByOptionKey && |
| 660 |
our functionEditor() -> clickWasModifiedByCommandKey; |
| 661 |
if (event -> shiftKeyPressed && ! rubberBanding) { |
| 662 |
if (our anchorTime > 0.5 * (our startSelection() + our endSelection())) |
| 663 |
our setSelection (our startSelection(), our anchorTime); |
| 664 |
else |
| 665 |
our setSelection (our anchorTime, our endSelection()); |
| 666 |
} |
| 667 |
if (! boundaryOrPointIsMovable) { |
| 668 |
our draggingTime = undefined; |
| 669 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 670 |
our anchorTime = undefined; |
| 671 |
our clickedLeftBoundary = 0; |
| 672 |
return FunctionEditor_UPDATE_NEEDED; |
| 673 |
} |
| 674 |
/* |
| 675 |
Determine the set of selected boundaries and points, and the dragging range. |
| 676 |
*/ |
| 677 |
our draggingTiers = zero_BOOLVEC (numberOfTiers); |
| 678 |
if (rubberBanding) { |
| 679 |
our leftDraggingBoundary = our startSelection(); |
| 680 |
our rightDraggingBoundary = our endSelection(); |
| 681 |
} else { |
| 682 |
our leftDraggingBoundary = our tmin(); |
| 683 |
our rightDraggingBoundary = our tmax(); |
| 684 |
} |
| 685 |
for (int itier = 1; itier <= numberOfTiers; itier ++) { |
| 686 |
/* |
| 687 |
If the user has pressed the shift key, let her drag all the boundaries and points at this time. |
| 688 |
Otherwise, let her drag only the boundary or point on the clicked tier. |
| 689 |
*/ |
| 690 |
if (itier == mouseTier || our functionEditor() -> clickWasModifiedByShiftKey == our instancePref_shiftDragMultiple()) { |
| 691 |
IntervalTier intervalTier; |
| 692 |
TextTier textTier; |
| 693 |
AnyTextGridTier_identifyClass (our textGrid() -> tiers->at [itier], & intervalTier, & textTier); |
| 694 |
if (intervalTier) { |
| 695 |
const integer ibound = IntervalTier_hasBoundary (intervalTier, our anchorTime); |
| 696 |
if (ibound) { |
| 697 |
TextInterval leftInterval = intervalTier -> intervals.at [ibound - 1]; |
| 698 |
TextInterval rightInterval = intervalTier -> intervals.at [ibound]; |
| 699 |
our draggingTiers [itier] = true; |
| 700 |
if (! rubberBanding) { |
| 701 |
/* |
| 702 |
Prevent the user from dragging the boundary past its left or right neighbours on the same tier. |
| 703 |
*/ |
| 704 |
Melder_clipLeft (leftInterval -> xmin, & our leftDraggingBoundary); |
| 705 |
Melder_clipRight (& our rightDraggingBoundary, rightInterval -> xmax); |
| 706 |
} |
| 707 |
} |
| 708 |
} else { |
| 709 |
Melder_assert (isdefined (our anchorTime)); |
| 710 |
if (AnyTier_hasPoint (textTier->asAnyTier(), our anchorTime)) { |
| 711 |
/* |
| 712 |
Other than with boundaries on interval tiers, |
| 713 |
points on text tiers can be dragged past their neighbours. |
| 714 |
*/ |
| 715 |
our draggingTiers [itier] = true; |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
} else if (nearCursorCircle && our editable()) { |
| 721 |
/* |
| 722 |
Possibility 2: the user clicked near the cursor circle. |
| 723 |
Insert boundary or point. There is no danger that we insert on top of an existing boundary or point, |
| 724 |
because we are not 'nearBoundaryOrPoint'. |
| 725 |
*/ |
| 726 |
Melder_assert (isdefined (our startSelection())); // precondition of v_updateText() |
| 727 |
if (our selectedTier != oldSelectedTier) |
| 728 |
our v_updateText(); // this puts the text of the newly clicked tier into the text area |
| 729 |
insertBoundaryOrPoint (this, mouseTier, our startSelection(), our startSelection(), false); |
| 730 |
FunctionArea_broadcastDataChanged (this); |
| 731 |
} else { |
| 732 |
/* |
| 733 |
Possibility 3: the user clicked in empty space. |
| 734 |
Select the interval, if any. |
| 735 |
*/ |
| 736 |
if (selectedIntervalTier) |
| 737 |
our setSelection (startInterval, endInterval); |
| 738 |
} |
| 739 |
} else if (event -> isDrag ()) { |
| 740 |
if (our editable() && isdefined (our anchorTime) && our draggingTiers.size > 0) { |
| 741 |
our draggingTime = x_world; |
| 742 |
if (! our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce) { |
| 743 |
const double distanceToAnchor_mm = fabs (Graphics_dxWCtoMM (our graphics(), x_world - our anchorTime)); |
| 744 |
if (distanceToAnchor_mm > draggingVicinityRadius_mm) |
| 745 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = true; |
| 746 |
} |
| 747 |
} |
| 748 |
} else if (event -> isDrop ()) { |
| 749 |
if (isundef (our anchorTime) || our draggingTiers.size == 0) { // TODO: figure out a circumstance under which anchorTime could be undefined |
| 750 |
our draggingTime = undefined; |
| 751 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 752 |
our anchorTime = undefined; |
| 753 |
our clickedLeftBoundary = 0; |
| 754 |
return FunctionEditor_UPDATE_NEEDED; |
| 755 |
} |
| 756 |
/* |
| 757 |
If the user shift-clicked, we extend the selection (this already happened during click()). |
| 758 |
*/ |
| 759 |
if (event -> shiftKeyPressed && ! our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce) { |
| 760 |
our draggingTime = undefined; |
| 761 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 762 |
our anchorTime = undefined; |
| 763 |
our clickedLeftBoundary = 0; |
| 764 |
return FunctionEditor_UPDATE_NEEDED; |
| 765 |
} |
| 766 |
/* |
| 767 |
If the user dropped near an existing boundary in an unselected tier, |
| 768 |
we snap to that mark. |
| 769 |
*/ |
| 770 |
const integer itierDrop = localY_fraction_toTier (this, localY_fraction); |
| 771 |
bool droppedOnABoundaryOrPointInsideAnUnselectedTier = false; |
| 772 |
if (x_world > 0.0 && ! our draggingTiers [itierDrop]) { // dropped inside an unselected tier? |
| 773 |
const Function anyTierDrop = our textGrid() -> tiers->at [itierDrop]; |
| 774 |
if (anyTierDrop -> classInfo == classIntervalTier) { |
| 775 |
const IntervalTier tierDrop = (IntervalTier) anyTierDrop; |
| 776 |
for (integer ibound = 1; ibound < tierDrop -> intervals.size; ibound ++) { |
| 777 |
const TextInterval left = tierDrop -> intervals.at [ibound]; |
| 778 |
const double mouseDistanceToBoundary = fabs (Graphics_dxWCtoMM (our graphics(), x_world - left -> xmax)); |
| 779 |
if (mouseDistanceToBoundary < droppingVicinityRadius_mm) { |
| 780 |
x_world = left -> xmax; // snap to boundary |
| 781 |
droppedOnABoundaryOrPointInsideAnUnselectedTier = true; |
| 782 |
} |
| 783 |
} |
| 784 |
} else { |
| 785 |
const TextTier tierDrop = (TextTier) anyTierDrop; |
| 786 |
for (integer ipoint = 1; ipoint <= tierDrop -> points.size; ipoint ++) { |
| 787 |
const TextPoint point = tierDrop -> points.at [ipoint]; |
| 788 |
const double mouseDistanceToPoint_mm = fabs (Graphics_dxWCtoMM (our graphics(), x_world - point -> number)); |
| 789 |
if (mouseDistanceToPoint_mm < droppingVicinityRadius_mm) { |
| 790 |
x_world = point -> number; // snap to point |
| 791 |
droppedOnABoundaryOrPointInsideAnUnselectedTier = true; |
| 792 |
} |
| 793 |
} |
| 794 |
} |
| 795 |
} |
| 796 |
/* |
| 797 |
If the user dropped near the cursor (outside the anchor), |
| 798 |
we snap to the cursor. |
| 799 |
*/ |
| 800 |
if (our startSelection() == our endSelection() && our startSelection() != our anchorTime) { |
| 801 |
const double mouseDistanceToCursor = fabs (Graphics_dxWCtoMM (our graphics(), x_world - our startSelection())); |
| 802 |
if (mouseDistanceToCursor < droppingVicinityRadius_mm) |
| 803 |
x_world = our startSelection(); |
| 804 |
} |
| 805 |
/* |
| 806 |
If the user wiggled near the anchor, we snap to the anchor and bail out |
| 807 |
(a boundary has been selected, but nothing has been dragged). |
| 808 |
*/ |
| 809 |
if (! our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce && ! droppedOnABoundaryOrPointInsideAnUnselectedTier) { |
| 810 |
our setSelection (our anchorTime, our anchorTime); |
| 811 |
our draggingTime = undefined; |
| 812 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 813 |
our anchorTime = undefined; |
| 814 |
our clickedLeftBoundary = 0; |
| 815 |
return FunctionEditor_UPDATE_NEEDED; |
| 816 |
} |
| 817 |
|
| 818 |
if (! our editable()) { |
| 819 |
our draggingTime = undefined; |
| 820 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 821 |
our anchorTime = undefined; |
| 822 |
our clickedLeftBoundary = 0; |
| 823 |
return FunctionEditor_UPDATE_NEEDED; |
| 824 |
} |
| 825 |
/* |
| 826 |
We cannot move a boundary out of the dragging range. |
| 827 |
*/ |
| 828 |
if (x_world <= our leftDraggingBoundary || x_world >= our rightDraggingBoundary) { |
| 829 |
Melder_beep (); |
| 830 |
our draggingTime = undefined; |
| 831 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 832 |
our anchorTime = undefined; |
| 833 |
our clickedLeftBoundary = 0; |
| 834 |
return FunctionEditor_UPDATE_NEEDED; |
| 835 |
} |
| 836 |
|
| 837 |
const bool rubberBanding = our functionEditor() -> clickWasModifiedByOptionKey && |
| 838 |
our functionEditor() -> clickWasModifiedByCommandKey; |
| 839 |
FunctionArea_save (this, rubberBanding ? U"Rubber banding" : U"Drag"); |
| 840 |
|
| 841 |
for (integer itier = 1; itier <= numberOfTiers; itier ++) { |
| 842 |
if (! our draggingTiers [itier]) |
| 843 |
continue; |
| 844 |
IntervalTier intervalTier; |
| 845 |
TextTier textTier; |
| 846 |
AnyTextGridTier_identifyClass (our textGrid() -> tiers->at [itier], & intervalTier, & textTier); |
| 847 |
if (rubberBanding) { |
| 848 |
if (intervalTier) { |
| 849 |
for (integer iinterval = 1; iinterval <= intervalTier -> intervals.size; iinterval ++) { |
| 850 |
const mutableTextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 851 |
if (interval -> xmin > leftDraggingBoundary && interval -> xmin < rightDraggingBoundary) { |
| 852 |
if (interval -> xmin < our anchorTime) |
| 853 |
NUMscale (& interval -> xmin, our leftDraggingBoundary, our anchorTime, our leftDraggingBoundary, x_world); |
| 854 |
else |
| 855 |
NUMscale (& interval -> xmin, our anchorTime, our rightDraggingBoundary, x_world, our rightDraggingBoundary); |
| 856 |
} |
| 857 |
if (interval -> xmax > leftDraggingBoundary && interval -> xmax < rightDraggingBoundary) { |
| 858 |
if (interval -> xmax < our anchorTime) |
| 859 |
NUMscale (& interval -> xmax, our leftDraggingBoundary, our anchorTime, our leftDraggingBoundary, x_world); |
| 860 |
else |
| 861 |
NUMscale (& interval -> xmax, our anchorTime, our rightDraggingBoundary, x_world, our rightDraggingBoundary); |
| 862 |
} |
| 863 |
} |
| 864 |
} else { |
| 865 |
for (integer ipoint = 1; ipoint <= textTier -> points.size; ipoint ++) { |
| 866 |
const mutableTextPoint point = textTier -> points.at [ipoint]; |
| 867 |
if (point -> number > leftDraggingBoundary && point -> number < rightDraggingBoundary) { |
| 868 |
if (point -> number < our anchorTime) |
| 869 |
NUMscale (& point -> number, our leftDraggingBoundary, our anchorTime, our leftDraggingBoundary, x_world); |
| 870 |
else |
| 871 |
NUMscale (& point -> number, our anchorTime, our rightDraggingBoundary, x_world, our rightDraggingBoundary); |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
} else { |
| 876 |
if (intervalTier) { |
| 877 |
const integer numberOfIntervals = intervalTier -> intervals.size; |
| 878 |
for (integer ibound = 2; ibound <= numberOfIntervals; ibound ++) { |
| 879 |
TextInterval left = intervalTier -> intervals.at [ibound - 1], right = intervalTier -> intervals.at [ibound]; |
| 880 |
if (left -> xmax == our anchorTime) { // boundary dragged? |
| 881 |
left -> xmax = right -> xmin = x_world; // move boundary to drop site |
| 882 |
break; |
| 883 |
} |
| 884 |
} |
| 885 |
} else { |
| 886 |
Melder_assert (isdefined (our anchorTime)); |
| 887 |
const integer iDraggedPoint = AnyTier_hasPoint (textTier->asAnyTier(), our anchorTime); |
| 888 |
if (iDraggedPoint) { |
| 889 |
Melder_assert (isdefined (x_world)); |
| 890 |
const integer dropSiteHasPoint = AnyTier_hasPoint (textTier->asAnyTier(), x_world); |
| 891 |
if (dropSiteHasPoint != 0) { |
| 892 |
Melder_warning (U"Cannot drop point on an existing point."); |
| 893 |
} else { |
| 894 |
const TextPoint point = textTier -> points.at [iDraggedPoint]; |
| 895 |
/* |
| 896 |
Move point to drop site. May have passed another point. |
| 897 |
*/ |
| 898 |
autoTextPoint newPoint = Data_copy (point); |
| 899 |
newPoint -> number = x_world; // move point to drop site |
| 900 |
textTier -> points. removeItem (iDraggedPoint); |
| 901 |
textTier -> points. addItem_move (newPoint.move()); |
| 902 |
} |
| 903 |
} |
| 904 |
} |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
/* |
| 909 |
Select the drop site. |
| 910 |
*/ |
| 911 |
our setSelection (x_world, x_world); |
| 912 |
our draggingTime = undefined; |
| 913 |
our hasBeenDraggedBeyondVicinityRadiusAtLeastOnce = false; |
| 914 |
our anchorTime = undefined; |
| 915 |
our clickedLeftBoundary = 0; |
| 916 |
FunctionArea_broadcastDataChanged (this); |
| 917 |
} |
| 918 |
return FunctionEditor_UPDATE_NEEDED; |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
#pragma mark - TextGridArea File/Save |
| 923 |
|
| 924 |
static void menu_cb_SaveWholeTextGridAsTextFile (TextGridArea me, EDITOR_ARGS) { |
| 925 |
EDITOR_FORM_SAVE (U"Save whole TextGrid as text file", nullptr) |
| 926 |
Melder_sprint (defaultName,300, my textGrid() -> name.get(), U".TextGrid"); |
| 927 |
EDITOR_DO_SAVE |
| 928 |
Data_writeToTextFile (my textGrid(), file); |
| 929 |
EDITOR_END |
| 930 |
} |
| 931 |
void structTextGridArea :: v_createMenuItems_save (EditorMenu menu) { |
| 932 |
FunctionAreaMenu_addCommand (menu, U"- Save TextGrid to disk:", 0, nullptr, this); |
| 933 |
FunctionAreaMenu_addCommand (menu, |
| 934 |
U"Save whole TextGrid as text file... || Save TextGrid as text file... || Write TextGrid to text file...", |
| 935 |
'S' | GuiMenu_DEPTH_1, menu_cb_SaveWholeTextGridAsTextFile, this |
| 936 |
); |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
#pragma mark - TextGridArea Edit menu |
| 941 |
|
| 942 |
#ifndef macintosh |
| 943 |
static void menu_cb_Cut (TextGridArea me, EDITOR_ARGS) { |
| 944 |
GuiText_cut (my functionEditor() -> textArea); |
| 945 |
} |
| 946 |
static void menu_cb_Copy (TextGridArea me, EDITOR_ARGS) { |
| 947 |
GuiText_copy (my functionEditor() -> textArea); |
| 948 |
} |
| 949 |
static void menu_cb_Paste (TextGridArea me, EDITOR_ARGS) { |
| 950 |
GuiText_paste (my functionEditor() -> textArea); |
| 951 |
} |
| 952 |
static void menu_cb_Erase (TextGridArea me, EDITOR_ARGS) { |
| 953 |
GuiText_remove (my functionEditor() -> textArea); |
| 954 |
} |
| 955 |
#endif |
| 956 |
|
| 957 |
static void menu_cb_ConvertToBackslashTrigraphs (TextGridArea me, EDITOR_ARGS) { |
| 958 |
FunctionArea_save (me, U"Convert to Backslash Trigraphs"); |
| 959 |
TextGrid_convertToBackslashTrigraphs (my textGrid()); |
| 960 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_updateText() |
| 961 |
FunctionArea_broadcastDataChanged (me); |
| 962 |
} |
| 963 |
static void menu_cb_ConvertToUnicode (TextGridArea me, EDITOR_ARGS) { |
| 964 |
FunctionArea_save (me, U"Convert to Unicode"); |
| 965 |
TextGrid_convertToUnicode (my textGrid()); |
| 966 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_updateText() |
| 967 |
FunctionArea_broadcastDataChanged (me); |
| 968 |
} |
| 969 |
static void findInTier (TextGridArea me) { |
| 970 |
checkTierSelection (me, U"find a text"); |
| 971 |
Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 972 |
if (anyTier -> classInfo == classIntervalTier) { |
| 973 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 974 |
integer iinterval = IntervalTier_timeToIndex (tier, my startSelection()) + 1; |
| 975 |
while (iinterval <= tier -> intervals.size) { |
| 976 |
TextInterval interval = tier -> intervals.at [iinterval]; |
| 977 |
conststring32 text = interval -> text.get(); |
| 978 |
if (text) { |
| 979 |
const char32 *position = str32str (text, my findString.get()); |
| 980 |
if (position) { |
| 981 |
my setSelection (interval -> xmin, interval -> xmax); |
| 982 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 983 |
FunctionEditor_scrollToNewSelection (my functionEditor(), my startSelection()); |
| 984 |
if (my editable ()) |
| 985 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 986 |
position - text, position - text + Melder_length (my findString.get())); |
| 987 |
return; |
| 988 |
} |
| 989 |
} |
| 990 |
iinterval ++; |
| 991 |
} |
| 992 |
if (iinterval > tier -> intervals.size) |
| 993 |
Melder_beep (); |
| 994 |
} else { |
| 995 |
TextTier tier = (TextTier) anyTier; |
| 996 |
integer ipoint = AnyTier_timeToLowIndex (tier->asAnyTier(), my startSelection()) + 1; |
| 997 |
while (ipoint <= tier -> points.size) { |
| 998 |
const TextPoint point = tier->points.at [ipoint]; |
| 999 |
conststring32 text = point -> mark.get(); |
| 1000 |
if (text) { |
| 1001 |
const char32 *const position = str32str (text, my findString.get()); |
| 1002 |
if (position) { |
| 1003 |
my setSelection (point -> number, point -> number); |
| 1004 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 1005 |
FunctionEditor_scrollToNewSelection (my functionEditor(), point -> number); |
| 1006 |
if (my editable ()) |
| 1007 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 1008 |
position - text, position - text + Melder_length (my findString.get())); |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
} |
| 1012 |
ipoint ++; |
| 1013 |
} |
| 1014 |
if (ipoint > tier -> points.size) |
| 1015 |
Melder_beep (); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
static void do_find (TextGridArea me) { |
| 1019 |
if (my findString) { |
| 1020 |
if (my editable ()) { |
| 1021 |
integer left, right; |
| 1022 |
autostring32 label = GuiText_getStringAndSelectionPosition (my functionEditor() -> textArea, & left, & right); |
| 1023 |
const char32 *const position = str32str (& label [right], my findString.get()); // CRLF BUG? |
| 1024 |
if (position) |
| 1025 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 1026 |
position - label.get(), position - label.get() + Melder_length (my findString.get())); |
| 1027 |
else |
| 1028 |
findInTier (me); |
| 1029 |
} else |
| 1030 |
findInTier (me); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
static void menu_cb_Find (TextGridArea me, EDITOR_ARGS) { |
| 1035 |
EDITOR_FORM (U"Find text", nullptr) |
| 1036 |
TEXTFIELD (findString, U"Text", U"", 3) |
| 1037 |
EDITOR_OK |
| 1038 |
EDITOR_DO |
| 1039 |
my findString = Melder_dup (findString); |
| 1040 |
do_find (me); |
| 1041 |
EDITOR_END |
| 1042 |
} |
| 1043 |
static void menu_cb_FindAgain (TextGridArea me, EDITOR_ARGS) { |
| 1044 |
do_find (me); |
| 1045 |
} |
| 1046 |
void structTextGridArea :: v_createMenuItems_edit (EditorMenu menu) { |
| 1047 |
#ifndef macintosh |
| 1048 |
if (our editable()) { |
| 1049 |
FunctionAreaMenu_addCommand (menu, U"-- cut copy paste --", 0, nullptr, this); |
| 1050 |
FunctionAreaMenu_addCommand (menu, U"Cut text", 'X', menu_cb_Cut, this); |
| 1051 |
FunctionAreaMenu_addCommand (menu, U"Cut", GuiMenu_HIDDEN, menu_cb_Cut, this); |
| 1052 |
FunctionAreaMenu_addCommand (menu, U"Copy text", 'C', menu_cb_Copy, this); |
| 1053 |
FunctionAreaMenu_addCommand (menu, U"Copy", GuiMenu_HIDDEN, menu_cb_Copy, this); |
| 1054 |
FunctionAreaMenu_addCommand (menu, U"Paste text", 'V', menu_cb_Paste, this); |
| 1055 |
FunctionAreaMenu_addCommand (menu, U"Paste", GuiMenu_HIDDEN, menu_cb_Paste, this); |
| 1056 |
FunctionAreaMenu_addCommand (menu, U"Erase text", 0, menu_cb_Erase, this); |
| 1057 |
FunctionAreaMenu_addCommand (menu, U"Erase", GuiMenu_HIDDEN, menu_cb_Erase, this); |
| 1058 |
} |
| 1059 |
#endif |
| 1060 |
FunctionAreaMenu_addCommand (menu, U"-- search --", 0, nullptr, this); |
| 1061 |
FunctionAreaMenu_addCommand (menu, U"Find...", 'F', menu_cb_Find, this); |
| 1062 |
FunctionAreaMenu_addCommand (menu, U"Find again", 'G', menu_cb_FindAgain, this); |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
#pragma mark - TextGridArea Query |
| 1067 |
|
| 1068 |
static void QUERY_DATA_FOR_REAL__GetStartingPointOfInterval (TextGridArea me, EDITOR_ARGS) { |
| 1069 |
QUERY_DATA_FOR_REAL |
| 1070 |
checkTierSelection (me, U"query the starting point of an interval"); |
| 1071 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1072 |
Melder_require (anyTier -> classInfo == classIntervalTier, |
| 1073 |
U"The selected tier is not an interval tier."); |
| 1074 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1075 |
const integer iinterval = IntervalTier_timeToIndex (tier, my startSelection()); |
| 1076 |
const double result = ( iinterval < 1 || iinterval > tier -> intervals.size ? undefined : |
| 1077 |
tier -> intervals.at [iinterval] -> xmin ); |
| 1078 |
QUERY_DATA_FOR_REAL_END (U" seconds") |
| 1079 |
} |
| 1080 |
|
| 1081 |
static void QUERY_DATA_FOR_REAL__GetEndPointOfInterval (TextGridArea me, EDITOR_ARGS) { |
| 1082 |
QUERY_DATA_FOR_REAL |
| 1083 |
checkTierSelection (me, U"query the end point of an interval"); |
| 1084 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1085 |
Melder_require (anyTier -> classInfo == classIntervalTier, |
| 1086 |
U"The selected tier is not an interval tier."); |
| 1087 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1088 |
const integer iinterval = IntervalTier_timeToIndex (tier, my startSelection()); |
| 1089 |
const double result = ( iinterval < 1 || iinterval > tier -> intervals.size ? undefined : |
| 1090 |
tier -> intervals.at [iinterval] -> xmax ); |
| 1091 |
QUERY_DATA_FOR_REAL_END (U" seconds") |
| 1092 |
} |
| 1093 |
|
| 1094 |
static void QUERY_DATA_FOR_STRING__GetLabelOfInterval (TextGridArea me, EDITOR_ARGS) { |
| 1095 |
QUERY_DATA_FOR_STRING |
| 1096 |
checkTierSelection (me, U"query the label of an interval"); |
| 1097 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1098 |
Melder_require (anyTier -> classInfo == classIntervalTier, |
| 1099 |
U"The selected tier is not an interval tier."); |
| 1100 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1101 |
const integer iinterval = IntervalTier_timeToIndex (tier, my startSelection()); |
| 1102 |
const conststring32 result = ( iinterval < 1 || iinterval > tier -> intervals.size ? U"" : |
| 1103 |
tier -> intervals.at [iinterval] -> text.get() ); |
| 1104 |
QUERY_DATA_FOR_STRING_END |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
#pragma mark - TextGridArea changing |
| 1109 |
|
| 1110 |
static void gui_text_cb_changed (TextGridArea me, GuiTextEvent /* event */) { |
| 1111 |
trace (my suppressRedraw); |
| 1112 |
if (my suppressRedraw) |
| 1113 |
return; // prevent infinite loop if 'draw' method or Editor_broadcastChange calls GuiText_setString |
| 1114 |
if (my selectedTier) { |
| 1115 |
autostring32 text = GuiText_getString (my functionEditor() -> textArea); |
| 1116 |
IntervalTier intervalTier; |
| 1117 |
TextTier textTier; |
| 1118 |
AnyTextGridTier_identifyClass (my textGrid() -> tiers->at [my selectedTier], & intervalTier, & textTier); |
| 1119 |
if (intervalTier) { |
| 1120 |
const integer selectedInterval = getSelectedInterval (me); |
| 1121 |
if (selectedInterval) { |
| 1122 |
TextInterval interval = intervalTier -> intervals.at [selectedInterval]; |
| 1123 |
TextInterval_setText (interval, text.get()); |
| 1124 |
my suppressTextCursorJump = true; |
| 1125 |
FunctionArea_broadcastDataChanged (me); |
| 1126 |
my suppressTextCursorJump = false; |
| 1127 |
} |
| 1128 |
} else { |
| 1129 |
const integer selectedPoint = getSelectedPoint (me); |
| 1130 |
if (selectedPoint) { |
| 1131 |
TextPoint point = textTier -> points.at [selectedPoint]; |
| 1132 |
point -> mark. reset(); |
| 1133 |
if (Melder_findInk (text.get())) // any visible characters? |
| 1134 |
point -> mark = Melder_dup_f (text.get()); |
| 1135 |
my suppressTextCursorJump = true; |
| 1136 |
FunctionArea_broadcastDataChanged (me); |
| 1137 |
my suppressTextCursorJump = false; |
| 1138 |
} |
| 1139 |
} |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
#pragma mark - TextGridArea TextGrid/Prefs |
| 1145 |
|
| 1146 |
static void menu_cb_TextGridSettings (TextGridArea me, EDITOR_ARGS) { |
| 1147 |
EDITOR_FORM (U"TextGrid settings", nullptr) |
| 1148 |
POSITIVE (fontSize, U"Font size (points)", my default_fontSize()) |
| 1149 |
OPTIONMENU_ENUM (kGraphics_horizontalAlignment, textAlignmentInIntervals, |
| 1150 |
U"Text alignment in intervals", kGraphics_horizontalAlignment::DEFAULT) |
| 1151 |
OPTIONMENU (useTextStyles, U"The symbols %#_^ in labels", my default_useTextStyles() + 1) |
| 1152 |
OPTION (U"are shown as typed") |
| 1153 |
OPTION (U"mean italic/bold/sub/super") |
| 1154 |
OPTIONMENU_VARIABLE (shiftDragMultiple) |
| 1155 |
if (my editable()) { |
| 1156 |
OPTIONMENU_FIELD (shiftDragMultiple, U"With the shift key, you drag", my default_shiftDragMultiple() + 1) |
| 1157 |
OPTION (U"a single boundary") |
| 1158 |
OPTION (U"multiple boundaries") |
| 1159 |
} |
| 1160 |
OPTIONMENU_ENUM (kTextGridArea_showNumberOf, showNumberOf, |
| 1161 |
U"Show number of", kTextGridArea_showNumberOf::DEFAULT) |
| 1162 |
OPTIONMENU_ENUM (kMelder_string, paintIntervalsGreenWhoseLabel, |
| 1163 |
U"Paint intervals green whose label...", kMelder_string::DEFAULT) |
| 1164 |
SENTENCE (theText, U"...the text", my default_greenString()) |
| 1165 |
EDITOR_OK |
| 1166 |
SET_OPTION (useTextStyles, my instancePref_useTextStyles() + 1) |
| 1167 |
SET_REAL (fontSize, my instancePref_fontSize()) |
| 1168 |
SET_ENUM (textAlignmentInIntervals, kGraphics_horizontalAlignment, my instancePref_alignment()) |
| 1169 |
if (my editable()) |
| 1170 |
SET_OPTION (shiftDragMultiple, my instancePref_shiftDragMultiple() + 1) |
| 1171 |
SET_ENUM (showNumberOf, kTextGridArea_showNumberOf, my instancePref_showNumberOf()) |
| 1172 |
SET_ENUM (paintIntervalsGreenWhoseLabel, kMelder_string, my instancePref_greenMethod()) |
| 1173 |
SET_STRING (theText, my instancePref_greenString()) |
| 1174 |
EDITOR_DO |
| 1175 |
my setInstancePref_useTextStyles (useTextStyles - 1); |
| 1176 |
my setInstancePref_fontSize (fontSize); |
| 1177 |
my setInstancePref_alignment (textAlignmentInIntervals); |
| 1178 |
if (my editable()) |
| 1179 |
my setInstancePref_shiftDragMultiple (shiftDragMultiple - 1); |
| 1180 |
my setInstancePref_showNumberOf (showNumberOf); |
| 1181 |
my setInstancePref_greenMethod (paintIntervalsGreenWhoseLabel); |
| 1182 |
my setInstancePref_greenString (theText); |
| 1183 |
FunctionEditor_redraw (my functionEditor()); |
| 1184 |
EDITOR_END |
| 1185 |
} |
| 1186 |
|
| 1187 |
|
| 1188 |
#pragma mark - TextGridArea TextGrid/Select |
| 1189 |
|
| 1190 |
static void do_selectAdjacentTier (TextGridArea me, bool previous) { |
| 1191 |
const integer n = my textGrid() -> tiers->size; |
| 1192 |
if (n >= 2) { |
| 1193 |
my selectedTier = ( previous ? |
| 1194 |
my selectedTier > 1 ? my selectedTier - 1 : n : |
| 1195 |
my selectedTier < n ? my selectedTier + 1 : 1 ); |
| 1196 |
double startInterval, endInterval; |
| 1197 |
timeToInterval (me, my startSelection(), my selectedTier, & startInterval, & endInterval); |
| 1198 |
my setSelection (startInterval, endInterval); |
| 1199 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_selectionMarksChanged() |
| 1200 |
FunctionEditor_selectionMarksChanged (my functionEditor()); |
| 1201 |
} |
| 1202 |
} |
| 1203 |
static void menu_cb_SelectPreviousTier (TextGridArea me, EDITOR_ARGS) { |
| 1204 |
do_selectAdjacentTier (me, true); |
| 1205 |
} |
| 1206 |
static void menu_cb_SelectNextTier (TextGridArea me, EDITOR_ARGS) { |
| 1207 |
do_selectAdjacentTier (me, false); |
| 1208 |
} |
| 1209 |
static void do_selectAdjacentInterval (TextGridArea me, bool previous, bool shift) { |
| 1210 |
IntervalTier intervalTier; |
| 1211 |
TextTier textTier; |
| 1212 |
if (my selectedTier < 1 || my selectedTier > my textGrid() -> tiers->size) |
| 1213 |
return; |
| 1214 |
AnyTextGridTier_identifyClass (my textGrid() -> tiers->at [my selectedTier], & intervalTier, & textTier); |
| 1215 |
if (intervalTier) { |
| 1216 |
const integer n = intervalTier -> intervals.size; |
| 1217 |
if (n >= 2) { |
| 1218 |
integer iinterval = IntervalTier_timeToIndex (intervalTier, my startSelection()); |
| 1219 |
if (shift) { |
| 1220 |
const integer binterval = IntervalTier_timeToIndex (intervalTier, my startSelection()); |
| 1221 |
integer einterval = IntervalTier_timeToIndex (intervalTier, my endSelection()); |
| 1222 |
if (my endSelection() == intervalTier -> xmax) |
| 1223 |
einterval ++; |
| 1224 |
if (binterval < iinterval && einterval > iinterval + 1) { |
| 1225 |
const TextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 1226 |
my setSelection (interval -> xmin, interval -> xmax); |
| 1227 |
} else if (previous) { |
| 1228 |
if (einterval > iinterval + 1) { |
| 1229 |
if (einterval <= n + 1) { |
| 1230 |
const TextInterval interval = intervalTier -> intervals.at [einterval - 1]; |
| 1231 |
my setSelection (my startSelection(), interval -> xmin); |
| 1232 |
} |
| 1233 |
} else if (binterval > 1) { |
| 1234 |
const TextInterval interval = intervalTier -> intervals.at [binterval - 1]; |
| 1235 |
my setSelection (interval -> xmin, my endSelection()); |
| 1236 |
} |
| 1237 |
} else { |
| 1238 |
if (binterval < iinterval) { |
| 1239 |
if (binterval > 0) { |
| 1240 |
const TextInterval interval = intervalTier -> intervals.at [binterval]; |
| 1241 |
my setSelection (interval -> xmax, my endSelection()); |
| 1242 |
} |
| 1243 |
} else if (einterval <= n) { |
| 1244 |
const TextInterval interval = intervalTier -> intervals.at [einterval]; |
| 1245 |
my setSelection (my startSelection(), interval -> xmax); |
| 1246 |
} |
| 1247 |
} |
| 1248 |
} else { |
| 1249 |
iinterval = ( previous ? |
| 1250 |
iinterval > 1 ? iinterval - 1 : n : |
| 1251 |
iinterval < n ? iinterval + 1 : 1 ); |
| 1252 |
const TextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 1253 |
my setSelection (interval -> xmin, interval -> xmax); |
| 1254 |
} |
| 1255 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 1256 |
FunctionEditor_scrollToNewSelection (my functionEditor(), iinterval == n ? my startSelection() : iinterval == 1 ? my endSelection() : 0.5 * (my startSelection() + my endSelection())); |
| 1257 |
} |
| 1258 |
} else { |
| 1259 |
const integer n = textTier -> points.size; |
| 1260 |
if (n >= 2) { |
| 1261 |
integer ipoint = AnyTier_timeToHighIndex (textTier->asAnyTier(), my startSelection()); |
| 1262 |
ipoint = ( previous ? |
| 1263 |
ipoint > 1 ? ipoint - 1 : n : |
| 1264 |
ipoint < n ? ipoint + 1 : 1 ); |
| 1265 |
const TextPoint point = textTier -> points.at [ipoint]; |
| 1266 |
my setSelection (point -> number, point -> number); |
| 1267 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 1268 |
FunctionEditor_scrollToNewSelection (my functionEditor(), my startSelection()); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
} |
| 1272 |
static void menu_cb_SelectPreviousInterval (TextGridArea me, EDITOR_ARGS) { |
| 1273 |
do_selectAdjacentInterval (me, true, false); |
| 1274 |
} |
| 1275 |
static void menu_cb_SelectNextInterval (TextGridArea me, EDITOR_ARGS) { |
| 1276 |
do_selectAdjacentInterval (me, false, false); |
| 1277 |
} |
| 1278 |
static void menu_cb_ExtendSelectPreviousInterval (TextGridArea me, EDITOR_ARGS) { |
| 1279 |
do_selectAdjacentInterval (me, true, true); |
| 1280 |
} |
| 1281 |
static void menu_cb_ExtendSelectNextInterval (TextGridArea me, EDITOR_ARGS) { |
| 1282 |
do_selectAdjacentInterval (me, false, true); |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
#pragma mark - TextGridArea Draw |
| 1287 |
|
| 1288 |
static void menu_cb_DrawVisibleTextGrid (TextGridArea me, EDITOR_ARGS) { |
| 1289 |
EDITOR_FORM (U"Draw visible TextGrid", nullptr) |
| 1290 |
my v_form_pictureWindow (cmd); |
| 1291 |
my v_form_pictureMargins (cmd); |
| 1292 |
my v_form_pictureSelection (cmd); |
| 1293 |
BOOLEAN (garnish, U"Garnish", my default_picture_garnish()) |
| 1294 |
EDITOR_OK |
| 1295 |
my v_ok_pictureWindow (cmd); |
| 1296 |
my v_ok_pictureMargins (cmd); |
| 1297 |
my v_ok_pictureSelection (cmd); |
| 1298 |
SET_BOOLEAN (garnish, my classPref_picture_garnish()) |
| 1299 |
EDITOR_DO |
| 1300 |
my v_do_pictureWindow (cmd); |
| 1301 |
my v_do_pictureMargins (cmd); |
| 1302 |
my v_do_pictureSelection (cmd); |
| 1303 |
my setClassPref_picture_garnish (garnish); |
| 1304 |
DataGui_openPraatPicture (me); |
| 1305 |
TextGrid_Sound_draw (my textGrid(), nullptr, my pictureGraphics(), |
| 1306 |
my startWindow(), my endWindow(), true, my instancePref_useTextStyles(), garnish); |
| 1307 |
FunctionArea_garnishPicture (me); |
| 1308 |
DataGui_closePraatPicture (me); |
| 1309 |
EDITOR_END |
| 1310 |
} |
| 1311 |
static void menu_cb_DrawVisibleSoundAndTextGrid (TextGridArea me, EDITOR_ARGS) { |
| 1312 |
EDITOR_FORM (U"Draw visible sound and TextGrid", nullptr) |
| 1313 |
my v_form_pictureWindow (cmd); |
| 1314 |
my v_form_pictureMargins (cmd); |
| 1315 |
my v_form_pictureSelection (cmd); |
| 1316 |
BOOLEAN (garnish, U"Garnish", my default_picture_garnish()) |
| 1317 |
EDITOR_OK |
| 1318 |
my v_ok_pictureWindow (cmd); |
| 1319 |
my v_ok_pictureMargins (cmd); |
| 1320 |
my v_ok_pictureSelection (cmd); |
| 1321 |
SET_BOOLEAN (garnish, my classPref_picture_garnish()) |
| 1322 |
EDITOR_DO |
| 1323 |
my v_do_pictureWindow (cmd); |
| 1324 |
my v_do_pictureMargins (cmd); |
| 1325 |
my v_do_pictureSelection (cmd); |
| 1326 |
my setClassPref_picture_garnish (garnish); |
| 1327 |
DataGui_openPraatPicture (me); |
| 1328 |
{// scope |
| 1329 |
autoSound sound = ( |
| 1330 |
my borrowedSoundArea -> longSound() ? |
| 1331 |
LongSound_extractPart (my borrowedSoundArea -> longSound(), |
| 1332 |
my startWindow(), my endWindow(), true) |
| 1333 |
: Sound_extractPart (my borrowedSoundArea -> sound(), |
| 1334 |
my startWindow(), my endWindow(), kSound_windowShape::RECTANGULAR, 1.0, true) |
| 1335 |
); |
| 1336 |
TextGrid_Sound_draw (my textGrid(), sound.get(), my pictureGraphics(), |
| 1337 |
my startWindow(), my endWindow(), true, my instancePref_useTextStyles(), garnish); |
| 1338 |
} |
| 1339 |
FunctionArea_garnishPicture (me); |
| 1340 |
DataGui_closePraatPicture (me); |
| 1341 |
EDITOR_END |
| 1342 |
} |
| 1343 |
static void menu_cb_DrawTextGridAndPitch (TextGridArea me, EDITOR_ARGS) { |
| 1344 |
EDITOR_FORM (U"Draw TextGrid and Pitch separately", nullptr) |
| 1345 |
my v_form_pictureWindow (cmd); |
| 1346 |
COMMENT (U"TextGrid:") |
| 1347 |
BOOLEAN (showBoundariesAndPoints, U"Show boundaries and points", my default_picture_showBoundaries ()); |
| 1348 |
COMMENT (U"Pitch:") |
| 1349 |
BOOLEAN (speckle, U"Speckle", my default_picture_pitch_speckle ()); |
| 1350 |
my v_form_pictureMargins (cmd); |
| 1351 |
my v_form_pictureSelection (cmd); |
| 1352 |
BOOLEAN (garnish, U"Garnish", my default_picture_garnish ()); |
| 1353 |
EDITOR_OK |
| 1354 |
my v_ok_pictureWindow (cmd); |
| 1355 |
SET_BOOLEAN (showBoundariesAndPoints, my classPref_picture_showBoundaries()) |
| 1356 |
SET_BOOLEAN (speckle, my classPref_picture_pitch_speckle()) |
| 1357 |
my v_ok_pictureMargins (cmd); |
| 1358 |
my v_ok_pictureSelection (cmd); |
| 1359 |
SET_BOOLEAN (garnish, my classPref_picture_garnish()) |
| 1360 |
EDITOR_DO |
| 1361 |
my v_do_pictureWindow (cmd); |
| 1362 |
my setClassPref_picture_showBoundaries (showBoundariesAndPoints); // set prefs even if analyses are missing (it would be annoying not to) |
| 1363 |
my setClassPref_picture_pitch_speckle (speckle); |
| 1364 |
my v_do_pictureMargins (cmd); |
| 1365 |
my v_do_pictureSelection (cmd); |
| 1366 |
my setClassPref_picture_garnish (garnish); |
| 1367 |
SoundAnalysisArea_haveVisiblePitch (my borrowedSoundAnalysisArea); |
| 1368 |
DataGui_openPraatPicture (me); |
| 1369 |
const kPitch_unit borrowedPitchUnit = my borrowedSoundAnalysisArea -> dynamic_instancePref_pitch_unit(); |
| 1370 |
const double pitchFloor_hidden = Function_convertStandardToSpecialUnit (my borrowedSoundAnalysisArea -> d_pitch.get(), |
| 1371 |
my borrowedSoundAnalysisArea -> dynamic_instancePref_pitch_floor(), Pitch_LEVEL_FREQUENCY, (int) borrowedPitchUnit); |
| 1372 |
const double pitchCeiling_hidden = Function_convertStandardToSpecialUnit (my borrowedSoundAnalysisArea -> d_pitch.get(), |
| 1373 |
my borrowedSoundAnalysisArea -> dynamic_instancePref_pitch_ceilingOrTop(), Pitch_LEVEL_FREQUENCY, (int) borrowedPitchUnit); |
| 1374 |
const double pitchFloor_overt = Function_convertToNonlogarithmic (my borrowedSoundAnalysisArea -> d_pitch.get(), |
| 1375 |
pitchFloor_hidden, Pitch_LEVEL_FREQUENCY, (int) borrowedPitchUnit); |
| 1376 |
const double pitchCeiling_overt = Function_convertToNonlogarithmic (my borrowedSoundAnalysisArea -> d_pitch.get(), |
| 1377 |
pitchCeiling_hidden, Pitch_LEVEL_FREQUENCY, (int) borrowedPitchUnit); |
| 1378 |
const double borrowedPitchViewFrom = my borrowedSoundAnalysisArea -> dynamic_instancePref_pitch_viewFrom(); |
| 1379 |
const double borrowedPitchViewTo = my borrowedSoundAnalysisArea -> dynamic_instancePref_pitch_viewTo(); |
| 1380 |
const double pitchViewFrom_overt = ( borrowedPitchViewFrom < borrowedPitchViewTo ? borrowedPitchViewFrom : pitchFloor_overt ); |
| 1381 |
const double pitchViewTo_overt = ( borrowedPitchViewFrom < borrowedPitchViewTo ? borrowedPitchViewTo : pitchCeiling_overt ); |
| 1382 |
TextGrid_Pitch_drawSeparately (my textGrid(), my borrowedSoundAnalysisArea -> d_pitch.get(), my pictureGraphics(), my startWindow(), my endWindow(), |
| 1383 |
pitchViewFrom_overt, pitchViewTo_overt, showBoundariesAndPoints, my instancePref_useTextStyles(), garnish, |
| 1384 |
speckle, borrowedPitchUnit |
| 1385 |
); |
| 1386 |
FunctionArea_garnishPicture (me); |
| 1387 |
DataGui_closePraatPicture (me); |
| 1388 |
EDITOR_END |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
#pragma mark - TextGridArea Extract |
| 1393 |
|
| 1394 |
static void CONVERT_DATA_TO_ONE__ExtractSelectedTextGrid_preserveTimes (TextGridArea me, EDITOR_ARGS) { |
| 1395 |
CONVERT_DATA_TO_ONE |
| 1396 |
if (my endSelection() <= my startSelection()) |
| 1397 |
Melder_throw (U"No selection."); |
| 1398 |
autoTextGrid result = TextGrid_extractPart (my textGrid(), my startSelection(), my endSelection(), true); |
| 1399 |
CONVERT_DATA_TO_ONE_END (U"untitled") |
| 1400 |
} |
| 1401 |
static void CONVERT_DATA_TO_ONE__ExtractSelectedTextGrid_timeFromZero (TextGridArea me, EDITOR_ARGS) { |
| 1402 |
CONVERT_DATA_TO_ONE |
| 1403 |
if (my endSelection() <= my startSelection()) |
| 1404 |
Melder_throw (U"No selection."); |
| 1405 |
autoTextGrid result = TextGrid_extractPart (my textGrid(), my startSelection(), my endSelection(), false); |
| 1406 |
CONVERT_DATA_TO_ONE_END (U"untitled") |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
#pragma mark - TextGridArea Interval menu |
| 1411 |
|
| 1412 |
static void menu_cb_AlignInterval (TextGridArea me, EDITOR_ARGS) { |
| 1413 |
checkTierSelection (me, U"align words"); |
| 1414 |
const AnyTier tier = static_cast <AnyTier> (my textGrid() -> tiers->at [my selectedTier]); |
| 1415 |
if (tier -> classInfo != classIntervalTier) |
| 1416 |
Melder_throw (U"Alignment works only for interval tiers, whereas tier ", my selectedTier, U" is a point tier.\nSelect an interval tier instead."); |
| 1417 |
const integer intervalNumber = getSelectedInterval (me); |
| 1418 |
if (! intervalNumber) |
| 1419 |
Melder_throw (U"Select an interval first"); |
| 1420 |
if (! my instancePref_align_includeWords() && ! my instancePref_align_includePhonemes()) |
| 1421 |
Melder_throw (U"Nothing to be done.\nPlease switch on \"Include words\" and/or \"Include phonemes\" in the \"Alignment settings\"."); |
| 1422 |
{// scope |
| 1423 |
const autoMelderProgressOff noprogress; |
| 1424 |
FunctionArea_save (me, U"Align interval"); |
| 1425 |
TextGrid_anySound_alignInterval (my textGrid(), my borrowedSoundArea -> soundOrLongSound(), my selectedTier, intervalNumber, |
| 1426 |
my instancePref_align_language(), my instancePref_align_includeWords(), my instancePref_align_includePhonemes()); |
| 1427 |
} |
| 1428 |
FunctionArea_broadcastDataChanged (me); |
| 1429 |
} |
| 1430 |
static void menu_cb_AlignmentSettings (TextGridArea me, EDITOR_ARGS) { |
| 1431 |
EDITOR_FORM (U"Alignment settings", nullptr) |
| 1432 |
OPTIONMENU (language, U"Language", (int) NUMfindFirst (theSpeechSynthesizerLanguageNames, U"English (Great Britain)")) |
| 1433 |
for (integer i = 1; i <= theSpeechSynthesizerLanguageNames.size; i ++) { |
| 1434 |
OPTION (theSpeechSynthesizerLanguageNames [i]); |
| 1435 |
} |
| 1436 |
BOOLEAN (includeWords, U"Include words", my default_align_includeWords ()) |
| 1437 |
BOOLEAN (includePhonemes, U"Include phonemes", my default_align_includePhonemes ()) |
| 1438 |
BOOLEAN (allowSilences, U"Allow silences", my default_align_allowSilences ()) |
| 1439 |
EDITOR_OK |
| 1440 |
int prefVoice = (int) NUMfindFirst (theSpeechSynthesizerLanguageNames, my instancePref_align_language()); |
| 1441 |
if (prefVoice == 0) |
| 1442 |
prefVoice = (int) NUMfindFirst (theSpeechSynthesizerLanguageNames, U"English (Great Britain)"); |
| 1443 |
SET_OPTION (language, prefVoice) |
| 1444 |
SET_BOOLEAN (includeWords, my instancePref_align_includeWords()) |
| 1445 |
SET_BOOLEAN (includePhonemes, my instancePref_align_includePhonemes()) |
| 1446 |
SET_BOOLEAN (allowSilences, my instancePref_align_allowSilences()) |
| 1447 |
EDITOR_DO |
| 1448 |
my setInstancePref_align_language (theSpeechSynthesizerLanguageNames [language]); |
| 1449 |
my setInstancePref_align_includeWords (includeWords); |
| 1450 |
my setInstancePref_align_includePhonemes (includePhonemes); |
| 1451 |
my setInstancePref_align_allowSilences (allowSilences); |
| 1452 |
EDITOR_END |
| 1453 |
} |
| 1454 |
|
| 1455 |
static void menu_cb_TranscribeInterval (TextGridArea me, EDITOR_ARGS) { |
| 1456 |
checkTierSelection (me, U"transcribe interval"); |
| 1457 |
const AnyTier tier = static_cast <AnyTier> (my textGrid() -> tiers->at [my selectedTier]); |
| 1458 |
if (tier -> classInfo != classIntervalTier) |
| 1459 |
Melder_throw (U"Transcription works only for interval tiers, whereas tier ", my selectedTier, U" is a point tier.\nSelect an interval tier instead."); |
| 1460 |
const integer intervalNumber = getSelectedInterval (me); |
| 1461 |
if (! intervalNumber) |
| 1462 |
Melder_throw (U"Select an interval first"); |
| 1463 |
{// scope |
| 1464 |
const autoMelderProgressOff noprogress; |
| 1465 |
FunctionArea_save (me, U"Transcribe interval"); |
| 1466 |
TextGrid_Sound_transcribeInterval (my textGrid(), my borrowedSoundArea -> sound(), my selectedTier, intervalNumber, |
| 1467 |
my instancePref_transcribe_model(), my instancePref_transcribe_language(), |
| 1468 |
my instancePref_transcribe_includeWords(), my instancePref_transcribe_useVad(), |
| 1469 |
my instancePref_vad_speechThreshold(), my instancePref_vad_minNonSpeech(), |
| 1470 |
my instancePref_vad_minSpeech(),my instancePref_vad_speechPadding(), |
| 1471 |
my instancePref_transcribe_diarize(), |
| 1472 |
my instancePref_diarize_maxNumSpeakers(), my instancePref_diarize_allowOverlap(), |
| 1473 |
my instancePref_diarize_clusterThreshold(), my instancePref_diarize_segmentationStep()); |
| 1474 |
} |
| 1475 |
FunctionArea_broadcastDataChanged (me); |
| 1476 |
} |
| 1477 |
|
| 1478 |
static void menu_cb_TranscriptionSettings (TextGridArea me, EDITOR_ARGS) { |
| 1479 |
EDITOR_FORM (U"Transcription settings", U"transcription with whisper.cpp") |
| 1480 |
HEADING (U"Transcription...") |
| 1481 |
LISTNUMSTR (modelIndex, modelName, U"Whisper model", constSTRVEC(), 1) |
| 1482 |
OPTIONMENU (language, U"Language", (int) NUMfindFirst (theSpeechRecognizerLanguageNames(), TranscriptionDefaults::languageName)) |
| 1483 |
for (integer i = 1; i <= theSpeechRecognizerLanguageNames().size; i ++) { |
| 1484 |
OPTION (theSpeechRecognizerLanguageNames() [i]); |
| 1485 |
} |
| 1486 |
BOOLEAN (includeWords, U"Include words", my default_transcribe_includeWords()) |
| 1487 |
HEADING (U"Non-speech detection...") |
| 1488 |
BOOLEAN (useVad, U"Detect non-speech", my default_transcribe_useVad()) |
| 1489 |
NONNEGATIVE (speechProbabilityThreshold, U"Speech probability threshold (0-1)", my default_vad_speechThreshold()) |
| 1490 |
NONNEGATIVE (minNonSpeechDuration, U"Min. gap between speech segments (s)", my default_vad_minNonSpeech()) |
| 1491 |
NONNEGATIVE (minSpeechDuration, U"Min. speech segment (s)", my default_vad_minSpeech()) |
| 1492 |
NONNEGATIVE (speechPad, U"Padding around speech segments (s)", my default_vad_speechPadding()) |
| 1493 |
HEADING (U"Diarization...") |
| 1494 |
BOOLEAN (includeDiarization, U"Include diarization", my default_transcribe_diarize()) |
| 1495 |
NATURAL (maxNumSpeakers, U"Max. number of speakers (≥ 2)", DiarizationDefaults::maxNumSpeakers) |
| 1496 |
BOOLEAN (allowSpeakersOverlap, U"Allow speakers to overlap", DiarizationDefaults::allowOverlap) |
| 1497 |
POSITIVE (clusterThreshold, U"Clustering threshold (0-2)", DiarizationDefaults::clusterThreshold) |
| 1498 |
POSITIVE (segmentationStep, U"Segmentation step (0-1)", DiarizationDefaults::segmentationStep) |
| 1499 |
EDITOR_OK |
| 1500 |
static autoSTRVEC modelNames; |
| 1501 |
modelNames = copy_STRVEC (theCurrentSpeechRecognizerModelNames()); // cannot be called twice in the same scope |
| 1502 |
|
| 1503 |
Melder_require (modelNames.size > 0, |
| 1504 |
U"Found no Whisper-cpp models to do speech recognition with.\n" |
| 1505 |
U"You can install them into the subfolders “whispercpp” of the folder “models” in the Praat preferences folder." |
| 1506 |
); |
| 1507 |
|
| 1508 |
SET_BOOLEAN (includeWords, my instancePref_transcribe_includeWords()) |
| 1509 |
SET_BOOLEAN (includeDiarization, my instancePref_transcribe_diarize()) |
| 1510 |
SET_BOOLEAN (useVad, my instancePref_transcribe_useVad()) |
| 1511 |
SET_REAL (speechProbabilityThreshold, my instancePref_vad_speechThreshold()) |
| 1512 |
SET_REAL (minNonSpeechDuration, my instancePref_vad_minNonSpeech()) |
| 1513 |
SET_REAL (minSpeechDuration, my instancePref_vad_minSpeech()) |
| 1514 |
SET_REAL (speechPad, my instancePref_vad_speechPadding()) |
| 1515 |
SET_INTEGER (maxNumSpeakers, my instancePref_diarize_maxNumSpeakers()) |
| 1516 |
SET_BOOLEAN (allowSpeakersOverlap, my instancePref_diarize_allowOverlap()) |
| 1517 |
SET_REAL (clusterThreshold, my instancePref_diarize_clusterThreshold()) |
| 1518 |
SET_REAL (segmentationStep, my instancePref_diarize_segmentationStep()) |
| 1519 |
|
| 1520 |
integer prefModel = NUMfindFirst (modelNames.get (), my instancePref_transcribe_model()); |
| 1521 |
if (prefModel == 0) |
| 1522 |
prefModel = NUMfindFirst (modelNames.get (), TranscriptionDefaults::modelName); |
| 1523 |
SET_INTEGER (modelIndex, prefModel) |
| 1524 |
SET_LIST (modelIndex, modelName, modelNames.get (), prefModel) |
| 1525 |
|
| 1526 |
integer prefLanguage = NUMfindFirst (theSpeechRecognizerLanguageNames(), my instancePref_transcribe_language()); |
| 1527 |
if (prefLanguage == 0) |
| 1528 |
prefLanguage = NUMfindFirst (theSpeechRecognizerLanguageNames(), TranscriptionDefaults::languageName); |
| 1529 |
SET_OPTION (language, prefLanguage) |
| 1530 |
EDITOR_DO |
| 1531 |
my setInstancePref_transcribe_model (modelName); |
| 1532 |
my setInstancePref_transcribe_language (theSpeechRecognizerLanguageNames() [language]); |
| 1533 |
my setInstancePref_transcribe_includeWords (includeWords); |
| 1534 |
my setInstancePref_transcribe_diarize (includeDiarization); |
| 1535 |
my setInstancePref_transcribe_useVad (useVad); |
| 1536 |
my setInstancePref_vad_speechThreshold (speechProbabilityThreshold); |
| 1537 |
my setInstancePref_vad_minNonSpeech (minNonSpeechDuration); |
| 1538 |
my setInstancePref_vad_minSpeech (minSpeechDuration); |
| 1539 |
my setInstancePref_vad_speechPadding (speechPad); |
| 1540 |
my setInstancePref_diarize_maxNumSpeakers (maxNumSpeakers); |
| 1541 |
my setInstancePref_diarize_allowOverlap (allowSpeakersOverlap); |
| 1542 |
my setInstancePref_diarize_clusterThreshold (clusterThreshold); |
| 1543 |
my setInstancePref_diarize_segmentationStep (segmentationStep); |
| 1544 |
EDITOR_END |
| 1545 |
} |
| 1546 |
|
| 1547 |
static void menu_cb_DiarizeInterval (TextGridArea me, EDITOR_ARGS) { |
| 1548 |
checkTierSelection (me, U"diarize interval"); |
| 1549 |
const AnyTier tier = static_cast <AnyTier> (my textGrid() -> tiers->at [my selectedTier]); |
| 1550 |
if (tier -> classInfo != classIntervalTier) |
| 1551 |
Melder_throw (U"Diarization works only for interval tiers, whereas tier ", my selectedTier, U" is a point tier.\nSelect an interval tier instead."); |
| 1552 |
const integer intervalNumber = getSelectedInterval (me); |
| 1553 |
if (! intervalNumber) |
| 1554 |
Melder_throw (U"Select an interval first"); |
| 1555 |
{// scope |
| 1556 |
const autoMelderProgressOff noprogress; |
| 1557 |
FunctionArea_save (me, U"Diarize interval"); |
| 1558 |
TextGrid_Sound_diarizeInterval (my textGrid(), my borrowedSoundArea -> sound(), my selectedTier, intervalNumber, |
| 1559 |
my instancePref_diarize_maxNumSpeakers(), my instancePref_diarize_allowOverlap(), |
| 1560 |
my instancePref_diarize_nonSpeechLabel(), my instancePref_diarize_speechLabel(), |
| 1561 |
my instancePref_diarize_clusterThreshold(), my instancePref_diarize_segmentationStep() |
| 1562 |
); |
| 1563 |
} |
| 1564 |
FunctionArea_broadcastDataChanged (me); |
| 1565 |
} |
| 1566 |
|
| 1567 |
static void menu_cb_DiarizationSettings (TextGridArea me, EDITOR_ARGS) { |
| 1568 |
EDITOR_FORM (U"Diarization settings", U"speaker diarization with adapted pyannote.audio") |
| 1569 |
NATURAL (maxNumSpeakers, U"Max. number of speakers (≥ 2)", DiarizationDefaults::maxNumSpeakers) |
| 1570 |
BOOLEAN (allowSpeakersOverlap, U"Allow speakers to overlap", DiarizationDefaults::allowOverlap) |
| 1571 |
WORD (nonSpeechLabel, U"Non-speech interval label", DiarizationDefaults::nonSpeechLabel) |
| 1572 |
WORD (speechLabel, U"Speech interval label", DiarizationDefaults::speechLabel) |
| 1573 |
POSITIVE (clusterThreshold, U"Clustering threshold (0-2)", DiarizationDefaults::clusterThreshold) |
| 1574 |
POSITIVE (segmentationStep, U"Segmentation step (0-1)", DiarizationDefaults::segmentationStep) |
| 1575 |
EDITOR_OK |
| 1576 |
SET_INTEGER (maxNumSpeakers, my instancePref_diarize_maxNumSpeakers()) |
| 1577 |
SET_BOOLEAN (allowSpeakersOverlap, my instancePref_diarize_allowOverlap()) |
| 1578 |
SET_STRING (nonSpeechLabel, my instancePref_diarize_nonSpeechLabel()) |
| 1579 |
SET_STRING (speechLabel, my instancePref_diarize_speechLabel()) |
| 1580 |
SET_REAL (clusterThreshold, my instancePref_diarize_clusterThreshold()) |
| 1581 |
SET_REAL (segmentationStep, my instancePref_diarize_segmentationStep()) |
| 1582 |
EDITOR_DO |
| 1583 |
my setInstancePref_diarize_maxNumSpeakers (maxNumSpeakers); |
| 1584 |
my setInstancePref_diarize_allowOverlap (allowSpeakersOverlap); |
| 1585 |
my setInstancePref_diarize_nonSpeechLabel (nonSpeechLabel); |
| 1586 |
my setInstancePref_diarize_speechLabel (speechLabel); |
| 1587 |
my setInstancePref_diarize_clusterThreshold (clusterThreshold); |
| 1588 |
my setInstancePref_diarize_segmentationStep (segmentationStep); |
| 1589 |
EDITOR_END |
| 1590 |
} |
| 1591 |
|
| 1592 |
static void do_insertIntervalOnTier (TextGridArea me, int itier) { |
| 1593 |
try { |
| 1594 |
insertBoundaryOrPoint (me, itier, |
| 1595 |
my functionEditor() -> duringPlay ? my functionEditor() -> playCursor : my startSelection(), |
| 1596 |
my functionEditor() -> duringPlay ? my functionEditor() -> playCursor : my endSelection(), |
| 1597 |
true |
| 1598 |
); |
| 1599 |
my selectedTier = itier; |
| 1600 |
FunctionArea_broadcastDataChanged (me); |
| 1601 |
} catch (MelderError) { |
| 1602 |
Melder_throw (U"Interval not inserted."); |
| 1603 |
} |
| 1604 |
} |
| 1605 |
static void menu_cb_InsertIntervalOnTier1 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 1); } |
| 1606 |
static void menu_cb_InsertIntervalOnTier2 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 2); } |
| 1607 |
static void menu_cb_InsertIntervalOnTier3 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 3); } |
| 1608 |
static void menu_cb_InsertIntervalOnTier4 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 4); } |
| 1609 |
static void menu_cb_InsertIntervalOnTier5 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 5); } |
| 1610 |
static void menu_cb_InsertIntervalOnTier6 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 6); } |
| 1611 |
static void menu_cb_InsertIntervalOnTier7 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 7); } |
| 1612 |
static void menu_cb_InsertIntervalOnTier8 (TextGridArea me, EDITOR_ARGS) { do_insertIntervalOnTier (me, 8); } |
| 1613 |
|
| 1614 |
#pragma mark - TextGridArea Boundary menu |
| 1615 |
|
| 1616 |
static void menu_cb_RemovePointOrBoundary (TextGridArea me, EDITOR_ARGS) { |
| 1617 |
checkTierSelection (me, U"remove a point or boundary"); |
| 1618 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1619 |
if (anyTier -> classInfo == classIntervalTier) { |
| 1620 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1621 |
const integer selectedLeftBoundary = getSelectedLeftBoundary (me); |
| 1622 |
if (selectedLeftBoundary == 0) |
| 1623 |
Melder_throw (U"To remove a boundary, first click on it."); |
| 1624 |
|
| 1625 |
FunctionArea_save (me, U"Remove boundary"); |
| 1626 |
IntervalTier_removeLeftBoundary (tier, selectedLeftBoundary); |
| 1627 |
} else { |
| 1628 |
const TextTier tier = (TextTier) anyTier; |
| 1629 |
const integer selectedPoint = getSelectedPoint (me); |
| 1630 |
if (selectedPoint == 0) |
| 1631 |
Melder_throw (U"To remove a point, first click on it."); |
| 1632 |
|
| 1633 |
FunctionArea_save (me, U"Remove point"); |
| 1634 |
tier -> points. removeItem (selectedPoint); |
| 1635 |
} |
| 1636 |
FunctionArea_broadcastDataChanged (me); |
| 1637 |
} |
| 1638 |
static void do_movePointOrBoundary (TextGridArea me, int where) { |
| 1639 |
if (where == 0 && ! (my borrowedSoundArea && my borrowedSoundArea -> sound())) |
| 1640 |
return; |
| 1641 |
checkTierSelection (me, U"move a point or boundary"); |
| 1642 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1643 |
if (anyTier -> classInfo == classIntervalTier) { |
| 1644 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1645 |
static const conststring32 boundarySaveText [3] { U"Move boundary to zero crossing", U"Move boundary to B", U"Move boundary to E" }; |
| 1646 |
const integer selectedLeftBoundary = getSelectedLeftBoundary (me); |
| 1647 |
if (selectedLeftBoundary == 0) |
| 1648 |
Melder_throw (U"To move a boundary, first click on it."); |
| 1649 |
const TextInterval left = tier -> intervals.at [selectedLeftBoundary - 1]; |
| 1650 |
const TextInterval right = tier -> intervals.at [selectedLeftBoundary]; |
| 1651 |
const double position = ( where == 1 ? my startSelection() : where == 2 ? my endSelection() : |
| 1652 |
Sound_getNearestZeroCrossing (my borrowedSoundArea -> sound(), left -> xmax, 1) ); // STEREO BUG |
| 1653 |
if (isundef (position)) |
| 1654 |
Melder_throw (U"There is no zero crossing to move to."); |
| 1655 |
if (position <= left -> xmin || position >= right -> xmax) |
| 1656 |
Melder_throw (U"Cannot move a boundary past its neighbour."); |
| 1657 |
|
| 1658 |
FunctionArea_save (me, boundarySaveText [where]); |
| 1659 |
|
| 1660 |
left -> xmax = right -> xmin = position; |
| 1661 |
my setSelection (position, position); |
| 1662 |
} else { |
| 1663 |
TextTier tier = (TextTier) anyTier; |
| 1664 |
static const conststring32 pointSaveText [3] { U"Move point to zero crossing", U"Move point to B", U"Move point to E" }; |
| 1665 |
const integer selectedPoint = getSelectedPoint (me); |
| 1666 |
if (selectedPoint == 0) |
| 1667 |
Melder_throw (U"To move a point, first click on it."); |
| 1668 |
const TextPoint point = tier -> points.at [selectedPoint]; |
| 1669 |
const double position = ( where == 1 ? my startSelection() : where == 2 ? my endSelection() : |
| 1670 |
Sound_getNearestZeroCrossing (my borrowedSoundArea -> sound(), point -> number, 1) ); // STEREO BUG |
| 1671 |
if (isundef (position)) |
| 1672 |
Melder_throw (U"There is no zero crossing to move to."); |
| 1673 |
|
| 1674 |
FunctionArea_save (me, pointSaveText [where]); |
| 1675 |
|
| 1676 |
point -> number = position; |
| 1677 |
my setSelection (position, position); |
| 1678 |
} |
| 1679 |
FunctionArea_broadcastDataChanged (me); |
| 1680 |
} |
| 1681 |
static void menu_cb_MoveToB (TextGridArea me, EDITOR_ARGS) { |
| 1682 |
do_movePointOrBoundary (me, 1); |
| 1683 |
} |
| 1684 |
static void menu_cb_MoveToE (TextGridArea me, EDITOR_ARGS) { |
| 1685 |
do_movePointOrBoundary (me, 2); |
| 1686 |
} |
| 1687 |
static void menu_cb_MoveToZero (TextGridArea me, EDITOR_ARGS) { |
| 1688 |
do_movePointOrBoundary (me, 0); |
| 1689 |
} |
| 1690 |
static void do_insertOnTier (TextGridArea me, integer itier) { |
| 1691 |
try { |
| 1692 |
insertBoundaryOrPoint (me, itier, |
| 1693 |
my functionEditor() -> duringPlay ? my functionEditor() -> playCursor : my startSelection(), |
| 1694 |
my functionEditor() -> duringPlay ? my functionEditor() -> playCursor : my endSelection(), |
| 1695 |
false |
| 1696 |
); |
| 1697 |
my selectedTier = itier; |
| 1698 |
FunctionArea_broadcastDataChanged (me); |
| 1699 |
} catch (MelderError) { |
| 1700 |
Melder_throw (U"Boundary or point not inserted."); |
| 1701 |
} |
| 1702 |
} |
| 1703 |
static void menu_cb_InsertOnSelectedTier (TextGridArea me, EDITOR_ARGS) { |
| 1704 |
do_insertOnTier (me, my selectedTier); |
| 1705 |
} |
| 1706 |
static void menu_cb_InsertOnTier1 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 1); } |
| 1707 |
static void menu_cb_InsertOnTier2 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 2); } |
| 1708 |
static void menu_cb_InsertOnTier3 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 3); } |
| 1709 |
static void menu_cb_InsertOnTier4 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 4); } |
| 1710 |
static void menu_cb_InsertOnTier5 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 5); } |
| 1711 |
static void menu_cb_InsertOnTier6 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 6); } |
| 1712 |
static void menu_cb_InsertOnTier7 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 7); } |
| 1713 |
static void menu_cb_InsertOnTier8 (TextGridArea me, EDITOR_ARGS) { do_insertOnTier (me, 8); } |
| 1714 |
|
| 1715 |
static void menu_cb_InsertOnAllTiers (TextGridArea me, EDITOR_ARGS) { |
| 1716 |
const integer saveTier = my selectedTier; |
| 1717 |
for (integer itier = 1; itier <= my textGrid() -> tiers->size; itier ++) |
| 1718 |
do_insertOnTier (me, itier); |
| 1719 |
my selectedTier = saveTier; // only if everything went right; otherwise, the tier where something went wrong will stand selected |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
#pragma mark - TextGridArea Tier menu |
| 1724 |
|
| 1725 |
static void menu_cb_RenameTier (TextGridArea me, EDITOR_ARGS) { |
| 1726 |
EDITOR_FORM (U"Rename tier", nullptr) |
| 1727 |
SENTENCE (newName, U"New name", U""); |
| 1728 |
EDITOR_OK |
| 1729 |
checkTierSelection (me, U"rename a tier"); |
| 1730 |
const Daata tier = my textGrid() -> tiers->at [my selectedTier]; |
| 1731 |
SET_STRING (newName, tier -> name ? tier -> name.get() : U"") |
| 1732 |
EDITOR_DO |
| 1733 |
checkTierSelection (me, U"rename a tier"); |
| 1734 |
const Function tier = my textGrid() -> tiers->at [my selectedTier]; |
| 1735 |
|
| 1736 |
FunctionArea_save (me, U"Rename tier"); |
| 1737 |
|
| 1738 |
Thing_setName (tier, newName); |
| 1739 |
|
| 1740 |
FunctionArea_broadcastDataChanged (me); |
| 1741 |
EDITOR_END |
| 1742 |
} |
| 1743 |
static void CONVERT_DATA_TO_ONE__PublishTier (TextGridArea me, EDITOR_ARGS) { |
| 1744 |
CONVERT_DATA_TO_ONE |
| 1745 |
checkTierSelection (me, U"publish a tier"); |
| 1746 |
const Function tier = my textGrid() -> tiers->at [my selectedTier]; |
| 1747 |
autoTextGrid result = TextGrid_createWithoutTiers (1e308, -1e308); |
| 1748 |
TextGrid_addTier_copy (result.get(), tier); |
| 1749 |
CONVERT_DATA_TO_ONE_END (tier -> name.get()) |
| 1750 |
} |
| 1751 |
static void menu_cb_RemoveAllTextFromTier (TextGridArea me, EDITOR_ARGS) { |
| 1752 |
checkTierSelection (me, U"remove all text from a tier"); |
| 1753 |
IntervalTier intervalTier; |
| 1754 |
TextTier textTier; |
| 1755 |
AnyTextGridTier_identifyClass (my textGrid() -> tiers->at [my selectedTier], & intervalTier, & textTier); |
| 1756 |
|
| 1757 |
FunctionArea_save (me, U"Remove text from tier"); |
| 1758 |
if (intervalTier) |
| 1759 |
IntervalTier_removeText (intervalTier); |
| 1760 |
else |
| 1761 |
TextTier_removeText (textTier); |
| 1762 |
|
| 1763 |
FunctionArea_broadcastDataChanged (me); |
| 1764 |
} |
| 1765 |
static void menu_cb_RemoveTier (TextGridArea me, EDITOR_ARGS) { |
| 1766 |
if (my textGrid() -> tiers->size <= 1) |
| 1767 |
Melder_throw (U"Sorry, I refuse to remove the last tier."); |
| 1768 |
checkTierSelection (me, U"remove a tier"); |
| 1769 |
|
| 1770 |
FunctionArea_save (me, U"Remove tier"); |
| 1771 |
my textGrid() -> tiers -> removeItem (my selectedTier); |
| 1772 |
|
| 1773 |
//my textGridArea -> selectedTier = 1; TRY OUT 2022-07-23 |
| 1774 |
FunctionArea_broadcastDataChanged (me); |
| 1775 |
} |
| 1776 |
static void menu_cb_AddIntervalTier (TextGridArea me, EDITOR_ARGS) { |
| 1777 |
EDITOR_FORM (U"Add interval tier", nullptr) |
| 1778 |
NATURAL (position, U"Position", U"1 (= at top)") |
| 1779 |
SENTENCE (name, U"Name", U"") |
| 1780 |
EDITOR_OK |
| 1781 |
SET_INTEGER_AS_STRING (position, Melder_cat (my textGrid() -> tiers->size + 1, U" (= at bottom)")) |
| 1782 |
SET_STRING (name, U"") |
| 1783 |
EDITOR_DO |
| 1784 |
{// scope |
| 1785 |
autoIntervalTier tier = IntervalTier_create (my textGrid() -> xmin, my textGrid() -> xmax); |
| 1786 |
Melder_clipRight (& position, my textGrid() -> tiers->size + 1); |
| 1787 |
Thing_setName (tier.get(), name); |
| 1788 |
|
| 1789 |
FunctionArea_save (me, U"Add interval tier"); |
| 1790 |
my textGrid() -> tiers -> addItemAtPosition_move (tier.move(), position); |
| 1791 |
} |
| 1792 |
|
| 1793 |
my selectedTier = position; |
| 1794 |
FunctionArea_broadcastDataChanged (me); |
| 1795 |
EDITOR_END |
| 1796 |
} |
| 1797 |
static void menu_cb_AddPointTier (TextGridArea me, EDITOR_ARGS) { |
| 1798 |
EDITOR_FORM (U"Add point tier", nullptr) |
| 1799 |
NATURAL (position, U"Position", U"1 (= at top)") |
| 1800 |
SENTENCE (name, U"Name", U""); |
| 1801 |
EDITOR_OK |
| 1802 |
SET_INTEGER_AS_STRING (position, Melder_cat (my textGrid() -> tiers->size + 1, U" (= at bottom)")) |
| 1803 |
SET_STRING (name, U"") |
| 1804 |
EDITOR_DO |
| 1805 |
{// scope |
| 1806 |
autoTextTier tier = TextTier_create (my textGrid() -> xmin, my textGrid() -> xmax); |
| 1807 |
Melder_clipRight (& position, my textGrid() -> tiers->size + 1); |
| 1808 |
Thing_setName (tier.get(), name); |
| 1809 |
|
| 1810 |
FunctionArea_save (me, U"Add point tier"); |
| 1811 |
my textGrid() -> tiers -> addItemAtPosition_move (tier.move(), position); |
| 1812 |
} |
| 1813 |
|
| 1814 |
my selectedTier = position; |
| 1815 |
FunctionArea_broadcastDataChanged (me); |
| 1816 |
EDITOR_END |
| 1817 |
} |
| 1818 |
static void menu_cb_DuplicateTier (TextGridArea me, EDITOR_ARGS) { |
| 1819 |
EDITOR_FORM (U"Duplicate tier", nullptr) |
| 1820 |
NATURAL (position, U"Position", U"1 (= at top)") |
| 1821 |
SENTENCE (name, U"Name", U"") |
| 1822 |
EDITOR_OK |
| 1823 |
if (my selectedTier != 0) { |
| 1824 |
SET_INTEGER (position, my selectedTier + 1) |
| 1825 |
SET_STRING (name, my textGrid() -> tiers->at [my selectedTier] -> name.get()) |
| 1826 |
} |
| 1827 |
EDITOR_DO |
| 1828 |
checkTierSelection (me, U"duplicate a tier"); |
| 1829 |
const Function tier = my textGrid() -> tiers->at [my selectedTier]; |
| 1830 |
{// scope |
| 1831 |
autoFunction newTier = Data_copy (tier); |
| 1832 |
Melder_clipRight (& position, my textGrid() -> tiers->size + 1); |
| 1833 |
Thing_setName (newTier.get(), name); |
| 1834 |
|
| 1835 |
FunctionArea_save (me, U"Duplicate tier"); |
| 1836 |
my textGrid() -> tiers -> addItemAtPosition_move (newTier.move(), position); |
| 1837 |
} |
| 1838 |
|
| 1839 |
my selectedTier = position; |
| 1840 |
FunctionArea_broadcastDataChanged (me); |
| 1841 |
EDITOR_END |
| 1842 |
} |
| 1843 |
|
| 1844 |
|
| 1845 |
#pragma mark - TextGridArea Spell menu |
| 1846 |
|
| 1847 |
static void checkSpellingInTier (TextGridArea me) { |
| 1848 |
checkTierSelection (me, U"check spelling"); |
| 1849 |
const Function anyTier = my textGrid() -> tiers->at [my selectedTier]; |
| 1850 |
if (anyTier -> classInfo == classIntervalTier) { |
| 1851 |
const IntervalTier tier = (IntervalTier) anyTier; |
| 1852 |
integer iinterval = IntervalTier_timeToIndex (tier, my startSelection()) + 1; |
| 1853 |
while (iinterval <= tier -> intervals.size) { |
| 1854 |
TextInterval interval = tier -> intervals.at [iinterval]; |
| 1855 |
conststring32 text = interval -> text.get(); |
| 1856 |
if (text) { |
| 1857 |
integer position = 0; |
| 1858 |
conststring32 notAllowed = SpellingChecker_nextNotAllowedWord (my spellingChecker, text, & position); |
| 1859 |
if (notAllowed) { |
| 1860 |
my setSelection (interval -> xmin, interval -> xmax); |
| 1861 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 1862 |
FunctionEditor_scrollToNewSelection (my functionEditor(), my startSelection()); |
| 1863 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 1864 |
position, position + Melder_length (notAllowed)); |
| 1865 |
return; |
| 1866 |
} |
| 1867 |
} |
| 1868 |
iinterval ++; |
| 1869 |
} |
| 1870 |
if (iinterval > tier -> intervals.size) |
| 1871 |
Melder_beep (); |
| 1872 |
} else { |
| 1873 |
const TextTier tier = (TextTier) anyTier; |
| 1874 |
integer ipoint = AnyTier_timeToLowIndex (tier->asAnyTier(), my startSelection()) + 1; |
| 1875 |
while (ipoint <= tier -> points.size) { |
| 1876 |
TextPoint point = tier -> points.at [ipoint]; |
| 1877 |
conststring32 text = point -> mark.get(); |
| 1878 |
if (text) { |
| 1879 |
integer position = 0; |
| 1880 |
conststring32 notAllowed = SpellingChecker_nextNotAllowedWord (my spellingChecker, text, & position); |
| 1881 |
if (notAllowed) { |
| 1882 |
my setSelection (point -> number, point -> number); |
| 1883 |
Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_scrollToNewSelection() |
| 1884 |
FunctionEditor_scrollToNewSelection (my functionEditor(), point -> number); |
| 1885 |
GuiText_setSelection (my functionEditor() -> textArea, position, position + Melder_length (notAllowed)); |
| 1886 |
return; |
| 1887 |
} |
| 1888 |
} |
| 1889 |
ipoint ++; |
| 1890 |
} |
| 1891 |
if (ipoint > tier -> points.size) |
| 1892 |
Melder_beep (); |
| 1893 |
} |
| 1894 |
} |
| 1895 |
static void menu_cb_CheckSpelling (TextGridArea me, EDITOR_ARGS) { |
| 1896 |
if (my spellingChecker) { |
| 1897 |
integer left, right; |
| 1898 |
autostring32 label = GuiText_getStringAndSelectionPosition (my functionEditor() -> textArea, & left, & right); |
| 1899 |
integer position = right; |
| 1900 |
conststring32 notAllowed = SpellingChecker_nextNotAllowedWord (my spellingChecker, label.get(), & position); |
| 1901 |
if (notAllowed) |
| 1902 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 1903 |
position, position + Melder_length (notAllowed)); |
| 1904 |
else |
| 1905 |
checkSpellingInTier (me); |
| 1906 |
} |
| 1907 |
} |
| 1908 |
static void menu_cb_CheckSpellingInInterval (TextGridArea me, EDITOR_ARGS) { |
| 1909 |
if (my spellingChecker) { |
| 1910 |
integer left, right; |
| 1911 |
autostring32 label = GuiText_getStringAndSelectionPosition (my functionEditor() -> textArea, & left, & right); |
| 1912 |
integer position = right; |
| 1913 |
conststring32 notAllowed = SpellingChecker_nextNotAllowedWord (my spellingChecker, label.get(), & position); |
| 1914 |
if (notAllowed) |
| 1915 |
GuiText_setSelection (my functionEditor() -> textArea, |
| 1916 |
position, position + Melder_length (notAllowed)); |
| 1917 |
} |
| 1918 |
} |
| 1919 |
static void menu_cb_AddToUserDictionary (TextGridArea me, EDITOR_ARGS) { |
| 1920 |
if (my spellingChecker) { |
| 1921 |
const autostring32 word = GuiText_getSelection (my functionEditor() -> textArea); |
| 1922 |
SpellingChecker_addNewWord (my spellingChecker, word.get()); |
| 1923 |
FunctionArea_broadcastDataChanged (me); |
| 1924 |
} |
| 1925 |
} |
| 1926 |
|
| 1927 |
|
| 1928 |
#pragma mark - TextGridArea all menus |
| 1929 |
|
| 1930 |
void structTextGridArea :: v_createMenus () { |
| 1931 |
EditorMenu textGridMenu = Editor_addMenu (our functionEditor(), U"TextGrid", 0); |
| 1932 |
FunctionAreaMenu_addCommand (textGridMenu, U"TextGrid settings... || TextGrid preferences...", 0, |
| 1933 |
menu_cb_TextGridSettings, this); // alternative deprecated 2023 |
| 1934 |
if (editable()) { |
| 1935 |
FunctionAreaMenu_addCommand (textGridMenu, U"-- encoding --", 0, nullptr, this); |
| 1936 |
FunctionAreaMenu_addCommand (textGridMenu, U"Convert entire TextGrid to backslash trigraphs", 0, |
| 1937 |
menu_cb_ConvertToBackslashTrigraphs, this); |
| 1938 |
FunctionAreaMenu_addCommand (textGridMenu, U"Convert entire TextGrid to Unicode", 0, |
| 1939 |
menu_cb_ConvertToUnicode, this); |
| 1940 |
} |
| 1941 |
|
| 1942 |
FunctionAreaMenu_addCommand (textGridMenu, U"- Select by TextGrid:", 0, nullptr, this); |
| 1943 |
FunctionAreaMenu_addCommand (textGridMenu, U"Select previous tier", GuiMenu_OPTION | GuiMenu_UP_ARROW | GuiMenu_DEPTH_1, |
| 1944 |
menu_cb_SelectPreviousTier, this); |
| 1945 |
FunctionAreaMenu_addCommand (textGridMenu, U"Select next tier", GuiMenu_OPTION | GuiMenu_DOWN_ARROW | GuiMenu_DEPTH_1, |
| 1946 |
menu_cb_SelectNextTier, this); |
| 1947 |
FunctionAreaMenu_addCommand (textGridMenu, U"Select previous interval", GuiMenu_OPTION | GuiMenu_LEFT_ARROW | GuiMenu_DEPTH_1, |
| 1948 |
menu_cb_SelectPreviousInterval, this); |
| 1949 |
FunctionAreaMenu_addCommand (textGridMenu, U"Select next interval", GuiMenu_OPTION | GuiMenu_RIGHT_ARROW | GuiMenu_DEPTH_1, |
| 1950 |
menu_cb_SelectNextInterval, this); |
| 1951 |
FunctionAreaMenu_addCommand (textGridMenu, U"Extend-select left", GuiMenu_SHIFT | GuiMenu_OPTION | GuiMenu_LEFT_ARROW | GuiMenu_DEPTH_1, |
| 1952 |
menu_cb_ExtendSelectPreviousInterval, this); |
| 1953 |
FunctionAreaMenu_addCommand (textGridMenu, U"Extend-select right", GuiMenu_SHIFT | GuiMenu_OPTION | GuiMenu_RIGHT_ARROW | GuiMenu_DEPTH_1, |
| 1954 |
menu_cb_ExtendSelectNextInterval, this); |
| 1955 |
|
| 1956 |
FunctionAreaMenu_addCommand (textGridMenu, U"- Draw TextGrid to picture window:", 0, nullptr, this); |
| 1957 |
FunctionAreaMenu_addCommand (textGridMenu, U"Draw visible TextGrid...", 1, |
| 1958 |
menu_cb_DrawVisibleTextGrid, this); |
| 1959 |
if (our borrowedSoundArea) |
| 1960 |
FunctionAreaMenu_addCommand (textGridMenu, U"Draw visible sound and TextGrid...", 1, |
| 1961 |
menu_cb_DrawVisibleSoundAndTextGrid, this); |
| 1962 |
if (our borrowedSoundAnalysisArea) |
| 1963 |
FunctionAreaMenu_addCommand (textGridMenu, U"Draw visible pitch contour and TextGrid...", 1, |
| 1964 |
menu_cb_DrawTextGridAndPitch, this); |
| 1965 |
|
| 1966 |
FunctionAreaMenu_addCommand (textGridMenu, U"- Extract TextGrid to objects window:", 0, nullptr, this); |
| 1967 |
our extractSelectedTextGridPreserveTimesButton = FunctionAreaMenu_addCommand (textGridMenu, |
| 1968 |
U"Extract selected TextGrid (preserve times)", |
| 1969 |
1, CONVERT_DATA_TO_ONE__ExtractSelectedTextGrid_preserveTimes, this |
| 1970 |
); |
| 1971 |
our extractSelectedTextGridTimeFromZeroButton = FunctionAreaMenu_addCommand (textGridMenu, |
| 1972 |
U"Extract selected TextGrid (time from 0)", |
| 1973 |
1, CONVERT_DATA_TO_ONE__ExtractSelectedTextGrid_timeFromZero, this |
| 1974 |
); |
| 1975 |
|
| 1976 |
EditorMenu intervalMenu = Editor_addMenu (our functionEditor(), U"Interval", 0); |
| 1977 |
if (our editable()) { |
| 1978 |
if (our borrowedSoundArea) { |
| 1979 |
FunctionAreaMenu_addCommand (intervalMenu, U"Align interval", 'E', |
| 1980 |
menu_cb_AlignInterval, this); |
| 1981 |
FunctionAreaMenu_addCommand (intervalMenu, U"Alignment settings...", 0, |
| 1982 |
menu_cb_AlignmentSettings, this); |
| 1983 |
FunctionAreaMenu_addCommand (intervalMenu, U"-- after align --", 0, nullptr, this); |
| 1984 |
FunctionAreaMenu_addCommand (intervalMenu, U"Transcribe interval", 'T', |
| 1985 |
menu_cb_TranscribeInterval, this); |
| 1986 |
FunctionAreaMenu_addCommand (intervalMenu, U"Transcription settings...", 0, |
| 1987 |
menu_cb_TranscriptionSettings, this); |
| 1988 |
FunctionAreaMenu_addCommand (intervalMenu, U"-- after transcribe --", 0, nullptr, this); |
| 1989 |
FunctionAreaMenu_addCommand (intervalMenu, U"Diarize interval", 'D', |
| 1990 |
menu_cb_DiarizeInterval, this); |
| 1991 |
FunctionAreaMenu_addCommand (intervalMenu, U"Diarization settings...", 0, |
| 1992 |
menu_cb_DiarizationSettings, this); |
| 1993 |
FunctionAreaMenu_addCommand (intervalMenu, U"-- after diarize --", 0, nullptr, this); |
| 1994 |
} |
| 1995 |
FunctionAreaMenu_addCommand (intervalMenu, U"New interval:", 0, nullptr, this); |
| 1996 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 1", GuiMenu_COMMAND | '1' | GuiMenu_DEPTH_1, |
| 1997 |
menu_cb_InsertIntervalOnTier1, this); |
| 1998 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 2", GuiMenu_COMMAND | '2' | GuiMenu_DEPTH_1, |
| 1999 |
menu_cb_InsertIntervalOnTier2, this); |
| 2000 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 3", GuiMenu_COMMAND | '3' | GuiMenu_DEPTH_1, |
| 2001 |
menu_cb_InsertIntervalOnTier3, this); |
| 2002 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 4", GuiMenu_COMMAND | '4' | GuiMenu_DEPTH_1, |
| 2003 |
menu_cb_InsertIntervalOnTier4, this); |
| 2004 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 5", GuiMenu_COMMAND | '5' | GuiMenu_DEPTH_1, |
| 2005 |
menu_cb_InsertIntervalOnTier5, this); |
| 2006 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 6", GuiMenu_COMMAND | '6' | GuiMenu_DEPTH_1, |
| 2007 |
menu_cb_InsertIntervalOnTier6, this); |
| 2008 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 7", GuiMenu_COMMAND | '7' | GuiMenu_DEPTH_1, |
| 2009 |
menu_cb_InsertIntervalOnTier7, this); |
| 2010 |
FunctionAreaMenu_addCommand (intervalMenu, U"Add interval on tier 8", GuiMenu_COMMAND | '8' | GuiMenu_DEPTH_1, |
| 2011 |
menu_cb_InsertIntervalOnTier8, this); |
| 2012 |
} |
| 2013 |
|
| 2014 |
FunctionAreaMenu_addCommand (intervalMenu, U"- Query interval:", 0, nullptr, this); |
| 2015 |
FunctionAreaMenu_addCommand (intervalMenu, U"Get starting point of interval", 1, |
| 2016 |
QUERY_DATA_FOR_REAL__GetStartingPointOfInterval, this); |
| 2017 |
FunctionAreaMenu_addCommand (intervalMenu, U"Get end point of interval", 1, |
| 2018 |
QUERY_DATA_FOR_REAL__GetEndPointOfInterval, this); |
| 2019 |
FunctionAreaMenu_addCommand (intervalMenu, U"Get label of interval", 1, |
| 2020 |
QUERY_DATA_FOR_STRING__GetLabelOfInterval, this); |
| 2021 |
|
| 2022 |
EditorMenu boundaryMenu = Editor_addMenu (our functionEditor(), U"Boundary", 0); |
| 2023 |
/*FunctionAreaMenu_addCommand (boundaryMenu, U"Move to B", 0, menu_cb_MoveToB, this); |
| 2024 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Move to E", 0, menu_cb_MoveToE, this);*/ |
| 2025 |
if (our editable()) { |
| 2026 |
FunctionAreaMenu_addCommand (boundaryMenu, U"New boundary or point:", 0, nullptr, this); |
| 2027 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on selected tier", GuiMenu_ENTER | GuiMenu_DEPTH_1, |
| 2028 |
menu_cb_InsertOnSelectedTier, this); |
| 2029 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 1", GuiMenu_COMMAND_EXTRA | '1' | GuiMenu_DEPTH_1, |
| 2030 |
menu_cb_InsertOnTier1, this); |
| 2031 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 2", GuiMenu_COMMAND_EXTRA | '2' | GuiMenu_DEPTH_1, |
| 2032 |
menu_cb_InsertOnTier2, this); |
| 2033 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 3", GuiMenu_COMMAND_EXTRA | '3' | GuiMenu_DEPTH_1, |
| 2034 |
menu_cb_InsertOnTier3, this); |
| 2035 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 4", GuiMenu_COMMAND_EXTRA | '4' | GuiMenu_DEPTH_1, |
| 2036 |
menu_cb_InsertOnTier4, this); |
| 2037 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 5", GuiMenu_COMMAND_EXTRA | '5' | GuiMenu_DEPTH_1, |
| 2038 |
menu_cb_InsertOnTier5, this); |
| 2039 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 6", GuiMenu_COMMAND_EXTRA | '6' | GuiMenu_DEPTH_1, |
| 2040 |
menu_cb_InsertOnTier6, this); |
| 2041 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 7", GuiMenu_COMMAND_EXTRA | '7' | GuiMenu_DEPTH_1, |
| 2042 |
menu_cb_InsertOnTier7, this); |
| 2043 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on tier 8", GuiMenu_COMMAND_EXTRA | '8' | GuiMenu_DEPTH_1, |
| 2044 |
menu_cb_InsertOnTier8, this); |
| 2045 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Add on all tiers", GuiMenu_COMMAND_EXTRA | '9' | GuiMenu_DEPTH_1, |
| 2046 |
menu_cb_InsertOnAllTiers, this); |
| 2047 |
FunctionAreaMenu_addCommand (boundaryMenu, U"- Modify boundary or point:", 0, nullptr, this); |
| 2048 |
if (our borrowedSoundArea && ! Thing_isa (our borrowedSoundArea, classLongSoundArea)) { |
| 2049 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Move to nearest zero crossing", 1, |
| 2050 |
menu_cb_MoveToZero, this); |
| 2051 |
} |
| 2052 |
FunctionAreaMenu_addCommand (boundaryMenu, U"Remove", GuiMenu_OPTION | GuiMenu_BACKSPACE | GuiMenu_DEPTH_1, |
| 2053 |
menu_cb_RemovePointOrBoundary, this); |
| 2054 |
} |
| 2055 |
|
| 2056 |
EditorMenu tierMenu = Editor_addMenu (our functionEditor(), U"Tier", 0); |
| 2057 |
if (our editable()) { |
| 2058 |
FunctionAreaMenu_addCommand (tierMenu, U"New tier:", 0, nullptr, this); |
| 2059 |
FunctionAreaMenu_addCommand (tierMenu, U"Add interval tier...", 1, |
| 2060 |
menu_cb_AddIntervalTier, this); |
| 2061 |
FunctionAreaMenu_addCommand (tierMenu, U"Add point tier...", 1, |
| 2062 |
menu_cb_AddPointTier, this); |
| 2063 |
FunctionAreaMenu_addCommand (tierMenu, U"Duplicate tier...", 1, |
| 2064 |
menu_cb_DuplicateTier, this); |
| 2065 |
FunctionAreaMenu_addCommand (tierMenu, U"- Modify tier:", 0, nullptr, this); |
| 2066 |
FunctionAreaMenu_addCommand (tierMenu, U"Rename tier...", 1, |
| 2067 |
menu_cb_RenameTier, this); |
| 2068 |
FunctionAreaMenu_addCommand (tierMenu, U"Remove all text from tier", 1, |
| 2069 |
menu_cb_RemoveAllTextFromTier, this); |
| 2070 |
FunctionAreaMenu_addCommand (tierMenu, U"Remove entire tier", 1, |
| 2071 |
menu_cb_RemoveTier, this); |
| 2072 |
} |
| 2073 |
FunctionAreaMenu_addCommand (tierMenu, U"- Extract to list of objects:", 0, nullptr, this); |
| 2074 |
FunctionAreaMenu_addCommand (tierMenu, U"Extract entire selected tier", 1, |
| 2075 |
CONVERT_DATA_TO_ONE__PublishTier, this); |
| 2076 |
|
| 2077 |
if (our functionEditor() -> textArea) |
| 2078 |
GuiText_setChangedCallback (our functionEditor() -> textArea, gui_text_cb_changed, this); |
| 2079 |
|
| 2080 |
if (our spellingChecker) { |
| 2081 |
EditorMenu spellMenu = Editor_addMenu (our functionEditor(), U"Spell", 0); |
| 2082 |
FunctionAreaMenu_addCommand (spellMenu, U"Check spelling in tier", GuiMenu_COMMAND_EXTRA | 'L', |
| 2083 |
menu_cb_CheckSpelling, this); |
| 2084 |
FunctionAreaMenu_addCommand (spellMenu, U"Check spelling in interval", 0, |
| 2085 |
menu_cb_CheckSpellingInInterval, this); |
| 2086 |
FunctionAreaMenu_addCommand (spellMenu, U"-- edit lexicon --", 0, nullptr, this); |
| 2087 |
FunctionAreaMenu_addCommand (spellMenu, U"Add selected word to user dictionary", 0, |
| 2088 |
menu_cb_AddToUserDictionary, this); |
| 2089 |
} |
| 2090 |
} |
| 2091 |
void structTextGridArea :: v_updateMenuItems () { |
| 2092 |
GuiThing_setSensitive (extractSelectedTextGridPreserveTimesButton, our endSelection() > our startSelection()); |
| 2093 |
GuiThing_setSensitive (extractSelectedTextGridTimeFromZeroButton, our endSelection() > our startSelection()); |
| 2094 |
} |
| 2095 |
|
| 2096 |
void structTextGridArea :: v_updateText () { |
| 2097 |
if (! our textGrid()) |
| 2098 |
return; // BUG: should not be needed |
| 2099 |
if (our suppressTextCursorJump) |
| 2100 |
return; |
| 2101 |
conststring32 newText = U""; |
| 2102 |
if (our selectedTier != 0) { |
| 2103 |
IntervalTier intervalTier; |
| 2104 |
TextTier textTier; |
| 2105 |
trace (U"TextGrid ", Melder_pointer (our textGrid())); |
| 2106 |
AnyTextGridTier_identifyClass (our textGrid() -> tiers->at [our selectedTier], & intervalTier, & textTier); |
| 2107 |
if (intervalTier) { |
| 2108 |
const integer iinterval = IntervalTier_timeToIndex (intervalTier, our startSelection()); |
| 2109 |
if (iinterval) { |
| 2110 |
TextInterval interval = intervalTier -> intervals.at [iinterval]; |
| 2111 |
if (interval -> text) |
| 2112 |
newText = interval -> text.get(); |
| 2113 |
} |
| 2114 |
} else { |
| 2115 |
Melder_assert (isdefined (our startSelection())); |
| 2116 |
const integer ipoint = AnyTier_hasPoint (textTier->asAnyTier(), our startSelection()); |
| 2117 |
if (ipoint) { |
| 2118 |
TextPoint point = textTier -> points.at [ipoint]; |
| 2119 |
if (point -> mark) |
| 2120 |
newText = point -> mark.get(); |
| 2121 |
} |
| 2122 |
} |
| 2123 |
} |
| 2124 |
if (our functionEditor() -> textArea) { |
| 2125 |
our suppressRedraw = true; // prevent valueChangedCallback from redrawing |
| 2126 |
trace (U"setting new text ", newText); |
| 2127 |
GuiText_setString (our functionEditor() -> textArea, newText); |
| 2128 |
const integer cursor = Melder_length (newText); // at end |
| 2129 |
GuiText_setSelection (our functionEditor() -> textArea, cursor, cursor); |
| 2130 |
our suppressRedraw = false; |
| 2131 |
} |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
#pragma mark - TextGridArea IPA chart |
| 2136 |
|
| 2137 |
static const conststring32 characters [12] [10] = { |
| 2138 |
{ U"ɑ", U"ɐ", U"ɒ", U"æ", U"ʙ", U"ɓ", U"β", U"ç", U"ɕ", U"ð" }, |
| 2139 |
{ U"ɗ", U"ɖ", U"ɛ", U"ɜ", U"ə", U"ɢ", U"ɠ", U"ʛ", U"ɣ", U"ɤ" }, |
| 2140 |
{ U"ˠ", U"ʜ", U"ɦ", U"ħ", U"ʰ", U"ɧ", U"ɪ", U"ɨ", U"ı", U"ɟ" }, |
| 2141 |
{ U"ʝ", U"ʄ", U"ᴊ", U"ʲ", U"ʟ", U"ɬ", U"ɭ", U"ɮ", U"ɫ", U"ˡ" }, |
| 2142 |
{ U"ɰ", U"ɯ", U"ɱ", U"ɴ", U"ŋ", U"ɲ", U"ɳ", U"ⁿ", U"ɔ", U"ɵ" }, |
| 2143 |
|
| 2144 |
{ U"ø", U"œ", U"ɶ", U"ɸ", U"ɹ", U"ʀ", U"ʁ", U"ɾ", U"ɽ", U"ɺ" }, |
| 2145 |
{ U"ɻ", U"ʃ", U"ʂ", U"θ", U"ʈ", U"ʉ", U"ʊ", U"ʌ", U"ʋ", U"ʍ" }, |
| 2146 |
{ U"ʷ", U"χ", U"ʎ", U"ʏ", U"ɥ", U"ʒ", U"ʐ", U"ʑ", U"ˑ", U"ː" }, |
| 2147 |
{ U"ʔ", U"ʡ", U"ʕ", U"ʢ", U"ˤ", U"ǃ", U"ʘ", U"ǀ", U"ǁ", U"ǂ" }, |
| 2148 |
{ U"ʤ", U"ɘ", U"ɚ", U"ɝ", U"ʱ", U"ˢ", U"ʧ", U"ɞ", U"ʦ", U"ʣ" }, |
| 2149 |
|
| 2150 |
{ U"ʨ", U"ʥ", U"z̊", U"z̥", U"z̤", U"z̰", U"z̪", U"z̩", U"z̝", U"z̞" }, |
| 2151 |
{ U"ý", U"ȳ", U"ỳ", U"ÿ", U"ỹ", U"o̟", U"o̱", U"o̹", U"o̜", U"t̚" }, |
| 2152 |
}; |
| 2153 |
|
| 2154 |
void TextGridArea_drawSelectionViewer (TextGridArea me) { |
| 2155 |
Graphics_setWindow (my graphics(), 0.5, 10.5, 0.5, 12.5); |
| 2156 |
Graphics_setColour (my graphics(), Melder_WHITE); |
| 2157 |
Graphics_fillRectangle (my graphics(), 0.5, 10.5, 0.5, 12.5); |
| 2158 |
Graphics_setColour (my graphics(), Melder_BLACK); |
| 2159 |
Graphics_setFont (my graphics(), kGraphics_font::TIMES); |
| 2160 |
const double pointsPerMillimetre = 72.0 / 25.4; |
| 2161 |
const double cellWidth_points = Graphics_dxWCtoMM (my graphics(), 1.0) * pointsPerMillimetre; |
| 2162 |
const double cellHeight_points = Graphics_dyWCtoMM (my graphics(), 1.0) * pointsPerMillimetre; |
| 2163 |
const double fontSize = std::min (0.8 * cellHeight_points, 1.2 * cellWidth_points); |
| 2164 |
Graphics_setFontSize (my graphics(), fontSize); |
| 2165 |
Graphics_setTextAlignment (my graphics(), Graphics_CENTRE, Graphics_HALF); |
| 2166 |
for (integer irow = 1; irow <= 12; irow ++) |
| 2167 |
for (integer icol = 1; icol <= 10; icol ++) |
| 2168 |
Graphics_text (my graphics(), 0.0 + 1.0 * icol, 13.0 - 1.0 * irow, characters [irow-1] [icol-1]); |
| 2169 |
} |
| 2170 |
void TextGridArea_clickSelectionViewer (TextGridArea me, double x_fraction, double y_fraction) { |
| 2171 |
const integer rowNumber = Melder_iceiling ((1.0 - y_fraction) * 12.0); |
| 2172 |
const integer columnNumber = Melder_iceiling (x_fraction * 10.0); |
| 2173 |
if (rowNumber < 1 || rowNumber > 12) |
| 2174 |
return; |
| 2175 |
if (columnNumber < 1 || columnNumber > 10) |
| 2176 |
return; |
| 2177 |
conststring32 character = characters [rowNumber-1] [columnNumber-1]; |
| 2178 |
character += Melder_length (character) - 1; |
| 2179 |
if (my functionEditor() -> textArea) { |
| 2180 |
integer first = 0, last = 0; |
| 2181 |
autostring32 oldText = GuiText_getStringAndSelectionPosition (my functionEditor() -> textArea, & first, & last); |
| 2182 |
static MelderString newText; |
| 2183 |
MelderString_empty (& newText); |
| 2184 |
MelderString_ncopy (& newText, oldText.get(), first); |
| 2185 |
MelderString_append (& newText, character); |
| 2186 |
MelderString_append (& newText, oldText.get() + last); |
| 2187 |
if (my selectedTier != 0) { |
| 2188 |
IntervalTier intervalTier; |
| 2189 |
TextTier textTier; |
| 2190 |
AnyTextGridTier_identifyClass (my textGrid() -> tiers->at [my selectedTier], & intervalTier, & textTier); |
| 2191 |
if (intervalTier) { |
| 2192 |
const integer selectedInterval = getSelectedInterval (me); |
| 2193 |
if (selectedInterval != 0) { |
| 2194 |
TextInterval interval = intervalTier -> intervals.at [selectedInterval]; |
| 2195 |
TextInterval_setText (interval, newText.string); |
| 2196 |
|
| 2197 |
my suppressRedraw = true; // prevent valueChangedCallback from redrawing |
| 2198 |
trace (U"setting new text ", newText.string); |
| 2199 |
GuiText_setString (my functionEditor() -> textArea, newText.string); |
| 2200 |
GuiText_setSelection (my functionEditor() -> textArea, first + 1, first + 1); |
| 2201 |
my suppressRedraw = false; |
| 2202 |
|
| 2203 |
my suppressTextCursorJump = true; |
| 2204 |
FunctionArea_broadcastDataChanged (me); |
| 2205 |
my suppressTextCursorJump = false; |
| 2206 |
} |
| 2207 |
} else { |
| 2208 |
const integer selectedPoint = getSelectedPoint (me); |
| 2209 |
if (selectedPoint != 0) { |
| 2210 |
TextPoint point = textTier -> points.at [selectedPoint]; |
| 2211 |
point -> mark. reset(); |
| 2212 |
if (Melder_findInk (newText.string)) // any visible characters? |
| 2213 |
point -> mark = Melder_dup_f (newText.string); |
| 2214 |
|
| 2215 |
my suppressRedraw = true; // prevent valueChangedCallback from redrawing |
| 2216 |
trace (U"setting new text ", newText.string); |
| 2217 |
GuiText_setString (my functionEditor() -> textArea, newText.string); |
| 2218 |
GuiText_setSelection (my functionEditor() -> textArea, first + 1, first + 1); |
| 2219 |
my suppressRedraw = false; |
| 2220 |
|
| 2221 |
my suppressTextCursorJump = true; |
| 2222 |
FunctionArea_broadcastDataChanged (me); |
| 2223 |
my suppressTextCursorJump = false; |
| 2224 |
} |
| 2225 |
} |
| 2226 |
} |
| 2227 |
} |
| 2228 |
} |
| 2229 |
|
| 2230 |
/* End of file TextGridArea.cpp */ |