summaryrefslogtreecommitdiff
path: root/lily/key-item.cc
blob: c765fd0206cc55331cd314f5d507a8653d7f0b2f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
  key-item.cc -- implement Key_item

  source file of the GNU LilyPond music typesetter

  (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>

  keyplacement by Mats Bengtsson
*/

#include "key-item.hh"
#include "key.hh"
#include "debug.hh"
#include "molecule.hh"
#include "paper-def.hh"
#include "lookup.hh"

#include "key-grav.hh"

const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
const int SHARP_TOP_PITCH=4; /*  ais and bis typeset in lower octave */

Key_item::Key_item (int c)
{
    breakable_b_ =true;
    default_b_ = false;
    set_c_position (c);
}

void
Key_item::read (Key_engraver const & key_grav_r)
{
    assert (!key_grav_r.key_.multi_octave_b_);
    const Array<int> &idx_arr =key_grav_r.accidental_idx_arr_; 
    for (int i = 0 ; i< idx_arr.size(); i++) {
	int note = idx_arr[i];
	int acc = ((Key &) key_grav_r.key_).oct (0).acc (note);

	add (note, acc);
    }
}

void 
Key_item::set_c_position (int c0)
{
    int octaves =(abs (c0) / 7) +1 ;
    c_position=(c0 + 7*octaves)%7;
}


void
Key_item::add (int p, int a)
{
    if ((a<0 && p>FLAT_TOP_PITCH) ||
        (a>0 && p>SHARP_TOP_PITCH)) {
      p -= 7; /* Typeset below c_position */
    }
    pitch.push (p);
    acc.push (a);
}


Molecule*
Key_item::brew_molecule_p()const
{
    Molecule*output = new Molecule;
    Real inter = paper()->internote_f ();
    
    for (int i =0; i < pitch.size(); i++) {
	Symbol s= paper()->lookup_l ()->accidental (acc[i]);
	Atom a (s);
	a.translate ((c_position + pitch[i]) * inter, Y_AXIS);
	Molecule m (a);
	output->add_right (m);	
    }
    if ( pitch.size()) {
	Molecule m (paper()->lookup_l ()->fill (Box (
	Interval (0, paper()->note_width ()),
	Interval (0,0))));

	output->add_right (m);
    }
    return output;
}

IMPLEMENT_IS_TYPE_B1(Key_item,Item);

void 
Key_item::do_pre_processing()
{
    if (default_b_) {
	empty_b_ = transparent_b_ = (break_status_i() != 1);
    }
}