2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 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 for (int i = 3; i--; p1 = gh_cdr (p1), p2 = gh_cdr (p2))
23 if (scm_less_p (gh_car (p1), gh_car (p2)))
25 if (gh_car (p1) != gh_car (p2))
37 pitch_less_proc = gh_new_procedure2_0 ("pitch-less", &pitch_less);
40 ADD_SCM_INIT_FUNC(pitch,init_pitch_funcs);
44 Local_key_item::add_pitch (Score_element*me, Musical_pitch p, bool cautionary, bool natural)
46 SCM acs = me->get_elt_property ("accidentals");
47 SCM pitch = p.to_scm ();
50 opts = gh_cons (ly_symbol2scm ("cautionary"), opts);
52 opts = gh_cons (ly_symbol2scm ("natural"), opts);
54 pitch = gh_append2 (pitch, opts);
55 acs = scm_merge_x (acs, gh_cons (pitch, SCM_EOL), pitch_less_proc);
57 me->set_elt_property ("accidentals", acs);
61 Local_key_item::parenthesize (Score_element*me, Molecule m)
63 Molecule open = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-("));
64 Molecule close = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-)"));
65 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
66 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
72 UGH. clean me, revise placement routine (See Ross & Wanske;
73 accidental placement is more complicated than this.
76 MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule,1);
78 Local_key_item::brew_molecule (SCM smob)
80 Score_element* me = unsmob_element (smob);
84 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
89 SCM accs = me->get_elt_property ("accidentals");
91 gh_pair_p (s); s = gh_cdr (s))
93 Musical_pitch p (gh_car (s));
96 if (p.octave_i_ != lastoct)
100 Real dy =lastoct*7* note_distance;
101 octave_mol.translate_axis (dy, Y_AXIS);
102 mol.add_molecule (octave_mol);
103 octave_mol = Molecule ();
108 lastoct = p.octave_i_;
110 SCM c0 = me->get_elt_property ("c0-position");
111 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
114 Molecule acc (Font_interface::get_default_font (me)->find_by_name (String ("accidentals-")
115 + to_str (p.accidental_i_)));
117 if (scm_memq (ly_symbol2scm ("natural"), gh_car (s)) != SCM_BOOL_F)
119 Molecule prefix = Font_interface::get_default_font (me)->find_by_name (String ("accidentals-0"));
120 acc.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
123 if (scm_memq (ly_symbol2scm ("cautionary"), gh_car (s)) != SCM_BOOL_F)
124 acc = parenthesize (me, acc);
126 acc.translate_axis (dy, Y_AXIS);
127 octave_mol.add_at_edge (X_AXIS, RIGHT, acc, 0);
132 Real dy =lastoct*7*note_distance;
133 octave_mol.translate_axis (dy, Y_AXIS);
134 mol.add_molecule (octave_mol);
135 octave_mol = Molecule ();
138 if (gh_pair_p (accs))
140 Drul_array<SCM> pads;
145 pads[RIGHT] = me->get_elt_property ("right-padding");
146 pads[LEFT] = me->get_elt_property ("left-padding");
152 if (!gh_number_p (pads[d]))
155 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
157 Molecule m (Lookup::blank (b));
158 mol.add_at_edge (X_AXIS, d, m, 0);
159 } while ( flip (&d)!= LEFT);
162 return mol.smobbed_copy();
166 Local_key_item::has_interface (Score_element*m)
168 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));
171 Local_key_item::set_interface (Score_element*m)
173 m->set_interface (ly_symbol2scm ("accidentals-interface"));