]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.1.51
[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 #include "scalar.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 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 void
37 Local_key_item::do_pre_processing()
38 {
39   accidental_arr_.sort (Local_key_cautionary_tuple::compare);
40   Note_head_side::do_pre_processing ();
41 }
42
43 Molecule*
44 Local_key_item::do_brew_molecule_p() const
45 {
46   Molecule*output = new Molecule;
47   Real note_distance = staff_line_leading_f ()/2;
48   Molecule *octave_mol_p = 0;
49   int lastoct = -100;
50   
51   for  (int i = 0; i <  accidental_arr_.size(); i++) 
52     {
53       Musical_pitch p (accidental_arr_[i].pitch_);
54       // do one octave
55       if (p.octave_i_ != lastoct) 
56         {
57           if (octave_mol_p)
58             {
59               Real dy =lastoct*7* note_distance;
60               octave_mol_p->translate_axis (dy, Y_AXIS);
61               output->add_molecule (*octave_mol_p);
62               delete octave_mol_p;
63             }
64           octave_mol_p= new Molecule;
65         }
66       
67       lastoct = p.octave_i_;
68       Real dy =
69         (c0_position_i_ + p.notename_i_)
70         * note_distance;
71       Molecule m (lookup_l ()->accidental (p.accidental_i_, 
72                                            accidental_arr_[i].cautionary_b_));
73
74       m.translate_axis (dy, Y_AXIS);
75       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
76     }
77
78   if (octave_mol_p)
79     {
80       Real dy =lastoct*7*note_distance;
81       octave_mol_p->translate_axis (dy, Y_AXIS);
82       output->add_molecule (*octave_mol_p);
83       delete octave_mol_p;
84     }
85   
86  if (accidental_arr_.size()) 
87     {
88       Box b(Interval (0, 0.6 * note_distance), Interval (0,0));
89       Molecule m (lookup_l ()->fill (b));
90       output->add_at_edge (X_AXIS, RIGHT, m, 0);
91     }
92
93   return output;
94 }
95
96 void
97 Local_key_item::do_substitute_element_pointer (Score_element *o, Score_element*n)
98 {
99   Note_head_side::do_substitute_element_pointer (o,n);
100   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
101   
102 }