lilypond-1.3.11
[lilypond.git] / lily / local-key-item.cc
blob72c7104e4abfdf3e856242bbf8937dafbac11e5e
1 /*
2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "local-key-item.hh"
9 #include "molecule.hh"
10 #include "staff-symbol-referencer.hh"
12 #include "lookup.hh"
13 #include "paper-def.hh"
14 #include "musical-request.hh"
15 #include "note-head.hh"
16 #include "misc.hh"
18 Local_key_item::Local_key_item ()
20 c0_position_i_ = 0;
23 void
24 Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural)
26 for (int i=0; i< accidental_arr_.size(); i++)
27 if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
28 return;
29 /* maybe natural (and cautionary) should be modif. nonetheless? */
31 Local_key_cautionary_tuple t;
32 t.pitch_ = p;
33 t.cautionary_b_ = cautionary;
34 t.natural_b_ = natural;
35 accidental_arr_.push (t);
40 void
41 Local_key_item::do_pre_processing()
43 accidental_arr_.sort (Local_key_cautionary_tuple::compare);
44 Note_head_side::do_pre_processing ();
47 Molecule
48 Local_key_item::accidental (int j, bool cautionary, bool natural) const
50 Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
51 if (natural)
53 Molecule prefix = lookup_l ()->afm_find (String ("accidentals-0"));
54 m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
56 if (cautionary)
58 Molecule open = lookup_l ()->afm_find (String ("accidentals-("));
59 Molecule close = lookup_l ()->afm_find (String ("accidentals-)"));
60 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
61 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
64 return m;
67 Molecule*
68 Local_key_item::do_brew_molecule_p() const
70 Molecule*output = new Molecule;
71 Staff_symbol_referencer_interface si (this);
72 Real note_distance = si.staff_line_leading_f ()/2;
73 Molecule *octave_mol_p = 0;
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 (octave_mol_p)
84 Real dy =lastoct*7* note_distance;
85 octave_mol_p->translate_axis (dy, Y_AXIS);
86 output->add_molecule (*octave_mol_p);
87 delete octave_mol_p;
89 octave_mol_p= new Molecule;
92 lastoct = p.octave_i_;
93 Real dy =
94 (c0_position_i_ + p.notename_i_)
95 * note_distance;
97 Molecule m (accidental (p.accidental_i_,
98 accidental_arr_[i].cautionary_b_,
99 accidental_arr_[i].natural_b_));
101 m.translate_axis (dy, Y_AXIS);
102 octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
105 if (octave_mol_p)
107 Real dy =lastoct*7*note_distance;
108 octave_mol_p->translate_axis (dy, Y_AXIS);
109 output->add_molecule (*octave_mol_p);
110 delete octave_mol_p;
113 if (accidental_arr_.size())
115 Drul_array<SCM> pads;
118 Use a cons?
120 pads[RIGHT] = get_elt_property ("right-padding");
121 pads[LEFT] = get_elt_property ("left-padding");
123 Direction d = LEFT;
124 do {
125 if (!gh_number_p (pads[d]))
126 continue;
128 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
129 Interval (0,0));
130 Molecule m (lookup_l ()->fill (b));
131 output->add_at_edge (X_AXIS, d, m, 0);
132 } while ( flip (&d)!= LEFT);
135 return output;