X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fnote-column.cc;h=e528b9e956369d94ace5744e9f76161ee7745808;hb=c844072722a39a5fcd20372b0497d9130bd41dd7;hp=075e61d1ab79567738c9330753f0d1c89e28823e;hpb=e85b008ae96fef8fc0c15529e8a172584d5d08fd;p=lilypond.git diff --git a/lily/note-column.cc b/lily/note-column.cc index 075e61d1ab..e528b9e956 100644 --- a/lily/note-column.cc +++ b/lily/note-column.cc @@ -1,160 +1,153 @@ /* note-column.cc -- implement Note_column - source file of the LilyPond music typesetter + source file of the GNU LilyPond music typesetter - (c) 1997 Han-Wen Nienhuys + (c) 1997--1998 Han-Wen Nienhuys */ - +#include "dot-column.hh" #include "note-column.hh" -#include "debug.hh" #include "script.hh" -#include "notehead.hh" +#include "note-head.hh" #include "stem.hh" +#include "rest.hh" +#include "debug.hh" -IMPLEMENT_STATIC_NAME(Note_column); - +IMPLEMENT_IS_TYPE_B1(Note_column,Script_column); -void -Note_column::add(Stem*stem_l) +bool +Note_column::rest_b () const { - assert(!stem_l_); - stem_l_ = stem_l; - add_dependency(stem_l); + return rest_l_arr_.size (); } -void -Note_column::add(Notehead* n_l) +Note_column::Note_column() { - if (head_l_arr_.size()){ - if (n_l->rest_b_ != rest_b_) return; // ugly fix. Should think about integrating rests into colunms. - } else - rest_b_ = n_l->rest_b_; - - head_l_arr_.push(n_l); - add_dependency(n_l); + stem_l_ = 0; + h_shift_b_ = false; + dir_ =CENTER; } void -Note_column::add(Script*s_l) +Note_column::sort() { - script_l_arr_.push(s_l); - add_dependency(s_l); + head_l_arr_.sort (Note_head::compare); } - -void -Note_column::translate(Offset o) + +Interval_t +Note_column::head_positions_interval() const { - for (int i=0; i < head_l_arr_.size(); i++) - head_l_arr_[i]->translate(o); - for (int i=0; i < script_l_arr_.size(); i++) - script_l_arr_[i]->translate(o); - if (stem_l_) - stem_l_->translate(o); + ((Note_column*)this)->sort(); + return Interval_t (head_l_arr_[0]->position_i_, + head_l_arr_.top()->position_i_); + } +Interval +Note_column::width () const +{ + if (head_l_arr_.size ()) + return head_l_arr_[0]->width (); + else + return Interval (0,0); +} void -Note_column::do_print()const +Note_column::do_pre_processing() { - mtor << "heads: " << head_l_arr_.size() << '\n'; - mtor << "scripts: " << script_l_arr_.size() << '\n'; + + if (!dir_) + { + if (stem_l_) + dir_ = stem_l_->dir_; + else if (head_l_arr_.size ()) + { + dir_ = (head_positions_interval().center () >= 5) ? DOWN:UP; + } + } + Script_column::do_pre_processing(); } -Interval -Note_column::do_height()const return r + + +void +Note_column::set (Stem * stem_l) { - if (stem_l_) - r.unite(stem_l_->height()); - for (int i=0; i < head_l_arr_.size(); i++) - r.unite(head_l_arr_[i]->height()); - for (int i=0; i < script_l_arr_.size(); i++) - r.unite(script_l_arr_[i]->height()); + add_support (stem_l); + stem_l_ = stem_l; + /* + don't add stem to support; mostly invisible for rest-columns (and possibly taken . .) + */ + Score_elem::add_dependency (stem_l); + for (int i=0; i < script_l_arr_.size(); i++) + script_l_arr_[i]->set_stem (stem_l); } -Interval -Note_column::do_width()const return r; +void +Note_column::add (Script *script_l) { - if (stem_l_) - r.unite(stem_l_->width()); - for (int i=0; i < head_l_arr_.size(); i++) - r.unite(head_l_arr_[i]->width()); - for (int i=0; i < script_l_arr_.size(); i++) - r.unite(script_l_arr_[i]->width()); + Script_column::add (script_l) ; + if (stem_l_) + script_l->set_stem (stem_l_); } void -Note_column::do_pre_processing() +Note_column::do_substitute_dependency (Score_elem*o, Score_elem*n) { - if (stem_l_ && !dir_i_) - dir_i_ = stem_l_->dir_i_; - - if (!script_l_arr_.size()) - return; - - Array placed_l_arr_a[4]; - for (int i=0; i < script_l_arr_.size(); i++) { - Script*s_l = script_l_arr_[i]; - int j = (s_l->dir_i_ >0) ? 0 : 2; - if (!s_l->inside_staff_b_) - j ++; - - placed_l_arr_a[j].push(s_l); + if (stem_l_ == o) + { + stem_l_ = n ? (Stem*)n->item():0; } - for (int j =0; j <4; j++) { - placed_l_arr_a[j].sort( Script::compare); + if (o->is_type_b (Note_head::static_name ())) + { + head_l_arr_.substitute ((Note_head*)o->item(), + (n)? (Note_head*)n->item() : 0); } - - Notehead *top_head_l=0; - Notehead *bot_head_l=0; - for (int i=0; i< head_l_arr_.size(); i++) { - if (head_l_arr_[i]->extremal == -1) - bot_head_l = head_l_arr_[i]; - else if (head_l_arr_[i]->extremal == 1) - top_head_l = head_l_arr_[i]; + Script_column::do_substitute_dependency (o,n); + if (o->is_type_b (Rest::static_name ())) + { + rest_l_arr_.substitute ((Rest*)o->item(), + (n)? (Rest*)n->item() : 0); } - /* argh. This sux. */ - if (!top_head_l) - top_head_l = bot_head_l; - if (!bot_head_l) - bot_head_l = top_head_l; - assert(bot_head_l && top_head_l); - Item *support_l=top_head_l; - int j; - for (j = 0; j < 2; j++ ) { - for (int i=0; i < placed_l_arr_a[j].size(); i++) { - placed_l_arr_a[j][i]->add_support(support_l); - support_l = placed_l_arr_a[j][i]; - } +} + +void +Note_column::add (Rhythmic_head *h) +{ + if (h->is_type_b (Rest::static_name ())) + { + rest_l_arr_.push ((Rest*)h); + add_support (h); } - - support_l=bot_head_l; - for (; j < 4; j++ ) { - for (int i=0; i < placed_l_arr_a[j].size(); i++) { - placed_l_arr_a[j][i]->add_support(support_l); - support_l = placed_l_arr_a[j][i]; - } + if (h->is_type_b (Note_head::static_name ())) + { + head_l_arr_.push ((Note_head*) h); + add_support (h); } } -Note_column::Note_column() +/** + translate the rest symbols + */ +void +Note_column::translate_rests (int dy_i) { - h_shift_b_ =false; - stem_l_ =0; - rest_b_ = false; - dir_i_ =0; + invalidate_cache (Y_AXIS); + for (int i=0; i < rest_l_arr_.size(); i++) + rest_l_arr_[i]->position_i_ += dy_i; } + void -Note_column::sort() +Note_column::do_print() const { - head_l_arr_.sort( Notehead::compare); +#ifndef NPRINT + DOUT << "rests: " << rest_l_arr_.size() << ", "; + DOUT << "heads: " << head_l_arr_.size(); +#endif } - -Interval_t -Note_column::head_positions_interval()const -{ - ( (Note_column*)this)->sort(); - return Interval_t ( head_l_arr_[0]->position, - head_l_arr_.top()->position); +void +Note_column::set (Dot_column *d) +{ + add_element (d); }