]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/include/global-context.hh (Context): clean-up data hiding.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 13 Mar 2004 10:51:51 +0000 (10:51 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 13 Mar 2004 10:51:51 +0000 (10:51 +0000)
* lily/include/music-iterator.hh (class Music_iterator): clean-up
data hiding.

* lily/include/grace-fixup.hh (struct Grace_fixup): new file.

* input/regression/stem-shorten.ly: add chord case.

* lily/stem.cc (get_default_stem_end_position): shorten stems
triggered by note-head positions, not by forced-direction. This
fixes a bug with too short stems.

18 files changed:
ChangeLog
input/regression/staccato-pos.ly
input/regression/stem-shorten.ly
lily/global-context.cc
lily/hyphen-engraver.cc
lily/include/global-context.hh
lily/include/grace-fixup.hh [new file with mode: 0644]
lily/include/lily-proto.hh
lily/include/music-iterator.hh
lily/include/sequential-iterator.hh
lily/multi-measure-rest-engraver.cc
lily/music-iterator.cc
lily/score.cc
lily/sequential-iterator.cc
lily/span-bar-engraver.cc
lily/stem.cc
lily/timing-translator.cc
scm/define-grobs.scm

index a5faceed65e1309c08efc4be9135248488083be4..d8a0907ed55b36e0de88609cc0e0365f89a51fd1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-03-13  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * lily/include/global-context.hh (Context): clean-up data hiding.
+
+       * lily/include/music-iterator.hh (class Music_iterator): clean-up
+       data hiding.
+
+       * lily/include/grace-fixup.hh (struct Grace_fixup): new file.
+
+       * input/regression/stem-shorten.ly: add chord case.
+
+       * lily/stem.cc (get_default_stem_end_position): shorten stems
+       triggered by note-head positions, not by forced-direction. This
+       fixes a bug with too short stems.  
 2004-03-12  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * scripts/lilypond-book.py (Lilypond_snippet.output_html,
index f4fbedc00d993afb2de91226223007b154964faf..adcc01891897daff754f8123115a9c27e03b7868 100644 (file)
@@ -2,19 +2,22 @@
 \version "2.1.30"
 
 \header{
-texidoc="
-The staccato dot (and all scripts with follow-into-staff set) must
-not be on staff lines.
-"
+
+    texidoc=" The staccato dot (and all scripts with follow-into-staff
+set) must not be on staff lines. The staccato dot is close to the
+notehead. If the head is in a space, then the dot is in the space next
+to it.  "
+
 }
+
 \score { 
-  \context Voice \notes\relative c' {
-       e'4-. f-. d-. c-. b-.
+    \context Voice \notes\relative c' {
+       e'4-. f-. g-. d-. c-. b-.
        \stemDown
        e,-. d-. c-. b-. a-. g-.    
-  }
-  \paper {
-    raggedright = ##t
-  }  
+    }
+    \paper {
+       raggedright = ##t
+    }  
 }
 
index a3c511c95aebb3ed6546779c2a024881050fbaa0..cfa16c89907c4fc55b3fd55b25bfa15977a99cf9 100644 (file)
@@ -3,15 +3,22 @@
 
 \header {
     
-    texidoc = "Stems in forced directions (as well as the ones
-    starting from the middle line) are shortened."
+    texidoc = "If note head is `over' the center line, the stem is
+ shortened.  This happens with forced stem directions, and with some
+ chord configurations."
 
 }
 
 \score {
-    \notes \relative c'' { \stemDown d c b a g f e
-                          \stemBoth
-                          \stemUp a b c d e f g a 
-                      } 
-    \paper  {raggedright = ##t }
+    \notes \relative c'' {
+       \stemDown d c b a g f e
+       \stemBoth
+       \stemUp a b c d e f g a
+       \stemBoth
+       <g, e'>2 <b e g> <c e g> <d f g>
+       
+    } 
+    \paper  {
+       raggedright = ##t
+    }
 }
index 7ea4f98732e6061e1cf1e56dbbc1ca1795b5fe60..5c273a1893679a76d6565f4455e06dd187d1adb2 100644 (file)
 #include "score-context.hh"
 #include "context-def.hh"
 #include "music-output-def.hh"
+#include "grace-fixup.hh"
 
-Global_context::Global_context (Music_output_def*o)
+Global_context::Global_context (Music_output_def *o, Moment final)
 {
   output_def_ = o;
+  final_mom_ = final;
   definition_ = o->find_context_def (ly_symbol2scm ("Global"));
   unsmob_context_def (definition_)->apply_default_property_operations (this);
   accepts_list_ = scm_list_1 (ly_symbol2scm ("Score"));
@@ -34,7 +36,7 @@ Global_context::get_output_def () const
 void
 Global_context::add_moment_to_process (Moment m)
 {
-  if (m  > final_mom_)
+  if (m > final_mom_)
     return;
 
   if (m < now_mom_)
@@ -125,17 +127,6 @@ Global_context::run_iterator_on_me (Music_iterator * iter)
       if (w.main_part_.is_infinity ())
        break ;
       
-#if 0      
-      //      printf ("proccing %s\n ",       w.to_string ().to_str0 ());
-      if (first)
-       {
-         /*
-           Huh? 
-          */
-         set_property ("measurePosition", w.smobbed_copy ());
-       }
-#endif
-      
       prepare (w);
 
       if (iter->ok ())
@@ -157,7 +148,7 @@ Global_context::run_iterator_on_me (Music_iterator * iter)
        }
       
       one_time_step ();
-      first = false;      
+      first = false;
     }
 }
 
@@ -173,8 +164,8 @@ Global_context::apply_finalizations ()
 }
 
 /*
-   Add a function to execute before stepping to the next time step.
- */
+  Add a function to execute before stepping to the next time step.
+*/
 void
 Global_context::add_finalization (SCM x)
 {
@@ -183,3 +174,8 @@ Global_context::add_finalization (SCM x)
   set_property ("finalizations" ,lst); 
 }
 
+Moment
+Global_context::previous_moment () const
+{
+  return prev_mom_;
+}
index 96ec03b3fcb54ae44514801aad4698b01160f721..96839f8f99e2b481979a924a10ff3d5fbbccbd93 100644 (file)
@@ -15,9 +15,9 @@
 
 class Hyphen_engraver : public Engraver
 {
-  Musicev_;
-  Spannerhyphen_;
-  Spanner * finished_hyphen_;  
+  Music *ev_;
+  Spanner *hyphen_;
+  Spanner *finished_hyphen_;  
 public:
   TRANSLATOR_DECLARATIONS (Hyphen_engraver);
 
index ba75d260871d7f3b3b5423ecfdf5960e32b9de93..f48f94313805301c779c6d7338a17769d8543e26 100644 (file)
@@ -20,7 +20,7 @@ class Global_context : public virtual Context
   
   friend class Music_output_def;
 public:
-  Global_context (Music_output_def*);
+  Global_context (Music_output_def*, Moment final);
   int get_moments_left () const;
   Moment sneaky_insert_extra_moment (Moment);
   void add_moment_to_process (Moment);
@@ -37,10 +37,11 @@ public:
   virtual Music_output_def* get_output_def () const; 
   virtual Moment now_mom () const;
 
+  Moment previous_moment () const;
+protected:
   Moment final_mom_;
   Moment prev_mom_;
   Moment now_mom_;
-protected:
 };
 
 
diff --git a/lily/include/grace-fixup.hh b/lily/include/grace-fixup.hh
new file mode 100644 (file)
index 0000000..22b4a74
--- /dev/null
@@ -0,0 +1,49 @@
+/*   
+     grace-fixup.hh -- declare Grace_fixup
+
+     source file of the GNU LilyPond music typesetter
+
+     (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef GRACE_FIXUP_HH
+#define GRACE_FIXUP_HH
+
+#include "moment.hh"
+
+/*
+
+  This is a lookahead list for grace notes.
+
+   {  ... X \grace Y  Z ... }
+
+   normally, the ending of X is the start of Z. In case of a grace
+   note, we take off a little at the end of X. What is stored: START
+   (start point of X), LENGTH (length of X), GRACE_START (start_music
+   of Y), and the next fixup element.
+
+  This is also done for nested musics, i.e.
+
+  voiceA = \notes { \grace b16 c'2 }
+  voiceB = \notes { c'2 \voiceA }
+
+  the iterator for voiceB will contain a fixup entry with (START=0/1,
+  LENGTH=2/1, GRACE_START=(0G-1/16) ) 
+   
+  Graces at the start of a sequential music iterator are handled
+  by initting here_mom_ with Music::start_music (); no fixups are needed.
+
+*/
+struct Grace_fixup 
+{
+  Moment start_;
+  Moment length_;
+
+  Rational grace_start_;
+
+  Grace_fixup * next_;
+};
+
+#endif /* GRACE_FIXUP_HH */
+
index 017271de13bdb6e92e052ff0663886dfc1f3c858..b537a981a99099be69cf288ef38ceaa59a61b5ab 100644 (file)
@@ -33,7 +33,6 @@ class Auto_change_music;
 class Axis_group_engraver;
 class Bar_engraver;
 class Bar_req_collect_engraver;
-class Base_span_bar_engraver;
 class Beaming_info_list;
 class Bezier;
 class Bezier_bow;
@@ -52,11 +51,10 @@ class Folded_repeat_iterator;
 class Font_metric;
 class Font_size_engraver;
 class Global_context;
+class Grace_fixup;
 class Gourlay_breaking;
-class Grace_engraver_group;
 class Grace_iterator;
 class Grace_music;
-class Grace_performer_group;
 class Hara_kiri_engraver;
 class Hara_kiri_line_group_engraver;
 class Includable_lexer;
@@ -70,7 +68,6 @@ class Ligature_engraver;
 class Ligature_bracket_engraver;
 class Line_group_engraver_group;
 class System;
-class Local_key_item;
 class Lookup;
 class Lyric_combine_music;
 class Lyric_combine_music_iterator;
index b482b7ccc5206cf465cc479f7faff2bcdc1935e5..5622e1660184976d52cc2255b2ce937bcba699c0 100644 (file)
@@ -62,7 +62,7 @@ protected:
 public:
   
   Moment music_get_length () const;
-  Moment music_start_mom () const;
+  virtual Moment music_start_mom () const;
   Music_iterator ();
 
   /**
index eac01f3f7741a17940b4fd4378a81ea1fe35427e..c0c37e394394b3c3827c3c49d092641a72551038 100644 (file)
 #include "music-iterator.hh"
 #include "protected-scm.hh"
 
-/*
-
-  This is a lookahead list for grace notes.
-
-   {  ... X \grace Y  Z ... }
-
-   normally, the ending of X is the start of Z. In case of a grace
-   note, we take off a little at the end of X. What is stored: START
-   (start point of X), LENGTH (length of X), GRACE_START (start_music
-   of Y), and the next fixup element.
-
-  This is also done for nested musics, i.e.
-
-  voiceA = \notes { \grace b16 c'2 }
-  voiceB = \notes { c'2 \voiceA }
-
-  the iterator for voiceB will contain a fixup entry with (START=0/1,
-  LENGTH=2/1, GRACE_START=(0G-1/16) ) 
-   
-  Graces at the start of a sequential music iterator are handled
-  by initting here_mom_ with Music::start_music (); no fixups are needed.
-
-*/
-struct Grace_fixup 
-{
-  Moment start_;
-  Moment length_;
-
-  Rational grace_start_;  
-  Grace_fixup *next_;
-};
 
 /** Sequential_music iteration: walk each element in turn, and
   construct an iterator for every element.
@@ -77,8 +46,8 @@ protected:
   void next_grace_fixup ();
   
 private:
+  Moment last_mom_;
   Moment here_mom_;
-  SCM list_;
   SCM cursor_;
   Grace_fixup * grace_fixups_;
   
index 7d66ce48be1560b4284166ab97fe9ed4849d7c37..598477b5f421a32e0f9ae6cb3cbbb78c7fda0e6f 100644 (file)
@@ -17,7 +17,6 @@
 
 /**
    The name says it all: make multi measure rests 
-
 */
 class Multi_measure_rest_engraver : public Engraver
 {
@@ -39,7 +38,7 @@ private:
   Moment stop_moment_;
   
   bool bar_seen_;
-  
+  Item *last_command_item_ ;
   Spanner *last_rest_;
   Spanner *mmrest_;
 
@@ -49,6 +48,7 @@ private:
 
 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
 {
+  last_command_item_ = 0;
   bar_seen_ = false;
   start_measure_ = 0;
   mmrest_ = 0;
@@ -151,24 +151,34 @@ Multi_measure_rest_engraver::stop_translation_timestep ()
       Grob *cmc = unsmob_grob (get_property ("breakableSeparationItem"));
       if (!cmc)
        cmc = unsmob_grob (get_property ("currentCommandColumn"));
-      
-      Item *it = dynamic_cast<Item*> (cmc);
-      
+
+      /*
+       Ugh, this is a kludge - need this for multi-measure-rest-grace.ly
+       */
+      last_command_item_ = dynamic_cast<Item*> (cmc);
+    }
+
+  if (last_command_item_ &&  (mmrest_ || last_rest_))
+    {
+          
+      if (last_rest_)
+       {
+         add_bound_item (last_rest_, last_command_item_);
+         for (int i = 0; i < last_numbers_.size (); i++)
+           add_bound_item (last_numbers_[i], last_command_item_);
+       }
+
       if (mmrest_)
        {
-         add_bound_item (mmrest_, it);
+         add_bound_item (mmrest_, last_command_item_);
          for (int i = 0; i < numbers_.size (); i++)
-           add_bound_item (numbers_[i], it);
+           add_bound_item (numbers_[i], last_command_item_);
+
+         last_command_item_ = 0;
        }
-      
-      if (last_rest_)
-       {
-         add_bound_item (last_rest_,it);
-         for (int i = 0; i < last_numbers_.size (); i++)
-           add_bound_item (last_numbers_[i], it);
-       }      
     }
   
+  
   SCM smp = get_property ("measurePosition");
   Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
 
index 9af76a408fd147925d7ca58c9c64a1521f895f79..02e6200abb9845a6bc53f43f8fb9d33867a0e40d 100644 (file)
@@ -98,6 +98,7 @@ Music_iterator::get_static_get_iterator (Music *m)
   assert (m);
   p->music_length_ = m->get_length ();
   p->start_mom_ = m->start_mom ();
+  
   return iter;
 }
 
index d0124b2c746c939f4bc23730650edf6fcbf05961..d007e2a2a2e509230d7a7860b25d1da75931dc77 100644 (file)
@@ -113,7 +113,9 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
   
   Cpu_timer timer;
   
-  Global_context * trans = new Global_context (odef);
+  Global_context * trans = new Global_context (odef,
+                                              music->get_length ()
+                                              );
   
   if (!trans)
     {
@@ -122,7 +124,6 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
     }
   progress_indication (_ ("Interpreting music..."));
   
-  trans->final_mom_ = music->get_length ();
   SCM protected_iter = Music_iterator::get_static_get_iterator (music);
   Music_iterator * iter = unsmob_iterator (protected_iter);
   iter->init_translator (music, trans);
@@ -132,7 +133,7 @@ LY_DEFINE (ly_run_translator, "ly:run-translator",
   if (! iter->ok ())
     {
       warning (_ ("Need music in a score"));
-      return SCM_BOOL_F;       // todo: shoudl throw exception.
+      return SCM_BOOL_F;       // todo: should throw exception.
     }
 
   trans->run_iterator_on_me (iter);
index 81e9dac2963a6e12bd38a2a1014c970b4d0c1264..39cc1a5bd56f49230a6f4cbd86c0afcc464bab18 100644 (file)
@@ -10,8 +10,7 @@
 #include "context.hh"
 #include "sequential-iterator.hh"
 #include "music-list.hh"
-
-Grace_fixup *get_grace_fixups (SCM cursor);
+#include "grace-fixup.hh"
 
 /*
   
@@ -38,7 +37,6 @@ Grace_fixup *get_grace_fixups (SCM cursor);
 Sequential_iterator::Sequential_iterator ()
 {
   here_mom_ = Moment (0);
-  list_ = SCM_EOL;
   cursor_ = SCM_EOL; 
   grace_fixups_ = 0;
   iter_ = 0;
@@ -61,23 +59,24 @@ Sequential_iterator::do_quit ()
 
 
 void
-Sequential_iterator::derived_mark ()const
+Sequential_iterator::derived_mark () const
 {
   if (iter_)
     scm_gc_mark (iter_->self_scm ());
-  scm_gc_mark (list_);
   scm_gc_mark (cursor_);
 }
 
 
 void
-Sequential_iterator::derived_substitute (Context *f,Context *t)
+Sequential_iterator::derived_substitute (Context *f, Context *t)
 {
   if (iter_)
-    iter_->substitute_outlet (f,t);
-  
+    iter_->substitute_outlet (f, t);
 }
 
+/*
+  TODO: this should be made lazily.
+ */
 Grace_fixup *
 create_grace_fixup_list (SCM cursor)
 {
@@ -121,13 +120,12 @@ create_grace_fixup_list (SCM cursor)
 void
 Sequential_iterator::construct_children ()
 {
-  list_ = get_music_list ();
-  cursor_ = list_; 
+  cursor_ = get_music_list ();
 
   iter_ = 0;
   if (gh_pair_p (cursor_))
     {
-      Music *m  =unsmob_music (ly_car (cursor_));
+      Music *m unsmob_music (ly_car (cursor_));
       iter_ = unsmob_iterator (get_iterator (m));
     }
   
@@ -136,6 +134,7 @@ Sequential_iterator::construct_children ()
       next_element (true);
     }
 
+  last_mom_ = Moment (-1);
   here_mom_ = get_music ()->start_mom ();
   grace_fixups_ = create_grace_fixup_list (cursor_);
 
@@ -161,7 +160,8 @@ Sequential_iterator::next_element (bool)
       && get_grace_fixup ())
     {
       Grace_fixup *gf = get_grace_fixup ();
-      
+
+      last_mom_ = here_mom_;
       here_mom_ += gf->length_;
       here_mom_.grace_part_ += gf->grace_start_;
 
@@ -169,6 +169,7 @@ Sequential_iterator::next_element (bool)
     }
   else if (len.grace_part_ && !len.main_part_)
     {
+      last_mom_ = here_mom_;
       here_mom_.grace_part_ =0;
     }
   else
@@ -180,6 +181,7 @@ Sequential_iterator::next_element (bool)
        in that chunk should be in len.grace_part_
 
       */
+      last_mom_ = here_mom_;;
       here_mom_ += len;
     }
   
@@ -212,8 +214,6 @@ Sequential_iterator::descend_to_child ()
     set_translator (child_report);
 }
 
-
-
 void
 Sequential_iterator::process (Moment until)
 {
@@ -299,7 +299,6 @@ Sequential_iterator::next_grace_fixup ()
   grace_fixups_ = n;
 }
 
-
 Grace_fixup*
 Sequential_iterator::get_grace_fixup () const
 {
index a75ef41fe1551f2cdc55e152415955fae1998c40..15e7234259b7794f07d347cf29c847042faefd5e 100644 (file)
@@ -25,7 +25,7 @@
   */
 class Span_bar_engraver : public Engraver
 {
-  Item * spanbar_;
+  Item *spanbar_;
   Link_array<Item> bars_;
 
 public:
@@ -33,17 +33,13 @@ public:
 protected:
   virtual void acknowledge_grob (Grob_info);
   virtual void stop_translation_timestep ();
-
 };
 
-
 Span_bar_engraver::Span_bar_engraver ()
 {
   spanbar_ =0;
 }
 
-
-
 void
 Span_bar_engraver::acknowledge_grob (Grob_info i)
 {
@@ -58,11 +54,11 @@ Span_bar_engraver::acknowledge_grob (Grob_info i)
          spanbar_ = make_item ("SpanBar");
 
          spanbar_->set_parent (bars_[0], X_AXIS);
-
          announce_grob (spanbar_, SCM_EOL);
        }
     }
 }
+
 void
 Span_bar_engraver::stop_translation_timestep ()
 {
@@ -73,7 +69,7 @@ Span_bar_engraver::stop_translation_timestep ()
 
       SCM vissym =ly_symbol2scm ("break-visibility");
       SCM vis = bars_[0]->internal_get_property (vissym);        
-      if (scm_equal_p (spanbar_->internal_get_property (vissym), vis) != SCM_BOOL_T)
+      if (gh_equal_p (spanbar_->internal_get_property (vissym), vis))
        spanbar_->internal_set_property (vissym, vis);
 
       typeset_grob (spanbar_);
@@ -83,11 +79,6 @@ Span_bar_engraver::stop_translation_timestep ()
 }
 
 
-
-
-
-
-
 ENTER_DESCRIPTION (Span_bar_engraver,
 /* descr */       "This engraver makes cross-staff barlines: It catches all normal "
 "bar lines, and draws a single span-bar across them.",
index 1a80ca819919576f68938f849ef7aae80da76cdf..30fc0040c89c08adb7b6887d0551f3fb20eb3432 100644 (file)
@@ -302,8 +302,6 @@ Stem::get_default_stem_end_position (Grob*me)
        }
     }
 
-
-
   /* URGURGURG
      'set-default-stemlen' sets direction too
    */
@@ -314,14 +312,10 @@ Stem::get_default_stem_end_position (Grob*me)
       set_grob_direction (me, dir);
     }
 
-
   /* stems in unnatural (forced) direction should be shortened, 
     according to [Roush & Gourlay] */
-  if (!chord_start_y (me)
-      || (get_direction (me) != get_default_dir (me)))
+  if (dir * head_positions (me)[dir] >= 0)
     {
-      
-  
       SCM sshorten = me->get_property ("stem-shorten");
       SCM scm_shorten = gh_pair_p (sshorten) ?
        robust_list_ref ((duration_log (me) - 2) >? 0, sshorten): SCM_EOL;
@@ -329,7 +323,7 @@ Stem::get_default_stem_end_position (Grob*me)
       
   
       /* On boundary: shorten only half */
-      if (abs (head_positions (me)[get_direction (me)]) <= 1)
+      if (abs (head_positions (me)[dir]) <= 1)
        shorten *= 0.5;
   
       length -= shorten;
index e097d93197d182dbea377d2171e4118ad46b7814..85bffc00b68b252df5a0b06522e5df954c936423 100644 (file)
@@ -96,8 +96,8 @@ Timing_translator::start_translation_timestep ()
 {
   Global_context *global =get_global_context ();
 
-  Moment now = global->now_mom_;
-  Moment dt = now  - global->prev_mom_;
+  Moment now = global->now_mom ();
+  Moment dt = now  - global->previous_moment ();
   if (dt < Moment (0))
     {
       programming_error ("Moving backwards in time");
index 1920f4a57cd3f345a0cb1d2b5e2b8635bbc6e74f..3cc58925029a154d0ea867eb718f1318d88cf155 100644 (file)
 
        ;; This value is sensitive: if too large, staccato dots will move a
        ;; space a away.
-       (padding . 0.25)
+       (padding . 0.20)
        (staff-padding . 0.25)
        ;; (script-priority . 0) priorities for scripts, see script.scm
        (X-offset-callbacks . (,Self_alignment_interface::centered_on_parent))