| 1 | /* SoundAnalysisArea.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2026 Paul Boersma, 2026 yjzxkxdn (spectrogram colour schemes) |
| 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 "SoundAnalysisArea.h" |
| 20 | #include "Sound_and_Spectrogram.h" |
| 21 | #include "Photo.h" |
| 22 | #include "Sound_and_Spectrum.h" |
| 23 | #include "Sound_to_Pitch.h" |
| 24 | #include "Sound_to_Intensity.h" |
| 25 | #include "Sound_to_Formant.h" |
| 26 | #include "Pitch_to_PointProcess.h" |
| 27 | #include "VoiceAnalysis.h" |
| 28 | #include "EditorM.h" |
| 29 | #include "praat_script.h" |
| 30 | |
| 31 | Thing_implement (SoundAnalysisArea, FunctionArea, 0); |
| 32 | |
| 33 | #include "enums_getText.h" |
| 34 | #include "SoundAnalysisArea_enums.h" |
| 35 | #include "enums_getValue.h" |
| 36 | #include "SoundAnalysisArea_enums.h" |
| 37 | |
| 38 | #include "Prefs_define.h" |
| 39 | #include "SoundAnalysisArea_prefs.h" |
| 40 | #include "Prefs_install.h" |
| 41 | #include "SoundAnalysisArea_prefs.h" |
| 42 | #include "Prefs_copyToInstance.h" |
| 43 | #include "SoundAnalysisArea_prefs.h" |
| 44 | |
| 45 | void structSoundAnalysisArea :: v_reset_analysis () { |
| 46 | our d_spectrogramList. reset(); |
| 47 | our d_pitch. reset(); |
| 48 | our d_intensity. reset(); |
| 49 | our d_formant. reset(); |
| 50 | our d_pulses. reset(); |
| 51 | } |
| 52 | |
| 53 | #define DEFINE_dynamic_instancePref_pitch(type,setting) \ |
| 54 | type structSoundAnalysisArea :: dynamic_instancePref_pitch_##setting () { \ |
| 55 | switch (our instancePref_pitch_method()) { \ |
| 56 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_AUTOCORRELATION: \ |
| 57 | return our instancePref_pitch_filteredAC_##setting(); \ |
| 58 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION: \ |
| 59 | return our instancePref_pitch_rawCC_##setting(); \ |
| 60 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION: \ |
| 61 | return our instancePref_pitch_rawAC_##setting(); \ |
| 62 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_CROSS_CORRELATION: \ |
| 63 | return our instancePref_pitch_filteredCC_##setting(); \ |
| 64 | default: \ |
| 65 | Melder_crash (U"Unknown pitch analysis method ", (int) our instancePref_pitch_method(), U"."); \ |
| 66 | } \ |
| 67 | } |
| 68 | DEFINE_dynamic_instancePref_pitch (double, floor) |
| 69 | DEFINE_dynamic_instancePref_pitch (kPitch_unit, unit) |
| 70 | DEFINE_dynamic_instancePref_pitch (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod) |
| 71 | DEFINE_dynamic_instancePref_pitch (double, viewFrom) |
| 72 | DEFINE_dynamic_instancePref_pitch (double, viewTo) |
| 73 | DEFINE_dynamic_instancePref_pitch (bool, veryAccurate) |
| 74 | DEFINE_dynamic_instancePref_pitch (integer, maximumNumberOfCandidates) |
| 75 | DEFINE_dynamic_instancePref_pitch (double, silenceThreshold) |
| 76 | DEFINE_dynamic_instancePref_pitch (double, voicingThreshold) |
| 77 | |
| 78 | double structSoundAnalysisArea :: dynamic_instancePref_pitch_ceilingOrTop () { |
| 79 | switch (our instancePref_pitch_method()) { |
| 80 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_AUTOCORRELATION: |
| 81 | return our instancePref_pitch_filteredAC_top(); |
| 82 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION: |
| 83 | return our instancePref_pitch_rawCC_ceiling(); |
| 84 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION: |
| 85 | return our instancePref_pitch_rawAC_ceiling(); |
| 86 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_CROSS_CORRELATION: |
| 87 | return our instancePref_pitch_filteredCC_top(); |
| 88 | default: |
| 89 | Melder_crash (U"Unknown pitch analysis method ", (int) our instancePref_pitch_method(), U"."); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | static double dynamic_instancePref_pitch_attenuationAtTop (SoundAnalysisArea me) { |
| 94 | switch (my instancePref_pitch_method()) { |
| 95 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_AUTOCORRELATION: |
| 96 | return my instancePref_pitch_filteredAC_attenuationAtTop(); |
| 97 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_CROSS_CORRELATION: |
| 98 | return my instancePref_pitch_filteredCC_attenuationAtTop(); |
| 99 | default: |
| 100 | Melder_crash (U"Unknown pitch analysis method ", (int) my instancePref_pitch_method(), U"."); |
| 101 | } |
| 102 | } |
| 103 | static double periodsPerAnalysisWindow (SoundAnalysisArea me) { |
| 104 | switch (my instancePref_pitch_method()) { |
| 105 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_AUTOCORRELATION: |
| 106 | return 3.0; |
| 107 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION: |
| 108 | return 1.0; |
| 109 | case kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION: |
| 110 | return 3.0; |
| 111 | case kSoundAnalysisArea_pitch_analysisMethod::FILTERED_CROSS_CORRELATION: |
| 112 | return 1.0; |
| 113 | default: |
| 114 | Melder_crash (U"Unknown pitch analysis method ", (int) my instancePref_pitch_method(), U"."); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | Some tryToCompute<Analysis>() functions. |
| 120 | The "try" means that any exceptions that are generated, will be ignored; |
| 121 | this is necessary because these functions have to be used in an editor window, |
| 122 | where they have to work in the background, |
| 123 | because they are not explicly called by a user action. |
| 124 | |
| 125 | Postcondition: |
| 126 | - If a tryToCompute<Analysis>() function fails, the <Analysis> should be null; |
| 127 | this is how tryToCompute<Analysis>() signals failure. |
| 128 | */ |
| 129 | static autoSound extractSoundOrNull (SoundAnalysisArea me, double tmin, double tmax) { |
| 130 | autoSound sound; |
| 131 | if (my longSound()) { |
| 132 | if (Function_intersectRangeWithDomain (my longSound(), & tmin, & tmax)) |
| 133 | sound = LongSound_extractPart (my longSound(), tmin, tmax, true); |
| 134 | } else if (my sound()) { |
| 135 | if (Function_intersectRangeWithDomain (my sound(), & tmin, & tmax)) |
| 136 | sound = Sound_extractPart (my sound(), tmin, tmax, kSound_windowShape::RECTANGULAR, 1.0, true); |
| 137 | } |
| 138 | return sound; |
| 139 | } |
| 140 | static void tryToComputeSpectrogram (SoundAnalysisArea me) { |
| 141 | autoMelderProgressOff progress; |
| 142 | const double margin = ( my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? |
| 143 | my instancePref_spectrogram_windowLength() : 0.5 * my instancePref_spectrogram_windowLength() ); |
| 144 | try { |
| 145 | my d_spectrogramList = SpectrogramList_create (); // also throws away the old one |
| 146 | autoSound sound = extractSoundOrNull (me, my startWindow() - margin, my endWindow() + margin); |
| 147 | if (! sound) |
| 148 | return; |
| 149 | if (sound -> ny == 3 && my instancePref_spectrogram_threeChannelsIsRGB()) { |
| 150 | for (integer ichan = 1; ichan <= 3; ichan ++) { |
| 151 | autoSound channel = Sound_extractChannel (sound.get(), ichan); |
| 152 | autoSpectrogram spectrogram = Sound_to_Spectrogram_e (channel.get(), |
| 153 | my instancePref_spectrogram_windowLength(), |
| 154 | my instancePref_spectrogram_viewTo(), |
| 155 | (my endWindow() - my startWindow()) / my instancePref_spectrogram_timeSteps(), |
| 156 | my instancePref_spectrogram_viewTo() / my instancePref_spectrogram_frequencySteps(), |
| 157 | my instancePref_spectrogram_windowShape(), 8.0, 8.0 |
| 158 | ); |
| 159 | spectrogram -> xmin = my startWindow(); |
| 160 | spectrogram -> xmax = my endWindow(); |
| 161 | my d_spectrogramList -> addItem_move (spectrogram.move()); |
| 162 | } |
| 163 | } else { |
| 164 | autoSpectrogram spectrogram = Sound_to_Spectrogram_e (sound.get(), |
| 165 | my instancePref_spectrogram_windowLength(), |
| 166 | my instancePref_spectrogram_viewTo(), |
| 167 | (my endWindow() - my startWindow()) / my instancePref_spectrogram_timeSteps(), |
| 168 | my instancePref_spectrogram_viewTo() / my instancePref_spectrogram_frequencySteps(), |
| 169 | my instancePref_spectrogram_windowShape(), 8.0, 8.0 |
| 170 | ); |
| 171 | my d_spectrogramList -> addItem_move (spectrogram.move()); |
| 172 | } |
| 173 | } catch (MelderError) { |
| 174 | my d_spectrogramList. reset(); // signal a failure |
| 175 | Melder_clearError (); |
| 176 | } |
| 177 | } |
| 178 | static void tryToComputePitch (SoundAnalysisArea me) { |
| 179 | autoMelderProgressOff progress; |
| 180 | const double margin = ( my dynamic_instancePref_pitch_veryAccurate() ? 3.0 : 1.5 ) / my dynamic_instancePref_pitch_floor(); |
| 181 | try { |
| 182 | autoSound sound = extractSoundOrNull (me, my startWindow() - margin, my endWindow() + margin); |
| 183 | if (! sound) |
| 184 | return; |
| 185 | const double pitchTimeStep = ( |
| 186 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::FIXED_ ? my instancePref_fixedTimeStep() : |
| 187 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::VIEW_DEPENDENT ? (my endWindow() - my startWindow()) / my instancePref_numberOfTimeStepsPerView() : |
| 188 | 0.0 // the default: determined by pitch floor |
| 189 | ); |
| 190 | if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::FILTERED_AUTOCORRELATION) |
| 191 | my d_pitch = Sound_to_Pitch_filteredAc (sound.get(), |
| 192 | pitchTimeStep, my instancePref_pitch_filteredAC_floor(), my instancePref_pitch_filteredAC_top(), |
| 193 | my instancePref_pitch_filteredAC_maximumNumberOfCandidates(), my instancePref_pitch_filteredAC_veryAccurate(), |
| 194 | my instancePref_pitch_filteredAC_attenuationAtTop(), |
| 195 | my instancePref_pitch_filteredAC_silenceThreshold(), my instancePref_pitch_filteredAC_voicingThreshold(), |
| 196 | my instancePref_pitch_filteredAC_octaveCost(), my instancePref_pitch_filteredAC_octaveJumpCost(), |
| 197 | my instancePref_pitch_filteredAC_voicedUnvoicedCost() |
| 198 | ); |
| 199 | else if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION) |
| 200 | my d_pitch = Sound_to_Pitch_rawCc (sound.get(), |
| 201 | pitchTimeStep, my instancePref_pitch_rawCC_floor(), my instancePref_pitch_rawCC_ceiling(), |
| 202 | my instancePref_pitch_rawCC_maximumNumberOfCandidates(), my instancePref_pitch_rawCC_veryAccurate(), |
| 203 | my instancePref_pitch_rawCC_silenceThreshold(), my instancePref_pitch_rawCC_voicingThreshold(), |
| 204 | my instancePref_pitch_rawCC_octaveCost(), my instancePref_pitch_rawCC_octaveJumpCost(), |
| 205 | my instancePref_pitch_rawCC_voicedUnvoicedCost() |
| 206 | ); |
| 207 | else if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION) |
| 208 | my d_pitch = Sound_to_Pitch_rawAc (sound.get(), |
| 209 | pitchTimeStep, my instancePref_pitch_rawAC_floor(), my instancePref_pitch_rawAC_ceiling(), |
| 210 | my instancePref_pitch_rawAC_maximumNumberOfCandidates(), my instancePref_pitch_rawAC_veryAccurate(), |
| 211 | my instancePref_pitch_rawAC_silenceThreshold(), my instancePref_pitch_rawAC_voicingThreshold(), |
| 212 | my instancePref_pitch_rawAC_octaveCost(), my instancePref_pitch_rawAC_octaveJumpCost(), |
| 213 | my instancePref_pitch_rawAC_voicedUnvoicedCost() |
| 214 | ); |
| 215 | else if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::FILTERED_CROSS_CORRELATION) |
| 216 | my d_pitch = Sound_to_Pitch_filteredCc (sound.get(), pitchTimeStep, |
| 217 | my instancePref_pitch_filteredCC_floor(), my instancePref_pitch_filteredCC_top(), |
| 218 | my instancePref_pitch_filteredCC_maximumNumberOfCandidates(), my instancePref_pitch_filteredCC_veryAccurate(), |
| 219 | my instancePref_pitch_filteredCC_attenuationAtTop(), |
| 220 | my instancePref_pitch_filteredCC_silenceThreshold(), my instancePref_pitch_filteredCC_voicingThreshold(), |
| 221 | my instancePref_pitch_filteredCC_octaveCost(), my instancePref_pitch_filteredCC_octaveJumpCost(), |
| 222 | my instancePref_pitch_filteredCC_voicedUnvoicedCost() |
| 223 | ); |
| 224 | else |
| 225 | Melder_crash (U"Unknown pitch method ", (int) my instancePref_pitch_method(), U"."); |
| 226 | my d_pitch -> xmin = my startWindow(); |
| 227 | my d_pitch -> xmax = my endWindow(); |
| 228 | } catch (MelderError) { |
| 229 | my d_pitch. reset(); // signal a failure |
| 230 | Melder_clearError (); |
| 231 | } |
| 232 | } |
| 233 | static void tryToComputeIntensity (SoundAnalysisArea me) { |
| 234 | autoMelderProgressOff progress; |
| 235 | const double margin = 3.2 / my dynamic_instancePref_pitch_floor(); |
| 236 | try { |
| 237 | autoSound sound = extractSoundOrNull (me, my startWindow() - margin, my endWindow() + margin); |
| 238 | if (! sound) |
| 239 | return; |
| 240 | my d_intensity = Sound_to_Intensity (sound.get(), my dynamic_instancePref_pitch_floor(), |
| 241 | my endWindow() - my startWindow() > my instancePref_longestAnalysis() ? (my endWindow() - my startWindow()) / 100 : 0.0, |
| 242 | my instancePref_intensity_subtractMeanPressure() |
| 243 | ); |
| 244 | my d_intensity -> xmin = my startWindow(); |
| 245 | my d_intensity -> xmax = my endWindow(); |
| 246 | } catch (MelderError) { |
| 247 | my d_intensity. reset(); // signal a failure |
| 248 | Melder_clearError (); |
| 249 | } |
| 250 | } |
| 251 | static void tryToComputeFormants (SoundAnalysisArea me) { |
| 252 | autoMelderProgressOff progress; |
| 253 | const double margin = my instancePref_formant_windowLength(); |
| 254 | try { |
| 255 | autoSound sound = ( my endWindow() - my startWindow() > my instancePref_longestAnalysis() ? |
| 256 | extractSoundOrNull (me, |
| 257 | 0.5 * (my startWindow() + my endWindow() - my instancePref_longestAnalysis()) - margin, |
| 258 | 0.5 * (my startWindow() + my endWindow() + my instancePref_longestAnalysis()) + margin |
| 259 | ) : |
| 260 | extractSoundOrNull (me, my startWindow() - margin, my endWindow() + margin) |
| 261 | ); |
| 262 | if (! sound) |
| 263 | return; |
| 264 | const double formantTimeStep = ( |
| 265 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::FIXED_ ? my instancePref_fixedTimeStep() : |
| 266 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::VIEW_DEPENDENT ? (my endWindow() - my startWindow()) / my instancePref_numberOfTimeStepsPerView() : |
| 267 | 0.0 // the default: determined by analysis window length |
| 268 | ); |
| 269 | my d_formant = Sound_to_Formant_any (sound.get(), formantTimeStep, |
| 270 | Melder_iround (my instancePref_formant_numberOfFormants() * 2.0), my instancePref_formant_ceiling(), |
| 271 | my instancePref_formant_windowLength(), (int) my instancePref_formant_method(), my instancePref_formant_preemphasisFrom(), 50.0 |
| 272 | ); |
| 273 | my d_formant -> xmin = my startWindow(); |
| 274 | my d_formant -> xmax = my endWindow(); |
| 275 | } catch (MelderError) { |
| 276 | my d_formant. reset(); // signal a failure |
| 277 | Melder_clearError (); |
| 278 | } |
| 279 | } |
| 280 | static void tryToComputePulses (SoundAnalysisArea me) { |
| 281 | if (! my d_pitch) |
| 282 | tryToComputePitch (me); |
| 283 | if (my d_pitch) { |
| 284 | autoMelderProgressOff progress; |
| 285 | try { |
| 286 | autoSound sound = extractSoundOrNull (me, my startWindow(), my endWindow()); |
| 287 | if (! sound) |
| 288 | return; |
| 289 | my d_pulses = Sound_Pitch_to_PointProcess_cc (sound.get(), my d_pitch.get()); |
| 290 | } catch (MelderError) { |
| 291 | my d_pulses. reset(); // signal a failure |
| 292 | Melder_clearError (); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | Some tryToHave<Analysis>() functions. |
| 299 | The "try" again means that any exceptions that are generated, will be ignored; |
| 300 | failure is again signalled by the Analysis being null. |
| 301 | The "have" means that these functions do nothing if the Analysis already exists, |
| 302 | but will (try to) create an Analysis if it does not exist. |
| 303 | */ |
| 304 | static void tryToHaveSpectrogram (SoundAnalysisArea me) { |
| 305 | if (! my d_spectrogramList && my endWindow() - my startWindow() <= my instancePref_longestAnalysis()) |
| 306 | tryToComputeSpectrogram (me); |
| 307 | } |
| 308 | static void tryToHavePitch (SoundAnalysisArea me) { |
| 309 | if (! my d_pitch && my endWindow() - my startWindow() <= my instancePref_longestAnalysis()) |
| 310 | tryToComputePitch (me); |
| 311 | } |
| 312 | static void tryToHaveIntensity (SoundAnalysisArea me) { |
| 313 | if (! my d_intensity && my endWindow() - my startWindow() <= my instancePref_longestAnalysis()) |
| 314 | tryToComputeIntensity (me); |
| 315 | } |
| 316 | static void tryToHaveFormants (SoundAnalysisArea me) { |
| 317 | if (! my d_formant && my endWindow() - my startWindow() <= my instancePref_longestAnalysis()) |
| 318 | tryToComputeFormants (me); |
| 319 | } |
| 320 | static void tryToHavePulses (SoundAnalysisArea me) { |
| 321 | if (! my d_pulses && my endWindow() - my startWindow() <= my instancePref_longestAnalysis()) |
| 322 | tryToComputePulses (me); |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | Some SoundAnalysisArea_haveVisible<Analysis>() functions. |
| 327 | These add error reporting that is specific to having editor windows, |
| 328 | thereby replacing the ignored errors that would have been generated |
| 329 | if the analysis had been performed by an explicit user action. |
| 330 | |
| 331 | These can be used for querying, extracting, and drawing to the Picture window, |
| 332 | because those require the user to be aware of the need to have a visible Analysis. |
| 333 | They cannot be used when drawing into the analysis part of the editor window, |
| 334 | because of the low degree of explicitness of the need to draw an Analysis there. |
| 335 | */ |
| 336 | void SoundAnalysisArea_haveVisibleSpectrogram (SoundAnalysisArea me) { |
| 337 | if (! my instancePref_spectrogram_show()) |
| 338 | Melder_throw (U"No spectrogram is visible.\nFirst choose \"Show spectrogram\" from the Spectrogram menu."); |
| 339 | tryToHaveSpectrogram (me); |
| 340 | if (! my d_spectrogramList) |
| 341 | Melder_throw (U"The spectrogram is not defined at the edge of the sound."); |
| 342 | } |
| 343 | void SoundAnalysisArea_haveVisiblePitch (SoundAnalysisArea me) { |
| 344 | if (! my instancePref_pitch_show()) |
| 345 | Melder_throw (U"No pitch contour is visible.\nFirst choose \"Show pitch\" from the Pitch menu."); |
| 346 | tryToHavePitch (me); |
| 347 | if (! my d_pitch) |
| 348 | Melder_throw (U"The pitch contour is not defined at the edge of the sound."); |
| 349 | } |
| 350 | void SoundAnalysisArea_haveVisibleIntensity (SoundAnalysisArea me) { |
| 351 | if (! my instancePref_intensity_show()) |
| 352 | Melder_throw (U"No intensity contour is visible.\nFirst choose \"Show intensity\" from the Intensity menu."); |
| 353 | tryToHaveIntensity (me); |
| 354 | if (! my d_intensity) |
| 355 | Melder_throw (U"The intensity curve is not defined at the edge of the sound."); |
| 356 | } |
| 357 | void SoundAnalysisArea_haveVisibleFormants (SoundAnalysisArea me) { |
| 358 | if (! my instancePref_formant_show()) |
| 359 | Melder_throw (U"No formant contour is visible.\nFirst choose \"Show formants\" from the Formants menu."); |
| 360 | tryToHaveFormants (me); |
| 361 | if (! my d_formant) |
| 362 | Melder_throw (U"The formants are not defined at the edge of the sound."); |
| 363 | } |
| 364 | void SoundAnalysisArea_haveVisiblePulses (SoundAnalysisArea me) { |
| 365 | if (! my instancePref_pulses_show()) |
| 366 | Melder_throw (U"No pulses are visible.\nFirst choose \"Show pulses\" from the Pulses menu."); |
| 367 | tryToHavePulses (me); |
| 368 | if (! my d_pulses) |
| 369 | Melder_throw (U"The pulses are not defined at the edge of the sound."); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | #pragma mark - SoundAnalysisArea tracking |
| 374 | |
| 375 | bool structSoundAnalysisArea :: v_mouse (GuiDrawingArea_MouseEvent event, double x_world, double localY_fraction) { |
| 376 | #if 0 |
| 377 | BUG: NYI |
| 378 | if (event -> isClick()) { |
| 379 | if (our instancePref_pitch_show()) { |
| 380 | if (x_world >= our endWindow() && localY_fraction > 0.96 && localY_fraction <= 1.00) { |
| 381 | our setInstancePref_pitch_ceiling (our instancePref_pitch_ceiling() * 1.26); |
| 382 | our d_pitch. reset(); |
| 383 | our d_intensity. reset(); |
| 384 | our d_pulses. reset(); |
| 385 | return FunctionEditor_UPDATE_NEEDED; |
| 386 | } |
| 387 | if (x_world >= our endWindow() && localY_fraction > 0.92 && localY_fraction <= 0.96) { |
| 388 | our setInstancePref_pitch_ceiling (our instancePref_pitch_ceiling() / 1.26); |
| 389 | our d_pitch. reset(); |
| 390 | our d_intensity. reset(); |
| 391 | our d_pulses. reset(); |
| 392 | return FunctionEditor_UPDATE_NEEDED; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | #endif |
| 397 | if (x_world > our startWindow() && x_world < our endWindow()) |
| 398 | our d_spectrogram_cursor = localY_fraction * our instancePref_spectrogram_viewTo() |
| 399 | + (1.0 - localY_fraction) * our instancePref_spectrogram_viewFrom(); |
| 400 | return FunctionEditor_defaultMouseInWideDataView (our functionEditor(), event, x_world); |
| 401 | } |
| 402 | |
| 403 | bool SoundAnalysisArea_mouse (SoundAnalysisArea me, GuiDrawingArea_MouseEvent event, double x_world, double globalY_fraction) { |
| 404 | const double localY_fraction = my y_fraction_globalToLocal (globalY_fraction); |
| 405 | return my v_mouse (event, x_world, localY_fraction); |
| 406 | } |
| 407 | |
| 408 | #pragma mark - SoundAnalysisArea info |
| 409 | |
| 410 | void structSoundAnalysisArea :: v_spectrogramInfo () const { |
| 411 | /* Spectrogram flag: */ |
| 412 | MelderInfo_writeLine (U"Spectrogram show: ", our instancePref_spectrogram_show()); |
| 413 | /* Spectrogram settings: */ |
| 414 | MelderInfo_writeLine (U"Spectrogram view from: ", our instancePref_spectrogram_viewFrom(), U" Hz"); |
| 415 | MelderInfo_writeLine (U"Spectrogram view to: ", our instancePref_spectrogram_viewTo(), U" Hz"); |
| 416 | MelderInfo_writeLine (U"Spectrogram window length: ", our instancePref_spectrogram_windowLength(), U" seconds"); |
| 417 | MelderInfo_writeLine (U"Spectrogram dynamic range: ", our instancePref_spectrogram_dynamicRange(), U" dB"); |
| 418 | /* Advanced spectrogram settings: */ |
| 419 | MelderInfo_writeLine (U"Spectrogram number of time steps: ", our instancePref_spectrogram_timeSteps()); |
| 420 | MelderInfo_writeLine (U"Spectrogram number of frequency steps: ", our instancePref_spectrogram_frequencySteps()); |
| 421 | MelderInfo_writeLine (U"Spectrogram method: ", U"Fourier"); |
| 422 | MelderInfo_writeLine (U"Spectrogram window shape: ", kSound_to_Spectrogram_windowShape_getText (our instancePref_spectrogram_windowShape())); |
| 423 | MelderInfo_writeLine (U"Spectrogram autoscaling: ", our instancePref_spectrogram_autoscaling()); |
| 424 | MelderInfo_writeLine (U"Spectrogram maximum: ", our instancePref_spectrogram_maximum(), U" dB/Hz"); |
| 425 | MelderInfo_writeLine (U"Spectrogram pre-emphasis: ", our instancePref_spectrogram_preemphasis(), U" dB/octave"); |
| 426 | MelderInfo_writeLine (U"Spectrogram dynamicCompression: ", our instancePref_spectrogram_dynamicCompression()); |
| 427 | /* Dynamic information: */ |
| 428 | MelderInfo_writeLine (U"Spectrogram cursor frequency: ", our d_spectrogram_cursor, U" Hz"); |
| 429 | } |
| 430 | void structSoundAnalysisArea :: v_pitchInfo () const { |
| 431 | /* |
| 432 | Pitch flag: |
| 433 | */ |
| 434 | MelderInfo_writeLine (U"Pitch show: ", our instancePref_pitch_show()); |
| 435 | /* |
| 436 | General pitch settings: |
| 437 | */ |
| 438 | MelderInfo_writeLine (U"Pitch method: ", kSoundAnalysisArea_pitch_analysisMethod_getText (our instancePref_pitch_method())); |
| 439 | /* |
| 440 | Pitch settings for filtered autocorrelation: |
| 441 | */ |
| 442 | conststring32 unitText = Function_getUnitText (Thing_dummyObject (Pitch), |
| 443 | Pitch_LEVEL_FREQUENCY, (int) our instancePref_pitch_filteredAC_unit(), Function_UNIT_TEXT_MENU); |
| 444 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) floor: ", |
| 445 | our instancePref_pitch_filteredAC_floor(), U" Hz"); |
| 446 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) top: ", |
| 447 | our instancePref_pitch_filteredAC_top(), U" Hz"); |
| 448 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) unit: ", |
| 449 | unitText); |
| 450 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) drawing method: ", |
| 451 | kSoundAnalysisArea_pitch_drawingMethod_getText (our instancePref_pitch_filteredAC_drawingMethod())); |
| 452 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) view from: ", |
| 453 | our instancePref_pitch_filteredAC_viewFrom(), U" ", unitText); |
| 454 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) view to: ", |
| 455 | our instancePref_pitch_filteredAC_viewTo(), U" ", unitText); |
| 456 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) max. number of candidates: ", |
| 457 | our instancePref_pitch_filteredAC_maximumNumberOfCandidates()); |
| 458 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) very accurate: ", |
| 459 | our instancePref_pitch_filteredAC_veryAccurate()); |
| 460 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) attenuation at top: ", |
| 461 | our instancePref_pitch_filteredAC_attenuationAtTop()); |
| 462 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) silence threshold: ", |
| 463 | our instancePref_pitch_filteredAC_silenceThreshold(), U" of global peak"); |
| 464 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) voicing threshold: ", |
| 465 | our instancePref_pitch_filteredAC_voicingThreshold(), U" (periodic power / total power)"); |
| 466 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) octave cost: ", |
| 467 | our instancePref_pitch_filteredAC_octaveCost(), U" per octave"); |
| 468 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) octave jump cost: ", |
| 469 | our instancePref_pitch_filteredAC_octaveJumpCost(), U" per octave"); |
| 470 | MelderInfo_writeLine (U"Pitch (filtered autocorrelation) voiced/unvoiced cost: ", |
| 471 | our instancePref_pitch_filteredAC_voicedUnvoicedCost()); |
| 472 | /* |
| 473 | Pitch settings for raw cross-correlation: |
| 474 | */ |
| 475 | unitText = Function_getUnitText (Thing_dummyObject (Pitch), |
| 476 | Pitch_LEVEL_FREQUENCY, (int) our instancePref_pitch_rawCC_unit(), Function_UNIT_TEXT_MENU); |
| 477 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) floor: ", |
| 478 | our instancePref_pitch_rawCC_floor(), U" Hz"); |
| 479 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) ceiling: ", |
| 480 | our instancePref_pitch_rawCC_ceiling(), U" Hz"); |
| 481 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) unit: ", |
| 482 | unitText); |
| 483 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) drawing method: ", |
| 484 | kSoundAnalysisArea_pitch_drawingMethod_getText (our instancePref_pitch_rawCC_drawingMethod())); |
| 485 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) view from: ", |
| 486 | our instancePref_pitch_rawCC_viewFrom(), U" ", unitText); |
| 487 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) view to: ", |
| 488 | our instancePref_pitch_rawCC_viewTo(), U" ", unitText); |
| 489 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) max. number of candidates: ", |
| 490 | our instancePref_pitch_rawCC_maximumNumberOfCandidates()); |
| 491 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) very accurate: ", |
| 492 | our instancePref_pitch_rawCC_veryAccurate()); |
| 493 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) silence threshold: ", |
| 494 | our instancePref_pitch_rawCC_silenceThreshold(), U" of global peak"); |
| 495 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) voicing threshold: ", |
| 496 | our instancePref_pitch_rawCC_voicingThreshold(), U" (periodic power / total power)"); |
| 497 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) octave cost: ", |
| 498 | our instancePref_pitch_rawCC_octaveCost(), U" per octave"); |
| 499 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) octave jump cost: ", |
| 500 | our instancePref_pitch_rawCC_octaveJumpCost(), U" per octave"); |
| 501 | MelderInfo_writeLine (U"Pitch (raw cross-correlation) voiced/unvoiced cost: ", |
| 502 | our instancePref_pitch_rawCC_voicedUnvoicedCost()); |
| 503 | /* |
| 504 | Pitch settings for raw autocorrelation: |
| 505 | */ |
| 506 | unitText = Function_getUnitText (Thing_dummyObject (Pitch), |
| 507 | Pitch_LEVEL_FREQUENCY, (int) our instancePref_pitch_rawAC_unit(), Function_UNIT_TEXT_MENU); |
| 508 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) floor: ", |
| 509 | our instancePref_pitch_rawAC_floor(), U" Hz"); |
| 510 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) ceiling: ", |
| 511 | our instancePref_pitch_rawAC_ceiling(), U" Hz"); |
| 512 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) unit: ", |
| 513 | unitText); |
| 514 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) drawing method: ", |
| 515 | kSoundAnalysisArea_pitch_drawingMethod_getText (our instancePref_pitch_rawAC_drawingMethod())); |
| 516 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) view from: ", |
| 517 | our instancePref_pitch_rawAC_viewFrom(), U" ", unitText); |
| 518 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) view to: ", |
| 519 | our instancePref_pitch_rawAC_viewTo(), U" ", unitText); |
| 520 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) max. number of candidates: ", |
| 521 | our instancePref_pitch_rawAC_maximumNumberOfCandidates()); |
| 522 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) very accurate: ", |
| 523 | our instancePref_pitch_rawAC_veryAccurate()); |
| 524 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) silence threshold: ", |
| 525 | our instancePref_pitch_rawAC_silenceThreshold(), U" of global peak"); |
| 526 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) voicing threshold: ", |
| 527 | our instancePref_pitch_rawAC_voicingThreshold(), U" (periodic power / total power)"); |
| 528 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) octave cost: ", |
| 529 | our instancePref_pitch_rawAC_octaveCost(), U" per octave"); |
| 530 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) octave jump cost: ", |
| 531 | our instancePref_pitch_rawAC_octaveJumpCost(), U" per octave"); |
| 532 | MelderInfo_writeLine (U"Pitch (raw autocorrelation) voiced/unvoiced cost: ", |
| 533 | our instancePref_pitch_rawAC_voicedUnvoicedCost()); |
| 534 | /* |
| 535 | Pitch settings for filtered cross-correlation: |
| 536 | */ |
| 537 | unitText = Function_getUnitText (Thing_dummyObject (Pitch), |
| 538 | Pitch_LEVEL_FREQUENCY, (int) our instancePref_pitch_filteredCC_unit(), Function_UNIT_TEXT_MENU); |
| 539 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) floor: ", |
| 540 | our instancePref_pitch_filteredCC_floor(), U" Hz"); |
| 541 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) top: ", |
| 542 | our instancePref_pitch_filteredCC_top(), U" Hz"); |
| 543 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) unit: ", |
| 544 | unitText); |
| 545 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) drawing method: ", |
| 546 | kSoundAnalysisArea_pitch_drawingMethod_getText (our instancePref_pitch_filteredCC_drawingMethod())); |
| 547 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) view from: ", |
| 548 | our instancePref_pitch_filteredCC_viewFrom(), U" ", unitText); |
| 549 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) view to: ", |
| 550 | our instancePref_pitch_filteredCC_viewTo(), U" ", unitText); |
| 551 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) max. number of candidates: ", |
| 552 | our instancePref_pitch_filteredCC_maximumNumberOfCandidates()); |
| 553 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) very accurate: ", |
| 554 | our instancePref_pitch_filteredCC_veryAccurate()); |
| 555 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) attenuation at top: ", |
| 556 | our instancePref_pitch_filteredCC_attenuationAtTop()); |
| 557 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) silence threshold: ", |
| 558 | our instancePref_pitch_filteredCC_silenceThreshold(), U" of global peak"); |
| 559 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) voicing threshold: ", |
| 560 | our instancePref_pitch_filteredCC_voicingThreshold(), U" (periodic power / total power)"); |
| 561 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) octave cost: ", |
| 562 | our instancePref_pitch_filteredCC_octaveCost(), U" per octave"); |
| 563 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) octave jump cost: ", |
| 564 | our instancePref_pitch_filteredCC_octaveJumpCost(), U" per octave"); |
| 565 | MelderInfo_writeLine (U"Pitch (filtered cross-correlation) voiced/unvoiced cost: ", |
| 566 | our instancePref_pitch_filteredCC_voicedUnvoicedCost()); |
| 567 | } |
| 568 | void structSoundAnalysisArea :: v_intensityInfo () const { |
| 569 | /* Intensity flag: */ |
| 570 | MelderInfo_writeLine (U"Intensity show: ", our instancePref_intensity_show()); |
| 571 | /* Intensity settings: */ |
| 572 | MelderInfo_writeLine (U"Intensity view from: ", our instancePref_intensity_viewFrom(), U" dB"); |
| 573 | MelderInfo_writeLine (U"Intensity view to: ", our instancePref_intensity_viewTo(), U" dB"); |
| 574 | MelderInfo_writeLine (U"Intensity averaging method: ", kSoundAnalysisArea_intensity_averagingMethod_getText (our instancePref_intensity_averagingMethod())); |
| 575 | MelderInfo_writeLine (U"Intensity subtract mean pressure: ", our instancePref_intensity_subtractMeanPressure()); |
| 576 | } |
| 577 | void structSoundAnalysisArea :: v_formantsInfo () const { |
| 578 | /* Formants flag: */ |
| 579 | MelderInfo_writeLine (U"Formant show: ", our instancePref_formant_show()); |
| 580 | /* Formant settings: */ |
| 581 | MelderInfo_writeLine (U"Formant ceiling: ", our instancePref_formant_ceiling(), U" Hz"); |
| 582 | MelderInfo_writeLine (U"Formant number of poles: ", Melder_iround (2.0 * our instancePref_formant_numberOfFormants())); // should be a whole number |
| 583 | MelderInfo_writeLine (U"Formant window length: ", our instancePref_formant_windowLength(), U" seconds"); |
| 584 | MelderInfo_writeLine (U"Formant dynamic range: ", our instancePref_formant_dynamicRange(), U" dB"); |
| 585 | MelderInfo_writeLine (U"Formant dot size: ", our instancePref_formant_dotSize(), U" mm"); |
| 586 | /* Advanced formant settings: */ |
| 587 | MelderInfo_writeLine (U"Formant method: ", kSoundAnalysisArea_formant_analysisMethod_getText (our instancePref_formant_method())); |
| 588 | MelderInfo_writeLine (U"Formant pre-emphasis from: ", our instancePref_formant_preemphasisFrom(), U" Hz"); |
| 589 | } |
| 590 | void structSoundAnalysisArea :: v_pulsesInfo () const { |
| 591 | /* Pulses flag: */ |
| 592 | MelderInfo_writeLine (U"Pulses show: ", our instancePref_pulses_show()); |
| 593 | MelderInfo_writeLine (U"Pulses maximum period factor: ", our instancePref_pulses_maximumPeriodFactor()); |
| 594 | MelderInfo_writeLine (U"Pulses maximum amplitude factor: ", our instancePref_pulses_maximumAmplitudeFactor()); |
| 595 | } |
| 596 | void structSoundAnalysisArea :: v1_info () { |
| 597 | MelderInfo_writeLine (U"Longest analysis: ", our instancePref_longestAnalysis(), U" seconds"); |
| 598 | if (our v_hasSpectrogram ()) |
| 599 | our v_spectrogramInfo (); |
| 600 | if (v_hasPitch ()) |
| 601 | our v_pitchInfo (); |
| 602 | if (v_hasIntensity ()) |
| 603 | our v_intensityInfo (); |
| 604 | if (v_hasFormants ()) |
| 605 | our v_formantsInfo (); |
| 606 | if (v_hasPulses ()) |
| 607 | our v_pulsesInfo (); |
| 608 | const conststring32 logTargetTexts [3] = { U"log file only", U"Info window only", U"log file and Info window" }; |
| 609 | const conststring32 log1TargetText = logTargetTexts [our instancePref_log1_toLogFile() + 2 * our instancePref_log1_toInfoWindow() - 1]; |
| 610 | MelderInfo_writeLine (U"Log 1 target: ", log1TargetText); |
| 611 | MelderInfo_writeLine (U"Log 1 file: ", our instancePref_log1_fileName()); |
| 612 | MelderInfo_writeLine (U"Log 1 format: ", our instancePref_log1_format()); |
| 613 | const conststring32 log2TargetText = logTargetTexts [our instancePref_log2_toLogFile() + 2 * our instancePref_log2_toInfoWindow() - 1]; |
| 614 | MelderInfo_writeLine (U"Log 2 target: ", log2TargetText); |
| 615 | MelderInfo_writeLine (U"Log 2 file: ", our instancePref_log2_fileName()); |
| 616 | MelderInfo_writeLine (U"Log 2 format: ", our instancePref_log2_format()); |
| 617 | MelderInfo_writeLine (U"Log 3 script: ", our instancePref_logScript3()); |
| 618 | MelderInfo_writeLine (U"Log 4 script: ", our instancePref_logScript4()); |
| 619 | /* |
| 620 | COMPATIBILITY < 6400 |
| 621 | */ |
| 622 | if (v_hasPitch ()) { |
| 623 | kSoundAnalysisArea_pitch_analysisMethod pitchMethod = our instancePref_pitch_method(); |
| 624 | if (pitchMethod == kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION) { |
| 625 | MelderInfo_writeLine (U"\nCOMPATIBILITY (obsolete settings for the benefit of old scripts):"); |
| 626 | MelderInfo_writeLine (U"Pitch max. number of candidates: ", our instancePref_pitch_rawAC_maximumNumberOfCandidates()); |
| 627 | MelderInfo_writeLine (U"Pitch very accurate: ", our instancePref_pitch_rawAC_veryAccurate()); |
| 628 | MelderInfo_writeLine (U"Pitch silence threshold: ", our instancePref_pitch_rawAC_silenceThreshold(), U" of global peak"); |
| 629 | MelderInfo_writeLine (U"Pitch voicing threshold: ", our instancePref_pitch_rawAC_voicingThreshold(), U" (periodic power / total power)"); |
| 630 | MelderInfo_writeLine (U"Pitch octave cost: ", our instancePref_pitch_rawAC_octaveCost(), U" per octave"); |
| 631 | MelderInfo_writeLine (U"Pitch octave jump cost: ", our instancePref_pitch_rawAC_octaveJumpCost(), U" per octave"); |
| 632 | MelderInfo_writeLine (U"Pitch voiced/unvoiced cost: ", our instancePref_pitch_rawAC_voicedUnvoicedCost()); |
| 633 | } else if (pitchMethod == kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION) { |
| 634 | MelderInfo_writeLine (U"\nCOMPATIBILITY (obsolete settings for the benefit of old scripts):"); |
| 635 | MelderInfo_writeLine (U"Pitch max. number of candidates: ", our instancePref_pitch_rawCC_maximumNumberOfCandidates()); |
| 636 | MelderInfo_writeLine (U"Pitch very accurate: ", our instancePref_pitch_rawCC_veryAccurate()); |
| 637 | MelderInfo_writeLine (U"Pitch silence threshold: ", our instancePref_pitch_rawCC_silenceThreshold(), U" of global peak"); |
| 638 | MelderInfo_writeLine (U"Pitch voicing threshold: ", our instancePref_pitch_rawCC_voicingThreshold(), U" (periodic power / total power)"); |
| 639 | MelderInfo_writeLine (U"Pitch octave cost: ", our instancePref_pitch_rawCC_octaveCost(), U" per octave"); |
| 640 | MelderInfo_writeLine (U"Pitch octave jump cost: ", our instancePref_pitch_rawCC_octaveJumpCost(), U" per octave"); |
| 641 | MelderInfo_writeLine (U"Pitch voiced/unvoiced cost: ", our instancePref_pitch_rawCC_voicedUnvoicedCost()); |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | |
| 647 | #pragma mark - SoundAnalysisArea Analysis settings menu |
| 648 | |
| 649 | static void menu_cb_showAnalyses (SoundAnalysisArea me, EDITOR_ARGS) { |
| 650 | EDITOR_FORM (U"Show analyses", nullptr) |
| 651 | BOOLEAN (showSpectrogram, U"Show spectrogram", my default_spectrogram_show ()) |
| 652 | BOOLEAN (showPitch, U"Show pitch", my default_pitch_show ()) |
| 653 | BOOLEAN (showIntensity, U"Show intensity", my default_intensity_show ()) |
| 654 | BOOLEAN (showFormants, U"Show formants", my default_formant_show ()) |
| 655 | BOOLEAN (showPulses, U"Show pulses", my default_pulses_show ()) |
| 656 | POSITIVE (longestAnalysis, U"Longest analysis (s)", my default_longestAnalysis ()) |
| 657 | EDITOR_OK |
| 658 | SET_BOOLEAN (showSpectrogram, my instancePref_spectrogram_show()) |
| 659 | SET_BOOLEAN (showPitch, my instancePref_pitch_show()) |
| 660 | SET_BOOLEAN (showIntensity, my instancePref_intensity_show()) |
| 661 | SET_BOOLEAN (showFormants, my instancePref_formant_show()) |
| 662 | SET_BOOLEAN (showPulses, my instancePref_pulses_show()) |
| 663 | SET_REAL (longestAnalysis, my instancePref_longestAnalysis()) |
| 664 | EDITOR_DO |
| 665 | my setInstancePref_spectrogram_show (showSpectrogram); |
| 666 | my setInstancePref_pitch_show (showPitch); |
| 667 | my setInstancePref_intensity_show (showIntensity); |
| 668 | my setInstancePref_formant_show (showFormants); |
| 669 | my setInstancePref_pulses_show (showPulses); |
| 670 | GuiMenuItem_check (my spectrogramToggle, showSpectrogram); |
| 671 | GuiMenuItem_check (my pitchToggle, showPitch); |
| 672 | GuiMenuItem_check (my intensityToggle, showIntensity); |
| 673 | GuiMenuItem_check (my formantToggle, showFormants); |
| 674 | GuiMenuItem_check (my pulsesToggle, showPulses); |
| 675 | my setInstancePref_longestAnalysis (longestAnalysis); |
| 676 | FunctionEditor_redraw (my functionEditor()); |
| 677 | EDITOR_END |
| 678 | } |
| 679 | |
| 680 | static void menu_cb_timeStepSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 681 | EDITOR_FORM (U"Time step settings", U"Time step settings...") |
| 682 | OPTIONMENU_ENUM (kSoundAnalysisArea_timeStepStrategy, timeStepStrategy, |
| 683 | U"Time step strategy", my default_timeStepStrategy ()) |
| 684 | COMMENT (U"") |
| 685 | COMMENT (U"If the time step strategy is \"fixed\":") |
| 686 | POSITIVE (fixedTimeStep, U"Fixed time step (s)", my default_fixedTimeStep ()) |
| 687 | COMMENT (U"") |
| 688 | COMMENT (U"If the time step strategy is \"view-dependent\":") |
| 689 | NATURAL (numberOfTimeStepsPerView, U"Number of time steps per view", my default_numberOfTimeStepsPerView ()) |
| 690 | EDITOR_OK |
| 691 | SET_ENUM (timeStepStrategy, kSoundAnalysisArea_timeStepStrategy, my instancePref_timeStepStrategy()) |
| 692 | SET_REAL (fixedTimeStep, my instancePref_fixedTimeStep()) |
| 693 | SET_INTEGER (numberOfTimeStepsPerView, my instancePref_numberOfTimeStepsPerView()) |
| 694 | EDITOR_DO |
| 695 | my setInstancePref_timeStepStrategy (timeStepStrategy); |
| 696 | my setInstancePref_fixedTimeStep (fixedTimeStep); |
| 697 | my setInstancePref_numberOfTimeStepsPerView (numberOfTimeStepsPerView); |
| 698 | my d_pitch. reset(); |
| 699 | my d_formant. reset(); |
| 700 | my d_intensity. reset(); |
| 701 | my d_pulses. reset(); |
| 702 | FunctionEditor_redraw (my functionEditor()); |
| 703 | EDITOR_END |
| 704 | } |
| 705 | |
| 706 | |
| 707 | #pragma mark - SoundAnalysisArea Analyses settings menu |
| 708 | |
| 709 | enum { |
| 710 | SoundAnalysisArea_PART_CURSOR = 1, |
| 711 | SoundAnalysisArea_PART_SELECTION = 2 |
| 712 | }; |
| 713 | |
| 714 | static const conststring32 SoundAnalysisArea_partString (int part) { |
| 715 | static const conststring32 strings [] = { U"", U"CURSOR", U"SELECTION" }; |
| 716 | return strings [part]; |
| 717 | } |
| 718 | |
| 719 | static const conststring32 SoundAnalysisArea_partString_locative (int part) { |
| 720 | static const conststring32 strings [] = { U"", U"at CURSOR", U"in SELECTION" }; |
| 721 | return strings [part]; |
| 722 | } |
| 723 | |
| 724 | static int makeQueriable (SoundAnalysisArea me, bool allowCursor, double *tmin, double *tmax) { |
| 725 | if (my endWindow() - my startWindow() > my instancePref_longestAnalysis()) |
| 726 | Melder_throw (U"Window too long to show analyses. " |
| 727 | U"Zoom in to at most ", Melder_half (my instancePref_longestAnalysis()), U" seconds " |
| 728 | U"or set the \"longest analysis\" to at least ", Melder_half (my endWindow() - my startWindow()), |
| 729 | U" seconds (with \"Show analyses\" in the Analysis menu)." |
| 730 | ); |
| 731 | if (my startSelection() == my endSelection()) { |
| 732 | if (allowCursor) { |
| 733 | *tmin = *tmax = my startSelection(); |
| 734 | return SoundAnalysisArea_PART_CURSOR; |
| 735 | } else { |
| 736 | Melder_throw (U"Make a selection first."); |
| 737 | } |
| 738 | } else if (my startSelection() < my startWindow() || my endSelection() > my endWindow()) { |
| 739 | Melder_throw (U"Command ambiguous: a part of the selection (", my startSelection(), U", ", my endSelection(), U") " |
| 740 | U"is outside of the window (", my startWindow(), U", ", my endWindow(), U"). " |
| 741 | U"Either zoom or re-select."); |
| 742 | } |
| 743 | *tmin = my startSelection(); |
| 744 | *tmax = my endSelection(); |
| 745 | return SoundAnalysisArea_PART_SELECTION; |
| 746 | } |
| 747 | |
| 748 | static void menu_cb_logSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 749 | EDITOR_FORM (U"Log settings", U"Log files") |
| 750 | OPTIONMENU (writeLog1To, U"Write log 1 to", 3) |
| 751 | OPTION (U"log file only") |
| 752 | OPTION (U"Info window only") |
| 753 | OPTION (U"log file and Info window") |
| 754 | OUTFILE (logFile1, U"Log file 1:", my default_log1_fileName ()) |
| 755 | TEXTFIELD (log1format, U"Log 1 format:", my default_log1_format (), 3) |
| 756 | OPTIONMENU (writeLog2To, U"Write log 2 to", 3) |
| 757 | OPTION (U"log file only") |
| 758 | OPTION (U"Info window only") |
| 759 | OPTION (U"log file and Info window") |
| 760 | OUTFILE (logFile2, U"Log file 2:", my default_log2_fileName ()) |
| 761 | TEXTFIELD (log2format, U"Log 2 format:", my default_log2_format (), 3) |
| 762 | OUTFILE (logScript3, U"Log script 3:", my default_logScript3 ()) |
| 763 | OUTFILE (logScript4, U"Log script 4:", my default_logScript4 ()) |
| 764 | EDITOR_OK |
| 765 | SET_OPTION (writeLog1To, my instancePref_log1_toLogFile() + 2 * my instancePref_log1_toInfoWindow()) |
| 766 | SET_STRING (logFile1, my instancePref_log1_fileName()) |
| 767 | SET_STRING (log1format, my instancePref_log1_format()) |
| 768 | SET_OPTION (writeLog2To, my instancePref_log2_toLogFile() + 2 * my instancePref_log2_toInfoWindow()) |
| 769 | SET_STRING (logFile2, my instancePref_log2_fileName()) |
| 770 | SET_STRING (log2format, my instancePref_log2_format()) |
| 771 | SET_STRING (logScript3, my instancePref_logScript3()) |
| 772 | SET_STRING (logScript4, my instancePref_logScript4()) |
| 773 | EDITOR_DO |
| 774 | my setInstancePref_log1_toLogFile ((writeLog1To & 1) != 0); |
| 775 | my setInstancePref_log1_toInfoWindow ((writeLog1To & 2) != 0); |
| 776 | my setInstancePref_log1_fileName (logFile1); |
| 777 | my setInstancePref_log1_format (log1format); |
| 778 | my setInstancePref_log2_toLogFile ((writeLog2To & 1) != 0); |
| 779 | my setInstancePref_log2_toInfoWindow ((writeLog2To & 2) != 0); |
| 780 | my setInstancePref_log2_fileName (logFile2); |
| 781 | my setInstancePref_log2_format (log2format); |
| 782 | my setInstancePref_logScript3 (logScript3); |
| 783 | my setInstancePref_logScript4 (logScript4); |
| 784 | EDITOR_END |
| 785 | } |
| 786 | |
| 787 | static void menu_cb_deleteLogFile1 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 788 | VOID_EDITOR |
| 789 | structMelderFile file { }; |
| 790 | Melder_pathToFile (my instancePref_log1_fileName(), & file); |
| 791 | MelderFile_delete (& file); |
| 792 | VOID_EDITOR_END |
| 793 | } |
| 794 | |
| 795 | static void menu_cb_deleteLogFile2 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 796 | VOID_EDITOR |
| 797 | structMelderFile file { }; |
| 798 | Melder_pathToFile (my instancePref_log2_fileName(), & file); |
| 799 | MelderFile_delete (& file); |
| 800 | VOID_EDITOR_END |
| 801 | } |
| 802 | |
| 803 | static void do_log (SoundAnalysisArea me, int which) { |
| 804 | PrefsString format; |
| 805 | double tmin, tmax; |
| 806 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 807 | str32cpy (format, which == 1 ? my instancePref_log1_format() : my instancePref_log2_format()); |
| 808 | for (char32 *p = format; *p != U'\0'; p ++) if (*p == U'\'') { |
| 809 | /* |
| 810 | Found a left quote. Search for a matching right quote. |
| 811 | */ |
| 812 | char32 *q = p + 1, varName [300], *r, *s, *colon; |
| 813 | integer precision = -1; |
| 814 | double value = undefined; |
| 815 | conststring32 stringValue = nullptr; |
| 816 | while (*q != U'\0' && *q != U'\'') |
| 817 | q ++; |
| 818 | if (*q == U'\0') |
| 819 | break; // no matching right quote: done with this line |
| 820 | if (q - p == 1) |
| 821 | continue; // ignore empty variable names |
| 822 | /* |
| 823 | Found a right quote. Get potential variable name. |
| 824 | */ |
| 825 | for (r = p + 1, s = varName; q - r > 0; r ++, s ++) |
| 826 | *s = *r; |
| 827 | *s = U'\0'; // trailing null byte |
| 828 | colon = str32chr (varName, U':'); |
| 829 | if (colon) { |
| 830 | precision = Melder_atoi (colon + 1); |
| 831 | *colon = U'\0'; |
| 832 | } |
| 833 | if (str32equ (varName, U"time")) { |
| 834 | value = 0.5 * (tmin + tmax); |
| 835 | } else if (str32equ (varName, U"t1")) { |
| 836 | value = tmin; |
| 837 | } else if (str32equ (varName, U"t2")) { |
| 838 | value = tmax; |
| 839 | } else if (str32equ (varName, U"dur")) { |
| 840 | value = tmax - tmin; |
| 841 | } else if (str32equ (varName, U"freq")) { |
| 842 | value = my d_spectrogram_cursor; |
| 843 | } else if (str32equ (varName, U"tab$")) { |
| 844 | stringValue = U"\t"; |
| 845 | } else if (str32equ (varName, U"editor$")) { |
| 846 | stringValue = my boss() -> name.get(); |
| 847 | } else if (str32equ (varName, U"f0")) { |
| 848 | SoundAnalysisArea_haveVisiblePitch (me); |
| 849 | const kPitch_unit unit = my dynamic_instancePref_pitch_unit(); |
| 850 | if (part == SoundAnalysisArea_PART_CURSOR) |
| 851 | value = Pitch_getValueAtTime (my d_pitch.get(), tmin, unit, 1); |
| 852 | else |
| 853 | value = Pitch_getMean (my d_pitch.get(), tmin, tmax, unit); |
| 854 | value = Function_convertToNonlogarithmic (my d_pitch.get(), value, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 855 | } else if (varName [0] == U'f' && varName [1] >= U'1' && varName [1] <= U'5' && varName [2] == U'\0') { |
| 856 | SoundAnalysisArea_haveVisibleFormants (me); |
| 857 | if (part == SoundAnalysisArea_PART_CURSOR) |
| 858 | value = Formant_getValueAtTime (my d_formant.get(), (int) (varName [1] - U'0'), tmin, kFormant_unit::HERTZ); |
| 859 | else |
| 860 | value = Formant_getMean (my d_formant.get(), (int) (varName [1] - U'0'), tmin, tmax, kFormant_unit::HERTZ); |
| 861 | } else if (varName [0] == U'b' && varName [1] >= U'1' && varName [1] <= U'5' && varName [2] == U'\0') { |
| 862 | SoundAnalysisArea_haveVisibleFormants (me); |
| 863 | value = Formant_getBandwidthAtTime (my d_formant.get(), (int) (varName [1] - U'0'), 0.5 * (tmin + tmax), kFormant_unit::HERTZ); |
| 864 | } else if (str32equ (varName, U"intensity")) { |
| 865 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 866 | if (part == SoundAnalysisArea_PART_CURSOR) |
| 867 | value = Vector_getValueAtX (my d_intensity.get(), tmin, Vector_CHANNEL_1, kVector_valueInterpolation :: LINEAR); |
| 868 | else |
| 869 | value = Intensity_getAverage (my d_intensity.get(), tmin, tmax, (int) my instancePref_intensity_averagingMethod()); |
| 870 | } else if (str32equ (varName, U"power")) { |
| 871 | SoundAnalysisArea_haveVisibleSpectrogram (me); |
| 872 | if (part != SoundAnalysisArea_PART_CURSOR) |
| 873 | Melder_throw (U"Click inside the spectrogram first."); |
| 874 | if (my d_spectrogramList->size == 1) |
| 875 | value = Matrix_getValueAtXY (my d_spectrogramList->at [1], tmin, my d_spectrogram_cursor); |
| 876 | else |
| 877 | value = undefined; |
| 878 | } |
| 879 | if (isdefined (value)) { |
| 880 | const integer varlen = (q - p) - 1, headlen = p - format; |
| 881 | char32 formattedNumber [400]; |
| 882 | if (precision >= 0) |
| 883 | Melder_sprint (formattedNumber,400, Melder_fixed (value, precision)); |
| 884 | else |
| 885 | Melder_sprint (formattedNumber,400, value); |
| 886 | const integer arglen = Melder_length (formattedNumber); |
| 887 | static MelderString buffer; |
| 888 | MelderString_ncopy (& buffer, format, headlen); |
| 889 | MelderString_append (& buffer, formattedNumber, p + varlen + 2); |
| 890 | str32cpy (format, buffer.string); |
| 891 | p += arglen - 1; |
| 892 | } else if (stringValue) { |
| 893 | const integer varlen = (q - p) - 1, headlen = p - format, arglen = Melder_length (stringValue); |
| 894 | static MelderString buffer; |
| 895 | MelderString_ncopy (& buffer, format, headlen); |
| 896 | MelderString_append (& buffer, stringValue, p + varlen + 2); |
| 897 | str32cpy (format, buffer.string); |
| 898 | p += arglen - 1; |
| 899 | } else { |
| 900 | p = q - 1; // go to before next quote |
| 901 | } |
| 902 | } |
| 903 | if (which == 1 && my instancePref_log1_toInfoWindow() || which == 2 && my instancePref_log2_toInfoWindow()) { |
| 904 | MelderInfo_write (format); |
| 905 | MelderInfo_close (); |
| 906 | } |
| 907 | if (which == 1 && my instancePref_log1_toLogFile() || which == 2 && my instancePref_log2_toLogFile()) { |
| 908 | structMelderFile file { }; |
| 909 | str32cat (format, U"\n"); |
| 910 | Melder_relativePathToFile (which == 1 ? my instancePref_log1_fileName() : my instancePref_log2_fileName(), & file); |
| 911 | MelderFile_appendText_e (& file, format); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | static void menu_cb_log1 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 916 | VOID_EDITOR |
| 917 | do_log (me, 1); |
| 918 | VOID_EDITOR_END |
| 919 | } |
| 920 | static void menu_cb_log2 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 921 | VOID_EDITOR |
| 922 | do_log (me, 2); |
| 923 | VOID_EDITOR_END |
| 924 | } |
| 925 | static void menu_cb_logScript3 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 926 | VOID_EDITOR |
| 927 | praat_executeScriptFromEditorCommand (my functionEditor(), cmd, my instancePref_logScript3()); |
| 928 | VOID_EDITOR_END |
| 929 | } |
| 930 | static void menu_cb_logScript4 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 931 | VOID_EDITOR |
| 932 | praat_executeScriptFromEditorCommand (my functionEditor(), cmd, my instancePref_logScript4()); |
| 933 | VOID_EDITOR_END |
| 934 | } |
| 935 | |
| 936 | |
| 937 | #pragma mark - SoundAnalysisArea Spectrogram menu |
| 938 | |
| 939 | static void menu_cb_showSpectrogram (SoundAnalysisArea me, EDITOR_ARGS) { |
| 940 | VOID_EDITOR |
| 941 | my setInstancePref_spectrogram_show (! my instancePref_spectrogram_show()); // toggle |
| 942 | GuiMenuItem_check (my spectrogramToggle, my instancePref_spectrogram_show()); // in case we're called from a script |
| 943 | FunctionEditor_redraw (my functionEditor()); |
| 944 | VOID_EDITOR_END |
| 945 | } |
| 946 | |
| 947 | static void menu_cb_spectrogramSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 948 | EDITOR_FORM (U"Spectrogram settings", U"Intro 3.2. Configuring the spectrogram") |
| 949 | REAL (viewFrom, U"left View range (Hz)", my default_spectrogram_viewFrom()) |
| 950 | POSITIVE (viewTo, U"right View range (Hz)", my default_spectrogram_viewTo()) |
| 951 | POSITIVE (windowLength, U"Window length (s)", my default_spectrogram_windowLength()) |
| 952 | POSITIVE (dynamicRange, U"Dynamic range (dB)", my default_spectrogram_dynamicRange()) |
| 953 | MUTABLE_COMMENT (note1, U"") |
| 954 | MUTABLE_COMMENT (note2, U"") |
| 955 | EDITOR_OK |
| 956 | SET_REAL (viewFrom, my instancePref_spectrogram_viewFrom()) |
| 957 | SET_REAL (viewTo, my instancePref_spectrogram_viewTo()) |
| 958 | SET_REAL (windowLength, my instancePref_spectrogram_windowLength()) |
| 959 | SET_REAL (dynamicRange, my instancePref_spectrogram_dynamicRange()) |
| 960 | if (my instancePref_spectrogram_timeSteps() != Melder_atof (my default_spectrogram_timeSteps()) || |
| 961 | my instancePref_spectrogram_frequencySteps() != Melder_atof (my default_spectrogram_frequencySteps()) || |
| 962 | my instancePref_spectrogram_method() != my default_spectrogram_method() || |
| 963 | my instancePref_spectrogram_windowShape() != my default_spectrogram_windowShape() || |
| 964 | my instancePref_spectrogram_maximum() != Melder_atof (my default_spectrogram_maximum()) || |
| 965 | my instancePref_spectrogram_autoscaling() != my default_spectrogram_autoscaling()|| |
| 966 | my instancePref_spectrogram_preemphasis() != Melder_atof (my default_spectrogram_preemphasis()) || |
| 967 | my instancePref_spectrogram_dynamicCompression() != Melder_atof (my default_spectrogram_dynamicCompression())) |
| 968 | { |
| 969 | SET_STRING (note1, U"Warning: you have non-standard \"advanced settings\".") |
| 970 | } else { |
| 971 | SET_STRING (note1, U"(all of your \"advanced settings\" have their standard values)") |
| 972 | } |
| 973 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy()) { |
| 974 | SET_STRING (note2, U"Warning: you have a non-standard \"time step strategy\".") |
| 975 | } else { |
| 976 | SET_STRING (note2, U"(your \"time step strategy\" has its standard value: automatic)") |
| 977 | } |
| 978 | EDITOR_DO |
| 979 | Melder_require (viewFrom < viewTo, |
| 980 | U"The ceiling of the spectrogram view range should be greater than the floor."); |
| 981 | my setInstancePref_spectrogram_viewFrom (viewFrom); |
| 982 | my setInstancePref_spectrogram_viewTo (viewTo); |
| 983 | my setInstancePref_spectrogram_windowLength (windowLength); |
| 984 | my setInstancePref_spectrogram_dynamicRange (dynamicRange); |
| 985 | my d_spectrogramList. reset(); |
| 986 | FunctionEditor_redraw (my functionEditor()); |
| 987 | EDITOR_END |
| 988 | } |
| 989 | |
| 990 | static void menu_cb_spectrogramColourSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 991 | EDITOR_FORM (U"Spectrogram colour settings", U"Intro 3.2. Configuring the spectrogram") |
| 992 | OPTIONMENU_ENUM (kSpectrogram_colourMap, colourMap, U"Colour map", my default_spectrogram_colourMap()) |
| 993 | BOOLEAN (invertColours, U"Invert colours", my default_spectrogram_invertColours()) |
| 994 | BOOLEAN (threeChannelsIsRGB, U"Three channels is RGB", my default_spectrogram_threeChannelsIsRGB()) |
| 995 | EDITOR_OK |
| 996 | SET_ENUM (colourMap, kSpectrogram_colourMap, my instancePref_spectrogram_colourMap()) |
| 997 | SET_BOOLEAN (invertColours, my instancePref_spectrogram_invertColours()) |
| 998 | SET_BOOLEAN (threeChannelsIsRGB, my instancePref_spectrogram_threeChannelsIsRGB()) |
| 999 | EDITOR_DO |
| 1000 | my setInstancePref_spectrogram_colourMap (colourMap); |
| 1001 | my setInstancePref_spectrogram_invertColours (invertColours); |
| 1002 | my setInstancePref_spectrogram_threeChannelsIsRGB (threeChannelsIsRGB); |
| 1003 | my d_spectrogramList. reset(); |
| 1004 | FunctionEditor_redraw (my functionEditor()); |
| 1005 | EDITOR_END |
| 1006 | } |
| 1007 | |
| 1008 | static void menu_cb_advancedSpectrogramSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1009 | EDITOR_FORM (U"Advanced spectrogram settings", U"Advanced spectrogram settings...") |
| 1010 | COMMENT (U"Time and frequency resolutions:") |
| 1011 | NATURAL (numberOfTimeSteps, U"Number of time steps", my default_spectrogram_timeSteps()) |
| 1012 | NATURAL (numberOfFrequencySteps, U"Number of frequency steps", my default_spectrogram_frequencySteps()) |
| 1013 | COMMENT (U"Spectrogram analysis settings:") |
| 1014 | OPTIONMENU_ENUM (kSound_to_Spectrogram_method, method, |
| 1015 | U"Method", my default_spectrogram_method ()) |
| 1016 | OPTIONMENU_ENUM (kSound_to_Spectrogram_windowShape, windowShape, |
| 1017 | U"Window shape", my default_spectrogram_windowShape ()) |
| 1018 | COMMENT (U"Spectrogram view settings:") |
| 1019 | BOOLEAN (autoscaling, U"Autoscaling", my default_spectrogram_autoscaling()) |
| 1020 | REAL (maximum, U"Maximum (dB/Hz)", my default_spectrogram_maximum()) |
| 1021 | REAL (preemphasis, U"Pre-emphasis (dB/oct)", my default_spectrogram_preemphasis()) |
| 1022 | REAL (dynamicCompression, U"Dynamic compression (0 – 1)", my default_spectrogram_dynamicCompression()) |
| 1023 | EDITOR_OK |
| 1024 | SET_INTEGER (numberOfTimeSteps, my instancePref_spectrogram_timeSteps()) |
| 1025 | SET_INTEGER (numberOfFrequencySteps, my instancePref_spectrogram_frequencySteps()) |
| 1026 | SET_ENUM (method, kSound_to_Spectrogram_method, my instancePref_spectrogram_method()) |
| 1027 | SET_ENUM (windowShape, kSound_to_Spectrogram_windowShape, my instancePref_spectrogram_windowShape()) |
| 1028 | SET_BOOLEAN (autoscaling, my instancePref_spectrogram_autoscaling()) |
| 1029 | SET_REAL (maximum, my instancePref_spectrogram_maximum()) |
| 1030 | SET_REAL (preemphasis, my instancePref_spectrogram_preemphasis()) |
| 1031 | SET_REAL (dynamicCompression, my instancePref_spectrogram_dynamicCompression()) |
| 1032 | EDITOR_DO |
| 1033 | my setInstancePref_spectrogram_timeSteps (numberOfTimeSteps); |
| 1034 | my setInstancePref_spectrogram_frequencySteps (numberOfFrequencySteps); |
| 1035 | my setInstancePref_spectrogram_method (method); |
| 1036 | my setInstancePref_spectrogram_windowShape (windowShape); |
| 1037 | my setInstancePref_spectrogram_autoscaling (autoscaling); |
| 1038 | my setInstancePref_spectrogram_maximum (maximum); |
| 1039 | my setInstancePref_spectrogram_preemphasis (preemphasis); |
| 1040 | my setInstancePref_spectrogram_dynamicCompression (dynamicCompression); |
| 1041 | my d_spectrogramList. reset(); |
| 1042 | FunctionEditor_redraw (my functionEditor()); |
| 1043 | EDITOR_END |
| 1044 | } |
| 1045 | |
| 1046 | static void QUERY_EDITOR_FOR_REAL__getFrequency (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1047 | QUERY_EDITOR_FOR_REAL |
| 1048 | const double result = my d_spectrogram_cursor; |
| 1049 | QUERY_EDITOR_FOR_REAL_END (U" Hz") |
| 1050 | } |
| 1051 | |
| 1052 | static void QUERY_DATA_FOR_REAL__getSpectralPowerAtCursorCross (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1053 | QUERY_DATA_FOR_REAL |
| 1054 | double tmin, tmax; |
| 1055 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 1056 | SoundAnalysisArea_haveVisibleSpectrogram (me); |
| 1057 | if (part != SoundAnalysisArea_PART_CURSOR) |
| 1058 | Melder_throw (U"Click inside the spectrogram first."); |
| 1059 | double result = undefined; |
| 1060 | if (my d_spectrogramList) |
| 1061 | result = Matrix_getValueAtXY (my d_spectrogramList->at [1], tmin, my d_spectrogram_cursor); |
| 1062 | QUERY_DATA_FOR_REAL_END (U" Pa2/Hz (at time = ", tmin, U" seconds and frequency = ", my d_spectrogram_cursor, U" Hz)"); |
| 1063 | } |
| 1064 | |
| 1065 | static void menu_cb_moveFrequencyCursorTo (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1066 | if (! my instancePref_spectrogram_show()) |
| 1067 | Melder_throw (U"No spectrogram is visible.\nFirst choose \"Show spectrogram\" from the Spectrogram menu."); |
| 1068 | EDITOR_FORM (U"Move frequency cursor to", nullptr) |
| 1069 | REAL (frequency, U"Frequency (Hz)", U"0.0") |
| 1070 | EDITOR_OK |
| 1071 | SET_REAL (frequency, my d_spectrogram_cursor) |
| 1072 | EDITOR_DO |
| 1073 | my d_spectrogram_cursor = frequency; |
| 1074 | FunctionEditor_redraw (my functionEditor()); |
| 1075 | EDITOR_END |
| 1076 | } |
| 1077 | |
| 1078 | static void CONVERT_DATA_TO_ONE__ExtractVisibleSpectrogram (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1079 | CONVERT_DATA_TO_ONE |
| 1080 | SoundAnalysisArea_haveVisibleSpectrogram (me); |
| 1081 | autoSpectrogram result; |
| 1082 | if (my d_spectrogramList->size == 1) |
| 1083 | result = Data_copy (my d_spectrogramList->at [1]); |
| 1084 | CONVERT_DATA_TO_ONE_END (U"untitled") |
| 1085 | } |
| 1086 | |
| 1087 | static void CONVERT_DATA_TO_ONE__ViewSpectralSlice (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1088 | CONVERT_DATA_TO_ONE |
| 1089 | const double start = ( my startSelection() == my endSelection() ? |
| 1090 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? my startSelection() - my instancePref_spectrogram_windowLength() : |
| 1091 | my startSelection() - my instancePref_spectrogram_windowLength() / 2 : my startSelection() |
| 1092 | ); |
| 1093 | const double finish = ( my startSelection() == my endSelection() ? |
| 1094 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? my endSelection() + my instancePref_spectrogram_windowLength() : |
| 1095 | my endSelection() + my instancePref_spectrogram_windowLength() / 2 : my endSelection() |
| 1096 | ); |
| 1097 | autoSound sound = extractSoundOrNull (me, start, finish); |
| 1098 | if (! sound) |
| 1099 | return; |
| 1100 | Sound_multiplyByWindow (sound.get(), |
| 1101 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::SQUARE ? kSound_windowShape::RECTANGULAR : |
| 1102 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::HAMMING ? kSound_windowShape::HAMMING : |
| 1103 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::BARTLETT ? kSound_windowShape::TRIANGULAR : |
| 1104 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::WELCH ? kSound_windowShape::PARABOLIC : |
| 1105 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::HANNING ? kSound_windowShape::HANNING : |
| 1106 | my instancePref_spectrogram_windowShape() == kSound_to_Spectrogram_windowShape::GAUSSIAN ? kSound_windowShape::GAUSSIAN_2 : kSound_windowShape::RECTANGULAR |
| 1107 | ); |
| 1108 | autoSpectrum result = Sound_to_Spectrum (sound.get(), true); |
| 1109 | CONVERT_DATA_TO_ONE_END (Melder_cat (( my data() ? my data() -> name.get() : U"untitled" ), |
| 1110 | U"_", Melder_fixed (0.5 * (my startSelection() + my endSelection()), 3))) |
| 1111 | } |
| 1112 | |
| 1113 | static void menu_cb_paintVisibleSpectrogram (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1114 | EDITOR_FORM (U"Paint visible spectrogram", nullptr) |
| 1115 | my v_form_pictureWindow (cmd); // BUG: isn't really virtual |
| 1116 | my v_form_pictureMargins (cmd); |
| 1117 | my v_form_pictureSelection (cmd); |
| 1118 | BOOLEAN (garnish, U"Garnish", true) |
| 1119 | EDITOR_OK |
| 1120 | my v_ok_pictureWindow (cmd); |
| 1121 | my v_ok_pictureMargins (cmd); |
| 1122 | my v_ok_pictureSelection (cmd); |
| 1123 | SET_BOOLEAN (garnish, my instancePref_spectrogram_picture_garnish()) |
| 1124 | EDITOR_DO |
| 1125 | my v_do_pictureWindow (cmd); |
| 1126 | my v_do_pictureMargins (cmd); |
| 1127 | my v_do_pictureSelection (cmd); |
| 1128 | my setInstancePref_spectrogram_picture_garnish (garnish); |
| 1129 | SoundAnalysisArea_haveVisibleSpectrogram (me); |
| 1130 | DataGui_openPraatPicture (me); |
| 1131 | SpectrogramList_paint (my d_spectrogramList.get(), my pictureGraphics(), my startWindow(), my endWindow(), |
| 1132 | my instancePref_spectrogram_viewFrom(), my instancePref_spectrogram_viewTo(), |
| 1133 | my instancePref_spectrogram_maximum(), my instancePref_spectrogram_autoscaling(), |
| 1134 | my instancePref_spectrogram_dynamicRange(), my instancePref_spectrogram_preemphasis(), |
| 1135 | my instancePref_spectrogram_dynamicCompression(), |
| 1136 | my instancePref_spectrogram_colourMap(), my instancePref_spectrogram_invertColours(), |
| 1137 | garnish |
| 1138 | ); |
| 1139 | FunctionArea_garnishPicture (me); |
| 1140 | DataGui_closePraatPicture (me); |
| 1141 | EDITOR_END |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | #pragma mark - SoundAnalysisArea Pitch menu |
| 1146 | |
| 1147 | static void menu_cb_showPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1148 | VOID_EDITOR |
| 1149 | my setInstancePref_pitch_show (! my instancePref_pitch_show()); // toggle |
| 1150 | GuiMenuItem_check (my pitchToggle, my instancePref_pitch_show()); // in case we're called from a script |
| 1151 | FunctionEditor_redraw (my functionEditor()); |
| 1152 | VOID_EDITOR_END |
| 1153 | } |
| 1154 | |
| 1155 | static void menu_cb_pitchSettings_BEFORE_6400 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1156 | EDITOR_FORM (U"Pitch settings", U"Intro 4.2. Configuring the pitch contour") |
| 1157 | COMMENT (U"YOU SHOULD NEVER SEE THIS OBSOLETE SETTINGS WINDOW;") |
| 1158 | COMMENT (U"IT IS HERE ONLY FOR COMPATIBILITY WITH OLD SCRIPTS.") |
| 1159 | POSITIVE (pitchFloor, U"left Pitch range (Hz)", my default_pitch_rawAC_floor()) // the default is ignored if not shown |
| 1160 | POSITIVE (pitchCeiling, U"right Pitch range (Hz)", my default_pitch_rawAC_ceiling()) |
| 1161 | OPTIONMENU_ENUM (kPitch_unit, unit, U"Unit", my default_pitch_rawAC_unit ()) |
| 1162 | CHOICE_ENUM (kSoundAnalysisArea_pitch_analysisMethod, analysisMethod, U"Analysis method", my default_pitch_method()) |
| 1163 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, U"Drawing method", my default_pitch_rawAC_drawingMethod()) |
| 1164 | EDITOR_OK |
| 1165 | EDITOR_DO |
| 1166 | Melder_require ( |
| 1167 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION || |
| 1168 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION, |
| 1169 | U"Obsolete pitch settings command can handle only raw AC and CC methods." |
| 1170 | U"Use one of the modern pitch setting commands instead." |
| 1171 | ); |
| 1172 | Melder_require (pitchCeiling > pitchFloor, |
| 1173 | U"The pitch ceiling has to be greater than the pitch floor, so they cannot be ", |
| 1174 | pitchCeiling, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1175 | ); |
| 1176 | my setInstancePref_pitch_method (analysisMethod); |
| 1177 | my setInstancePref_pitch_rawAC_floor (pitchFloor); |
| 1178 | my setInstancePref_pitch_rawCC_floor (pitchFloor); |
| 1179 | my setInstancePref_pitch_rawAC_ceiling (pitchCeiling); |
| 1180 | my setInstancePref_pitch_rawCC_ceiling (pitchCeiling); |
| 1181 | my setInstancePref_pitch_rawAC_unit (unit); |
| 1182 | my setInstancePref_pitch_rawCC_unit (unit); |
| 1183 | my setInstancePref_pitch_rawAC_drawingMethod (drawingMethod); |
| 1184 | my setInstancePref_pitch_rawCC_drawingMethod (drawingMethod); |
| 1185 | my d_pitch. reset(); |
| 1186 | my d_intensity. reset(); |
| 1187 | my d_pulses. reset(); |
| 1188 | FunctionEditor_redraw (my functionEditor()); |
| 1189 | EDITOR_END |
| 1190 | } |
| 1191 | |
| 1192 | static void menu_cb_pitchSettings_BEFORE_6414 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1193 | EDITOR_FORM (U"Pitch settings", U"Intro 4.2. Configuring the pitch contour") |
| 1194 | COMMENT (U"YOU SHOULD NEVER SEE THIS OBSOLETE SETTINGS WINDOW;") |
| 1195 | COMMENT (U"IT IS HERE ONLY FOR COMPATIBILITY WITH OLD SCRIPTS.") |
| 1196 | POSITIVE (pitchFloor, U"left Pitch range (Hz)", my default_pitch_rawAC_floor()) // the default is ignored if not shown |
| 1197 | POSITIVE (pitchCeiling, U"right Pitch range (Hz)", my default_pitch_rawAC_ceiling()) |
| 1198 | OPTIONMENU_ENUM (kPitch_unit, unit, |
| 1199 | U"Unit", my default_pitch_rawAC_unit ()) |
| 1200 | CHOICE_ENUM (kSoundAnalysisArea_pitch_analysisMethod, analysisMethod, |
| 1201 | U"Analysis method", my default_pitch_method()) |
| 1202 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, |
| 1203 | U"Drawing method", my default_pitch_rawAC_drawingMethod()) |
| 1204 | REAL (viewFrom, U"left View range (units)", my default_pitch_rawAC_viewFrom ()) |
| 1205 | REAL (viewTo, U"right View range (units)", my default_pitch_rawAC_viewTo ()) |
| 1206 | EDITOR_OK |
| 1207 | EDITOR_DO_ALTERNATIVE (menu_cb_pitchSettings_BEFORE_6400) |
| 1208 | Melder_require ( |
| 1209 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_AUTOCORRELATION || |
| 1210 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION || |
| 1211 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION || |
| 1212 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_CROSS_CORRELATION, |
| 1213 | U"Obsolete pitch settings command can handle only filtered or raw AC and CC methods." |
| 1214 | U"Use one of the modern pitch setting commands instead." |
| 1215 | ); |
| 1216 | Melder_require (pitchCeiling > pitchFloor, |
| 1217 | U"The pitch ceiling has to be greater than the pitch floor, so they cannot be ", |
| 1218 | pitchCeiling, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1219 | ); |
| 1220 | my setInstancePref_pitch_method (analysisMethod); |
| 1221 | my setInstancePref_pitch_filteredAC_floor (pitchFloor); |
| 1222 | my setInstancePref_pitch_filteredAC_top (pitchCeiling); |
| 1223 | my setInstancePref_pitch_filteredAC_unit (unit); |
| 1224 | my setInstancePref_pitch_filteredAC_drawingMethod (drawingMethod); |
| 1225 | my setInstancePref_pitch_filteredAC_viewFrom (viewFrom); |
| 1226 | my setInstancePref_pitch_filteredAC_viewTo (viewTo); |
| 1227 | my setInstancePref_pitch_rawCC_floor (pitchFloor); |
| 1228 | my setInstancePref_pitch_rawCC_ceiling (pitchCeiling); |
| 1229 | my setInstancePref_pitch_rawCC_unit (unit); |
| 1230 | my setInstancePref_pitch_rawCC_drawingMethod (drawingMethod); |
| 1231 | my setInstancePref_pitch_rawCC_viewFrom (viewFrom); |
| 1232 | my setInstancePref_pitch_rawCC_viewTo (viewTo); |
| 1233 | my setInstancePref_pitch_rawAC_floor (pitchFloor); |
| 1234 | my setInstancePref_pitch_rawAC_ceiling (pitchCeiling); |
| 1235 | my setInstancePref_pitch_rawAC_unit (unit); |
| 1236 | my setInstancePref_pitch_rawAC_drawingMethod (drawingMethod); |
| 1237 | my setInstancePref_pitch_rawAC_viewFrom (viewFrom); |
| 1238 | my setInstancePref_pitch_rawAC_viewTo (viewTo); |
| 1239 | my setInstancePref_pitch_filteredCC_floor (pitchFloor); |
| 1240 | my setInstancePref_pitch_filteredCC_top (pitchCeiling); |
| 1241 | my setInstancePref_pitch_filteredCC_unit (unit); |
| 1242 | my setInstancePref_pitch_filteredCC_drawingMethod (drawingMethod); |
| 1243 | my setInstancePref_pitch_filteredCC_viewFrom (viewFrom); |
| 1244 | my setInstancePref_pitch_filteredCC_viewTo (viewTo); |
| 1245 | my d_pitch. reset(); |
| 1246 | my d_intensity. reset(); |
| 1247 | my d_pulses. reset(); |
| 1248 | FunctionEditor_redraw (my functionEditor()); |
| 1249 | EDITOR_END |
| 1250 | } |
| 1251 | |
| 1252 | static void menu_cb_advancedPitchSettings_BEFORE_6400 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1253 | EDITOR_FORM (U"Advanced pitch settings", U"Advanced pitch settings...") |
| 1254 | COMMENT (U"YOU SHOULD NEVER SEE THIS OBSOLETE SETTINGS WINDOW;") |
| 1255 | COMMENT (U"IT IS HERE ONLY FOR COMPATIBILITY WITH OLD SCRIPTS.") |
| 1256 | REAL (viewFrom, U"left View range (units)", my default_pitch_rawAC_viewFrom ()) // the default is ignored if not shown |
| 1257 | REAL (viewTo, U"right View range (units)", my default_pitch_rawAC_viewTo ()) |
| 1258 | BOOLEAN (veryAccurate, U"Very accurate", false) |
| 1259 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_rawAC_maximumNumberOfCandidates ()) |
| 1260 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_rawAC_silenceThreshold ()) |
| 1261 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_rawAC_voicingThreshold ()) |
| 1262 | REAL (octaveCost, U"Octave cost", my default_pitch_rawAC_octaveCost ()) |
| 1263 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_rawAC_octaveJumpCost ()) |
| 1264 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_rawAC_voicedUnvoicedCost ()) |
| 1265 | EDITOR_OK |
| 1266 | EDITOR_DO |
| 1267 | if (maximumNumberOfCandidates < 2) |
| 1268 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1269 | kSoundAnalysisArea_pitch_analysisMethod analysisMethod = my instancePref_pitch_method(); |
| 1270 | Melder_require ( |
| 1271 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION || |
| 1272 | analysisMethod == kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION, |
| 1273 | U"Obsolete advanced pitch settings command can handle only raw AC and CC methods." |
| 1274 | U"Use one of the modern pitch setting commands instead." |
| 1275 | ); |
| 1276 | my setInstancePref_pitch_rawAC_viewFrom (viewFrom); |
| 1277 | my setInstancePref_pitch_rawCC_viewFrom (viewFrom); |
| 1278 | my setInstancePref_pitch_rawAC_viewTo (viewTo); |
| 1279 | my setInstancePref_pitch_rawCC_viewTo (viewTo); |
| 1280 | my setInstancePref_pitch_rawAC_veryAccurate (veryAccurate); |
| 1281 | my setInstancePref_pitch_rawCC_veryAccurate (veryAccurate); |
| 1282 | my setInstancePref_pitch_rawAC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1283 | my setInstancePref_pitch_rawCC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1284 | my setInstancePref_pitch_rawAC_silenceThreshold (silenceThreshold); |
| 1285 | my setInstancePref_pitch_rawCC_silenceThreshold (silenceThreshold); |
| 1286 | my setInstancePref_pitch_rawAC_voicingThreshold (voicingThreshold); |
| 1287 | my setInstancePref_pitch_rawCC_voicingThreshold (voicingThreshold); |
| 1288 | my setInstancePref_pitch_rawAC_octaveCost (octaveCost); |
| 1289 | my setInstancePref_pitch_rawCC_octaveCost (octaveCost); |
| 1290 | my setInstancePref_pitch_rawAC_octaveJumpCost (octaveJumpCost); |
| 1291 | my setInstancePref_pitch_rawCC_octaveJumpCost (octaveJumpCost); |
| 1292 | my setInstancePref_pitch_rawAC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1293 | my setInstancePref_pitch_rawCC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1294 | my d_pitch. reset(); |
| 1295 | my d_intensity. reset(); |
| 1296 | my d_pulses. reset(); |
| 1297 | FunctionEditor_redraw (my functionEditor()); |
| 1298 | EDITOR_END |
| 1299 | } |
| 1300 | |
| 1301 | static void menu_cb_advancedPitchSettings_rawAcCc_BEFORE_6414 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1302 | EDITOR_FORM (U"Advanced pitch settings (raw AC and CC)", U"Advanced pitch settings (raw AC and CC)...") |
| 1303 | COMMENT (U"YOU SHOULD NEVER SEE THIS OBSOLETE SETTINGS WINDOW;") |
| 1304 | COMMENT (U"IT IS HERE ONLY FOR COMPATIBILITY WITH OLD SCRIPTS.") |
| 1305 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_rawAC_maximumNumberOfCandidates ()) // the default is ignored if not shown |
| 1306 | BOOLEAN (veryAccurate, U"Very accurate", false) |
| 1307 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_rawAC_silenceThreshold ()) |
| 1308 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_rawAC_voicingThreshold ()) |
| 1309 | REAL (octaveCost, U"Octave cost", my default_pitch_rawAC_octaveCost ()) |
| 1310 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_rawAC_octaveJumpCost ()) |
| 1311 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_rawAC_voicedUnvoicedCost ()) |
| 1312 | EDITOR_OK |
| 1313 | EDITOR_DO |
| 1314 | if (maximumNumberOfCandidates < 2) |
| 1315 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1316 | my setInstancePref_pitch_rawAC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1317 | my setInstancePref_pitch_rawCC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1318 | my setInstancePref_pitch_rawAC_veryAccurate (veryAccurate); |
| 1319 | my setInstancePref_pitch_rawCC_veryAccurate (veryAccurate); |
| 1320 | my setInstancePref_pitch_rawAC_silenceThreshold (silenceThreshold); |
| 1321 | my setInstancePref_pitch_rawCC_silenceThreshold (silenceThreshold); |
| 1322 | my setInstancePref_pitch_rawAC_voicingThreshold (voicingThreshold); |
| 1323 | my setInstancePref_pitch_rawCC_voicingThreshold (voicingThreshold); |
| 1324 | my setInstancePref_pitch_rawAC_octaveCost (octaveCost); |
| 1325 | my setInstancePref_pitch_rawCC_octaveCost (octaveCost); |
| 1326 | my setInstancePref_pitch_rawAC_octaveJumpCost (octaveJumpCost); |
| 1327 | my setInstancePref_pitch_rawCC_octaveJumpCost (octaveJumpCost); |
| 1328 | my setInstancePref_pitch_rawAC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1329 | my setInstancePref_pitch_rawCC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1330 | my d_pitch. reset(); |
| 1331 | my d_intensity. reset(); |
| 1332 | my d_pulses. reset(); |
| 1333 | FunctionEditor_redraw (my functionEditor()); |
| 1334 | EDITOR_END |
| 1335 | } |
| 1336 | |
| 1337 | static void menu_cb_advancedPitchSettings_filteredAcCc_BEFORE_6414 (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1338 | EDITOR_FORM (U"Advanced pitch settings (filtered AC and CC)", U"Advanced pitch settings (filtered AC and CC)...") |
| 1339 | COMMENT (U"YOU SHOULD NEVER SEE THIS OBSOLETE SETTINGS WINDOW;") |
| 1340 | COMMENT (U"IT IS HERE ONLY FOR COMPATIBILITY WITH OLD SCRIPTS.") |
| 1341 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_filteredAC_maximumNumberOfCandidates ()) // the default is ignored if not shown |
| 1342 | BOOLEAN (veryAccurate, U"Very accurate", my default_pitch_filteredAC_veryAccurate ()) |
| 1343 | POSITIVE (attenuationAtTop, U"Attenuation at top", my default_pitch_filteredAC_attenuationAtTop ()) |
| 1344 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_filteredAC_silenceThreshold ()) |
| 1345 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_filteredAC_voicingThreshold ()) |
| 1346 | REAL (octaveCost, U"Octave cost", my default_pitch_filteredAC_octaveCost ()) |
| 1347 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_filteredAC_octaveJumpCost ()) |
| 1348 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_filteredAC_voicedUnvoicedCost ()) |
| 1349 | EDITOR_OK |
| 1350 | EDITOR_DO |
| 1351 | if (maximumNumberOfCandidates < 2) |
| 1352 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1353 | my setInstancePref_pitch_filteredAC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1354 | my setInstancePref_pitch_filteredCC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1355 | my setInstancePref_pitch_filteredAC_veryAccurate (veryAccurate); |
| 1356 | my setInstancePref_pitch_filteredCC_veryAccurate (veryAccurate); |
| 1357 | my setInstancePref_pitch_filteredAC_attenuationAtTop (attenuationAtTop); |
| 1358 | my setInstancePref_pitch_filteredCC_attenuationAtTop (attenuationAtTop); |
| 1359 | my setInstancePref_pitch_filteredAC_silenceThreshold (silenceThreshold); |
| 1360 | my setInstancePref_pitch_filteredCC_silenceThreshold (silenceThreshold); |
| 1361 | my setInstancePref_pitch_filteredAC_voicingThreshold (voicingThreshold); |
| 1362 | my setInstancePref_pitch_filteredCC_voicingThreshold (voicingThreshold); |
| 1363 | my setInstancePref_pitch_filteredAC_octaveCost (octaveCost); |
| 1364 | my setInstancePref_pitch_filteredCC_octaveCost (octaveCost); |
| 1365 | my setInstancePref_pitch_filteredAC_octaveJumpCost (octaveJumpCost); |
| 1366 | my setInstancePref_pitch_filteredCC_octaveJumpCost (octaveJumpCost); |
| 1367 | my setInstancePref_pitch_filteredAC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1368 | my setInstancePref_pitch_filteredCC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1369 | my d_pitch. reset(); |
| 1370 | my d_intensity. reset(); |
| 1371 | my d_pulses. reset(); |
| 1372 | FunctionEditor_redraw (my functionEditor()); |
| 1373 | EDITOR_END |
| 1374 | } |
| 1375 | |
| 1376 | static void menu_cb_pitchSettings_filteredAC (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1377 | EDITOR_FORM (U"Pitch settings for the filtered autocorrelation method", U"Intro 4.2. Configuring the pitch contour") |
| 1378 | MUTABLE_COMMENT (methodMatchWarning, U"") |
| 1379 | HEADING (U"Where to search...") |
| 1380 | MUTABLE_CAPTION (note, U"") |
| 1381 | POSITIVE (pitchFloor, U"left Pitch floor and top (Hz)", my default_pitch_filteredAC_floor()) |
| 1382 | POSITIVE (pitchTop, U"right Pitch floor and top (Hz)", my default_pitch_filteredAC_top()) |
| 1383 | HEADING (U"How to view...") |
| 1384 | OPTIONMENU_ENUM (kPitch_unit, unit, |
| 1385 | U"Unit", my default_pitch_filteredAC_unit ()) |
| 1386 | REAL (viewFrom, U"left View range (units)", my default_pitch_filteredAC_viewFrom()) |
| 1387 | REAL (viewTo, U"right View range (units)", my default_pitch_filteredAC_viewTo()) |
| 1388 | CAPTION (U"(“auto” means ‘same as pitch floor and top’)") |
| 1389 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, |
| 1390 | U"Drawing method", my default_pitch_filteredAC_drawingMethod()) |
| 1391 | HEADING (U"How to find the candidates...") |
| 1392 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_filteredAC_maximumNumberOfCandidates ()) |
| 1393 | BOOLEAN (veryAccurate, U"Very accurate", my default_pitch_filteredAC_veryAccurate()) |
| 1394 | HEADING (U"How to preprocess the sound...") |
| 1395 | POSITIVE (attenuationAtTop, U"Attenuation at top", my default_pitch_filteredAC_attenuationAtTop ()) |
| 1396 | HEADING (U"How to find a path through the candidates...") |
| 1397 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_filteredAC_silenceThreshold ()) |
| 1398 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_filteredAC_voicingThreshold ()) |
| 1399 | REAL (octaveCost, U"Octave cost", my default_pitch_filteredAC_octaveCost ()) |
| 1400 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_filteredAC_octaveJumpCost ()) |
| 1401 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_filteredAC_voicedUnvoicedCost ()) |
| 1402 | EDITOR_OK |
| 1403 | const bool methodMatch = ( my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_AUTOCORRELATION ); |
| 1404 | const conststring32 currentMethodText = kSoundAnalysisArea_pitch_analysisMethod_getText (my instancePref_pitch_method()); |
| 1405 | SET_STRING (methodMatchWarning, methodMatch ? |
| 1406 | Melder_cat (U"(your current pitch analysis method is indeed ", currentMethodText, U")") : |
| 1407 | Melder_cat (U"WARNING: your current pitch analysis method is ", currentMethodText, U"!") |
| 1408 | ) |
| 1409 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy ()) |
| 1410 | SET_STRING (note, U"(Warning: your time step settings are non-standard; see Analysis menu)") |
| 1411 | else |
| 1412 | SET_STRING (note, U"(you have standard time step settings; see Analysis menu)") |
| 1413 | SET_REAL (pitchFloor, my instancePref_pitch_filteredAC_floor()) |
| 1414 | SET_REAL (pitchTop, my instancePref_pitch_filteredAC_top()) |
| 1415 | SET_ENUM (unit, kPitch_unit, my instancePref_pitch_filteredAC_unit()) |
| 1416 | SET_REAL (viewFrom, my instancePref_pitch_filteredAC_viewFrom()) |
| 1417 | SET_REAL (viewTo, my instancePref_pitch_filteredAC_viewTo()) |
| 1418 | SET_ENUM (drawingMethod, kSoundAnalysisArea_pitch_drawingMethod, |
| 1419 | my instancePref_pitch_filteredAC_drawingMethod()) |
| 1420 | SET_INTEGER (maximumNumberOfCandidates, my instancePref_pitch_filteredAC_maximumNumberOfCandidates()) |
| 1421 | SET_BOOLEAN (veryAccurate, my instancePref_pitch_filteredAC_veryAccurate()) |
| 1422 | SET_REAL (attenuationAtTop, my instancePref_pitch_filteredAC_attenuationAtTop()) |
| 1423 | SET_REAL (silenceThreshold, my instancePref_pitch_filteredAC_silenceThreshold()) |
| 1424 | SET_REAL (voicingThreshold, my instancePref_pitch_filteredAC_voicingThreshold()) |
| 1425 | SET_REAL (octaveCost, my instancePref_pitch_filteredAC_octaveCost()) |
| 1426 | SET_REAL (octaveJumpCost, my instancePref_pitch_filteredAC_octaveJumpCost()) |
| 1427 | SET_REAL (voicedUnvoicedCost, my instancePref_pitch_filteredAC_voicedUnvoicedCost()) |
| 1428 | EDITOR_DO |
| 1429 | Melder_require (pitchTop > pitchFloor, |
| 1430 | U"The pitch top has to be greater than the pitch floor, so they cannot be ", |
| 1431 | pitchTop, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1432 | ); |
| 1433 | if (maximumNumberOfCandidates < 2) |
| 1434 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1435 | my setInstancePref_pitch_filteredAC_floor (pitchFloor); |
| 1436 | my setInstancePref_pitch_filteredAC_top (pitchTop); |
| 1437 | my setInstancePref_pitch_filteredAC_unit (unit); |
| 1438 | my setInstancePref_pitch_filteredAC_viewFrom (viewFrom); |
| 1439 | my setInstancePref_pitch_filteredAC_viewTo (viewTo); |
| 1440 | my setInstancePref_pitch_filteredAC_drawingMethod (drawingMethod); |
| 1441 | my setInstancePref_pitch_filteredAC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1442 | my setInstancePref_pitch_filteredAC_veryAccurate (veryAccurate); |
| 1443 | my setInstancePref_pitch_filteredAC_attenuationAtTop (attenuationAtTop); |
| 1444 | my setInstancePref_pitch_filteredAC_silenceThreshold (silenceThreshold); |
| 1445 | my setInstancePref_pitch_filteredAC_voicingThreshold (voicingThreshold); |
| 1446 | my setInstancePref_pitch_filteredAC_octaveCost (octaveCost); |
| 1447 | my setInstancePref_pitch_filteredAC_octaveJumpCost (octaveJumpCost); |
| 1448 | my setInstancePref_pitch_filteredAC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1449 | my d_pitch. reset(); |
| 1450 | my d_intensity. reset(); |
| 1451 | my d_pulses. reset(); |
| 1452 | FunctionEditor_redraw (my functionEditor()); |
| 1453 | EDITOR_END |
| 1454 | } |
| 1455 | |
| 1456 | static void menu_cb_pitchSettings_rawCC (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1457 | EDITOR_FORM (U"Pitch settings for the raw cross-correlation method", U"Intro 4.2. Configuring the pitch contour") |
| 1458 | MUTABLE_COMMENT (methodMatchWarning, U"") |
| 1459 | HEADING (U"Where to search...") |
| 1460 | MUTABLE_CAPTION (note, U"") |
| 1461 | POSITIVE (pitchFloor, U"left Pitch floor and ceiling (Hz)", my default_pitch_rawCC_floor()) |
| 1462 | POSITIVE (pitchCeiling, U"right Pitch floor and ceiling (Hz)", my default_pitch_rawCC_ceiling()) |
| 1463 | HEADING (U"How to view...") |
| 1464 | OPTIONMENU_ENUM (kPitch_unit, unit, |
| 1465 | U"Unit", my default_pitch_rawCC_unit ()) |
| 1466 | REAL (viewFrom, U"left View range (units)", my default_pitch_rawCC_viewFrom()) |
| 1467 | REAL (viewTo, U"right View range (units)", my default_pitch_rawCC_viewTo()) |
| 1468 | CAPTION (U"(“auto” means ‘same as pitch floor and ceiling’)") |
| 1469 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, |
| 1470 | U"Drawing method", my default_pitch_rawCC_drawingMethod()) |
| 1471 | HEADING (U"How to find the candidates...") |
| 1472 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_rawCC_maximumNumberOfCandidates ()) |
| 1473 | BOOLEAN (veryAccurate, U"Very accurate", my default_pitch_rawCC_veryAccurate()) |
| 1474 | HEADING (U"How to find a path through the candidates...") |
| 1475 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_rawCC_silenceThreshold ()) |
| 1476 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_rawCC_voicingThreshold ()) |
| 1477 | REAL (octaveCost, U"Octave cost", my default_pitch_rawCC_octaveCost ()) |
| 1478 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_rawCC_octaveJumpCost ()) |
| 1479 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_rawCC_voicedUnvoicedCost ()) |
| 1480 | EDITOR_OK |
| 1481 | const bool methodMatch = ( my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION ); |
| 1482 | const conststring32 currentMethodText = kSoundAnalysisArea_pitch_analysisMethod_getText (my instancePref_pitch_method()); |
| 1483 | SET_STRING (methodMatchWarning, methodMatch ? |
| 1484 | Melder_cat (U"(your current pitch analysis method is indeed ", currentMethodText, U")") : |
| 1485 | Melder_cat (U"WARNING: your current pitch analysis method is ", currentMethodText, U"!") |
| 1486 | ) |
| 1487 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy ()) |
| 1488 | SET_STRING (note, U"(Warning: your time step settings are non-standard; see Analysis menu)") |
| 1489 | else |
| 1490 | SET_STRING (note, U"(you have standard time step settings; see Analysis menu)") |
| 1491 | SET_REAL (pitchFloor, my instancePref_pitch_rawCC_floor()) |
| 1492 | SET_REAL (pitchCeiling, my instancePref_pitch_rawCC_ceiling()) |
| 1493 | SET_ENUM (unit, kPitch_unit, my instancePref_pitch_rawCC_unit()) |
| 1494 | SET_REAL (viewFrom, my instancePref_pitch_rawCC_viewFrom()) |
| 1495 | SET_REAL (viewTo, my instancePref_pitch_rawCC_viewTo()) |
| 1496 | SET_ENUM (drawingMethod, kSoundAnalysisArea_pitch_drawingMethod, |
| 1497 | my instancePref_pitch_rawCC_drawingMethod()) |
| 1498 | SET_INTEGER (maximumNumberOfCandidates, my instancePref_pitch_rawCC_maximumNumberOfCandidates()) |
| 1499 | SET_BOOLEAN (veryAccurate, my instancePref_pitch_rawCC_veryAccurate()) |
| 1500 | SET_REAL (silenceThreshold, my instancePref_pitch_rawCC_silenceThreshold()) |
| 1501 | SET_REAL (voicingThreshold, my instancePref_pitch_rawCC_voicingThreshold()) |
| 1502 | SET_REAL (octaveCost, my instancePref_pitch_rawCC_octaveCost()) |
| 1503 | SET_REAL (octaveJumpCost, my instancePref_pitch_rawCC_octaveJumpCost()) |
| 1504 | SET_REAL (voicedUnvoicedCost, my instancePref_pitch_rawCC_voicedUnvoicedCost()) |
| 1505 | EDITOR_DO |
| 1506 | Melder_require (pitchCeiling > pitchFloor, |
| 1507 | U"The pitch ceiling has to be greater than the pitch floor, so they cannot be ", |
| 1508 | pitchCeiling, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1509 | ); |
| 1510 | if (maximumNumberOfCandidates < 2) |
| 1511 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1512 | my setInstancePref_pitch_rawCC_floor (pitchFloor); |
| 1513 | my setInstancePref_pitch_rawCC_ceiling (pitchCeiling); |
| 1514 | my setInstancePref_pitch_rawCC_unit (unit); |
| 1515 | my setInstancePref_pitch_rawCC_viewFrom (viewFrom); |
| 1516 | my setInstancePref_pitch_rawCC_viewTo (viewTo); |
| 1517 | my setInstancePref_pitch_rawCC_drawingMethod (drawingMethod); |
| 1518 | my setInstancePref_pitch_rawCC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1519 | my setInstancePref_pitch_rawCC_veryAccurate (veryAccurate); |
| 1520 | my setInstancePref_pitch_rawCC_silenceThreshold (silenceThreshold); |
| 1521 | my setInstancePref_pitch_rawCC_voicingThreshold (voicingThreshold); |
| 1522 | my setInstancePref_pitch_rawCC_octaveCost (octaveCost); |
| 1523 | my setInstancePref_pitch_rawCC_octaveJumpCost (octaveJumpCost); |
| 1524 | my setInstancePref_pitch_rawCC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1525 | my d_pitch. reset(); |
| 1526 | my d_intensity. reset(); |
| 1527 | my d_pulses. reset(); |
| 1528 | FunctionEditor_redraw (my functionEditor()); |
| 1529 | EDITOR_END |
| 1530 | } |
| 1531 | |
| 1532 | static void menu_cb_pitchSettings_rawAC (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1533 | EDITOR_FORM (U"Pitch settings for the raw autocorrelation method", U"Intro 4.2. Configuring the pitch contour") |
| 1534 | MUTABLE_COMMENT (methodMatchWarning, U"") |
| 1535 | HEADING (U"Where to search...") |
| 1536 | MUTABLE_CAPTION (note, U"") |
| 1537 | POSITIVE (pitchFloor, U"left Pitch floor and ceiling (Hz)", my default_pitch_rawAC_floor()) |
| 1538 | POSITIVE (pitchCeiling, U"right Pitch floor and ceiling (Hz)", my default_pitch_rawAC_ceiling()) |
| 1539 | HEADING (U"How to view...") |
| 1540 | OPTIONMENU_ENUM (kPitch_unit, unit, |
| 1541 | U"Unit", my default_pitch_rawAC_unit ()) |
| 1542 | REAL (viewFrom, U"left View range (units)", my default_pitch_rawAC_viewFrom()) |
| 1543 | REAL (viewTo, U"right View range (units)", my default_pitch_rawAC_viewTo()) |
| 1544 | CAPTION (U"(“auto” means ‘same as pitch floor and ceiling’)") |
| 1545 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, |
| 1546 | U"Drawing method", my default_pitch_rawAC_drawingMethod()) |
| 1547 | HEADING (U"How to find the candidates...") |
| 1548 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_rawAC_maximumNumberOfCandidates ()) |
| 1549 | BOOLEAN (veryAccurate, U"Very accurate", my default_pitch_rawAC_veryAccurate()) |
| 1550 | HEADING (U"How to find a path through the candidates...") |
| 1551 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_rawAC_silenceThreshold ()) |
| 1552 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_rawAC_voicingThreshold ()) |
| 1553 | REAL (octaveCost, U"Octave cost", my default_pitch_rawAC_octaveCost ()) |
| 1554 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_rawAC_octaveJumpCost ()) |
| 1555 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_rawAC_voicedUnvoicedCost ()) |
| 1556 | EDITOR_OK |
| 1557 | const bool methodMatch = ( my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION ); |
| 1558 | const conststring32 currentMethodText = kSoundAnalysisArea_pitch_analysisMethod_getText (my instancePref_pitch_method()); |
| 1559 | SET_STRING (methodMatchWarning, methodMatch ? |
| 1560 | Melder_cat (U"(your current pitch analysis method is indeed ", currentMethodText, U")") : |
| 1561 | Melder_cat (U"WARNING: your current pitch analysis method is ", currentMethodText, U"!") |
| 1562 | ) |
| 1563 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy ()) |
| 1564 | SET_STRING (note, U"(Warning: your time step settings are non-standard; see Analysis menu)") |
| 1565 | else |
| 1566 | SET_STRING (note, U"(you have standard time step settings; see Analysis menu)") |
| 1567 | SET_REAL (pitchFloor, my instancePref_pitch_rawAC_floor()) |
| 1568 | SET_REAL (pitchCeiling, my instancePref_pitch_rawAC_ceiling()) |
| 1569 | SET_ENUM (unit, kPitch_unit, my instancePref_pitch_rawAC_unit()) |
| 1570 | SET_REAL (viewFrom, my instancePref_pitch_rawAC_viewFrom()) |
| 1571 | SET_REAL (viewTo, my instancePref_pitch_rawAC_viewTo()) |
| 1572 | SET_ENUM (drawingMethod, kSoundAnalysisArea_pitch_drawingMethod, |
| 1573 | my instancePref_pitch_rawAC_drawingMethod()) |
| 1574 | SET_INTEGER (maximumNumberOfCandidates, my instancePref_pitch_rawAC_maximumNumberOfCandidates()) |
| 1575 | SET_BOOLEAN (veryAccurate, my instancePref_pitch_rawAC_veryAccurate()) |
| 1576 | SET_REAL (silenceThreshold, my instancePref_pitch_rawAC_silenceThreshold()) |
| 1577 | SET_REAL (voicingThreshold, my instancePref_pitch_rawAC_voicingThreshold()) |
| 1578 | SET_REAL (octaveCost, my instancePref_pitch_rawAC_octaveCost()) |
| 1579 | SET_REAL (octaveJumpCost, my instancePref_pitch_rawAC_octaveJumpCost()) |
| 1580 | SET_REAL (voicedUnvoicedCost, my instancePref_pitch_rawAC_voicedUnvoicedCost()) |
| 1581 | EDITOR_DO |
| 1582 | Melder_require (pitchCeiling > pitchFloor, |
| 1583 | U"The pitch ceiling has to be greater than the pitch floor, so they cannot be ", |
| 1584 | pitchCeiling, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1585 | ); |
| 1586 | if (maximumNumberOfCandidates < 2) |
| 1587 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1588 | my setInstancePref_pitch_rawAC_floor (pitchFloor); |
| 1589 | my setInstancePref_pitch_rawAC_ceiling (pitchCeiling); |
| 1590 | my setInstancePref_pitch_rawAC_unit (unit); |
| 1591 | my setInstancePref_pitch_rawAC_viewFrom (viewFrom); |
| 1592 | my setInstancePref_pitch_rawAC_viewTo (viewTo); |
| 1593 | my setInstancePref_pitch_rawAC_drawingMethod (drawingMethod); |
| 1594 | my setInstancePref_pitch_rawAC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1595 | my setInstancePref_pitch_rawAC_veryAccurate (veryAccurate); |
| 1596 | my setInstancePref_pitch_rawAC_silenceThreshold (silenceThreshold); |
| 1597 | my setInstancePref_pitch_rawAC_voicingThreshold (voicingThreshold); |
| 1598 | my setInstancePref_pitch_rawAC_octaveCost (octaveCost); |
| 1599 | my setInstancePref_pitch_rawAC_octaveJumpCost (octaveJumpCost); |
| 1600 | my setInstancePref_pitch_rawAC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1601 | my d_pitch. reset(); |
| 1602 | my d_intensity. reset(); |
| 1603 | my d_pulses. reset(); |
| 1604 | FunctionEditor_redraw (my functionEditor()); |
| 1605 | EDITOR_END |
| 1606 | } |
| 1607 | |
| 1608 | static void menu_cb_pitchSettings_filteredCC (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1609 | EDITOR_FORM (U"Pitch settings for the filtered cross-correlation method", U"Intro 4.2. Configuring the pitch contour") |
| 1610 | MUTABLE_COMMENT (methodMatchWarning, U"") |
| 1611 | HEADING (U"Where to search...") |
| 1612 | MUTABLE_CAPTION (note, U"") |
| 1613 | POSITIVE (pitchFloor, U"left Pitch floor and top (Hz)", my default_pitch_filteredCC_floor()) |
| 1614 | POSITIVE (pitchTop, U"right Pitch floor and top (Hz)", my default_pitch_filteredCC_top()) |
| 1615 | HEADING (U"How to view...") |
| 1616 | OPTIONMENU_ENUM (kPitch_unit, unit, |
| 1617 | U"Unit", my default_pitch_filteredCC_unit ()) |
| 1618 | REAL (viewFrom, U"left View range (units)", my default_pitch_filteredCC_viewFrom()) |
| 1619 | REAL (viewTo, U"right View range (units)", my default_pitch_filteredCC_viewTo()) |
| 1620 | CAPTION (U"(“auto” means ‘same as pitch floor and top’)") |
| 1621 | OPTIONMENU_ENUM (kSoundAnalysisArea_pitch_drawingMethod, drawingMethod, |
| 1622 | U"Drawing method", my default_pitch_filteredCC_drawingMethod()) |
| 1623 | HEADING (U"How to find the candidates...") |
| 1624 | NATURAL (maximumNumberOfCandidates, U"Max. number of candidates", my default_pitch_filteredCC_maximumNumberOfCandidates ()) |
| 1625 | BOOLEAN (veryAccurate, U"Very accurate", my default_pitch_filteredCC_veryAccurate()) |
| 1626 | HEADING (U"How to preprocess the sound...") |
| 1627 | POSITIVE (attenuationAtTop, U"Attenuation at top", my default_pitch_filteredCC_attenuationAtTop ()) |
| 1628 | HEADING (U"How to find a path through the candidates...") |
| 1629 | REAL (silenceThreshold, U"Silence threshold", my default_pitch_filteredCC_silenceThreshold ()) |
| 1630 | REAL (voicingThreshold, U"Voicing threshold", my default_pitch_filteredCC_voicingThreshold ()) |
| 1631 | REAL (octaveCost, U"Octave cost", my default_pitch_filteredCC_octaveCost ()) |
| 1632 | REAL (octaveJumpCost, U"Octave-jump cost", my default_pitch_filteredCC_octaveJumpCost ()) |
| 1633 | REAL (voicedUnvoicedCost, U"Voiced / unvoiced cost", my default_pitch_filteredCC_voicedUnvoicedCost ()) |
| 1634 | EDITOR_OK |
| 1635 | const bool methodMatch = ( my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_CROSS_CORRELATION ); |
| 1636 | const conststring32 currentMethodText = kSoundAnalysisArea_pitch_analysisMethod_getText (my instancePref_pitch_method()); |
| 1637 | SET_STRING (methodMatchWarning, methodMatch ? |
| 1638 | Melder_cat (U"(your current pitch analysis method is indeed ", currentMethodText, U")") : |
| 1639 | Melder_cat (U"WARNING: your current pitch analysis method is ", currentMethodText, U"!") |
| 1640 | ) |
| 1641 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy ()) |
| 1642 | SET_STRING (note, U"(Warning: your time step settings are non-standard; see Analysis menu)") |
| 1643 | else |
| 1644 | SET_STRING (note, U"(you have standard time step settings; see Analysis menu)") |
| 1645 | SET_REAL (pitchFloor, my instancePref_pitch_filteredCC_floor()) |
| 1646 | SET_REAL (pitchTop, my instancePref_pitch_filteredCC_top()) |
| 1647 | SET_ENUM (unit, kPitch_unit, my instancePref_pitch_filteredCC_unit()) |
| 1648 | SET_REAL (viewFrom, my instancePref_pitch_filteredCC_viewFrom()) |
| 1649 | SET_REAL (viewTo, my instancePref_pitch_filteredCC_viewTo()) |
| 1650 | SET_ENUM (drawingMethod, kSoundAnalysisArea_pitch_drawingMethod, |
| 1651 | my instancePref_pitch_filteredCC_drawingMethod()) |
| 1652 | SET_INTEGER (maximumNumberOfCandidates, my instancePref_pitch_filteredCC_maximumNumberOfCandidates()) |
| 1653 | SET_BOOLEAN (veryAccurate, my instancePref_pitch_filteredCC_veryAccurate()) |
| 1654 | SET_REAL (attenuationAtTop, my instancePref_pitch_filteredCC_attenuationAtTop()) |
| 1655 | SET_REAL (silenceThreshold, my instancePref_pitch_filteredCC_silenceThreshold()) |
| 1656 | SET_REAL (voicingThreshold, my instancePref_pitch_filteredCC_voicingThreshold()) |
| 1657 | SET_REAL (octaveCost, my instancePref_pitch_filteredCC_octaveCost()) |
| 1658 | SET_REAL (octaveJumpCost, my instancePref_pitch_filteredCC_octaveJumpCost()) |
| 1659 | SET_REAL (voicedUnvoicedCost, my instancePref_pitch_filteredCC_voicedUnvoicedCost()) |
| 1660 | EDITOR_DO |
| 1661 | Melder_require (pitchTop > pitchFloor, |
| 1662 | U"The pitch top has to be greater than the pitch floor, so they cannot be ", |
| 1663 | pitchTop, U" and ", pitchFloor, U" ", kPitch_unit_getText (unit), U", respectively." |
| 1664 | ); |
| 1665 | if (maximumNumberOfCandidates < 2) |
| 1666 | Melder_throw (U"Your maximum number of candidates should be greater than 1."); |
| 1667 | my setInstancePref_pitch_filteredCC_floor (pitchFloor); |
| 1668 | my setInstancePref_pitch_filteredCC_top (pitchTop); |
| 1669 | my setInstancePref_pitch_filteredCC_unit (unit); |
| 1670 | my setInstancePref_pitch_filteredCC_viewFrom (viewFrom); |
| 1671 | my setInstancePref_pitch_filteredCC_viewTo (viewTo); |
| 1672 | my setInstancePref_pitch_filteredCC_drawingMethod (drawingMethod); |
| 1673 | my setInstancePref_pitch_filteredCC_maximumNumberOfCandidates (maximumNumberOfCandidates); |
| 1674 | my setInstancePref_pitch_filteredCC_veryAccurate (veryAccurate); |
| 1675 | my setInstancePref_pitch_filteredCC_attenuationAtTop (attenuationAtTop); |
| 1676 | my setInstancePref_pitch_filteredCC_silenceThreshold (silenceThreshold); |
| 1677 | my setInstancePref_pitch_filteredCC_voicingThreshold (voicingThreshold); |
| 1678 | my setInstancePref_pitch_filteredCC_octaveCost (octaveCost); |
| 1679 | my setInstancePref_pitch_filteredCC_octaveJumpCost (octaveJumpCost); |
| 1680 | my setInstancePref_pitch_filteredCC_voicedUnvoicedCost (voicedUnvoicedCost); |
| 1681 | my d_pitch. reset(); |
| 1682 | my d_intensity. reset(); |
| 1683 | my d_pulses. reset(); |
| 1684 | FunctionEditor_redraw (my functionEditor()); |
| 1685 | EDITOR_END |
| 1686 | } |
| 1687 | |
| 1688 | static void menu_cb_howToChooseAPitchAnalysisMethod (SoundAnalysisArea /* me */, EDITOR_ARGS) { |
| 1689 | Melder_help (U"how to choose a pitch analysis method"); |
| 1690 | } |
| 1691 | |
| 1692 | static void shared_menu_cb_pitchMethodIsXXX (SoundAnalysisArea me, kSoundAnalysisArea_pitch_analysisMethod method) { |
| 1693 | my setInstancePref_pitch_method (method); |
| 1694 | my d_pitch. reset(); |
| 1695 | my d_intensity. reset(); |
| 1696 | my d_pulses. reset(); |
| 1697 | FunctionEditor_redraw (my functionEditor()); // this will call v_updateMenuItems (last checked 2024-07-18 for Mac, Win, Linux) |
| 1698 | } |
| 1699 | static void menu_cb_pitchMethodIsFilteredAutocorrelation (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1700 | shared_menu_cb_pitchMethodIsXXX (me, kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_AUTOCORRELATION); |
| 1701 | } |
| 1702 | static void menu_cb_pitchMethodIsRawCrossCorrelation (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1703 | shared_menu_cb_pitchMethodIsXXX (me, kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION); |
| 1704 | } |
| 1705 | static void menu_cb_pitchMethodIsRawAutocorrelation (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1706 | shared_menu_cb_pitchMethodIsXXX (me, kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION); |
| 1707 | } |
| 1708 | static void menu_cb_pitchMethodIsFilteredCrossCorrelation (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1709 | shared_menu_cb_pitchMethodIsXXX (me, kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_CROSS_CORRELATION); |
| 1710 | } |
| 1711 | |
| 1712 | static void INFO_DATA__pitchListing (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1713 | INFO_DATA |
| 1714 | double tmin, tmax; |
| 1715 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 1716 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1717 | MelderInfo_open (); |
| 1718 | const kPitch_unit unit = my dynamic_instancePref_pitch_unit(); |
| 1719 | MelderInfo_writeLine (U"Time_s F0_", |
| 1720 | Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) unit, Function_UNIT_TEXT_SHORT)); |
| 1721 | if (part == SoundAnalysisArea_PART_CURSOR) { |
| 1722 | double f0 = Pitch_getValueAtTime (my d_pitch.get(), tmin, unit, true); |
| 1723 | f0 = Function_convertToNonlogarithmic (my d_pitch.get(), f0, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1724 | MelderInfo_writeLine (Melder_fixed (tmin, 6), U" ", Melder_fixed (f0, 6)); |
| 1725 | } else { |
| 1726 | integer i, i1, i2; |
| 1727 | Sampled_getWindowSamples (my d_pitch.get(), tmin, tmax, & i1, & i2); |
| 1728 | for (i = i1; i <= i2; i ++) { |
| 1729 | const double t = Sampled_indexToX (my d_pitch.get(), i); |
| 1730 | double f0 = Sampled_getValueAtSample (my d_pitch.get(), i, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1731 | f0 = Function_convertToNonlogarithmic (my d_pitch.get(), f0, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1732 | MelderInfo_writeLine (Melder_fixed (t, 6), U" ", Melder_fixed (f0, 6)); |
| 1733 | } |
| 1734 | } |
| 1735 | MelderInfo_close (); |
| 1736 | INFO_DATA_END |
| 1737 | } |
| 1738 | |
| 1739 | static void QUERY_DATA_FOR_REAL__getPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1740 | QUERY_DATA_FOR_REAL |
| 1741 | double tmin, tmax; |
| 1742 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 1743 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1744 | const kPitch_unit unit = my dynamic_instancePref_pitch_unit(); |
| 1745 | double result = |
| 1746 | part == SoundAnalysisArea_PART_CURSOR |
| 1747 | ? Pitch_getValueAtTime (my d_pitch.get(), tmin, unit, true) |
| 1748 | : Pitch_getMean (my d_pitch.get(), tmin, tmax, unit) |
| 1749 | ; |
| 1750 | result = Function_convertToNonlogarithmic (my d_pitch.get(), result, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1751 | QUERY_DATA_FOR_REAL_END (U" ", |
| 1752 | Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) unit, 0), |
| 1753 | part == SoundAnalysisArea_PART_CURSOR |
| 1754 | ? U" (interpolated pitch at CURSOR)" |
| 1755 | : Melder_cat (U" (mean pitch ", SoundAnalysisArea_partString_locative (part), U")") |
| 1756 | ); |
| 1757 | } |
| 1758 | |
| 1759 | static void QUERY_DATA_FOR_REAL__getMinimumPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1760 | QUERY_DATA_FOR_REAL |
| 1761 | double tmin, tmax; |
| 1762 | const int part = makeQueriable (me, false, & tmin, & tmax); |
| 1763 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1764 | const kPitch_unit unit = my dynamic_instancePref_pitch_unit(); |
| 1765 | double result = Pitch_getMinimum (my d_pitch.get(), tmin, tmax, unit, true); |
| 1766 | result = Function_convertToNonlogarithmic (my d_pitch.get(), result, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1767 | QUERY_DATA_FOR_REAL_END (U" ", Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) unit, 0), |
| 1768 | U" (minimum pitch ", SoundAnalysisArea_partString_locative (part), U")"); |
| 1769 | } |
| 1770 | |
| 1771 | static void QUERY_DATA_FOR_REAL__getMaximumPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1772 | QUERY_DATA_FOR_REAL |
| 1773 | double tmin, tmax; |
| 1774 | const int part = makeQueriable (me, false, & tmin, & tmax); |
| 1775 | SoundAnalysisArea_haveVisiblePitch (me); // BUG |
| 1776 | const kPitch_unit unit = my dynamic_instancePref_pitch_unit(); |
| 1777 | double result = Pitch_getMaximum (my d_pitch.get(), tmin, tmax, unit, true); |
| 1778 | result = Function_convertToNonlogarithmic (my d_pitch.get(), result, Pitch_LEVEL_FREQUENCY, (int) unit); |
| 1779 | QUERY_DATA_FOR_REAL_END (U" ", Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) unit, 0), |
| 1780 | U" (maximum pitch ", SoundAnalysisArea_partString_locative (part), U")"); |
| 1781 | } |
| 1782 | |
| 1783 | static void menu_cb_moveCursorToMinimumPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1784 | VOID_EDITOR |
| 1785 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1786 | if (my startSelection() == my endSelection()) { |
| 1787 | Melder_throw (U"Empty selection."); |
| 1788 | } else { |
| 1789 | double time; |
| 1790 | Pitch_getMinimumAndTime (my d_pitch.get(), my startSelection(), my endSelection(), |
| 1791 | my dynamic_instancePref_pitch_unit(), 1, nullptr, & time); |
| 1792 | if (isundef (time)) |
| 1793 | Melder_throw (U"Selection is voiceless."); |
| 1794 | my setSelection (time, time); |
| 1795 | Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_selectionMarksChanged() |
| 1796 | FunctionEditor_selectionMarksChanged (my functionEditor()); |
| 1797 | } |
| 1798 | VOID_EDITOR_END |
| 1799 | } |
| 1800 | |
| 1801 | static void menu_cb_moveCursorToMaximumPitch (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1802 | VOID_EDITOR |
| 1803 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1804 | if (my startSelection() == my endSelection()) { |
| 1805 | Melder_throw (U"Empty selection."); |
| 1806 | } else { |
| 1807 | double time; |
| 1808 | Pitch_getMaximumAndTime (my d_pitch.get(), my startSelection(), my endSelection(), |
| 1809 | my dynamic_instancePref_pitch_unit(), 1, nullptr, & time); |
| 1810 | if (isundef (time)) |
| 1811 | Melder_throw (U"Selection is voiceless."); |
| 1812 | my setSelection (time, time); |
| 1813 | Melder_assert (isdefined (my startSelection())); // precondition of FunctionEditor_selectionMarksChanged() |
| 1814 | FunctionEditor_selectionMarksChanged (my functionEditor()); |
| 1815 | } |
| 1816 | VOID_EDITOR_END |
| 1817 | } |
| 1818 | |
| 1819 | static void CONVERT_DATA_TO_ONE__ExtractVisiblePitchContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1820 | CONVERT_DATA_TO_ONE |
| 1821 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1822 | autoPitch result = Data_copy (my d_pitch.get()); |
| 1823 | CONVERT_DATA_TO_ONE_END (U"untitled") |
| 1824 | } |
| 1825 | |
| 1826 | static void menu_cb_drawVisiblePitchContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1827 | EDITOR_FORM (U"Draw visible pitch contour", nullptr) |
| 1828 | my v_form_pictureWindow (cmd); |
| 1829 | COMMENT (U"Pitch:") |
| 1830 | BOOLEAN (speckle, U"Speckle", false) |
| 1831 | my v_form_pictureMargins (cmd); |
| 1832 | my v_form_pictureSelection (cmd); |
| 1833 | BOOLEAN (garnish, U"Garnish", true) |
| 1834 | EDITOR_OK |
| 1835 | my v_ok_pictureWindow (cmd); |
| 1836 | SET_BOOLEAN (speckle, my instancePref_pitch_picture_speckle()) |
| 1837 | my v_ok_pictureMargins (cmd); |
| 1838 | my v_ok_pictureSelection (cmd); |
| 1839 | SET_BOOLEAN (garnish, my instancePref_pitch_picture_garnish()) |
| 1840 | EDITOR_DO |
| 1841 | my v_do_pictureWindow (cmd); |
| 1842 | my setInstancePref_pitch_picture_speckle (speckle); |
| 1843 | my v_do_pictureMargins (cmd); |
| 1844 | my v_do_pictureSelection (cmd); |
| 1845 | my setInstancePref_pitch_picture_garnish (garnish); |
| 1846 | SoundAnalysisArea_haveVisiblePitch (me); |
| 1847 | DataGui_openPraatPicture (me); |
| 1848 | const kPitch_unit pitchUnit = my dynamic_instancePref_pitch_unit(); |
| 1849 | const double pitchFloor_hidden = Function_convertStandardToSpecialUnit (my d_pitch.get(), |
| 1850 | my dynamic_instancePref_pitch_floor(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 1851 | const double pitchCeiling_hidden = Function_convertStandardToSpecialUnit (my d_pitch.get(), |
| 1852 | my dynamic_instancePref_pitch_ceilingOrTop(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 1853 | const double pitchFloor_overt = Function_convertToNonlogarithmic (my d_pitch.get(), |
| 1854 | pitchFloor_hidden, Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 1855 | const double pitchCeiling_overt = Function_convertToNonlogarithmic (my d_pitch.get(), |
| 1856 | pitchCeiling_hidden, Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 1857 | const double pitchViewFrom = my dynamic_instancePref_pitch_viewFrom(), pitchViewTo = my dynamic_instancePref_pitch_viewTo(); |
| 1858 | const double pitchViewFrom_overt = ( pitchViewFrom < pitchViewTo ? pitchViewFrom : pitchFloor_overt ); |
| 1859 | const double pitchViewTo_overt = ( pitchViewFrom < pitchViewTo ? pitchViewTo : pitchCeiling_overt ); |
| 1860 | Pitch_draw (my d_pitch.get(), my pictureGraphics(), my startWindow(), my endWindow(), pitchViewFrom_overt, pitchViewTo_overt, |
| 1861 | garnish, speckle, pitchUnit); |
| 1862 | FunctionArea_garnishPicture (me); |
| 1863 | DataGui_closePraatPicture (me); |
| 1864 | EDITOR_END |
| 1865 | } |
| 1866 | |
| 1867 | |
| 1868 | #pragma mark - SoundAnalysisArea Intensity menu |
| 1869 | |
| 1870 | static void menu_cb_showIntensity (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1871 | VOID_EDITOR |
| 1872 | my setInstancePref_intensity_show (! my instancePref_intensity_show()); // toggle |
| 1873 | GuiMenuItem_check (my intensityToggle, my instancePref_intensity_show()); // in case we're called from a script |
| 1874 | FunctionEditor_redraw (my functionEditor()); |
| 1875 | VOID_EDITOR_END |
| 1876 | } |
| 1877 | |
| 1878 | static void menu_cb_intensitySettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1879 | EDITOR_FORM (U"Intensity settings", U"Intro 6.2. Configuring the intensity contour") |
| 1880 | REAL (viewFrom, U"left View range (dB)", my default_intensity_viewFrom ()) |
| 1881 | REAL (viewTo, U"right View range (dB)", my default_intensity_viewTo ()) |
| 1882 | CHOICE_ENUM (kSoundAnalysisArea_intensity_averagingMethod, averagingMethod, |
| 1883 | U"Averaging method", my default_intensity_averagingMethod ()) |
| 1884 | BOOLEAN (subtractMeanPressure, U"Subtract mean pressure", my default_intensity_subtractMeanPressure ()) |
| 1885 | COMMENT (U"Note: the pitch floor is taken from the pitch settings.") |
| 1886 | MUTABLE_COMMENT (note2, U"") |
| 1887 | EDITOR_OK |
| 1888 | SET_REAL (viewFrom, my instancePref_intensity_viewFrom()) |
| 1889 | SET_REAL (viewTo, my instancePref_intensity_viewTo()) |
| 1890 | SET_ENUM (averagingMethod, kSoundAnalysisArea_intensity_averagingMethod, my instancePref_intensity_averagingMethod()) |
| 1891 | SET_BOOLEAN (subtractMeanPressure, my instancePref_intensity_subtractMeanPressure()) |
| 1892 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy ()) { |
| 1893 | SET_STRING (note2, U"Warning: you have a non-standard \"time step strategy\".") |
| 1894 | } else { |
| 1895 | SET_STRING (note2, U"(your \"time step strategy\" has its standard value: automatic)") |
| 1896 | } |
| 1897 | EDITOR_DO |
| 1898 | Melder_require (viewTo > viewFrom, |
| 1899 | U"The ceiling of the view range should be greater than the floor."); |
| 1900 | my setInstancePref_intensity_viewFrom (viewFrom); |
| 1901 | my setInstancePref_intensity_viewTo (viewTo); |
| 1902 | my setInstancePref_intensity_averagingMethod (averagingMethod); |
| 1903 | my setInstancePref_intensity_subtractMeanPressure (subtractMeanPressure); |
| 1904 | my d_intensity. reset(); |
| 1905 | FunctionEditor_redraw (my functionEditor()); |
| 1906 | EDITOR_END |
| 1907 | } |
| 1908 | |
| 1909 | static void CONVERT_DATA_TO_ONE__ExtractVisibleIntensityContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1910 | CONVERT_DATA_TO_ONE |
| 1911 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1912 | autoIntensity result = Data_copy (my d_intensity.get()); |
| 1913 | CONVERT_DATA_TO_ONE_END (U"untitled") |
| 1914 | } |
| 1915 | |
| 1916 | static void menu_cb_drawVisibleIntensityContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1917 | EDITOR_FORM (U"Draw visible intensity contour", nullptr) |
| 1918 | my v_form_pictureWindow (cmd); |
| 1919 | my v_form_pictureMargins (cmd); |
| 1920 | my v_form_pictureSelection (cmd); |
| 1921 | BOOLEAN (garnish, U"Garnish", true) |
| 1922 | EDITOR_OK |
| 1923 | my v_ok_pictureWindow (cmd); |
| 1924 | my v_ok_pictureMargins (cmd); |
| 1925 | my v_ok_pictureSelection (cmd); |
| 1926 | SET_BOOLEAN (garnish, my instancePref_intensity_picture_garnish()) |
| 1927 | EDITOR_DO |
| 1928 | my v_do_pictureWindow (cmd); |
| 1929 | my v_do_pictureMargins (cmd); |
| 1930 | my v_do_pictureSelection (cmd); |
| 1931 | my setInstancePref_intensity_picture_garnish (garnish); |
| 1932 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1933 | DataGui_openPraatPicture (me); |
| 1934 | Intensity_draw (my d_intensity.get(), my pictureGraphics(), my startWindow(), my endWindow(), |
| 1935 | my instancePref_intensity_viewFrom(), my instancePref_intensity_viewTo(), garnish); |
| 1936 | FunctionArea_garnishPicture (me); |
| 1937 | DataGui_closePraatPicture (me); |
| 1938 | EDITOR_END |
| 1939 | } |
| 1940 | |
| 1941 | static void INFO_DATA__intensityListing (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1942 | INFO_DATA |
| 1943 | double tmin, tmax; |
| 1944 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 1945 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1946 | MelderInfo_open (); |
| 1947 | MelderInfo_writeLine (U"Time_s Intensity_dB"); |
| 1948 | if (part == SoundAnalysisArea_PART_CURSOR) { |
| 1949 | const double intensity = Vector_getValueAtX (my d_intensity.get(), tmin, Vector_CHANNEL_1, kVector_valueInterpolation :: LINEAR); |
| 1950 | MelderInfo_writeLine (Melder_fixed (tmin, 6), U" ", Melder_fixed (intensity, 6)); |
| 1951 | } else { |
| 1952 | integer i, i1, i2; |
| 1953 | Sampled_getWindowSamples (my d_intensity.get(), tmin, tmax, & i1, & i2); |
| 1954 | for (i = i1; i <= i2; i ++) { |
| 1955 | const double time = Sampled_indexToX (my d_intensity.get(), i); |
| 1956 | const double intensity = Vector_getValueAtX (my d_intensity.get(), time, Vector_CHANNEL_1, kVector_valueInterpolation :: NEAREST); |
| 1957 | MelderInfo_writeLine (Melder_fixed (time, 6), U" ", Melder_fixed (intensity, 6)); |
| 1958 | } |
| 1959 | } |
| 1960 | MelderInfo_close (); |
| 1961 | INFO_DATA_END |
| 1962 | } |
| 1963 | |
| 1964 | static void QUERY_DATA_FOR_REAL__getIntensity (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1965 | QUERY_DATA_FOR_REAL |
| 1966 | double tmin, tmax; |
| 1967 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 1968 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1969 | const double result = ( part == SoundAnalysisArea_PART_CURSOR |
| 1970 | ? Vector_getValueAtX (my d_intensity.get(), tmin, Vector_CHANNEL_1, kVector_valueInterpolation :: LINEAR) |
| 1971 | : Intensity_getAverage (my d_intensity.get(), tmin, tmax, (int) my instancePref_intensity_averagingMethod()) |
| 1972 | ); |
| 1973 | static const conststring32 methodString [] = { U"median", U"mean-energy", U"mean-sones", U"mean-dB" }; |
| 1974 | QUERY_DATA_FOR_REAL_END (part == SoundAnalysisArea_PART_CURSOR |
| 1975 | ? U" dB (intensity at CURSOR)" |
| 1976 | : Melder_cat (U" dB (", methodString [(int) my instancePref_intensity_averagingMethod()], U" intensity ", |
| 1977 | SoundAnalysisArea_partString_locative (part), U")") |
| 1978 | ); |
| 1979 | } |
| 1980 | |
| 1981 | static void QUERY_DATA_FOR_REAL__getMinimumIntensity (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1982 | QUERY_DATA_FOR_REAL |
| 1983 | double tmin, tmax; |
| 1984 | const int part = makeQueriable (me, false, & tmin, & tmax); |
| 1985 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1986 | const double result = Vector_getMinimum (my d_intensity.get(), tmin, tmax, kVector_peakInterpolation :: PARABOLIC); |
| 1987 | QUERY_DATA_FOR_REAL_END (U" dB (minimum intensity ", SoundAnalysisArea_partString_locative (part), U")"); |
| 1988 | } |
| 1989 | |
| 1990 | static void QUERY_DATA_FOR_REAL__getMaximumIntensity (SoundAnalysisArea me, EDITOR_ARGS) { |
| 1991 | QUERY_DATA_FOR_REAL |
| 1992 | double tmin, tmax; |
| 1993 | const int part = makeQueriable (me, false, & tmin, & tmax); |
| 1994 | SoundAnalysisArea_haveVisibleIntensity (me); |
| 1995 | const double result = Vector_getMaximum (my d_intensity.get(), tmin, tmax, kVector_peakInterpolation :: PARABOLIC); |
| 1996 | QUERY_DATA_FOR_REAL_END (U" dB (maximum intensity ", SoundAnalysisArea_partString_locative (part), U")"); |
| 1997 | } |
| 1998 | |
| 1999 | |
| 2000 | #pragma mark - SoundAnalysisArea Formants menu |
| 2001 | |
| 2002 | static void menu_cb_showFormants (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2003 | VOID_EDITOR |
| 2004 | my setInstancePref_formant_show (! my instancePref_formant_show()); // toggle |
| 2005 | GuiMenuItem_check (my formantToggle, my instancePref_formant_show()); // in case we're called from a script |
| 2006 | FunctionEditor_redraw (my functionEditor()); |
| 2007 | VOID_EDITOR_END |
| 2008 | } |
| 2009 | |
| 2010 | static void menu_cb_formantSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2011 | EDITOR_FORM (U"Formant settings", U"Intro 5.2. Configuring the formant contours") |
| 2012 | POSITIVE (formantCeiling, U"Formant ceiling (Hz)", my default_formant_ceiling ()) |
| 2013 | POSITIVE (numberOfFormants, U"Number of formants", my default_formant_numberOfFormants ()) |
| 2014 | POSITIVE (windowLength, U"Window length (s)", my default_formant_windowLength ()) |
| 2015 | REAL (dynamicRange, U"Dynamic range (dB)", my default_formant_dynamicRange ()) |
| 2016 | POSITIVE (dotSize, U"Dot size (mm)", my default_formant_dotSize ()) |
| 2017 | MUTABLE_COMMENT (note1, U"") |
| 2018 | MUTABLE_COMMENT (note2, U"") |
| 2019 | EDITOR_OK |
| 2020 | SET_REAL (formantCeiling, my instancePref_formant_ceiling()) |
| 2021 | SET_REAL (numberOfFormants, my instancePref_formant_numberOfFormants()) |
| 2022 | SET_REAL (windowLength, my instancePref_formant_windowLength()) |
| 2023 | SET_REAL (dynamicRange, my instancePref_formant_dynamicRange()) |
| 2024 | SET_REAL (dotSize, my instancePref_formant_dotSize()) |
| 2025 | if (my instancePref_formant_method() != my default_formant_method () || my instancePref_formant_preemphasisFrom() != Melder_atof (my default_formant_preemphasisFrom())) { |
| 2026 | SET_STRING (note1, U"Warning: you have non-standard \"advanced settings\".") |
| 2027 | } else { |
| 2028 | SET_STRING (note1, U"(all of your \"advanced settings\" have their standard values)") |
| 2029 | } |
| 2030 | if (my instancePref_timeStepStrategy() != my default_timeStepStrategy()) { |
| 2031 | SET_STRING (note2, U"Warning: you have a non-standard \"time step strategy\".") |
| 2032 | } else { |
| 2033 | SET_STRING (note2, U"(your \"time step strategy\" has its standard value: automatic)") |
| 2034 | } |
| 2035 | EDITOR_DO |
| 2036 | my setInstancePref_formant_ceiling (formantCeiling); |
| 2037 | my setInstancePref_formant_numberOfFormants (numberOfFormants); |
| 2038 | my setInstancePref_formant_windowLength (windowLength); |
| 2039 | my setInstancePref_formant_dynamicRange (dynamicRange); |
| 2040 | my setInstancePref_formant_dotSize (dotSize); |
| 2041 | my d_formant. reset(); |
| 2042 | FunctionEditor_redraw (my functionEditor()); |
| 2043 | EDITOR_END |
| 2044 | } |
| 2045 | |
| 2046 | static void menu_cb_advancedFormantSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2047 | EDITOR_FORM (U"Advanced formant settings", U"Advanced formant settings...") |
| 2048 | CHOICE_ENUM (kSoundAnalysisArea_formant_analysisMethod, method, |
| 2049 | U"Method", my default_formant_method ()) |
| 2050 | POSITIVE (preemphasisFrom, U"Pre-emphasis from (Hz)", my default_formant_preemphasisFrom ()) |
| 2051 | EDITOR_OK |
| 2052 | SET_ENUM (method, kSoundAnalysisArea_formant_analysisMethod, my instancePref_formant_method()) |
| 2053 | SET_REAL (preemphasisFrom, my instancePref_formant_preemphasisFrom()) |
| 2054 | EDITOR_DO |
| 2055 | my setInstancePref_formant_method (method); |
| 2056 | my setInstancePref_formant_preemphasisFrom (preemphasisFrom); |
| 2057 | my d_formant. reset(); |
| 2058 | FunctionEditor_redraw (my functionEditor()); |
| 2059 | EDITOR_END |
| 2060 | } |
| 2061 | |
| 2062 | static void CONVERT_DATA_TO_ONE__ExtractVisibleFormantContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2063 | CONVERT_DATA_TO_ONE |
| 2064 | SoundAnalysisArea_haveVisibleFormants (me); |
| 2065 | autoFormant result = Data_copy (my d_formant.get()); |
| 2066 | CONVERT_DATA_TO_ONE_END (U"untitled") |
| 2067 | } |
| 2068 | |
| 2069 | static void menu_cb_drawVisibleFormantContour (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2070 | EDITOR_FORM (U"Draw visible formant contour", nullptr) |
| 2071 | my v_form_pictureWindow (cmd); |
| 2072 | my v_form_pictureMargins (cmd); |
| 2073 | my v_form_pictureSelection (cmd); |
| 2074 | BOOLEAN (garnish, U"Garnish", true) |
| 2075 | EDITOR_OK |
| 2076 | my v_ok_pictureWindow (cmd); |
| 2077 | my v_ok_pictureMargins (cmd); |
| 2078 | my v_ok_pictureSelection (cmd); |
| 2079 | SET_BOOLEAN (garnish, my instancePref_formant_picture_garnish()) |
| 2080 | EDITOR_DO |
| 2081 | my v_do_pictureWindow (cmd); |
| 2082 | my v_do_pictureMargins (cmd); |
| 2083 | my v_do_pictureSelection (cmd); |
| 2084 | my setInstancePref_formant_picture_garnish (garnish); |
| 2085 | SoundAnalysisArea_haveVisibleFormants (me); |
| 2086 | DataGui_openPraatPicture (me); |
| 2087 | Formant_drawSpeckles (my d_formant.get(), my pictureGraphics(), my startWindow(), my endWindow(), |
| 2088 | my instancePref_spectrogram_viewTo(), my instancePref_formant_dynamicRange(), |
| 2089 | garnish |
| 2090 | ); |
| 2091 | FunctionArea_garnishPicture (me); |
| 2092 | DataGui_closePraatPicture (me); |
| 2093 | EDITOR_END |
| 2094 | } |
| 2095 | |
| 2096 | static void INFO_DATA__formantListing (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2097 | INFO_DATA |
| 2098 | double tmin, tmax; |
| 2099 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 2100 | SoundAnalysisArea_haveVisibleFormants (me); |
| 2101 | MelderInfo_open (); |
| 2102 | MelderInfo_writeLine (U"Time_s F1_Hz F2_Hz F3_Hz F4_Hz"); |
| 2103 | if (part == SoundAnalysisArea_PART_CURSOR) { |
| 2104 | const double f1 = Formant_getValueAtTime (my d_formant.get(), 1, tmin, kFormant_unit::HERTZ); |
| 2105 | const double f2 = Formant_getValueAtTime (my d_formant.get(), 2, tmin, kFormant_unit::HERTZ); |
| 2106 | const double f3 = Formant_getValueAtTime (my d_formant.get(), 3, tmin, kFormant_unit::HERTZ); |
| 2107 | const double f4 = Formant_getValueAtTime (my d_formant.get(), 4, tmin, kFormant_unit::HERTZ); |
| 2108 | MelderInfo_writeLine (Melder_fixed (tmin, 6), U" ", Melder_fixed (f1, 6), U" ", Melder_fixed (f2, 6), U" ", Melder_fixed (f3, 6), U" ", Melder_fixed (f4, 6)); |
| 2109 | } else { |
| 2110 | integer i1, i2; |
| 2111 | Sampled_getWindowSamples (my d_formant.get(), tmin, tmax, & i1, & i2); |
| 2112 | for (integer i = i1; i <= i2; i ++) { |
| 2113 | const double t = Sampled_indexToX (my d_formant.get(), i); |
| 2114 | const double f1 = Formant_getValueAtTime (my d_formant.get(), 1, t, kFormant_unit::HERTZ); |
| 2115 | const double f2 = Formant_getValueAtTime (my d_formant.get(), 2, t, kFormant_unit::HERTZ); |
| 2116 | const double f3 = Formant_getValueAtTime (my d_formant.get(), 3, t, kFormant_unit::HERTZ); |
| 2117 | const double f4 = Formant_getValueAtTime (my d_formant.get(), 4, t, kFormant_unit::HERTZ); |
| 2118 | MelderInfo_writeLine (Melder_fixed (t, 6), U" ", Melder_fixed (f1, 6), U" ", Melder_fixed (f2, 6), U" ", Melder_fixed (f3, 6), U" ", Melder_fixed (f4, 6)); |
| 2119 | } |
| 2120 | } |
| 2121 | MelderInfo_close (); |
| 2122 | INFO_DATA_END |
| 2123 | } |
| 2124 | |
| 2125 | static void do_getFormant (SoundAnalysisArea me, integer iformant, Interpreter optionalInterpreter) { |
| 2126 | QUERY_DATA_FOR_REAL |
| 2127 | double tmin, tmax; |
| 2128 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 2129 | SoundAnalysisArea_haveVisibleFormants (me); |
| 2130 | const double result = ( part == SoundAnalysisArea_PART_CURSOR |
| 2131 | ? Formant_getValueAtTime (my d_formant.get(), iformant, tmin, kFormant_unit::HERTZ) |
| 2132 | : Formant_getMean (my d_formant.get(), iformant, tmin, tmax, kFormant_unit::HERTZ) |
| 2133 | ); |
| 2134 | QUERY_DATA_FOR_REAL_END (part == SoundAnalysisArea_PART_CURSOR |
| 2135 | ? Melder_cat (U" Hz (nearest F", iformant, U" to CURSOR)") |
| 2136 | : Melder_cat (U" Hz (mean F", iformant, U" ", SoundAnalysisArea_partString_locative (part), U")") |
| 2137 | ) |
| 2138 | } |
| 2139 | static void do_getBandwidth (SoundAnalysisArea me, integer iformant, Interpreter optionalInterpreter) { |
| 2140 | QUERY_DATA_FOR_REAL |
| 2141 | double tmin, tmax; |
| 2142 | const int part = makeQueriable (me, true, & tmin, & tmax); |
| 2143 | SoundAnalysisArea_haveVisibleFormants (me); |
| 2144 | const double result = ( part == SoundAnalysisArea_PART_CURSOR |
| 2145 | ? Formant_getBandwidthAtTime (my d_formant.get(), iformant, tmin, kFormant_unit::HERTZ) |
| 2146 | : Formant_getBandwidthAtTime (my d_formant.get(), iformant, 0.5 * (tmin + tmax), kFormant_unit::HERTZ) |
| 2147 | ); |
| 2148 | QUERY_DATA_FOR_REAL_END (part == SoundAnalysisArea_PART_CURSOR |
| 2149 | ? Melder_cat (U" Hz (nearest B", iformant, U" to CURSOR)") |
| 2150 | : Melder_cat ( U" Hz (B", iformant, U" in centre of ", SoundAnalysisArea_partString (part), U")") |
| 2151 | ) |
| 2152 | } |
| 2153 | static void QUERY_DATA_FOR_REAL__getFirstFormant (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2154 | do_getFormant (me, 1, optionalInterpreter); |
| 2155 | } |
| 2156 | static void QUERY_DATA_FOR_REAL__getFirstBandwidth (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2157 | do_getBandwidth (me, 1, optionalInterpreter); |
| 2158 | } |
| 2159 | static void QUERY_DATA_FOR_REAL__getSecondFormant (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2160 | do_getFormant (me, 2, optionalInterpreter); |
| 2161 | } |
| 2162 | static void QUERY_DATA_FOR_REAL__getSecondBandwidth (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2163 | do_getBandwidth (me, 2, optionalInterpreter); |
| 2164 | } |
| 2165 | static void QUERY_DATA_FOR_REAL__getThirdFormant (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2166 | do_getFormant (me, 3, optionalInterpreter); |
| 2167 | } |
| 2168 | static void QUERY_DATA_FOR_REAL__getThirdBandwidth (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2169 | do_getBandwidth (me, 3, optionalInterpreter); |
| 2170 | } |
| 2171 | static void QUERY_DATA_FOR_REAL__getFourthFormant (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2172 | do_getFormant (me, 4, optionalInterpreter); |
| 2173 | } |
| 2174 | static void QUERY_DATA_FOR_REAL__getFourthBandwidth (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2175 | do_getBandwidth (me, 4, optionalInterpreter); |
| 2176 | } |
| 2177 | |
| 2178 | static void QUERY_DATA_FOR_REAL__getFormant (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2179 | EDITOR_FORM (U"Get formant", nullptr) |
| 2180 | NATURAL (formantNumber, U"Formant number", U"5") |
| 2181 | EDITOR_OK |
| 2182 | EDITOR_DO |
| 2183 | do_getFormant (me, formantNumber, optionalInterpreter); |
| 2184 | EDITOR_END |
| 2185 | } |
| 2186 | |
| 2187 | static void QUERY_DATA_FOR_REAL__getBandwidth (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2188 | EDITOR_FORM (U"Get bandwidth", nullptr) |
| 2189 | NATURAL (formantNumber, U"Formant number", U"5") |
| 2190 | EDITOR_OK |
| 2191 | EDITOR_DO |
| 2192 | do_getBandwidth (me, formantNumber, optionalInterpreter); |
| 2193 | EDITOR_END |
| 2194 | } |
| 2195 | |
| 2196 | |
| 2197 | #pragma mark - SoundAnalysisArea Pulses menu |
| 2198 | |
| 2199 | static void menu_cb_showPulses (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2200 | VOID_EDITOR |
| 2201 | my setInstancePref_pulses_show (! my instancePref_pulses_show()); // toggle |
| 2202 | GuiMenuItem_check (my pulsesToggle, my instancePref_pulses_show()); // in case we're called from a script |
| 2203 | FunctionEditor_redraw (my functionEditor()); |
| 2204 | VOID_EDITOR_END |
| 2205 | } |
| 2206 | |
| 2207 | static void menu_cb_advancedPulsesSettings (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2208 | EDITOR_FORM (U"Advanced pulses settings", U"Advanced pulses settings...") |
| 2209 | POSITIVE (maximumPeriodFactor, U"Maximum period factor", my default_pulses_maximumPeriodFactor ()) |
| 2210 | POSITIVE (maximumAmplitudeFactor, U"Maximum amplitude factor", my default_pulses_maximumAmplitudeFactor ()) |
| 2211 | EDITOR_OK |
| 2212 | SET_REAL (maximumPeriodFactor, my instancePref_pulses_maximumPeriodFactor()) |
| 2213 | SET_REAL (maximumAmplitudeFactor, my instancePref_pulses_maximumAmplitudeFactor()) |
| 2214 | EDITOR_DO |
| 2215 | my setInstancePref_pulses_maximumPeriodFactor (maximumPeriodFactor); |
| 2216 | my setInstancePref_pulses_maximumAmplitudeFactor (maximumAmplitudeFactor); |
| 2217 | my d_pulses. reset(); |
| 2218 | FunctionEditor_redraw (my functionEditor()); |
| 2219 | EDITOR_END |
| 2220 | } |
| 2221 | |
| 2222 | static void CONVERT_DATA_TO_ONE__ExtractVisiblePulses (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2223 | CONVERT_DATA_TO_ONE |
| 2224 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2225 | autoPointProcess result = Data_copy (my d_pulses.get()); |
| 2226 | CONVERT_DATA_TO_ONE_END (U"untitled") |
| 2227 | } |
| 2228 | |
| 2229 | static void menu_cb_drawVisiblePulses (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2230 | EDITOR_FORM (U"Draw visible pulses", nullptr) |
| 2231 | my v_form_pictureWindow (cmd); |
| 2232 | my v_form_pictureMargins (cmd); |
| 2233 | my v_form_pictureSelection (cmd); |
| 2234 | BOOLEAN (garnish, U"Garnish", true) |
| 2235 | EDITOR_OK |
| 2236 | my v_ok_pictureWindow (cmd); |
| 2237 | my v_ok_pictureMargins (cmd); |
| 2238 | my v_ok_pictureSelection (cmd); |
| 2239 | SET_BOOLEAN (garnish, my instancePref_pulses_picture_garnish()) |
| 2240 | EDITOR_DO |
| 2241 | my v_do_pictureWindow (cmd); |
| 2242 | my v_do_pictureMargins (cmd); |
| 2243 | my v_do_pictureSelection (cmd); |
| 2244 | my setInstancePref_pulses_picture_garnish (garnish); |
| 2245 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2246 | DataGui_openPraatPicture (me); |
| 2247 | PointProcess_draw (my d_pulses.get(), my pictureGraphics(), my startWindow(), my endWindow(), garnish); |
| 2248 | FunctionArea_garnishPicture (me); |
| 2249 | DataGui_closePraatPicture (me); |
| 2250 | EDITOR_END |
| 2251 | } |
| 2252 | |
| 2253 | static void INFO_DATA__voiceReport (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2254 | INFO_DATA |
| 2255 | time_t today = time (nullptr); |
| 2256 | double tmin, tmax; |
| 2257 | const int part = makeQueriable (me, false, & tmin, & tmax); |
| 2258 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2259 | autoSound sound = extractSoundOrNull (me, tmin, tmax); |
| 2260 | if (! sound) |
| 2261 | return; |
| 2262 | MelderInfo_open (); |
| 2263 | MelderInfo_writeLine (U"-- Voice report for ", my name.get(), U" --\nDate: ", Melder_peek8to32_u (ctime (& today))); |
| 2264 | if (my instancePref_pitch_method() != kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION) { |
| 2265 | if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION) |
| 2266 | MelderInfo_writeLine (U"WARNING: some of the following measurements may be imprecise.\n" |
| 2267 | "For more precision, go to “Pitch settings” and choose\n" |
| 2268 | "the raw cross-correlation analysis method to optimize for voice research.\n" |
| 2269 | ); |
| 2270 | else |
| 2271 | MelderInfo_writeLine (U"WARNING: several of the following measurements, especially those on harmonicity, will be incorrect,\n" |
| 2272 | "because they are based on a sound from which higher frequencies have been filtered out.\n" |
| 2273 | "For more correctness, go to “Pitch settings” and choose\n" |
| 2274 | "the raw cross-correlation analysis method to optimize for voice research.\n" |
| 2275 | ); |
| 2276 | } |
| 2277 | MelderInfo_writeLine (U"Time range of ", SoundAnalysisArea_partString (part)); |
| 2278 | Sound_Pitch_PointProcess_voiceReport (sound.get(), my d_pitch.get(), my d_pulses.get(), tmin, tmax, |
| 2279 | my dynamic_instancePref_pitch_floor(), my dynamic_instancePref_pitch_ceilingOrTop(), |
| 2280 | my instancePref_pulses_maximumPeriodFactor(), my instancePref_pulses_maximumAmplitudeFactor(), |
| 2281 | my dynamic_instancePref_pitch_silenceThreshold(), my dynamic_instancePref_pitch_voicingThreshold() |
| 2282 | ); |
| 2283 | if (my instancePref_pitch_method() != kSoundAnalysisArea_pitch_analysisMethod::RAW_CROSS_CORRELATION) { |
| 2284 | if (my instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod::RAW_AUTOCORRELATION) |
| 2285 | MelderInfo_writeLine (U"\nWARNING: some of the above measurements may be imprecise.\n" |
| 2286 | "For more precision, go to “Pitch settings” and choose\n" |
| 2287 | "the raw cross-correlation analysis method to optimize for voice research.\n" |
| 2288 | ); |
| 2289 | else |
| 2290 | MelderInfo_writeLine (U"WARNING: several of the above measurements, especially those on harmonicity, will be incorrect,\n" |
| 2291 | "because they are based on a sound from which higher frequencies have been filtered out.\n" |
| 2292 | "For more correctness, go to “Pitch settings” and choose\n" |
| 2293 | "the raw cross-correlation analysis method to optimize for voice research.\n" |
| 2294 | ); |
| 2295 | } |
| 2296 | MelderInfo_close (); |
| 2297 | INFO_DATA_END |
| 2298 | } |
| 2299 | |
| 2300 | static void INFO_DATA__pulseListing (SoundAnalysisArea me, EDITOR_ARGS) { |
| 2301 | INFO_DATA |
| 2302 | double tmin, tmax; |
| 2303 | makeQueriable (me, false, & tmin, & tmax); |
| 2304 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2305 | MelderInfo_open (); |
| 2306 | MelderInfo_writeLine (U"Time_s"); |
| 2307 | const integer i1 = PointProcess_getHighIndex (my d_pulses.get(), tmin); |
| 2308 | const integer i2 = PointProcess_getLowIndex (my d_pulses.get(), tmax); |
| 2309 | for (integer i = i1; i <= i2; i ++) { |
| 2310 | const double t = my d_pulses -> t [i]; |
| 2311 | MelderInfo_writeLine (Melder_fixed (t, 12)); |
| 2312 | } |
| 2313 | MelderInfo_close (); |
| 2314 | INFO_DATA_END |
| 2315 | } |
| 2316 | |
| 2317 | /* |
| 2318 | static void cb_getJitter_xx (SoundAnalysisArea me, double (*PointProcess_getJitter_xx) (PointProcess, double, double, double, double, double)) { |
| 2319 | const double minimumPeriod = 0.8 / my p_pitch_ceiling, maximumPeriod = 1.25 / my p_pitch_floor; |
| 2320 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2321 | if (my startSelection() == my endSelection()) |
| 2322 | Melder_throw (U"Make a selection first."); |
| 2323 | makeQueriable |
| 2324 | Melder_informationReal (PointProcess_getJitter_xx (my d_pulses, my startSelection(), my endSelection(), |
| 2325 | minimumPeriod, maximumPeriod, my p_pulses_maximumPeriodFactor), nullptr); |
| 2326 | } |
| 2327 | DIRECT (SoundAnalysisArea, cb_getJitter_local) { cb_getJitter_xx (me, PointProcess_getJitter_local); END } |
| 2328 | DIRECT (SoundAnalysisArea, cb_getJitter_local_absolute) { cb_getJitter_xx (me, PointProcess_getJitter_local_absolute); END } |
| 2329 | DIRECT (SoundAnalysisArea, cb_getJitter_rap) { cb_getJitter_xx (me, PointProcess_getJitter_rap); END } |
| 2330 | DIRECT (SoundAnalysisArea, cb_getJitter_ppq5) { cb_getJitter_xx (me, PointProcess_getJitter_ppq5); END } |
| 2331 | DIRECT (SoundAnalysisArea, cb_getJitter_ddp) { cb_getJitter_xx (me, PointProcess_getJitter_ddp); END } |
| 2332 | |
| 2333 | static void cb_getShimmer_xx (SoundAnalysisArea me, double (*PointProcess_Sound_getShimmer_xx) (PointProcess, Sound, double, double, double, double, double)) { |
| 2334 | const double minimumPeriod = 0.8 / my p_pitch_ceiling, maximumPeriod = 1.25 / my p_pitch_floor; |
| 2335 | SoundAnalysisArea_haveVisiblePulses (me); |
| 2336 | if (my startSelection() == my endSelection()) |
| 2337 | Melder_throw (U"Make a selection first."); |
| 2338 | makeQueriable |
| 2339 | autoSound sound = extractSound (me, my startSelection(), my endSelection()); |
| 2340 | Melder_informationReal (PointProcess_Sound_getShimmer_xx (my d_pulses, sound, my startSelection(), my endSelection(), |
| 2341 | minimumPeriod, maximumPeriod, my p_pulses_maximumAmplitudeFactor), nullptr); |
| 2342 | } |
| 2343 | DIRECT (SoundAnalysisArea, cb_getShimmer_local) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_local); END } |
| 2344 | DIRECT (SoundAnalysisArea, cb_getShimmer_local_dB) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_local_dB); END } |
| 2345 | DIRECT (SoundAnalysisArea, cb_getShimmer_apq3) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_apq3); END } |
| 2346 | DIRECT (SoundAnalysisArea, cb_getShimmer_apq5) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_apq5); END } |
| 2347 | DIRECT (SoundAnalysisArea, cb_getShimmer_apq11) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_apq11); END } |
| 2348 | DIRECT (SoundAnalysisArea, cb_getShimmer_dda) { cb_getShimmer_xx (me, PointProcess_Sound_getShimmer_dda); END } |
| 2349 | */ |
| 2350 | |
| 2351 | |
| 2352 | #pragma mark - SoundAnalysisArea All menus |
| 2353 | |
| 2354 | void structSoundAnalysisArea :: v_createMenuItems_formant (EditorMenu menu) { |
| 2355 | our formantToggle = FunctionAreaMenu_addCommand (menu, U"Show formants", |
| 2356 | GuiMenu_CHECKBUTTON | (instancePref_formant_show() ? GuiMenu_TOGGLE_ON : 0), |
| 2357 | menu_cb_showFormants, this |
| 2358 | ); |
| 2359 | FunctionAreaMenu_addCommand (menu, U"Formant settings...", |
| 2360 | 0, menu_cb_formantSettings, this); |
| 2361 | FunctionAreaMenu_addCommand (menu, U"Advanced formant settings...", |
| 2362 | 0, menu_cb_advancedFormantSettings, this); |
| 2363 | |
| 2364 | FunctionAreaMenu_addCommand (menu, U"- Query formants:", 0, nullptr, this); |
| 2365 | FunctionAreaMenu_addCommand (menu, U"Formant listing", GuiMenu_F1 | GuiMenu_COMMAND | GuiMenu_DEPTH_1, |
| 2366 | INFO_DATA__formantListing, this); |
| 2367 | FunctionAreaMenu_addCommand (menu, U"Get first formant", GuiMenu_F1 | GuiMenu_DEPTH_1, |
| 2368 | QUERY_DATA_FOR_REAL__getFirstFormant, this); |
| 2369 | FunctionAreaMenu_addCommand (menu, U"Get first bandwidth", 1, |
| 2370 | QUERY_DATA_FOR_REAL__getFirstBandwidth, this); |
| 2371 | FunctionAreaMenu_addCommand (menu, U"Get second formant", GuiMenu_F2 | GuiMenu_DEPTH_1, |
| 2372 | QUERY_DATA_FOR_REAL__getSecondFormant, this); |
| 2373 | FunctionAreaMenu_addCommand (menu, U"Get second bandwidth", 1, |
| 2374 | QUERY_DATA_FOR_REAL__getSecondBandwidth, this); |
| 2375 | FunctionAreaMenu_addCommand (menu, U"Get third formant", GuiMenu_F3 | GuiMenu_DEPTH_1, |
| 2376 | QUERY_DATA_FOR_REAL__getThirdFormant, this); |
| 2377 | FunctionAreaMenu_addCommand (menu, U"Get third bandwidth", 1, |
| 2378 | QUERY_DATA_FOR_REAL__getThirdBandwidth, this); |
| 2379 | FunctionAreaMenu_addCommand (menu, U"Get fourth formant", GuiMenu_F4 | GuiMenu_DEPTH_1, |
| 2380 | QUERY_DATA_FOR_REAL__getFourthFormant, this); |
| 2381 | FunctionAreaMenu_addCommand (menu, U"Get fourth bandwidth", 1, |
| 2382 | QUERY_DATA_FOR_REAL__getFourthBandwidth, this); |
| 2383 | FunctionAreaMenu_addCommand (menu, U"Get formant...", 1, |
| 2384 | QUERY_DATA_FOR_REAL__getFormant, this); |
| 2385 | FunctionAreaMenu_addCommand (menu, U"Get bandwidth...", 1, |
| 2386 | QUERY_DATA_FOR_REAL__getBandwidth, this); |
| 2387 | |
| 2388 | FunctionAreaMenu_addCommand (menu, U"- Draw formants to picture window:", 0, nullptr, this); |
| 2389 | FunctionAreaMenu_addCommand (menu, U"Draw visible formant contour...", 1, |
| 2390 | menu_cb_drawVisibleFormantContour, this); |
| 2391 | |
| 2392 | FunctionAreaMenu_addCommand (menu, U"- Extract formants to objects window:", 0, nullptr, this); |
| 2393 | FunctionAreaMenu_addCommand (menu, U"Extract visible formant contour", 1, |
| 2394 | CONVERT_DATA_TO_ONE__ExtractVisibleFormantContour, this); |
| 2395 | } |
| 2396 | |
| 2397 | void structSoundAnalysisArea :: v_createMenus () { |
| 2398 | if (our v_hasSpectrogram () && our v_hasPitch () && our v_hasIntensity () && our v_hasPulses ()) { |
| 2399 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Analyses", 0); |
| 2400 | FunctionAreaMenu_addCommand (menu, U"Show analyses...", 0, menu_cb_showAnalyses, this); |
| 2401 | FunctionAreaMenu_addCommand (menu, U"Time step settings...", 0, menu_cb_timeStepSettings, this); |
| 2402 | FunctionAreaMenu_addCommand (menu, U"-- query log --", 0, nullptr, this); |
| 2403 | FunctionAreaMenu_addCommand (menu, U"Log settings...", 0, menu_cb_logSettings, this); |
| 2404 | FunctionAreaMenu_addCommand (menu, U"Delete log file 1", 0, menu_cb_deleteLogFile1, this); |
| 2405 | FunctionAreaMenu_addCommand (menu, U"Delete log file 2", 0, menu_cb_deleteLogFile2, this); |
| 2406 | FunctionAreaMenu_addCommand (menu, U"Log 1", GuiMenu_F12, menu_cb_log1, this); |
| 2407 | FunctionAreaMenu_addCommand (menu, U"Log 2", GuiMenu_F12 | GuiMenu_SHIFT, menu_cb_log2, this); |
| 2408 | FunctionAreaMenu_addCommand (menu, U"Log script 3 (...)", GuiMenu_F12 | GuiMenu_OPTION, menu_cb_logScript3, this); |
| 2409 | FunctionAreaMenu_addCommand (menu, U"Log script 4 (...)", GuiMenu_F12 | GuiMenu_COMMAND, menu_cb_logScript4, this); |
| 2410 | } |
| 2411 | |
| 2412 | if (our v_hasSpectrogram ()) { |
| 2413 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Spectrogram", 0); |
| 2414 | our spectrogramToggle = FunctionAreaMenu_addCommand (menu, U"Show spectrogram", |
| 2415 | GuiMenu_CHECKBUTTON | (instancePref_spectrogram_show() ? GuiMenu_TOGGLE_ON : 0), |
| 2416 | menu_cb_showSpectrogram, this |
| 2417 | ); |
| 2418 | FunctionAreaMenu_addCommand (menu, U"Spectrogram settings...", 0, |
| 2419 | menu_cb_spectrogramSettings, this); |
| 2420 | FunctionAreaMenu_addCommand (menu, U"Spectrogram colour settings...", 0, |
| 2421 | menu_cb_spectrogramColourSettings, this); |
| 2422 | FunctionAreaMenu_addCommand (menu, U"Advanced spectrogram settings...", 0, |
| 2423 | menu_cb_advancedSpectrogramSettings, this); |
| 2424 | FunctionAreaMenu_addCommand (menu, U"- Query spectrogram:", 0, nullptr, this); |
| 2425 | FunctionAreaMenu_addCommand (menu, U"Get frequency at frequency cursor", 1, |
| 2426 | QUERY_EDITOR_FOR_REAL__getFrequency, this); |
| 2427 | FunctionAreaMenu_addCommand (menu, U"Get spectral power at cursor cross", GuiMenu_F7 | GuiMenu_DEPTH_1, |
| 2428 | QUERY_DATA_FOR_REAL__getSpectralPowerAtCursorCross, this); |
| 2429 | FunctionAreaMenu_addCommand (menu, U"- Select frequency:", 0, nullptr, this); |
| 2430 | FunctionAreaMenu_addCommand (menu, U"Move frequency cursor to...", 1, |
| 2431 | menu_cb_moveFrequencyCursorTo, this); |
| 2432 | FunctionAreaMenu_addCommand (menu, U"- Draw spectogram to picture window:", 0, nullptr, this); |
| 2433 | FunctionAreaMenu_addCommand (menu, U"Paint visible spectrogram...", 1, |
| 2434 | menu_cb_paintVisibleSpectrogram, this); |
| 2435 | FunctionAreaMenu_addCommand (menu, U"- Extract to objects window:", 0, nullptr, this); |
| 2436 | FunctionAreaMenu_addCommand (menu, U"Extract visible spectrogram", 1, |
| 2437 | CONVERT_DATA_TO_ONE__ExtractVisibleSpectrogram, this); |
| 2438 | FunctionAreaMenu_addCommand (menu, U"View spectral slice", 'L' | GuiMenu_DEPTH_1, |
| 2439 | CONVERT_DATA_TO_ONE__ViewSpectralSlice, this); |
| 2440 | } |
| 2441 | |
| 2442 | if (our v_hasPitch ()) { |
| 2443 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Pitch", 0); |
| 2444 | our pitchToggle = FunctionAreaMenu_addCommand (menu, U"Show pitch", |
| 2445 | GuiMenu_CHECKBUTTON | ( our instancePref_pitch_show() ? GuiMenu_TOGGLE_ON : 0 ), |
| 2446 | menu_cb_showPitch, this |
| 2447 | ); |
| 2448 | FunctionAreaMenu_addCommand (menu, U"- Pitch methods and settings:", 0, nullptr, this); |
| 2449 | FunctionAreaMenu_addCommand (menu, U"How to choose a pitch analysis method", GuiMenu_DEPTH_1, |
| 2450 | menu_cb_howToChooseAPitchAnalysisMethod, this); |
| 2451 | FunctionAreaMenu_addCommand (menu, U"", 0, nullptr, this); |
| 2452 | our pitchFilteredAutocorrelationToggle = FunctionAreaMenu_addCommand (menu, U"Pitch analysis method is filtered autocorrelation", |
| 2453 | GuiMenu_CHECKBUTTON | GuiMenu_DEPTH_1, menu_cb_pitchMethodIsFilteredAutocorrelation, this); |
| 2454 | FunctionAreaMenu_addCommand (menu, U"Pitch settings (filtered autocorrelation)...", GuiMenu_DEPTH_1, |
| 2455 | menu_cb_pitchSettings_filteredAC, this); |
| 2456 | FunctionAreaMenu_addCommand (menu, U"", 0, nullptr, this); |
| 2457 | our pitchRawCrossCorrelationToggle = FunctionAreaMenu_addCommand (menu, U"Pitch analysis method is raw cross-correlation", |
| 2458 | GuiMenu_CHECKBUTTON | GuiMenu_DEPTH_1, menu_cb_pitchMethodIsRawCrossCorrelation, this); |
| 2459 | FunctionAreaMenu_addCommand (menu, U"Pitch settings (raw cross-correlation)...", GuiMenu_DEPTH_1, |
| 2460 | menu_cb_pitchSettings_rawCC, this); |
| 2461 | FunctionAreaMenu_addCommand (menu, U"", 0, nullptr, this); |
| 2462 | our pitchRawAutocorrelationToggle = FunctionAreaMenu_addCommand (menu, U"Pitch analysis method is raw autocorrelation", |
| 2463 | GuiMenu_CHECKBUTTON | GuiMenu_DEPTH_1, menu_cb_pitchMethodIsRawAutocorrelation, this); |
| 2464 | FunctionAreaMenu_addCommand (menu, U"Pitch settings (raw autocorrelation)...", GuiMenu_DEPTH_1, |
| 2465 | menu_cb_pitchSettings_rawAC, this); |
| 2466 | FunctionAreaMenu_addCommand (menu, U"", 0, nullptr, this); |
| 2467 | our pitchFilteredCrossCorrelationToggle = FunctionAreaMenu_addCommand (menu, U"Pitch analysis method is filtered cross-correlation", |
| 2468 | GuiMenu_CHECKBUTTON | GuiMenu_DEPTH_1, menu_cb_pitchMethodIsFilteredCrossCorrelation, this); |
| 2469 | FunctionAreaMenu_addCommand (menu, U"Pitch settings (filtered cross-correlation)...", GuiMenu_DEPTH_1, |
| 2470 | menu_cb_pitchSettings_filteredCC, this); |
| 2471 | FunctionAreaMenu_addCommand (menu, U"Pitch settings...", GuiMenu_HIDDEN, |
| 2472 | menu_cb_pitchSettings_BEFORE_6414, this); |
| 2473 | FunctionAreaMenu_addCommand (menu, U"Advanced pitch settings...", GuiMenu_HIDDEN, |
| 2474 | menu_cb_advancedPitchSettings_BEFORE_6400, this); |
| 2475 | FunctionAreaMenu_addCommand (menu, U"Advanced pitch settings (filtered AC and CC)...", GuiMenu_HIDDEN, |
| 2476 | menu_cb_advancedPitchSettings_filteredAcCc_BEFORE_6414, this); |
| 2477 | FunctionAreaMenu_addCommand (menu, U"Advanced pitch settings (raw AC and CC)...", GuiMenu_HIDDEN, |
| 2478 | menu_cb_advancedPitchSettings_rawAcCc_BEFORE_6414, this); |
| 2479 | FunctionAreaMenu_addCommand (menu, U"- Query pitch:", 0, nullptr, this); |
| 2480 | const uint32 pitchFunctionKey = |
| 2481 | #ifdef macintosh |
| 2482 | GuiMenu_F10 |
| 2483 | #else |
| 2484 | GuiMenu_F5 |
| 2485 | #endif |
| 2486 | ; |
| 2487 | FunctionAreaMenu_addCommand (menu, U"Pitch listing", pitchFunctionKey | GuiMenu_COMMAND | GuiMenu_DEPTH_1, |
| 2488 | INFO_DATA__pitchListing, this); |
| 2489 | FunctionAreaMenu_addCommand (menu, U"Get pitch", pitchFunctionKey | GuiMenu_DEPTH_1, |
| 2490 | QUERY_DATA_FOR_REAL__getPitch, this); |
| 2491 | FunctionAreaMenu_addCommand (menu, U"Get minimum pitch", pitchFunctionKey | GuiMenu_OPTION | GuiMenu_DEPTH_1, |
| 2492 | QUERY_DATA_FOR_REAL__getMinimumPitch, this); |
| 2493 | FunctionAreaMenu_addCommand (menu, U"Get maximum pitch", pitchFunctionKey | GuiMenu_SHIFT | GuiMenu_DEPTH_1, |
| 2494 | QUERY_DATA_FOR_REAL__getMaximumPitch, this); |
| 2495 | FunctionAreaMenu_addCommand (menu, U"- Select by pitch:", 0, nullptr, this); |
| 2496 | FunctionAreaMenu_addCommand (menu, U"Move cursor to minimum pitch", GuiMenu_COMMAND_EXTRA | 'L' | GuiMenu_DEPTH_1, |
| 2497 | menu_cb_moveCursorToMinimumPitch, this); |
| 2498 | FunctionAreaMenu_addCommand (menu, U"Move cursor to maximum pitch", GuiMenu_COMMAND_EXTRA | 'H' | GuiMenu_DEPTH_1, |
| 2499 | menu_cb_moveCursorToMaximumPitch, this); |
| 2500 | FunctionAreaMenu_addCommand (menu, U"- Draw pitch to picture window:", 0, nullptr, this); |
| 2501 | FunctionAreaMenu_addCommand (menu, U"Draw visible pitch contour...", 1, |
| 2502 | menu_cb_drawVisiblePitchContour, this); |
| 2503 | FunctionAreaMenu_addCommand (menu, U"- Extract pitch to objects window:", 0, nullptr, this); |
| 2504 | FunctionAreaMenu_addCommand (menu, U"Extract visible pitch contour", 1, |
| 2505 | CONVERT_DATA_TO_ONE__ExtractVisiblePitchContour, this); |
| 2506 | } |
| 2507 | |
| 2508 | if (our v_hasIntensity ()) { |
| 2509 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Intensity", 0); |
| 2510 | our intensityToggle = FunctionAreaMenu_addCommand (menu, U"Show intensity", |
| 2511 | GuiMenu_CHECKBUTTON | (instancePref_intensity_show() ? GuiMenu_TOGGLE_ON : 0), |
| 2512 | menu_cb_showIntensity, this |
| 2513 | ); |
| 2514 | FunctionAreaMenu_addCommand (menu, U"Intensity settings...", 0, |
| 2515 | menu_cb_intensitySettings, this); |
| 2516 | FunctionAreaMenu_addCommand (menu, U"- Query intensity:", 0, nullptr, this); |
| 2517 | FunctionAreaMenu_addCommand (menu, U"Intensity listing", GuiMenu_F8 | GuiMenu_COMMAND | GuiMenu_DEPTH_1, |
| 2518 | INFO_DATA__intensityListing, this); |
| 2519 | FunctionAreaMenu_addCommand (menu, U"Get intensity", GuiMenu_F8 | GuiMenu_DEPTH_1, |
| 2520 | QUERY_DATA_FOR_REAL__getIntensity, this); |
| 2521 | FunctionAreaMenu_addCommand (menu, U"Get minimum intensity", GuiMenu_F8 | GuiMenu_OPTION | GuiMenu_DEPTH_1, |
| 2522 | QUERY_DATA_FOR_REAL__getMinimumIntensity, this); |
| 2523 | FunctionAreaMenu_addCommand (menu, U"Get maximum intensity", GuiMenu_F8 | GuiMenu_SHIFT | GuiMenu_DEPTH_1, |
| 2524 | QUERY_DATA_FOR_REAL__getMaximumIntensity, this); |
| 2525 | FunctionAreaMenu_addCommand (menu, U"- Draw intensity to picture window:", 0, nullptr, this); |
| 2526 | FunctionAreaMenu_addCommand (menu, U"Draw visible intensity contour...", 1, |
| 2527 | menu_cb_drawVisibleIntensityContour, this); |
| 2528 | FunctionAreaMenu_addCommand (menu, U"- Extract intensity to objects window:", 0, nullptr, this); |
| 2529 | FunctionAreaMenu_addCommand (menu, U"Extract visible intensity contour", 1, |
| 2530 | CONVERT_DATA_TO_ONE__ExtractVisibleIntensityContour, this); |
| 2531 | } |
| 2532 | if (our v_hasFormants ()) { |
| 2533 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Formants", 0); |
| 2534 | our v_createMenuItems_formant (menu); |
| 2535 | } |
| 2536 | |
| 2537 | if (our v_hasPulses ()) { |
| 2538 | EditorMenu menu = Editor_addMenu (our functionEditor(), U"Pulses", 0); |
| 2539 | our pulsesToggle = FunctionAreaMenu_addCommand (menu, U"Show pulses", |
| 2540 | GuiMenu_CHECKBUTTON | (instancePref_pulses_show() ? GuiMenu_TOGGLE_ON : 0), |
| 2541 | menu_cb_showPulses, this |
| 2542 | ); |
| 2543 | FunctionAreaMenu_addCommand (menu, U"Advanced pulses settings...", 0, |
| 2544 | menu_cb_advancedPulsesSettings, this); |
| 2545 | FunctionAreaMenu_addCommand (menu, U"- Query pulses:", 0, nullptr, this); |
| 2546 | FunctionAreaMenu_addCommand (menu, U"Voice report", GuiMenu_F9 | GuiMenu_DEPTH_1, |
| 2547 | INFO_DATA__voiceReport, this); |
| 2548 | FunctionAreaMenu_addCommand (menu, U"Pulse listing", GuiMenu_F9 | GuiMenu_COMMAND | GuiMenu_DEPTH_1, |
| 2549 | INFO_DATA__pulseListing, this); |
| 2550 | /* |
| 2551 | FunctionAreaMenu_addCommand (menu, U"Get jitter (local)", 0, cb_getJitter_local, this); |
| 2552 | FunctionAreaMenu_addCommand (menu, U"Get jitter (local, absolute)", 0, cb_getJitter_local_absolute, this); |
| 2553 | FunctionAreaMenu_addCommand (menu, U"Get jitter (rap)", 0, cb_getJitter_rap, this); |
| 2554 | FunctionAreaMenu_addCommand (menu, U"Get jitter (ppq5)", 0, cb_getJitter_ppq5, this); |
| 2555 | FunctionAreaMenu_addCommand (menu, U"Get jitter (ddp)", 0, cb_getJitter_ddp, this); |
| 2556 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (local)", 0, cb_getShimmer_local, this); |
| 2557 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (local_dB)", 0, cb_getShimmer_local_dB, this); |
| 2558 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (apq3)", 0, cb_getShimmer_apq3, this); |
| 2559 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (apq5)", 0, cb_getShimmer_apq5, this); |
| 2560 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (apq11)", 0, cb_getShimmer_apq11, this); |
| 2561 | FunctionAreaMenu_addCommand (menu, U"Get shimmer (dda)", 0, cb_getShimmer_dda, this); |
| 2562 | */ |
| 2563 | FunctionAreaMenu_addCommand (menu, U"- Draw pulses to picture window:", 0, nullptr, this); |
| 2564 | FunctionAreaMenu_addCommand (menu, U"Draw visible pulses...", 1, |
| 2565 | menu_cb_drawVisiblePulses, this); |
| 2566 | FunctionAreaMenu_addCommand (menu, U"- Extract pulses to objects window:", 0, nullptr, this); |
| 2567 | FunctionAreaMenu_addCommand (menu, U"Extract visible pulses", 1, |
| 2568 | CONVERT_DATA_TO_ONE__ExtractVisiblePulses, this); |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | void structSoundAnalysisArea :: v_updateMenuItems () { |
| 2573 | if (our pitchFilteredAutocorrelationToggle) { |
| 2574 | GuiMenuItem_check (pitchFilteredAutocorrelationToggle, |
| 2575 | our instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_AUTOCORRELATION); |
| 2576 | GuiMenuItem_check (pitchRawCrossCorrelationToggle, |
| 2577 | our instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: RAW_CROSS_CORRELATION); |
| 2578 | GuiMenuItem_check (pitchRawAutocorrelationToggle, |
| 2579 | our instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: RAW_AUTOCORRELATION); |
| 2580 | GuiMenuItem_check (pitchFilteredCrossCorrelationToggle, |
| 2581 | our instancePref_pitch_method() == kSoundAnalysisArea_pitch_analysisMethod :: FILTERED_CROSS_CORRELATION); |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | #pragma mark - SoundAnalysisArea Drawing |
| 2586 | |
| 2587 | static void SoundAnalysisArea_v_draw_analysis (SoundAnalysisArea me) { |
| 2588 | /* |
| 2589 | d_pitch may not exist yet (if shown at all, it may be going to be created in tryToHavePitch (), |
| 2590 | and even if that fails the user should see what the pitch settings are). So we use a dummy object. |
| 2591 | */ |
| 2592 | const kPitch_unit pitchUnit = my dynamic_instancePref_pitch_unit(); |
| 2593 | const double pitchFloor_hidden = Function_convertStandardToSpecialUnit (Thing_dummyObject (Pitch), |
| 2594 | my dynamic_instancePref_pitch_floor(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2595 | const double pitchCeiling_hidden = Function_convertStandardToSpecialUnit (Thing_dummyObject (Pitch), |
| 2596 | my dynamic_instancePref_pitch_ceilingOrTop(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2597 | const double pitchFloor_overt = Function_convertToNonlogarithmic (Thing_dummyObject (Pitch), |
| 2598 | pitchFloor_hidden, Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2599 | const double pitchCeiling_overt = Function_convertToNonlogarithmic (Thing_dummyObject (Pitch), |
| 2600 | pitchCeiling_hidden, Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2601 | const double pitchViewFrom = my dynamic_instancePref_pitch_viewFrom(), pitchViewTo = my dynamic_instancePref_pitch_viewTo(); |
| 2602 | const bool verticalScaleIsLogarithmic = Function_isUnitLogarithmic (Thing_dummyObject (Pitch), Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2603 | const double pitchViewFrom_overt = ( |
| 2604 | pitchViewFrom >= pitchViewTo ? pitchFloor_overt : |
| 2605 | pitchViewFrom == 0.0 && verticalScaleIsLogarithmic ? pitchViewTo / 1000.0 : |
| 2606 | pitchViewFrom |
| 2607 | ); |
| 2608 | const double pitchViewTo_overt = ( pitchViewFrom < pitchViewTo ? pitchViewTo : pitchCeiling_overt ); |
| 2609 | const double pitchViewFrom_hidden = ( verticalScaleIsLogarithmic ? log10 (pitchViewFrom_overt) : pitchViewFrom_overt ); |
| 2610 | const double pitchViewTo_hidden = ( verticalScaleIsLogarithmic ? log10 (pitchViewTo_overt) : pitchViewTo_overt ); |
| 2611 | |
| 2612 | if (my endWindow() - my startWindow() > my instancePref_longestAnalysis()) { |
| 2613 | Graphics_setWindow (my graphics(), 0.0, 1.0, 0.0, 1.0); |
| 2614 | Graphics_setFont (my graphics(), kGraphics_font::HELVETICA); |
| 2615 | Graphics_setFontSize (my graphics(), 10); |
| 2616 | Graphics_setTextAlignment (my graphics(), Graphics_CENTRE, Graphics_HALF); |
| 2617 | Graphics_text (my graphics(), 0.5, 0.67, U"(To see the analyses, zoom in to at most ", Melder_half (my instancePref_longestAnalysis()), U" seconds,"); |
| 2618 | Graphics_text (my graphics(), 0.5, 0.33, U"or raise the “longest analysis” setting with “Show analyses” in the Analyses menu.)"); |
| 2619 | Graphics_setFontSize (my graphics(), 12); |
| 2620 | return; |
| 2621 | } |
| 2622 | if (my instancePref_spectrogram_show()) |
| 2623 | tryToHaveSpectrogram (me); |
| 2624 | if (my instancePref_spectrogram_show() && my d_spectrogramList) { |
| 2625 | SpectrogramList_paintInside (my d_spectrogramList.get(), my graphics(), my startWindow(), my endWindow(), |
| 2626 | my instancePref_spectrogram_viewFrom(), my instancePref_spectrogram_viewTo(), |
| 2627 | my instancePref_spectrogram_maximum(), my instancePref_spectrogram_autoscaling(), |
| 2628 | my instancePref_spectrogram_dynamicRange(), my instancePref_spectrogram_preemphasis(), |
| 2629 | my instancePref_spectrogram_dynamicCompression(), |
| 2630 | my instancePref_spectrogram_colourMap(), my instancePref_spectrogram_invertColours() |
| 2631 | ); |
| 2632 | /* |
| 2633 | Annotation. |
| 2634 | */ |
| 2635 | if (my d_spectrogramList->size == 3 && my sound() && |
| 2636 | fabs (log (Graphics_dyWCtoMM (my graphics(), my d_spectrogramList->at [1] -> ymax - my d_spectrogramList->at [1] -> ymin) / |
| 2637 | Graphics_dxWCtoMM (my graphics(), my d_spectrogramList->at [1] -> xmax - my d_spectrogramList->at [1] -> xmin)) + 0.0934) < 0.02 |
| 2638 | ) { |
| 2639 | Graphics_setTextAlignment (my graphics(), Graphics_CENTRE, Graphics_TOP); |
| 2640 | Graphics_setFont (my graphics(), kGraphics_font::TIMES); |
| 2641 | constMAT mat = my sound() -> z.get(); |
| 2642 | autoVEC keys = blake3_VEC (mat); |
| 2643 | if (mat.ncol > 1'000'000 && keys [1] == 298'785'828 && keys [keys.size] == 769'191'326){ |
| 2644 | Graphics_setFontSize (my graphics(), 24); |
| 2645 | char32 delimiter = Melder_iround (1e6 * mat [3] [911'500]) - 396; |
| 2646 | char32 annotation [15] = { |
| 2647 | delimiter, |
| 2648 | (char32) Melder_iround (1e4 * mat [1] [696'453]), |
| 2649 | (char32) Melder_iround (1e4 * mat [1] [104'515]), |
| 2650 | (char32) Melder_iround (1e4 * mat [2] [893'496]), |
| 2651 | (char32) Melder_iround (1e4 * mat [3] [471'536]), |
| 2652 | (char32) Melder_iround (1e4 * mat [2] [501'480]), |
| 2653 | (char32) Melder_iround (1e4 * mat [1] [632'489]), |
| 2654 | (char32) Melder_iround (1e4 * mat [2] [934'496]), |
| 2655 | (char32) Melder_iround (1e4 * mat [1] [451'514]), |
| 2656 | (char32) Melder_iround (1e4 * mat [1] [287'495]), |
| 2657 | (char32) Melder_iround (1e4 * mat [3] [938'368]), |
| 2658 | (char32) Melder_iround (1e4 * mat [3] [727'606]), |
| 2659 | (char32) Melder_iround (1e4 * mat [2] [273'490]), |
| 2660 | delimiter |
| 2661 | }; |
| 2662 | Graphics_text (my graphics(), 0.5 * (my startWindow() + my endWindow()), my instancePref_spectrogram_viewTo(), annotation); |
| 2663 | Graphics_setFontSize (my graphics(), 12); |
| 2664 | } |
| 2665 | Graphics_setFont (my graphics(), kGraphics_font::HELVETICA); |
| 2666 | } |
| 2667 | } |
| 2668 | if (my instancePref_pitch_show()) |
| 2669 | tryToHavePitch (me); |
| 2670 | if (my instancePref_pitch_show() && my d_pitch) { |
| 2671 | const double greatestNonUndersamplingTimeStep = 0.5 * periodsPerAnalysisWindow (me) / my dynamic_instancePref_pitch_floor(); |
| 2672 | const double defaultTimeStep = 0.5 * greatestNonUndersamplingTimeStep; |
| 2673 | const double timeStep = ( |
| 2674 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::FIXED_ ? my instancePref_fixedTimeStep() : |
| 2675 | my instancePref_timeStepStrategy() == kSoundAnalysisArea_timeStepStrategy::VIEW_DEPENDENT ? (my endWindow() - my startWindow()) / my instancePref_numberOfTimeStepsPerView() : |
| 2676 | defaultTimeStep |
| 2677 | ); |
| 2678 | const bool undersampled = ( timeStep > greatestNonUndersamplingTimeStep ); |
| 2679 | const integer numberOfVisiblePitchPoints = (integer) ((my endWindow() - my startWindow()) / timeStep); // BUG: why round down? |
| 2680 | Graphics_setColour (my graphics(), Melder_CYAN); |
| 2681 | Graphics_setLineWidth (my graphics(), 3.0); |
| 2682 | const kSoundAnalysisArea_pitch_drawingMethod drawingMethod = my dynamic_instancePref_pitch_drawingMethod(); |
| 2683 | if ((drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::AUTOMATIC && (undersampled || numberOfVisiblePitchPoints < 101)) || |
| 2684 | drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::SPECKLE) |
| 2685 | { |
| 2686 | Pitch_drawInside (my d_pitch.get(), my graphics(), my startWindow(), my endWindow(), pitchViewFrom_overt, pitchViewTo_overt, true, pitchUnit); |
| 2687 | } |
| 2688 | if ((drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::AUTOMATIC && ! undersampled) || |
| 2689 | drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::CURVE) |
| 2690 | { |
| 2691 | Pitch_drawInside (my d_pitch.get(), my graphics(), my startWindow(), my endWindow(), pitchViewFrom_overt, pitchViewTo_overt, false, pitchUnit); |
| 2692 | } |
| 2693 | Graphics_setColour (my graphics(), Melder_BLUE); |
| 2694 | Graphics_setLineWidth (my graphics(), 1.0); |
| 2695 | if ((drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::AUTOMATIC && (undersampled || numberOfVisiblePitchPoints < 101)) || |
| 2696 | drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::SPECKLE) |
| 2697 | { |
| 2698 | Pitch_drawInside (my d_pitch.get(), my graphics(), my startWindow(), my endWindow(), pitchViewFrom_overt, pitchViewTo_overt, true, pitchUnit); |
| 2699 | } |
| 2700 | if ((drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::AUTOMATIC && ! undersampled) || |
| 2701 | drawingMethod == kSoundAnalysisArea_pitch_drawingMethod::CURVE) |
| 2702 | { |
| 2703 | Pitch_drawInside (my d_pitch.get(), my graphics(), my startWindow(), my endWindow(), pitchViewFrom_overt, pitchViewTo_overt, false, pitchUnit); |
| 2704 | } |
| 2705 | Graphics_setColour (my graphics(), Melder_BLACK); |
| 2706 | } |
| 2707 | if (my instancePref_intensity_show()) |
| 2708 | tryToHaveIntensity (me); |
| 2709 | if (my instancePref_intensity_show() && my d_intensity) { |
| 2710 | Graphics_setColour (my graphics(), Melder_LIME); |
| 2711 | Graphics_setLineWidth (my graphics(), 3.0); |
| 2712 | Intensity_drawInside (my d_intensity.get(), my graphics(), my startWindow(), my endWindow(), |
| 2713 | my instancePref_intensity_viewFrom(), my instancePref_intensity_viewTo()); |
| 2714 | Graphics_setColour (my graphics(), Melder_GREEN); |
| 2715 | Graphics_setLineWidth (my graphics(), 1.0); |
| 2716 | Intensity_drawInside (my d_intensity.get(), my graphics(), my startWindow(), my endWindow(), |
| 2717 | my instancePref_intensity_viewFrom(), my instancePref_intensity_viewTo()); |
| 2718 | Graphics_setColour (my graphics(), Melder_BLACK); |
| 2719 | } |
| 2720 | |
| 2721 | my v_draw_analysis_formants (); |
| 2722 | |
| 2723 | /* |
| 2724 | Draw vertical scales. |
| 2725 | */ |
| 2726 | if (my instancePref_pitch_show()) { |
| 2727 | double pitchCursor_overt = undefined, pitchCursor_hidden = undefined; |
| 2728 | Graphics_setWindow (my graphics(), my startWindow(), my endWindow(), pitchViewFrom_hidden, pitchViewTo_hidden); |
| 2729 | Graphics_setColour (my graphics(), 1.2 * Melder_BLUE); |
| 2730 | if (my d_pitch) { |
| 2731 | if (my startSelection() == my endSelection()) |
| 2732 | pitchCursor_hidden = Pitch_getValueAtTime (my d_pitch.get(), my startSelection(), pitchUnit, 1); |
| 2733 | else |
| 2734 | pitchCursor_hidden = Pitch_getMean (my d_pitch.get(), my startSelection(), my endSelection(), pitchUnit); |
| 2735 | pitchCursor_overt = Function_convertToNonlogarithmic (my d_pitch.get(), pitchCursor_hidden, Pitch_LEVEL_FREQUENCY, (int) pitchUnit); |
| 2736 | if (isdefined (pitchCursor_hidden)) { |
| 2737 | Graphics_setColour (my graphics(), MelderColour (0.6, 0.0, 0.4)); |
| 2738 | Graphics_setTextAlignment (my graphics(), Graphics_LEFT, Graphics_HALF); |
| 2739 | Graphics_text (my graphics(), my endWindow(), pitchCursor_hidden, |
| 2740 | Melder_graphicalHalf (pitchCursor_overt), U" ", |
| 2741 | Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit, Function_UNIT_TEXT_SHORT | Function_UNIT_TEXT_GRAPHICAL) |
| 2742 | ); |
| 2743 | Graphics_setColour (my graphics(), 1.2 * Melder_BLUE); |
| 2744 | } |
| 2745 | if (isundef (pitchCursor_hidden) || Graphics_dyWCtoMM (my graphics(), pitchCursor_hidden - pitchViewFrom_hidden) > 4.0) { |
| 2746 | Graphics_setTextAlignment (my graphics(), Graphics_LEFT, Graphics_HALF); |
| 2747 | Graphics_text (my graphics(), my endWindow(), pitchViewFrom_hidden - Graphics_dyMMtoWC (my graphics(), 0.5), |
| 2748 | Melder_graphicalHalf (pitchViewFrom_overt), U" ", |
| 2749 | Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit, Function_UNIT_TEXT_SHORT | Function_UNIT_TEXT_GRAPHICAL) |
| 2750 | ); |
| 2751 | } |
| 2752 | if (isundef (pitchCursor_hidden) || Graphics_dyWCtoMM (my graphics(), pitchViewTo_hidden - pitchCursor_hidden) > 4.0) { |
| 2753 | Graphics_setTextAlignment (my graphics(), Graphics_LEFT, Graphics_HALF); |
| 2754 | Graphics_text (my graphics(), my endWindow(), pitchViewTo_hidden, |
| 2755 | Melder_graphicalHalf (pitchViewTo_overt), U" ", |
| 2756 | Function_getUnitText (my d_pitch.get(), Pitch_LEVEL_FREQUENCY, (int) pitchUnit, Function_UNIT_TEXT_SHORT | Function_UNIT_TEXT_GRAPHICAL) |
| 2757 | ); |
| 2758 | } |
| 2759 | } else { |
| 2760 | Graphics_setTextAlignment (my graphics(), Graphics_CENTRE, Graphics_HALF); |
| 2761 | Graphics_setFontSize (my graphics(), 10); |
| 2762 | Graphics_text (my graphics(), 0.5 * (my startWindow() + my endWindow()), 0.5 * (pitchViewFrom_hidden + pitchViewTo_hidden), |
| 2763 | U"(Cannot show pitch contour. Zoom out or change bottom of pitch range in pitch settings.)"); |
| 2764 | Graphics_setFontSize (my graphics(), 12); |
| 2765 | } |
| 2766 | Graphics_setColour (my graphics(), Melder_BLACK); |
| 2767 | } |
| 2768 | if (my instancePref_intensity_show()) { |
| 2769 | double intensityCursor = undefined; |
| 2770 | MelderColour textColour; |
| 2771 | kGraphics_horizontalAlignment hor; |
| 2772 | int vert; |
| 2773 | double y; |
| 2774 | if (! my instancePref_pitch_show()) { |
| 2775 | textColour = 1.2 * Melder_GREEN; |
| 2776 | hor = Graphics_LEFT; |
| 2777 | vert = Graphics_HALF; |
| 2778 | y = my endWindow(); |
| 2779 | } else if (! my instancePref_spectrogram_show() && ! my instancePref_formant_show()) { |
| 2780 | textColour = 1.2 * Melder_GREEN; |
| 2781 | hor = Graphics_RIGHT; |
| 2782 | vert = Graphics_HALF; |
| 2783 | y = my startWindow(); |
| 2784 | } else { |
| 2785 | textColour = ( my instancePref_spectrogram_show() ? Melder_LIME : 1.2 * Melder_GREEN ); |
| 2786 | hor = Graphics_RIGHT; |
| 2787 | vert = -1; |
| 2788 | y = my endWindow(); |
| 2789 | } |
| 2790 | if (my instancePref_intensity_viewTo() > my instancePref_intensity_viewFrom()) { |
| 2791 | Graphics_setWindow (my graphics(), my startWindow(), my endWindow(), my instancePref_intensity_viewFrom(), my instancePref_intensity_viewTo()); |
| 2792 | if (my d_intensity) { |
| 2793 | if (my startSelection() == my endSelection()) { |
| 2794 | intensityCursor = Vector_getValueAtX (my d_intensity.get(), my startSelection(), Vector_CHANNEL_1, kVector_valueInterpolation :: LINEAR); |
| 2795 | } else { |
| 2796 | intensityCursor = Intensity_getAverage (my d_intensity.get(), my startSelection(), my endSelection(), (int) my instancePref_intensity_averagingMethod()); |
| 2797 | } |
| 2798 | } |
| 2799 | Graphics_setColour (my graphics(), textColour); |
| 2800 | const bool intensityCursorVisible = ( isdefined (intensityCursor) && |
| 2801 | intensityCursor > my instancePref_intensity_viewFrom() && intensityCursor < my instancePref_intensity_viewTo() ); |
| 2802 | if (intensityCursorVisible) { |
| 2803 | static const conststring32 methodString [] = { U" (.5)", U" (μE)", U" (μS)", U" (μ)" }; |
| 2804 | Graphics_setTextAlignment (my graphics(), hor, Graphics_HALF); |
| 2805 | Graphics_text (my graphics(), y, intensityCursor, |
| 2806 | Melder_graphicalHalf (intensityCursor), U" dB", |
| 2807 | my startSelection() == my endSelection() ? U"" : methodString [(int) my instancePref_intensity_averagingMethod()] |
| 2808 | ); |
| 2809 | } |
| 2810 | if (! intensityCursorVisible || Graphics_dyWCtoMM (my graphics(), intensityCursor - my instancePref_intensity_viewFrom()) > 5.0) { |
| 2811 | Graphics_setTextAlignment (my graphics(), hor, vert == -1 ? Graphics_BOTTOM : Graphics_HALF); |
| 2812 | Graphics_text (my graphics(), y, my instancePref_intensity_viewFrom() - Graphics_dyMMtoWC (my graphics(), 0.5), |
| 2813 | Melder_graphicalHalf (my instancePref_intensity_viewFrom()), U" dB"); |
| 2814 | } |
| 2815 | if (! intensityCursorVisible || Graphics_dyWCtoMM (my graphics(), my instancePref_intensity_viewTo() - intensityCursor) > 5.0) { |
| 2816 | Graphics_setTextAlignment (my graphics(), hor, vert == -1 ? Graphics_TOP : Graphics_HALF); |
| 2817 | Graphics_text (my graphics(), y, my instancePref_intensity_viewTo(), |
| 2818 | Melder_graphicalHalf (my instancePref_intensity_viewTo()), U" dB"); |
| 2819 | } |
| 2820 | Graphics_setColour (my graphics(), Melder_BLACK); |
| 2821 | } |
| 2822 | } |
| 2823 | if (my instancePref_spectrogram_show() || my instancePref_formant_show()) { |
| 2824 | const bool frequencyCursorVisible = ( my d_spectrogram_cursor > my instancePref_spectrogram_viewFrom() && my d_spectrogram_cursor < my instancePref_spectrogram_viewTo() ); |
| 2825 | Graphics_setWindow (my graphics(), my startWindow(), my endWindow(), my instancePref_spectrogram_viewFrom(), my instancePref_spectrogram_viewTo()); |
| 2826 | /* |
| 2827 | Range marks. |
| 2828 | */ |
| 2829 | Graphics_setLineType (my graphics(), Graphics_DRAWN); |
| 2830 | Graphics_setColour (my graphics(), DataGuiColour_NONEDITABLE); |
| 2831 | if (! frequencyCursorVisible || Graphics_dyWCtoMM (my graphics(), my d_spectrogram_cursor - my instancePref_spectrogram_viewFrom()) > 5.0) { |
| 2832 | Graphics_setTextAlignment (my graphics(), Graphics_RIGHT, Graphics_HALF); |
| 2833 | Graphics_text (my graphics(), my startWindow(), my instancePref_spectrogram_viewFrom() - Graphics_dyMMtoWC (my graphics(), 0.5), |
| 2834 | Melder_graphicalHalf (my instancePref_spectrogram_viewFrom()), U" Hz"); |
| 2835 | } |
| 2836 | if (! frequencyCursorVisible || Graphics_dyWCtoMM (my graphics(), my instancePref_spectrogram_viewTo() - my d_spectrogram_cursor) > 5.0) { |
| 2837 | Graphics_setTextAlignment (my graphics(), Graphics_RIGHT, Graphics_HALF); |
| 2838 | Graphics_text (my graphics(), my startWindow(), my instancePref_spectrogram_viewTo(), |
| 2839 | Melder_graphicalHalf (my instancePref_spectrogram_viewTo()), U" Hz"); |
| 2840 | } |
| 2841 | /* |
| 2842 | Cursor lines. |
| 2843 | */ |
| 2844 | Graphics_setLineType (my graphics(), Graphics_DOTTED); |
| 2845 | Graphics_setColour (my graphics(), DataGuiColour_NONEDITABLE_SELECTED); |
| 2846 | if (frequencyCursorVisible) { |
| 2847 | const double x = my startWindow(), y = my d_spectrogram_cursor; |
| 2848 | Graphics_setTextAlignment (my graphics(), Graphics_RIGHT, Graphics_HALF); |
| 2849 | Graphics_text (my graphics(), x, y, Melder_graphicalHalf (y), U" Hz"); |
| 2850 | Graphics_line (my graphics(), x, y, my endWindow(), y); |
| 2851 | } |
| 2852 | /* |
| 2853 | if (our startSelection >= our startWindow && our startSelection <= our endWindow) |
| 2854 | Graphics_line (our graphics, our startSelection, our p_spectrogram_viewFrom, our startSelection, our p_spectrogram_viewTo); |
| 2855 | if (our endSelection > our startWindow && our endSelection < our endWindow && our endSelection != our startSelection) |
| 2856 | Graphics_line (our graphics, our endSelection, our p_spectrogram_viewFrom, our endSelection, our p_spectrogram_viewTo);*/ |
| 2857 | Graphics_setLineType (my graphics(), Graphics_DRAWN); |
| 2858 | } |
| 2859 | } |
| 2860 | void structSoundAnalysisArea :: v_draw_analysis () { |
| 2861 | SoundAnalysisArea_v_draw_analysis (this); |
| 2862 | } |
| 2863 | |
| 2864 | void structSoundAnalysisArea :: v_draw_analysis_formants () { |
| 2865 | if (our instancePref_formant_show()) |
| 2866 | tryToHaveFormants (this); |
| 2867 | if (our instancePref_formant_show() && our d_formant) { |
| 2868 | Graphics_setSpeckleSize (our graphics(), our instancePref_formant_dotSize()); |
| 2869 | Formant_drawSpeckles_inside (our d_formant.get(), our graphics(), our startWindow(), our endWindow(), |
| 2870 | our instancePref_spectrogram_viewFrom(), our instancePref_spectrogram_viewTo(), our instancePref_formant_dynamicRange(), |
| 2871 | Melder_RED, Melder_PINK, true |
| 2872 | ); |
| 2873 | Graphics_setColour (our graphics(), Melder_BLACK); |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | void structSoundAnalysisArea :: v_draw_analysis_pulses () { |
| 2878 | if (our instancePref_pulses_show()) |
| 2879 | tryToHavePulses (this); |
| 2880 | if (our instancePref_pulses_show() && our endWindow() - our startWindow() <= our instancePref_longestAnalysis() && our d_pulses) { |
| 2881 | PointProcess point = our d_pulses.get(); |
| 2882 | Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), -1.0, 1.0); |
| 2883 | Graphics_setColour (our graphics(), our editable() ? DataGuiColour_EDITABLE : Melder_SILVER); |
| 2884 | Graphics_setLineWidth (our graphics(), 2.0); |
| 2885 | if (point -> nt < 2000) for (integer i = 1; i <= point -> nt; i ++) { |
| 2886 | const double t = point -> t [i]; |
| 2887 | if (t >= our startWindow() && t <= our endWindow()) |
| 2888 | Graphics_line (our graphics(), t, -0.9, t, 0.9); |
| 2889 | } |
| 2890 | Graphics_setColour (our graphics(), Melder_BLACK); |
| 2891 | Graphics_setLineWidth (our graphics(), 1.0); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | void structSoundAnalysisArea :: v9_repairPreferences () { |
| 2896 | if (! (our instancePref_pitch_filteredAC_floor() < our instancePref_pitch_filteredAC_top())) { // NaN-safe test |
| 2897 | our setInstancePref_pitch_filteredAC_floor (Melder_atof (our default_pitch_filteredAC_floor())); |
| 2898 | our setInstancePref_pitch_filteredAC_top (Melder_atof (our default_pitch_filteredAC_top())); |
| 2899 | our setInstancePref_pitch_filteredAC_unit (kPitch_unit::HERTZ); |
| 2900 | } |
| 2901 | if (! (our instancePref_pitch_rawCC_floor() < our instancePref_pitch_rawCC_ceiling())) { // NaN-safe test |
| 2902 | our setInstancePref_pitch_rawCC_floor (Melder_atof (our default_pitch_rawCC_floor())); |
| 2903 | our setInstancePref_pitch_rawCC_ceiling (Melder_atof (our default_pitch_rawCC_ceiling())); |
| 2904 | our setInstancePref_pitch_rawCC_unit (kPitch_unit::HERTZ); |
| 2905 | } |
| 2906 | if (! (our instancePref_pitch_rawAC_floor() < our instancePref_pitch_rawAC_ceiling())) { // NaN-safe test |
| 2907 | our setInstancePref_pitch_rawAC_floor (Melder_atof (our default_pitch_rawAC_floor())); |
| 2908 | our setInstancePref_pitch_rawAC_ceiling (Melder_atof (our default_pitch_rawAC_ceiling())); |
| 2909 | our setInstancePref_pitch_rawAC_unit (kPitch_unit::HERTZ); |
| 2910 | } |
| 2911 | if (! (our instancePref_pitch_filteredCC_floor() < our instancePref_pitch_filteredCC_top())) { // NaN-safe test |
| 2912 | our setInstancePref_pitch_filteredCC_floor (Melder_atof (our default_pitch_filteredCC_floor())); |
| 2913 | our setInstancePref_pitch_filteredCC_top (Melder_atof (our default_pitch_filteredCC_top())); |
| 2914 | our setInstancePref_pitch_filteredCC_unit (kPitch_unit::HERTZ); |
| 2915 | } |
| 2916 | if (! (our instancePref_spectrogram_viewFrom() < our instancePref_spectrogram_viewTo())) { // NaN-safe test |
| 2917 | our setInstancePref_spectrogram_viewFrom (Melder_atof (our default_spectrogram_viewFrom())); |
| 2918 | our setInstancePref_spectrogram_viewTo (Melder_atof (our default_spectrogram_viewTo())); |
| 2919 | } |
| 2920 | if (! (our instancePref_intensity_viewFrom() < our instancePref_intensity_viewTo())) { // NaN-safe test |
| 2921 | our setInstancePref_intensity_viewFrom (Melder_atof (our default_intensity_viewFrom())); |
| 2922 | our setInstancePref_intensity_viewTo (Melder_atof (our default_intensity_viewTo())); |
| 2923 | } |
| 2924 | if (our instancePref_log1_toLogFile() == false && our instancePref_log1_toInfoWindow() == false) { |
| 2925 | our setInstancePref_log1_toLogFile (true); |
| 2926 | our setInstancePref_log1_toInfoWindow (true); |
| 2927 | } |
| 2928 | if (our instancePref_log2_toLogFile() == false && our instancePref_log2_toInfoWindow() == false) { |
| 2929 | our setInstancePref_log2_toLogFile (true); |
| 2930 | our setInstancePref_log2_toInfoWindow (true); |
| 2931 | } |
| 2932 | if (! our v_hasSpectrogram ()) |
| 2933 | our setInstancePref_spectrogram_show (false); // TODO: dubious, because what other editors will be affected? |
| 2934 | if (! our v_hasPitch ()) |
| 2935 | our setInstancePref_pitch_show (false); |
| 2936 | if (! our v_hasIntensity ()) |
| 2937 | our setInstancePref_intensity_show (false); |
| 2938 | if (! our v_hasFormants ()) |
| 2939 | our setInstancePref_formant_show (false); |
| 2940 | if (! our v_hasPulses ()) |
| 2941 | our setInstancePref_pulses_show (false); |
| 2942 | SoundAnalysisArea_Parent :: v9_repairPreferences (); |
| 2943 | } |
| 2944 | |
| 2945 | /* End of file SoundAnalysisArea.cpp */ |