summaryrefslogtreecommitdiff
path: root/lily/slur.cc
blob: 57f6ab649f43a9cc2203a591fe0de6e59d112afc (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
/*
  slur.cc -- implement  Slur

  source file of the GNU LilyPond music typesetter

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

/*

  TODO:
  
  think about crossing stems.
  Begin and end should be treated as a Script.
  
 */
#include "slur.hh"
#include "scalar.hh"
#include "lookup.hh"
#include "paper-def.hh"
#include "note-column.hh"
#include "stem.hh"
#include "p-col.hh"
#include "molecule.hh"
#include "debug.hh"
#include "boxes.hh"



void
Slur::add(Note_column*n)
{
    encompass_arr_.push(n);
    add_dependency(n);
}

void
Slur::set_default_dir()
{
    dir_i_ = -1;
    for (int i=0; i < encompass_arr_.size(); i ++) {
	if (encompass_arr_[i]->dir_i_ < 0) {
	    dir_i_ =1;
	    break;
	}
    }
}

void
Slur::do_pre_processing()
{
    right_col_l_  = encompass_arr_.top()->pcol_l_;
    left_col_l_ = encompass_arr_[0]->pcol_l_;    
}

void
Slur::do_break_at(PCol*l, PCol*r) 
{
    assert(l->line_l_ == r->line_l_);

    Array<Note_column*> old_encompass_arr = encompass_arr_;
    encompass_arr_.set_size(0);
    for (int i =0; i < old_encompass_arr.size(); i++) {
	if (old_encompass_arr[i]->pcol_l_->line_l_==l->line_l_)
	    encompass_arr_.push(old_encompass_arr[i]);
    }
}

void
Slur::do_substitute_dependency(Score_elem*o, Score_elem*n)
{
    int i;
    while((i = encompass_arr_.find_i((Note_column*)o->item())) >=0) {
	if (n)
	    encompass_arr_[i] = (Note_column*)n->item();
	else
	    encompass_arr_.del(i);
    }
}


static int 
Note_column_compare(Note_column *const&n1 , Note_column* const&n2)
{
    return n1->pcol_l_->rank_i() - n2->pcol_l_->rank_i();
}

void
Slur::do_post_processing()
{
    encompass_arr_.sort(Note_column_compare);
    if (!dir_i_)
	set_default_dir();
    Real inter_f = paper()->internote_f();
    
    if (encompass_arr_[0]->stem_l_) 
        left_pos_i_ = rint(encompass_arr_[0]->stem_l_->height()[dir_i_]/inter_f);
    else 
        left_pos_i_ = rint ( encompass_arr_[0]->head_positions_interval()[dir_i_]);
    
    if (encompass_arr_.top()->stem_l_)
        right_pos_i_ = rint(encompass_arr_.top()->stem_l_->height()[dir_i_]/inter_f);
    else 
        right_pos_i_ = rint (encompass_arr_.top()->head_positions_interval()[dir_i_]);

    left_pos_i_ += dir_i_;
    right_pos_i_ += dir_i_;
}
IMPLEMENT_STATIC_NAME(Slur);