]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
*** empty log message ***
[lilypond.git] / lily / tie.cc
1 /*
2   tie.cc -- implement Tie
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "tie.hh"
10
11 #include <math.h>
12
13 #include "spanner.hh"
14 #include "lookup.hh"
15 #include "output-def.hh"
16 #include "rhythmic-head.hh"
17 #include "bezier.hh"
18 #include "paper-column.hh"
19 #include "warn.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "directional-element-interface.hh"
22 #include "bezier.hh"
23 #include "stem.hh"
24 #include "note-head.hh"
25 #include "tie-column.hh"
26
27 /*
28   tie: Connect two noteheads.
29
30   What if we have
31
32   c4 ~ \clef bass ; c4 or
33
34   c4 \staffchange c4
35
36   do we have non-horizontal ties then?
37 */
38
39 void
40 Tie::set_head (Grob *me, Direction d, Grob *h)
41 {
42   assert (!head (me, d));
43   index_set_cell (me->get_property ("head-pair"), d, h->self_scm ());
44
45   dynamic_cast<Spanner *> (me)->set_bound (d, h);
46   me->add_dependency (h);
47 }
48
49 void
50 Tie::set_interface (Grob *me)
51 {
52   me->set_property ("head-pair", scm_cons (SCM_EOL, SCM_EOL));
53 }
54
55 Grob *
56 Tie::head (Grob *me, Direction d)
57 {
58   SCM c = me->get_property ("head-pair");
59
60   if (scm_is_pair (c))
61     return unsmob_grob (index_get_cell (c, d));
62   else
63     return 0;
64 }
65
66 int
67 Tie::get_column_rank (Grob *me, Direction d)
68 {
69   Spanner *span = dynamic_cast<Spanner *> (me);
70   Grob *h = head (me, d);
71   if (!h)
72     h = span->get_bound (d);
73
74   Grob *col = dynamic_cast<Item *> (h)->get_column ();
75   return Paper_column::get_rank (col);
76 }
77
78 Real
79 Tie::get_position (Grob *me)
80 {
81   Direction d = head (me, LEFT) ? LEFT : RIGHT;
82   return Staff_symbol_referencer::get_position (head (me, d));
83 }
84
85 /*
86   Default:  Put the tie oppositie of the stem [Wanske p231]
87
88   In case of chords: Tie_column takes over
89
90   The direction of the Tie is more complicated (See [Ross] p136 and
91   further).
92
93   (what about linebreaks? )
94 */
95 Direction
96 Tie::get_default_dir (Grob *me)
97 {
98   Item *sl = head (me, LEFT) ? Rhythmic_head::get_stem (head (me, LEFT)) : 0;
99   Item *sr = head (me, RIGHT) ? Rhythmic_head::get_stem (head (me, RIGHT)) : 0;
100   if (sl && sr)
101     {
102       if (get_grob_direction (sl) == UP
103           && get_grob_direction (sr) == UP)
104         return DOWN;
105     }
106   else if (sl || sr)
107     {
108       Item *s = sl ? sl : sr;
109       return -get_grob_direction (s);
110     }
111
112   return UP;
113 }
114
115 void
116 Tie::set_direction (Grob *me)
117 {
118   if (!get_grob_direction (me))
119     {
120       if (Tie_column::has_interface (me->get_parent (Y_AXIS)))
121         Tie_column::set_directions (me->get_parent (Y_AXIS));
122       else
123         set_grob_direction (me, Tie::get_default_dir (me));
124     }
125 }
126
127 MAKE_SCHEME_CALLBACK (Tie, print, 1);
128 SCM
129 Tie::print (SCM smob)
130 {
131   Grob *me = unsmob_grob (smob);
132
133   SCM cp = me->get_property ("control-points");
134   if (!scm_is_pair (cp))                // list is more accurate
135     {
136       cp = get_control_points (smob);
137       me->set_property ("control-points", cp);
138     }
139
140   if (!scm_is_pair (cp))
141     return Stencil ().smobbed_copy ();
142
143   Real staff_thick = Staff_symbol_referencer::line_thickness (me);
144   Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
145   Real thick = base_thick * staff_thick;
146
147   Bezier b;
148   int i = 0;
149   for (SCM s = cp; s != SCM_EOL; s = scm_cdr (s))
150     {
151       b.control_[i] = ly_scm2offset (scm_car (s));
152       i++;
153     }
154
155   Stencil a;
156
157   SCM p = me->get_property ("dash-period");
158   SCM f = me->get_property ("dash-fraction");
159   if (scm_is_number (p) && scm_is_number (f))
160     a = Lookup::dashed_slur (b,
161                              thick,
162                              robust_scm2double (p, 1.0),
163                              robust_scm2double (f, 0));
164   else
165     a = Lookup::slur (b,
166                       get_grob_direction (me) * staff_thick,
167                       thick);
168
169   return a.smobbed_copy ();
170 }
171
172 ADD_INTERFACE (Tie,
173                "tie-interface",
174                "A tie connecting two noteheads.\n",
175
176                "y-offset dash-period dash-fraction "
177                "staffline-clearance control-points head-pair "
178                "details thickness x-gap direction minimum-length");