summaryrefslogtreecommitdiff
path: root/lily/tie.cc
blob: d67aacccfcbfdc864695699e767a8f7f4cf58ad3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
  tie.cc -- implement Tie

  source file of the GNU LilyPond music typesetter

  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
*/

#include "paper-def.hh"
#include "tie.hh"
#include "note-head.hh"
#include "p-col.hh"


void
Tie::set_head(int x_pos, Note_head * head_l)
{
    if (x_pos >0) {
	assert(!right_head_l_);
	right_head_l_ = head_l;
    } else {
	assert(!left_head_l_);
	left_head_l_ = head_l;
    }
    add_dependency(head_l);
}

Tie::Tie()
{
    right_head_l_ =0;
    left_head_l_ =0;
    same_pitch_b_ =false;
}

void
Tie::set_default_dir()
{
    int m= (left_head_l_->position_i_ + right_head_l_->position_i_) /2 ;
    dir_i_ =  (m < 5)? -1:1;			// ugh
}
    

void
Tie::do_add_processing()
{
    assert(left_head_l_ && right_head_l_);
    left_col_l_ = left_head_l_ -> pcol_l_;
    right_col_l_ = right_head_l_ -> pcol_l_;
}

/**
  This is already getting hairy. Should use Note_head *heads[2]
 */
void
Tie::do_post_processing()
{
    assert(left_head_l_ || right_head_l_);
    left_pos_i_ =  (left_head_l_)? 
	left_head_l_->position_i_ : right_head_l_->position_i_;
    right_pos_i_ = (right_head_l_) ? 
	right_head_l_->position_i_ : left_head_l_->position_i_;
 
    if ( right_head_l_ && right_head_l_->extremal_i_) {
	right_pos_i_ += 2*dir_i_;
	right_dx_f_ -= 0.25;
    } else
	right_dx_f_ -= 0.5;

    if (left_head_l_ && left_head_l_->extremal_i_) {
	left_pos_i_ += 2*dir_i_;
	left_dx_f_ += 0.25;
    } else
	left_dx_f_ += 0.5;
    
    if (!right_head_l_)
	right_pos_i_ = left_pos_i_;
    if (! left_head_l_)
	left_pos_i_ = right_pos_i_;
}



void
Tie::do_substitute_dependency(Score_elem*o, Score_elem*n)
{
    Note_head *new_l =n?(Note_head*)n->item():0;
    if (o->item() == left_head_l_)
	left_head_l_ = new_l;
    else if (o->item() == right_head_l_)
	right_head_l_ = new_l;
}



IMPLEMENT_IS_TYPE_B1(Tie,Bow);