Debian Codegraph @

foned/RealTierArea.h

raw
1 #ifndef _RealTierArea_h_
2 #define _RealTierArea_h_
3 /* RealTierArea.h
4 *
5 * Copyright (C) 1992-2005,2007-2012,2015-2018,2020-2022 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "FunctionArea.h"
22 #include "RealTier.h"
23
24 Thing_define (RealTierArea, FunctionArea) {
25 RealTier realTier() { return static_cast <RealTier> (our function()); }
26
27 virtual double v_minimumLegalY () { return undefined; }
28 virtual double v_maximumLegalY () { return undefined; }
29
30 double ymin, ymax, ycursor = 1.0; // BUG: this should be in a cache
31 public: // BUG: should be "protected" (now public because it is sometimes used as a message)
32 virtual void v_updateScaling () {
33 /*
34 Computes ymin, ymax and ycursor on the basis of the data.
35 */
36 Melder_assert (isdefined (our instancePref_dataFreeMinimum()));
37 Melder_assert (isdefined (our instancePref_dataFreeMaximum()));
38 our ymin = our instancePref_dataFreeMinimum();
39 our ymax = our instancePref_dataFreeMaximum();
40 if (our realTier() && our realTier() -> points.size > 0) {
41 Melder_assert (! (our v_maximumLegalY() < our v_minimumLegalY())); // NaN-safe
42 const double minimumValue = Melder_clipped (our v_minimumLegalY(), RealTier_getMinimumValue (our realTier()), our v_maximumLegalY());
43 const double maximumValue = Melder_clipped (our v_minimumLegalY(), RealTier_getMaximumValue (our realTier()), our v_maximumLegalY());
44 Melder_clipRight (& our ymin, minimumValue);
45 Melder_clipLeft (maximumValue, & our ymax);
46 }
47 if (our ycursor <= our ymin || our ycursor >= our ymax)
48 our ycursor = 0.382 * our ymin + 0.618 * our ymax;
49 }
50 protected:
51 void v_computeAuxiliaryData () override {
52 our RealTierArea_Parent :: v_computeAuxiliaryData ();
53 our v_updateScaling ();
54 }
55
56 public:
57 virtual conststring32 v_rightTickUnits () { return U""; }
58
59 double anchorTime = undefined, anchorY;
60 bool anchorIsInFreePart, anchorIsNearPoint; // only in cb_mouse
61 bool draggingSelection;
62 double dt = 0.0, dy = 0.0;
63 integer firstSelected, lastSelected;
64
65 void viewRealTierAsWorldByWorld () const {
66 FunctionArea_setViewport (this);
67 Graphics_setWindow (our graphics(), our startWindow(), our endWindow(), our ymin, our ymax);
68 }
69 void v_drawInside ()
70 override;
71 bool v_mouse (GuiDrawingArea_MouseEvent event, double x_world, double localY_fraction)
72 override;
73 void v_createMenus ()
74 override;
75
76 virtual conststring32 v_menuTitle () { return U"RealTier"; }
77 virtual conststring32 v_quantityText () { return U"Y"; } // normally includes units
78 virtual conststring32 v_setRangeTitle () { return U"Set range..."; }
79 virtual conststring32 v_minimumLabelText () { return U"Minimum"; } // normally includes units
80 virtual conststring32 v_maximumLabelText () { return U"Maximum"; } // normally includes units
81
82 #include "RealTierArea_prefs.h"
83 };
84
85 void RealTierArea_addPointAt (RealTierArea me, double time, double desiredY);
86
87 void RealTierArea_removePoints (RealTierArea me);
88
89 void RealTierArea_addPointAtCursor (RealTierArea me);
90
91 DEFINE_FunctionArea_create (RealTierArea, RealTier)
92
93 /* End of file RealTierArea.h */
94 #endif