2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "local-key-item.hh"
10 #include "staff-symbol-referencer.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "rhythmic-head.hh"
18 Local_key_item::add_pitch (Musical_pitch p
, bool cautionary
, bool natural
)
20 for (int i
=0; i
< accidental_arr_
.size(); i
++)
21 if (!Musical_pitch::compare (p
, accidental_arr_
[i
].pitch_
))
23 /* maybe natural (and cautionary) should be modif. nonetheless? */
25 Local_key_cautionary_tuple t
;
27 t
.cautionary_b_
= cautionary
;
28 t
.natural_b_
= natural
;
29 accidental_arr_
.push (t
);
32 MAKE_SCHEME_CALLBACK(Local_key_item
,before_line_breaking
);
35 Local_key_item::before_line_breaking (SCM smob
)
37 Local_key_item
* me
= dynamic_cast<Local_key_item
*>(unsmob_element (smob
));
40 me
->accidental_arr_
.sort (Local_key_cautionary_tuple::compare
);
45 Local_key_item::accidental (Score_element
*me
, int j
, bool cautionary
, bool natural
)
47 Molecule
m (me
->lookup_l ()->afm_find (String ("accidentals-") + to_str (j
)));
50 Molecule prefix
= me
->lookup_l ()->afm_find (String ("accidentals-0"));
51 m
.add_at_edge(X_AXIS
, LEFT
, Molecule(prefix
), 0);
55 Molecule open
= me
->lookup_l ()->afm_find (String ("accidentals-("));
56 Molecule close
= me
->lookup_l ()->afm_find (String ("accidentals-)"));
57 m
.add_at_edge(X_AXIS
, LEFT
, Molecule(open
), 0);
58 m
.add_at_edge(X_AXIS
, RIGHT
, Molecule(close
), 0);
68 MAKE_SCHEME_CALLBACK(Local_key_item
,brew_molecule
);
70 Local_key_item::brew_molecule (SCM smob
)
72 Local_key_item
* lki
= dynamic_cast<Local_key_item
*>(unsmob_element (smob
));
73 Score_element
* me
= lki
;
77 Real note_distance
= Staff_symbol_referencer::staff_space (me
)/2;
82 for (int i
= 0; i
< lki
->accidental_arr_
.size(); i
++)
84 Musical_pitch
p (lki
->accidental_arr_
[i
].pitch_
);
86 if (p
.octave_i_
!= lastoct
)
90 Real dy
=lastoct
*7* note_distance
;
91 octave_mol
.translate_axis (dy
, Y_AXIS
);
92 mol
.add_molecule (octave_mol
);
93 octave_mol
= Molecule ();
98 lastoct
= p
.octave_i_
;
100 SCM c0
= me
->get_elt_property ("c0-position");
101 Real dy
= (gh_number_p (c0
) ? gh_scm2int (c0
) : 0 + p
.notename_i_
)
104 Molecule
m (accidental (me
,p
.accidental_i_
,
105 lki
->accidental_arr_
[i
].cautionary_b_
,
106 lki
->accidental_arr_
[i
].natural_b_
));
108 m
.translate_axis (dy
, Y_AXIS
);
109 octave_mol
.add_at_edge (X_AXIS
, RIGHT
, m
, 0);
114 Real dy
=lastoct
*7*note_distance
;
115 octave_mol
.translate_axis (dy
, Y_AXIS
);
116 mol
.add_molecule (octave_mol
);
117 octave_mol
= Molecule ();
120 if (lki
->accidental_arr_
.size())
122 Drul_array
<SCM
> pads
;
127 pads
[RIGHT
] = me
->get_elt_property ("right-padding");
128 pads
[LEFT
] = me
->get_elt_property ("left-padding");
134 if (!gh_number_p (pads
[d
]))
137 Box
b(Interval (0, gh_scm2double (pads
[d
]) * note_distance
),
139 Molecule
m (me
->lookup_l ()->blank (b
));
140 mol
.add_at_edge (X_AXIS
, d
, m
, 0);
141 } while ( flip (&d
)!= LEFT
);
144 return mol
.create_scheme();
147 Local_key_item::Local_key_item (SCM s
)
153 Local_key_item::has_interface (Score_element
*m
)
155 return m
&& m
->has_interface (ly_symbol2scm ("accidentals-interface"));