]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem-engraver.cc
release: 1.3.68
[lilypond.git] / lily / stem-engraver.cc
index 1679e52441275bdab90ca4e37760835274188471..08b598f1e2c215753903937d7acac5c76715b88d 100644 (file)
@@ -3,35 +3,64 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "stem-engraver.hh"
-#include "note-head.hh"
+#include "staff-symbol-referencer.hh"
+#include "rhythmic-head.hh"
 #include "stem.hh"
 #include "musical-request.hh"
-#include "duration-convert.hh"
 #include "misc.hh"
 #include "stem-tremolo.hh"
-#include "staff-info.hh"
+
 #include "translator-group.hh"
+#include "engraver.hh"
+
+/**
+  Make stems upon receiving noteheads.
+ */
+class Stem_engraver : public Engraver
+{
 
-Stem_engraver::Stem_engraver()
+public:
+  VIRTUAL_COPY_CONS (Translator);
+  Stem_engraver();
+  
+protected:
+  virtual void do_creation_processing ();
+  virtual void acknowledge_element (Score_element_info);
+  virtual void do_pre_move_processing ();
+  virtual bool do_try_music (Music*);
+  
+private:
+  int default_tremolo_type_i_;
+  Stem *stem_p_;
+  Score_element *tremolo_p_;
+  Rhythmic_req *rhythmic_req_l_;
+  Tremolo_req* tremolo_req_l_;
+};
+
+ADD_THIS_TRANSLATOR (Stem_engraver);
+
+Stem_engraver::Stem_engraver ()
 {
-  abbrev_req_l_ = 0;
+  tremolo_req_l_ = 0;
   stem_p_ = 0;
-  abbrev_p_ = 0;
-  default_abbrev_i_ = 16;
+  tremolo_p_ = 0;
+  default_tremolo_type_i_ = 16;
   rhythmic_req_l_ =0;
 }
 
 void
 Stem_engraver::do_creation_processing ()
 {
-  Scalar prop = get_property ("abbrev", 0);
-  if (prop.isnum_b ()) 
+  /*
+    huh, why only at creation time?
+  */
+  SCM prop = get_property ("tremoloFlags");
+  if (gh_number_p(prop)) 
     {
-      default_abbrev_i_  = prop;
+      default_tremolo_type_i_  = gh_scm2int (prop);
     }
 }
 
@@ -40,44 +69,61 @@ Stem_engraver::acknowledge_element(Score_element_info i)
 {
   if (Rhythmic_head * h = dynamic_cast<Rhythmic_head *> (i.elem_l_))
     {
-      if (h->stem_l_)
+      if (h->stem_l ())
        return;
       
       Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
       int duration_log = r->duration_.durlog_i_;      
       if (!stem_p_) 
        {
-         stem_p_ = new Stem;
-         stem_p_->flag_i_ = duration_log;
+         stem_p_ = new Stem (get_property ("basicStemProperties"));
+         Staff_symbol_referencer_interface::set_interface(stem_p_);
 
-         if (abbrev_req_l_)
+         
+         stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
+
+         if (tremolo_req_l_)
            {
              /*
-               suggests typing of:
-               c8:16 c: c: c:
-               hmm, which isn't so bad?
-             */
-             int t = abbrev_req_l_->type_i_;
-             if (!t)
-               t = default_abbrev_i_;
+               Stem tremolo is never applied to a note by default,
+               is must me requested.  But there is a default for the
+               tremolo value:
+
+                  c4:8 c c:
+
+               the first and last (quarter) note bothe get one tremolo flag.
+              */
+             int requested_type = tremolo_req_l_->type_i_;
+             if (!requested_type)
+               requested_type = default_tremolo_type_i_;
              else
-               default_abbrev_i_ = t;
+               default_tremolo_type_i_ = requested_type;
 
-             if (t)
+             if (requested_type)
                {
-                 abbrev_p_ = new Stem_tremolo;
-                 announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
-                 abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (duration_log>? 2);
+                 tremolo_p_ = new Item (get_property ("basicStemTremoloProperties"));
+                 Stem_tremolo::set_interface (tremolo_p_);
+
+                 announce_element (Score_element_info (tremolo_p_, tremolo_req_l_));
+                 /*
+                   The number of tremolo flags is the number of flags of
+                   the tremolo-type minus the number of flags of the note
+                   itself.
+                  */
+                 int tremolo_flags = intlog2 (requested_type) - 2
+                   - (duration_log > 2 ? duration_log - 2 : 0);
+                 if (tremolo_flags < 0)
+                   tremolo_flags = 0;
+                 tremolo_p_->set_elt_property ("tremolo-flags",
+                                               gh_int2scm (tremolo_flags));
                }
            }
-
-         // must give the request, to preserve the rhythmic info.
          announce_element (Score_element_info (stem_p_, r));
        }
 
-      if (stem_p_->flag_i_ != duration_log)
+      if (stem_p_->flag_i () != duration_log)
        {
-         r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i_));
+         r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i ()));
        }
 
       stem_p_->add_head (h);
@@ -87,53 +133,47 @@ Stem_engraver::acknowledge_element(Score_element_info i)
 void
 Stem_engraver::do_pre_move_processing()
 {
-  if (abbrev_p_)
+  if (tremolo_p_)
     {
-      abbrev_p_->set_stem (stem_p_);
-      typeset_element (abbrev_p_);
-      abbrev_p_ = 0;
+      Stem_tremolo::set_stem (tremolo_p_, stem_p_);
+      typeset_element (tremolo_p_);
+      tremolo_p_ = 0;
     }
 
   if (stem_p_)
     {
-      Scalar prop = get_property ("verticalDirection", 0);
-      Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
-      if (dir)
+      SCM prop = get_property ("stemLeftBeamCount");
+      if (gh_number_p(prop))
        {
-         stem_p_->dir_ = dir;
-         stem_p_->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
+         stem_p_->set_beaming (gh_scm2int (prop),LEFT);
+         daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
        }
-
-      Translator_group* which;
-      prop = get_property ("stemLeftBeamCount", &which);
-      if (prop.isnum_b ())
+      prop = get_property ("stemRightBeamCount");
+      if (gh_number_p(prop))
        {
-         stem_p_->beams_i_drul_[LEFT] = prop;
-         ((Translator_group*)which)->set_property ("stemLeftBeamCount", "");
-       }
-      prop = get_property ("stemRightBeamCount", &which);
-      if (prop.isnum_b ())
-       {
-         stem_p_->beams_i_drul_[RIGHT] = prop;
-         ((Translator_group*)which)->set_property ("stemRightBeamCount", "");
+         stem_p_->set_beaming (gh_scm2int (prop), RIGHT);
+         daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
        }
 
-      prop = get_property ("stemLength", 0);
-      if (prop.isnum_b ())
+      
+      // UGH. Should mark non-forced instead.
+
+      /*
+        aargh: I don't get it.  direction is being set (and then set
+        to forced), if we have a Chord_tremolo.
+       */
+      SCM dir = stem_p_->get_elt_property ("direction");
+      if (gh_number_p (dir) && to_dir(dir))
        {
-         stem_p_->set_elt_property (length_scm_sym, gh_double2scm (prop.to_f ()));
+         stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);   
        }
 
-      prop = get_property ("stemStyle", 0);
-      if (prop.to_bool ())
-       {
-         stem_p_->set_elt_property (style_scm_sym, ly_ch_C_to_scm (prop.ch_C()));
-       }
-      
       typeset_element(stem_p_);
       stem_p_ = 0;
     }
-  abbrev_req_l_ = 0;
+
+
+  tremolo_req_l_ = 0;
 }
 
 bool
@@ -141,11 +181,9 @@ Stem_engraver::do_try_music (Music* r)
 {
   if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
     {
-      abbrev_req_l_ = a;
+      tremolo_req_l_ = a;
       return true;
     }
   return false;
 }
 
-
-ADD_THIS_TRANSLATOR(Stem_engraver);