summaryrefslogtreecommitdiff
path: root/lily/tie-grav.cc
blob: cbe5f35f7be216a155702364845f0cd4f54fae6b (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
  tie-reg.cc -- implement Tie_engraver

  source file of the GNU LilyPond music typesetter

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

#include "tie-grav.hh"
#include "tie.hh"
#include "note-head.hh"
#include "musical-request.hh"
#include "music-list.hh"

Tie_engraver::Tie_engraver()
{
    end_tie_p_ = 0;
    tie_p_ = 0;
    req_l_ =0;
    end_req_l_ =0;
    end_mom_ = -1;
    melodic_req_l_ = 0;
    end_melodic_req_l_ =0;
    dir_i_ = 0;
}

void
Tie_engraver::sync_features()
{
    dir_i_ = get_feature ("vdir");
}
    

void
Tie_engraver::do_post_move_processing()
{
    if (tie_p_ && get_staff_info().when () == end_mom_) {
	end_tie_p_ = tie_p_;
	end_req_l_ = req_l_;
	end_melodic_req_l_ = melodic_req_l_;
	tie_p_ =0;
	req_l_ =0;
	end_mom_ = -1;
    }
}

bool
Tie_engraver::acceptable_request_b (Request*r)
{
    return r->musical() && r->musical ()->tie ();
}

bool
Tie_engraver::do_try_request (Request*r)
{
    if (!acceptable_request_b (r))
	return false;
    if (req_l_) {
	return false;
    }
    req_l_ = r->musical()->tie ();
    end_mom_ = r->parent_music_l_->time_int().length ()
	+ get_staff_info().when ();
    return true;
}

void
Tie_engraver::do_process_requests()
{
    if (req_l_ && ! tie_p_) {
	tie_p_ = new Tie;
    }
}

void
Tie_engraver::acknowledge_element (Score_elem_info i)
{
    if (i.elem_l_->name() == Note_head::static_name ()) {
	if (tie_p_) {
	    tie_p_->set_head (-1, (Note_head*)i.elem_l_->item());
	    melodic_req_l_ = i.req_l_->musical()->melodic ();
	}

	if (end_tie_p_) {
	    end_tie_p_->set_head (1, (Note_head*)i.elem_l_->item());
	    if (!Melodic_req::compare ( *end_melodic_req_l_, *melodic_req_l_))
		end_tie_p_->same_pitch_b_ = true;
	    announce_element (Score_elem_info (end_tie_p_,end_req_l_));
	}
    }
}

void
Tie_engraver::do_pre_move_processing()
{
    if (end_tie_p_) {
	if (dir_i_)
	    end_tie_p_->dir_i_ =  dir_i_;
	
	typeset_element (end_tie_p_);
	end_tie_p_ =0;
	end_req_l_ =0;
    }
 
}

Tie_engraver::~Tie_engraver()
{
    if (tie_p_) {
	req_l_->warning ("unended Tie");
	delete tie_p_;
    }
}

void
Tie_engraver::set_feature (Feature f)
{
    if (f.type_ == "vdir")
	dir_i_ = f.value_;
}


IMPLEMENT_IS_TYPE_B1(Tie_engraver,Engraver);
ADD_THIS_ENGRAVER(Tie_engraver);