1 /* This file is part of the KDE project
2  * Copyright (C) 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef MUSIC_CORE_STAFF_H
20 #define MUSIC_CORE_STAFF_H
21 
22 #include <QObject>
23 #include <QString>
24 
25 namespace MusicCore {
26 
27 class Part;
28 class Clef;
29 class Bar;
30 class KeySignature;
31 class TimeSignature;
32 
33 /**
34  * A Staff is purely used for displaying/formatting. The staff class is used to indicate on what staff
35  * music elements should be printed, but does only contain information regarding the formatting.
36  */
37 class Staff : QObject
38 {
39     Q_OBJECT
40 public:
41     /**
42      * Creates a new staff in the given part. This does not actually add the staff to the part, to do that call the
43      * addStaff of the part.
44      *
45      * @param part the part in which to create a staff
46      */
47     explicit Staff(Part *part);
48 
49     /**
50      * Destructor.
51      */
52     ~Staff() override;
53 
54     /**
55      * Returns the part this staff is part of.
56      */
57     Part* part();
58 
59     /**
60      * Sets the part this staff is part of. You should not call this method after adding the staff to a part using the
61      * addStaff method in the Part class.
62      *
63      * @param part the part that this staff is part of
64      */
65     void setPart(Part* part);
66 
67     /**
68      * Returns the spacing in points between this staff and the staff above it.
69      */
70     qreal spacing() const;
71 
72     /**
73      * Returns the vertical position of this staff relative to the top of the staff system.
74      */
75     qreal top();
76     qreal center();
77     qreal bottom();
78 
79     /**
80      * Returns the number of lines in this staff. Typical values are 5 for normal music, or 1 for a percussion part.
81      * The default value for this attribute is 5.
82      */
83     int lineCount() const;
84 
85     /**
86      * Returns the distance in points between two lines of this staff.
87      */
88     qreal lineSpacing() const;
89 
90     /**
91      * Returns the closest line corresponding to the given y coordinate, where the coordinate should be relative
92      * to the top of the staff. 0 Is the bottom line, 2 the line above it, and so on.
93      *
94      * @param y the coordinate for which to return the closest line.
95      */
96     int line(qreal y) const;
97 
98     /**
99      * Returns the last Clef element in this staff that is at or before the given time in the given bar. If oldClef is
100      * specified and no clef changes are found in the given bar, this method returns oldClef instead of searching for
101      * older clef changes.
102      */
103     Clef* lastClefChange(int bar, int time = -1, Clef* oldClef = 0);
104     Clef* lastClefChange(Bar* bar, int time = -1, Clef* oldClef = 0);
105     KeySignature* lastKeySignatureChange(int bar);
106     KeySignature* lastKeySignatureChange(Bar* bar);
107     TimeSignature* lastTimeSignatureChange(int bar);
108     TimeSignature* lastTimeSignatureChange(Bar* bar);
109 
110     void updateAccidentals(int fromBar = 0);
111     void updateAccidentals(Bar* fromBar);
112 public Q_SLOTS:
113     /**
114      * Set the spacing between this staff and the staff above it.
115      *
116      * @param spacing the new spacing.
117      */
118     void setSpacing(qreal spacing);
119 
120     /**
121      * Sets the number of lines of this staff.
122      *
123      * @param lineCount the new number of lines in this staff.
124      */
125     void setLineCount(int lineCount);
126 
127     /**
128      * Sets the distance in points between two lines of this staff.
129      *
130      * @param lineSpacing the new distance between two lines.
131      */
132     void setLineSpacing(qreal lineSpacing);
133 Q_SIGNALS:
134     void spacingChanged(qreal spacing);
135     void lineCountChanged(int lineCount);
136     void lineSpacingChanged(qreal lineSpacing);
137 private:
138     class Private;
139     Private * const d;
140 };
141 
142 } // namespace MusicCore
143 
144 #endif // MUSIC_CORE_PART_H
145