Re: Scheme function to affect a compound music expression?
2014-10-24 23:01 GMT+02:00 Peter Crighton petecrigh...@gmail.com: 2014-10-24 16:54 GMT+02:00 Robin Bannister r...@dataway.ch: So it looks like LilyPond wants to merge the rests, but will do this only if they seem identical. Having read through the regression snippet and been inspired by the way it removes things, we can modify bgr to make it remove rests: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (music-is-of-type? mus 'rest-event) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) Note A: found 'rest-event in the Internals Reference Note B: renamed your parameter to not imply just note Hope this helps. Thanks again, Robin, this helps a lot! The next time I dive into Scheming I might be getting further by myself before I have to ask on the list. :) Nope, I didn’t really and have to ask again, sorry … I now wanted to improve the function to also skip MultiMeasureRests and first tried replacing 'rest-event with 'multi-measure-rest-event to see if that would work, which it doesn’t. I searched a lot for other examples where something similar might appear, but I couldn’t find anything, so I’m (again) rather clueless. Do I need to replace something else? Do MultiMeasureRests require another approach? Or is it not possible with them? -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Hi Peter, On Sat, Oct 25, 2014 at 10:41 AM, Peter Crighton petecrigh...@gmail.com wrote: 2014-10-24 23:01 GMT+02:00 Peter Crighton petecrigh...@gmail.com: 2014-10-24 16:54 GMT+02:00 Robin Bannister r...@dataway.ch: So it looks like LilyPond wants to merge the rests, but will do this only if they seem identical. Having read through the regression snippet and been inspired by the way it removes things, we can modify bgr to make it remove rests: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (music-is-of-type? mus 'rest-event) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) Note A: found 'rest-event in the Internals Reference Note B: renamed your parameter to not imply just note Hope this helps. Thanks again, Robin, this helps a lot! The next time I dive into Scheming I might be getting further by myself before I have to ask on the list. :) Nope, I didn’t really and have to ask again, sorry … I now wanted to improve the function to also skip MultiMeasureRests and first tried replacing 'rest-event with 'multi-measure-rest-event to see if that would work, which it doesn’t. Yes, this was a stumbling block for me too recently. It doesn't seem that you can use 'multi-measure-rest-event with music-is-of-type? This approach will work, though: \version 2.19.15 bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (or (music-is-of-type? mus 'rest-event) (eq? (ly:music-property mus 'name) 'MultiMeasureRestMusic)) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) \new Voice \relative c' { c4 d r f R1 c4 d r f } \relative c' \bgr { e4 f r a R1 e4 f r a } %%% --David ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
2014-10-25 17:51 GMT+02:00 David Nalesnik david.nales...@gmail.com: Hi Peter, On Sat, Oct 25, 2014 at 10:41 AM, Peter Crighton petecrigh...@gmail.com wrote: I now wanted to improve the function to also skip MultiMeasureRests and first tried replacing 'rest-event with 'multi-measure-rest-event to see if that would work, which it doesn’t. Yes, this was a stumbling block for me too recently. It doesn't seem that you can use 'multi-measure-rest-event with music-is-of-type? This approach will work, though: \version 2.19.15 bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (or (music-is-of-type? mus 'rest-event) (eq? (ly:music-property mus 'name) 'MultiMeasureRestMusic)) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) \new Voice \relative c' { c4 d r f R1 c4 d r f } \relative c' \bgr { e4 f r a R1 e4 f r a } Thanks, David, that indeed does the trick! -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
On Sat, Oct 25, 2014 at 11:01 AM, Peter Crighton petecrigh...@gmail.com wrote: Thanks, David, that indeed does the trick! I'm curious--what example was Robin's suggestion not working for? Removing the check for 'MultiMeasureRestEvent works fine for me with multi-measure rests. --David ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Hi again, Peter-- On Sat, Oct 25, 2014 at 11:01 AM, Peter Crighton petecrigh...@gmail.com wrote: 2014-10-25 17:51 GMT+02:00 David Nalesnik david.nales...@gmail.com: Hi Peter, On Sat, Oct 25, 2014 at 10:41 AM, Peter Crighton petecrigh...@gmail.com wrote: I now wanted to improve the function to also skip MultiMeasureRests and first tried replacing 'rest-event with 'multi-measure-rest-event to see if that would work, which it doesn’t. Yes, this was a stumbling block for me too recently. It doesn't seem that you can use 'multi-measure-rest-event with music-is-of-type? Turns out that you can use music-is-of-type? to get what you want. See: http://lilypond.org/doc/v2.18/Documentation/internals/multimeasurerestmusic for the list of types of MultiMeasureRestMusic. So you can use the following: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (or (music-is-of-type? mus 'rest-event) (music-is-of-type? mus 'multi-measure-rest)) %%% --David ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Peter Crighton wrote: But I would like to be able to use the function [...] so it doesn’t only affect the next note, but a sequence of notes enclosed in { … }: The source file music-functions.scm defines music-map which you can use for this: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (note) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #note #}) music )) There is an advanced example in the regression tests: http://www.lilypond.org/doc/v2.18/input/regression/collated-files.html#music-map.ly Cheers, Robin ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
2014-10-24 11:05 GMT+02:00 Robin Bannister r...@dataway.ch: Peter Crighton wrote: But I would like to be able to use the function [...] so it doesn’t only affect the next note, but a sequence of notes enclosed in { … }: The source file music-functions.scm defines music-map which you can use for this: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (note) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #note #}) music )) There is an advanced example in the regression tests: http://www.lilypond.org/doc/v2.18/input/regression/ collated-files.html#music-map.ly Thanks a lot, Robin! I wouldn’t have thought it would be this easy … But maybe this could be better documented? I never would have thought of looking for it in the regression tests (in fact I didn’t even know about them). Are there other places to learn about Scheme in LilyPond than the Scheme tutorial? -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
2014-10-24 13:57 GMT+02:00 Peter Crighton petecrigh...@gmail.com: 2014-10-24 11:05 GMT+02:00 Robin Bannister r...@dataway.ch: The source file music-functions.scm defines music-map which you can use for this: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (note) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #note #}) music )) There is an advanced example in the regression tests: http://www.lilypond.org/doc/v2.18/input/regression/ collated-files.html#music-map.ly Thanks a lot, Robin! I wouldn’t have thought it would be this easy … Although I now came upon the following situation with rests: \version 2.19.13 bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (note) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #note #}) music)) \new Voice \relative c' { c4 d r f } \relative c' \bgr { e4 f r a } I get these warnings: /home/peter/bgr.ly:21:16: warning: Two simultaneous rest events, junking this one \relative c' \bgr { /home/peter/bgr.ly:18:10: warning: Previous rest event here c4 d r f Although it doesn’t seem to affect the output, it is still not desired behaviour, and I don’t know why the \bgr function causes it. Any ideas? But maybe this could be better documented? I never would have thought of looking for it in the regression tests (in fact I didn’t even know about them). Are there other places to learn about Scheme in LilyPond than the Scheme tutorial? -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Peter Crighton wrote: I don’t know why the \bgr function causes it. Any ideas? ... Are there other places to learn about Scheme in LilyPond than the Scheme tutorial? Welcome to Scheme in LilyPond. This example shows that knowing Scheme isn't enough. You have to cooperate with Lilypond, and to do that successfully you have to know how Lilypond does things (under the hood). So read the whole LilyPond source code before you start! Or maybe you can just peek at the seemingly relevant bits. A more workable approach is to modify similar snippets. How about a black box approach here? You got a nice warning - very explicit, with location info. Try simpler cases: \new Voice { c4 d r f } { e4 f r a } doesn't complain, but \new Voice { c4 d r f } { e4 f \tweak color #black r a } does complain. \new Voice { c4 d e f } { e4 f e a } shows both noteheads and doesn't complain, and \new Voice { c4 d e f } { e4 f \tweak color #black e a } also shows both noteheads and doesn't complain. So it looks like LilyPond wants to merge the rests, but will do this only if they seem identical. Having read through the regression snippet and been inspired by the way it removes things, we can modify bgr to make it remove rests: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (music-is-of-type? mus 'rest-event) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) Note A: found 'rest-event in the Internals Reference Note B: renamed your parameter to not imply just note Hope this helps. Cheers, Robin ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
2014-10-24 16:54 GMT+02:00 Robin Bannister r...@dataway.ch: So it looks like LilyPond wants to merge the rests, but will do this only if they seem identical. Having read through the regression snippet and been inspired by the way it removes things, we can modify bgr to make it remove rests: bgr = #(define-music-function (parser location music) (ly:music?) (music-map (lambda (mus) (if (music-is-of-type? mus 'rest-event) (make-music 'SkipEvent mus) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #mus #})) music )) Note A: found 'rest-event in the Internals Reference Note B: renamed your parameter to not imply just note Hope this helps. Thanks again, Robin, this helps a lot! The next time I dive into Scheming I might be getting further by myself before I have to ask on the list. :) -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Robin Bannister wrote A more workable approach is to modify similar snippets. Maybe this is a good example of music-map to add to the LSR? http://lsr.di.unimi.it/LSR/Search Cheers, -Paul -- View this message in context: http://lilypond.1069038.n5.nabble.com/Scheme-function-to-affect-a-compound-music-expression-tp167817p167884.html Sent from the User mailing list archive at Nabble.com. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Scheme function to affect a compound music expression?
Hello all, I tried to write such a function, but failed at the point you’ll see in the attachment. I’d like to learn how this can be made to work ;-) … The problem is in extracting the list from SequentialMusic’s 'element property. And I suspect it has to do with the following question: With display-music I can obtain: #Prob: Music C++: Music((duration . #Duration 4 ) (pitch . #Pitch e ) (origin . #location c:/users/simon/appdata/local/temp/frescobaldi-_4tllv/tmpdndxnp/bgr.ly:25:10))((display-methods #procedure #f (note parser)) (name . NoteEvent) (iterator-ctor . #primitive-procedure ly:rhythmic-music-iterator::constructor) (types general-music event note-event rhythmic-event melodic-event)) : { ((duration . #Duration 4 ) (pitch . #Pitch e ) (origin . #location c:/users/simon/appdata/local/temp/frescobaldi-_4tllv/tmpdndxnp/bgr.ly:25:10)) } and with display-scheme-music: (make-music 'NoteEvent 'duration (ly:make-duration 2) 'pitch (ly:make-pitch -1 2)) What kind of syntax is the first one? And how can I compute one from the other? Grateful as always for help and with best regards, Simon Am 23.10.2014 um 14:05 schrieb Peter Crighton: Hello all, I’m taking my very first little steps into Scheme right now by trying to write a function that can make single note heads (and accidentals) in a chord smaller (to differentiate background vocals from lead vocal when writing them all in one voice). What I have so far is: bgr = #(define-music-function (parser location note) (ly:music?) #{ \tweak NoteHead.font-size #-2 \tweak Accidental.font-size #-2 #note #}) or bgr = #(define-music-function (parser location note) (ly:music?) (set! (ly:music-property note 'tweaks) (cons (cons (cons (quote NoteHead) (quote font-size)) -2) (ly:music-property note 'tweaks))) (set! (ly:music-property note 'tweaks) (cons (cons (cons (quote Accidental) (quote font-size)) -2) (ly:music-property note 'tweaks))) note) which should be the same. Here is an example that uses it: \new Voice \relative c' { c4 d e f } \relative c' { \bgr e4 \bgr f \bgr g \bgr a } But I would like to be able to use the function as follows, so it doesn’t only affect the next note, but a sequence of notes enclosed in { … }: \new Voice \relative c' { c4 d e f } \relative c' { \bgr { e4 f g a } } Can somebody point me in the right direction how to do this? -- Peter Crighton | Musician Music Engraver based in Mainz, Germany http://www.petercrighton.de ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user \version 2.19.12 bgr = #(define-music-function (parser location mus) (ly:music?) ; for testing only ;(display-scheme-music mus) ;mus (map (lambda (note) (set! (ly:music-property note 'tweaks) (list (cons (cons (quote Accidental) (quote font-size)) -2) (cons (cons (quote NoteHead) (quote font-size)) -2 (ly:music-property mus 'elements))) \new Voice \relative c' { c4 d e f } \relative c' { \bgr e4 \bgr f \bgr g \bgr a } \new Voice \relative c' { c4 d e f } \relative c' { \bgr { e4 f g a } } ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user