From 61d4126a7ef5b2f61ea8d72fa167f39149484c0f Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 29 Dec 2008 17:10:44 +0100 Subject: [PATCH] Better functions this commit (hopefully) solves once and for all the piano staves bug. Whenever a << \\ >> construct was used, the accidentals didn't appear because the Voices that were internally created didn't have the Accidental_engraver. So I had to keep the engraver at a Staff level, and just kill the accidentals on the fly in the PseudoVoice. --- definitions/functions.ly | 73 +++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/definitions/functions.ly b/definitions/functions.ly index 964166c..581126a 100755 --- a/definitions/functions.ly +++ b/definitions/functions.ly @@ -30,35 +30,52 @@ tttt = %% Polyphony shortcuts --------------------------------------------% -pl = -#(define-music-function (parser location one two) (ly:music? ly:music?) -#{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #}) +%%% Functions (Issue #442 workaround) -plperc = -#(define-music-function (parser location one two) (ly:music? ly:music?) -#{ << { \stemDown $one \stemNeutral } \new DrumVoice { \stemUp $two } >> #}) - -%%% Piano stuff (Issue #442 workaround) - -#(define (remove music) -"Sends the whole thing to Devnull whenever possible" +#(define (remove music) ; throw everything into the Big Void... (context-spec-music music 'Devnull)) - %%FIXME: add arpeggios in the filter. +#(define (unpitch music) + ; in addition to the PitchSquash thing, we need to make + ; accidentals disappear (since these are engraved at a + ; Staff level, and since we don't want to affect the + ; real Voice). + (let* ((es (ly:music-property music 'elements)) + (e (ly:music-property music 'element)) + (p (ly:music-property music 'pitch))) + (if (pair? es) + (ly:music-set-property! + music 'elements + (map (lambda (x) (unpitch x)) es))) + (if (ly:music? e) + (ly:music-set-property! + music 'element + (unpitch e))) + (if (ly:pitch? p) + (ly:music-set-property! music 'pitch 0))) + music) + #(define (event-filter event) (let ((n (ly:music-property event 'name))) (if (or (eq? n 'ContextSpeccedMusic) ; to avoid clefs and ottavas - (eq? n 'ContextChange)) ; cross-staff voices are supported + (eq? n 'ContextChange) ; cross-staff voices are supported + (eq? n 'ArpeggioEvent)) ; arpeggios need to go too (music-map remove event)) (if (eq? n 'SimultaneousMusic) ; we don't want a new Voice to be created (ly:music-set-property! event 'name 'NoteEvent)))) makeGhost = #(define-music-function (parser location music) (ly:music?) - (context-spec-music (music-filter event-filter music) 'PseudoVoice)) + (context-spec-music (music-filter event-filter (unpitch music)) 'PseudoVoice)) -showAnyway = +pl = +#(define-music-function (parser location one two) (ly:music? ly:music?) +#{ << { \voiceTwo $one } \\ { \voiceOne $two } >> #}) + +%%% Piano implementation + +showAnyway = %not needed #(define-music-function (parser location music) (ly:music?) #{ \unset Score.keepAliveInterfaces @@ -68,30 +85,28 @@ showAnyway = percent-repeat-interface stanza-number-interface) #}) -md = { \change Staff = "md" } - -mg = { \change Staff = "mg" } - PianoDeuxMains= #(define-music-function (parser location droite gauche) (ly:music? ly:music?) #{ \new PianoStaff << - \new Staff = "md" \with { \remove Accidental_engraver } + \new Staff = "md" << - \new Voice \with { \consists Accidental_engraver } { \clef treble $droite } + \new Voice { \clef treble $droite } \new Voice { \makeGhost $gauche } >> - \new Staff = "mg" \with { \remove Accidental_engraver } + \new Staff = "mg" << - \new Voice \with { \consists Accidental_engraver } { \clef bass $gauche } + \new Voice { \clef bass $gauche } \new Voice { \makeGhost $droite } >> >> #}) -droite = { \change Staff = "percuDroite" } +md = { \change Staff = "md" } -gauche = { \change Staff = "percuGauche" } +mg = { \change Staff = "mg" } + +%%% The same, for percussions. PercuDeuxMains= #(define-music-function (parser location droite gauche) (ly:music? ly:music?) @@ -110,6 +125,14 @@ PercuDeuxMains= >> #}) +droite = { \change Staff = "percuDroite" } + +gauche = { \change Staff = "percuGauche" } + +plperc = +#(define-music-function (parser location one two) (ly:music? ly:music?) +#{ << { \stemDown $one \stemNeutral } \new DrumVoice { \stemUp $two } >> #}) + %% Music formatting -----------------------------------------------% -- 2.11.4.GIT