lilypond-1.3.65
[lilypond.git] / lily / local-key-item.cc
blob0c1ec92137f530c59e871a16897203a891785fc0
1 /*
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>
7 */
8 #include "local-key-item.hh"
9 #include "molecule.hh"
10 #include "staff-symbol-referencer.hh"
11 #include "lookup.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "note-head.hh"
15 #include "misc.hh"
17 void
18 Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural)
20 for (int i=0; i< accidental_arr_.size(); i++)
21 if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
22 return;
23 /* maybe natural (and cautionary) should be modif. nonetheless? */
25 Local_key_cautionary_tuple t;
26 t.pitch_ = p;
27 t.cautionary_b_ = cautionary;
28 t.natural_b_ = natural;
29 accidental_arr_.push (t);
32 GLUE_SCORE_ELEMENT(Local_key_item,before_line_breaking);
34 SCM
35 Local_key_item::member_before_line_breaking ()
37 accidental_arr_.sort (Local_key_cautionary_tuple::compare);
38 return SCM_UNDEFINED;
41 Molecule
42 Local_key_item::accidental (int j, bool cautionary, bool natural) const
44 Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
45 if (natural)
47 Molecule prefix = lookup_l ()->afm_find (String ("accidentals-0"));
48 m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
50 if (cautionary)
52 Molecule open = lookup_l ()->afm_find (String ("accidentals-("));
53 Molecule close = lookup_l ()->afm_find (String ("accidentals-)"));
54 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
55 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
58 return m;
62 UGH. clean me up
65 GLUE_SCORE_ELEMENT(Local_key_item,brew_molecule);
66 SCM
67 Local_key_item::member_brew_molecule () const
69 Molecule mol;
70 Staff_symbol_referencer_interface si (this);
71 Real note_distance = si.staff_space ()/2;
72 Molecule octave_mol;
73 bool oct_b = false;
74 int lastoct = -100;
76 for (int i = 0; i < accidental_arr_.size(); i++)
78 Musical_pitch p (accidental_arr_[i].pitch_);
79 // do one octave
80 if (p.octave_i_ != lastoct)
82 if (oct_b)
84 Real dy =lastoct*7* note_distance;
85 octave_mol.translate_axis (dy, Y_AXIS);
86 mol.add_molecule (octave_mol);
87 octave_mol = Molecule ();
89 oct_b = true;
92 lastoct = p.octave_i_;
94 SCM c0 = get_elt_property ("c0-position");
95 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
96 * note_distance;
98 Molecule m (accidental (p.accidental_i_,
99 accidental_arr_[i].cautionary_b_,
100 accidental_arr_[i].natural_b_));
102 m.translate_axis (dy, Y_AXIS);
103 octave_mol.add_at_edge (X_AXIS, RIGHT, m, 0);
106 if (oct_b)
108 Real dy =lastoct*7*note_distance;
109 octave_mol.translate_axis (dy, Y_AXIS);
110 mol.add_molecule (octave_mol);
111 octave_mol = Molecule ();
114 if (accidental_arr_.size())
116 Drul_array<SCM> pads;
119 Use a cons?
121 pads[RIGHT] = get_elt_property ("right-padding");
122 pads[LEFT] = get_elt_property ("left-padding");
125 // unused ?
126 Direction d = LEFT;
127 do {
128 if (!gh_number_p (pads[d]))
129 continue;
131 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
132 Interval (0,0));
133 Molecule m (lookup_l ()->blank (b));
134 mol.add_at_edge (X_AXIS, d, m, 0);
135 } while ( flip (&d)!= LEFT);
138 return mol.create_scheme();
141 Local_key_item::Local_key_item (SCM s)
142 : Item (s)