1 /* SpectrogramEditor.cpp
2 *
3 * Copyright (C) 1992-2005,2007-2012,2014-2020 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "SpectrogramEditor.h"
20
21 Thing_implement (SpectrogramEditor, FunctionEditor, 0);
22
v_draw()23 void structSpectrogramEditor :: v_draw () {
24 Spectrogram spectrogram = (Spectrogram) our data;
25
26 Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
27 Graphics_setColour (our graphics.get(), Melder_WHITE);
28 Graphics_fillRectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
29 Graphics_setColour (our graphics.get(), Melder_BLACK);
30 Graphics_rectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
31
32 integer itmin, itmax;
33 Sampled_getWindowSamples (spectrogram, our startWindow, our endWindow, & itmin, & itmax);
34
35 /*
36 Autoscale frequency axis.
37 */
38 our maximum = spectrogram -> ymax;
39
40 Graphics_setWindow (our graphics.get(), our startWindow, our endWindow, 0.0, our maximum);
41 Spectrogram_paintInside (spectrogram, our graphics.get(), our startWindow, our endWindow, 0, 0, 0.0, true,
42 60, 6.0, 0);
43
44 /*
45 Horizontal scaling lines.
46 */
47 Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, our maximum);
48 Graphics_setTextAlignment (our graphics.get(), Graphics_RIGHT, Graphics_HALF);
49 Graphics_setColour (our graphics.get(), Melder_RED);
50 integer df = 1000;
51 for (integer f = df; f <= our maximum; f += df) {
52 Graphics_line (our graphics.get(), 0.0, f, 1.0, f);
53 Graphics_text (our graphics.get(), -0.01, f, f, U" Hz");
54 }
55
56 /*
57 Vertical cursor lines.
58 */
59 Graphics_setWindow (our graphics.get(), our startWindow, our endWindow, 0.0, our maximum);
60 if (our startSelection > our startWindow && our startSelection < our endWindow)
61 Graphics_line (our graphics.get(), our startSelection, 0, our startSelection, our maximum);
62 if (our endSelection > our startWindow && our endSelection < our endWindow)
63 Graphics_line (our graphics.get(), our endSelection, 0, our endSelection, our maximum);
64 Graphics_setColour (our graphics.get(), Melder_BLACK);
65 }
66
v_mouseInWideDataView(GuiDrawingArea_MouseEvent event,double x_world,double y_fraction)67 bool structSpectrogramEditor :: v_mouseInWideDataView (GuiDrawingArea_MouseEvent event, double x_world, double y_fraction) {
68 if (event -> isClick()) {
69 Spectrogram spectrogram = (Spectrogram) our data;
70 double clickedFrequency = y_fraction * our maximum;
71 Melder_assert (spectrogram -> nx >= 1);
72 const integer clickedFrame = Melder_clipped (1_integer, Sampled_xToNearestIndex (spectrogram, x_world), spectrogram -> nx);
73 // TODO
74 }
75 return our SpectrogramEditor_Parent :: v_mouseInWideDataView (event, x_world, y_fraction);
76 }
77
SpectrogramEditor_create(conststring32 title,Spectrogram data)78 autoSpectrogramEditor SpectrogramEditor_create (conststring32 title, Spectrogram data) {
79 try {
80 autoSpectrogramEditor me = Thing_new (SpectrogramEditor);
81 FunctionEditor_init (me.get(), title, data);
82 my maximum = 10000.0;
83 return me;
84 } catch (MelderError) {
85 Melder_throw (U"Spectrogram window not created.");
86 }
87 }
88
89 /* End of file SpectrogramEditor.cpp */
90