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 : #pragma once
24 :
25 : #include <climits>
26 :
27 : #include "../types/propertyvalue.h"
28 :
29 : namespace mu::engraving {
30 : class EngravingItem;
31 :
32 : enum class Pid : short;
33 :
34 : //---------------------------------------------------------
35 : // Location
36 : //---------------------------------------------------------
37 :
38 : class Location
39 : {
40 : public:
41 30044 : constexpr Location(int staff, int voice, int measure, Fraction frac, int graceIndex, int note, bool rel)
42 30044 : : m_staff(staff), m_voice(voice), m_measure(measure), m_frac(frac), m_graceIndex(graceIndex), m_note(note), m_rel(rel)
43 : {
44 30044 : }
45 :
46 26141 : static constexpr Location absolute()
47 : {
48 26141 : return Location(INT_MIN, INT_MIN, INT_MIN, Fraction(INT_MIN, 1), INT_MIN, INT_MIN, false);
49 : }
50 :
51 3903 : static constexpr Location relative() { return Location(0, 0, 0, Fraction(0, 1), INT_MIN, 0, true); }
52 :
53 : void toAbsolute(const Location& ref);
54 : void toRelative(const Location& ref);
55 :
56 12009 : bool isAbsolute() const { return !m_rel; }
57 1129 : bool isRelative() const { return m_rel; }
58 :
59 1614 : int staff() const { return m_staff; }
60 1042 : void setStaff(int staff) { m_staff = staff; }
61 580 : int voice() const { return m_voice; }
62 31 : void setVoice(int voice) { m_voice = voice; }
63 : int track() const;
64 : void setTrack(int track);
65 50650 : int measure() const { return m_measure; }
66 7523 : void setMeasure(int measure) { m_measure = measure; }
67 22585 : Fraction frac() const { return m_frac; }
68 10161 : void setFrac(Fraction frac) { m_frac = frac; }
69 4413 : int graceIndex() const { return m_graceIndex; }
70 3977 : void setGraceIndex(int index) { m_graceIndex = index; }
71 2061 : int note() const { return m_note; }
72 3909 : void setNote(int note) { m_note = note; }
73 :
74 : void fillForElement(const EngravingItem* e, bool absfrac = true);
75 : void fillPositionForElement(const EngravingItem* e, bool absfrac = true);
76 : static Location forElement(const EngravingItem* e, bool absfrac = true);
77 : static Location positionForElement(const EngravingItem* e, bool absfrac = true);
78 : static PropertyValue getLocationProperty(Pid pid, const EngravingItem* start, const EngravingItem* end);
79 :
80 286 : void setIsTimeTick(bool v) { m_isTimeTick = v; }
81 503 : bool isTimeTick() const { return m_isTimeTick; }
82 :
83 : bool operator==(const Location& other) const;
84 : bool operator!=(const Location& other) const { return !(*this == other); }
85 :
86 : private:
87 :
88 : static int track(const EngravingItem* e);
89 : static int measure(const EngravingItem* e);
90 : static int graceIndex(const EngravingItem* e);
91 : static int note(const EngravingItem* e);
92 :
93 : int m_staff = 0;
94 : int m_voice = 0;
95 : int m_measure = 0;
96 : Fraction m_frac;
97 : int m_graceIndex = 0;
98 : int m_note = 0;
99 : bool m_rel = false;
100 : bool m_isTimeTick = false;
101 : };
102 : }
|