GUIDOLib  1.7.7
Guido Engine Internal Documentation
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
GRBeam.h
1 #ifndef GRBeam_H
2 #define GRBeam_H
3 
4 /*
5  GUIDO Library
6  Copyright (C) 2002 Holger Hoos, Juergen Kilian, Kai Renz
7  Copyright (C) 2002-2017 Grame
8 
9  This Source Code Form is subject to the terms of the Mozilla Public
10  License, v. 2.0. If a copy of the MPL was not distributed with this
11  file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 
13  Grame Research Laboratory, 11, cours de Verdun Gensoul 69002 Lyon - France
14  research@grame.fr
15 
16 */
17 
18 #include <cmath>
19 #include <string>
20 #include <sstream>
21 #include <vector>
22 
23 #include "ARBeam.h"
24 #include "ARFeatheredBeam.h"
25 #include "GRPTagARNotationElement.h"
26 #include "GRSystemTagInterface.h"
27 #include "GRVisitor.h"
28 
29 class GRSimpleBeam;
30 class GREvent;
31 
32 typedef std::vector<GRSimpleBeam *> SimpleBeamList;
33 typedef struct beamRect {
38 
39  void xList(float* l) const { l[0] = topLeft.x; l[1] = bottomLeft.x, l[2] = bottomRight.x; l[3] = topRight.x; }
40  void yList(float* l) const { l[0] = topLeft.y; l[1] = bottomLeft.y, l[2] = bottomRight.y; l[3] = topRight.y; }
41  float height() const { return topRight.y - topLeft.y; }
42  float width() const { return std::abs(topRight.x - topLeft.x); }
43  float slope() const { return height() / width(); }
44  std::string toString() const { std::stringstream s; s << topLeft << " " << bottomLeft << " " << bottomRight << " " << topRight; return s.str(); }
45 
46  void operator -= (NVPoint p) { topLeft -= p; bottomLeft -= p; bottomRight -= p; topRight -= p; }
47  void yOffset (float val) { topLeft.y += val; bottomLeft.y += val; bottomRight.y += val; topRight.y += val;}
48  void tilt (float val) { topLeft.y -= val; bottomLeft.y -= val; bottomRight.y += val; topRight.y += val;}
49  bool includes (float x) const { return (topLeft.x <= x) && (topRight.x >= x); }
50 
51  bool operator == (struct beamRect& r) { return (topLeft==r.topLeft) && (topRight==r.topRight) && (bottomLeft==r.bottomLeft) && (bottomRight==r.bottomRight); }
52  bool operator != (struct beamRect& r) { return !(*this == r); }
53 } BeamRect;
54 
56 {
57  public:
59  {
60  dirset = 0;
61  direction = 0;
62  }
63 
64  virtual ~GRBeamSaveStruct();
65 
66  int dirset;
67  int direction;
68 // BeamRect fRect;
70  std::string duration;
71  SimpleBeamList simpleBeams; // the list of all graphics beams, including the main one appart in case of nested beams
72 };
73 
74 
80 {
81 public:
82  GRBeam(GRStaff * grstf, const ARBeam * arbeam);
83  virtual ~GRBeam();
84 
85  virtual void accept (GRVisitor& visitor);
86 
87  virtual void checkPosition(const GRSystem * grsys);
88  virtual void ResumeTag (GRStaff * grstaff,GuidoPos assocpos);
89  virtual void BreakTag (GRStaff * grstaff,GuidoPos &assocpos);
90  virtual void setError (const GRStaff * grstaff,int p_error);
91  virtual void tellPosition(GObject * gobj,const NVPoint &pos);
92  virtual void StaffBegin (GRStaff * grstaff = 0);
93  virtual void StaffFinished(GRStaff * grstaff = 0);
94  virtual void RangeEnd (GRStaff * grstaff = 0);
95  virtual void addAssociation(GRNotationElement * grnot);
96  virtual void OnDraw ( VGDevice & hdc ) const;
97  virtual void addSmallerBeam(GRBeam * beam);
98 
99  virtual GRNotationElement * getEndElement();
100  virtual bool isAutoBeam() const { return false; } // derived by GRAutoBeam
101  virtual void setLevel(int l) { fLevel = l;}
102  virtual void decLevel() { fLevel--;}
103  virtual void incLevel() { fLevel++;}
104  virtual bool isGraceBeaming() const { return fIsGraceBeaming;}
105 
106  void refreshPosition();
107  void refreshBeams (const GRSystemStartEndStruct * sse, float currentLSPACE, int dir);
108  std::string beamed() const; // gives the list of beamed notes as a string
109  void setParent(GRBeam* parent) { fParent = parent; }
110  GRBeam* topParent(GRBeam* parent) { return fParent ? fParent->topParent(fParent) : parent; }
111  const GREvent* startElt() const { return fStartElt; };
112  const GREvent* endElt() const { return fEndElt; };
113  GDirection getStemsDir () const;
114 
115 
116 protected:
117  const ARBeam * getARBeam() { return static_cast<const ARBeam *>(mAbstractRepresentation); }
119  virtual bool checkNotes(GRStaff * grstaff);
120 
121 
122 private:
123  typedef struct PosInfos {
124  GDirection stemdir;
125  float currentSize;
126  float currentLSPACE;
127  bool oneNote;
128  bool stemsReverse; // set to true when the beaming connect reversed stems (up and down)
129  bool stavesStartEnd; // set to true when start and end are on different staves
130  const GREvent* highNote; // the highest note (y position)
131  const GREvent* lowNote; // the lowest note
132  NVPoint startStaff; // the start staff position
133  float highStaff; // the higher staff y position
134  float lowStaff; // the lower staff y position
135  NVPoint endStaff; // the end staff position
136  } PosInfos;
137 
138  void initTopLeft (GRSystemStartEndStruct * sse, const GREvent * startEl, PosInfos& infos);
139  void initBottomLeft (GRSystemStartEndStruct * sse, PosInfos& infos);
140  void initTopRight (GRSystemStartEndStruct * sse, const GREvent * endEl, PosInfos& infos);
141  void initBottomRight (GRSystemStartEndStruct * sse, PosInfos& infos);
142  void initRect (const GREvent * startEl, const GREvent * endElt, const GRBeam* parent, const PosInfos& infos);
143  void slopeAdjust (GRSystemStartEndStruct * sse, const GREvent * startEl, const GREvent * endEl,float slope, PosInfos& infos);
144  float slopeAdjust (BeamRect& rect);
145  void adjustFeathered (float yFact1, float yFact2, PosInfos& info, GRSystemStartEndStruct * sse);
146  void setStemEndPos (GRSystemStartEndStruct * sse, PosInfos& info, bool needsadjust);
147  void adjustStemEndPos (GRSystemStartEndStruct * sse, PosInfos& infos);
148  void setBeams (GRSystemStartEndStruct * sse, PosInfos& infos, float yFact1, float yFact2, int direction);
149  bool reverseStems (const NEPointerList* assoc) const;
150  void yRange (const NEPointerList* assoc, const GREvent*& high, const GREvent*& low) const;
151  void scanStaves (const NEPointerList* assoc, float& highStaff, float& lowStaff) const;
152  bool checkPartialBeaming (GuidoPos pos, GuidoPos endpos, GREvent *& next, int curFaehnchen);
153  BeamRect getLeftPartialBeam (GREvent* elt, float space, float size, float lspace, float slope, bool dirchange, int num) const;
154  void getRightPartialBeam (BeamRect& r1, float size, float lspace, float slope) const;
155 
156  void setLeft (BeamRect& r, const NVPoint& pos, const GRStaff* staff) const;
157  void setRight (BeamRect& r, const NVPoint& pos, const GRStaff* staff, float xadjust) const;
158  void adjustTremolos (GuidoPos pos);
159  void setUserLengths(GRNotationElement* start, GRNotationElement* end, const ARBeam * arBeam);
160  const GREvent* previousEvent (GREvent* ev) const;
161 
162  float getBeamSpace(float lspace) const { return 0.75f * lspace; }
163  float getBeamSize (float lspace) const { return 0.4f * lspace; }
164  float getStemsOffset (GRSystemStartEndStruct * sse, PosInfos& infos, bool needsadjust) const;
165  float getSlope (const GRSystem * system) const;
166  BeamRect& mainRect () { return fRect; }
167  const BeamRect& mainRect () const { return fRect; }
168 
169  bool fIsFeathered;
170  bool fIsGraceBeaming;
171  bool fDrawDur;
172  int fLevel;
173  bool fHasRestInMiddle;
174 
175  static std::pair<float, float> fLastPositionOfBarDuration;
176  BeamRect fRect;
177  std::vector<GRBeam *> fSmallerBeams; // smaller beams are beams nested in the current one
178  GRBeam * fParent = nullptr; // the parent beam in case of nested beams
179  GREvent* fStartElt = nullptr;
180  GREvent* fEndElt = nullptr;
181 
182 };
183 
184 #endif
GRBeam::tellPosition
virtual void tellPosition(GObject *gobj, const NVPoint &pos)
GRBeam::setError
virtual void setError(const GRStaff *grstaff, int p_error)
GRVisitor
Definition: GRVisitor.h:39
GRBeam::getNewGRSaveStruct
virtual GRPositionTag::GRSaveStruct * getNewGRSaveStruct()
Definition: GRBeam.h:118
GRBeam::RangeEnd
virtual void RangeEnd(GRStaff *grstaff=0)
GRSystemStartEndStruct
This class is used to determine when a position tag ends.
Definition: GRPositionTag.h:32
beamRect::yList
void yList(float *l) const
Definition: GRBeam.h:40
GRBeam::GRBeam
GRBeam(GRStaff *grstf, const ARBeam *arbeam)
GRBeam::beamed
std::string beamed() const
GRBeam::startElt
const GREvent * startElt() const
Definition: GRBeam.h:111
GRBeam::BreakTag
virtual void BreakTag(GRStaff *grstaff, GuidoPos &assocpos)
beamRect::yOffset
void yOffset(float val)
Definition: GRBeam.h:47
GRBeam::getARBeam
const ARBeam * getARBeam()
Definition: GRBeam.h:117
GObject
The base class for all graphic objects.
Definition: GObject.h:54
NVPoint::x
float x
Definition: NVPoint.h:68
GRBeamSaveStruct::dirset
int dirset
Definition: GRBeam.h:66
GRBeam::accept
virtual void accept(GRVisitor &visitor)
GRBeam::checkPosition
virtual void checkPosition(const GRSystem *grsys)
GRBeam::refreshPosition
void refreshPosition()
GRBeam::setParent
void setParent(GRBeam *parent)
Definition: GRBeam.h:109
GRNotationElement
parent class for all notation elements.
Definition: GRNotationElement.h:54
ARBeam
Abstract representation of a beam.
Definition: ARBeam.h:50
GRBeamSaveStruct::GRBeamSaveStruct
GRBeamSaveStruct()
Definition: GRBeam.h:58
GREvent
Graphical representation for an event (= has duration).
Definition: GREvent.h:61
GRBeam::~GRBeam
virtual ~GRBeam()
NVPoint
Definition: NVPoint.h:20
beamRect::tilt
void tilt(float val)
Definition: GRBeam.h:48
GRBeamSaveStruct::DurationLine
NVPoint DurationLine[6]
Definition: GRBeam.h:69
beamRect::xList
void xList(float *l) const
Definition: GRBeam.h:39
GRPositionTag::GRSaveStruct
Definition: GRPositionTag.h:68
beamRect::toString
std::string toString() const
Definition: GRBeam.h:44
beamRect::operator==
bool operator==(struct beamRect &r)
Definition: GRBeam.h:51
GRBeam::addAssociation
virtual void addAssociation(GRNotationElement *grnot)
GRBeam::isAutoBeam
virtual bool isAutoBeam() const
Definition: GRBeam.h:100
GRStaff
A GRStaff represents a single line of music.
Definition: GRStaff.h:181
GRBeamSaveStruct::direction
int direction
Definition: GRBeam.h:67
GRBeamSaveStruct::~GRBeamSaveStruct
virtual ~GRBeamSaveStruct()
GRBeam::decLevel
virtual void decLevel()
Definition: GRBeam.h:102
GRBeam::OnDraw
virtual void OnDraw(VGDevice &hdc) const
GRSimpleBeam
Graphical representation af a Beam.
Definition: GRSimpleBeam.h:23
GRBeam::setLevel
virtual void setLevel(int l)
Definition: GRBeam.h:101
GRBeam::isGraceBeaming
virtual bool isGraceBeaming() const
Definition: GRBeam.h:104
NVPoint::y
float y
Definition: NVPoint.h:69
GRPTagARNotationElement
not yet documented
Definition: GRPTagARNotationElement.h:25
GRBeamSaveStruct::simpleBeams
SimpleBeamList simpleBeams
Definition: GRBeam.h:71
GRBeam::incLevel
virtual void incLevel()
Definition: GRBeam.h:103
beamRect
Definition: GRBeam.h:33
VGDevice
Generic platform independant drawing device.
Definition: VGDevice.h:68
GRBeam::topParent
GRBeam * topParent(GRBeam *parent)
Definition: GRBeam.h:110
GRBeam::checkNotes
virtual bool checkNotes(GRStaff *grstaff)
beamRect::topRight
NVPoint topRight
Definition: GRBeam.h:37
GRBeam::StaffFinished
virtual void StaffFinished(GRStaff *grstaff=0)
GRBeam::getEndElement
virtual GRNotationElement * getEndElement()
beamRect::operator!=
bool operator!=(struct beamRect &r)
Definition: GRBeam.h:52
beamRect::topLeft
NVPoint topLeft
Definition: GRBeam.h:34
GRARNotationElement::mAbstractRepresentation
const ARMusicalObject * mAbstractRepresentation
Definition: GRARNotationElement.h:39
beamRect::operator-=
void operator-=(NVPoint p)
Definition: GRBeam.h:46
beamRect::includes
bool includes(float x) const
Definition: GRBeam.h:49
GRBeam::refreshBeams
void refreshBeams(const GRSystemStartEndStruct *sse, float currentLSPACE, int dir)
beamRect::bottomLeft
NVPoint bottomLeft
Definition: GRBeam.h:35
GRBeam::addSmallerBeam
virtual void addSmallerBeam(GRBeam *beam)
GRBeam
The Beam notation element.
Definition: GRBeam.h:79
beamRect::bottomRight
NVPoint bottomRight
Definition: GRBeam.h:36
GRBeam::ResumeTag
virtual void ResumeTag(GRStaff *grstaff, GuidoPos assocpos)
GRSystemTagInterface
not yet documented
Definition: GRSystemTagInterface.h:23
beamRect::height
float height() const
Definition: GRBeam.h:41
beamRect::width
float width() const
Definition: GRBeam.h:42
GRSystem
Manages a number of staffs and has a given start and end timeposition. GRSystem is the grafical repre...
Definition: GRSystem.h:52
GRBeamSaveStruct
Definition: GRBeam.h:55
GRBeam::endElt
const GREvent * endElt() const
Definition: GRBeam.h:112
GRBeamSaveStruct::duration
std::string duration
Definition: GRBeam.h:70
beamRect::slope
float slope() const
Definition: GRBeam.h:43
GRBeam::StaffBegin
virtual void StaffBegin(GRStaff *grstaff=0)
GRBeam::getStemsDir
GDirection getStemsDir() const
NEPointerList
Definition: NEPointerList.h:34

Guido Project Copyright © 2019 Grame-CNCM