2 key-item.cc -- implement Key_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 keyplacement by Mats Bengtsson
11 #include "group-interface.hh"
12 #include "key-item.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
16 #include "staff-symbol-referencer.hh"
18 const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
19 const int SHARP_TOP_PITCH=4; /* ais and bis typeset in lower octave */
21 Key_item::Key_item (SCM s)
24 set_elt_property ("c0-position", gh_int2scm (0));
28 Key_item::add (int p, int a)
30 SCM pair = gh_cons (gh_int2scm (p),gh_int2scm (a));
31 Group_interface (this, "new-accidentals").add_thing (pair);
35 Key_item::add_old (int p, int a)
37 SCM pair = gh_cons (gh_int2scm (p),gh_int2scm (a));
38 Group_interface (this, "old-accidentals").add_thing (pair);
43 Key_item::calculate_position(SCM pair) const
45 int p = gh_scm2int (gh_car (pair));
46 int a = gh_scm2int (gh_cdr (pair));
48 if (to_boolean (get_elt_property ("multi-octave")))
50 return p + gh_scm2int (get_elt_property ("c0-position"));
53 // Find the c in the range -4 through 2
54 int from_bottom_pos = gh_scm2int (get_elt_property ("c0-position")) + 4;
55 from_bottom_pos = from_bottom_pos%7;
56 from_bottom_pos = (from_bottom_pos + 7)%7; // Precaution to get positive.
57 int c0 = from_bottom_pos - 4;
60 if ((a<0 && ((p>FLAT_TOP_PITCH) || (p+c0>4)) && (p+c0>1))
62 (a>0 && ((p>SHARP_TOP_PITCH) || (p+c0>5)) && (p+c0>2)))
64 p -= 7; /* Typeset below c_position */
66 /* Provide for the four cases in which there's a glitch
67 it's a hack, but probably not worth
68 the effort of finding a nicer solution.
70 if (c0==2 && a>0 && p==3)
72 if (c0==-3 && a>0 && p==-1)
74 if (c0==-4 && a<0 && p==-1)
76 if (c0==-2 && a<0 && p==-3)
85 - space the `natural' signs wider
89 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Key_item)
91 Key_item::do_brew_molecule () const
95 Staff_symbol_referencer_interface si (this);
96 Real inter = si.staff_space ()/2.0;
98 SCM newas = get_elt_property ("new-accidentals");
101 SCM lists are stacks, so we work from right to left, ending with
102 the cancellation signature.
104 for (SCM s = newas; gh_pair_p (s); s = gh_cdr (s))
106 int a = gh_scm2int (gh_cdar (s));
107 Molecule m = lookup_l ()->afm_find ("accidentals-" + to_str (a));
108 m.translate_axis (calculate_position(gh_car (s)) * inter, Y_AXIS);
109 mol.add_at_edge (X_AXIS, LEFT, m, 0);
112 if (break_status_dir () != RIGHT)
114 SCM old = get_elt_property ("old-accidentals");
116 Add half a space between cancellation and key sig.
118 As suggested by [Ross], p.148.
120 Interval x(0, inter);
123 mol.add_at_edge (X_AXIS, LEFT, lookup_l()->blank (Box(x,y)),0);
125 for (; gh_pair_p (old); old = gh_cdr (old))
130 find correspondences in pitches
132 for (SCM s = newas; gh_pair_p (s); s = gh_cdr (s))
133 if (gh_caar(s) == gh_caar (old))
136 if (found == SCM_EOL || gh_cdr (found) != gh_cdar (old))
138 Molecule m =lookup_l ()->afm_find ("accidentals-0");
140 m.translate_axis (calculate_position(gh_car(old)) * inter, Y_AXIS);
141 mol.add_at_edge (X_AXIS, LEFT, m,0);