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 pitch_less (SCM p1
, SCM p2
)
20 for (int i
= 3; i
--; p1
= gh_cdr (p1
), p2
= gh_cdr (p2
))
22 if (scm_less_p (gh_car (p1
), gh_car (p2
)))
24 if (gh_car (p1
) != gh_car (p2
))
36 pitch_less_proc
= gh_new_procedure2_0 ("pitch-less", &pitch_less
);
39 ADD_SCM_INIT_FUNC(pitch
,init_pitch_funcs
);
43 Local_key_item::add_pitch (Score_element
*me
, Musical_pitch p
, bool cautionary
, bool natural
)
45 SCM acs
= me
->get_elt_property ("accidentals");
46 SCM pitch
= p
.to_scm ();
49 opts
= gh_cons (ly_symbol2scm ("cautionary"), opts
);
51 opts
= gh_cons (ly_symbol2scm ("natural"), opts
);
53 pitch
= gh_append2 (pitch
, opts
);
54 acs
= scm_merge_x (acs
, gh_cons (pitch
, SCM_EOL
), pitch_less_proc
);
56 me
->set_elt_property ("accidentals", acs
);
60 Local_key_item::parenthesize (Score_element
*me
, Molecule m
)
62 Molecule open
= me
->lookup_l ()->afm_find (String ("accidentals-("));
63 Molecule close
= me
->lookup_l ()->afm_find (String ("accidentals-)"));
64 m
.add_at_edge(X_AXIS
, LEFT
, Molecule(open
), 0);
65 m
.add_at_edge(X_AXIS
, RIGHT
, Molecule(close
), 0);
71 UGH. clean me, revise placement routine (See Ross & Wanske;
72 accidental placement is more complicated than this.
75 MAKE_SCHEME_CALLBACK(Local_key_item
,brew_molecule
);
77 Local_key_item::brew_molecule (SCM smob
)
79 Score_element
* me
= unsmob_element (smob
);
83 Real note_distance
= Staff_symbol_referencer::staff_space (me
)/2;
88 SCM accs
= me
->get_elt_property ("accidentals");
90 gh_pair_p (s
); s
= gh_cdr (s
))
92 Musical_pitch
p (gh_car (s
));
95 if (p
.octave_i_
!= lastoct
)
99 Real dy
=lastoct
*7* note_distance
;
100 octave_mol
.translate_axis (dy
, Y_AXIS
);
101 mol
.add_molecule (octave_mol
);
102 octave_mol
= Molecule ();
107 lastoct
= p
.octave_i_
;
109 SCM c0
= me
->get_elt_property ("c0-position");
110 Real dy
= (gh_number_p (c0
) ? gh_scm2int (c0
) : 0 + p
.notename_i_
)
113 Molecule
acc (me
->lookup_l ()->afm_find (String ("accidentals-")
114 + to_str (p
.accidental_i_
)));
116 if (scm_memq (ly_symbol2scm ("natural"), gh_car (s
)) != SCM_BOOL_F
)
118 Molecule prefix
= me
->lookup_l ()->afm_find (String ("accidentals-0"));
119 acc
.add_at_edge(X_AXIS
, LEFT
, Molecule(prefix
), 0);
122 if (scm_memq (ly_symbol2scm ("cautionary"), gh_car (s
)) != SCM_BOOL_F
)
123 acc
= parenthesize (me
, acc
);
125 acc
.translate_axis (dy
, Y_AXIS
);
126 octave_mol
.add_at_edge (X_AXIS
, RIGHT
, acc
, 0);
131 Real dy
=lastoct
*7*note_distance
;
132 octave_mol
.translate_axis (dy
, Y_AXIS
);
133 mol
.add_molecule (octave_mol
);
134 octave_mol
= Molecule ();
137 if (gh_pair_p (accs
))
139 Drul_array
<SCM
> pads
;
144 pads
[RIGHT
] = me
->get_elt_property ("right-padding");
145 pads
[LEFT
] = me
->get_elt_property ("left-padding");
151 if (!gh_number_p (pads
[d
]))
154 Box
b(Interval (0, gh_scm2double (pads
[d
]) * note_distance
),
156 Molecule
m (me
->lookup_l ()->blank (b
));
157 mol
.add_at_edge (X_AXIS
, d
, m
, 0);
158 } while ( flip (&d
)!= LEFT
);
161 return mol
.create_scheme();
165 Local_key_item::has_interface (Score_element
*m
)
167 return m
&& m
->has_interface (ly_symbol2scm ("accidentals-interface"));
170 Local_key_item::set_interface (Score_element
*m
)
172 m
->set_interface (ly_symbol2scm ("accidentals-interface"));