]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie.cc
release: 0.1.41
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "paper-def.hh"
10 #include "tie.hh"
11 #include "note-head.hh"
12 #include "p-col.hh"
13 #include "debug.hh"
14
15
16 void
17 Tie::set_head (Direction d, Note_head * head_l)
18 {
19   assert (!head_l_drul_[d]);
20   head_l_drul_[d] = head_l;
21   set_bounds (d, head_l);
22
23   add_dependency (head_l);
24 }
25
26 Tie::Tie()
27 {
28   head_l_drul_[RIGHT] =0;
29   head_l_drul_[LEFT] =0;
30   same_pitch_b_ =false;
31 }
32
33
34 /*
35   ugh: direction of the Tie is more complicated.  See [Ross] p136 and further
36  */
37 void
38 Tie::set_default_dir()
39 {
40   int m= (head_l_drul_[LEFT]->position_i_ 
41           + head_l_drul_[RIGHT]->position_i_) /2;
42   dir_ =  (m < 0)? DOWN : UP;
43 }
44
45 void
46 Tie::do_add_processing()
47 {
48   if (!(head_l_drul_[LEFT] && head_l_drul_[RIGHT]))
49     warning (_("Lonely tie.. "));
50
51   Direction d = LEFT;
52   Drul_array<Note_head *> new_head_drul = head_l_drul_;
53   do {
54     if (!head_l_drul_[d])
55       new_head_drul[d] = head_l_drul_[(Direction)-d];
56   } while ((d *= -1) != LEFT);
57   head_l_drul_ = new_head_drul;
58 }
59
60 void
61 Tie::do_post_processing()
62 {
63   Real nw_f = paper ()->note_width ();
64   Real interline_f = paper ()->interline_f ();
65   assert (head_l_drul_[LEFT] || head_l_drul_[RIGHT]);
66
67   /* 
68    [OSU]: slur and tie placement
69
70    ties:
71    * x = inner raakpunt - d * gap
72
73    * y = length < 5ss : horizontal raakpunt
74      y = length >= 5ss : y next interline - d * 0.25 ss
75      --> height <= 5 length ?? we use <= 3 length, now...
76
77    * suggested gap = ss / 5;
78    */
79   // jcn: 1/5 seems so small?
80   Real gap_f = interline_f / 2; // 5;
81
82   Direction d = LEFT;
83   do
84     {
85       dy_f_drul_[d] = .5 * interline_f * (head_l_drul_[d] 
86                        ? head_l_drul_[d]->position_i_
87                        : head_l_drul_[(Direction)-d]->position_i_);
88     }
89   while ((d *= -1) != LEFT);
90
91   do
92     {
93       if (head_l_drul_[d] && head_l_drul_[d]->extremal_i_)
94         {
95           /* normal tie between noteheads, with gap of space */
96           dx_f_drul_[d] += -d * (0.5 * nw_f + gap_f);
97           /* attach to outer 3/4 end of head */
98           dy_f_drul_[d] += dir_ * 0.25 * interline_f;
99         }
100       else if (head_l_drul_[d])
101         {
102           dx_f_drul_[d] += d*0.5 * nw_f;
103         }
104       else
105         {
106           dy_f_drul_[d] = dy_f_drul_[(Direction) -d];
107           dx_f_drul_[d] = -d * (spanned_drul_[d]->width ().length () 
108                                 -0.5 * nw_f);
109         }
110     }
111   while ((d *= -1) != LEFT);
112 }
113
114 void
115 Tie::do_substitute_dependency (Score_elem*o, Score_elem*n)
116 {
117   Note_head *new_l =n?(Note_head*)n->item():0;
118   if (o->item() == head_l_drul_[LEFT])
119     head_l_drul_[LEFT] = new_l;
120   else if (o->item() == head_l_drul_[RIGHT])
121     head_l_drul_[RIGHT] = new_l;
122 }
123
124 IMPLEMENT_IS_TYPE_B1(Tie,Bow);