]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
release: 0.1.7
[lilypond.git] / lily / stem.cc
index 7fb36e3005988369f805fbf195f274ea41f1917b..d0f9f8105c72cd8a949f74406b105273cbdfb28f 100644 (file)
@@ -1,8 +1,16 @@
+/*
+  stem.cc -- implement Stem
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
 #include "stem.hh"
 #include "dimen.hh" 
 #include "debug.hh"
 #include "paper-def.hh"
-#include "notehead.hh"
+#include "note-head.hh"
 #include "lookup.hh"
 #include "molecule.hh"
 #include "p-col.hh"
@@ -41,17 +49,16 @@ Stem::Stem(int c)
 
     print_flag_b_=true;
     stem_xoffset_f_ =0;
-
 }
 
-IMPLEMENT_STATIC_NAME(Stem);
+
+IMPLEMENT_IS_TYPE_B1(Stem,Item);
 
 void
 Stem::do_print() const
 {
 #ifndef NPRINT
     mtor << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
-
 #endif
 }
 
@@ -73,6 +80,7 @@ Stem::stem_end_f() const
     return (dir_i_ < 0)? stem_bottom_f_ : stem_top_f_;
 }
 
+
 void
 Stem::set_stemend(Real se)
 {
@@ -86,7 +94,7 @@ Stem::set_stemend(Real se)
 }
 
 void
-Stem::add(Notehead *n)
+Stem::add(Note_head *n)
 {
     n->add_dependency(this);
     if (n->rest_b_) {
@@ -105,16 +113,41 @@ Stem::invisible_b()const
     return !head_l_arr_.size();
 }
 
+// if dir_i_ is set we return fake values.
+
+int
+Stem::get_center_distance_from_top()
+{
+    if (dir_i_)
+       return (dir_i_ > 0) ? 0 : 1;
+
+    int staff_center = staff_size_i_ / 2;
+    int max = max_head_i() - staff_center;
+    return max >? 0;
+}
+
+// if dir_i_ is set we return fake values.
+int
+Stem::get_center_distance_from_bottom()
+{
+    if (dir_i_)
+       return (dir_i_ > 0) ? 1 : 0;
+
+    int staff_center = staff_size_i_ / 2;
+    int min = staff_center - min_head_i();
+    return min >? 0;
+}
+
 int
 Stem::get_default_dir()
 {
-    int staff_center = staff_size_i_ /2;
     if (dir_i_)
        return dir_i_;
-    Real mean = (min_head_i() + max_head_i())/2;
-    return (mean > staff_center) ? -1: 1;
+    return (get_center_distance_from_top() >=
+       get_center_distance_from_bottom()) ? -1 : 1;
 }
 
+
 void
 Stem::set_default_dir()
 {
@@ -154,12 +187,21 @@ Stem::set_default_extents()
        stem_xoffset_f_ = 0;
 }
 
+/*
+  TODO
+  
+  move into note_column.cc
+
+  */
 void
 Stem::set_noteheads()
 {
     if(!head_l_arr_.size())
        return;
-    head_l_arr_.sort(Notehead::compare);
+    head_l_arr_.sort(Note_head::compare);
+    if (dir_i_ < 0) 
+       head_l_arr_.reverse();
+    
     head_l_arr_[0]->extremal_i_ = -1;
     head_l_arr_.top()->extremal_i_ = 1;
     int parity=1;
@@ -184,6 +226,8 @@ Stem::do_pre_processing()
        set_default_extents();
     set_noteheads();
     flag_i_ = dir_i_*abs(flag_i_);
+    transparent_b_ = invisible_b();
+    empty_b_ = invisible_b();
 }
 
 
@@ -193,7 +237,7 @@ Stem::do_width()const
     if (!print_flag_b_ || abs(flag_i_) <= 4)
        return Interval(0,0);   // TODO!
     Paper_def*p= paper();
-    Interval r(p->lookup_l()->flag(flag_i_).dim.x);
+    Interval r(p->lookup_l()->flag(flag_i_).dim.x());
     r+= stem_xoffset_f_;
     return r;
 }
@@ -202,9 +246,7 @@ Molecule*
 Stem::brew_molecule_p()const 
 {
     Molecule *out =0;
-    if ( invisible_b() )
-       return Staff_elem::brew_molecule_p();
-    
+        
     Real bot  = stem_bottom_f_;
     Real top = stem_top_f_;
     
@@ -212,7 +254,7 @@ Stem::brew_molecule_p()const
  
     Paper_def *p =paper();
 
-    Real dy = p->internote();
+    Real dy = p->internote_f();
     Symbol ss =p->lookup_l()->stem(bot*dy,top*dy);
 
     out = new Molecule(Atom(ss));
@@ -228,7 +270,7 @@ Stem::brew_molecule_p()const
            assert(false); 
     }
 
-    out->translate(Offset(stem_xoffset_f_,0));
+    out->translate(stem_xoffset_f_, X_AXIS);
     return out;
 }
 
@@ -239,3 +281,12 @@ Stem::hpos_f()const
 }
 
 
+void
+Stem::do_substitute_dependency(Score_elem*o,Score_elem*n)
+{
+    Item * o_l = o->item();
+    Item * n_l = n? n->item():0;
+    whole_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
+    head_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
+    rest_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
+}