]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-column.cc
release: 1.1.32
[lilypond.git] / lily / note-column.cc
index e40724976a7eab34216f5f26553e5cd8d6608209..770157d0738b4f2c369474758763b5734e4008e2 100644 (file)
 /*
   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 <hanwen@stack.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-
+#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);
+bool
+Note_column::rest_b () const
+{
+  return rest_l_arr_.size ();
+}
+
+Note_column::Note_column()
+{
+  stem_l_ = 0;
+  h_shift_b_ = false;
+  dir_ =CENTER;
+}
 
 void
-Note_column::add(Stem*stem_l)
+Note_column::sort()
+{
+  head_l_arr_.sort (Note_head::compare);
+}
+  
+Interval_t<int>
+Note_column::head_positions_interval() const
 {
-    stem_l_ = stem_l;
-    add_support(stem_l);
+  ((Note_column*)this)->sort();
+  Interval_t<int>  iv;
+
+  iv.set_empty ();
+
+  if (head_l_arr_.size ())
+    iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
+                        head_l_arr_.top()->position_i_);
+  
+  return iv;
 }
 
 void
-Note_column::add(Notehead* n_l)
+Note_column::do_pre_processing()
 {
-    assert(!n_l->rest_b_);
-    head_l_arr_.push(n_l);
-    add_support(n_l);
+  if (!dir_)
+    {
+      if (stem_l_)
+       dir_ = stem_l_->dir_;
+      else if (head_l_arr_.size ())
+       {
+         //      assert (false);       // looks obsolete?
+         dir_ = sign (head_positions_interval().center ());
+       }
+    }
+  Script_column::do_pre_processing();
 }
 
-Note_column::Note_column()
+  
+
+void
+Note_column::set_stem (Stem * stem_l)
 {
-    stem_l_ = 0;
-    h_shift_b_ =false;
-    dir_i_ =0;
+  add_support (stem_l);
+  stem_l_ = stem_l;
+  /* 
+     don't add stem to support; mostly invisible for rest-columns (and possibly taken . .)
+  */
+  Score_element::add_dependency (stem_l);
+  for (int i=0; i < script_l_arr_.size(); i++)
+    script_l_arr_[i]->set_stem (stem_l);
 }
 
 void
-Note_column::sort()
+Note_column::add_script (Script *script_l)
 {
-    head_l_arr_.sort( Notehead::compare);
+  Script_column::add_script (script_l) ;
+  if  (stem_l_)
+    script_l->set_stem (stem_l_);
 }
-    
-Interval_t<int>
-Note_column::head_positions_interval()const
+
+void
+Note_column::do_substitute_element_pointer (Score_element*o, Score_element*n)
 {
-    (    (Note_column*)this)->sort();
-    return Interval_t<int> ( head_l_arr_[0]->position_i_, 
-                            head_l_arr_.top()->position_i_);
+  if (stem_l_ == o) 
+    {
+      stem_l_ = n ? dynamic_cast<Stem *> (n):0;
+    }
+  if (dynamic_cast<Note_head *> (o))
+    {
+      head_l_arr_.substitute (dynamic_cast<Note_head *> (o), 
+                             (n)? dynamic_cast<Note_head *> (n) : 0);
+    }
+  Script_column::do_substitute_element_pointer (o,n);
+  if (dynamic_cast<Rest *> (o)) 
+    {
+      rest_l_arr_.substitute (dynamic_cast<Rest *> (o), 
+                             (n)? dynamic_cast<Rest *> (n) : 0);
+    }
+}
 
+void
+Note_column::add_head (Rhythmic_head *h)
+{
+  if (Rest*r=dynamic_cast<Rest *> (h))
+    {
+      rest_l_arr_.push (r);
+      add_support (r);  
+    }
+  if (Note_head *nh=dynamic_cast<Note_head *> (h))
+    {
+      head_l_arr_.push (nh);
+      add_support (nh);
+    }
 }
 
+/**
+  translate the rest symbols
+ */
+void
+Note_column::translate_rests (int dy_i)
+{
+  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::do_pre_processing()
+Note_column::do_print() const
+{
+#ifndef NPRINT
+  DOUT << "rests: " << rest_l_arr_.size() << ", ";
+  DOUT << "heads: " << head_l_arr_.size();
+#endif
+}
+
+void
+Note_column::set_dotcol (Dot_column *d)
 {
-    if (!dir_i_)
-       dir_i_ = stem_l_->dir_i_;
+  add_element (d);
 }