2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "local-key-item.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "note-head.hh"
17 Local_key_item::Local_key_item ()
23 Local_key_item::add_support (Item
*head_l
)
25 if (support_items_
.find_l(head_l
))
27 support_items_
.push (head_l
);
28 add_dependency (head_l
);
32 Local_key_item::add_pitch (Musical_pitch p
, bool cautionary
)
34 for (int i
=0; i
< accidental_arr_
.size(); i
++)
35 if (!Musical_pitch::compare (p
, accidental_arr_
[i
].pitch_
))
38 Local_key_cautionary_tuple t
;
40 t
.cautionary_b_
= cautionary
;
41 accidental_arr_
.push (t
);
45 Local_key_item::do_pre_processing()
47 accidental_arr_
.sort (Local_key_cautionary_tuple::compare
);
51 Local_key_item::do_brew_molecule_p() const
53 Molecule
*output
= new Molecule
;
54 Real note_distance
= staff_line_leading_f ()/2;
55 Molecule
*octave_mol_p
= 0;
58 for (int i
= 0; i
< accidental_arr_
.size(); i
++)
60 Musical_pitch
p (accidental_arr_
[i
].pitch_
);
62 if (p
.octave_i_
!= lastoct
)
66 Real dy
=lastoct
*7* note_distance
;
67 octave_mol_p
->translate_axis (dy
, Y_AXIS
);
68 output
->add_molecule (*octave_mol_p
);
71 octave_mol_p
= new Molecule
;
74 lastoct
= p
.octave_i_
;
76 (c0_position_i_
+ p
.notename_i_
)
78 Molecule
m (lookup_l ()->accidental (p
.accidental_i_
,
79 accidental_arr_
[i
].cautionary_b_
));
81 m
.translate_axis (dy
, Y_AXIS
);
82 octave_mol_p
->add_at_edge (X_AXIS
, RIGHT
, m
, 0);
87 Real dy
=lastoct
*7*note_distance
;
88 octave_mol_p
->translate_axis (dy
, Y_AXIS
);
89 output
->add_molecule (*octave_mol_p
);
93 if (accidental_arr_
.size())
95 Box
b(Interval (0, 0.6 * note_distance
), Interval (0,0));
96 Molecule
m (lookup_l ()->fill (b
));
97 output
->add_at_edge (X_AXIS
, RIGHT
, m
, 0);
101 for (int i
=0; i
< support_items_
.size(); i
++)
103 Dimension_cache
*common
=
104 common_group (support_items_
[i
], X_AXIS
);
106 Real x
= support_items_
[i
]->relative_coordinate (common
, X_AXIS
)
107 - relative_coordinate (common
, X_AXIS
);
109 x_int
.unite (x
+ support_items_
[i
]->extent (X_AXIS
));
112 if (x_int
.empty_b ())
113 x_int
= Interval(0,0);
115 output
->translate_axis (-output
->extent()[X_AXIS
][RIGHT
] + x_int
[LEFT
], X_AXIS
);
123 Local_key_item::do_substitute_element_pointer (Score_element
*o
,Score_element
*n
)
125 if (Item
* o_l
= dynamic_cast <Item
*> (o
))
126 support_items_
.substitute (o_l
,dynamic_cast <Item
*> (n
));