2 local-key-item.cc -- implement Local_key_item, Pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "local-key-item.hh"
10 #include "staff-symbol-referencer.hh"
11 #include "font-interface.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "rhythmic-head.hh"
21 pitch_less (SCM p1
, SCM p2
)
23 return Pitch::less_p (gh_car (p1
), gh_car (p2
));
26 static SCM pitch_less_proc
;
31 pitch_less_proc
= gh_new_procedure2_0 ("pits-less", &pitch_less
);
34 ADD_SCM_INIT_FUNC (lkpitch
,init_pitch_funcs
);
38 Local_key_item::add_pitch (Grob
*me
, Pitch p
, bool cautionary
, bool natural
,
39 Grob
* tie_break_reminder
)
41 SCM acs
= me
->get_grob_property ("accidentals");
42 SCM pitch
= p
.smobbed_copy ();
45 opts
= gh_cons (ly_symbol2scm ("cautionary"), opts
);
47 opts
= gh_cons (ly_symbol2scm ("natural"), opts
);
48 if (tie_break_reminder
)
50 /* Ugh, these 'options' can't have a value, faking... */
51 opts
= gh_cons (tie_break_reminder
->self_scm (), opts
);
52 opts
= gh_cons (ly_symbol2scm ("tie-break-reminder"), opts
);
55 pitch
= gh_cons (pitch
, opts
);
56 acs
= scm_merge_x (acs
, gh_cons (pitch
, SCM_EOL
), pitch_less_proc
);
58 me
->set_grob_property ("accidentals", acs
);
62 Local_key_item::parenthesize (Grob
*me
, Molecule m
)
64 Molecule open
= Font_interface::get_default_font (me
)->find_by_name (String ("accidentals-("));
65 Molecule close
= Font_interface::get_default_font (me
)->find_by_name (String ("accidentals-)"));
66 m
.add_at_edge (X_AXIS
, LEFT
, Molecule (open
), 0);
67 m
.add_at_edge (X_AXIS
, RIGHT
, Molecule (close
), 0);
72 /* HW says: maybe move to tie.cc
74 Note, tie should not kill all accidentals when broken, only the ones
75 that are indicated by a property tie-break-reminder, I guess
77 Find if any of the accidentals were created because they're at the rhs of a
78 tie. If that's the reason they exist, and the tie was NOT broken,
79 put the accidental up for deletion. Clear molecule cache. */
80 MAKE_SCHEME_CALLBACK (Local_key_item
, after_line_breaking
, 1);
82 Local_key_item::after_line_breaking (SCM smob
)
84 Grob
*me
= unsmob_grob (smob
);
86 SCM accs
= me
->get_grob_property ("accidentals");
88 gh_pair_p (s
); s
= gh_cdr (s
))
90 SCM opts
= gh_cdar (s
);
92 SCM t
= scm_memq (ly_symbol2scm ("tie-break-reminder"), opts
);
95 Grob
*tie
= unsmob_grob (gh_cadr (t
));
96 Spanner
*sp
= dynamic_cast<Spanner
*> (tie
);
99 /* there should be a better way to delete part of me */
100 scm_set_car_x (s
, gh_list (gh_caar (s
),
101 ly_symbol2scm ("deleted"),
103 me
->set_grob_property ("molecule", SCM_EOL
);
108 return SCM_UNSPECIFIED
;
112 UGH. clean me, revise placement routine (See Ross & Wanske;
113 accidental placement is more complicated than this.
116 MAKE_SCHEME_CALLBACK (Local_key_item
,brew_molecule
,1);
118 Local_key_item::brew_molecule (SCM smob
)
120 Grob
* me
= unsmob_grob (smob
);
124 Real note_distance
= Staff_symbol_referencer::staff_space (me
)/2;
129 SCM scm_style
= me
->get_grob_property ("style");
131 if (gh_symbol_p (scm_style
))
133 style
= ly_scm2string (scm_symbol_to_string (scm_style
));
138 preferably no name for the default style.
143 SCM accs
= me
->get_grob_property ("accidentals");
145 gh_pair_p (s
); s
= gh_cdr (s
))
147 Pitch
p (*unsmob_pitch (gh_caar (s
)));
148 SCM opts
= gh_cdar (s
);
150 if (scm_memq (ly_symbol2scm ("deleted"), opts
) != SCM_BOOL_F
)
154 if (p
.octave_i () != lastoct
)
158 Real dy
=lastoct
*7* note_distance
;
159 octave_mol
.translate_axis (dy
, Y_AXIS
);
160 mol
.add_molecule (octave_mol
);
161 octave_mol
= Molecule ();
166 lastoct
= p
.octave_i () ;
168 SCM c0
= me
->get_grob_property ("c0-position");
169 Real dy
= (gh_number_p (c0
) ? gh_scm2int (c0
) : 0 + p
.notename_i_
)
172 Molecule
acc (Font_interface::get_default_font (me
)->
173 find_by_name (String ("accidentals-") +
175 to_str (p
.alteration_i_
)));
177 if (scm_memq (ly_symbol2scm ("natural"), opts
) != SCM_BOOL_F
)
179 Molecule prefix
= Font_interface::get_default_font (me
)->
180 find_by_name (String ("accidentals-") + style
+ String ("0"));
181 acc
.add_at_edge (X_AXIS
, LEFT
, Molecule (prefix
), 0);
184 if (scm_memq (ly_symbol2scm ("cautionary"), opts
) != SCM_BOOL_F
)
185 acc
= parenthesize (me
, acc
);
187 acc
.translate_axis (dy
, Y_AXIS
);
188 octave_mol
.add_at_edge (X_AXIS
, RIGHT
, acc
, 0);
193 Real dy
=lastoct
*7*note_distance
;
194 octave_mol
.translate_axis (dy
, Y_AXIS
);
195 mol
.add_molecule (octave_mol
);
196 octave_mol
= Molecule ();
199 if (gh_pair_p (accs
))
201 Drul_array
<SCM
> pads
;
206 pads
[RIGHT
] = me
->get_grob_property ("right-padding");
207 pads
[LEFT
] = me
->get_grob_property ("left-padding");
213 if (!gh_number_p (pads
[d
]))
216 Box
b (Interval (0, gh_scm2double (pads
[d
]) * note_distance
),
218 Molecule
m (Lookup::blank (b
));
219 mol
.add_at_edge (X_AXIS
, d
, m
, 0);
220 } while (flip (&d
)!= LEFT
);
223 return mol
.smobbed_copy ();
227 Local_key_item::has_interface (Grob
*m
)
229 return m
&& m
->has_interface (ly_symbol2scm ("accidentals-interface"));
232 Local_key_item::set_interface (Grob
*m
)
234 m
->set_interface (ly_symbol2scm ("accidentals-interface"));