That's exactly what I was thinking. Thank you David!

And yes, yesterday I found this part of the manual and I start reading it.

Thanks a lot for your help!
g.

On 20 November 2017 at 23:01, David Kastrup <d...@gnu.org> wrote:

> Gianmaria Lari <gianmarial...@gmail.com> writes:
>
> > On 20 November 2017 at 15:18, David Kastrup <d...@gnu.org> wrote:
> >
> >> Gianmaria Lari <gianmarial...@gmail.com> writes:
> >>
> >> > On 20 November 2017 at 12:00, David Kastrup <d...@gnu.org> wrote:
> >> >
> >> >> Gianmaria Lari <gianmarial...@gmail.com> writes:
> >>
> >> >> > Is there any (simple) way to rewrite it in a more concise way like
> >> >> > this for example?
> >> >> >
> >> >> >   \repeat unfold 7 {
> >> >> >     \modalTranspose c "c+index" \scale \pattern
> >> >> >   }
> >> >>
> >> >> What is simple?
> >> >>
> >> >> \version "2.18.0"
> >> >>
> >> >> scale = {c d e f g a b}
> >> >> pattern = {c d e f}
> >> >>
> >> >> \fixed c' {
> >> >>   #@(map
> >> >>       (lambda (p)
> >> >>         #{ \modalTranspose c #(ly:make-pitch -1 p) \scale \pattern
> #})
> >> >>       (iota 8))
> >> >> }
> >> >
> >> > Thank you David, it works perfectly!
> >> >
> >> > Is there any way to encapsulate it in a function to avoid to write
> >> > all the code any time I need it?
> >>
> >> What is "all the code"?  I really have no idea what makes you consider
> >> something simple (and your "explanation" below does not help at all
> >> since it is tantamount to "simple depends on the viewer's metrics").
> >> I also have no idea what part of the above you consider "it" to be
> >> encapsulated and what you consider variable.
> >
> > I'm sorry I have not been clear. If you have a look to the following
> source
> > you'll see that the same code is repeated three times (only the variable
> > 'pattern' changes).
> >
> > \version "2.18.0"
> > scale = {c d e f g a b}
> >
> > pattern = {c d e f}
> > \fixed c' {
> >   #@(map
> >       (lambda (p)
> >         #{ \modalTranspose c #(ly:make-pitch -1 p) \scale \pattern #})
> >       (iota 8))
> > }
> >
> > pattern = {f e d c}
> > \fixed c' {
> >   #@(map
> >       (lambda (p)
> >         #{ \modalTranspose c #(ly:make-pitch -1 p) \scale \pattern #})
> >       (iota 8))
> > }
> >
> > pattern = {a c e g}
> > \fixed c' {
> >   #@(map
> >       (lambda (p)
> >         #{ \modalTranspose c #(ly:make-pitch -1 p) \scale \pattern #})
> >       (iota 8))
> > }
> >
> >
> > I was wondering if it was possible to to avoid this redundancy.
>
> whatever =
> #(define-music-function (pattern) (ly:music?)
>   #{ \fixed c' {
>        #@(map
>            (lambda (p)
>              #{ \modalTranspose c #(ly:make-pitch -1 p) \scale #pattern #})
>            (iota 8))
>      } #})
>
> \whatever {c d e f}
> \whatever {f e d c}
> \whatever {a c e g}
>
> It might make sense to read up on the basics of music functions in the
> notation reference.  Simple substitution functions like the above should
> be more or less covered and adding
>
> ... =
> #(define-music-function (pattern) (ly:music?)
>   #{ ... #})
>
> around some LilyPond code is not exactly rocket science.  For that
> reason my question about what you consider simple and what not.
>
> --
> David Kastrup
>
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to