]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix 524 pitched trill losing accidental.
authorNeil Puttock <n.puttock@gmail.com>
Fri, 4 Jul 2008 22:32:09 +0000 (23:32 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Sat, 5 Jul 2008 00:05:06 +0000 (01:05 +0100)
- check localKeySignature more thoroughly when deciding whether
to print an accidental.  This includes checks for alteration and
measure number.
- print accidental if forced.
- move get_bar_number () from accidental-engraver.cc to context.cc
so that pitched-trill-engraver.cc can also use it.
- check secondary note events for `forced-accidental' property and pass to
engraver via trill-span-event if set.
- prevent accidental-engraver.cc setting `forced' property on non-existent
accidentals.
- add regression tests for forced-accidental and consecutive pitched trills.

input/regression/trill-spanner-pitched-consecutive.ly [new file with mode: 0644]
input/regression/trill-spanner-pitched-forced.ly [new file with mode: 0644]
lily/accidental-engraver.cc
lily/context.cc
lily/include/context.hh
lily/pitched-trill-engraver.cc
ly/music-functions-init.ly

diff --git a/input/regression/trill-spanner-pitched-consecutive.ly b/input/regression/trill-spanner-pitched-consecutive.ly
new file mode 100644 (file)
index 0000000..33fcf81
--- /dev/null
@@ -0,0 +1,28 @@
+\version "2.11.51"
+
+\header {
+  texidoc = "Pitched trills on consecutive notes with the same
+name and octave should not lose accidentals; in the following
+example, accidentals should be visible for all trill-pitches.
+"
+}
+
+\relative c' {
+  \pitchedTrill
+  f4\startTrillSpan ges f\stopTrillSpan
+  
+  \pitchedTrill
+  f4\startTrillSpan g gis\stopTrillSpan ~
+  
+  \pitchedTrill
+  gis4\startTrillSpan ges f\stopTrillSpan
+  
+  \pitchedTrill
+  g4\startTrillSpan gis f\stopTrillSpan
+  
+  \pitchedTrill
+  f4\startTrillSpan gisis f\stopTrillSpan
+  
+  \pitchedTrill
+  f4\startTrillSpan geses f\stopTrillSpan
+}
diff --git a/input/regression/trill-spanner-pitched-forced.ly b/input/regression/trill-spanner-pitched-forced.ly
new file mode 100644 (file)
index 0000000..e888bbc
--- /dev/null
@@ -0,0 +1,16 @@
+\version "2.11.51"
+
+\header {
+  texidoc = "Pitched trill accidentals can be forced."
+}
+
+\relative c' {  
+  \pitchedTrill
+  c4\startTrillSpan es f\stopTrillSpan
+  \pitchedTrill
+  c4\startTrillSpan es f\stopTrillSpan
+  \pitchedTrill
+  c4\startTrillSpan es f\stopTrillSpan
+  \pitchedTrill
+  c4\startTrillSpan-"forced" es! f\stopTrillSpan
+}
index ce9a670f044a462a268f172a27fcbbec87036cd6..211cbe4ab199d59074a935bf72dd8ed04ea2d0e4 100644 (file)
@@ -51,7 +51,6 @@ Accidental_entry::Accidental_entry ()
 
 class Accidental_engraver : public Engraver
 {
-  int get_bar_number ();
   void update_local_key_signature (SCM new_signature);
   void create_accidental (Accidental_entry *entry, bool, bool);
   Grob *make_standard_accidental (Stream_event *note, Grob *note_head, Engraver *trans, bool);
@@ -297,21 +296,6 @@ check_pitch_against_rules (Pitch const &pitch, Context *origin,
   return result;
 }
 
-int
-Accidental_engraver::get_bar_number ()
-{
-  SCM barnum = get_property ("internalBarNumber");
-  SCM smp = get_property ("measurePosition");
-
-  int bn = robust_scm2int (barnum, 0);
-
-  Moment mp = robust_scm2moment (smp, Moment (0));
-  if (mp.main_part_ < Rational (0))
-    bn--;
-
-  return bn;
-}
-
 void
 Accidental_engraver::process_acknowledged ()
 {
@@ -319,7 +303,7 @@ Accidental_engraver::process_acknowledged ()
     {
       SCM accidental_rules = get_property ("autoAccidentals");
       SCM cautionary_rules = get_property ("autoCautionaries");
-      int barnum = get_bar_number ();
+      int barnum = measure_number (context());
 
       for (vsize i = 0; i < accidentals_.size (); i++)
        {
@@ -354,12 +338,14 @@ Accidental_engraver::process_acknowledged ()
 
          /* Cannot look for ties: it's not guaranteed that they reach
             us before the notes. */
-         if (acc.need_acc
-             && !note->in_event_class ("trill-span-event"))
-           create_accidental (&accidentals_[i], acc.need_restore, cautionary);
+         if (!note->in_event_class ("trill-span-event"))
+           {
+             if (acc.need_acc)       
+               create_accidental (&accidentals_[i], acc.need_restore, cautionary);
 
-         if (forced || cautionary)
-           accidentals_[i].accidental_->set_property ("forced", SCM_BOOL_T);
+             if (forced || cautionary)
+               accidentals_[i].accidental_->set_property ("forced", SCM_BOOL_T);
+           }
        }
     }
 }
@@ -474,12 +460,12 @@ Accidental_engraver::stop_translation_timestep ()
     }
 
   for (vsize i = accidentals_.size (); i--;)
-    {
-      int barnum = get_bar_number ();
-
+    {      
       Stream_event *note = accidentals_[i].melodic_;
       Context *origin = accidentals_[i].origin_;
 
+      int barnum = measure_number (origin);
+
       Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
       if (!pitch)
        continue;
index ba3809e69a18d20f4c697562e54d84177bfa616a..2f23024e2d9d8700f113881c9955547e9997fc89 100644 (file)
@@ -709,6 +709,20 @@ measure_position (Context const *context)
   return m;
 }
 
+int
+measure_number (Context const *context)
+{
+  SCM barnum = context->get_property ("internalBarNumber");
+  SCM smp = context->get_property ("measurePosition");
+
+  int bn = robust_scm2int (barnum, 0);
+  Moment mp = robust_scm2moment (smp, Moment (0));
+  if (mp.main_part_ < Rational (0))
+    bn--;
+
+  return bn;
+}
+
 
 void
 set_context_property_on_children (Context *trans, SCM sym, SCM val)
index 33e8f8c9a03e6257dfc9326bf856c436c8423a67..f0cd67c314e12e57f02d1a8caf7eb9083dcadf7c 100644 (file)
@@ -140,6 +140,7 @@ DECLARE_UNSMOB (Context, context);
 
 Moment measure_position (Context const *context);
 Rational measure_length (Context const *context);
+int measure_number (Context const *context);
 void set_context_property_on_children (Context *trans, SCM sym, SCM val);
 
 /* Shorthand for creating and broadcasting stream events. */
index 3104b48ce02b1ba3ad1b0224eb5de04edf2c3d79..39cb899acc6b3b0e257082fe9c253d99fb9f6eef 100644 (file)
@@ -80,9 +80,22 @@ Pitched_trill_engraver::make_trill (Stream_event *ev)
   SCM key = scm_cons (scm_from_int (p->get_octave ()),
                      scm_from_int (p->get_notename ()));
 
+  int bn = measure_number (context());
+
   SCM handle = scm_assoc (key, keysig);
+  if (handle != SCM_BOOL_F)
+    {
+      bool same_bar = (bn == robust_scm2int (scm_cddr (handle), 0));
+      bool same_alt
+       = (p->get_alteration () == robust_scm2rational (scm_cadr (handle), 0));
+
+      if (!same_bar || (same_bar && !same_alt))
+       handle = SCM_BOOL_F;
+    }
+
   bool print_acc
-    = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0);
+    = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0)
+    || (ev->get_property ("force-accidental") == SCM_BOOL_T);
 
   if (trill_head_)
     {
index 2e2a154d7d904fc73ffbdffb44a9aab155decfb7..f978e36daa358fe295495d17c4a56ad9e6e6ebeb 100644 (file)
@@ -471,20 +471,24 @@ pitchedTrill =
                      (ly:music-property ev-chord 'elements))))
        (sec-note-events (get-notes secondary-note))
        (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
-                             (ly:music-property main-note 'elements)))
-
-       (trill-pitch
-        (if (pair? sec-note-events)
-            (ly:music-property (car sec-note-events) 'pitch)
-            )))
-     
-     (if (ly:pitch? trill-pitch)
-        (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
-                  trill-events)
-        (begin
-          (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
-          (display sec-note-events)))
+                             (ly:music-property main-note 'elements))))
 
+     (if (pair? sec-note-events)
+        (begin
+          (let*
+              ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
+               (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
+            
+            (if (ly:pitch? trill-pitch)
+                (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
+                          trill-events)
+                (begin
+                  (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
+                  (display sec-note-events)))
+
+            (if (eq? forced #t)
+                (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
+                          trill-events)))))
      main-note))