]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 0.0.51
[lilypond.git] / lily / note-column.cc
1 /*
2   note-column.cc -- implement Note_column
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "note-column.hh"
10 #include "debug.hh"
11 #include "script.hh"
12 #include "notehead.hh"
13 #include "stem.hh"
14
15 IMPLEMENT_STATIC_NAME(Note_column);
16
17
18 void
19 Note_column::add(Stem*stem_l)
20 {
21     assert(!stem_l_);
22     stem_l_ = stem_l;
23     add_dependency(stem_l);
24 }
25
26 void
27 Note_column::add(Notehead* n_l)
28 {
29     head_l_arr_.push(n_l);
30     add_dependency(n_l);
31 }
32
33 void
34 Note_column::add(Script*s_l)
35 {
36     script_l_arr_.push(s_l);
37     add_dependency(s_l);
38 }
39
40 void
41 Note_column::translate(Offset o)
42 {
43     for (int i=0; i < head_l_arr_.size(); i++)
44         head_l_arr_[i]->translate(o);
45     for (int i=0; i < script_l_arr_.size(); i++) 
46         script_l_arr_[i]->translate(o);
47     if (stem_l_)
48         stem_l_->translate(o);
49 }
50
51
52 void
53 Note_column::do_print()const
54 {
55     mtor << "heads: " << head_l_arr_.size() << '\n'; 
56     mtor << "scripts: " << script_l_arr_.size() << '\n'; 
57 }
58
59 Interval
60 Note_column::do_height()const return r
61 {
62     if (stem_l_)
63          r.unite(stem_l_->height());
64     for (int i=0; i < head_l_arr_.size(); i++)
65         r.unite(head_l_arr_[i]->height());
66     for (int i=0; i < script_l_arr_.size(); i++) 
67         r.unite(script_l_arr_[i]->height());
68 }
69
70 Interval
71 Note_column::do_width()const return r;
72 {
73     if (stem_l_)
74          r.unite(stem_l_->width());
75     for (int i=0; i < head_l_arr_.size(); i++)
76         r.unite(head_l_arr_[i]->width());
77     for (int i=0; i < script_l_arr_.size(); i++) 
78         r.unite(script_l_arr_[i]->width());
79 }
80
81 void
82 Note_column::do_pre_processing()
83 {
84     if (!script_l_arr_.size()) 
85         return;
86
87     Array<Script*> placed_l_arr_a[4];
88     for (int i=0; i < script_l_arr_.size(); i++) {
89         Script*s_l = script_l_arr_[i];
90         int j = (s_l->dir_i_ >0) ? 0 : 2;
91         if (!s_l->inside_staff_b_) 
92             j ++;
93         
94         placed_l_arr_a[j].push(s_l);
95     }
96     for (int j =0; j <4; j++) {
97         placed_l_arr_a[j].sort( Script::compare);
98     }
99     
100     Notehead *top_head_l=0;
101     Notehead *bot_head_l=0;
102     for (int i=0; i< head_l_arr_.size(); i++) {
103         if (head_l_arr_[i]->extremal == -1)
104             bot_head_l = head_l_arr_[i];
105         else if (head_l_arr_[i]->extremal == 1)
106             top_head_l = head_l_arr_[i];
107     }
108     /* argh. This sux. */
109     if (!top_head_l) 
110         top_head_l = bot_head_l;
111     if (!bot_head_l) 
112         bot_head_l = top_head_l;
113     assert(bot_head_l && top_head_l);
114     Item *support_l=top_head_l;
115     int j;
116     for (j = 0; j < 2; j++ ) {
117         for (int i=0; i < placed_l_arr_a[j].size(); i++) {
118             placed_l_arr_a[j][i]->add_support(support_l);
119             support_l = placed_l_arr_a[j][i];
120         }
121     }
122     
123     support_l=bot_head_l;
124     for (; j < 4; j++ ) {
125         for (int i=0; i < placed_l_arr_a[j].size(); i++) {
126             placed_l_arr_a[j][i]->add_support(support_l);
127             support_l = placed_l_arr_a[j][i];
128         }
129     }
130 }
131 Note_column::Note_column()
132 {
133     stem_l_ =0;
134 }
135