]> git.donarmstrong.com Git - lilypond.git/blob - lily/bow.cc
b986debd303d301679687daccb5e0c2047310692
[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@stack.nl>
7       Jan Nieuwenhuizen <jan@digicash.com>
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 IMPLEMENT_IS_TYPE_B1(Bow,Directional_spanner);
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 = paper ()->lookup_l ()->slur (c);
37   else
38     a = paper ()->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 (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 Interval
72 Bow::do_width () const    
73 {
74   Interval i = Spanner::do_width ();
75   Real dx = i.length();
76   return Interval (0, dx);
77 }
78
79 Array<Offset>
80 Bow::get_controls () const
81 {
82   Bezier_bow b (paper ());
83   b.set (get_encompass_offset_arr (), dir_);
84   b.calc ();
85   Array<Offset> controls;
86   controls.set_size (8);
87   for (int i = 0; i < 4; i++)
88     controls[i] = b.control_[i];
89   for (int i = 0; i < 4; i++)
90     controls[i + 4] = b.return_[i];
91   return controls;
92 }
93
94 Array<Offset>
95 Bow::get_encompass_offset_arr () const
96 {
97   Offset d (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
98     dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
99   d.x() += width (). length ();
100
101 #define RESIZE_ICE
102 #ifndef RESIZE_ICE
103   Array<Offset> notes;
104   notes.push (Offset 0, 0));
105   notes.push (d);
106 #else
107   Array<Offset> notes (2);
108   notes[0] = Offset (0, 0);
109   notes[1] = Offset (d);
110 #endif
111
112   return notes;
113 }
114