Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2023 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include "layoutcontext.h"
26 :
27 : namespace mu::engraving {
28 : class Chord;
29 : class Stem;
30 : class StaffType;
31 : class Rest;
32 : }
33 :
34 : namespace mu::engraving::rendering::score {
35 : class StemLayout
36 : {
37 : public:
38 : // all in spatium units
39 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMLEN_UP = 3.0;
40 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMDIST_UP = 1.0;
41 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMPOSY_UP = -STAFFTYPE_TAB_DEFAULTSTEMDIST_UP;
42 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMLEN_DN = 3.0;
43 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMDIST_DN = 1.0;
44 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMPOSY_DN = STAFFTYPE_TAB_DEFAULTSTEMDIST_DN;
45 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMLEN_THRU = 3.5;
46 : static constexpr double STAFFTYPE_TAB_DEFAULTSTEMPOSX = 0.75;
47 : // TAB STEM NOTATION
48 : // the ratio between the length of a full stem and the length of a short stem
49 : // (used for half note stems, in some TAB styles)
50 : static constexpr double STAFFTYPE_TAB_SHORTSTEMRATIO = 0.5;
51 : // metrics of slashes through half note stems
52 : static constexpr double STAFFTYPE_TAB_SLASH_WIDTH = 1.2; /* X width of half note slash */
53 : static constexpr double STAFFTYPE_TAB_SLASH_SLANTY = 0.8; /* the Y coord of the slash slant */
54 : static constexpr double STAFFTYPE_TAB_SLASH_THICK = 0.4; /* slash thickness */
55 : static constexpr double STAFFTYPE_TAB_SLASH_DISPL = 0.8; /* the total displacement between one slash and the next:
56 : includes slash thickness and empty space between slashes*/
57 : // the total height of a double slash
58 : static constexpr double STAFFTYPE_TAB_SLASH_2TOTHEIGHT
59 : = (STAFFTYPE_TAB_SLASH_THICK + STAFFTYPE_TAB_SLASH_DISPL + STAFFTYPE_TAB_SLASH_SLANTY);
60 : // the initial Y coord for a double shash on an UP stem = topmost corner of topmost slash
61 : static constexpr double STAFFTYPE_TAB_SLASH_2STARTY_UP = ((STAFFTYPE_TAB_DEFAULTSTEMLEN_UP - STAFFTYPE_TAB_SLASH_2TOTHEIGHT) * 0.5);
62 : // the initial Y coord for a double shash on an DN stem = topmost corner of topmost slash
63 : static constexpr double STAFFTYPE_TAB_SLASH_2STARTY_DN = ((STAFFTYPE_TAB_DEFAULTSTEMLEN_UP + STAFFTYPE_TAB_SLASH_2TOTHEIGHT) * 0.5);
64 :
65 : static double calcDefaultStemLength(Chord* item, const LayoutContext& ctx);
66 : static int minStaffOverlap(bool up, int staffLines, int beamCount, bool hasHook, double beamSpacing, bool useWideBeams,
67 : bool isFullSize);
68 :
69 : static double stemPosX(const ChordRest* item);
70 : static double stemPosX(const Chord* item);
71 : static double stemPosX(const Rest* item);
72 :
73 : static PointF stemPos(const ChordRest* item);
74 : static PointF stemPos(const Chord* item);
75 : static PointF stemPos(const Rest* item);
76 :
77 : static double tabStemLength(const Chord* item, const StaffType* st);
78 83 : static double tabStemPosX() { return STAFFTYPE_TAB_DEFAULTSTEMPOSX; }
79 : static double tabRestStemPosY(const ChordRest* item, const StaffType* st);
80 : static PointF tabStemPos(const Chord* item, const StaffType* st);
81 :
82 : private:
83 : static int stemLengthBeamAddition(const Chord* item, const LayoutContext& ctx);
84 : static int maxReduction(const Chord* item, const LayoutContext& ctx, int extensionOutsideStaff);
85 : static int stemOpticalAdjustment(const Chord* item, int stemEndPosition);
86 : static int calcMinStemLength(Chord* item, const LayoutContext& ctx);
87 : static int calc4BeamsException(const Chord* item, int stemLength);
88 :
89 : static inline int calcBeamCount(const Chord* item);
90 : };
91 : } // namespace mu::engraving::rendering::score
|