Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread Werner LEMBERG

> The documentation clearly states:
> 
> 
> 
>Arguments are distinguished according to their type:
>• a markup, corresponding to type predicate ‘markup?’;
>• a list of markups, corresponding to type predicate
>  ‘markup-list?’;
>• any other scheme object, corresponding to type predicates such
>  as ‘list?’, ‘number?’, ‘boolean?’, etc.
>
> You use a predicate other than markup? or markup-list?, so this
> counts as any other scheme object.

OK.

> The real question is what you actually are trying to achieve here.

I want to write a user-friendly markup command that can accept either
a markup or a markup list as arguments.  Example:

```
% \ornament   
\markup \ornament \number ♭
  \musicglyph "scripts.turn"
  \number ♮
\markup \ornament { \number ♭ \number ♭ }
  \musicglyph "scripts.turn"
  \number ♮
```


Werner


Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread David Kastrup
Werner LEMBERG  writes:

>> The real question is what you actually are trying to achieve here.
>
> I want to write a user-friendly markup command that can accept either
> a markup or a markup list as arguments.  Example:
>
> ```
> % \ornament   
> \markup \ornament \number ♭
>   \musicglyph "scripts.turn"
>   \number ♮
> \markup \ornament { \number ♭ \number ♭ }
>   \musicglyph "scripts.turn"
>   \number ♮
> ```

So if you give a markup list here, is this supposed to be stacked
horizontally or vertically?  If horizontally, adding \line does not seem
all that terrible.

And it will be hard to explain what

\markup \ornament \with-color #red { \number ♭ \number ♭ } ...

is supposed to do: is \with-color #red applied to the numbers or to the
whole list?

-- 
David Kastrup



Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread Werner LEMBERG

>> I want to write a user-friendly markup command that can accept either
>> a markup or a markup list as arguments.  Example:
>>
>> ```
>> % \ornament   
>> \markup \ornament \number ♭
>>   \musicglyph "scripts.turn"
>>   \number ♮
>> \markup \ornament { \number ♭ \number ♭ }
>>   \musicglyph "scripts.turn"
>>   \number ♮
>> ```
> 
> So if you give a markup list here, is this supposed to be stacked
> horizontally or vertically?

Vertically.

> If horizontally, adding \line does not seem all that terrible.

Yep.

> And it will be hard to explain what
> 
> \markup \ornament \with-color #red { \number ♭ \number ♭ } ...
> 
> is supposed to do: is \with-color #red applied to the numbers or to
> the whole list?

I would rather write either

  \markup \with-color #red \ornament { \number ♭ \number ♭ } ...

or 

  \markup \ornament { \with-color #red \number ♭
  \with-color #red \number ♭ } ...

so I don't mind if

  \markup \ornament \with-color #red { \number ♭ \number ♭ } ...

is probably not well defined.


Werner


Re: need help building a Scheme function

2024-06-22 Thread Kieren MacMillan
Hi again,

> There is no necessity to return a new NoteEvent; you can just change
> pitch on the existing one.
> 
> Music functions are allowed to modify their music arguments in place.

This is what I have so far, which appears to do what I want:

%%%  SNIPPET BEGINS
\version "2.25.11"

adjustPitch = 
#(define-music-function (pitchIn pitchOut music) (ly:pitch? ly:pitch? ly:music?)
   (music-map
(lambda (m)
(if (music-is-of-type? m 'note-event)
(if (equal? (ly:pitch-notename (ly:music-property m 'pitch)) 
(ly:pitch-notename pitchIn))
(ly:music-set-property! m 'pitch (ly:make-pitch 
(ly:pitch-octave (ly:music-property m 'pitch)) (ly:pitch-notename pitchOut) 0))
(make-music 'NoteEvent m))
(ly:message "Not of type"))
m)
music))

\adjustPitch ees e \fixed c' { c4 d es f g c' es' }
%%%  SNIPPET ENDS

Comments before I move to the next step…?

Thanks,
Kieren.
__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.




Re: need help building a Scheme function

2024-06-22 Thread David Kastrup
Kieren MacMillan  writes:

> Hi again,
>
>> There is no necessity to return a new NoteEvent; you can just change
>> pitch on the existing one.
>> 
>> Music functions are allowed to modify their music arguments in place.
>
> This is what I have so far, which appears to do what I want:
>
> %%%  SNIPPET BEGINS
> \version "2.25.11"
>
> adjustPitch = 
> #(define-music-function (pitchIn pitchOut music) (ly:pitch? ly:pitch? 
> ly:music?)
>(music-map
> (lambda (m)
> (if (music-is-of-type? m 'note-event)
> (if (equal? (ly:pitch-notename (ly:music-property m 'pitch)) 
> (ly:pitch-notename pitchIn))
> (ly:music-set-property! m 'pitch (ly:make-pitch 
> (ly:pitch-octave (ly:music-property m 'pitch)) (ly:pitch-notename pitchOut) 
> 0))
> (make-music 'NoteEvent m))
> (ly:message "Not of type"))
> m)
> music))
>
> \adjustPitch ees e \fixed c' { c4 d es f g c' es' }
> %%%  SNIPPET ENDS
>
> Comments before I move to the next step…?

This will also adjust eis and eses to e.  Note names are numbers and can
be compared with = .  (make-music 'NoteEvent m) is silly and creates an
unnecessary copy.  You can just use m instead.

If you do, you don't replace any music, so music-map is unnecessary.
This can be better done with for-some-music .

-- 
David Kastrup



Re: need help building a Scheme function

2024-06-22 Thread Kieren MacMillan
Hi David,

> This will also adjust eis and eses to e.  Note names are numbers and can
> be compared with = .  (make-music 'NoteEvent m) is silly and creates an
> unnecessary copy.  You can just use m instead.

Thanks — current version:

%%%  SNIPPET BEGINS
\version "2.25.11"

adjustPitch =
#(define-music-function (pitchIn pitchOut music) (ly:pitch? ly:pitch? ly:music?)
   (music-map
(lambda (m)
(if (music-is-of-type? m 'note-event)
(if (and (= (ly:pitch-notename (ly:music-property m 'pitch)) 
(ly:pitch-notename pitchIn))
  (= (ly:pitch-alteration (ly:music-property m 'pitch)) 
(ly:pitch-alteration pitchIn)))
(ly:music-set-property! m 'pitch
(ly:make-pitch
 (ly:pitch-octave (ly:music-property m 
'pitch))
 (ly:pitch-notename pitchOut)
 (ly:pitch-alteration pitchOut)))
m)
#f)
m)
music))

testmusic = \fixed c' { c4 d es e f g c' es' eis' }

{ \testmusic }

{ \adjustPitch ees e \testmusic }
%%%  SNIPPET ENDS

Q: Is there a more efficient way to test for note name and alteration 
independent of octave?

> If you do, you don't replace any music, so music-map is unnecessary.
> This can be better done with for-some-music .

I tried a few times, but got errors (about returning unspecified). Hints 
appreciated.

As for next step(s): I’m thinking some let-ing would make sense?

Thanks,
Kieren.
__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.




Re: need help building a Scheme function

2024-06-22 Thread David Kastrup
Kieren MacMillan  writes:

> I tried a few times, but got errors (about returning
> unspecified). Hints appreciated.

for-some-music does not return music.  It works on music in-place.  So
the last thing in your music function must not be for-some-music but
rather the music that you have been working on.

-- 
David Kastrup



Re: need help building a Scheme function

2024-06-22 Thread Kieren MacMillan
Hi David,

> for-some-music does not return music.  It works on music in-place.  So
> the last thing in your music function must not be for-some-music but
> rather the music that you have been working on.

So…

%%%  SNIPPET BEGINS
adjustPitch =
#(define-music-function (pitchIn pitchOut music) (ly:pitch? ly:pitch? ly:music?)
   (for-some-music
(lambda (m)
(if (music-is-of-type? m 'note-event)
(if (and (= (ly:pitch-notename (ly:music-property m 'pitch)) 
(ly:pitch-notename pitchIn))
  (= (ly:pitch-alteration (ly:music-property m 'pitch)) 
(ly:pitch-alteration pitchIn)))
(ly:music-set-property! m 'pitch
(ly:make-pitch
 (ly:pitch-octave (ly:music-property m 
'pitch))
 (ly:pitch-notename pitchOut)
 (ly:pitch-alteration pitchOut)))
m)
#f))
music)
music)

testmusic = \fixed c' { c4 d es e f g c' es' eis }

{ \testmusic }

{ \adjustPitch ees e \testmusic }
%%%  SNIPPET ENDS

??

Thanks,
Kieren.
__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.