lilypond-1.3.28
[lilypond.git] / lily / local-key-item.cc
blobd18824b443a58c77df4ab3504b8ace86a5d517f9
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"
18 void
19 Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural)
21 for (int i=0; i< accidental_arr_.size(); i++)
22 if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
23 return;
24 /* maybe natural (and cautionary) should be modif. nonetheless? */
26 Local_key_cautionary_tuple t;
27 t.pitch_ = p;
28 t.cautionary_b_ = cautionary;
29 t.natural_b_ = natural;
30 accidental_arr_.push (t);
35 void
36 Local_key_item::do_pre_processing()
38 accidental_arr_.sort (Local_key_cautionary_tuple::compare);
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;
61 Molecule*
62 Local_key_item::do_brew_molecule_p() const
64 Molecule*output = new Molecule;
65 Staff_symbol_referencer_interface si (this);
66 Real note_distance = si.staff_space ()/2;
67 Molecule *octave_mol_p = 0;
68 int lastoct = -100;
70 for (int i = 0; i < accidental_arr_.size(); i++)
72 Musical_pitch p (accidental_arr_[i].pitch_);
73 // do one octave
74 if (p.octave_i_ != lastoct)
76 if (octave_mol_p)
78 Real dy =lastoct*7* note_distance;
79 octave_mol_p->translate_axis (dy, Y_AXIS);
80 output->add_molecule (*octave_mol_p);
81 delete octave_mol_p;
83 octave_mol_p= new Molecule;
86 lastoct = p.octave_i_;
88 SCM c0 = get_elt_property ("c0-position");
89 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
90 * note_distance;
92 Molecule m (accidental (p.accidental_i_,
93 accidental_arr_[i].cautionary_b_,
94 accidental_arr_[i].natural_b_));
96 m.translate_axis (dy, Y_AXIS);
97 octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
100 if (octave_mol_p)
102 Real dy =lastoct*7*note_distance;
103 octave_mol_p->translate_axis (dy, Y_AXIS);
104 output->add_molecule (*octave_mol_p);
105 delete octave_mol_p;
108 if (accidental_arr_.size())
110 Drul_array<SCM> pads;
113 Use a cons?
115 pads[RIGHT] = get_elt_property ("right-padding");
116 pads[LEFT] = get_elt_property ("left-padding");
118 Direction d = LEFT;
119 do {
120 if (!gh_number_p (pads[d]))
121 continue;
123 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
124 Interval (0,0));
125 Molecule m (lookup_l ()->fill (b));
126 output->add_at_edge (X_AXIS, d, m, 0);
127 } while ( flip (&d)!= LEFT);
130 return output;