Re: Help with music function
Many thanks, Aaron. A clear and helpful answer! The “why” was simply an exercise in seeing if I could cleanup a LP file by using such syntactic sugar (to which the answer is no :-) ). Thanks again ..m. > On 19 Dec 2023, at 07:05, Aaron Hill wrote: > > On 2023-12-17 9:33 pm, Mark Probert wrote: >> Hi. >> I'm struggling some with writing a music function for rests. Basically I >> want to be able to write something like >> \rel-rest( b', 1) > > Minor nit: Functions in LilyPond do not use parentheses and commas for > arguments in this way. You need only say something like the following to > invoke your function: > > > \rel-rest b' 1 > > >> which would place a dotted quarter rest on the indicated pitch (the >> equivalent of >> b'1\rest >> I'm starting with >> rel-rest = >> #(define-music-function (pit dur) (ly:pitch? ly:duration?) >> #{ >>#pit#dur\rest >> #}) >> but that gives me an error. >> Any suggestions? > > There are a few things the errors in the output log should be communicating. > >> Unbound variable: #{pit\#dur\\rest}# > > Firstly, whitespace is important in Scheme. Jamming together #pit#dur\rest > gives the parser little hope to understand what you mean. It thinks this > refers to a singular named thing, which in this context does not exist. > > So, give each part of that expression some room to breathe: > > > #pit #dur \rest > > > But then LilyPond is not satisfied that this represents a valid music > expression. When using variables, often the number sign (#) is correct, > however there are some spots when you need to use the dollar sign ($) instead. > > > $pit $dur \rest > > > Lastly, I am not sure why using the duration "1" as you indicated would > result in a dotted quarter rest. Did you mean "4." or is the point of the > music function to manipulate the inputs in some way? I am not sure I see the > connection/logic there, so you are going to be a bit on your own there. > > But with the modification indicated above, you can now do this: > > > { \rel-rest b' 4. } > > %% ...or even... > > { \rel-rest b'4. } > > > However, this feels like more typing than just using the \rest post-event, > apart from being prefixed. > > > -- Aaron Hill
Re: Help with music function
Dear Mark, I did this in a slightly different way...if you do \displayMusic c4\rest you can see how to represent a rest using the make-music procedure in scheme code. Modifying that a bit, I got % \version "2.25.6" %\displayMusic c4\rest = %(make-music %'RestEvent %'duration %(ly:make-duration 2) %'pitch %(ly:make-pitch -1 0)) restt = #(define-music-function (pit dur) (ly:pitch? ly:duration?) (make-music 'RestEvent 'duration dur 'pitch pit) ) \relative c' { \restt c 4 \restt e 4 \restt g 4 \restt c 4 \restt b 2 \restt a 2 \restt g 2. \restt g 4 } % -William On 12/18/23 00:33, Mark Probert wrote: Hi. I'm struggling some with writing a music function for rests. Basically I want to be able to write something like \rel-rest( b', 1) which would place a dotted quarter rest on the indicated pitch (the equivalent of b'1\rest I'm starting with rel-rest = #(define-music-function (pit dur) (ly:pitch? ly:duration?) #{ #pit#dur\rest #}) but that gives me an error. Any suggestions? -- -- -mark. -- William Rehwinkel - Oberlin College and Conservatory '24 will...@williamrehwinkel.net PGP key: https://ftp.williamrehwinkel.net/pubkey.txt OpenPGP_signature.asc Description: OpenPGP digital signature
Re: Help with music function
On 2023-12-17 9:33 pm, Mark Probert wrote: Hi. I'm struggling some with writing a music function for rests. Basically I want to be able to write something like \rel-rest( b', 1) Minor nit: Functions in LilyPond do not use parentheses and commas for arguments in this way. You need only say something like the following to invoke your function: \rel-rest b' 1 which would place a dotted quarter rest on the indicated pitch (the equivalent of b'1\rest I'm starting with rel-rest = #(define-music-function (pit dur) (ly:pitch? ly:duration?) #{ #pit#dur\rest #}) but that gives me an error. Any suggestions? There are a few things the errors in the output log should be communicating. Unbound variable: #{pit\#dur\\rest}# Firstly, whitespace is important in Scheme. Jamming together #pit#dur\rest gives the parser little hope to understand what you mean. It thinks this refers to a singular named thing, which in this context does not exist. So, give each part of that expression some room to breathe: #pit #dur \rest But then LilyPond is not satisfied that this represents a valid music expression. When using variables, often the number sign (#) is correct, however there are some spots when you need to use the dollar sign ($) instead. $pit $dur \rest Lastly, I am not sure why using the duration "1" as you indicated would result in a dotted quarter rest. Did you mean "4." or is the point of the music function to manipulate the inputs in some way? I am not sure I see the connection/logic there, so you are going to be a bit on your own there. But with the modification indicated above, you can now do this: { \rel-rest b' 4. } %% ...or even... { \rel-rest b'4. } However, this feels like more typing than just using the \rest post-event, apart from being prefixed. -- Aaron Hill
Help with music function
Hi. I'm struggling some with writing a music function for rests. Basically I want to be able to write something like \rel-rest( b', 1) which would place a dotted quarter rest on the indicated pitch (the equivalent of b'1\rest I'm starting with rel-rest = #(define-music-function (pit dur) (ly:pitch? ly:duration?) #{ #pit#dur\rest #}) but that gives me an error. Any suggestions? -- -- -mark.
Re: Help with music-function generating music
Am 26.03.2014 22:53, schrieb Paul Morris: Hi Urs, I had a chance to work on the iteration part. This one accepts a note as an argument which is a better approach, following the examples here: http://lilypond.org/doc/v2.18/Documentation/extending/doubling-a-note-with-slurs-_0028example_0029 http://lilypond.org/doc/v2.18/Documentation/extending/adding-articulation-to-notes-_0028example_0029 The iteration is done with a named let (which is just one option) see these docs for Guile and Scheme: https://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Iteration.html https://www.gnu.org/software/guile/manual/guile.html#while-do Cheers, -Paul Thank you very much. Such concrete examples are incredibly helpful. I had already started to fiddle around with yesterday's example and was trying to achieve something similar to your new example. But I didn't come to an end (Scheme gives you soo many opportunities to do something wrong ...), so I can now investigate your example with some pre-knowledge. I hope (but honestly doubt) to find the time to pour these experiences in a tutorial (series), as I think that this step is a hard one for many people, and the respective documentation is really hard to grasp. Urs \version 2.18.0 myNotes = #(define-music-function (parser location note num) (ly:music? number?) Returns a series of notes. @var{note} is repeated @var{num} times. @var{note} is supposed to be a single note. ;; iteration by named let (let loop ;; two variables/arguments, ;; i is the iteration count ;; nts is the list of notes we're building ((i 0) (nts '())) ;; conditional (cond (( i num) ;; call the loop again with modified values for i and nts (loop (+ i 1) (append nts (list (ly:music-deep-copy note) (else ;; when done, return the music (make-music 'SequentialMusic 'elements nts) { \myNotes g'16 #8 } -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160867.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 ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help with music-function generating music
Urs Liska u...@openlilylib.org writes: \version 2.18.0 myNotes = #(define-music-function (parser location note num) (ly:music? number?) Returns a series of notes. @var{note} is repeated @var{num} times. @var{note} is supposed to be a single note. ;; iteration by named let (let loop ;; two variables/arguments, ;; i is the iteration count ;; nts is the list of notes we're building ((i 0) (nts '())) ;; conditional (cond (( i num) ;; call the loop again with modified values for i and nts (loop (+ i 1) (append nts (list (ly:music-deep-copy note) (else ;; when done, return the music (make-music 'SequentialMusic 'elements nts) In this case, it is likely easier to replace the named let with (make-sequential-music (ly:music-deep-copy (make-list num note))) Which is a bit of a dead end for further manipulation which one would likely do with map or similar on the list returned by ly:music-deep-copy. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help with music-function generating music
David Kastrup wrote In this case, it is likely easier to replace the named let with (make-sequential-music (ly:music-deep-copy (make-list num note))) Which is a bit of a dead end for further manipulation which one would likely do with map or similar on the list returned by ly:music-deep-copy. Thanks! That does look like a better approach. -Paul -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160879.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
Help with music-function generating music
Hi all, I'm completely at a loss and need to get some help and pushes in the right direction. I'm for the first time trying to write a music function that actually gerenates music events on its own, i.e. that doesn't use #{ #} to output music. The sections in the Scheme tutorial in the Extending Manual don't really help me, and trying to understand http://lsr.di.unimi.it/LSR/Snippet?id=566 which seems to be quite related to what I want is equally over my head. Therefore I'd be happy if someone could give me a (commented?) example of at least the first steps of what I try. From there I'd be able to go forward or ask more concrete questions. The initial thing my function should do is: - take a pitch and a number - repeat that pitch for the given number of times - beam the whole group - make that in a loop that allows me to apply a new override for each note I think that should be very basic, and it's actually quite far from what I want to achieve, but it should be a good starting point for understanding how it works. Thanks in advance Urs ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help with music-function generating music
Urs Liska wrote I'm completely at a loss and need to get some help and pushes in the right direction. I would start here with \displayMusic http://lilypond.org/doc/v2.18/Documentation/extending/displaying-music-expressions HTH, -Paul -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160857.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: Help with music-function generating music
Am 26.03.2014 16:08, schrieb Paul Morris: Urs Liska wrote I'm completely at a loss and need to get some help and pushes in the right direction. I would start here with \displayMusic http://lilypond.org/doc/v2.18/Documentation/extending/displaying-music-expressions HTH, not too much, I'm afraid. That's where I actually got stuck already. Fortunately there has been significant progress in the other thread (Exact stem length). But apart from a solution for the problem at hand I'll of course want to learn to deal with this myself... Urs -Paul -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160857.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 -- Urs Liska +49(0)179-4642905 u...@beautifulscores.net http://beautifulScores.net ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help with music-function generating music
Ok, here are some next steps. Only dealing with specifying pitch so far. The number of notes and their duration are both still hard-coded... -Paul \version 2.18.0 % use this to see what the end result should look like: % \displayMusic { c'4 d e f } % === % Here it is: { #(make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 2 0 1) 'pitch (ly:make-pitch 0 0 0)) (make-music 'NoteEvent 'pitch (ly:make-pitch -1 1 0) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch -1 2 0) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch -1 3 0) 'duration (ly:make-duration 2 0 1 } % a function that accepts three arguments that are used to determine pitch: % octave note and alteration: makeFourQuarterNotes = #(define-music-function (parser location oct nt alt) (number? number? number?) (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 2 0 1) 'pitch (ly:make-pitch oct nt alt)) (make-music 'NoteEvent 'pitch (ly:make-pitch oct nt alt) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch oct nt alt) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch oct nt alt) 'duration (ly:make-duration 2 0 1) { \makeFourQuarterNotes #1 #1 #0 \makeFourQuarterNotes #1 #2 #0 \makeFourQuarterNotes #0 #1 #-1/2 \makeFourQuarterNotes #0 #2 #1/2 } -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160861.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: Help with music-function generating music
Urs Liska wrote Hi all, I'm completely at a loss and need to get some help and pushes in the right direction. I'm for the first time trying to write a music function that actually gerenates music events on its own, i.e. that doesn't use #{ #} to output music. The sections in the Scheme tutorial in the Extending Manual don't really help me, and trying to understand http://lsr.di.unimi.it/LSR/Snippet?id=566 which seems to be quite related to what I want is equally over my head. Therefore I'd be happy if someone could give me a (commented?) example of at least the first steps of what I try. From there I'd be able to go forward or ask more concrete questions. The initial thing my function should do is: - take a pitch and a number - repeat that pitch for the given number of times - beam the whole group - make that in a loop that allows me to apply a new override for each note I think that should be very basic, and it's actually quite far from what I want to achieve, but it should be a good starting point for understanding how it works. Thanks in advance Urs ___ lilypond-user mailing list lilypond-user@ https://lists.gnu.org/mailman/listinfo/lilypond-user Hi, as Paul Morris pointed out \displayMusic is the best starting point to learn the scheme way of writing music. For example \displayMusic { c8[ c c c] } will show you how to beam a group. Also I don't really get your last point. What kind of override do you want to apply to the notes? Regards, Tao -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160866.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: Help with music-function generating music
Hi Urs, I had a chance to work on the iteration part. This one accepts a note as an argument which is a better approach, following the examples here: http://lilypond.org/doc/v2.18/Documentation/extending/doubling-a-note-with-slurs-_0028example_0029 http://lilypond.org/doc/v2.18/Documentation/extending/adding-articulation-to-notes-_0028example_0029 The iteration is done with a named let (which is just one option) see these docs for Guile and Scheme: https://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Iteration.html https://www.gnu.org/software/guile/manual/guile.html#while-do Cheers, -Paul \version 2.18.0 myNotes = #(define-music-function (parser location note num) (ly:music? number?) Returns a series of notes. @var{note} is repeated @var{num} times. @var{note} is supposed to be a single note. ;; iteration by named let (let loop ;; two variables/arguments, ;; i is the iteration count ;; nts is the list of notes we're building ((i 0) (nts '())) ;; conditional (cond (( i num) ;; call the loop again with modified values for i and nts (loop (+ i 1) (append nts (list (ly:music-deep-copy note) (else ;; when done, return the music (make-music 'SequentialMusic 'elements nts) { \myNotes g'16 #8 } -- View this message in context: http://lilypond.1069038.n5.nabble.com/Help-with-music-function-generating-music-tp160833p160867.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
Help debugging music function
Could someone with knowhow help me to debug this music function? I want a function to create arrows in a Lilypond score: arrow = #(define-music-function (parser location arg1 ) ( pair?) #{ \markup { \line \draw-line #arg1 \arrow-head #X #RIGHT ##t }} #}) When I process: \version 2.16.0 \include header.ly \score { \new Staff { c4_\arrow #'(10 . 0) } } I get output: Ontleden... arrowtest.ly:10:3: fout: music function cannot return (#procedure line-markup (layout props args) ((#procedure draw-line-markup (layout props dest) (10 . 0)) (#procedure arrow-head-markup (layout props axis dir filled) 0 1 #t))) c4_ \arrow #'(10 . 0) Interpreting music... programmeerfout: Not a music type Thanks in advance, Vivian. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help debugging music function
2012/11/5 Vivian Barty-Taylor belast...@vivbt.nl: Could someone with knowhow help me to debug this music function? I want a function to create arrows in a Lilypond score: arrow = #(define-music-function (parser location arg1 ) ( pair?) #{ \markup { \line \draw-line #arg1 \arrow-head #X #RIGHT ##t }} #}) When I process: \version 2.16.0 \include header.ly \score { \new Staff { c4_\arrow #'(10 . 0) } } I get output: Ontleden... arrowtest.ly:10:3: fout: music function cannot return (#procedure line-markup (layout props args) ((#procedure draw-line-markup (layout props dest) (10 . 0)) (#procedure arrow-head-markup (layout props axis dir filled) 0 1 #t))) c4_ \arrow #'(10 . 0) Interpreting music... programmeerfout: Not a music type Thanks in advance, Vivian. ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user Hi, you could try: \version 2.16.0 arrow = #(define-music-function (parser location arg1) ( pair?) (make-music 'TextScriptEvent 'text #{ \markup \line { \draw-line #arg1 \arrow-head #X #RIGHT ##t } #} )) \new Staff { c4-\arrow #'(10 . 0) } But see: http://code.google.com/p/lilypond/issues/detail?id=2949 by David Kastrup (5 minutes ago) Cheers, Harm ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help debugging music function
Vivian Barty-Taylor belast...@vivbt.nl writes: Could someone with knowhow help me to debug this music function? I want a function to create arrows in a Lilypond score: arrow = #(define-music-function (parser location arg1 ) ( pair?) #{ \markup { \line \draw-line #arg1 \arrow-head #X #RIGHT ##t }} #}) A markup is not music, and a music function can only return music. In version 2.17.6, just using define-scheme-function instead of define-music-function should have been enough (apart from needing to match braces better). Turns out that this is not the case, but will be after issue 2949 URL:http://code.google.com/p/lilypond/issues/detail?id=2949 passes. The nicest 2.16 approach would likely be using define-event-function here and writing #{ - \markup ... #} instead of just #{ \markup ... #}. In that case, you can use \arrow _only_ as a text script and not otherwise as text/markup. The traditional approach would rather use define-markup-command (different overall syntax, however), and would require using _\markup \arrow ... for calling this. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help, simple music function not compiling
%% the function that will fail tempoMarkEqual = #(define-music-function (parser location before after) (string? string?) #{ \mark \markup \tiny { \note $before #1 = \note $after #1 } #} ) with a '#' before $before and $after, it works. Thanks a lot ! Can somebody explain why the #s were needed in that case ? ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Help, simple music function not compiling
Hi lilypond helpers, Here is a small program that does not compile: --- \version 2.12.3 %% the function that will fail tempoMarkEqual = #(define-music-function (parser location before after) (string? string?) #{ \mark \markup \tiny { \note $before #1 = \note $after #1 } #} ) %% example begins here { \time 2/4 re'2 | %% this works well \mark \markup \tiny {\note #8 #1 = \note #8 #1 } re'2 | %% this is an attempt to get the same result with a function \tempoMarkEqual #8 #8 re'2 } -- The first \mark command works well, but the function fails with: string:2:30: Error : syntax error, unexpected STRING_IDENTIFIER, expecting SCM_IDENTIFIER or SCM_TOKEN \mark \markup \tiny { \note \lilyvartmpb #1 = \note \lilyvartmpc #1 } What did I miss ? Thanks, Eric ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Help, simple music function not compiling
On 29 January 2011 23:23, Eric Dedieu papa.e...@free.fr wrote: Hi lilypond helpers, Here is a small program that does not compile: --- \version 2.12.3 %% the function that will fail tempoMarkEqual = #(define-music-function (parser location before after) (string? string?) #{ \mark \markup \tiny { \note $before #1 = \note $after #1 } #} ) %% example begins here { \time 2/4 re'2 | %% this works well \mark \markup \tiny {\note #8 #1 = \note #8 #1 } re'2 | %% this is an attempt to get the same result with a function \tempoMarkEqual #8 #8 re'2 } -- The first \mark command works well, but the function fails with: string:2:30: Error : syntax error, unexpected STRING_IDENTIFIER, expecting SCM_IDENTIFIER or SCM_TOKEN \mark \markup \tiny { \note \lilyvartmpb #1 = \note \lilyvartmpc #1 } What did I miss ? Use tempoMarkEqual = #(define-music-function (parser location before after) (string? string?) #{ \mark \markup \tiny { \note #$before #1 = \note #$after #1 } #} ) with a '#' before $before and $after, it works. Par contre pour les explications je passe la main... Cordialement, Xavier -- Xavier Scheuer x.sche...@gmail.com ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user