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_cautionary)
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_cautionary)
50 /* Ugh, these 'options' can't have a value, faking... */
51 opts = gh_cons (tie_break_cautionary->self_scm (), opts);
52 opts = gh_cons (ly_symbol2scm ("tie-break-cautionary"), 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);
73 HW says: move to tie.cc
75 Ugh: this doesn't work: brew_molecule is called before line-breaking
77 MAKE_SCHEME_CALLBACK (Local_key_item, after_line_breaking, 1);
79 Local_key_item::after_line_breaking (SCM smob)
81 Grob *me = unsmob_grob (smob);
83 SCM accs = me->get_grob_property ("accidentals");
85 gh_pair_p (s); s = gh_cdr (s))
87 SCM opts = gh_cdar (s);
89 SCM t = scm_memq (ly_symbol2scm ("tie-break-cautionary"), opts);
92 Grob *tie = unsmob_grob (gh_cadr (t));
93 Spanner *sp = dynamic_cast<Spanner*> (tie);
96 /* there should be a better way to delete me */
97 scm_set_car_x (s, gh_list (gh_caar (s),
98 ly_symbol2scm ("deleted"),
100 me->set_grob_property ("molecule", SCM_EOL);
105 return SCM_UNSPECIFIED;
109 UGH. clean me, revise placement routine (See Ross & Wanske;
110 accidental placement is more complicated than this.
113 MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule,1);
115 Local_key_item::brew_molecule (SCM smob)
117 Grob* me = unsmob_grob (smob);
121 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
126 SCM accs = me->get_grob_property ("accidentals");
128 gh_pair_p (s); s = gh_cdr (s))
130 Pitch p (*unsmob_pitch (gh_caar (s)));
131 SCM opts = gh_cdar (s);
133 if (scm_memq (ly_symbol2scm ("deleted"), opts) != SCM_BOOL_F)
137 if (p.octave_i () != lastoct)
141 Real dy =lastoct*7* note_distance;
142 octave_mol.translate_axis (dy, Y_AXIS);
143 mol.add_molecule (octave_mol);
144 octave_mol = Molecule ();
149 lastoct = p.octave_i () ;
151 SCM c0 = me->get_grob_property ("c0-position");
152 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
155 Molecule acc (Font_interface::get_default_font (me)->find_by_name (String ("accidentals-")
156 + to_str (p.alteration_i_)));
158 if (scm_memq (ly_symbol2scm ("natural"), opts) != SCM_BOOL_F)
160 Molecule prefix = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-0"));
161 acc.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
164 if (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F)
165 acc = parenthesize (me, acc);
167 acc.translate_axis (dy, Y_AXIS);
168 octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
173 Real dy =lastoct*7*note_distance;
174 octave_mol.translate_axis (dy, Y_AXIS);
175 mol.add_molecule (octave_mol);
176 octave_mol = Molecule ();
179 if (gh_pair_p (accs))
181 Drul_array<SCM> pads;
186 pads[RIGHT] = me->get_grob_property ("right-padding");
187 pads[LEFT] = me->get_grob_property ("left-padding");
193 if (!gh_number_p (pads[d]))
196 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
198 Molecule m (Lookup::blank (b));
199 mol.add_at_edge (X_AXIS, d, m, 0);
200 } while ( flip (&d)!= LEFT);
203 return mol.smobbed_copy();
207 Local_key_item::has_interface (Grob*m)
209 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
212 Local_key_item::set_interface (Grob*m)
214 m->set_interface (ly_symbol2scm ("accidentals-interface"));