]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.3.55
[lilypond.git] / lily / local-key-item.cc
1 /*
2   local-key-item.cc -- implement Local_key_item, Musical_pitch
3
4   source file of the GNU LilyPond music typesetter
5
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"
16
17
18 void
19 Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural)
20 {
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? */
25
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);
31 }
32
33
34
35 void
36 Local_key_item::before_line_breaking ()
37 {
38   accidental_arr_.sort (Local_key_cautionary_tuple::compare);
39 }
40
41 Molecule
42 Local_key_item::accidental (int j, bool cautionary, bool natural) const
43 {
44   Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
45   if (natural)
46     {
47       Molecule prefix = lookup_l ()->afm_find (String ("accidentals-0"));
48       m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
49     }
50   if (cautionary) 
51     {
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);
56     }
57   
58   return m;
59 }
60
61 /*
62   UGH. clean me up
63  */
64 Molecule 
65 Local_key_item::do_brew_molecule() const
66 {
67   Molecule mol;
68   Staff_symbol_referencer_interface si (this);
69   Real note_distance = si.staff_space ()/2;
70   Molecule octave_mol;
71   bool oct_b = false;
72   int lastoct = -100;
73   
74   for  (int i = 0; i <  accidental_arr_.size(); i++) 
75     {
76       Musical_pitch p (accidental_arr_[i].pitch_);
77       // do one octave
78       if (p.octave_i_ != lastoct) 
79         {
80           if (oct_b)
81             {
82               Real dy =lastoct*7* note_distance;
83               octave_mol.translate_axis (dy, Y_AXIS);
84               mol.add_molecule (octave_mol);
85               octave_mol = Molecule ();
86             }
87           oct_b = true; 
88         }
89       
90       lastoct = p.octave_i_;
91
92       SCM c0 =  get_elt_property ("c0-position");
93       Real dy = (gh_number_p (c0) ? gh_scm2int (c0) : 0 + p.notename_i_)
94         * note_distance;
95       
96       Molecule m (accidental (p.accidental_i_,
97                               accidental_arr_[i].cautionary_b_,
98                               accidental_arr_[i].natural_b_));
99
100       m.translate_axis (dy, Y_AXIS);
101       octave_mol.add_at_edge (X_AXIS, RIGHT, m, 0);
102     }
103
104   if (oct_b)
105     {
106       Real dy =lastoct*7*note_distance;
107       octave_mol.translate_axis (dy, Y_AXIS);
108       mol.add_molecule (octave_mol);
109       octave_mol = Molecule ();
110     }
111   
112  if (accidental_arr_.size()) 
113     {
114       Drul_array<SCM> pads;
115
116       /*
117         Use a cons?
118        */
119       pads[RIGHT] = get_elt_property ("right-padding");
120       pads[LEFT] = get_elt_property ("left-padding");
121
122
123       // unused ?
124       Direction d = LEFT;
125       do {
126         if (!gh_number_p (pads[d]))
127           continue;
128
129         Box b(Interval (0, gh_scm2double (pads[d]) * note_distance),
130               Interval (0,0));
131         Molecule m (lookup_l ()->blank (b));
132         mol.add_at_edge (X_AXIS, d, m, 0);
133       } while ( flip (&d)!= LEFT);
134     }
135
136   return mol;
137 }
138
139 Local_key_item::Local_key_item (SCM s)
140   : Item (s)
141 {
142   
143 }