2 key-item.cc -- implement Key_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 keyplacement by Mats Bengtsson
11 #include "key-item.hh"
14 #include "molecule.hh"
15 #include "paper-def.hh"
17 #include "musical-pitch.hh"
19 const int FLAT_TOP_PITCH
=2; /* fes,ges,as and bes typeset in lower octave */
20 const int SHARP_TOP_PITCH
=4; /* ais and bis typeset in lower octave */
24 multi_octave_b_
= false;
31 Key_item::set_c_position (int c0
)
34 // Find the c in the range -4 through 2
35 int from_bottom_pos
= c0
+ 4;
36 from_bottom_pos
= from_bottom_pos
%7;
37 from_bottom_pos
= (from_bottom_pos
+ 7)%7; // Precaution to get positive.
38 c_position
= from_bottom_pos
- 4;
43 Key_item::add (int p
, int a
)
50 Key_item::add_old (int p
, int a
)
52 old_pitch_arr_
.push (p
);
53 old_acc_arr_
.push (a
);
58 Key_item::calculate_position(int p
, int a
) const
62 return p
+ c0_position
;
65 if ((a
<0 && ((p
>FLAT_TOP_PITCH
) || (p
+c_position
>4)) && (p
+c_position
>1))
67 (a
>0 && ((p
>SHARP_TOP_PITCH
) || (p
+c_position
>5)) && (p
+c_position
>2)))
69 p
-= 7; /* Typeset below c_position */
71 return p
+ c_position
;
76 TODO space the `natural' signs wider
79 Key_item::brew_molecule_p() const
81 Molecule
*output
= new Molecule
;
82 Real inter
= paper()->internote_f ();
85 if ((break_status_dir_
== LEFT
|| break_status_dir_
== CENTER
)
86 || old_pitch_arr_
.size ())
88 for (int i
=0; i
< old_pitch_arr_
.size(); i
++)
90 for (j
=0; (j
< pitch_arr_
.size())
91 && (old_pitch_arr_
[i
] != pitch_arr_
[j
]); j
++)
94 if (j
== pitch_arr_
.size()
95 || (old_pitch_arr_
[i
] == pitch_arr_
[j
]
96 && old_acc_arr_
[i
] != acc_arr_
[j
]))
98 Molecule m
=lookup_l ()->accidental (0,false);
99 m
.translate_axis (calculate_position(old_pitch_arr_
[i
], old_acc_arr_
[i
]) * inter
, Y_AXIS
);
100 output
->add_at_edge (X_AXIS
, RIGHT
, m
);
105 Add half a space between cancellation and key sig.
107 As suggested by [Ross], p.148.
109 Interval
x(0, inter
);
112 output
->add_at_edge (X_AXIS
, RIGHT
, lookup_l()->fill (Box(x
,y
)));
115 for (int i
=0; i
< pitch_arr_
.size(); i
++)
117 Molecule m
=lookup_l ()->accidental (acc_arr_
[i
],false);
118 m
.translate_axis (calculate_position(pitch_arr_
[i
], acc_arr_
[i
]) * inter
, Y_AXIS
);
119 output
->add_at_edge (X_AXIS
, RIGHT
, m
);
121 if (pitch_arr_
.size())
123 Molecule
m (lookup_l ()->fill (Box (
124 Interval (0, paper()->note_width ()),
127 output
->add_at_edge (X_AXIS
, RIGHT
, m
);
135 Key_item::do_pre_processing()
139 transparent_b_
= (break_status_dir() != RIGHT
);
140 set_empty (transparent_b_
);