]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-engraver.cc
2003 -> 2004
[lilypond.git] / lily / tuplet-engraver.cc
index 071e55e03bf5e49f5b87f5acf719581eb1cdeac1..2745f3461eb4d16457742c62539aba09270ebbb6 100644 (file)
@@ -3,56 +3,57 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 
-#include "command-request.hh"
-#include "tuplet-spanner.hh"
+
+#include "tuplet-bracket.hh"
 #include "note-column.hh"
 #include "time-scaled-music.hh"
 #include "beam.hh"
 #include "music-list.hh"
 #include "engraver.hh"
+#include "spanner.hh"
 
 class Tuplet_engraver : public Engraver
 {
 public:
-  VIRTUAL_COPY_CONS(Translator);
+  TRANSLATOR_DECLARATIONS(Tuplet_engraver);
 
 protected:
-  Link_array<Time_scaled_music> time_scaled_music_arr_;
-  /// when does the scaled music stop? Array order is synced with time_scaled_music_arr_
-  Array<Moment> stop_moments_;
-  /// when does the current spanner stop? Array order is synced with time_scaled_music_arr_
-  Array<Moment> span_stop_moments_;
+  Link_array<Music> time_scaled_musics_;
+  /// when does the scaled music stop? Array order is synced with time_scaled_musics_
+  Array<Rational> stop_moments_;
+  /// when does the current spanner stop? Array order is synced with time_scaled_musics_
+  Array<Rational> span_stop_moments_;
   
-  /// The spanners. Array order is synced with time_scaled_music_arr_
-  Link_array<Spanner> started_span_p_arr_;
-
-  virtual void do_removal_processing ();
-  virtual void acknowledge_element (Score_element_info);
-  virtual bool do_try_music (Music*r);
-  virtual void do_process_music ();
-  virtual void do_post_move_processing ();
+  /// The spanners. Array order is synced with time_scaled_musics_
+  Link_array<Spanner> started_spanners_;
+
+  virtual void finalize ();
+  virtual void acknowledge_grob (Grob_info);
+  virtual bool try_music (Music*r);
+  virtual void start_translation_timestep ();
+  virtual void process_acknowledged_grobs ();
 };
 
 bool
-Tuplet_engraver::do_try_music (Music *r)
+Tuplet_engraver::try_music (Music *c)
 {
-  if (Time_scaled_music * c = dynamic_cast<Time_scaled_music *> (r))
+  if (c->is_mus_type ("time-scaled-music"))
     {
-      Music *el = c->element_l ();
-      if (!dynamic_cast<Request_chord*> (el))
+      Music *el = unsmob_music (c->get_mus_property ("element"));
+      if (el && !el->is_mus_type ("event-chord"))
        {
-         time_scaled_music_arr_.push (c);
-         Moment m = now_mom () + c->length_mom ();
+         time_scaled_musics_.push (c);
+         Rational m = now_mom ().main_part_ + c->get_length ().main_part_;
          stop_moments_.push (m);
 
          SCM s = get_property ("tupletSpannerDuration");
-         if (unsmob_moment(s))
-           m = m <? (now_mom () + *unsmob_moment (s));
+         if (unsmob_moment (s))
+           m = m <? (now_mom () + *unsmob_moment (s)).main_part_;
          
          span_stop_moments_.push (m);
        }
@@ -62,98 +63,103 @@ Tuplet_engraver::do_try_music (Music *r)
 }
 
 void
-Tuplet_engraver::do_process_music ()
+Tuplet_engraver::process_acknowledged_grobs ()
 {
   SCM v = get_property ("tupletInvisible");
   if (to_boolean (v))
     return;
 
-  for (int i= 0; i < time_scaled_music_arr_.size (); i++)
+  for (int i= 0; i < time_scaled_musics_.size (); i++)
     {
-      if (i < started_span_p_arr_.size () && started_span_p_arr_[i])
+      if (i < started_spanners_.size () && started_spanners_[i])
        continue;
 
-      Spanner* glep = new Spanner (get_property ("basicTupletSpannerProperties"));
-      Tuplet_spanner::set_interface (glep);
-      if (i >= started_span_p_arr_.size ())
-       started_span_p_arr_.push (glep);
+      Spanner* glep = make_spanner ("TupletBracket");
+
+      if (i >= started_spanners_.size ())
+       started_spanners_.push (glep);
       else
-       started_span_p_arr_[i] = glep;
+       started_spanners_[i] = glep;
       
-      glep->set_elt_property ("text",
-                             ly_str02scm (to_str (time_scaled_music_arr_[i]->den_i_).ch_C()));
+
+      SCM proc = get_property ("tupletNumberFormatFunction");
+      if (gh_procedure_p (proc))
+       {
+         SCM t = gh_apply (proc, scm_list_n (time_scaled_musics_[i]->self_scm (), SCM_UNDEFINED));
+         glep->set_grob_property ("text", t);
+       }
       
-      announce_element (Score_element_info (glep, time_scaled_music_arr_ [i]));
+      announce_grob(glep, time_scaled_musics_ [i]->self_scm());
     }
 }
 
 void
-Tuplet_engraver::acknowledge_element (Score_element_info i)
+Tuplet_engraver::acknowledge_grob (Grob_info i)
 {
-  bool grace= to_boolean (i.elem_l_->get_elt_property ("grace"));
-  SCM wg = get_property ("weAreGraceContext");
-  bool wgb = to_boolean (wg);
-  if (grace != wgb)
-    return;
-  
-  if (Note_column *nc = dynamic_cast<Note_column *> (i.elem_l_))
-    {
-      for (int j =0; j  <started_span_p_arr_.size (); j++)
-       if (started_span_p_arr_[j]) 
-         Tuplet_spanner::add_column (started_span_p_arr_[j],nc);
-    }
-  else if (Beam *b = dynamic_cast<Beam *> (i.elem_l_))
+  if (Note_column::has_interface (i.grob_))
     {
-      for (int j = 0; j < started_span_p_arr_.size (); j++)
-       if (started_span_p_arr_[j]) 
-         Tuplet_spanner::add_beam (started_span_p_arr_[j],b);
+      for (int j =0; j  <started_spanners_.size (); j++)
+       if (started_spanners_[j]) 
+         Tuplet_bracket::add_column (started_spanners_[j], dynamic_cast<Item*> (i.grob_));
     }
 }
 
 void
-Tuplet_engraver::do_post_move_processing ()
+Tuplet_engraver::start_translation_timestep ()
 {
   Moment now = now_mom ();
 
   Moment tsd;
   SCM s = get_property ("tupletSpannerDuration");
   if (unsmob_moment (s))
-    tsd = *unsmob_moment (s);
+    tsd = unsmob_moment (s)->main_part_;
 
-  for (int i= started_span_p_arr_.size (); i--; )
+  for (int i= started_spanners_.size (); i--;)
     {
-      if (now >= span_stop_moments_[i])
+      if (now.main_part_ >= span_stop_moments_[i])
        {
-         if (started_span_p_arr_[i])
+         if (Spanner *sp = started_spanners_[i])
            {
-             typeset_element (started_span_p_arr_[i]);
-             started_span_p_arr_[i] =0;
+             if (!sp->get_bound (RIGHT))
+               sp->set_bound (RIGHT, sp->get_bound (LEFT));
+             
+             typeset_grob (sp);
+
+             started_spanners_[i] =0;
            }
          
-         if (tsd)
-           span_stop_moments_[i] += tsd;
+         if (tsd.to_bool ())
+           span_stop_moments_[i] += tsd.main_part_;
        }
 
-      if (now >= stop_moments_[i])
+      if (now.main_part_ >= stop_moments_[i])
        {
-         started_span_p_arr_.del (i);
-         stop_moments_.del(i);
+         started_spanners_.del (i);
+         stop_moments_.del (i);
          span_stop_moments_.del (i);
-         time_scaled_music_arr_.del(i);
+         time_scaled_musics_.del (i);
        }
     }
 }
 
 void
-Tuplet_engraver::do_removal_processing ()
+Tuplet_engraver::finalize ()
 {
-  for (int i=0; i < started_span_p_arr_.size (); i++)
+  for (int i=0; i < started_spanners_.size (); i++)
     {
-      if (started_span_p_arr_[i])
-       typeset_element (started_span_p_arr_[i]);
+      if (started_spanners_[i])
+       typeset_grob (started_spanners_[i]);
     }  
 }
 
-ADD_THIS_TRANSLATOR(Tuplet_engraver);
 
 
+Tuplet_engraver::Tuplet_engraver(){}
+
+ENTER_DESCRIPTION(Tuplet_engraver,
+/* descr */       "Catch Time_scaled_music and generate appropriate bracket  ",
+/* creats*/       "TupletBracket",
+/* accepts */     "time-scaled-music",
+/* acks  */      "note-column-interface",
+/* reads */       "tupletNumberFormatFunction tupletSpannerDuration tupletInvisible",
+/* write */       "");