| 1 |
/* FormantPathEditor.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2020-2023 David Weenink, 2022-2024 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 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 "FormantPathEditor.h" |
| 20 |
#include "FormantPath_to_IntervalTier.h" |
| 21 |
#include "Graphics_extensions.h" |
| 22 |
#include "EditorM.h" |
| 23 |
#include "Formant_extensions.h" |
| 24 |
#include "LPC_and_Formant.h" |
| 25 |
#include "NUM2.h" |
| 26 |
#include "NUMselect.h" |
| 27 |
#include "PitchTier.h" |
| 28 |
#include "PitchTier_to_PointProcess.h" |
| 29 |
#include "Sound_and_LPC.h" |
| 30 |
#include "Sound_extensions.h" |
| 31 |
#include "TextGrid_extensions.h" |
| 32 |
|
| 33 |
Thing_implement (FormantPathEditor, FunctionEditor, 0); |
| 34 |
|
| 35 |
#include "Prefs_define.h" |
| 36 |
#include "FormantPathEditor_prefs.h" |
| 37 |
#include "Prefs_install.h" |
| 38 |
#include "FormantPathEditor_prefs.h" |
| 39 |
#include "Prefs_copyToInstance.h" |
| 40 |
#include "FormantPathEditor_prefs.h" |
| 41 |
#include "PointProcess_and_Sound.h" |
| 42 |
|
| 43 |
void structFormantPathEditor :: v1_info () { |
| 44 |
FormantPathEditor_Parent :: v1_info (); |
| 45 |
} |
| 46 |
|
| 47 |
/* |
| 48 |
MelderColour markedCandidatesColour = MelderColour (0.984, 0.951, 0.020); // Melder_YELLOW |
| 49 |
In the selectionViewer, the following light yellow colour combines better with the chosen colours |
| 50 |
for the odd and even numbered formants (Melder_RED and Melder_PURPLE, respectively). |
| 51 |
*/ |
| 52 |
MelderColour markedCandidatesColour = MelderColour (0.984,0.984, 0.7); |
| 53 |
|
| 54 |
/********** UTILITIES **********/ |
| 55 |
|
| 56 |
#define MAX_T 0.02000000001 /* Maximum interval between two voice pulses (otherwise voiceless). */ |
| 57 |
|
| 58 |
static autoPitchTier Pitch_to_PitchTier_part (Pitch me, double startTime, double endTime) { |
| 59 |
try { |
| 60 |
autoPitchTier thee = PitchTier_create (startTime, endTime); |
| 61 |
for (integer i = 1; i <= my nx; i ++) { |
| 62 |
const double time = Sampled_indexToX (me, i); |
| 63 |
if (time < startTime) |
| 64 |
continue; |
| 65 |
if (time > endTime) |
| 66 |
break; |
| 67 |
const double frequency = my frames [i]. candidates [1]. frequency; |
| 68 |
/* |
| 69 |
Count only voiced frames. |
| 70 |
*/ |
| 71 |
if (Pitch_util_frequencyIsVoiced (frequency, my ceiling)) { |
| 72 |
RealTier_addPoint (thee.get(), time, frequency); |
| 73 |
} |
| 74 |
} |
| 75 |
return thee; |
| 76 |
} catch (MelderError) { |
| 77 |
Melder_throw (me, U": part not converted to PitchTier."); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
static autoPointProcess PointProcess_extractPart (PointProcess me, double startTime, double endTime) { |
| 82 |
try { |
| 83 |
integer i1 = 1, i2 = my nt; |
| 84 |
while (i1 <= my nt && my t [i1] < startTime) |
| 85 |
i1 ++; |
| 86 |
while (i2 >= 1 && my t [i2] > endTime) |
| 87 |
i2 --; |
| 88 |
const integer nt = i2 - i1 + 1; |
| 89 |
Melder_require (nt > 0, |
| 90 |
U"There must be at least one point in the interval."); |
| 91 |
autoPointProcess thee = PointProcess_create (startTime, endTime, nt); |
| 92 |
thy nt = nt; |
| 93 |
thy t.size = nt; |
| 94 |
thy t.get() <<= my t.part (i1, i2); |
| 95 |
return thee; |
| 96 |
} catch (MelderError) { |
| 97 |
Melder_throw (me, U": could not extract part."); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
static autoSound FormantPathEditor_getResynthesis (FormantPathEditor me, double startTime, double endTime) { |
| 102 |
try { |
| 103 |
SoundAnalysisArea_haveVisiblePitch (my formantPathArea().get()); |
| 104 |
Pitch pitch = my formantPathArea() -> d_pitch.get(); |
| 105 |
autoPitchTier pitchtierPart = Pitch_to_PitchTier_part (pitch, startTime, endTime); |
| 106 |
|
| 107 |
SoundAnalysisArea_haveVisiblePulses (my formantPathArea().get()); |
| 108 |
PointProcess pulses = my formantPathArea() -> d_pulses.get(); |
| 109 |
autoPointProcess pulsesPart = PointProcess_extractPart (pulses, startTime, endTime); |
| 110 |
|
| 111 |
autoPointProcess pulses2 = PitchTier_Point_to_PointProcess (pitchtierPart.get(), pulsesPart.get(), MAX_T); |
| 112 |
const double samplingFrequency = 22050.0; |
| 113 |
autoSound train = PointProcess_to_Sound_pulseTrain (pulses2.get(), samplingFrequency , 0.7, 0.05, 30); |
| 114 |
|
| 115 |
autoFormant formantPart = Formant_extractPart (my formantPathArea() -> d_formant.get(), startTime, endTime); |
| 116 |
autoLPC lpc = Formant_to_LPC (formantPart.get(), 1.0 / samplingFrequency); |
| 117 |
|
| 118 |
autoSound sound = LPC_Sound_filter (lpc.get(), train.get(), false); |
| 119 |
Vector_scale (sound.get(), 0.99); |
| 120 |
constexpr double fadeTime = 0.005; |
| 121 |
Sound_fade (sound.get(), 0, sound -> xmin, fadeTime, false, true); |
| 122 |
Sound_fade (sound.get(), 0, sound -> xmax, -fadeTime, true, true); |
| 123 |
return sound; |
| 124 |
} catch (MelderError) { |
| 125 |
Melder_throw (U"Could not synthesize."); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
static void FormantPathEditor_getDrawingData (FormantPathEditor me, double *out_startTime, double *out_endTime, double *out_xCursor, double *out_yCursor) { |
| 130 |
double startTime = my startWindow, endTime = my endWindow; |
| 131 |
double xCursor; |
| 132 |
if (my startSelection == my endSelection) { |
| 133 |
startTime = my startWindow; |
| 134 |
endTime = my endWindow; |
| 135 |
xCursor = my startSelection; |
| 136 |
} else { |
| 137 |
startTime = my startSelection; |
| 138 |
endTime = my endSelection; |
| 139 |
xCursor = my tmin - 1.0; // don't show |
| 140 |
} |
| 141 |
if (out_startTime) |
| 142 |
*out_startTime = startTime; |
| 143 |
if (out_endTime) |
| 144 |
*out_endTime = endTime; |
| 145 |
if (out_xCursor) |
| 146 |
*out_xCursor = xCursor; |
| 147 |
if (out_yCursor) |
| 148 |
*out_yCursor = ( my formantPathArea() -> d_spectrogram_cursor > my formantPathArea() -> instancePref_spectrogram_viewFrom() && |
| 149 |
my formantPathArea() -> d_spectrogram_cursor < my formantPathArea() -> instancePref_spectrogram_viewTo() ? my formantPathArea() -> d_spectrogram_cursor : -1000.0 ); |
| 150 |
} |
| 151 |
|
| 152 |
static void Formant_replaceFrames (Formant target, integer beginFrame, integer endFrame, Formant source) { |
| 153 |
// Precondition target and source have exactly the same Sampled xmin, xmax, x1, nx, dx |
| 154 |
if (beginFrame == endFrame && beginFrame == 0) { |
| 155 |
beginFrame = 1; |
| 156 |
endFrame = target -> nx; |
| 157 |
} |
| 158 |
Melder_require (beginFrame <= endFrame, |
| 159 |
U"The start frame should not be after the end frame."); |
| 160 |
Melder_require (beginFrame > 0, |
| 161 |
U"The begin frame should be larger than zero."); |
| 162 |
Melder_require (endFrame <= target->nx, |
| 163 |
U"The end frame sould not be larger than ", target->nx); |
| 164 |
for (integer iframe = beginFrame ; iframe <= endFrame; iframe ++) { |
| 165 |
Formant_Frame targetFrame = & target -> frames [iframe]; |
| 166 |
Formant_Frame sourceFrame = & source -> frames [iframe]; |
| 167 |
sourceFrame -> copy (targetFrame); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
static void FormantPathEditor_effectuateCandidateSelection (FormantPathEditor me, integer candidate) { |
| 172 |
if (candidate > 0 && candidate <= my formantPath() -> formantCandidates.size) { |
| 173 |
double tmin_ = my startWindow, tmax_ = my endWindow; |
| 174 |
if (my startSelection < my endSelection) { |
| 175 |
tmin_ = my startSelection; |
| 176 |
tmax_ = my endSelection; |
| 177 |
} |
| 178 |
my selectedCandidate = candidate; |
| 179 |
Editor_save (me, U"Change ceiling"); |
| 180 |
integer ifmin, ifmax; |
| 181 |
Sampled_getWindowSamples (my formantPath(), tmin_, tmax_, & ifmin, & ifmax); |
| 182 |
TextGrid_addInterval_force (my formantPath() -> path.get(), tmin_, tmax_, 1_integer, Melder_integer (candidate)); |
| 183 |
Formant source = my formantPath() -> formantCandidates.at [my selectedCandidate]; |
| 184 |
Formant_replaceFrames (my formantPathArea() -> d_formant.get(), ifmin, ifmax, source); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/********** METHODS **********/ |
| 189 |
|
| 190 |
/***** TIER MENU *****/ |
| 191 |
|
| 192 |
static void menu_cb_candidate_modellingSettings (FormantPathEditor me, EDITOR_ARGS) { |
| 193 |
EDITOR_FORM (U"Candidate modelling settings", U"Candidate modelling settings...") |
| 194 |
SENTENCE (parameters_string, U"Coefficients by track", my default_modeler_numberOfParametersPerTrack()) |
| 195 |
POSITIVE (varianceExponent, U"Variance exponent", U"1.25") |
| 196 |
EDITOR_OK |
| 197 |
SET_STRING (parameters_string, my instancePref_modeler_numberOfParametersPerTrack()) |
| 198 |
EDITOR_DO |
| 199 |
my setInstancePref_modeler_numberOfParametersPerTrack (parameters_string); |
| 200 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (my instancePref_modeler_numberOfParametersPerTrack()); |
| 201 |
Melder_require (parameters.size > 0, |
| 202 |
U"At least one coefficient should be given."); |
| 203 |
const integer numberOfTracks = FormantPath_getNumberOfFormantTracks (my formantPath()); |
| 204 |
Melder_require (parameters.size <= numberOfTracks, |
| 205 |
U"The number of coefficients (", parameters.size, U") should not exceed the number of tracks (", numberOfTracks, U")."); |
| 206 |
Melder_require (num::NUMmin_e (parameters.get()) > 0.0, |
| 207 |
U"All coefficients should be larger than zero."); |
| 208 |
my setInstancePref_modeler_varianceExponent (varianceExponent); |
| 209 |
FunctionEditor_redraw (me); |
| 210 |
EDITOR_END |
| 211 |
} |
| 212 |
|
| 213 |
static double FormantPath_getRoundedMaximumCeiling (FormantPath me) { |
| 214 |
const integer ceiling = 100 * Melder_iroundDown ((my ceilings [my ceilings.size] + 100.1) / 100.0); |
| 215 |
return (double) ceiling; |
| 216 |
} |
| 217 |
|
| 218 |
static void menu_cb_AdvancedCandidateDrawingSettings (FormantPathEditor me, EDITOR_ARGS) { |
| 219 |
EDITOR_FORM (U"Candidate drawing settings", nullptr) |
| 220 |
BOOLEAN (drawEstimatedModels, U"Draw estimated models", my default_candidate_draw_estimatedModels()) |
| 221 |
POSITIVE (yGridLineEvery_Hz, U"Hor. grid lines every (Hz)", my default_candidate_draw_yGridLineEvery_Hz()) |
| 222 |
COMMENT (U"Set the maximum frequency for the display of the candidates...") |
| 223 |
POSITIVE (maximumFrequency, U"Maximum frequency (Hz)", my default_candidate_draw_maximumFrequency()) |
| 224 |
COMMENT (U"...or, overrule this setting by using the maximum ceiling instead...") |
| 225 |
BOOLEAN (useMaximumCeiling, U"Use maximum ceiling", my default_candidate_draw_useMaximumCeiling()) |
| 226 |
COMMENT (U"If you want the Spectrogram and the candidates to have the same maximum frequency.") |
| 227 |
BOOLEAN (adjustSpectrogramView, U"Adjust spectrogram view", my default_candidate_draw_adjustSpectrogramView()); |
| 228 |
BOOLEAN (drawErrorBars, U"Draw bandwidths", my default_candidate_draw_showBandwidths()) |
| 229 |
EDITOR_OK |
| 230 |
SET_BOOLEAN (drawEstimatedModels, my instancePref_candidate_draw_estimatedModels()) |
| 231 |
SET_REAL (yGridLineEvery_Hz, my instancePref_candidate_draw_yGridLineEvery_Hz()) |
| 232 |
SET_REAL (maximumFrequency, my instancePref_candidate_draw_maximumFrequency()) |
| 233 |
SET_BOOLEAN (useMaximumCeiling, my instancePref_candidate_draw_useMaximumCeiling()) |
| 234 |
SET_BOOLEAN (adjustSpectrogramView, my instancePref_candidate_draw_adjustSpectrogramView()) |
| 235 |
SET_BOOLEAN (drawErrorBars, my instancePref_candidate_draw_showBandwidths()) |
| 236 |
EDITOR_DO |
| 237 |
my setInstancePref_candidate_draw_estimatedModels (drawEstimatedModels); |
| 238 |
if (useMaximumCeiling) |
| 239 |
maximumFrequency = FormantPath_getRoundedMaximumCeiling (my formantPath()); |
| 240 |
my setInstancePref_candidate_draw_maximumFrequency (maximumFrequency); |
| 241 |
my setInstancePref_candidate_draw_yGridLineEvery_Hz (yGridLineEvery_Hz); |
| 242 |
my setInstancePref_candidate_draw_adjustSpectrogramView (adjustSpectrogramView); |
| 243 |
if (adjustSpectrogramView) |
| 244 |
my formantPathArea() -> setInstancePref_spectrogram_viewTo (maximumFrequency); |
| 245 |
my setInstancePref_candidate_draw_showBandwidths (drawErrorBars); |
| 246 |
FunctionEditor_redraw (me); |
| 247 |
Editor_broadcastDataChanged (me); |
| 248 |
EDITOR_END |
| 249 |
} |
| 250 |
|
| 251 |
static void menu_cb_candidates_FindPath (FormantPathEditor me, EDITOR_ARGS) { |
| 252 |
EDITOR_FORM (U"Find path", nullptr) |
| 253 |
COMMENT (U"Within frame:") |
| 254 |
REAL (qWeight, U"F/B weight (0-1)", U"1.0") |
| 255 |
COMMENT (U"Between frames:") |
| 256 |
REAL (frequencyChangeWeight, U"Frequency change weight (0-1)", U"1.0") |
| 257 |
REAL (stressWeight, U"Stress weight (0-1)", U"1.0") |
| 258 |
REAL (ceilingChangeWeight, U"Ceiling change weight (0-1)", U"1.0") |
| 259 |
POSITIVE (intensityModulationStepSize, U"Intensity modulation step size (dB)", U"5.0") |
| 260 |
COMMENT (U"Global stress parameters:") |
| 261 |
POSITIVE (windowLength, U"Window length", U"0.035") |
| 262 |
EDITOR_OK |
| 263 |
EDITOR_DO |
| 264 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (my instancePref_modeler_numberOfParametersPerTrack()); |
| 265 |
FormantPath_pathFinder (my formantPath(), qWeight, frequencyChangeWeight, stressWeight, ceilingChangeWeight, |
| 266 |
intensityModulationStepSize, windowLength, parameters.get(), my instancePref_modeler_varianceExponent()); |
| 267 |
my formantPathArea() -> d_formant = FormantPath_extractFormant (my formantPath()); |
| 268 |
FunctionEditor_redraw (me); |
| 269 |
Editor_broadcastDataChanged (me); |
| 270 |
EDITOR_END |
| 271 |
} |
| 272 |
|
| 273 |
static void menu_cb_selectCandidateWithlowestStress (FormantPathEditor me, EDITOR_ARGS) { |
| 274 |
double startTime = my startSelection, endTime = my endSelection; |
| 275 |
if (my startSelection == my endSelection) { |
| 276 |
startTime = my startWindow; |
| 277 |
endTime = my endWindow; |
| 278 |
} |
| 279 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (my instancePref_modeler_numberOfParametersPerTrack()); |
| 280 |
autoVEC stresses = FormantPath_getStressOfCandidates (my formantPath(), startTime, endTime, 0, 0, parameters.get(), |
| 281 |
my instancePref_modeler_varianceExponent()); |
| 282 |
const integer minPos = NUMminPos (stresses.get()); |
| 283 |
Editor_save (me, U"Change ceiling"); |
| 284 |
FormantPathEditor_effectuateCandidateSelection (me, minPos); |
| 285 |
FunctionEditor_redraw (me); |
| 286 |
Editor_broadcastDataChanged (me); |
| 287 |
} |
| 288 |
|
| 289 |
static void menu_cb_DrawVisibleCandidates (FormantPathEditor me, EDITOR_ARGS) { |
| 290 |
EDITOR_FORM (U"Draw visible candidates", nullptr) |
| 291 |
my v_form_pictureWindow (cmd); |
| 292 |
my v_form_pictureMargins (cmd); |
| 293 |
BOOLEAN (crossHairs, U"Draw cross hairs", 0) |
| 294 |
BOOLEAN (garnish, U"Garnish", my formantPathArea() -> default_picture_garnish()); |
| 295 |
EDITOR_OK |
| 296 |
my v_ok_pictureWindow (cmd); |
| 297 |
my v_ok_pictureMargins (cmd); |
| 298 |
SET_BOOLEAN (garnish, my formantPathArea() -> classPref_picture_garnish()) |
| 299 |
EDITOR_DO |
| 300 |
my v_do_pictureWindow (cmd); |
| 301 |
my v_do_pictureMargins (cmd); |
| 302 |
my formantPathArea() -> setClassPref_picture_garnish (garnish); |
| 303 |
DataGui_openPraatPicture (me); |
| 304 |
Graphics_setInner (my pictureGraphics()); |
| 305 |
double startTime, endTime, xCursor, yCursor; |
| 306 |
FormantPathEditor_getDrawingData (me, & startTime, & endTime, & xCursor, & yCursor); |
| 307 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (my instancePref_modeler_numberOfParametersPerTrack()); |
| 308 |
constexpr double xSpace_fraction = 0.1, ySpace_fraction = 0.2; |
| 309 |
FormantPath_drawAsGrid_inside (my formantPath(), my pictureGraphics(), startTime, endTime, |
| 310 |
my instancePref_candidate_draw_maximumFrequency(), 1, 5, |
| 311 |
my instancePref_candidate_draw_showBandwidths(), Melder_RED, Melder_PURPLE, 0, 0, |
| 312 |
xSpace_fraction, ySpace_fraction, my instancePref_candidate_draw_yGridLineEvery_Hz(), |
| 313 |
xCursor, yCursor, markedCandidatesColour, parameters.get(), true, true, |
| 314 |
my instancePref_modeler_varianceExponent(), my instancePref_candidate_draw_estimatedModels(), true |
| 315 |
); |
| 316 |
Graphics_unsetInner (my pictureGraphics()); |
| 317 |
DataGui_closePraatPicture (me); |
| 318 |
EDITOR_END |
| 319 |
} |
| 320 |
|
| 321 |
static void menu_cb_play_resynthesis (FormantPathEditor me, EDITOR_ARGS) { |
| 322 |
PLAY_DATA |
| 323 |
MelderAudio_stopPlaying (MelderAudio_IMPLICIT); |
| 324 |
double startTime,endTime; |
| 325 |
FormantPathEditor_getDrawingData (me, & startTime, & endTime, nullptr, nullptr); |
| 326 |
autoSound resynthesis = FormantPathEditor_getResynthesis (me, startTime, endTime); |
| 327 |
Sound_playPart (resynthesis.get(), startTime, endTime, theFunctionEditor_playCallback, me); |
| 328 |
PLAY_DATA_END |
| 329 |
} |
| 330 |
|
| 331 |
static void menu_cb_extract_resynthesis (FormantPathEditor me, EDITOR_ARGS) { |
| 332 |
CONVERT_DATA_TO_ONE |
| 333 |
double startTime,endTime; |
| 334 |
FormantPathEditor_getDrawingData (me, & startTime, & endTime, nullptr, nullptr); |
| 335 |
|
| 336 |
autoSound result = FormantPathEditor_getResynthesis (me, startTime, endTime); |
| 337 |
CONVERT_DATA_TO_ONE_END (U"untitled") |
| 338 |
} |
| 339 |
|
| 340 |
static void INFO_DATA__ceilingOfCandidate (FormantPathEditor me, EDITOR_ARGS) { |
| 341 |
INFO_DATA |
| 342 |
if (my selectedCandidate > 0 && my selectedCandidate <= my formantPath() -> ceilings.size) |
| 343 |
Melder_information (Melder_double (my formantPath() -> ceilings [my selectedCandidate])); |
| 344 |
else |
| 345 |
Melder_information (U"--undefined--"); |
| 346 |
INFO_DATA_END |
| 347 |
} |
| 348 |
|
| 349 |
static void INFO_DATA__stressOfFitsListing (FormantPathEditor me, EDITOR_ARGS) { |
| 350 |
INFO_DATA |
| 351 |
double startTime = my startSelection, endTime = my endSelection; |
| 352 |
if (my startSelection == my endSelection) { |
| 353 |
startTime = my startWindow; |
| 354 |
endTime = my endWindow; |
| 355 |
} |
| 356 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (my instancePref_modeler_numberOfParametersPerTrack()); |
| 357 |
const integer numberOfStressDecimals = 2, numberOfTimeDecimals = 6; |
| 358 |
autoTable stressTable = FormantPath_downTo_Table_stresses (my formantPath(), startTime, endTime, parameters.get(), |
| 359 |
my instancePref_modeler_varianceExponent(), numberOfStressDecimals, true, numberOfTimeDecimals); |
| 360 |
Table_list (stressTable.get(), false); |
| 361 |
INFO_DATA_END |
| 362 |
} |
| 363 |
|
| 364 |
/***** HELP MENU *****/ |
| 365 |
|
| 366 |
static void menu_cb_FormantPathEditorHelp (FormantPathEditor, EDITOR_ARGS) { |
| 367 |
Melder_help (U"FormantPathEditor"); |
| 368 |
} |
| 369 |
|
| 370 |
static void menu_cb_AboutSpecialSymbols (FormantPathEditor, EDITOR_ARGS) { |
| 371 |
Melder_help (U"Special symbols"); |
| 372 |
} |
| 373 |
|
| 374 |
static void menu_cb_PhoneticSymbols (FormantPathEditor, EDITOR_ARGS) { |
| 375 |
Melder_help (U"Phonetic symbols"); |
| 376 |
} |
| 377 |
|
| 378 |
static void menu_cb_AboutTextStyles (FormantPathEditor, EDITOR_ARGS) { |
| 379 |
Melder_help (U"Text styles"); |
| 380 |
} |
| 381 |
|
| 382 |
void structFormantPathEditor :: v_createMenus () { |
| 383 |
FormantPathEditor_Parent :: v_createMenus (); |
| 384 |
EditorMenu menu = Editor_addMenu (this, U"Candidates", 0); |
| 385 |
EditorMenu_addCommand (menu, U"Candidate modelling settings...", 0, menu_cb_candidate_modellingSettings); |
| 386 |
EditorMenu_addCommand (menu, U"Advanced candidate drawing settings...", 0, menu_cb_AdvancedCandidateDrawingSettings); |
| 387 |
EditorMenu_addCommand (menu, U"- Draw candidates to picture window:", 0, nullptr); |
| 388 |
EditorMenu_addCommand (menu, U"Draw visible candidates...", 1, menu_cb_DrawVisibleCandidates); |
| 389 |
EditorMenu_addCommand (menu, U"- Select candidates:", 0, nullptr); |
| 390 |
EditorMenu_addCommand (menu, U"Select candidate with lowest stress", 1, menu_cb_selectCandidateWithlowestStress); |
| 391 |
EditorMenu_addCommand (menu, U"Find path...", 1, menu_cb_candidates_FindPath); |
| 392 |
EditorMenu_addCommand (menu, U"- Query candidates:", 0, nullptr); |
| 393 |
EditorMenu_addCommand (menu, U"Get ceiling of candidate", 1, INFO_DATA__ceilingOfCandidate); |
| 394 |
EditorMenu_addCommand (menu, U"Stress of fits listing", 1, INFO_DATA__stressOfFitsListing); |
| 395 |
if (soundArea()) { |
| 396 |
EditorMenu_addCommand (menu, U"- Candidate resynthesis:", 0, nullptr); |
| 397 |
EditorMenu_addCommand (menu, U"Play resynthesis", 1, menu_cb_play_resynthesis); |
| 398 |
EditorMenu_addCommand (menu, U"Extract resynthesis", 1, menu_cb_extract_resynthesis); |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
void structFormantPathEditor :: v_createMenuItems_help (EditorMenu menu) { |
| 403 |
FormantPathEditor_Parent :: v_createMenuItems_help (menu); |
| 404 |
EditorMenu_addCommand (menu, U"FormantPathEditor help", '?', menu_cb_FormantPathEditorHelp); |
| 405 |
EditorMenu_addCommand (menu, U"About special symbols", 0, menu_cb_AboutSpecialSymbols); |
| 406 |
EditorMenu_addCommand (menu, U"Phonetic symbols", 0, menu_cb_PhoneticSymbols); |
| 407 |
EditorMenu_addCommand (menu, U"About text styles", 0, menu_cb_AboutTextStyles); |
| 408 |
} |
| 409 |
|
| 410 |
/********** DRAWING AREA **********/ |
| 411 |
|
| 412 |
void structFormantPathEditor :: v_drawSelectionViewer () { |
| 413 |
static double previousStartTime, previousEndTime; |
| 414 |
constexpr double xSpace_fraction = 0.1, ySpace_fraction = 0.2; |
| 415 |
Graphics_setColour (our graphics.get(), Melder_WHITE); |
| 416 |
Graphics_fillRectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0); |
| 417 |
Graphics_setColour (our graphics.get(), Melder_BLACK); |
| 418 |
Graphics_setFontSize (our graphics.get(), 10.0); |
| 419 |
Graphics_setTextAlignment (our graphics.get(), Graphics_CENTRE, Graphics_HALF); |
| 420 |
double startTime, endTime = endWindow, xCursor, yCursor; |
| 421 |
FormantPathEditor_getDrawingData (this, & startTime, & endTime, & xCursor, & yCursor); |
| 422 |
const integer nrow = 0, ncol = 0; |
| 423 |
if (startTime != previousStartTime || endTime != previousEndTime) |
| 424 |
our selectedCandidate = 0; |
| 425 |
autoINTVEC parameters = splitByWhitespaceWithRanges_INTVEC (our instancePref_modeler_numberOfParametersPerTrack()); |
| 426 |
MelderColour oddColour = MelderColour_fromColourName (our formantPathArea() -> instancePref_formant_path_oddColour()); |
| 427 |
MelderColour evenColour = MelderColour_fromColourName (our formantPathArea() -> instancePref_formant_path_evenColour()); |
| 428 |
/* |
| 429 |
Put the number of model coefficients per track at the top |
| 430 |
*/ |
| 431 |
Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, 1.0); |
| 432 |
autoMelderString infoAtTop; |
| 433 |
MelderString_append (& infoAtTop, U"Coefficients by track: ", our instancePref_modeler_numberOfParametersPerTrack()); |
| 434 |
Graphics_setTextAlignment (our graphics.get(), Graphics_CENTRE, Graphics_BOTTOM); |
| 435 |
Graphics_text (our graphics.get(), 0.5, 1.0, infoAtTop.string); |
| 436 |
/* |
| 437 |
Now do the inset |
| 438 |
*/ |
| 439 |
Graphics_setInner (our graphics.get()); |
| 440 |
FormantPath_drawAsGrid_inside (our formantPath(), our graphics.get(), startTime, endTime, |
| 441 |
our instancePref_candidate_draw_maximumFrequency(), 1, 5, our instancePref_candidate_draw_showBandwidths(), oddColour, evenColour, |
| 442 |
nrow, ncol, xSpace_fraction, ySpace_fraction, our instancePref_candidate_draw_yGridLineEvery_Hz(), xCursor, yCursor, markedCandidatesColour, |
| 443 |
parameters.get(), true, true, our instancePref_modeler_varianceExponent(), our instancePref_candidate_draw_estimatedModels(), true |
| 444 |
); |
| 445 |
/* |
| 446 |
If we don't have clicked on a candidate, one or more have been implicitely coloured / selected. |
| 447 |
Find out which one so we can set the 'selectedCandidate' |
| 448 |
*/ |
| 449 |
if (selectedCandidate == 0) |
| 450 |
selectedCandidate = FormantPath_getUniqueCandidateInInterval (our formantPath(), startTime, endTime); |
| 451 |
Graphics_unsetInner (our graphics.get()); |
| 452 |
previousStartTime = startTime; |
| 453 |
previousEndTime = endTime; |
| 454 |
} |
| 455 |
|
| 456 |
void structFormantPathEditor :: v_clickSelectionViewer (double xWC, double yWC) { |
| 457 |
/* |
| 458 |
On which of the modelers was the click? |
| 459 |
*/ |
| 460 |
integer numberOfRows, numberOfColumns; |
| 461 |
const integer numberOfCandidates = our formantPath() -> formantCandidates.size; |
| 462 |
getGridLayout (numberOfCandidates, & numberOfRows, & numberOfColumns); |
| 463 |
integer candidate = getGridCellIndex (xWC, yWC, numberOfRows, numberOfColumns); |
| 464 |
FormantPathEditor_effectuateCandidateSelection (this, candidate); |
| 465 |
FunctionEditor_redraw (this); |
| 466 |
Editor_broadcastDataChanged (this); |
| 467 |
} |
| 468 |
|
| 469 |
void structFormantPathEditor :: v_play (double startingTime, double endTime) { |
| 470 |
if (our soundArea()) { |
| 471 |
if (our clickWasModifiedByShiftKey) { |
| 472 |
autoSound resynthesis = FormantPathEditor_getResynthesis (this, startingTime, endTime); |
| 473 |
Sound_playPart (resynthesis.get(), startingTime, endTime, theFunctionEditor_playCallback, this); |
| 474 |
our clickWasModifiedByShiftKey = false; |
| 475 |
} else { |
| 476 |
SoundArea_play (our soundArea().get(), startingTime, endTime); |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
/********** EXPORTED **********/ |
| 483 |
|
| 484 |
autoFormantPathEditor FormantPathEditor_create (conststring32 title, FormantPath formantPath, Sound soundToCopy, TextGrid textGridToCopy) { |
| 485 |
try { |
| 486 |
autoFormantPathEditor me = Thing_new (FormantPathEditor); |
| 487 |
if (soundToCopy) |
| 488 |
my soundArea() = SoundArea_create (false, soundToCopy, me.get()); |
| 489 |
my formantPathArea() = |
| 490 |
soundToCopy |
| 491 |
? |
| 492 |
FormantPathArea_create (true, soundToCopy, me.get()) |
| 493 |
: |
| 494 |
(autoFormantPathArea) FormantPathArea_without_Sound_create (true, nullptr, me.get()) |
| 495 |
; |
| 496 |
my formantPathArea() -> _formantPath = formantPath; |
| 497 |
if (textGridToCopy) |
| 498 |
my textGridArea() = TextGridArea_create (false, textGridToCopy, me.get()); |
| 499 |
FunctionEditor_init (me.get(), title, formantPath); |
| 500 |
my formantPathArea() -> d_formant = FormantPath_extractFormant (formantPath); // BUG: should be in other places |
| 501 |
if (my instancePref_modeler_numberOfParametersPerTrack() [0] == U'\0') |
| 502 |
my setInstancePref_modeler_numberOfParametersPerTrack (my default_modeler_numberOfParametersPerTrack()); |
| 503 |
if (my formantPathArea() -> instancePref_formant_default_colour() [0] == U'\0') |
| 504 |
my formantPathArea() -> setInstancePref_formant_default_colour (my formantPathArea() -> default_formant_default_colour ()); |
| 505 |
if (my formantPathArea() -> instancePref_formant_path_oddColour() [0] == U'\0') |
| 506 |
my formantPathArea() -> setInstancePref_formant_path_oddColour (my formantPathArea() -> default_formant_path_oddColour ()); |
| 507 |
if (my formantPathArea() -> instancePref_formant_path_evenColour() [0] == U'\0') |
| 508 |
my formantPathArea() -> setInstancePref_formant_path_evenColour (my formantPathArea() -> default_formant_path_evenColour ()); |
| 509 |
if (my formantPathArea() -> instancePref_formant_selected_colour() [0] == U'\0') |
| 510 |
my formantPathArea() -> setInstancePref_formant_selected_colour (my formantPathArea() -> default_formant_selected_colour ()); |
| 511 |
return me; |
| 512 |
} catch (MelderError) { |
| 513 |
Melder_throw (U"FormantPathEditor window not created."); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
/* End of file FormantPathEditor.cpp */ |