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"
19 pitch_less (SCM p1, SCM p2)
21 return Pitch::less_p (gh_car (p1), gh_car (p2));
24 static SCM pitch_less_proc;
29 pitch_less_proc = gh_new_procedure2_0 ("pits-less", &pitch_less);
32 ADD_SCM_INIT_FUNC(lkpitch,init_pitch_funcs);
36 Local_key_item::add_pitch (Grob*me, Pitch p, bool cautionary, bool natural)
38 SCM acs = me->get_grob_property ("accidentals");
39 SCM pitch = p.smobbed_copy ();
42 opts = gh_cons (ly_symbol2scm ("cautionary"), opts);
44 opts = gh_cons (ly_symbol2scm ("natural"), opts);
46 pitch = gh_cons (pitch, opts);
47 acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
49 me->set_grob_property ("accidentals", acs);
53 Local_key_item::parenthesize (Grob*me, Molecule m)
55 Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-("));
56 Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-)"));
57 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
58 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
64 UGH. clean me, revise placement routine (See Ross & Wanske;
65 accidental placement is more complicated than this.
68 MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule,1);
70 Local_key_item::brew_molecule (SCM smob)
72 Grob* me = unsmob_grob (smob);
76 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
81 SCM accs = me->get_grob_property ("accidentals");
83 gh_pair_p (s); s = gh_cdr (s))
85 Pitch p (*unsmob_pitch (gh_caar (s)));
86 SCM opts = gh_cdar (s);
89 if (p.octave_i () != lastoct)
93 Real dy =lastoct*7* note_distance;
94 octave_mol.translate_axis (dy, Y_AXIS);
95 mol.add_molecule (octave_mol);
96 octave_mol = Molecule ();
101 lastoct = p.octave_i () ;
103 SCM c0 = me->get_grob_property ("c0-position");
104 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
107 Molecule acc (Font_interface::get_default_font (me)->find_by_name (String ("accidentals-")
108 + to_str (p.alteration_i_)));
110 if (scm_memq (ly_symbol2scm ("natural"), opts) != SCM_BOOL_F)
112 Molecule prefix = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-0"));
113 acc.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
116 if (scm_memq (ly_symbol2scm ("cautionary"), opts) != SCM_BOOL_F)
117 acc = parenthesize (me, acc);
119 acc.translate_axis (dy, Y_AXIS);
120 octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
125 Real dy =lastoct*7*note_distance;
126 octave_mol.translate_axis (dy, Y_AXIS);
127 mol.add_molecule (octave_mol);
128 octave_mol = Molecule ();
131 if (gh_pair_p (accs))
133 Drul_array<SCM> pads;
138 pads[RIGHT] = me->get_grob_property ("right-padding");
139 pads[LEFT] = me->get_grob_property ("left-padding");
145 if (!gh_number_p (pads[d]))
148 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
150 Molecule m (Lookup::blank (b));
151 mol.add_at_edge (X_AXIS, d, m, 0);
152 } while ( flip (&d)!= LEFT);
155 return mol.smobbed_copy();
159 Local_key_item::has_interface (Grob*m)
161 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
164 Local_key_item::set_interface (Grob*m)
166 m->set_interface (ly_symbol2scm ("accidentals-interface"));