]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column-grav.cc
release: 0.0.77.jcn1
[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         ncol_p_ = new Note_column;
28         announce_element(Score_elem_info(ncol_p_, 0));
29     }
30     return ncol_p_;
31 }
32
33 Rest_column *
34 Note_column_engraver::rest_col_l()
35 {
36     if (!restcol_p_) {
37         restcol_p_  = new Rest_column;
38         announce_element(Score_elem_info(restcol_p_,0));
39     }
40     return restcol_p_;
41 }
42
43 void
44 Note_column_engraver::acknowledge_element(Score_elem_info i)
45 {
46     if (!acceptable_elem_b(i.elem_l_))
47         return;
48
49
50     char const*nC = i.elem_l_->name();
51
52     if (nC == Script::static_name()) {
53         script_l_arr_.push((Script*)i.elem_l_->item());
54     } else if (nC == Note_head::static_name()) {
55         Note_head * h_l = (Note_head*)i.elem_l_->item();
56         if (h_l->rest_b_)
57             rest_col_l()->add(h_l);
58         else
59             note_col_l()->add(h_l);
60
61     } else if (nC == Stem::static_name()){ 
62         stem_l_ = (Stem*)i.elem_l_->item();
63     }
64
65     if ( ncol_p_ || restcol_p_ ) {
66         if ( stem_l_ ) {
67             if (restcol_p_&& !restcol_p_->stem_l_)
68                 restcol_p_->set (stem_l_ );
69             if (ncol_p_ && !ncol_p_->stem_l_)
70                 ncol_p_->set(stem_l_);
71         }
72     
73     
74         for (int i=0; i < script_l_arr_.size(); i++) {
75             if (restcol_p_)
76                 restcol_p_->add(script_l_arr_[i]);
77             if ( ncol_p_ )
78                 ncol_p_->add(script_l_arr_[i]);
79         }
80     
81         script_l_arr_.set_size(0);
82     }
83
84 }
85
86 void
87 Note_column_engraver::do_pre_move_processing()
88 {
89     if (ncol_p_) {
90         if (! ncol_p_->h_shift_b_)
91             ncol_p_->h_shift_b_ = h_shift_b_;
92         if (! ncol_p_->dir_i_ )
93             ncol_p_->dir_i_ = dir_i_;
94
95         typeset_element(ncol_p_);
96         ncol_p_ =0;
97     }
98     if (restcol_p_) {
99         if (! restcol_p_->dir_i_ )
100             restcol_p_->dir_i_ = dir_i_;
101
102         typeset_element(restcol_p_);
103         restcol_p_ =0;
104     }
105 }
106
107 void
108 Note_column_engraver::do_post_move_processing()
109 {
110     script_l_arr_.set_size(0);
111     stem_l_ =0;
112 }
113
114 void
115 Note_column_engraver::set_feature(Feature i)
116 {
117      if (i.type_ == "vdir")     
118         dir_i_ = i.value_;
119      if (i.type_ == "hshift")
120          h_shift_b_ = (bool)(int)i.value_;
121 }
122
123 Note_column_engraver::Note_column_engraver()
124 {
125     dir_i_ =0;
126     h_shift_b_ = false;
127     
128     ncol_p_=0;
129     restcol_p_ =0;
130     do_post_move_processing();
131 }
132
133
134 IMPLEMENT_IS_TYPE_B1(Note_column_engraver,Engraver);
135 ADD_THIS_ENGRAVER(Note_column_engraver);