2 local-key-item.cc -- implement Local_key_item, Pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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 (ly_car (p1), ly_car (p2));
26 static SCM pitch_less_proc;
31 pitch_less_proc = gh_new_procedure2_0 ("pitch-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 ();
43 SCM opts = scm_assoc (pitch, acs);
44 bool new_pitch = !gh_pair_p (opts);
45 opts= new_pitch ? SCM_EOL : gh_cdr (opts);
48 opts = gh_cons (ly_symbol2scm ("cautionary"), opts);
50 opts = gh_cons (ly_symbol2scm ("natural"), opts);
51 if (tie_break_reminder)
53 /* Ugh, these 'options' can't have a value, faking... */
54 opts = gh_cons (tie_break_reminder->self_scm (), opts);
55 opts = gh_cons (ly_symbol2scm ("tie-break-reminder"), opts);
60 pitch = gh_cons (pitch, opts);
61 acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
64 scm_assoc_set_x (acs, pitch, opts);
66 me->set_grob_property ("accidentals", acs);
70 Local_key_item::parenthesize (Grob*me, Molecule m)
72 Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-leftparen"));
73 Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-rightparen"));
74 m.add_at_edge (X_AXIS, LEFT, Molecule (open), 0);
75 m.add_at_edge (X_AXIS, RIGHT, Molecule (close), 0);
81 HW says: maybe move to tie.cc
83 Note, tie should not kill all accidentals when broken, only the ones
84 that are indicated by a property tie-break-reminder, I guess
86 Find if any of the accidentals were created because they're at the rhs of a
87 tie. If that's the reason they exist, and the tie was NOT broken,
88 put the accidental up for deletion. Clear molecule cache. */
89 MAKE_SCHEME_CALLBACK (Local_key_item, after_line_breaking, 1);
91 Local_key_item::after_line_breaking (SCM smob)
93 Grob *me = unsmob_grob (smob);
95 SCM accs = me->get_grob_property ("accidentals");
97 gh_pair_p (s); s = ly_cdr (s))
99 SCM opts = ly_cdar (s);
101 SCM t = scm_memq (ly_symbol2scm ("tie-break-reminder"), opts);
104 Grob *tie = unsmob_grob (ly_cadr (t));
105 Spanner *sp = dynamic_cast<Spanner*> (tie);
106 if (!sp->original_l_)
108 /* there should be a better way to delete part of me */
109 scm_set_car_x (s, scm_list_n (ly_caar (s),
110 ly_symbol2scm ("deleted"),
112 me->set_grob_property ("molecule", SCM_EOL);
117 return SCM_UNSPECIFIED;
121 UGH. clean me, revise placement routine (See Ross & Wanske;
122 accidental placement is more complicated than this.
125 MAKE_SCHEME_CALLBACK (Local_key_item,brew_molecule,1);
127 Local_key_item::brew_molecule (SCM smob)
129 Grob* me = unsmob_grob (smob);
133 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
138 SCM scm_style = me->get_grob_property ("style");
140 if (gh_symbol_p (scm_style))
142 style = ly_scm2string (scm_symbol_to_string (scm_style));
147 preferably no name for the default style.
152 SCM accs = me->get_grob_property ("accidentals");
154 gh_pair_p (s); s = ly_cdr (s))
156 Pitch p (*unsmob_pitch (ly_caar (s)));
157 SCM opts = ly_cdar (s);
159 if (scm_memq (ly_symbol2scm ("deleted"), opts) != SCM_BOOL_F)
163 if (p.octave_i () != lastoct)
167 Real dy =lastoct*7* note_distance;
168 octave_mol.translate_axis (dy, Y_AXIS);
169 mol.add_molecule (octave_mol);
170 octave_mol = Molecule ();
176 lastoct = p.octave_i () ;
178 bool cautionary = (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F);
179 SCM font_rel_siz = me->get_grob_property("font-relative-size");
180 SCM caut_siz = me->get_grob_property("cautionary-size");
181 int frs = (gh_exact_p(font_rel_siz) ? gh_scm2int(font_rel_siz) : 0);
182 int cs = (gh_exact_p(caut_siz) ? gh_scm2int(caut_siz) : 0);
185 // Ugh. This will only work if only called once on each grob. --rz
186 if (cautionary && caut_siz!=0)
187 me->set_grob_property ("font-relative-size",gh_int2scm(frs+cs));
189 SCM c0 = me->get_grob_property ("c0-position");
190 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
193 Molecule acc (Font_interface::get_default_font (me)->
194 find_by_name (String ("accidentals-") +
196 to_str (p.alteration_i_)));
198 if (scm_memq (ly_symbol2scm ("natural"), opts) != SCM_BOOL_F)
200 Molecule prefix = Font_interface::get_default_font (me)->
201 find_by_name (String ("accidentals-") + style + String ("0"));
202 acc.add_at_edge (X_AXIS, LEFT, Molecule (prefix), 0);
205 if (cautionary && to_boolean(me->get_grob_property("paren-cautionaries")))
206 acc = parenthesize (me, acc);
208 acc.translate_axis (dy, Y_AXIS);
209 octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
214 Real dy =lastoct*7*note_distance;
215 octave_mol.translate_axis (dy, Y_AXIS);
216 mol.add_molecule (octave_mol);
217 octave_mol = Molecule ();
220 if (gh_pair_p (accs))
222 Drul_array<SCM> pads;
227 pads[RIGHT] = me->get_grob_property ("right-padding");
228 pads[LEFT] = me->get_grob_property ("left-padding");
234 if (!gh_number_p (pads[d]))
237 Box b (Interval (0, gh_scm2double (pads[d]) * note_distance),
239 Molecule m (Lookup::blank (b));
240 mol.add_at_edge (X_AXIS, d, m, 0);
241 } while (flip (&d)!= LEFT);
244 return mol.smobbed_copy ();
248 Local_key_item::has_interface (Grob*m)
250 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
255 ADD_INTERFACE (Local_key_item, "accidentals-interface",
257 "accidentals left-padding right-padding paren-cautionaries cautionary-size");