]> git.donarmstrong.com Git - lilypond.git/blob - lily/bow.cc
016308a23359fabbcb805135b52c2225bf475aa5
[lilypond.git] / lily / bow.cc
1 /*
2   bow.cc -- implement Bow
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7       Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "bow.hh"
11 #include "debug.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "lookup.hh"
15 #include "bezier.hh"
16 #include "main.hh"
17
18
19
20 Bow::Bow ()
21 {
22   dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = 0.0;
23   dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
24   dash_i_ = 0;
25 }
26
27 Molecule*
28 Bow::brew_molecule_p () const
29 {
30   Real thick = paper ()->get_var ("slur_thickness");
31   Array<Offset> c = get_controls ();
32   Real dy = c[3].y () - c[0].y ();
33   Atom a;
34
35   if (!dash_i_)
36     a = lookup_l ()->slur (c);
37   else
38     a = lookup_l ()->dashed_slur (c, thick, dash_i_);
39
40   if (check_debug && !monitor->silent_b ("Bow"))
41     {
42       static int i = 1;
43       cout << "******" << i++ << "******" << endl;
44       // gcc 2.7.2: ices
45 //      cout << "c0.y: " << c[0].y << endl;
46       cout << "c0.y: " << c[0].y () << endl;
47       cout << "c3.y: " << c[3].y () << endl;
48       cout << "dy: " << dy << endl;
49       cout << "dy_f_l: " << dy_f_drul_[LEFT] << endl;
50       cout << "dy_f_r: " << dy_f_drul_[RIGHT] << endl;
51       cout << "dy_f: " << dy_f_drul_[RIGHT] - dy_f_drul_[LEFT] << endl;
52     }
53   a.translate (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
54
55   Molecule* mol_p = new Molecule;
56   mol_p->add_atom (a);
57
58   return mol_p;
59 }
60
61 Offset
62 Bow::center () const
63 {
64   Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
65
66   Real dx = width ().length ();
67
68   return Offset (dx / 2, dy);
69 }
70
71
72
73 /*
74    
75    ugh .  Control points are too crude measures.
76  */
77 Interval
78 Bow::do_height () const
79 {
80   Interval iv;
81   Array<Offset> c (get_controls());
82   for (int i=0; i < c.size (); i++)
83     {
84       Real y = c[i][Y_AXIS];
85       iv.unite (Interval (y,y));
86     }
87   return iv;
88 }
89
90 Interval
91 Bow::do_width () const    
92 {
93   Interval i = Spanner::do_width ();
94   Real dx = i.length();
95   return Interval (0, dx);
96 }
97
98 Array<Offset>
99 Bow::get_controls () const
100 {
101   Bezier_bow b (paper ());
102   b.set (get_encompass_offset_arr (), dir_);
103   b.calc ();
104   Array<Offset> controls;
105   controls.set_size (8);
106   for (int i = 0; i < 4; i++)
107     controls[i] = b.control_[i];
108   for (int i = 0; i < 4; i++)
109     controls[i + 4] = b.return_[i];
110   return controls;
111 }
112
113 Array<Offset>
114 Bow::get_encompass_offset_arr () const
115 {
116   Offset d (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
117     dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
118   d.x() += width (). length ();
119
120   Array<Offset> notes;
121   notes.push (Offset (0, 0));
122   notes.push (d);
123
124   return notes;
125 }
126