Debian Codegraph @

foned/ManipulationEditor.cpp

raw symbols SCIP
1 /* ManipulationEditor.cpp
2 *
3 * Copyright (C) 1992-2024,2026 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "ManipulationEditor.h"
20 #include "PitchTier_to_PointProcess.h"
21 #include "Sound_to_PointProcess.h"
22 #include "Sound_to_Pitch.h"
23 #include "Pitch_to_PitchTier.h"
24 #include "Pitch_to_PointProcess.h"
25 #include "EditorM.h"
26
27
28 #pragma mark - ManipPulsesArea
29
30 Thing_implement (ManipulationPulsesArea, PointArea, 0);
31
32
33 #pragma mark - ManipPulsesArea Modify
34
35 static void menu_cb_removePulses (ManipulationPulsesArea me, EDITOR_ARGS) {
36 MODIFY_DATA (U"Remove pulse(s)")
37 if (my startSelection() == my endSelection())
38 PointProcess_removePointNear (my pulses(), my startSelection());
39 else
40 PointProcess_removePointsBetween (my pulses(), my startSelection(), my endSelection());
41 MODIFY_DATA_END
42 }
43 static void menu_cb_addPulseAtCursor (ManipulationPulsesArea me, EDITOR_ARGS) {
44 MODIFY_DATA (U"Add pulse")
45 PointProcess_addPoint (my pulses(), 0.5 * (my startSelection() + my endSelection()));
46 MODIFY_DATA_END
47 }
48 static void menu_cb_addPulseAt (ManipulationPulsesArea me, EDITOR_ARGS) {
49 EDITOR_FORM (U"Add pulse", nullptr)
50 REAL (position, U"Position (s)", U"0.0")
51 EDITOR_OK
52 SET_REAL (position, 0.5 * (my startSelection() + my endSelection()))
53 EDITOR_DO
54 MODIFY_DATA (U"Add pulse")
55 PointProcess_addPoint (my pulses(), position);
56 MODIFY_DATA_END
57 EDITOR_END
58 }
59
60
61 #pragma mark - ManipPulsesArea all menus
62
63 void structManipulationPulsesArea :: v_createMenus () {
64 EditorMenu menu = Editor_addMenu (our functionEditor(), U"Pulse", 0);
65 FunctionAreaMenu_addCommand (menu, U"Add pulse at cursor", 'P',
66 menu_cb_addPulseAtCursor, this);
67 FunctionAreaMenu_addCommand (menu, U"Add pulse at...", 0,
68 menu_cb_addPulseAt, this);
69 FunctionAreaMenu_addCommand (menu, U"-- remove pulses --", 0, nullptr, this);
70 FunctionAreaMenu_addCommand (menu, U"Remove pulse(s)", GuiMenu_COMMAND_EXTRA | 'P',
71 menu_cb_removePulses, this);
72 }
73
74
75 #pragma mark - ManipulationSoundArea
76
77 Thing_implement (ManipulationSoundArea, SoundArea, 0);
78
79
80 #pragma mark - ManipPitchTierArea
81
82 Thing_implement (ManipulationPitchTierArea, PitchTierArea, 0);
83
84 #include "enums_getText.h"
85 #include "ManipulationEditor_enums.h"
86 #include "enums_getValue.h"
87 #include "ManipulationEditor_enums.h"
88
89 #include "Prefs_define.h"
90 #include "ManipulationEditor_prefs.h"
91 #include "Prefs_install.h"
92 #include "ManipulationEditor_prefs.h"
93 #include "Prefs_copyToInstance.h"
94 #include "ManipulationEditor_prefs.h"
95
96
97 #pragma mark - ManipPitchTierArea Modify
98
99 static void menu_cb_removePitchPoints (ManipulationPitchTierArea me, EDITOR_ARGS) {
100 if (! my pitch())
101 return;
102 MODIFY_DATA (U"Remove pitch point(s)")
103 if (my startSelection() == my endSelection())
104 AnyTier_removePointNear (my pitch()->asAnyTier(), my startSelection());
105 else
106 AnyTier_removePointsBetween (my pitch()->asAnyTier(), my startSelection(), my endSelection());
107 MODIFY_DATA_END
108 }
109 static void menu_cb_addPitchPointAtCursor (ManipulationPitchTierArea me, EDITOR_ARGS) {
110 if (! my pitch())
111 return;
112 MODIFY_DATA (U"Add pitch point")
113 RealTier_addPoint (my pitch(), 0.5 * (my startSelection() + my endSelection()), my ycursor);
114 MODIFY_DATA_END
115 }
116 static void menu_cb_addPitchPointAtSlice (ManipulationPitchTierArea me, EDITOR_ARGS) {
117 if (! my borrowedPulsesArea || ! my borrowedPulsesArea -> pulses())
118 Melder_throw (U"There are no pulses.");
119 if (! my pitch())
120 return;
121 const integer ileft = PointProcess_getLowIndex (my borrowedPulsesArea -> pulses(), 0.5 * (my startSelection() + my endSelection()));
122 const integer iright = ileft + 1, nt = my borrowedPulsesArea -> pulses() -> nt;
123 constVEC t = my borrowedPulsesArea -> pulses() -> t.get();
124 double desiredY = my ycursor; // default
125 MODIFY_DATA (U"Add pitch point")
126 if (nt <= 1) {
127 /* Ignore. */
128 } else if (ileft <= 0) {
129 double tright = t [2] - t [1];
130 if (tright > 0.0 && tright <= 0.02)
131 desiredY = 1.0 / tright;
132 } else if (iright > nt) {
133 double tleft = t [nt] - t [nt - 1];
134 if (tleft > 0.0 && tleft <= 0.02)
135 desiredY = 1.0 / tleft;
136 } else { // three-period median
137 double tmid = t [iright] - t [ileft], tleft = 0.0, tright = 0.0;
138 if (ileft > 1)
139 tleft = t [ileft] - t [ileft - 1];
140 if (iright < nt)
141 tright = t [iright + 1] - t [iright];
142 if (tleft > 0.02)
143 tleft = 0.0;
144 if (tmid > 0.02)
145 tmid = 0.0;
146 if (tright > 0.02)
147 tright = 0.0;
148 /* Bubble-sort. */
149 Melder_sort (& tleft, & tmid);
150 Melder_sort (& tleft, & tright);
151 Melder_sort (& tmid, & tright);
152 if (tleft != 0.0)
153 desiredY = 1.0 / tmid; // median of 3
154 else if (tmid != 0.0)
155 desiredY = 2.0 / (tmid + tright); // median of 2
156 else if (tright != 0.0)
157 desiredY = 1.0 / tright; // median of 1
158 }
159 RealTierArea_addPointAt (me, 0.5 * (my startSelection() + my endSelection()), desiredY);
160 MODIFY_DATA_END
161 }
162 static void menu_cb_addPitchPointAt (ManipulationPitchTierArea me, EDITOR_ARGS) {
163 EDITOR_FORM (U"Add pitch point", nullptr)
164 REAL (time, U"Time (s)", U"0.0")
165 REAL (frequency, U"Frequency (Hz or st)", U"100.0")
166 EDITOR_OK
167 SET_REAL (time, 0.5 * (my startSelection() + my endSelection()))
168 SET_REAL (frequency, my ycursor)
169 EDITOR_DO
170 if (! my pitch())
171 return;
172 MODIFY_DATA (U"Add pitch point")
173 RealTierArea_addPointAt (me, time, frequency);
174 MODIFY_DATA_END
175 EDITOR_END
176 }
177 static void menu_cb_stylizePitch (ManipulationPitchTierArea me, EDITOR_ARGS) {
178 EDITOR_FORM (U"Stylize pitch", U"PitchTier: Stylize...")
179 REAL (frequencyResolution, U"Frequency resolution", my default_pitch_stylize_frequencyResolution ())
180 CHOICE (units, U"Units", my default_pitch_stylize_useSemitones () + 1)
181 OPTION (U"Hertz")
182 OPTION (U"semitones")
183 EDITOR_OK
184 SET_REAL (frequencyResolution, my instancePref_pitch_stylize_frequencyResolution())
185 SET_OPTION (units, my instancePref_pitch_stylize_useSemitones() + 1)
186 EDITOR_DO
187 if (! my pitch())
188 return;
189 MODIFY_DATA (U"Stylize pitch")
190 my setInstancePref_pitch_stylize_frequencyResolution (frequencyResolution);
191 my setInstancePref_pitch_stylize_useSemitones (units - 1);
192 PitchTier_stylize (my pitch(), frequencyResolution, my instancePref_pitch_stylize_useSemitones());
193 MODIFY_DATA_END
194 EDITOR_END
195 }
196 static void menu_cb_stylizePitch_2st (ManipulationPitchTierArea me, EDITOR_ARGS) {
197 if (! my pitch())
198 return;
199 MODIFY_DATA (U"Stylize pitch")
200 PitchTier_stylize (my pitch(), 2.0, true);
201 MODIFY_DATA_END
202 }
203 static void menu_cb_interpolateQuadratically (ManipulationPitchTierArea me, EDITOR_ARGS) {
204 EDITOR_FORM (U"Interpolate quadratically", nullptr)
205 NATURAL (numberOfPointsPerParabola, U"Number of points per parabola", my default_pitch_interpolateQuadratically_numberOfPointsPerParabola ())
206 CHOICE (units, U"Units", my default_pitch_stylize_useSemitones () + 1)
207 OPTION (U"Hertz")
208 OPTION (U"semitones")
209 EDITOR_OK
210 SET_INTEGER (numberOfPointsPerParabola, my instancePref_pitch_interpolateQuadratically_numberOfPointsPerParabola())
211 SET_OPTION (units, my instancePref_pitch_stylize_useSemitones() + 1)
212 EDITOR_DO
213 if (! my pitch())
214 return;
215 MODIFY_DATA (U"Interpolate quadratically")
216 my setInstancePref_pitch_interpolateQuadratically_numberOfPointsPerParabola (numberOfPointsPerParabola);
217 my setInstancePref_pitch_stylize_useSemitones (units - 1);
218 RealTier_interpolateQuadratically (my pitch(), numberOfPointsPerParabola, my instancePref_pitch_stylize_useSemitones());
219 MODIFY_DATA_END
220 EDITOR_END
221 }
222 static void menu_cb_shiftPitchFrequencies (ManipulationPitchTierArea me, EDITOR_ARGS) {
223 EDITOR_FORM (U"Shift pitch frequencies", nullptr)
224 REAL (frequencyShift, U"Frequency shift", U"-20.0")
225 OPTIONMENU (unit_i, U"Unit", 1)
226 OPTION (U"Hertz")
227 OPTION (U"mel")
228 OPTION (U"logHertz")
229 OPTION (U"semitones")
230 OPTION (U"ERB")
231 EDITOR_OK
232 EDITOR_DO
233 kPitch_unit unit =
234 unit_i == 1 ? kPitch_unit::HERTZ :
235 unit_i == 2 ? kPitch_unit::MEL :
236 unit_i == 3 ? kPitch_unit::LOG_HERTZ :
237 unit_i == 4 ? kPitch_unit::SEMITONES_1 :
238 kPitch_unit::ERB;
239 if (! my pitch())
240 return;
241 MODIFY_DATA (U"Shift pitch frequencies")
242 try {
243 PitchTier_shiftFrequencies (my pitch(), my startSelection(), my endSelection(), frequencyShift, unit);
244 MODIFY_DATA_END
245 } catch (MelderError) {
246 // the PitchTier may have partially changed
247 MODIFY_DATA_END
248 throw;
249 }
250 EDITOR_END
251 }
252 static void menu_cb_multiplyPitchFrequencies (ManipulationPitchTierArea me, EDITOR_ARGS) {
253 EDITOR_FORM (U"Multiply pitch frequencies", nullptr)
254 POSITIVE (factor, U"Factor", U"1.2")
255 COMMENT (U"The multiplication is always done in hertz.")
256 EDITOR_OK
257 EDITOR_DO
258 if (! my pitch())
259 return;
260 MODIFY_DATA (U"Multiply pitch frequencies")
261 PitchTier_multiplyFrequencies (my pitch(), my startSelection(), my endSelection(), factor);
262 MODIFY_DATA_END
263 EDITOR_END
264 }
265 static void menu_cb_setPitchRange (ManipulationPitchTierArea me, EDITOR_ARGS) {
266 EDITOR_FORM (U"Set pitch range", nullptr)
267 REAL (dataFreeMinimum, U"Data-free minimum (Hz)", my default_dataFreeMinimum())
268 REAL (dataFreeMaximum, U"Data-free maximum (Hz)", my default_dataFreeMaximum())
269 EDITOR_OK
270 SET_REAL (dataFreeMinimum, my instancePref_dataFreeMinimum())
271 SET_REAL (dataFreeMaximum, my instancePref_dataFreeMaximum())
272 EDITOR_DO
273 my setInstancePref_dataFreeMinimum (dataFreeMinimum);
274 my setInstancePref_dataFreeMaximum (dataFreeMaximum);
275 my v_updateScaling (); // BUG: should be viewChanged()
276 FunctionEditor_redraw (my functionEditor());
277 EDITOR_END
278 }
279 void structManipulationPitchTierArea :: v_createMenus () {
280 EditorMenu menu = Editor_addMenu (our functionEditor(), U"Pitch", 0);
281
282 FunctionAreaMenu_addCommand (menu, U"Set pitch range...", 0,
283 menu_cb_setPitchRange, this);
284
285 FunctionAreaMenu_addCommand (menu, U"- Edit pitch:", 0, nullptr, this);
286 FunctionAreaMenu_addCommand (menu, U"Add pitch point at cursor", 'T' | GuiMenu_DEPTH_1,
287 menu_cb_addPitchPointAtCursor, this);
288 FunctionAreaMenu_addCommand (menu, U"Add pitch point at time slice", 1,
289 menu_cb_addPitchPointAtSlice, this);
290 FunctionAreaMenu_addCommand (menu, U"Add pitch point at...", 1,
291 menu_cb_addPitchPointAt, this);
292 FunctionAreaMenu_addCommand (menu, U"Remove pitch point(s)", GuiMenu_COMMAND_EXTRA | 'T' | GuiMenu_DEPTH_1,
293 menu_cb_removePitchPoints, this);
294
295 FunctionAreaMenu_addCommand (menu, U"- Modify selected pitch:", 0, nullptr, this);
296 FunctionAreaMenu_addCommand (menu, U"Shift pitch frequencies...", 1,
297 menu_cb_shiftPitchFrequencies, this);
298 FunctionAreaMenu_addCommand (menu, U"Multiply pitch frequencies...", 1,
299 menu_cb_multiplyPitchFrequencies, this);
300
301 FunctionAreaMenu_addCommand (menu, U"- Modify whole pitch:", 0, nullptr, this);
302 FunctionAreaMenu_addCommand (menu, U"Stylize pitch...", 1,
303 menu_cb_stylizePitch, this);
304 FunctionAreaMenu_addCommand (menu, U"Stylize pitch (2 st)", '2' | GuiMenu_DEPTH_1,
305 menu_cb_stylizePitch_2st, this);
306 FunctionAreaMenu_addCommand (menu, U"Interpolate quadratically...", 1,
307 menu_cb_interpolateQuadratically, this);
308 }
309
310
311 #pragma mark - ManipDurationTierArea
312
313 Thing_implement (ManipulationDurationTierArea, DurationTierArea, 0);
314
315 static void menu_cb_setDurationRange (ManipulationDurationTierArea me, EDITOR_ARGS) {
316 EDITOR_FORM (U"Set duration range", nullptr)
317 REAL (dataFreeMinimum, U"Data-free minimum", my default_dataFreeMinimum())
318 REAL (dataFreeMaximum, U"Data-free maximum", my default_dataFreeMaximum())
319 EDITOR_OK
320 SET_REAL (dataFreeMinimum, my instancePref_dataFreeMinimum())
321 SET_REAL (dataFreeMaximum, my instancePref_dataFreeMaximum())
322 EDITOR_DO
323 if (dataFreeMinimum > 1.0)
324 Melder_throw (U"Minimum relative duration should not be greater than 1.");
325 if (dataFreeMaximum < 1.0)
326 Melder_throw (U"Maximum relative duration should not be less than 1.");
327 if (dataFreeMinimum >= dataFreeMaximum)
328 Melder_throw (U"Maximum relative duration should be greater than minimum.");
329 my setInstancePref_dataFreeMinimum (dataFreeMinimum);
330 my setInstancePref_dataFreeMaximum (dataFreeMaximum);
331 my v_updateScaling ();
332 FunctionEditor_redraw (my functionEditor());
333 EDITOR_END
334 }
335 static void menu_cb_removeDurationPoints (ManipulationDurationTierArea me, EDITOR_ARGS) {
336 if (! my duration())
337 return;
338 MODIFY_DATA (U"Remove duration point(s)")
339 if (my startSelection() == my endSelection())
340 AnyTier_removePointNear (my duration()->asAnyTier(), 0.5 * (my startSelection() + my endSelection()));
341 else
342 AnyTier_removePointsBetween (my duration()->asAnyTier(), my startSelection(), my endSelection());
343 MODIFY_DATA_END
344 }
345 static void menu_cb_addDurationPointAtCursor (ManipulationDurationTierArea me, EDITOR_ARGS) {
346 if (! my duration())
347 return;
348 MODIFY_DATA (U"Add duration point")
349 RealTier_addPoint (my duration(), 0.5 * (my startSelection() + my endSelection()), my ycursor);
350 MODIFY_DATA_END
351 }
352 static void menu_cb_addDurationPointAt (ManipulationDurationTierArea me, EDITOR_ARGS) {
353 EDITOR_FORM (U"Add duration point", nullptr)
354 REAL (time, U"Time (s)", U"0.0");
355 REAL (relativeDuration, U"Relative duration", U"1.0");
356 EDITOR_OK
357 SET_REAL (time, 0.5 * (my startSelection() + my endSelection()))
358 EDITOR_DO
359 if (! my duration())
360 return;
361 MODIFY_DATA (U"Add duration point")
362 RealTierArea_addPointAt (me, time, relativeDuration);
363 MODIFY_DATA_END
364 EDITOR_END
365 }
366 void structManipulationDurationTierArea :: v_createMenus () {
367 EditorMenu menu = Editor_addMenu (our functionEditor(), U"Dur", 0);
368
369 FunctionAreaMenu_addCommand (menu, U"Set duration range...", 0,
370 menu_cb_setDurationRange, this);
371
372 FunctionAreaMenu_addCommand (menu, U"- Edit duration:", 0, nullptr, this);
373 FunctionAreaMenu_addCommand (menu, U"Add duration point at cursor", 'D' | GuiMenu_DEPTH_1,
374 menu_cb_addDurationPointAtCursor, this);
375 FunctionAreaMenu_addCommand (menu, U"Add duration point at...", 1,
376 menu_cb_addDurationPointAt, this);
377 FunctionAreaMenu_addCommand (menu, U"Remove duration point(s)", GuiMenu_COMMAND_EXTRA | 'D' | GuiMenu_DEPTH_1,
378 menu_cb_removeDurationPoints, this);
379 }
380
381 #pragma mark - ManipulationEditor
382
383 Thing_implement (ManipulationEditor, FunctionEditor, 0);
384
385 /*
386 * How to add a synthesis method (in an interruptable order):
387 * 1. add an Manipulation_ #define in Manipulation.h;
388 * 2. add a synthesize_ routine in Manipulation.cpp, and a reference to it in Manipulation_to_Sound;
389 * 3. add a button in ManipulationEditor.h;
390 * 4. add a cb_Synth_ callback.
391 * 5. create the button in createMenus and update updateMenus;
392 */
393
394 static const conststring32 units_strings [] = { 0, U"Hz", U"st" };
395
396 static int prefs_synthesisMethod = Manipulation_OVERLAPADD; /* Remembered across editor creations, not across Praat sessions. */
397
398 void structManipulationEditor :: v_updateMenuItems () {
399 ManipulationEditor_Parent :: v_updateMenuItems ();
400 Melder_assert (our synthPulsesButton);
401 GuiMenuItem_check (our synthPulsesButton, our synthesisMethod == Manipulation_PULSES);
402 Melder_assert (our synthPulsesHumButton);
403 GuiMenuItem_check (our synthPulsesHumButton, our synthesisMethod == Manipulation_PULSES_HUM);
404 Melder_assert (our synthPulsesLpcButton);
405 GuiMenuItem_check (our synthPulsesLpcButton, our synthesisMethod == Manipulation_PULSES_LPC);
406 Melder_assert (our synthPitchButton);
407 GuiMenuItem_check (our synthPitchButton, our synthesisMethod == Manipulation_PITCH);
408 Melder_assert (our synthPitchHumButton);
409 GuiMenuItem_check (our synthPitchHumButton, our synthesisMethod == Manipulation_PITCH_HUM);
410 Melder_assert (our synthPulsesPitchButton);
411 GuiMenuItem_check (our synthPulsesPitchButton, our synthesisMethod == Manipulation_PULSES_PITCH);
412 Melder_assert (our synthPulsesPitchHumButton);
413 GuiMenuItem_check (our synthPulsesPitchHumButton, our synthesisMethod == Manipulation_PULSES_PITCH_HUM);
414 Melder_assert (our synthOverlapAddButton);
415 GuiMenuItem_check (our synthOverlapAddButton, our synthesisMethod == Manipulation_OVERLAPADD);
416 Melder_assert (our synthPitchLpcButton);
417 GuiMenuItem_check (our synthPitchLpcButton, our synthesisMethod == Manipulation_PITCH_LPC);
418 }
419
420 /***** FILE MENU *****/
421
422 static void CONVERT_DATA_TO_ONE__ExtractOriginalSound (ManipulationEditor me, EDITOR_ARGS) {
423 CONVERT_DATA_TO_ONE
424 autoSound result = Data_copy (my soundArea() -> sound());
425 CONVERT_DATA_TO_ONE_END (U"untitled")
426 }
427
428 static void CONVERT_DATA_TO_ONE__ExtractPulses (ManipulationEditor me, EDITOR_ARGS) {
429 CONVERT_DATA_TO_ONE
430 autoPointProcess result = Data_copy (my pulsesArea() -> pulses());
431 CONVERT_DATA_TO_ONE_END (U"untitled")
432 }
433
434 static void CONVERT_DATA_TO_ONE__ExtractPitchTier (ManipulationEditor me, EDITOR_ARGS) {
435 CONVERT_DATA_TO_ONE
436 autoPitchTier result = Data_copy (my pitchTierArea() -> pitch());
437 CONVERT_DATA_TO_ONE_END (U"untitled")
438 }
439
440 static void CONVERT_DATA_TO_ONE__ExtractDurationTier (ManipulationEditor me, EDITOR_ARGS) {
441 CONVERT_DATA_TO_ONE
442 autoDurationTier result = Data_copy (my durationTierArea() -> duration());
443 CONVERT_DATA_TO_ONE_END (U"untitled")
444 }
445
446 static void CONVERT_DATA_TO_ONE__ExtractManipulatedSound (ManipulationEditor me, EDITOR_ARGS) {
447 CONVERT_DATA_TO_ONE
448 autoSound result = Manipulation_to_Sound (my manipulation(), my synthesisMethod);
449 CONVERT_DATA_TO_ONE_END (U"untitled")
450 }
451
452 /***** EDIT MENU *****/
453
454 //void structManipulationEditor :: v_saveData () {
455 // our previousPulses = Data_copy (our manipulation() -> pulses.get()); // could be null
456 // our previousPitch = Data_copy (our manipulation() -> pitch.get()); // could be null
457 // our previousDuration = Data_copy (our manipulation() -> duration.get()); // could be null
458 //}
459
460 //void structManipulationEditor :: v_restoreData () {
461 // std::swap (our manipulation() -> pulses, our previousPulses); // could be null
462 // std::swap (our manipulation() -> pitch, our previousPitch); // could be null
463 // std::swap (our manipulation() -> duration, our previousDuration); // could be null
464 //}
465
466
467 static void menu_cb_ManipulationEditorHelp (ManipulationEditor, EDITOR_ARGS) { Melder_help (U"ManipulationEditor"); }
468 static void menu_cb_ManipulationHelp (ManipulationEditor, EDITOR_ARGS) { Melder_help (U"Manipulation"); }
469
470 #define menu_cb_Synth_common(menu_cb,meth) \
471 static void menu_cb (ManipulationEditor me, EDITOR_ARGS) { \
472 prefs_synthesisMethod = my synthesisMethod = meth; \
473 my v_updateMenuItems (); /* once this change should be reflected graphically, use FunctionEditor_redraw() instead */ \
474 }
475 menu_cb_Synth_common (menu_cb_Synth_Pulses, Manipulation_PULSES)
476 menu_cb_Synth_common (menu_cb_Synth_Pulses_hum, Manipulation_PULSES_HUM)
477 menu_cb_Synth_common (menu_cb_Synth_Pulses_Lpc, Manipulation_PULSES_LPC)
478 menu_cb_Synth_common (menu_cb_Synth_Pitch, Manipulation_PITCH)
479 menu_cb_Synth_common (menu_cb_Synth_Pitch_hum, Manipulation_PITCH_HUM)
480 menu_cb_Synth_common (menu_cb_Synth_Pulses_Pitch, Manipulation_PULSES_PITCH)
481 menu_cb_Synth_common (menu_cb_Synth_Pulses_Pitch_hum, Manipulation_PULSES_PITCH_HUM)
482 menu_cb_Synth_common (menu_cb_Synth_OverlapAdd_nodur, Manipulation_OVERLAPADD_NODUR)
483 menu_cb_Synth_common (menu_cb_Synth_OverlapAdd, Manipulation_OVERLAPADD)
484 menu_cb_Synth_common (menu_cb_Synth_Pitch_Lpc, Manipulation_PITCH_LPC)
485
486 void structManipulationEditor :: v_createMenus () {
487 ManipulationEditor_Parent :: v_createMenus ();
488
489 Editor_addCommand (this, U"File", U"Extract original sound", 0,
490 CONVERT_DATA_TO_ONE__ExtractOriginalSound);
491 Editor_addCommand (this, U"File", U"Extract pulses", 0,
492 CONVERT_DATA_TO_ONE__ExtractPulses);
493 Editor_addCommand (this, U"File", U"Extract pitch tier", 0,
494 CONVERT_DATA_TO_ONE__ExtractPitchTier);
495 Editor_addCommand (this, U"File", U"Extract duration tier", 0,
496 CONVERT_DATA_TO_ONE__ExtractDurationTier);
497 Editor_addCommand (this, U"File", U"Publish resynthesis", 0,
498 CONVERT_DATA_TO_ONE__ExtractManipulatedSound);
499 Editor_addCommand (this, U"File", U"-- close --", 0, nullptr);
500
501 Editor_addMenu (this, U"Synth", 0);
502 our synthPulsesButton = Editor_addCommand (this, U"Synth", U"Pulses --", GuiMenu_RADIO_FIRST, menu_cb_Synth_Pulses);
503 our synthPulsesHumButton = Editor_addCommand (this, U"Synth", U"Pulses (hum) --", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pulses_hum);
504
505 our synthPulsesLpcButton = Editor_addCommand (this, U"Synth", U"Pulses & LPC -- (\"LPC resynthesis\")", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pulses_Lpc);
506 Editor_addCommand (this, U"Synth", U"-- pitch resynth --", 0, nullptr);
507 our synthPitchButton = Editor_addCommand (this, U"Synth", U" -- Pitch", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pitch);
508 our synthPitchHumButton = Editor_addCommand (this, U"Synth", U" -- Pitch (hum)", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pitch_hum);
509 our synthPulsesPitchButton = Editor_addCommand (this, U"Synth", U"Pulses -- Pitch", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pulses_Pitch);
510 our synthPulsesPitchHumButton = Editor_addCommand (this, U"Synth", U"Pulses -- Pitch (hum)", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pulses_Pitch_hum);
511 Editor_addCommand (this, U"Synth", U"-- full resynth --", 0, nullptr);
512 our synthOverlapAddButton = Editor_addCommand (this, U"Synth", U"Sound & Pulses -- Pitch & Duration (\"Overlap-add manipulation\")", GuiMenu_RADIO_NEXT | GuiMenu_TOGGLE_ON, menu_cb_Synth_OverlapAdd);
513 our synthPitchLpcButton = Editor_addCommand (this, U"Synth", U"LPC -- Pitch (\"LPC pitch manipulation\")", GuiMenu_RADIO_NEXT, menu_cb_Synth_Pitch_Lpc);
514 }
515
516 void structManipulationEditor :: v_createMenuItems_help (EditorMenu menu) {
517 ManipulationEditor_Parent :: v_createMenuItems_help (menu);
518 EditorMenu_addCommand (menu, U"ManipulationEditor help", '?', menu_cb_ManipulationEditorHelp);
519 EditorMenu_addCommand (menu, U"Manipulation help", 0, menu_cb_ManipulationHelp);
520 }
521
522 /********** DRAWING AREA **********/
523
524 void structManipulationPitchTierArea :: v_drawInside () {
525 const bool cursorVisible = (
526 our startSelection() == our endSelection() &&
527 our startSelection() >= our startWindow() &&
528 our startSelection() <= our endWindow()
529 );
530 Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), our ymin, our ymax);
531
532 /*
533 Draw pitch contour based on pulses.
534 */
535 Graphics_setGrey (graphics(), 0.7);
536 /* BUG: should include grey dots */
537 constPointProcess pulses = ((ManipulationEditor) functionEditor()) -> manipulation() -> pulses.get();
538 if (pulses) for (integer i = 1; i < pulses -> nt; i ++) {
539 const double tleft = pulses -> t [i], tright = pulses -> t [i + 1], t = 0.5 * (tleft + tright);
540 if (t >= startWindow() && t <= endWindow()) {
541 if (tleft != tright) {
542 const double y = 1.0 / (tright - tleft);
543 if (y >= our ymin && y <= our ymax)
544 Graphics_fillCircle_mm (our graphics(), t, y, 1.0);
545 }
546 }
547 }
548 Graphics_setGrey (graphics(), 0.0);
549
550 constexpr double minimumFrequency = 50.0;
551 FunctionEditor_drawGridLine (our functionEditor(), minimumFrequency);
552
553 const integer n = ( our pitchTier() ? our pitchTier() -> points.size : 0 );
554 if (cursorVisible && n > 0) {
555 const double y = RealTier_getValueAtTime (our pitchTier(), our startSelection());
556 FunctionEditor_insertCursorFunctionValue (our functionEditor(), y,
557 Melder_fixed (y, 1), U" Hz",
558 our ymin, our ymax);
559 }
560 our ManipulationPitchTierArea_Parent :: v_drawInside ();
561 }
562
563 void structManipulationDurationTierArea :: v_drawInside () {
564 const bool cursorVisible = (
565 our startSelection() == our endSelection() &&
566 our startSelection() >= our startWindow() &&
567 our startSelection() <= our endWindow()
568 );
569 Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), our ymin, our ymax);
570 FunctionEditor_drawGridLine (our functionEditor(), 1.0); // BUG: should move to FunctionArea
571 if (cursorVisible && our durationTier() -> points.size > 0) {
572 const double y = RealTier_getValueAtTime (our durationTier(), our startSelection());
573 FunctionEditor_insertCursorFunctionValue (our functionEditor(), y, // BUG: should move to FunctionArea
574 Melder_fixed (y, 3), U"", our ymin, our ymax);
575 }
576 our ManipulationDurationTierArea_Parent :: v_drawInside ();
577 }
578
579 void structManipulationEditor :: v_play (double startTime, double endTime) {
580 if (our clickWasModifiedByShiftKey) {
581 Sound_playPart (our soundArea() -> sound(), startTime, endTime, theFunctionEditor_playCallback, this);
582 } else {
583 Manipulation_playPart (our manipulation(), startTime, endTime, our synthesisMethod);
584 }
585 }
586
587 autoManipulationEditor ManipulationEditor_create (conststring32 title, Manipulation manipulation) {
588 try {
589 autoManipulationEditor me = Thing_new (ManipulationEditor);
590 my soundArea() = ManipulationSoundArea_create (false, nullptr, me.get());
591 my pulsesArea() = ManipulationPulsesArea_create (true, nullptr, me.get());
592 my pitchTierArea() = ManipulationPitchTierArea_create (true, nullptr, me.get());
593 my pitchTierArea() -> borrowedPulsesArea = my pulsesArea().get();
594 my durationTierArea() = ManipulationDurationTierArea_create (true, nullptr, me.get());
595 FunctionEditor_init (me.get(), title, manipulation);
596
597 my synthesisMethod = prefs_synthesisMethod; // BUG: should be in v1_dataChanged()
598 //my v_updateMenuItems (); // BUG: should not be necessary
599 return me;
600 } catch (MelderError) {
601 Melder_throw (U"Manipulation window not created.");
602 }
603 }
604
605 /* End of file ManipulationEditor.cpp */