]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
patch::: 1.3.8.uu1
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "local-key-item.hh"
9 #include "molecule.hh"
10
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 Local_key_item::Local_key_item ()
18 {
19   c0_position_i_ = 0;
20 }
21
22 void
23 Local_key_item::add_pitch (Musical_pitch p, bool cautionary, bool natural)
24 {
25   for (int i=0; i< accidental_arr_.size(); i++)
26     if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
27       return;
28           /* maybe natural (and cautionary) should be modif. nonetheless? */
29
30   Local_key_cautionary_tuple t;
31   t.pitch_ = p;
32   t.cautionary_b_ = cautionary;
33   t.natural_b_ = natural;
34   accidental_arr_.push (t);
35 }
36
37
38
39 void
40 Local_key_item::do_pre_processing()
41 {
42   accidental_arr_.sort (Local_key_cautionary_tuple::compare);
43   Note_head_side::do_pre_processing ();
44 }
45
46 Molecule
47 Local_key_item::accidental (int j, bool cautionary, bool natural) const
48 {
49   Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
50   if (natural)
51     {
52           Molecule prefix = lookup_l ()->afm_find (String ("accidentals-0"));
53           m.add_at_edge(X_AXIS, LEFT, Molecule(prefix), 0);
54         }
55   if (cautionary) 
56     {
57       Molecule open = lookup_l ()->afm_find (String ("accidentals-("));
58       Molecule close = lookup_l ()->afm_find (String ("accidentals-)"));
59       m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
60       m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
61     }
62   
63   return m;
64 }
65
66 Molecule*
67 Local_key_item::do_brew_molecule_p() const
68 {
69   Molecule*output = new Molecule;
70   Real note_distance = staff_line_leading_f ()/2;
71   Molecule *octave_mol_p = 0;
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 (octave_mol_p)
81             {
82               Real dy =lastoct*7* note_distance;
83               octave_mol_p->translate_axis (dy, Y_AXIS);
84               output->add_molecule (*octave_mol_p);
85               delete octave_mol_p;
86             }
87           octave_mol_p= new Molecule;
88         }
89       
90       lastoct = p.octave_i_;
91       Real dy =
92         (c0_position_i_ + p.notename_i_)
93         * note_distance;
94       
95       Molecule m (accidental (p.accidental_i_,
96                                   accidental_arr_[i].cautionary_b_,
97                                   accidental_arr_[i].natural_b_));
98
99       m.translate_axis (dy, Y_AXIS);
100       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
101     }
102
103   if (octave_mol_p)
104     {
105       Real dy =lastoct*7*note_distance;
106       octave_mol_p->translate_axis (dy, Y_AXIS);
107       output->add_molecule (*octave_mol_p);
108       delete octave_mol_p;
109     }
110   
111  if (accidental_arr_.size()) 
112     {
113       Box b(Interval (0, 0.6 * note_distance), Interval (0,0));
114       Molecule m (lookup_l ()->fill (b));
115       output->add_at_edge (X_AXIS, RIGHT, m, 0);
116     }
117
118   return output;
119 }
120
121 void
122 Local_key_item::do_substitute_element_pointer (Score_element *o, Score_element*n)
123 {
124   Note_head_side::do_substitute_element_pointer (o,n);
125   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
126   
127 }