lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Will my scheme function work have unintended consequences? Adding st


From: Peter Engelbert
Subject: Re: Will my scheme function work have unintended consequences? Adding staccatos to notes.
Date: Fri, 14 Sep 2018 22:05:42 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

My apologies for the rookie mistake of initially responding indiviually rather 
than to the list.  I have posted this to the list in case you have any more 
insights you want to share and so that others can learn from your response.  I 
have a few more questions, below--I tend toward wanting complete understanding 
of how things work, so I hope you will humor me.

On Fri, Sep 14, 2018 at 11:18:11PM +0200, David Kastrup wrote:
> Peter Engelbert <address@hidden> writes:
> 
> > Here is the MWE I've used to test it:
> >
> > =====test.ly=======
> > \version "2.19.82"
> > \include "addStaccatos.ly"
> >
> > { c4 \addStaccatos { c4 c4 c4 | c4^> } }
> > ===================
> >
> > I am just checking, with more experienced eyes, whether or not this
> > function will work in all cases.
> 
> No.

Thank you -- I appreciate your help.  I have found learning scheme to be quite 
difficult compared to other languages I've learned, and even after learning a 
great deal I am struggling with the lilypond-specific aspects of it.

I am wondering if you might be able to supply me with a test case where my 
function will not work as intended?  It will help me a lot as I continue to 
learn, and it will also help me understand why your function works and mine 
doesn't.

> 
> > It seems to work in my minimal example, but I really don't know very
> > much about how scheme represents music, so I'm concerned that there
> > might be some cases where this will not work.
> 
> Music can be structured in a large number of ways.
> 

Any advice as to how I might deepen my understanding of how music is 
represented by scheme?  I have read the small amount on the topic in the 
lilypond 'extending' manual, but I am having trouble finding any resources 
beyond that.

> > Also, I tried a few earlier attempts at this before getting it to
> > work, one of them used the MUSIC-MAP function.  What does MUSIC-MAP
> > do,
> 
> Apply to all contained music.  Not what you want here.
> 
> > and how does it differ from the standard MAP?
> 
> It descends into music rather than a list.  And at all levels.
> 

By 'at all levels', I am assuming you mean the varying structural levels of the 
complext lists that comprise Scheme's representation of music?  How might those 
various levels be understood?

> > And most importantly, what is its proper syntax? I looked it up in the
> > .scm file where it's defined, but it's a bit beyond me at the moment.
> 
> I think this is rather a case for map-some-music where you can stop the
> recursion at appropriate levels.
> 

How do map-some-music and music-map differ? Is it not possible to stop the 
recursion with music-map? When would it be appropriate to actually use 
music-map?

> \version "2.19.82"
> 
> #(define (add-staccato event prop)
>    (set! (ly:music-property event prop)
>        (append
>         (ly:music-property event prop)
>         (list
>          (make-music 'ArticulationEvent 'articulation-type "staccato"))))
>    event)
> 

Is there a large difference between using append vs cons here? Just curious.

> addStaccatos =
> #(define-music-function (music) (ly:music?)
>    (define note? (music-type-predicate 'note-event))
>    (define chord? (music-type-predicate 'event-chord))
>    (define rhythmic-event? (music-type-predicate 'rhythmic-event))

I gather that you are defining various predicates for convenience in this 
function.

>    (map-some-music
>     (lambda (m)
>       (cond ((note? m) (add-staccato m 'articulations))

If we are encountering a note, then add staccato, I understand so far.

>           ((chord? m)
>            (if (or (any note? (ly:music-property m 'elements))
>                    (ly:duration? (ly:music-property m 'duration)))
>                (add-staccato m 'elements)
>                m))

If it's a chord we're encountering, and there are either a. any notes in the 
'elements list or b. the chord has a proper duration, then add staccato to the 
'elements list (and not to the 'articulations list).

I am assuming this has to do with how chords are represented in scheme, since 
the chord as a whole possesses a staccato marking, not the individual notes.

>           ((rhythmic-event? m) m)

If we encounter a rhythmic event, which is neither a not nor a chord, leave it 
alone.

>           (else #f)))

Otherwise, we have encountered something other than a note, chord, or rhythmic 
event.  But why return false here?

> 
> Note that recursion is stopped at rhythmic events, single note events
> get staccato added (at their end) in 'articulations, chords containing
> note events (or being a repeat chord, notable by having a duration) also
> get a staccato.  There are a number of code remnants using event-chord
> as a useless wrapper for non-chords, so I don't just embellish chords
> unconditionally here.  Most of the time, you should be fine just
> checking for event-chord.  But you asked about a general robust
> solution, so...
> 
> -- 
> David Kastrup

I missed this paragraph the first time around -- thank you very much.  This is 
very specific and helpful. I now understand that returning false is a way to 
stop the rrecursion of map-some-music.

Once again, thank you for responding and for your help.  Like I said, I find 
this difficult and I think the best way for me to learn is to ask detailed 
questions to the experts on this list.  Be well, and have a good weekend!

Peter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]