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) 2021 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 : #include "hook.h"
24 :
25 : #include "style/style.h"
26 :
27 : #include "chord.h"
28 :
29 : #include "log.h"
30 :
31 : using namespace mu;
32 : using namespace mu::engraving;
33 :
34 1269 : Hook::Hook(DummyParentOr<Chord> parent)
35 1269 : : Symbol(ElementType::HOOK, parent, ElementFlag::NOTHING)
36 : {
37 1269 : setZ(int(type()) * 100);
38 1269 : }
39 :
40 0 : EngravingItem* Hook::elementBase() const
41 : {
42 0 : return chord();
43 : }
44 :
45 3491 : void Hook::setHookType(int i)
46 : {
47 3491 : bool straight = style().styleB(Sid::useStraightNoteFlags);
48 3491 : m_hookType = i;
49 3491 : setSym(symIdForHookIndex(i, straight));
50 3491 : }
51 :
52 6680 : PointF Hook::smuflAnchor() const
53 : {
54 6680 : return symSmuflAnchor(m_sym, chord()->up() ? SmuflAnchorId::stemUpNW : SmuflAnchorId::stemDownSW);
55 : }
56 :
57 3491 : SymId Hook::symIdForHookIndex(int index, bool straight)
58 : {
59 3491 : switch (index) {
60 21 : case 0:
61 21 : return SymId::noSym;
62 1434 : case 1:
63 1434 : return straight ? SymId::flag8thUpStraight : SymId::flag8thUp;
64 94 : case 2:
65 94 : return straight ? SymId::flag16thUpStraight : SymId::flag16thUp;
66 47 : case 3:
67 47 : return straight ? SymId::flag32ndUpStraight : SymId::flag32ndUp;
68 7 : case 4:
69 7 : return straight ? SymId::flag64thUpStraight : SymId::flag64thUp;
70 6 : case 5:
71 6 : return straight ? SymId::flag128thUpStraight : SymId::flag128thUp;
72 0 : case 6:
73 0 : return straight ? SymId::flag256thUpStraight : SymId::flag256thUp;
74 0 : case 7:
75 0 : return straight ? SymId::flag512thUpStraight : SymId::flag512thUp;
76 0 : case 8:
77 0 : return straight ? SymId::flag1024thUpStraight : SymId::flag1024thUp;
78 :
79 1538 : case -1:
80 1538 : return straight ? SymId::flag8thDownStraight : SymId::flag8thDown;
81 295 : case -2:
82 295 : return straight ? SymId::flag16thDownStraight : SymId::flag16thDown;
83 32 : case -3:
84 32 : return straight ? SymId::flag32ndDownStraight : SymId::flag32ndDown;
85 7 : case -4:
86 7 : return straight ? SymId::flag64thDownStraight : SymId::flag64thDown;
87 10 : case -5:
88 10 : return straight ? SymId::flag128thDownStraight : SymId::flag128thDown;
89 0 : case -6:
90 0 : return straight ? SymId::flag256thDownStraight : SymId::flag256thDown;
91 0 : case -7:
92 0 : return straight ? SymId::flag512thDownStraight : SymId::flag512thDown;
93 0 : case -8:
94 0 : return straight ? SymId::flag1024thDownStraight : SymId::flag1024thDown;
95 0 : default:
96 0 : LOGE() << "No hook/flag for hook index: " << index;
97 0 : break;
98 : }
99 :
100 0 : return SymId::noSym;
101 : }
|