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"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "rhythmic-head.hh"
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_))
23 /* maybe natural (and cautionary) should be modif. nonetheless? */
25 Local_key_cautionary_tuple t;
27 t.cautionary_b_ = cautionary;
28 t.natural_b_ = natural;
29 accidental_arr_.push (t);
32 MAKE_SCHEME_CALLBACK(Local_key_item,before_line_breaking);
35 Local_key_item::before_line_breaking (SCM smob)
37 Local_key_item* me = dynamic_cast<Local_key_item*>(unsmob_element (smob));
38 me->accidental_arr_.sort (Local_key_cautionary_tuple::compare);
39 return SCM_UNSPECIFIED;
43 Local_key_item::accidental (Score_element*me, int j, bool cautionary, bool natural)
45 Molecule m (me->lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
48 Molecule prefix = me->lookup_l ()->afm_find (String ("accidentals-0"));
49 m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
53 Molecule open = me->lookup_l ()->afm_find (String ("accidentals-("));
54 Molecule close = me->lookup_l ()->afm_find (String ("accidentals-)"));
55 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
56 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
66 MAKE_SCHEME_CALLBACK(Local_key_item,brew_molecule);
68 Local_key_item::brew_molecule (SCM smob)
70 Local_key_item* lki = dynamic_cast<Local_key_item*>(unsmob_element (smob));
71 Score_element* me = lki;
75 Real note_distance = Staff_symbol_referencer::staff_space (me)/2;
80 for (int i = 0; i < lki->accidental_arr_.size(); i++)
82 Musical_pitch p (lki->accidental_arr_[i].pitch_);
84 if (p.octave_i_ != lastoct)
88 Real dy =lastoct*7* note_distance;
89 octave_mol.translate_axis (dy, Y_AXIS);
90 mol.add_molecule (octave_mol);
91 octave_mol = Molecule ();
96 lastoct = p.octave_i_;
98 SCM c0 = me->get_elt_property ("c0-position");
99 Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
102 Molecule m (accidental (me,p.accidental_i_,
103 lki->accidental_arr_[i].cautionary_b_,
104 lki->accidental_arr_[i].natural_b_));
106 m.translate_axis (dy, Y_AXIS);
107 octave_mol.add_at_edge (X_AXIS, RIGHT, m, 0);
112 Real dy =lastoct*7*note_distance;
113 octave_mol.translate_axis (dy, Y_AXIS);
114 mol.add_molecule (octave_mol);
115 octave_mol = Molecule ();
118 if (lki->accidental_arr_.size())
120 Drul_array<SCM> pads;
125 pads[RIGHT] = me->get_elt_property ("right-padding");
126 pads[LEFT] = me->get_elt_property ("left-padding");
132 if (!gh_number_p (pads[d]))
135 Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
137 Molecule m (me->lookup_l ()->blank (b));
138 mol.add_at_edge (X_AXIS, d, m, 0);
139 } while ( flip (&d)!= LEFT);
142 return mol.create_scheme();
145 Local_key_item::Local_key_item (SCM s)
151 Local_key_item::has_interface (Score_element*m)
153 return m && m->has_interface (ly_symbol2scm ("accidentals-interface"));