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);
94 if (!sp->broken_into_l_arr_.size ())
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"),
104 return SCM_UNSPECIFIED;
108 UGH. clean me, revise placement routine (See Ross & Wanske;
109 accidental placement is more complicated than this.
112 MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule,1);
114 Local_key_item::brew_molecule (SCM smob)
116 Grob* me = unsmob_grob (smob);
120 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
125 SCM accs = me->get_grob_property ("accidentals");
127 gh_pair_p (s); s = gh_cdr (s))
129 Pitch p (*unsmob_pitch (gh_caar (s)));
130 SCM opts = gh_cdar (s);
132 if (scm_memq (ly_symbol2scm ("deleted"), opts) != SCM_BOOL_F)
136 if (p.octave_i () != lastoct)
140 Real dy =lastoct*7* note_distance;
141 octave_mol.translate_axis (dy, Y_AXIS);
142 mol.add_molecule (octave_mol);
143 octave_mol = Molecule ();
148 lastoct = p.octave_i () ;
150 SCM c0 = me->get_grob_property ("c0-position");
151 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
154 Molecule acc (Font_interface::get_default_font (me)->find_by_name (String ("accidentals-")
155 + to_str (p.alteration_i_)));
157 if (scm_memq (ly_symbol2scm ("natural"), opts) != SCM_BOOL_F)
159 Molecule prefix = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-0"));
160 acc.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
163 if (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F)
164 acc = parenthesize (me, acc);
166 acc.translate_axis (dy, Y_AXIS);
167 octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
172 Real dy =lastoct*7*note_distance;
173 octave_mol.translate_axis (dy, Y_AXIS);
174 mol.add_molecule (octave_mol);
175 octave_mol = Molecule ();
178 if (gh_pair_p (accs))
180 Drul_array<SCM> pads;
185 pads[RIGHT] = me->get_grob_property ("right-padding");
186 pads[LEFT] = me->get_grob_property ("left-padding");
192 if (!gh_number_p (pads[d]))
195 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
197 Molecule m (Lookup::blank (b));
198 mol.add_at_edge (X_AXIS, d, m, 0);
199 } while ( flip (&d)!= LEFT);
202 return mol.smobbed_copy();
206 Local_key_item::has_interface (Grob*m)
208 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
211 Local_key_item::set_interface (Grob*m)
213 m->set_interface (ly_symbol2scm ("accidentals-interface"));