MuseScore  3.4
Music composition and notation
connector.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 __CONNECTOR_H__
14 #define __CONNECTOR_H__
15 
16 #include "location.h"
17 #include "types.h"
18 
19 namespace Ms {
20 
21 class Element;
22 class Score;
23 class ScoreElement;
24 class XmlReader;
25 class XmlWriter;
26 
27 //---------------------------------------------------------
28 // @@ ConnectorInfo
34 //---------------------------------------------------------
35 
37  const Element* _current { 0 };
38  bool _currentUpdated { false };
39  const Score* _score;
40 
41  bool finishedLeft() const;
42  bool finishedRight() const;
43 
44  static int orderedConnectionDistance(const ConnectorInfo& c1, const ConnectorInfo& c2);
45 
46  protected:
51 
54 
55  void updateLocation(const Element* e, Location& i, bool clipboardmode);
56  void updateCurrentInfo(bool clipboardmode);
57  bool currentUpdated() const { return _currentUpdated; }
58  void setCurrentUpdated(bool v) { _currentUpdated = v; }
59 
61  const ConnectorInfo* findFirst() const;
63  const ConnectorInfo* findLast() const;
64 
65  public:
66  ConnectorInfo(const Element* current, int track = -1, Fraction = { -1, 1});
67  ConnectorInfo(const Score* score, const Location& currentLocation);
68 
69  ConnectorInfo* prev() const { return _prev; }
70  ConnectorInfo* next() const { return _next; }
71  ConnectorInfo* start();
72  ConnectorInfo* end();
73 
74  ElementType type() const { return _type; }
75  const Location& location() const { return _currentLoc; }
76 
77  bool connect(ConnectorInfo* other);
78  bool finished() const;
79 
80  // for reconnection of broken connectors
81  int connectionDistance(const ConnectorInfo& c2) const;
82  void forceConnect(ConnectorInfo* c2);
83 
84  bool hasPrevious() const { return (_prevLoc.measure() != INT_MIN); }
85  bool hasNext() const { return (_nextLoc.measure() != INT_MIN); }
86  bool isStart() const { return (!hasPrevious() && hasNext()); }
87  bool isMiddle() const { return (hasPrevious() && hasNext()); }
88  bool isEnd() const { return (hasPrevious() && !hasNext()); }
89  };
90 
91 //---------------------------------------------------------
92 // @@ ConnectorInfoReader
94 //---------------------------------------------------------
95 
96 class ConnectorInfoReader final : public ConnectorInfo {
100 
101  void readEndpointLocation(Location& l);
102 
103  public:
104  ConnectorInfoReader(XmlReader& e, Element* current, int track = -1);
105  ConnectorInfoReader(XmlReader& e, Score* current, int track = -1);
106 
107  ConnectorInfoReader* prev() const { return static_cast<ConnectorInfoReader*>(_prev); }
108  ConnectorInfoReader* next() const { return static_cast<ConnectorInfoReader*>(_next); }
109 
110  Element* connector();
111  const Element* connector() const;
112  Element* releaseConnector(); // returns connector and "forgets" it by
113  // setting an internal pointer to it to zero
114 
115  bool read();
116  void update();
117  void addToScore(bool pasteMode);
118 
119  static void readConnector(std::unique_ptr<ConnectorInfoReader> info, XmlReader& e);
120  };
121 
122 //---------------------------------------------------------
123 // @@ ConnectorInfoWriter
127 //---------------------------------------------------------
128 
131 
132  protected:
134 
135  virtual const char* tagName() const = 0;
136 
137  public:
138  ConnectorInfoWriter(XmlWriter& xml, const Element* current, const Element* connector, int track = -1, Fraction = { -1, 1});
139 
140  ConnectorInfoWriter* prev() const { return static_cast<ConnectorInfoWriter*>(_prev); }
141  ConnectorInfoWriter* next() const { return static_cast<ConnectorInfoWriter*>(_next); }
142 
143  const Element* connector() const { return _connector; }
144 
145  void write();
146  };
147 
148 } // namespace Ms
149 #endif
Helper class for reading beams, tuplets and spanners.
Definition: connector.h:96
bool hasPrevious() const
Definition: connector.h:84
bool finishedLeft() const
Definition: connector.cpp:235
Definition: xml.h:67
ConnectorInfo * next() const
Definition: connector.h:70
bool hasNext() const
Definition: connector.h:85
bool finishedRight() const
Definition: connector.cpp:245
bool isMiddle() const
Definition: connector.h:87
void forceConnect(ConnectorInfo *c2)
Definition: connector.cpp:108
Definition: scoreElement.h:173
ConnectorInfo * findLast()
Definition: connector.cpp:200
ConnectorInfoWriter * next() const
Definition: connector.h:141
static int measure(const Element *e)
Definition: location.cpp:210
bool isEnd() const
Definition: connector.h:88
Base class of score layout elements.
Definition: element.h:158
ElementType _type
Definition: connector.h:47
ConnectorInfo * findFirst()
Definition: connector.cpp:174
const Element * _current
Definition: connector.h:37
Location _prevLoc
Definition: connector.h:49
Definition: score.h:391
ConnectorInfo * _next
Definition: connector.h:53
XmlWriter * _xml
Definition: connector.h:130
Location _currentLoc
Definition: connector.h:48
ConnectorInfo * _prev
Definition: connector.h:52
Location _nextLoc
Definition: connector.h:50
static constexpr Location absolute()
Definition: location.h:50
ConnectorInfoWriter * prev() const
Definition: connector.h:140
void updateCurrentInfo(bool clipboardmode)
Definition: connector.cpp:62
ConnectorInfo * end()
Definition: connector.cpp:267
ConnectorInfo(const Element *current, int track=-1, Fraction={ -1, 1})
Definition: connector.cpp:26
int connectionDistance(const ConnectorInfo &c2) const
Definition: connector.cpp:153
Element * _connector
Definition: connector.h:98
Definition: aeolus.cpp:26
bool isStart() const
Definition: connector.h:86
Definition: xml.h:218
Definition: xmlwriter.h:26
ConnectorInfo * prev() const
Definition: connector.h:69
bool currentUpdated() const
Definition: connector.h:57
Helper class for writing connecting elements.
Definition: connector.h:129
const Element * _connector
Definition: connector.h:133
Stores a general information on various connecting elements (currently only spanners) including their...
Definition: connector.h:36
ConnectorInfo * start()
Definition: connector.cpp:255
Definition: location.h:32
ElementType type() const
Definition: connector.h:74
void updateLocation(const Element *e, Location &i, bool clipboardmode)
Definition: connector.cpp:53
Definition: xmlreader.h:28
bool finished() const
Definition: connector.cpp:226
const Element * connector() const
Definition: connector.h:143
ConnectorInfoReader * prev() const
Definition: connector.h:107
Definition: fraction.h:46
ConnectorInfoReader * next() const
Definition: connector.h:108
ElementType
Definition: types.h:34
static int orderedConnectionDistance(const ConnectorInfo &c1, const ConnectorInfo &c2)
Definition: connector.cpp:133
bool connect(ConnectorInfo *other)
Definition: connector.cpp:73
bool _currentUpdated
Definition: connector.h:38
const Score * _score
Definition: connector.h:39
XmlReader * _reader
Definition: connector.h:97
ScoreElement * _connectorReceiver
Definition: connector.h:99
const Location & location() const
Definition: connector.h:75
void setCurrentUpdated(bool v)
Definition: connector.h:58