]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column-grav.cc
release: 0.1.9
[lilypond.git] / lily / note-column-grav.cc
1 /*
2   note-column-reg.cc -- implement Note_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "note-column-grav.hh"
10 #include "note-head.hh"
11 #include "stem.hh"
12 #include "note-column.hh"
13 #include "script.hh"
14 #include "rest-column.hh"
15
16 bool
17 Note_column_engraver::acceptable_elem_b (Score_elem const*elem_C)const
18 {
19   char const*nC = elem_C->name();
20   return (nC == Script::static_name() || nC == Note_head::static_name () 
21             || nC == Stem::static_name());
22 }
23 Note_column*
24 Note_column_engraver::note_col_l()
25 {
26   if (!ncol_p_)
27     {
28         ncol_p_ = new Note_column;
29         announce_element (Score_elem_info (ncol_p_, 0));
30     }
31   return ncol_p_;
32 }
33
34 Rest_column *
35 Note_column_engraver::rest_col_l()
36 {
37   if (!restcol_p_) 
38     {
39         restcol_p_  = new Rest_column;
40         announce_element (Score_elem_info (restcol_p_,0));
41     }
42   return restcol_p_;
43 }
44
45 void
46 Note_column_engraver::acknowledge_element (Score_elem_info i)
47 {
48   if (!acceptable_elem_b (i.elem_l_))
49         return;
50
51
52   char const*nC = i.elem_l_->name();
53
54   if (nC == Script::static_name() && i.req_l_ && i.req_l_->musical ()) 
55     {
56         script_l_arr_.push ((Script*)i.elem_l_->item());
57     }
58   else if (nC == Note_head::static_name()) 
59     {
60         Note_head * h_l = (Note_head*)i.elem_l_->item();
61         if (h_l->rest_b_)
62             rest_col_l()->add (h_l);
63         else
64             note_col_l()->add (h_l);
65
66     }
67   else if (nC == Stem::static_name())
68     {
69         stem_l_ = (Stem*)i.elem_l_->item();
70     }
71
72   if ( ncol_p_ || restcol_p_) 
73     {
74         if ( stem_l_) 
75           {
76             if (restcol_p_&& !restcol_p_->stem_l_)
77                 restcol_p_->set (stem_l_);
78             if (ncol_p_ && !ncol_p_->stem_l_)
79                 ncol_p_->set (stem_l_);
80           }
81   
82   
83         for (int i=0; i < script_l_arr_.size(); i++) 
84           {
85             if (restcol_p_)
86                 restcol_p_->add (script_l_arr_[i]);
87             if ( ncol_p_)
88                 ncol_p_->add (script_l_arr_[i]);
89           }
90   
91         script_l_arr_.clear();
92     }
93
94 }
95
96 void
97 Note_column_engraver::do_pre_move_processing()
98 {
99   if (ncol_p_) 
100     {
101         if (! ncol_p_->h_shift_b_)
102             ncol_p_->h_shift_b_ = h_shift_b_;
103         if (! ncol_p_->dir_i_)
104             ncol_p_->dir_i_ = dir_i_;
105
106         typeset_element (ncol_p_);
107         ncol_p_ =0;
108     }
109   if (restcol_p_) 
110     {
111         if (! restcol_p_->dir_i_)
112             restcol_p_->dir_i_ = dir_i_;
113
114         typeset_element (restcol_p_);
115         restcol_p_ =0;
116     }
117 }
118
119 void
120 Note_column_engraver::do_post_move_processing()
121 {
122   script_l_arr_.clear();
123   stem_l_ =0;
124 }
125
126 void
127 Note_column_engraver::set_feature (Feature i)
128 {
129    if (i.type_ == "vdir")       
130         dir_i_ = i.value_;
131    if (i.type_ == "hshift")
132          h_shift_b_ = (bool)(int)i.value_;
133 }
134
135 Note_column_engraver::Note_column_engraver()
136 {
137   dir_i_ =0;
138   h_shift_b_ = false;
139   
140   ncol_p_=0;
141   restcol_p_ =0;
142   do_post_move_processing();
143 }
144
145
146 IMPLEMENT_IS_TYPE_B1(Note_column_engraver,Engraver);
147 ADD_THIS_ENGRAVER(Note_column_engraver);