summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Puttock <n.puttock@gmail.com>2008-07-04 23:32:09 +0100
committerNeil Puttock <n.puttock@gmail.com>2008-07-05 01:05:06 +0100
commit2986878e42b272268adb989576e9ab946ca78d1e (patch)
treeb3dc3d8fff2fafef119be808635201fec4972040
parent6fc96a11b5a0321e9494c83dc4a8cae58255365a (diff)
Fix 524 pitched trill losing accidental.
- 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.
-rw-r--r--input/regression/trill-spanner-pitched-consecutive.ly28
-rw-r--r--input/regression/trill-spanner-pitched-forced.ly16
-rw-r--r--lily/accidental-engraver.cc36
-rw-r--r--lily/context.cc14
-rw-r--r--lily/include/context.hh1
-rw-r--r--lily/pitched-trill-engraver.cc15
-rw-r--r--ly/music-functions-init.ly30
7 files changed, 101 insertions, 39 deletions
diff --git a/input/regression/trill-spanner-pitched-consecutive.ly b/input/regression/trill-spanner-pitched-consecutive.ly
new file mode 100644
index 0000000000..33fcf817dc
--- /dev/null
+++ b/input/regression/trill-spanner-pitched-consecutive.ly
@@ -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
index 0000000000..e888bbcdbb
--- /dev/null
+++ b/input/regression/trill-spanner-pitched-forced.ly
@@ -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
+}
diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc
index ce9a670f04..211cbe4ab1 100644
--- a/lily/accidental-engraver.cc
+++ b/lily/accidental-engraver.cc
@@ -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;
diff --git a/lily/context.cc b/lily/context.cc
index ba3809e69a..2f23024e2d 100644
--- a/lily/context.cc
+++ b/lily/context.cc
@@ -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)
diff --git a/lily/include/context.hh b/lily/include/context.hh
index 33e8f8c9a0..f0cd67c314 100644
--- a/lily/include/context.hh
+++ b/lily/include/context.hh
@@ -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. */
diff --git a/lily/pitched-trill-engraver.cc b/lily/pitched-trill-engraver.cc
index 3104b48ce0..39cb899acc 100644
--- a/lily/pitched-trill-engraver.cc
+++ b/lily/pitched-trill-engraver.cc
@@ -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_)
{
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index 2e2a154d7d..f978e36daa 100644
--- a/ly/music-functions-init.ly
+++ b/ly/music-functions-init.ly
@@ -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))