From ec538f9d8b43800a6529afee25819d8476d5a08a Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Wed, 23 Jan 2008 09:36:30 +0100 Subject: [PATCH] Fix 467 Prevent clefs and octavation marks from disagreeing over middleCPosition by introducing a separate variable (middleCClefPosition and middleCOffset) for each purpose. --- lily/clef-engraver.cc | 1 - lily/ottava-engraver.cc | 5 ++--- lily/pitch-scheme.cc | 18 ++++++++++++++++ ly/engraver-init.ly | 6 +++++- scm/define-context-properties.scm | 8 ++++++- scm/music-functions.scm | 35 +++++++++++++------------------ scm/parser-clef.scm | 6 ++++-- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/lily/clef-engraver.cc b/lily/clef-engraver.cc index d9b2e27dea..74992be976 100644 --- a/lily/clef-engraver.cc +++ b/lily/clef-engraver.cc @@ -202,6 +202,5 @@ ADD_TRANSLATOR (Clef_engraver, "clefPosition " "explicitClefVisibility " "forceClef " - "middleCPosition " , /* write */ ""); diff --git a/lily/ottava-engraver.cc b/lily/ottava-engraver.cc index c1afcfed3c..01bf1d85c6 100644 --- a/lily/ottava-engraver.cc +++ b/lily/ottava-engraver.cc @@ -60,9 +60,8 @@ Ottava_spanner_engraver::process_music () span_ = make_spanner ("OttavaBracket", SCM_EOL); span_->set_property ("text", ott); - SCM c0 (get_property ("middleCPosition")); - SCM oc0 (get_property ("originalMiddleCPosition")); - if (scm_less_p (oc0, c0) == SCM_BOOL_T) + SCM offset (get_property ("middleCOffset")); + if (robust_scm2double (offset, 0) > 0) span_->set_property ("direction", scm_from_int (DOWN)); } } diff --git a/lily/pitch-scheme.cc b/lily/pitch-scheme.cc index 12ddddf10a..2eb36a6525 100644 --- a/lily/pitch-scheme.cc +++ b/lily/pitch-scheme.cc @@ -142,3 +142,21 @@ LY_DEFINE (ly_pitch_diff, "ly:pitch-diff", return pitch_interval (*r, *p).smobbed_copy (); } + +/* FIXME: probably isn't the right place for this function */ +#include "context.hh" +LY_DEFINE (ly_set_middle_C_x, "ly:set-middle-C!", + 1, 0, 0, (SCM context), + "Set the @code{middleCPosition} variable in @var{context}" + " based on the variables @code{middleCClefPosition} and" + " middleCOffset.") +{ + LY_ASSERT_SMOB (Context, context, 1); + + Context *c = unsmob_context (context); + int clef_pos = robust_scm2int (c->get_property ("middleCClefPosition"), 0); + int offset = robust_scm2int (c->get_property ("middleCOffset"), 0); + + c->set_property (ly_symbol2scm ("middleCPosition"), scm_from_int (clef_pos + offset)); + return SCM_UNDEFINED; +} diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index d8ffe8990f..2b7d5a8281 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -505,6 +505,7 @@ automatically when an output definition (a @code{\score} or tieWaitForNote = ##f clefGlyph = #"clefs.G" clefPosition = #-2 + middleCClefPosition = #-6 middleCPosition = #-6 firstClef = ##t @@ -571,7 +572,8 @@ automatically when an output definition (a @code{\score} or bassStaffProperties = #'((assign clefGlyph "clefs.F") (assign clefPosition 2) - (assign middleCPosition 6)) + (assign middleCPosition 6) + (assign middleCClefPosition 6)) %% tablature: stringOneTopmost = ##t highStringOne = ##t @@ -782,6 +784,7 @@ of Editio Vaticana." %% Choose vaticana do clef on 3rd line as default. clefGlyph = #"clefs.vaticana.do" middleCPosition = #1 + middleCClefPosition = #1 clefPosition = #1 clefOctavation = #0 @@ -882,6 +885,7 @@ accommodated for typesetting a piece in mensural style." %% Choose petrucci g clef on 2nd line as default. clefGlyph = #"clefs.petrucci.g" + middleCClefPosition = #-6 middleCPosition = #-6 clefPosition = #-2 clefOctavation = #0 diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 528bce0901..a80deb681c 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -306,9 +306,15 @@ markup. Called with two arguments, event and context.") @code{midiMinimumVolume}.") (midiMinimumVolume ,number? "Set the minimum loudness for MIDI. Ranges from 0 to@tie{}1.") + (middleCClefPosition ,number? "The position of the middle C, +as determined only by the clef. This can be calculated by looking at +@code{clefPosition} and @code{clefGlyph}.") + (middleCOffset ,number? "The offset of +middle C from the position given by @code{middleCClefPosition} This +is used for ottava brackets.") (middleCPosition ,number? "The place of the middle C, measured in half staff-spaces. Usually determined by looking at -@code{clefPosition} and @code{clefGlyph}.") +@code{middleCClefPosition} and @code{middleCOffset}.") (minimumFret ,number? "The tablature auto string-selecting mechanism selects the highest string with a fret at least @code{minimumFret}.") diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 5585eebdb7..1e7c524241 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -439,27 +439,20 @@ i.e. this is not an override" "Either reset middleCPosition to the stored original, or remember old middleCPosition, add OCTAVATION to middleCPosition, and set OTTAVATION to `8va', or whatever appropriate." - (if (number? (ly:context-property context 'middleCPosition)) - (begin - (if (number? (ly:context-property context 'originalMiddleCPosition)) - (let ((where (ly:context-property-where-defined context 'middleCPosition))) - - (ly:context-set-property! context 'middleCPosition - (ly:context-property context 'originalMiddleCPosition)) - (ly:context-unset-property where 'originalMiddleCPosition) - (ly:context-unset-property where 'ottavation))) -ot - (let* ((where (ly:context-property-where-defined context 'middleCPosition)) - (c0 (ly:context-property context 'middleCPosition)) - (new-c0 (+ c0 (* -7 octavation))) - (string (cdr (assoc octavation '((2 . "15ma") - (1 . "8va") - (0 . #f) - (-1 . "8vb") - (-2 . "15mb")))))) - (ly:context-set-property! context 'middleCPosition new-c0) - (ly:context-set-property! context 'originalMiddleCPosition c0) - (ly:context-set-property! context 'ottavation string))))) + (if (number? (ly:context-property context 'middleCOffset)) + (let ((where (ly:context-property-where-defined context 'middleCOffset))) + (ly:context-unset-property where 'middleCOffset) + (ly:context-unset-property where 'ottavation))) + + (let* ((offset (* -7 octavation)) + (string (cdr (assoc octavation '((2 . "15ma") + (1 . "8va") + (0 . #f) + (-1 . "8vb") + (-2 . "15mb")))))) + (ly:context-set-property! context 'middleCOffset offset) + (ly:context-set-property! context 'ottavation string) + (ly:set-middle-C! context))) (set! (ly:music-property m 'procedure) ottava-modify) (context-spec-music m 'Staff))) diff --git a/scm/parser-clef.scm b/scm/parser-clef.scm index 4724090ff9..ede242b4aa 100644 --- a/scm/parser-clef.scm +++ b/scm/parser-clef.scm @@ -113,15 +113,17 @@ (if (pair? e) (let* ((musics (map make-prop-set `(((symbol . clefGlyph) (value . ,(cadr e))) - ((symbol . middleCPosition) + ((symbol . middleCClefPosition) (value . ,(+ oct (caddr e) (cdr (assoc (cadr e) c0-pitch-alist))))) ((symbol . clefPosition) (value . ,(caddr e))) ((symbol . clefOctavation) (value . ,(- oct)))))) + (recalc-mid-C (make-music 'ApplyContext)) (seq (make-music 'SequentialMusic - 'elements musics)) + 'elements (append musics (list recalc-mid-C)))) (csp (make-music 'ContextSpeccedMusic))) + (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!) (context-spec-music seq 'Staff)) (begin (ly:warning (_ "unknown clef type `~a'") clef-name) -- 2.39.2