]> git.donarmstrong.com Git - lilypond.git/blob - lily/bow.cc
release: 1.0.1
[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 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 = 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   Array<Offset> c (get_controls());
81
82   Interval iv;
83   for (int i=0; i < c.size (); i++)
84     {
85       Real y = c[i][Y_AXIS];
86       iv.unite (Interval (y,y));
87     }
88   return iv;
89 }
90
91 Interval
92 Bow::do_width () const    
93 {
94   Interval i = Spanner::do_width ();
95   Real dx = i.length();
96   return Interval (0, dx);
97 }
98
99 Array<Offset>
100 Bow::get_controls () const
101 {
102   Bezier_bow b (paper ());
103   b.set (get_encompass_offset_arr (), dir_);
104   b.calc ();
105   Array<Offset> controls;
106   controls.set_size (8);
107   for (int i = 0; i < 4; i++)
108     controls[i] = b.control_[i];
109   for (int i = 0; i < 4; i++)
110     controls[i + 4] = b.return_[i];
111   return controls;
112 }
113
114 Array<Offset>
115 Bow::get_encompass_offset_arr () const
116 {
117   Offset d (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT],
118     dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]);
119   d.x() += width (). length ();
120
121 #define RESIZE_ICE
122 #ifndef RESIZE_ICE
123   Array<Offset> notes;
124   notes.push (Offset 0, 0));
125   notes.push (d);
126 #else
127   Array<Offset> notes (2);
128   notes[0] = Offset (0, 0);
129   notes[1] = Offset (d);
130 #endif
131
132   return notes;
133 }
134