]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.3.6
[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)
24 {
25   for (int i=0; i< accidental_arr_.size(); i++)
26     if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
27       return;
28
29   Local_key_cautionary_tuple t;
30   t.pitch_ = p;
31   t.cautionary_b_ = cautionary;
32   accidental_arr_.push (t);
33 }
34
35
36
37 void
38 Local_key_item::do_pre_processing()
39 {
40   accidental_arr_.sort (Local_key_cautionary_tuple::compare);
41   Note_head_side::do_pre_processing ();
42 }
43
44 Molecule
45 Local_key_item::accidental (int j, bool cautionary) const
46 {
47   Molecule m (lookup_l ()->afm_find (String ("accidentals-") + to_str (j)));
48   if (cautionary) 
49     {
50       Molecule open = lookup_l ()->afm_find (String ("accidentals-("));
51       Molecule close = lookup_l ()->afm_find (String ("accidentals-)"));
52       m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
53       m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
54     }
55   
56   return m;
57 }
58
59 Molecule*
60 Local_key_item::do_brew_molecule_p() const
61 {
62   Molecule*output = new Molecule;
63   Real note_distance = staff_line_leading_f ()/2;
64   Molecule *octave_mol_p = 0;
65   int lastoct = -100;
66   
67   for  (int i = 0; i <  accidental_arr_.size(); i++) 
68     {
69       Musical_pitch p (accidental_arr_[i].pitch_);
70       // do one octave
71       if (p.octave_i_ != lastoct) 
72         {
73           if (octave_mol_p)
74             {
75               Real dy =lastoct*7* note_distance;
76               octave_mol_p->translate_axis (dy, Y_AXIS);
77               output->add_molecule (*octave_mol_p);
78               delete octave_mol_p;
79             }
80           octave_mol_p= new Molecule;
81         }
82       
83       lastoct = p.octave_i_;
84       Real dy =
85         (c0_position_i_ + p.notename_i_)
86         * note_distance;
87       
88       Molecule m (accidental (p.accidental_i_, accidental_arr_[i].cautionary_b_));
89
90       m.translate_axis (dy, Y_AXIS);
91       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
92     }
93
94   if (octave_mol_p)
95     {
96       Real dy =lastoct*7*note_distance;
97       octave_mol_p->translate_axis (dy, Y_AXIS);
98       output->add_molecule (*octave_mol_p);
99       delete octave_mol_p;
100     }
101   
102  if (accidental_arr_.size()) 
103     {
104       Box b(Interval (0, 0.6 * note_distance), Interval (0,0));
105       Molecule m (lookup_l ()->fill (b));
106       output->add_at_edge (X_AXIS, RIGHT, m, 0);
107     }
108
109   return output;
110 }
111
112 void
113 Local_key_item::do_substitute_element_pointer (Score_element *o, Score_element*n)
114 {
115   Note_head_side::do_substitute_element_pointer (o,n);
116   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
117   
118 }