lilypond-1.1.21
[lilypond.git] / lily / bow.cc
blob016308a23359fabbcb805135b52c2225bf475aa5
1 /*
2 bow.cc -- implement Bow
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
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"
20 Bow::Bow ()
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;
27 Molecule*
28 Bow::brew_molecule_p () const
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;
35 if (!dash_i_)
36 a = lookup_l ()->slur (c);
37 else
38 a = lookup_l ()->dashed_slur (c, thick, dash_i_);
40 if (check_debug && !monitor->silent_b ("Bow"))
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;
53 a.translate (Offset (dx_f_drul_[LEFT], dy_f_drul_[LEFT]));
55 Molecule* mol_p = new Molecule;
56 mol_p->add_atom (a);
58 return mol_p;
61 Offset
62 Bow::center () const
64 Real dy = dy_f_drul_[RIGHT] - dy_f_drul_[LEFT];
66 Real dx = width ().length ();
68 return Offset (dx / 2, dy);
75 ugh . Control points are too crude measures.
77 Interval
78 Bow::do_height () const
80 Interval iv;
81 Array<Offset> c (get_controls());
82 for (int i=0; i < c.size (); i++)
84 Real y = c[i][Y_AXIS];
85 iv.unite (Interval (y,y));
87 return iv;
90 Interval
91 Bow::do_width () const
93 Interval i = Spanner::do_width ();
94 Real dx = i.length();
95 return Interval (0, dx);
98 Array<Offset>
99 Bow::get_controls () const
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;
113 Array<Offset>
114 Bow::get_encompass_offset_arr () const
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 ();
120 Array<Offset> notes;
121 notes.push (Offset (0, 0));
122 notes.push (d);
124 return notes;