MuseScore  3.4
Music composition and notation
location.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2018 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __POINT_H__
14 #define __POINT_H__
15 
16 #include "fraction.h"
17 
18 #include <climits>
19 
20 namespace Ms {
21 
22 class Element;
23 class XmlReader;
24 class XmlWriter;
25 
26 enum class Pid;
27 
28 //---------------------------------------------------------
29 // Location
30 //---------------------------------------------------------
31 
32 class Location {
33  int _staff;
34  int _voice;
35  int _measure;
38  int _note;
39  bool _rel;
40 
41  static int track(const Element* e);
42  static int measure(const Element* e);
43  static int graceIndex(const Element* e);
44  static int note(const Element* e);
45 
46  public:
47  constexpr Location(int staff, int voice, int measure, Fraction frac, int graceIndex, int note, bool rel)
48  : _staff(staff), _voice(voice), _measure(measure), _frac(frac), _graceIndex(graceIndex), _note(note), _rel(rel) {}
49 
50  static constexpr Location absolute() { return Location(INT_MIN, INT_MIN, INT_MIN, Fraction(INT_MIN,1), INT_MIN, INT_MIN, false); }
51  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  void write(XmlWriter& xml) const;
57  void read(XmlReader& e);
58 
59  bool isAbsolute() const { return !_rel; }
60  bool isRelative() const { return _rel; }
61 
62  int staff() const { return _staff; }
63  void setStaff(int staff) { _staff = staff; }
64  int voice() const { return _voice; }
65  void setVoice(int voice) { _voice = voice; }
66  int track() const;
67  void setTrack(int track);
68  int measure() const { return _measure; }
69  void setMeasure(int measure) { _measure = measure; }
70  Fraction frac() const { return _frac; }
71  void setFrac(Fraction frac) { _frac = frac; }
72  int graceIndex() const { return _graceIndex; }
73  void setGraceIndex(int index) { _graceIndex = index; }
74  int note() const { return _note; }
75  void setNote(int note) { _note = note; }
76 
77  void fillForElement(const Element* e, bool absfrac = true);
78  void fillPositionForElement(const Element* e, bool absfrac = true);
79  static Location forElement(const Element* e, bool absfrac = true);
80  static Location positionForElement(const Element* e, bool absfrac = true);
81  static QVariant getLocationProperty(Pid pid, const Element* start, const Element* end);
82 
83  bool operator==(const Location& other) const;
84  bool operator!=(const Location& other) const { return !(*this == other); }
85  };
86 
87 } // namespace Ms
88 #endif
int _graceIndex
Definition: location.h:37
int track() const
Definition: location.cpp:30
int graceIndex() const
Definition: location.h:72
int note() const
Definition: location.h:74
constexpr Location(int staff, int voice, int measure, Fraction frac, int graceIndex, int note, bool rel)
Definition: location.h:47
Pid
Definition: property.h:62
Definition: xml.h:67
void setFrac(Fraction frac)
Definition: location.h:71
void setTrack(int track)
Definition: location.cpp:41
bool operator!=(const Location &other) const
Definition: location.h:84
Base class of score layout elements.
Definition: element.h:158
int _measure
Definition: location.h:35
void setGraceIndex(int index)
Definition: location.h:73
int measure() const
Definition: location.h:68
void read(XmlReader &e)
Definition: location.cpp:69
void setMeasure(int measure)
Definition: location.h:69
void toRelative(const Location &ref)
Definition: location.cpp:111
void fillPositionForElement(const Element *e, bool absfrac=true)
Definition: location.cpp:131
int _voice
Definition: location.h:34
int _staff
Definition: location.h:33
void setNote(int note)
Definition: location.h:75
bool isRelative() const
Definition: location.h:60
void setVoice(int voice)
Definition: location.h:65
static constexpr Location absolute()
Definition: location.h:50
Fraction frac() const
Definition: location.h:70
bool _rel
Definition: location.h:39
Definition: aeolus.cpp:26
int staff() const
Definition: location.h:62
bool operator==(const Location &other) const
Definition: location.cpp:282
Definition: xml.h:218
void write(XmlWriter &xml) const
Definition: location.cpp:52
void setStaff(int staff)
Definition: location.h:63
Definition: xmlwriter.h:26
bool isAbsolute() const
Definition: location.h:59
int voice() const
Definition: location.h:64
int _note
Definition: location.h:38
Definition: location.h:32
Definition: xmlreader.h:28
void toAbsolute(const Location &ref)
Definition: location.cpp:95
Definition: fraction.h:46
static QVariant getLocationProperty(Pid pid, const Element *start, const Element *end)
Definition: location.cpp:258
void fillForElement(const Element *e, bool absfrac=true)
Definition: location.cpp:153
static constexpr Location relative()
Definition: location.h:51
static Location forElement(const Element *e, bool absfrac=true)
Definition: location.cpp:170
static Location positionForElement(const Element *e, bool absfrac=true)
Definition: location.cpp:181
Fraction _frac
Definition: location.h:36