Re: function to force accidentals on a subset of notes
This is what happens for me too. I think it has something to do with all the other functions I am using. Oct 30, 2023, 21:25 by l...@gmx.de: > > Hi Michael, > > Am 30.10.23 um 10:42 schrieb Michael Winter: > >> But I am confused about what you said. For me, it is posting the >> accidental on tied notes after line breaks. >> > > No I'm confused. :-) If I do > > > > \transpose a c' \relative > { > a8 gis~ gis g fis g gis a > gis1~ \break gis2 gis > } > > > > in my example file, I get: > > > > > > (To wit, no natural sign on the first b in measure 3). > > > Is this different for you? > > > Lukas > >
Re: function to force accidentals on a subset of notes
Hi Michael, Am 30.10.23 um 10:42 schrieb Michael Winter: But I am confused about what you said. For me, it is posting the accidental on tied notes after line breaks. No I'm confused. :-) If I do \transpose a c' \relative { a8 gis~ gis g fis g gis a gis1~ \break gis2 gis } in my example file, I get: (To wit, no natural sign on the first b in measure 3). Is this different for you? Lukas
Re: function to force accidentals on a subset of notes
Thanks! This seems to work quite well : ) But I am confused about what you said. For me, it is posting the accidental on tied notes after line breaks. Best, Michael Oct 28, 2023, 22:40 by l...@gmx.de: > Hi Michael, > >> Thanks Lukas! >> >> This works but also forces the accidental on tied notes. >> > > Sorry for not getting back to you sooner. > > The following version registers ties and removes our auto-generated > accidentals for notes in which a tie ends. (It's a bit overeager and also > removes tied accidentals after line breaks, so we get a behaviour as if > Accidental.hide-tied-accidental-after-break is set to ##t. Please give word > if you want me to change that.) > > Lukas > > \version "2.24.0" > > forced-accidentals-pitches = > #(music-pitches #{ bes b #}) > > #(define (diatonic-pitch-class= p q) > (and (= (ly:pitch-notename p) (ly:pitch-notename q)) > (= (ly:pitch-alteration p) (ly:pitch-alteration q > > Force_accidentals_engraver = > #(lambda (context) > (let > ((ties '()) > (affected-note-events '())) > (make-engraver > (end-acknowledgers > ((tie-interface engraver grob source-engraver) > (set! ties (cons grob ties > ((stop-translation-timestep engraver) > (for-each > (lambda (tie) > (let* ((right-notehead (ly:spanner-bound tie RIGHT)) > (right-notehead-cause (ly:grob-property right-notehead > 'cause))) > (if (member right-notehead-cause affected-note-events) > (ly:grob-suicide! > ;;; the accidental grob should be guaranteed to > ;;; exist since we forced it into existence... > (ly:grob-object > right-notehead 'accidental-grob) > ties) > (set! ties '()) > (set! affected-note-events '())) > (listeners > ((note-event engraver event) > (when (member (ly:event-property event 'pitch) > forced-accidentals-pitches > diatonic-pitch-class=) > (ly:event-set-property! event 'force-accidental #t) > (set! affected-note-events > (cons event affected-note-events > > \layout { > \context { > \Voice > \consists #Force_accidentals_engraver > } > } > > \transpose a c' \relative > { > a8 gis~ gis g fis g gis a > gis1~ gis2 gis > } >
Re: function to force accidentals on a subset of notes
Hi Michael, Thanks Lukas! This works but also forces the accidental on tied notes. Sorry for not getting back to you sooner. The following version registers ties and removes our auto-generated accidentals for notes in which a tie ends. (It's a bit overeager and also removes tied accidentals after line breaks, so we get a behaviour as if Accidental.hide-tied-accidental-after-break is set to ##t. Please give word if you want me to change that.) Lukas \version "2.24.0" forced-accidentals-pitches = #(music-pitches #{ bes b #}) #(define (diatonic-pitch-class= p q) (and (= (ly:pitch-notename p) (ly:pitch-notename q)) (= (ly:pitch-alteration p) (ly:pitch-alteration q Force_accidentals_engraver = #(lambda (context) (let ((ties '()) (affected-note-events '())) (make-engraver (end-acknowledgers ((tie-interface engraver grob source-engraver) (set! ties (cons grob ties ((stop-translation-timestep engraver) (for-each (lambda (tie) (let* ((right-notehead (ly:spanner-bound tie RIGHT)) (right-notehead-cause (ly:grob-property right-notehead 'cause))) (if (member right-notehead-cause affected-note-events) (ly:grob-suicide! ;;; the accidental grob should be guaranteed to ;;; exist since we forced it into existence... (ly:grob-object right-notehead 'accidental-grob) ties) (set! ties '()) (set! affected-note-events '())) (listeners ((note-event engraver event) (when (member (ly:event-property event 'pitch) forced-accidentals-pitches diatonic-pitch-class=) (ly:event-set-property! event 'force-accidental #t) (set! affected-note-events (cons event affected-note-events \layout { \context { \Voice \consists #Force_accidentals_engraver } } \transpose a c' \relative { a8 gis~ gis g fis g gis a gis1~ gis2 gis }
Re: function to force accidentals on a subset of notes
Thanks Lukas! This works but also forces the accidental on tied notes. Best, Michael Oct 22, 2023, 10:19 by l...@gmx.de: > > Hi Michael, > > > this is easily accomplished with an custom engraver. (I perfectly > understand that the terms "easily" and "custom engraver" don't seem to > go well together at first - I thought so for many years as well -, but > after some getting used to it, the concept is actually quite simple and > elegant.) > > > > \version "2.24.0" > > forced-accidentals-pitches = > #(music-pitches #{ bes b #}) > > #(define (diatonic-pitch-class= p q) > (and (= (ly:pitch-notename p) (ly:pitch-notename q)) > (= (ly:pitch-alteration p) (ly:pitch-alteration q > > Force_accidentals_engraver = > #(lambda (context) > (make-engraver > (listeners > ((note-event engraver event) > (if (member (ly:event-property event 'pitch) > forced-accidentals-pitches > diatonic-pitch-class=) > (ly:event-set-property! event 'force-accidental #t)) > > \layout { > \context { > \Voice > \consists #Force_accidentals_engraver > } > } > > \transpose a c' \relative > { > a8 gis g fis g gis a4 > } > > > > Lukas > > Am 21.10.23 um 11:37 schrieb Michael Winter via LilyPond user discussion: > >> Thanks Jean, >> >> I am not sure I completely follow. >> >> Lets say I have a music sequence: >> >> a b c d e f g a bes c d e f g ... >> >> How do I apply what you have written as a functionto only show the >> flats and naturals for b and bes. Again. I donot want to apply this >> to individual notes. >> >> Sorry if I am missing something. >> >> Best, >> >> Michael >> >> >> Oct 21, 2023, 01:37 by >> j...@abou-samra.fr>> : >> >>> >>> Try >>> >>> \displayMusic c'! >>> >>> This shows you that the >>> !>>> syntax corresponds to setting >>> the >>> force-accidental>>> property to true. Thus, if you >>> have identified the note events you want to force accidentals >>> on, you can do >>> >>> (ly:music-set-property! the-note-event 'force-accidental #t) >>> >>> on each of them. >>> >>> >>> Best, >>> >>> >>> Jean >>> >>> >> >>
Re: function to force accidentals on a subset of notes
Hi Michael, this is easily accomplished with an custom engraver. (I perfectly understand that the terms "easily" and "custom engraver" don't seem to go well together at first - I thought so for many years as well -, but after some getting used to it, the concept is actually quite simple and elegant.) \version "2.24.0" forced-accidentals-pitches = #(music-pitches #{ bes b #}) #(define (diatonic-pitch-class= p q) (and (= (ly:pitch-notename p) (ly:pitch-notename q)) (= (ly:pitch-alteration p) (ly:pitch-alteration q Force_accidentals_engraver = #(lambda (context) (make-engraver (listeners ((note-event engraver event) (if (member (ly:event-property event 'pitch) forced-accidentals-pitches diatonic-pitch-class=) (ly:event-set-property! event 'force-accidental #t)) \layout { \context { \Voice \consists #Force_accidentals_engraver } } \transpose a c' \relative { a8 gis g fis g gis a4 } Lukas Am 21.10.23 um 11:37 schrieb Michael Winter via LilyPond user discussion: Thanks Jean, I am not sure I completely follow. Lets say I have a music sequence: a b c d e f g a bes c d e f g ... How do I apply what you have written as a function to only show the flats and naturals for b and bes. Again. I do not want to apply this to individual notes. Sorry if I am missing something. Best, Michael Oct 21, 2023, 01:37 by j...@abou-samra.fr: Try |\displayMusic c'! | This shows you that the |!| syntax corresponds to setting the |force-accidental| property to true. Thus, if you have identified the note events you want to force accidentals on, you can do |(ly:music-set-property! the-note-event 'force-accidental #t) | on each of them. Best, Jean
Re: function to force accidentals on a subset of notes
Thanks Jean, I am not sure I completely follow. Lets say I have a music sequence: a b c d e f g a bes c d e f g ... How do I apply what you have written as a function to only show the flats and naturals for b and bes. Again. I do not want to apply this to individual notes. Sorry if I am missing something. Best, Michael Oct 21, 2023, 01:37 by j...@abou-samra.fr: > > Try > > \displayMusic c'! > > This shows you that the > !> syntax corresponds to settingthe > > force-accidental> property to true. Thus, if you haveidentified the note > events you want to force accidentalson, you can do > > (ly:music-set-property! the-note-event 'force-accidental #t) > > on each of them. > > > Best, > > > Jean > >
Re: function to force accidentals on a subset of notes
Try ``` \displayMusic c'! ``` This shows you that the `!` syntax corresponds to setting the `force-accidental` property to true. Thus, if you have identified the note events you want to force accidentals on, you can do ``` (ly:music-set-property! the-note-event 'force-accidental #t) ``` on each of them. Best, Jean signature.asc Description: This is a digitally signed message part
function to force accidentals on a subset of notes
I have a piece that is in the following scale: c d e fis g aes bes b Is it possible to force the accidentals just for the bes and the b? But here is the catch... I am both transposing the part and respelling pitch-classes as show below. The scale above is actually the resulting printed set of notes. The music is already generated and I would not want to have to do this manually for each occurance. Thanks in advance, Michael transposePitchClasses = #(define-music-function (scaleA scaleB music) (ly:music? ly:music? ly:music?) (let* ((scaleA (ly:music-property scaleA 'elements)) (scaleB (ly:music-property scaleB 'elements)) (scaleA (map (lambda (x) (ly:music-property x 'pitch)) scaleA)) (scaleB (map (lambda (x) (ly:music-property x 'pitch)) scaleB)) (classesA (map (lambda (p) (cons (ly:pitch-notename p) (ly:pitch-alteration p))) scaleA))) (map-some-music (lambda (m) (let ((p (ly:music-property m 'pitch))) (if (not (null? p)) (let* ((nn (ly:pitch-notename p)) (oct (ly:pitch-octave p)) (alt (ly:pitch-alteration p)) (pos (list-index (lambda (x) (and (= (car x) nn) (= (cdr x) alt))) classesA))) (if pos (let* ((p2 (list-ref scaleA pos)) (oct2 (ly:pitch-octave p2)) (p3 (list-ref scaleB pos)) (new-pitch (ly:pitch-transpose p3 (ly:make-pitch (- oct oct2) 0 (ly:music-set-property! m 'pitch new-pitch))) m) #f))) music) music)) \new Staff \with { instrumentName = #"synth I (2)" shortInstrumentName = #"synI" \remove "Time_signature_engraver" } << \transpose a c' \transposePitchClasses {a b cis dih e fih geh gis} {a b cis dis e f g gis} \include "includes/ammann_part_6.ly" %this is the music >>