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 #include "Clef.h"
20 
21 namespace MusicCore {
22 
23 class Clef::Private {
24 public:
25     ClefShape shape;
26     int line;
27     int octaveChange;
28 };
29 
Clef(Staff * staff,int startTime,Clef::ClefShape shape,int line,int octaveChange)30 Clef::Clef(Staff* staff, int startTime, Clef::ClefShape shape, int line, int octaveChange) : StaffElement(staff, startTime), d(new Private)
31 {
32     d->shape = shape;
33     d->line = line;
34     d->octaveChange = octaveChange;
35     setWidth(13);
36 }
37 
~Clef()38 Clef::~Clef()
39 {
40     delete d;
41 }
42 
priority() const43 int Clef::priority() const
44 {
45     return 150;
46 }
47 
shape() const48 Clef::ClefShape Clef::shape() const
49 {
50     return d->shape;
51 }
52 
setShape(ClefShape shape)53 void Clef::setShape(ClefShape shape)
54 {
55     if (d->shape == shape) return;
56     d->shape = shape;
57     emit shapeChanged(shape);
58 }
59 
line() const60 int Clef::line() const
61 {
62     return d->line;
63 }
64 
setLine(int line)65 void Clef::setLine(int line)
66 {
67     if (d->line == line) return;
68     d->line = line;
69     emit lineChanged(line);
70 }
71 
octaveChange() const72 int Clef::octaveChange() const
73 {
74     return d->octaveChange;
75 }
76 
setOctaveChange(int octaveChange)77 void Clef::setOctaveChange(int octaveChange)
78 {
79     if (d->octaveChange == octaveChange) return;
80     d->octaveChange = octaveChange;
81     emit octaveChangeChanged(octaveChange);
82 }
83 
lineToPitch(int line) const84 int Clef::lineToPitch(int line) const
85 {
86     int pitch = 0;
87     switch (d->shape) {
88         case GClef: pitch = 4; break;
89         case FClef: pitch = -4; break;
90         case CClef: pitch = 0; break;
91     }
92     // d->line is the line which has pitch 'pitch' (not counting spaces between lines)
93     // 'line' is the position (including spaces between lines) of which to know the pitch
94     return line - 2 * d->line + 2 + pitch;
95 }
96 
pitchToLine(int pitch) const97 int Clef::pitchToLine(int pitch) const
98 {
99     int line = 0;
100     switch (d->shape) {
101         case GClef: line = 14; break;
102         case FClef: line = 6; break;
103         case CClef: line = 10; break;
104     }
105     line -= 2 * d->line;
106     line -= pitch;
107     return line;
108 }
109 
110 } // namespace MusicCore
111