]> git.donarmstrong.com Git - lilypond.git/blob - src/keyitem.cc
release: 0.0.26
[lilypond.git] / src / keyitem.cc
1 #include "keyitem.hh"
2 #include "key.hh"
3 #include "debug.hh"
4 #include "molecule.hh"
5 #include "paper.hh"
6 #include "lookup.hh"
7 #include "clef.hh"
8
9 const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
10 const int SHARP_TOP_PITCH=4; /*  ais and bis typeset in lower octave */
11 NAME_METHOD(Keyitem);
12 Keyitem::Keyitem(int c)
13 {
14     c_position = c;
15 }
16
17 void
18 Keyitem::read(Array<int> s)
19 {
20     for (int i = 0 ; i< s.size(); ) {
21         int note = s[i++];
22         int acc = s[i++];
23             
24         add(note, acc);
25     }
26 }
27
28 void 
29 Keyitem::read(const Clef& c)
30 {
31     c_position=(c.c0_pos+70)%7;
32 }
33
34
35 void
36 Keyitem::add(int p, int a)
37 {
38     if ((a<0 && p>FLAT_TOP_PITCH) ||
39         (a>0 && p>SHARP_TOP_PITCH)) {
40       p=p-7; /* Typeset below c_position */
41     }
42     pitch.push(p);
43     acc.push(a);
44 }
45
46
47 Molecule*
48 Keyitem::brew_molecule_p()const
49 {
50     Molecule*output = new Molecule;
51     Real inter = paper()->interline()/2;
52     
53     for (int i =0; i < pitch.size(); i++) {
54         Symbol s= paper()->lookup_p_->accidental(acc[i]);
55         Atom a(s);
56         a.translate(Offset(0,(c_position + pitch[i]) * inter));
57         Molecule m(a);
58         output->add_right(m);   
59     }
60     Molecule m(paper()->lookup_p_->fill(Box(
61         Interval(0, paper()->note_width()),
62         Interval(0,0))));
63     output->add_right(m);
64     return output;
65 }