Debian Codegraph @

foned/SpectrogramArea.cpp

raw
1 /* SpectrogramArea.cpp
2 *
3 * Copyright (C) 1992-2005,2007-2012,2014-2022,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 "SpectrogramArea.h"
20
21 Thing_implement (SpectrogramArea, FunctionArea, 0);
22
23 void structSpectrogramArea :: v_drawInside () {
24 integer itmin, itmax;
25 Sampled_getWindowSamples (our spectrogram(), our startWindow(), our endWindow(), & itmin, & itmax);
26
27 /*
28 Autoscale frequency axis.
29 */
30 our maximum = our spectrogram() -> ymax;
31
32 Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), 0.0, our maximum);
33 Spectrogram_paintInside (our spectrogram(), our graphics(), our startWindow(), our endWindow(), 0, 0, 0.0, true,
34 60, 6.0, 0, kSpectrogram_colourMap::GREY, false);
35
36 /*
37 Horizontal scaling lines.
38 */
39 Graphics_setWindow (our graphics(), 0.0, 1.0, 0.0, our maximum);
40 Graphics_setTextAlignment (our graphics(), Graphics_RIGHT, Graphics_HALF);
41 Graphics_setColour (our graphics(), Melder_RED);
42 Graphics_setLineType (our graphics(), Graphics_DOTTED);
43 const integer df = 1000;
44 for (integer f = 0; f <= our maximum; f += df) {
45 if (f != 0.0 && f != our maximum)
46 Graphics_line (our graphics(), 0.0, f, 1.0, f);
47 Graphics_text (our graphics(), 0.0, f, f, U" Hz");
48 }
49 Graphics_setLineType (our graphics(), Graphics_DRAWN);
50 if (our frequencyCursor > 0.0 && our frequencyCursor < our maximum) {
51 Graphics_line (our graphics(), 0.0, our frequencyCursor, 1.0, our frequencyCursor);
52 Graphics_setTextAlignment (our graphics(), Graphics_LEFT, Graphics_HALF);
53 Graphics_text (our graphics(), 1.0, our frequencyCursor, Melder_iround (our frequencyCursor), U" Hz");
54 }
55
56 /*
57 Vertical cursor lines.
58 */
59 Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), 0.0, our maximum);
60 if (our startSelection() > our startWindow() && our startSelection() < our endWindow())
61 Graphics_line (our graphics(), our startSelection(), 0, our startSelection(), our maximum);
62 if (our endSelection() > our startWindow() && our endSelection() < our endWindow())
63 Graphics_line (our graphics(), our endSelection(), 0, our endSelection(), our maximum);
64 Graphics_setColour (our graphics(), Melder_BLACK);
65 }
66
67 bool structSpectrogramArea :: v_mouse (GuiDrawingArea_MouseEvent event, double x_world, double localY_fraction) {
68 our frequencyCursor = localY_fraction * our maximum;
69 const integer clickedFrame = Melder_clipped (1_integer, Sampled_xToNearestIndex (our spectrogram(), x_world), our spectrogram() -> nx); // TODO
70 return FunctionEditor_defaultMouseInWideDataView (our functionEditor(), event, x_world) || true;
71 }
72
73 /* End of file SpectrogramArea.cpp */