]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
c4041f0b92aefe4faa70795ce4553a8b48f21b87
[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--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "dimen.hh"
9 #include "local-key-item.hh"
10 #include "molecule.hh"
11 #include "scalar.hh"
12 #include "lookup.hh"
13 #include "paper-def.hh"
14 #include "musical-request.hh"
15 #include "note-head.hh"
16 #include "misc.hh"
17
18 Local_key_item::Local_key_item (int i)
19 {
20   c0_position  = i;
21 }
22
23 void
24 Local_key_item::add_support (Item*head_l)
25 {
26   if (support_items_.find_l(head_l))
27     return ;
28   support_items_.push (head_l);
29   add_dependency (head_l);
30 }
31
32 void
33 Local_key_item::add (Musical_pitch p)
34 {
35   for (int i=0; i< accs.size(); i++)
36     if (!Musical_pitch::compare (p, accs[i]))
37       return;
38   
39   accs.push (p);
40 }
41
42 void
43 Local_key_item::do_pre_processing()
44 {
45   accs.sort (Musical_pitch::compare);
46 }
47
48 Molecule*
49 Local_key_item::brew_molecule_p() const
50 {
51   Molecule*output = new Molecule;
52
53   Molecule *octave_mol_p = 0;
54   int lastoct = -100;
55   for  (int i = 0; i <  accs.size(); i++) 
56     {
57       // do one octave
58       if (accs[i].octave_i_ != lastoct) 
59         {
60           if (octave_mol_p)
61             {
62               Real dy =lastoct*7*paper()->internote_f ();
63               octave_mol_p->translate_axis (dy, Y_AXIS);
64               output->add (*octave_mol_p);
65               delete octave_mol_p;
66             }
67           octave_mol_p= new Molecule;
68         }
69       lastoct = accs[i].octave_i_;
70       Real dy = (accs[i].notename_i_ + c0_position) * paper()->internote_f ();
71       Atom a (paper()->lookup_l ()->accidental (accs[i].accidental_i_));
72
73       a.translate_axis (dy, Y_AXIS);
74       Molecule m(a);
75       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m);
76     }
77
78   if (octave_mol_p)
79     {
80       Real dy =lastoct*7*paper()->internote_f ();
81       octave_mol_p->translate_axis (dy, Y_AXIS);
82       output->add (*octave_mol_p);
83       delete octave_mol_p;
84     }
85   
86  if (accs.size()) 
87     {
88       Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
89       Molecule m (paper()->lookup_l ()->fill (b));
90       output->add_at_edge (X_AXIS, RIGHT, m);
91     }
92
93   Interval x_int;
94   for (int i=0; i < support_items_.size(); i++) 
95     {
96       Axis_group_element *common = 
97         common_group (support_items_[i], X_AXIS);
98
99       Real x = support_items_[i]->relative_coordinate (common, X_AXIS)  
100         -relative_coordinate (common, X_AXIS);
101
102       x_int.unite (x + support_items_[i]->width());
103     }
104   if (x_int.empty_b ())
105     x_int = Interval(0,0);
106   
107   output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
108   
109   return output;
110 }
111
112 IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
113
114 void
115 Local_key_item::do_substitute_dependency (Score_elem*o,Score_elem*n)
116 {
117   Item* o_l = o->item();
118   Item* n_l = n?n->item():0;
119
120   support_items_.substitute (o_l, n_l);
121 }